]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: add rawio attribute to disk element of domain XML
authorTaku Izumi <izumi.taku@jp.fujitsu.com>
Tue, 31 Jan 2012 04:49:00 +0000 (23:49 -0500)
committerLaine Stump <laine@laine.org>
Tue, 31 Jan 2012 18:36:23 +0000 (13:36 -0500)
 This patch adds a new attribute "rawio" to the "disk" element
 of domain XML. Valid values of "rawio" attribute are "yes"
 and "no".
 rawio='yes' indicates the disk is desirous of CAP_SYS_RAWIO.

 If you specify the following XML:

 <disk type='block' device='lun' rawio='yes'>
  ...
 </disk>

 the domain will be granted CAP_SYS_RAWIO.
 (of course, the domain have to be executed with root privilege)

NOTE:
   - "rawio" attribute is only valid when device='lun'
   - At the moment, any other disks you won't use rawio can use rawio.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
tests/qemuxml2argvdata/qemuxml2argv-virtio-lun.args
tests/qemuxml2argvdata/qemuxml2argv-virtio-lun.xml

index ab84730b8f9da545c70d52fc38841735fe8a32c9..a025a8ef6b67f1100dbcffda7255f5802b187bf5 100644 (file)
         - also note that device='lun' will only be recognized for
         actual raw devices, never for individual partitions or LVM
         partitions (in those cases, the kernel will reject the generic
-        SCSI commands, making it identical to device='disk').  The
-        optional <code>snapshot</code> attribute indicates the default
+        SCSI commands, making it identical to device='disk').
+        The optional <code>rawio</code> attribute indicates that the disk
+        is desirous of rawio capability. This attribute is only valid when
+        device is "lun".
+        The optional <code>snapshot</code> attribute indicates the default
         behavior of the disk during disk snapshots: "internal"
         requires a file format such as qcow2 that can store both the
         snapshot and the data changes since the snapshot;
index ee4270ab561d17bc3b5f592988d5b38ba68e26ea..66e5491fc86ecba7d78cf5bde81f888d502932a9 100644 (file)
           </choice>
         </attribute>
       </optional>
+      <optional>
+        <attribute name="rawio">
+          <choice>
+            <value>yes</value>
+            <value>no</value>
+          </choice>
+        </attribute>
+      </optional>
       <optional>
         <ref name="snapshot"/>
       </optional>
index 4803cdf33fcae30e3d4956d83fa91652d4f1c64d..35cb7a454d748e27b3751324d7cf0c9471d0492d 100644 (file)
@@ -2806,6 +2806,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
     char *type = NULL;
     char *device = NULL;
     char *snapshot = NULL;
+    char *rawio = NULL;
     char *driverName = NULL;
     char *driverType = NULL;
     char *source = NULL;
@@ -2850,6 +2851,8 @@ virDomainDiskDefParseXML(virCapsPtr caps,
 
     snapshot = virXMLPropString(node, "snapshot");
 
+    rawio = virXMLPropString(node, "rawio");
+
     cur = node->children;
     while (cur != NULL) {
         if (cur->type == XML_ELEMENT_NODE) {
@@ -3156,6 +3159,26 @@ virDomainDiskDefParseXML(virCapsPtr caps,
         def->snapshot = VIR_DOMAIN_DISK_SNAPSHOT_NO;
     }
 
+    if (rawio) {
+        def->rawio_specified = true;
+        if (def->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
+            if (STREQ(rawio, "yes")) {
+                def->rawio = 1;
+            } else if (STREQ(rawio, "no")) {
+                def->rawio = 0;
+            } else {
+                virDomainReportError(VIR_ERR_XML_ERROR,
+                                     _("unknown disk rawio setting '%s'"),
+                                     rawio);
+                goto error;
+            }
+        } else {
+            virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                                _("rawio can be used only with device='lun'"));
+            goto error;
+        }
+    }
+
     if (bus) {
         if ((def->bus = virDomainDiskBusTypeFromString(bus)) < 0) {
             virDomainReportError(VIR_ERR_INTERNAL_ERROR,
@@ -9972,6 +9995,13 @@ virDomainDiskDefFormat(virBufferPtr buf,
     virBufferAsprintf(buf,
                       "    <disk type='%s' device='%s'",
                       type, device);
+    if (def->rawio_specified) {
+        if (def->rawio == 1) {
+            virBufferAddLit(buf, " rawio='yes'");
+        } else if (def->rawio == 0) {
+            virBufferAddLit(buf, " rawio='no'");
+        }
+    }
     if (def->snapshot &&
         !(def->snapshot == VIR_DOMAIN_DISK_SNAPSHOT_NO && def->readonly))
         virBufferAsprintf(buf, " snapshot='%s'",
index 9a036853c93465714910ca4560ad58c99ebe354a..503684f408c6cf643eefe5b602bf34ee5af47e68 100644 (file)
@@ -413,6 +413,8 @@ struct _virDomainDiskDef {
     unsigned int transient : 1;
     virDomainDeviceInfo info;
     virStorageEncryptionPtr encryption;
+    bool rawio_specified;
+    int rawio; /* no = 0, yes = 1 */
 };
 
 
index 5df9182bfb60fdc0554518955efeff0a4c745749..b229f2a0dba37cfe2074cdd1400b74a257fdc51b 100644 (file)
@@ -4,8 +4,8 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 -boot dc -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x6 \
 -drive file=/dev/sdfake,if=none,id=drive-virtio-disk0 \
 -device virtio-blk-pci,scsi=on,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0 \
--drive file=/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso,if=none,media=cdrom,id=drive-ide0-1-0 \
--device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 \
+-drive file=/dev/sdfake2,if=none,id=drive-virtio-disk1 \
+-device virtio-blk-pci,scsi=on,bus=pci.0,addr=0x5,drive=drive-virtio-disk1,id=virtio-disk1 \
 -device virtio-net-pci,vlan=0,id=net0,mac=52:54:00:e5:48:58,bus=pci.0,addr=0x3 \
 -net user,vlan=0,name=hostnet0 -serial pty -usb -vnc 127.0.0.1:-809 -std-vga \
--device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x7
index abe1b2f3c3a25635d3287b360a2008fabc62130e..63107d524aa48a33e31653c32da08a92563d2c31 100644 (file)
   <on_crash>restart</on_crash>
   <devices>
     <emulator>/usr/bin/qemu</emulator>
-    <disk type='block' device='lun'>
+    <disk type='block' device='lun' rawio='yes'>
       <driver name='qemu' type='qcow2'/>
       <source dev='/dev/sdfake'/>
       <target dev='vda' bus='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </disk>
-    <disk type='file' device='cdrom'>
-      <driver name='qemu' type='raw'/>
-      <source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/>
-      <target dev='hdc' bus='ide'/>
-      <readonly/>
-      <address type='drive' controller='0' bus='1' unit='0'/>
+    <disk type='block' device='lun'>
+      <driver name='qemu' type='qcow2'/>
+      <source dev='/dev/sdfake2'/>
+      <target dev='vdb' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
     </disk>
     <controller type='virtio-serial' index='0'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>