From: John Ferlan <jferlan@redhat.com>
---
src/qemu/qemu_block.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 69 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index dedb92fd5..4e588c724 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -703,6 +703,70 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src)
}
+static virJSONValuePtr
+qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
+{
+ qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
+ const char *protocol = virStorageNetProtocolTypeToString(src->protocol);
+ char *target = NULL;
+ char *lunStr = NULL;
+ char *username = NULL;
+ char *objalias = NULL;
+ char *portal = NULL;
+ unsigned int lun = 0;
+ virJSONValuePtr ret = NULL;
+
+ /* { driver:"iscsi",
+ * transport:"tcp", ("iser" also possible)
+ * portal:"example.com",
+ * target:"iqn.2017-04.com.example:iscsi-disks",
+ * lun:1,
+ * user:"username",
+ * password-secret:"secret-alias",
+ * }
+ */
+
+ if (VIR_STRDUP(target, src->path) < 0)
+ goto cleanup;
+
+ /* Separate the target and lun */
+ if ((lunStr = strchr(target, '/'))) {
+ *(lunStr++) = '\0';
+ if (virStrToLong_ui(lunStr, NULL, 10, &lun) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot parse target for lunStr '%s'"),
+ target);
+ goto cleanup;
+ }
+ }
+
+ /* combine host and port into portal */
+ if (virAsprintf(&portal, "%s:%u", src->hosts[0].name, src->hosts[0].port) < 0)
+ goto cleanup;
+
+ if (src->auth) {
+ username = src->auth->username;
+ objalias = srcPriv->secinfo->s.aes.alias;
+ }
+
+ ignore_value(virJSONValueObjectCreate(&ret,
+ "s:driver", protocol,
+ "s:portal", portal,
+ "s:target", target,
+ "u:lun", lun,
+ "s:transport", "tcp",
+ "S:user", username,
+ "S:password-secret", objalias,
+ NULL));
+ goto cleanup;
+
+ cleanup:
+ VIR_FREE(target);
+ VIR_FREE(portal);
+ return ret;
+}
+
+
/**
* qemuBlockStorageSourceGetBackendProps:
* @src: disk source
@@ -752,10 +816,14 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src)
return NULL;
break;
+ case VIR_STORAGE_NET_PROTOCOL_ISCSI:
+ if (!(fileprops = qemuBlockStorageSourceGetISCSIProps(src)))
+ return NULL;
+ break;
+
case VIR_STORAGE_NET_PROTOCOL_NBD:
case VIR_STORAGE_NET_PROTOCOL_RBD:
case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
- case VIR_STORAGE_NET_PROTOCOL_ISCSI:
case VIR_STORAGE_NET_PROTOCOL_SSH:
case VIR_STORAGE_NET_PROTOCOL_NONE:
case VIR_STORAGE_NET_PROTOCOL_LAST:
--
2.14.3
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Fri, Nov 03, 2017 at 03:29:23PM +0100, Peter Krempa wrote:
>From: John Ferlan <jferlan@redhat.com>
>
>---
>+static virJSONValuePtr
>+qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
>+{
[...]
>+ if (VIR_STRDUP(target, src->path) < 0)
>+ goto cleanup;
>+
>+ /* Separate the target and lun */
>+ if ((lunStr = strchr(target, '/'))) {
>+ *(lunStr++) = '\0';
>+ if (virStrToLong_ui(lunStr, NULL, 10, &lun) < 0) {
>+ virReportError(VIR_ERR_INTERNAL_ERROR,
>+ _("cannot parse target for lunStr '%s'"),
>+ target);
>+ goto cleanup;
>+ }
>+ }
>+
>+ /* combine host and port into portal */
>+ if (virAsprintf(&portal, "%s:%u", src->hosts[0].name, src->hosts[0].port) < 0)
>+ goto cleanup;
Can src->hosts[0].name possibly be a literal IPv6 address?
Jan
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Sun, Nov 05, 2017 at 16:03:25 +0100, Ján Tomko wrote:
> On Fri, Nov 03, 2017 at 03:29:23PM +0100, Peter Krempa wrote:
> > From: John Ferlan <jferlan@redhat.com>
> >
> > ---
> > +static virJSONValuePtr
> > +qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
> > +{
>
> [...]
>
> > + if (VIR_STRDUP(target, src->path) < 0)
> > + goto cleanup;
> > +
> > + /* Separate the target and lun */
> > + if ((lunStr = strchr(target, '/'))) {
> > + *(lunStr++) = '\0';
> > + if (virStrToLong_ui(lunStr, NULL, 10, &lun) < 0) {
> > + virReportError(VIR_ERR_INTERNAL_ERROR,
> > + _("cannot parse target for lunStr '%s'"),
> > + target);
> > + goto cleanup;
> > + }
> > + }
> > +
> > + /* combine host and port into portal */
> > + if (virAsprintf(&portal, "%s:%u", src->hosts[0].name, src->hosts[0].port) < 0)
> > + goto cleanup;
>
> Can src->hosts[0].name possibly be a literal IPv6 address?
Yes, you are right. How about the following diff squashed in?
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index ffe2892ab..428c0b465 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -742,8 +742,15 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
}
/* combine host and port into portal */
- if (virAsprintf(&portal, "%s:%u", src->hosts[0].name, src->hosts[0].port) < 0)
- goto cleanup;
+ if (virSocketAddrNumericFamily(src->hosts[0].name) == AF_INET6) {
+ if (virAsprintf(&portal, "[%s]:%u",
+ src->hosts[0].name, src->hosts[0].port) < 0)
+ goto cleanup;
+ } else {
+ if (virAsprintf(&portal, "%s:%u",
+ src->hosts[0].name, src->hosts[0].port) < 0)
+ goto cleanup;
+ }
if (src->auth) {
username = src->auth->username;
Also our parser is buggy. I'll send patches separately.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Tue, Nov 07, 2017 at 04:04:02PM +0100, Peter Krempa wrote:
>On Sun, Nov 05, 2017 at 16:03:25 +0100, Ján Tomko wrote:
>> On Fri, Nov 03, 2017 at 03:29:23PM +0100, Peter Krempa wrote:
>> > From: John Ferlan <jferlan@redhat.com>
>> >
>> > ---
>> > +static virJSONValuePtr
>> > +qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
>> > +{
>>
>> [...]
>>
>> > + if (VIR_STRDUP(target, src->path) < 0)
>> > + goto cleanup;
>> > +
>> > + /* Separate the target and lun */
>> > + if ((lunStr = strchr(target, '/'))) {
>> > + *(lunStr++) = '\0';
>> > + if (virStrToLong_ui(lunStr, NULL, 10, &lun) < 0) {
>> > + virReportError(VIR_ERR_INTERNAL_ERROR,
>> > + _("cannot parse target for lunStr '%s'"),
>> > + target);
>> > + goto cleanup;
>> > + }
>> > + }
>> > +
>> > + /* combine host and port into portal */
>> > + if (virAsprintf(&portal, "%s:%u", src->hosts[0].name, src->hosts[0].port) < 0)
>> > + goto cleanup;
>>
>> Can src->hosts[0].name possibly be a literal IPv6 address?
>
>Yes, you are right. How about the following diff squashed in?
>
>diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
>index ffe2892ab..428c0b465 100644
>--- a/src/qemu/qemu_block.c
>+++ b/src/qemu/qemu_block.c
>@@ -742,8 +742,15 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
> }
>
> /* combine host and port into portal */
>- if (virAsprintf(&portal, "%s:%u", src->hosts[0].name, src->hosts[0].port) < 0)
>- goto cleanup;
>+ if (virSocketAddrNumericFamily(src->hosts[0].name) == AF_INET6) {
>+ if (virAsprintf(&portal, "[%s]:%u",
>+ src->hosts[0].name, src->hosts[0].port) < 0)
>+ goto cleanup;
>+ } else {
>+ if (virAsprintf(&portal, "%s:%u",
>+ src->hosts[0].name, src->hosts[0].port) < 0)
>+ goto cleanup;
>+ }
>
> if (src->auth) {
> username = src->auth->username;
>
ACK
>Also our parser is buggy. I'll send patches separately.
Thanks, patches are welcome.
Jan
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2025 Red Hat, Inc.