From f64f03b5b1e6f3ecd6c6d79316c3efedc00c2167 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Mon, 11 Sep 2017 19:18:21 -0400 Subject: [PATCH] qemu: Provide default LUN=0 for iSCSI if not provided 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 | 43 +++++++++++++++++++ .../qemuargv2xml-disk-drive-network-iscsi.xml | 2 +- ...xml2argv-disk-drive-network-iscsi-lun.args | 2 +- ...qemuxml2argv-disk-drive-network-iscsi.args | 2 +- .../qemuxml2argv-hostdev-scsi-lsi-iscsi.args | 2 +- ...emuxml2argv-hostdev-scsi-virtio-iscsi.args | 2 +- ...emuxml2xmlout-disk-drive-network-iscsi.xml | 2 +- .../qemuxml2xmlout-hostdev-scsi-lsi-iscsi.xml | 2 +- ...muxml2xmlout-hostdev-scsi-virtio-iscsi.xml | 2 +- 9 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 676fc0f34b..a43b25c318 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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; diff --git a/tests/qemuargv2xmldata/qemuargv2xml-disk-drive-network-iscsi.xml b/tests/qemuargv2xmldata/qemuargv2xml-disk-drive-network-iscsi.xml index 23542fa1dd..694412b5c7 100644 --- a/tests/qemuargv2xmldata/qemuargv2xml-disk-drive-network-iscsi.xml +++ b/tests/qemuargv2xmldata/qemuargv2xml-disk-drive-network-iscsi.xml @@ -16,7 +16,7 @@ /usr/bin/qemu-system-i686 - + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi-lun.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi-lun.args index b25f3a0d62..0fbfd9a6d9 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi-lun.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi-lun.args @@ -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 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi.args index a1d93af107..ed15fda212 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi.args @@ -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 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-lsi-iscsi.args b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-lsi-iscsi.args index 43c555a50a..07ae9f5929 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-lsi-iscsi.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-lsi-iscsi.args @@ -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,\ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-virtio-iscsi.args b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-virtio-iscsi.args index a78e3092c8..d80c859183 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-virtio-iscsi.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-virtio-iscsi.args @@ -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 \ diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-network-iscsi.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-network-iscsi.xml index 23542fa1dd..694412b5c7 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-network-iscsi.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-network-iscsi.xml @@ -16,7 +16,7 @@ /usr/bin/qemu-system-i686 - + diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-lsi-iscsi.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-lsi-iscsi.xml index e19bce6ea1..b7312ca4f3 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-lsi-iscsi.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-lsi-iscsi.xml @@ -32,7 +32,7 @@ - +
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-virtio-iscsi.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-virtio-iscsi.xml index 37635b4f90..ddf7801602 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-virtio-iscsi.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-scsi-virtio-iscsi.xml @@ -32,7 +32,7 @@ - +