]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Provide default LUN=0 for iSCSI if not provided
authorJohn Ferlan <jferlan@redhat.com>
Mon, 11 Sep 2017 23:18:21 +0000 (19:18 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 12 Sep 2017 14:33:25 +0000 (10:33 -0400)
https://bugzilla.redhat.com/show_bug.cgi?id=1477880

If the "/#" is missing from the provided iSCSI path, then we need
to provide the default LUN of /0; otherwise, QEMU will fail to parse
the URL causing a failure to either create the guest or hotplug
attach the storage.

During post parse, for any iSCSI disk or hostdev, scan the source
path looking for the presence of '/', if found, then we can assume
the LUN is provided.  If not found, alter the input XML to add the
"/0".  This will cause the generated XML to have the generated
value when the domain config is saved after post parse.

src/conf/domain_conf.c
tests/qemuargv2xmldata/qemuargv2xml-disk-drive-network-iscsi.xml
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi-lun.args
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi.args
tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-lsi-iscsi.args
tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-virtio-iscsi.args
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-network-iscsi.xml
tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-lsi-iscsi.xml
tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-virtio-iscsi.xml

index 676fc0f34b6c4bd82f6cb09d8cedb65a87d1f5cb..a43b25c3186f8a19383ce943c3dd335b4076fd8d 100644 (file)
@@ -4308,16 +4308,54 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt,
 }
 
 
+/**
+ * virDomainPostParseCheckISCSIPath
+ * @srcpath: Source path read (a/k/a, IQN) either disk or hostdev
+ *
+ * The details of an IQN is defined by RFC 3720 and 3721, but
+ * we just need to make sure there's a lun provided. If not
+ * provided, then default to zero. For an ISCSI LUN that is
+ * is provided by /dev/disk/by-path/... , then that path will
+ * have the specific lun requested.
+ *
+ * Returns 0 on success, -1 on failure
+ */
+static int
+virDomainPostParseCheckISCSIPath(char **srcpath)
+{
+    char *path = NULL;
+
+    if (strchr(*srcpath, '/'))
+        return 0;
+
+    if (virAsprintf(&path, "%s/0", *srcpath) < 0)
+        return -1;
+    VIR_FREE(*srcpath);
+    VIR_STEAL_PTR(*srcpath, path);
+    return 0;
+}
+
+
 static int
 virDomainHostdevDefPostParse(virDomainHostdevDefPtr dev,
                              const virDomainDef *def,
                              virDomainXMLOptionPtr xmlopt)
 {
+    virDomainHostdevSubsysSCSIPtr scsisrc;
+
     if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
         return 0;
 
     switch (dev->source.subsys.type) {
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
+        scsisrc = &dev->source.subsys.u.scsi;
+        if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
+            virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
+
+            if (virDomainPostParseCheckISCSIPath(&iscsisrc->path) < 0)
+                return -1;
+        }
+
         if (dev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
             virDomainHostdevAssignAddress(xmlopt, def, dev) < 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -4455,6 +4493,11 @@ virDomainDeviceDefPostParseCommon(virDomainDeviceDefPtr dev,
             }
         }
 
+        if (disk->src->type == VIR_STORAGE_TYPE_NETWORK &&
+            disk->src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI &&
+            virDomainPostParseCheckISCSIPath(&disk->src->path) < 0)
+            return -1;
+
         if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO &&
             virDomainCheckVirtioOptions(disk->virtio) < 0)
             return -1;
index 23542fa1ddaaa9ec4ef03c45899739b2adf699cb..694412b5c7d174bc9a5da641483349ab37344bb2 100644 (file)
@@ -16,7 +16,7 @@
     <emulator>/usr/bin/qemu-system-i686</emulator>
     <disk type='network' device='disk'>
       <driver name='qemu' type='raw'/>
-      <source protocol='iscsi' name='iqn.1992-01.com.example'>
+      <source protocol='iscsi' name='iqn.1992-01.com.example/0'>
         <host name='example.org' port='6000'/>
       </source>
       <target dev='vda' bus='virtio'/>
index b25f3a0d62e7f6cdcca322ae464d246a477ab77a..0fbfd9a6d93cb723b74d47cc00393f0236f4e988 100644 (file)
@@ -21,7 +21,7 @@ server,nowait \
 -boot c \
 -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3 \
 -usb \
--drive file=iscsi://example.org:3260/iqn.1992-01.com.example,format=raw,\
+-drive file=iscsi://example.org:3260/iqn.1992-01.com.example/0,format=raw,\
 if=none,id=drive-scsi0-0-0-0 \
 -device scsi-block,bus=scsi0.0,channel=0,scsi-id=0,lun=0,\
 drive=drive-scsi0-0-0-0,id=scsi0-0-0-0
index a1d93af10728313d38ef5192a7018b4ee7abae8b..ed15fda212e12186fe7bb0ba918116500c2cf1e1 100644 (file)
@@ -19,7 +19,7 @@ server,nowait \
 -no-acpi \
 -boot c \
 -usb \
--drive file=iscsi://example.org:6000/iqn.1992-01.com.example,format=raw,\
+-drive file=iscsi://example.org:6000/iqn.1992-01.com.example/0,format=raw,\
 if=none,id=drive-virtio-disk0 \
 -device virtio-blk-pci,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,\
 id=virtio-disk0 \
index 43c555a50ad187508b0246cf2cae33e7c64b0faf..07ae9f592941286046dd913a2e6e61d4aa0ae465 100644 (file)
@@ -22,7 +22,7 @@ server,nowait \
 -usb \
 -drive file=/dev/HostVG/QEMUGuest2,format=raw,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=iscsi://example.org:3260/iqn.1992-01.com.example,if=none,\
+-drive file=iscsi://example.org:3260/iqn.1992-01.com.example/0,if=none,\
 format=raw,id=drive-hostdev0 \
 -device scsi-generic,bus=scsi0.0,scsi-id=4,drive=drive-hostdev0,id=hostdev0 \
 -drive file=iscsi://example.org:3260/iqn.1992-01.com.example/1,if=none,\
index a78e3092c8331ef61a9b5b6dd69302df0b17a45c..d80c859183488ca149d7733e05f0388986088f08 100644 (file)
@@ -22,7 +22,7 @@ server,nowait \
 -usb \
 -drive file=/dev/HostVG/QEMUGuest2,format=raw,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=iscsi://example.org:3260/iqn.1992-01.com.example,if=none,\
+-drive file=iscsi://example.org:3260/iqn.1992-01.com.example/0,if=none,\
 format=raw,id=drive-hostdev0 \
 -device scsi-generic,bus=scsi0.0,channel=0,scsi-id=2,lun=4,\
 drive=drive-hostdev0,id=hostdev0 \
index 23542fa1ddaaa9ec4ef03c45899739b2adf699cb..694412b5c7d174bc9a5da641483349ab37344bb2 100644 (file)
@@ -16,7 +16,7 @@
     <emulator>/usr/bin/qemu-system-i686</emulator>
     <disk type='network' device='disk'>
       <driver name='qemu' type='raw'/>
-      <source protocol='iscsi' name='iqn.1992-01.com.example'>
+      <source protocol='iscsi' name='iqn.1992-01.com.example/0'>
         <host name='example.org' port='6000'/>
       </source>
       <target dev='vda' bus='virtio'/>
index e19bce6ea193500132f02b9319ed23d44c2ac156..b7312ca4f338a8a530c8ab578a69cb8db8c77d12 100644 (file)
@@ -32,7 +32,7 @@
     <input type='mouse' bus='ps2'/>
     <input type='keyboard' bus='ps2'/>
     <hostdev mode='subsystem' type='scsi' managed='yes'>
-      <source protocol='iscsi' name='iqn.1992-01.com.example'>
+      <source protocol='iscsi' name='iqn.1992-01.com.example/0'>
         <host name='example.org' port='3260'/>
       </source>
       <address type='drive' controller='0' bus='0' target='0' unit='4'/>
index 37635b4f90edcbbf3dc90b2c1f1607db8c088ca9..ddf78016020534006f7f8839ad0ce2931b414e31 100644 (file)
@@ -32,7 +32,7 @@
     <input type='mouse' bus='ps2'/>
     <input type='keyboard' bus='ps2'/>
     <hostdev mode='subsystem' type='scsi' managed='yes'>
-      <source protocol='iscsi' name='iqn.1992-01.com.example'>
+      <source protocol='iscsi' name='iqn.1992-01.com.example/0'>
         <host name='example.org' port='3260'/>
       </source>
       <address type='drive' controller='0' bus='0' target='2' unit='4'/>