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.
This commit is contained in:
John Ferlan 2017-09-11 19:18:21 -04:00
parent 4fc3051258
commit f64f03b5b1
9 changed files with 51 additions and 8 deletions

View 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;

View 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'/>

View 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

View 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 \

View 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,\

View 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 \

View 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'/>

View 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'/>

View 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'/>