提交 1a308ee0 编写于 作者: P Paolo Bonzini 提交者: Osier Yang

qemu: add support for libiscsi

libiscsi provides a userspace iSCSI initiator.

The main advantage over the kernel initiator is that it is very
easy to provide different initiator names for VMs on the same host.
Thus libiscsi supports usage of persistent reservations in the VM,
which otherwise would only be possible with NPIV.

libiscsi uses "iscsi" as the scheme, not "iscsi+tcp".  We can change
this in the tests (while remaining backwards-compatible manner, because
QEMU uses TCP as the default transport for both Gluster and NBD).
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 d4500377
...@@ -1446,10 +1446,13 @@ ...@@ -1446,10 +1446,13 @@
are "nbd", "iscsi", "rbd", "sheepdog" or "gluster". If the are "nbd", "iscsi", "rbd", "sheepdog" or "gluster". If the
<code>protocol</code> attribute is "rbd", "sheepdog" or "gluster", an <code>protocol</code> attribute is "rbd", "sheepdog" or "gluster", an
additional attribute <code>name</code> is mandatory to specify which additional attribute <code>name</code> is mandatory to specify which
volume/image will be used; for "nbd" it is optional. When the disk volume/image will be used; for "nbd" it is optional. For "iscsi",
<code>type</code> is "network", the <code>source</code> may have zero the <code>name</code> attribute may include a logical unit number,
or more <code>host</code> sub-elements used to specify the hosts separated from the target's name by a slash (for example,
to connect. <code>iqn.1992-01.com.example/1</code>); the default LUN is zero.
When the disk <code>type</code> is "network", the <code>source</code>
may have zero or more <code>host</code> sub-elements used to
specify the hosts to connect.
<span class="since">Since 0.0.3; <code>type='dir'</code> since <span class="since">Since 0.0.3; <code>type='dir'</code> since
0.7.5; <code>type='network'</code> since 0.7.5; <code>type='network'</code> since
0.8.7; <code>protocol='iscsi'</code> since 1.0.4</span><br/> 0.8.7; <code>protocol='iscsi'</code> since 1.0.4</span><br/>
......
...@@ -2390,6 +2390,31 @@ qemuParseGlusterString(virDomainDiskDefPtr def) ...@@ -2390,6 +2390,31 @@ qemuParseGlusterString(virDomainDiskDefPtr def)
return qemuParseDriveURIString(def, uri, "gluster"); return qemuParseDriveURIString(def, uri, "gluster");
} }
static int
qemuParseISCSIString(virDomainDiskDefPtr def)
{
virURIPtr uri = NULL;
char *slash;
unsigned lun;
if (!(uri = virURIParse(def->src)))
return -1;
if (uri->path &&
(slash = strchr(uri->path + 1, '/')) != NULL) {
if (slash[1] == '\0')
*slash = '\0';
else if (virStrToLong_ui(slash + 1, NULL, 10, &lun) == -1) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid name '%s' for iSCSI disk"), def->src);
return -1;
}
}
return qemuParseDriveURIString(def, uri, "iscsi");
}
static int static int
qemuParseNBDString(virDomainDiskDefPtr disk) qemuParseNBDString(virDomainDiskDefPtr disk)
{ {
...@@ -2484,8 +2509,14 @@ qemuBuildDriveURIString(virDomainDiskDefPtr disk, virBufferPtr opt, ...@@ -2484,8 +2509,14 @@ qemuBuildDriveURIString(virDomainDiskDefPtr disk, virBufferPtr opt,
virBufferAddLit(opt, "file="); virBufferAddLit(opt, "file=");
transp = virDomainDiskProtocolTransportTypeToString(disk->hosts->transport); transp = virDomainDiskProtocolTransportTypeToString(disk->hosts->transport);
if (virAsprintf(&tmpscheme, "%s+%s", scheme, transp) < 0) if (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) {
goto no_memory; tmpscheme = strdup(scheme);
if (tmpscheme == NULL)
goto no_memory;
} else {
if (virAsprintf(&tmpscheme, "%s+%s", scheme, transp) < 0)
goto no_memory;
}
if (disk->src && virAsprintf(&volimg, "/%s", disk->src) < 0) if (disk->src && virAsprintf(&volimg, "/%s", disk->src) < 0)
goto no_memory; goto no_memory;
...@@ -2530,6 +2561,12 @@ qemuBuildGlusterString(virDomainDiskDefPtr disk, virBufferPtr opt) ...@@ -2530,6 +2561,12 @@ qemuBuildGlusterString(virDomainDiskDefPtr disk, virBufferPtr opt)
#define QEMU_DEFAULT_NBD_PORT "10809" #define QEMU_DEFAULT_NBD_PORT "10809"
static int
qemuBuildISCSIString(virDomainDiskDefPtr disk, virBufferPtr opt)
{
return qemuBuildDriveURIString(disk, opt, "iscsi");
}
static int static int
qemuBuildNBDString(virDomainDiskDefPtr disk, virBufferPtr opt) qemuBuildNBDString(virDomainDiskDefPtr disk, virBufferPtr opt)
{ {
...@@ -2713,6 +2750,11 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -2713,6 +2750,11 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
goto error; goto error;
virBufferAddChar(&opt, ','); virBufferAddChar(&opt, ',');
break; break;
case VIR_DOMAIN_DISK_PROTOCOL_ISCSI:
if (qemuBuildISCSIString(disk, &opt) < 0)
goto error;
virBufferAddChar(&opt, ',');
break;
case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG: case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
if (disk->nhosts == 0) { if (disk->nhosts == 0) {
...@@ -7909,6 +7951,12 @@ qemuParseCommandLineDisk(virCapsPtr qemuCaps, ...@@ -7909,6 +7951,12 @@ qemuParseCommandLineDisk(virCapsPtr qemuCaps,
if (qemuParseGlusterString(def) < 0) if (qemuParseGlusterString(def) < 0)
goto error; goto error;
} else if (STRPREFIX(def->src, "iscsi:")) {
def->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
def->protocol = VIR_DOMAIN_DISK_PROTOCOL_ISCSI;
if (qemuParseISCSIString(def) < 0)
goto error;
} else if (STRPREFIX(def->src, "sheepdog:")) { } else if (STRPREFIX(def->src, "sheepdog:")) {
char *p = def->src; char *p = def->src;
char *port, *vdi; char *port, *vdi;
...@@ -9199,6 +9247,11 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, ...@@ -9199,6 +9247,11 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
if (qemuParseGlusterString(disk) < 0) if (qemuParseGlusterString(disk) < 0)
goto error; goto error;
break;
case VIR_DOMAIN_DISK_PROTOCOL_ISCSI:
if (qemuParseISCSIString(disk) < 0)
goto error;
break; break;
} }
} }
......
...@@ -189,6 +189,7 @@ mymain(void) ...@@ -189,6 +189,7 @@ mymain(void)
DO_TEST("disk-drive-network-nbd-ipv6"); DO_TEST("disk-drive-network-nbd-ipv6");
DO_TEST("disk-drive-network-nbd-ipv6-export"); DO_TEST("disk-drive-network-nbd-ipv6-export");
DO_TEST("disk-drive-network-nbd-unix"); DO_TEST("disk-drive-network-nbd-unix");
DO_TEST("disk-drive-network-iscsi");
DO_TEST("disk-drive-network-gluster"); DO_TEST("disk-drive-network-gluster");
DO_TEST("disk-drive-network-rbd"); DO_TEST("disk-drive-network-rbd");
DO_TEST("disk-drive-network-rbd-ipv6"); DO_TEST("disk-drive-network-rbd-ipv6");
......
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb -drive file=gluster+tcp://example.org:6000/Volume1/Image,if=virtio,format=raw -drive 'file=gluster+unix:///Volume2/Image?socket=/path/to/sock,if=virtio,format=raw' -net none -serial none -parallel none LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb -drive file=gluster://example.org:6000/Volume1/Image,if=virtio,format=raw -drive 'file=gluster+unix:///Volume2/Image?socket=/path/to/sock,if=virtio,format=raw' -net none -serial none -parallel none
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb -drive file=iscsi://example.org:6000/iqn.1992-01.com.example,if=virtio,format=raw -drive file=iscsi://example.org:6000/iqn.1992-01.com.example/1,if=virtio,format=raw -net none -serial none -parallel none
...@@ -21,6 +21,13 @@ ...@@ -21,6 +21,13 @@
</source> </source>
<target dev='vda' bus='virtio'/> <target dev='vda' bus='virtio'/>
</disk> </disk>
<disk type='network' device='disk'>
<driver name='qemu' type='raw'/>
<source protocol='iscsi' name='iqn.1992-01.com.example/1'>
<host name='example.org' port='6000'/>
</source>
<target dev='vdb' bus='virtio'/>
</disk>
<controller type='usb' index='0'/> <controller type='usb' index='0'/>
<memballoon model='virtio'/> <memballoon model='virtio'/>
</devices> </devices>
......
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -drive file=/dev/HostVG/QEMUGuest1,if=ide,bus=0,unit=0 \ -no-acpi -boot c -usb -drive file=/dev/HostVG/QEMUGuest1,if=ide,bus=0,unit=0 \
-drive 'file=nbd+tcp://[::1]:6000/bar,if=virtio,format=raw' -net none \ -drive 'file=nbd://[::1]:6000/bar,if=virtio,format=raw' -net none \
-serial none -parallel none -serial none -parallel none
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -drive file=/dev/HostVG/QEMUGuest1,if=ide,bus=0,unit=0 \ -no-acpi -boot c -usb -drive file=/dev/HostVG/QEMUGuest1,if=ide,bus=0,unit=0 \
-drive 'file=nbd+tcp://[::1]:6000,if=virtio,format=raw' -net none \ -drive 'file=nbd://[::1]:6000,if=virtio,format=raw' -net none \
-serial none -parallel none -serial none -parallel none
...@@ -501,6 +501,8 @@ mymain(void) ...@@ -501,6 +501,8 @@ mymain(void)
QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT); QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT);
DO_TEST("disk-drive-network-nbd-unix", DO_TEST("disk-drive-network-nbd-unix",
QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT); QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT);
DO_TEST("disk-drive-network-iscsi",
QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT);
DO_TEST("disk-drive-network-gluster", DO_TEST("disk-drive-network-gluster",
QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT); QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT);
DO_TEST("disk-drive-network-rbd", DO_TEST("disk-drive-network-rbd",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册