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.
Signed-off-by: John Ferlan
---
v1: https://www.redhat.com/archives/libvir-list/2017-September/msg00122.html
Alter the patch to make the adjustment during device post parsing rather
than command line creation as requested by code review. This will alter
the output XML as well as the command line arguments for those entries
that don't supply a LUN. We had a few, so that works out testing wise!
src/conf/domain_conf.c | 43 ++
.../qemuargv2xml-disk-drive-network-iscsi.xml | 2 +-
.../qemuxml2argv-disk-drive-network-iscsi-lun.args | 2 +-
.../qemuxml2argv-disk-drive-network-iscsi.args | 2 +-
.../qemuxml2argv-hostdev-scsi-lsi-iscsi.args | 2 +-
.../qemuxml2argv-hostdev-scsi-virtio-iscsi.args| 2 +-
.../qemuxml2xmlout-disk-drive-network-iscsi.xml| 2 +-
.../qemuxml2xmlout-hostdev-scsi-lsi-iscsi.xml | 2 +-
.../qemuxml2xmlout-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 676fc0f34..a43b25c31 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 23542fa1d..694412b5c 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 b25f3a0d6..0fbfd9a6d 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.examp