]> xenbits.xensource.com Git - libvirt.git/commitdiff
Introduce <readonly> for hostdev
authorOsier Yang <jyang@redhat.com>
Fri, 3 May 2013 18:07:25 +0000 (02:07 +0800)
committerOsier Yang <jyang@redhat.com>
Mon, 13 May 2013 11:02:40 +0000 (19:02 +0800)
Since it's generic enough to be used by other types in future, I
put it in <hostdev> as sub-element, though now it's only used by
scsi host device.

docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-readonly.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-readonly.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmltest.c

index 27fd458fe5b9dec752d0003add8f22d902217e3b..ba2586e51645c30b86e36905406676702798a371 100644 (file)
         could be changed in the future with no impact to domains that
         don't specify anything.
       </dd>
+      <dt><code>readonly</code></dt>
+      <dd>Indicates that the device is readonly, only supported by SCSI host
+        device now. <span class="since">Since 1.0.6 (QEMU and KVM only)</span>
+      </dd>
     </dl>
 
 
index b8d0d6089b41a0c2a0450b51b2a0d77eb0901db2..4fdacab5c4391fa7f876c22ff476a9052e69a6b4 100644 (file)
         <optional>
           <ref name="address"/>
         </optional>
+        <optional>
+          <element name="readonly">
+            <empty/>
+          </element>
+        </optional>
       </interleave>
     </element>
   </define>
index d20faa5eef8cf5464ee2d06fd5db40e84516d75b..209602777dee298a5f3856a0d02ea24f7002501a 100644 (file)
@@ -8730,6 +8730,9 @@ virDomainHostdevDefParseXML(const xmlNodePtr node,
                                _("SCSI host devices must have address specified"));
                 goto error;
             }
+
+            if (virXPathBoolean("boolean(./readonly)", ctxt))
+                def->readonly = true;
             break;
         }
     }
@@ -15358,6 +15361,9 @@ virDomainHostdevDefFormat(virBufferPtr buf,
             return -1;
         break;
     }
+
+    if (def->readonly)
+        virBufferAddLit(buf, "<readonly/>\n");
     virBufferAdjustIndent(buf, -6);
 
     if (virDomainDeviceInfoFormat(buf, def->info,
index 1efae699c3ca73539717601f90695723ad59c268..5471cd3906bee67418dcf1c69742144a14287a0e 100644 (file)
@@ -461,6 +461,7 @@ struct _virDomainHostdevDef {
     int startupPolicy; /* enum virDomainStartupPolicy */
     bool managed;
     bool missing;
+    bool readonly;
     union {
         virDomainHostdevSubsys subsys;
         virDomainHostdevCaps caps;
index ef44809efac186fca51551ea6684f818b5cdc1cc..db345c824617aa86e386dc0b5ea814d22790bfe6 100644 (file)
@@ -4754,6 +4754,17 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
                       virDomainDeviceAddressTypeToString(dev->info->type),
                       dev->info->alias);
 
+    if (dev->readonly) {
+        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_READONLY)) {
+            virBufferAddLit(&buf, ",readonly=on");
+        } else {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("this qemu doesn't support 'readonly' "
+                             "for -drive"));
+            goto error;
+        }
+    }
+
     if (virBufferError(&buf)) {
         virReportOOMError();
         goto error;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-readonly.args b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-readonly.args
new file mode 100644 (file)
index 0000000..ea2f7af
--- /dev/null
@@ -0,0 +1,9 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
+pc -m 214 -smp 1 -nographic -nodefaults -monitor \
+unix:/tmp/test-monitor,server,nowait -no-acpi -boot c \
+-device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3 -usb \
+-drive file=/dev/HostVG/QEMUGuest2,if=none,id=drive-ide0-0-0 \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+-drive file=/dev/sg0,if=none,id=drive-hostdev-scsi_host0-0-0-0,readonly=on \
+-device scsi-generic,bus=scsi0.0,channel=0,scsi-id=4,lun=8,drive=drive-hostdev-scsi_host0-0-0-0,id=hostdev-scsi_host0-0-0-0 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-readonly.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-readonly.xml
new file mode 100644 (file)
index 0000000..359bb95
--- /dev/null
@@ -0,0 +1,36 @@
+<domain type='qemu'>
+  <name>QEMUGuest2</name>
+  <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest2'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='scsi' index='0' model='virtio-scsi'/>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <hostdev mode='subsystem' type='scsi' managed='yes'>
+      <source>
+        <adapter name='scsi_host0'/>
+        <address bus='0' target='0' unit='0'/>
+      </source>
+      <readonly/>
+      <address type='drive' controller='0' bus='0' target='4' unit='8'/>
+    </hostdev>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
index 1f86723aa81b4c1106c2f30c70aba397c2964ebf..feb2ed23ed1bbab857f658b5d1def0acaa4791e1 100644 (file)
@@ -985,6 +985,10 @@ mymain(void)
             QEMU_CAPS_DEVICE, QEMU_CAPS_DRIVE,
             QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_VIRTIO_SCSI,
             QEMU_CAPS_DEVICE_SCSI_GENERIC);
+    DO_TEST("hostdev-scsi-readonly", QEMU_CAPS_DRIVE,
+            QEMU_CAPS_DEVICE, QEMU_CAPS_DRIVE,
+            QEMU_CAPS_DRIVE_READONLY, QEMU_CAPS_VIRTIO_SCSI,
+            QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_DEVICE_SCSI_GENERIC);
 
     virObjectUnref(driver.config);
     virObjectUnref(driver.caps);
index 08c3eeb31be377a0e1508ec25b8eabd848f6822e..492ac601021f31f806860452fdc30a08ad794cd8 100644 (file)
@@ -287,6 +287,7 @@ mymain(void)
 
     DO_TEST("hostdev-scsi-lsi");
     DO_TEST("hostdev-scsi-virtio-scsi");
+    DO_TEST("hostdev-scsi-readonly");
 
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlopt);