Skip to contentSkip to conversation

iscsi: Fix iscsi_create

PATCH In review Fam Zheng 3 participants 5 messages Apr 10, 2017 – Apr 11, 2017 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 iscsi: Fix iscsi_create

Since d5895fcb (iscsi: Split URL into individual options), creating qcow2 image on an iscsi LUN fails:

qemu-img create -f qcow2 iscsi://$SERVER/$IQN/0 1G
qemu-img: iscsi://$SERVER/$IQN/0: Could not create image: Invalid
argument

The problem is iscsi_open now expects that transport_name, portal and target are already parsed into structured options by iscsi_parse_filename, but it is not called in iscsi_create.

---
 block/iscsi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
block/iscsi.c +8 -1
index 716e74a..07596b5 100644
@@ -2092,6 +2092,7 @@ static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
     BlockDriverState *bs;
     IscsiLun *iscsilun = NULL;
     QDict *bs_options;
+    Error *local_err = NULL;
 
     bs = bdrv_new();
 
@@ -2103,7 +2104,13 @@ static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
 
     bs_options = qdict_new();
     qdict_put(bs_options, "filename", qstring_from_str(filename));
-    ret = iscsi_open(bs, bs_options, 0, NULL);
+    iscsi_parse_filename(filename, bs_options, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        ret = -EINVAL;
+    } else {
+        ret = iscsi_open(bs, bs_options, 0, NULL);
+    }
     QDECREF(bs_options);
 
     if (ret != 0) {
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Fam Zheng

Since d5895fcb (iscsi: Split URL into individual options), creating qcow2 image on an iscsi LUN fails:

qemu-img create -f qcow2 iscsi://$SERVER/$IQN/0 1G
qemu-img: iscsi://$SERVER/$IQN/0: Could not create image: Invalid
argument

Quoted 9 lines

The problem is iscsi_open now expects that transport_name, portal and target are already parsed into structured options by iscsi_parse_filename, but it is not called in iscsi_create.

---
 block/iscsi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#2 lore raw
In reply to Fam Zheng
Quoted 29 lines · Fam Zheng

Since d5895fcb (iscsi: Split URL into individual options), creating qcow2 image on an iscsi LUN fails:

qemu-img create -f qcow2 iscsi://$SERVER/$IQN/0 1G
qemu-img: iscsi://$SERVER/$IQN/0: Could not create image: Invalid
argument

The problem is iscsi_open now expects that transport_name, portal and target are already parsed into structured options by iscsi_parse_filename, but it is not called in iscsi_create.

---
 block/iscsi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
block/iscsi.c +1 -0
index 716e74a..07596b5 100644
@@ -2092,6 +2092,7 @@ static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
     BlockDriverState *bs;
     IscsiLun *iscsilun = NULL;
     QDict *bs_options;
+    Error *local_err = NULL;
 
     bs = bdrv_new();
 

block/iscsi.c static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp) · line 2106

Quoted 3 lines
block/iscsi.c +0 -0
@@ -2103,7 +2104,13 @@ static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
 
     bs_options = qdict_new();
     qdict_put(bs_options, "filename", qstring_from_str(filename));

Doesn't the below change make this qdict_put() superfluous?

Max

Quoted 12 lines
block/iscsi.c +7 -1
-    ret = iscsi_open(bs, bs_options, 0, NULL);
+    iscsi_parse_filename(filename, bs_options, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        ret = -EINVAL;
+    } else {
+        ret = iscsi_open(bs, bs_options, 0, NULL);
+    }
     QDECREF(bs_options);
 
     if (ret != 0) {
author
#3 lore raw
Quoted 4 lines · Max Reitz
Quoted 2 lines
     bs_options = qdict_new();
     qdict_put(bs_options, "filename", qstring_from_str(filename));

Doesn't the below change make this qdict_put() superfluous?

You are right, bdrv_iscsi.bdrv_needs_filename is false.

Fam

#4 lore raw
In reply to Fam Zheng
Quoted 7 lines · Fam Zheng

Since d5895fcb (iscsi: Split URL into individual options), creating qcow2 image on an iscsi LUN fails:

qemu-img create -f qcow2 iscsi://$SERVER/$IQN/0 1G
qemu-img: iscsi://$SERVER/$IQN/0: Could not create image: Invalid
argument

Quoted 8 lines

The problem is iscsi_open now expects that transport_name, portal and target are already parsed into structured options by iscsi_parse_filename, but it is not called in iscsi_create.

---
 block/iscsi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Thanks, dropped the qdict_put() for "filename" and applied to my block branch:

https://github.com/XanClic/qemu/commits/block

Max