[libvirt] [PATCH v2 1/6] qemu: add support for libiscsi

2013-03-21 Thread Paolo Bonzini
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: Paolo Bonzini pbonz...@redhat.com
---
 docs/formatdomain.html.in  | 11 +++--
 src/qemu/qemu_command.c| 57 +-
 tests/qemuargv2xmltest.c   |  1 +
 .../qemuxml2argv-disk-drive-network-gluster.args   |  2 +-
 .../qemuxml2argv-disk-drive-network-iscsi.args |  1 +
 .../qemuxml2argv-disk-drive-network-iscsi.xml  |  7 +++
 ...ml2argv-disk-drive-network-nbd-ipv6-export.args |  2 +-
 .../qemuxml2argv-disk-drive-network-nbd-ipv6.args  |  2 +-
 tests/qemuxml2argvtest.c   |  2 +
 9 files changed, 76 insertions(+), 9 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi.args

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index e4ed3f7..f17b808 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1446,10 +1446,13 @@
 are nbd, iscsi, rbd, sheepdog or gluster.  If the
 codeprotocol/code attribute is rbd, sheepdog or gluster, an
 additional attribute codename/code is mandatory to specify which
-volume/image will be used; for nbd it is optional.  When the disk
-codetype/code is network, the codesource/code may have zero
-or more codehost/code sub-elements used to specify the hosts
-to connect.
+volume/image will be used; for nbd it is optional.  For iscsi,
+the codename/code attribute may include a logical unit number,
+separated from the target's name by a slash (for example,
+codeiqn.1992-01.com.example/1/code); the default LUN is zero.
+When the disk codetype/code is network, the codesource/code
+may have zero or more codehost/code sub-elements used to
+specify the hosts to connect.
 span class=sinceSince 0.0.3; codetype='dir'/code since
 0.7.5; codetype='network'/code since
 0.8.7; codeprotocol='iscsi'/code since 1.0.4/spanbr/
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8626b62..4774650 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2391,6 +2391,31 @@ qemuParseGlusterString(virDomainDiskDefPtr def)
 }
 
 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
 qemuParseNBDString(virDomainDiskDefPtr disk)
 {
 virDomainDiskHostDefPtr h = NULL;
@@ -2484,8 +2509,14 @@ qemuBuildDriveURIString(virDomainDiskDefPtr disk, 
virBufferPtr opt,
 virBufferAddLit(opt, file=);
 transp = 
virDomainDiskProtocolTransportTypeToString(disk-hosts-transport);
 
-if (virAsprintf(tmpscheme, %s+%s, scheme, transp)  0)
-goto no_memory;
+if (disk-hosts-transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) {
+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)
 goto no_memory;
@@ -2531,6 +2562,12 @@ qemuBuildGlusterString(virDomainDiskDefPtr disk, 
virBufferPtr opt)
 #define QEMU_DEFAULT_NBD_PORT 10809
 
 static int
+qemuBuildISCSIString(virDomainDiskDefPtr disk, virBufferPtr opt)
+{
+return qemuBuildDriveURIString(disk, opt, iscsi);
+}
+
+static int
 qemuBuildNBDString(virDomainDiskDefPtr disk, virBufferPtr opt)
 {
 const char *transp;
@@ -2713,6 +2750,11 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
 goto error;
 virBufferAddChar(opt, ',');
 break;
+case VIR_DOMAIN_DISK_PROTOCOL_ISCSI:
+if (qemuBuildISCSIString(disk, opt)  0)
+goto error;
+virBufferAddChar(opt, ',');
+break;
 
 case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
 if (disk-nhosts == 0) {
@@ -7909,6 +7951,12 @@ 

Re: [libvirt] [PATCH v2 1/6] qemu: add support for libiscsi

2013-03-21 Thread Osier Yang

On 2013年03月21日 19:53, Paolo Bonzini wrote:

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: Paolo Bonzinipbonz...@redhat.com
---
  docs/formatdomain.html.in  | 11 +++--
  src/qemu/qemu_command.c| 57 +-
  tests/qemuargv2xmltest.c   |  1 +
  .../qemuxml2argv-disk-drive-network-gluster.args   |  2 +-
  .../qemuxml2argv-disk-drive-network-iscsi.args |  1 +
  .../qemuxml2argv-disk-drive-network-iscsi.xml  |  7 +++
  ...ml2argv-disk-drive-network-nbd-ipv6-export.args |  2 +-
  .../qemuxml2argv-disk-drive-network-nbd-ipv6.args  |  2 +-
  tests/qemuxml2argvtest.c   |  2 +
  9 files changed, 76 insertions(+), 9 deletions(-)
  create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-iscsi.args

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index e4ed3f7..f17b808 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1446,10 +1446,13 @@
  are nbd, iscsi, rbd, sheepdog or gluster.  If the
  codeprotocol/code  attribute is rbd, sheepdog or gluster, an
  additional attributecodename/code  is mandatory to specify which
-volume/image will be used; for nbd it is optional.  When the disk
-codetype/code  is network, thecodesource/code  may have zero
-or morecodehost/code  sub-elements used to specify the hosts
-to connect.
+volume/image will be used; for nbd it is optional.  For iscsi,
+thecodename/code  attribute may include a logical unit number,
+separated from the target's name by a slash (for example,
+codeiqn.1992-01.com.example/1/code); the default LUN is zero.
+When the diskcodetype/code  is network, thecodesource/code
+may have zero or morecodehost/code  sub-elements used to
+specify the hosts to connect.
  span class=sinceSince 0.0.3;codetype='dir'/code  since
  0.7.5;codetype='network'/code  since
  0.8.7;codeprotocol='iscsi'/code  since 1.0.4/spanbr/
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8626b62..4774650 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2391,6 +2391,31 @@ qemuParseGlusterString(virDomainDiskDefPtr def)
  }

  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) {


Hm, we might need to change the helpers like virStrToLong_ui to accept
a NULL 4th argument to avoid the useless (lun here) variable. But
it doesn't relate with this patch.

Just small changes for the new logical unit, previous ACK stands.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list