Skip to contentSkip to conversation

Parse 'filename' option for RBD/iSCSI

PATCH Superseded Jeff Cody 1 participant 3 messages Jun 12, 2017 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jeff Cody

author
#0 lore raw

cover Parse 'filename' option for RBD/iSCSI

We need to be able to parse the 'filename' option for rbd and iscsi, because there may exist images in the wild that have json backing files, that specify the filename argument.

Jeff Cody (2):
block/rbd: enable filename option and parsing
block/iscsi: enable filename option and parsing

 block/iscsi.c | 19 ++++++++++++++++++-
 block/rbd.c   | 19 ++++++++++++++++++-
 2 files changed, 36 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH 1/2 block/rbd: enable filename option and parsing

When enabling option parsing and blockdev-add for rbd, we removed the 'filename' option. Unfortunately, this was a bit optimistic, as previous versions of QEMU allowed the use of the option in backing filenames via json. This means that without parsing this option, we cannot open existing images that used to work fine.

See bug: https://bugzilla.redhat.com/show_bug.cgi?id=1457088

---
 block/rbd.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
block/rbd.c +18 -1
index e551639..cbc0b85 100644
@@ -340,6 +340,10 @@ static QemuOptsList runtime_opts = {
             .type = QEMU_OPT_STRING,
             .help = "Legacy rados key/value option parameters",
         },
+        {
+            .name = "filename",
+            .type = QEMU_OPT_STRING,
+        },
         { /* end of list */ }
     },
 };
@@ -541,12 +545,24 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
 {
     BDRVRBDState *s = bs->opaque;
     const char *pool, *snap, *conf, *user, *image_name, *keypairs;
-    const char *secretid;
+    const char *secretid, *filename;
     QemuOpts *opts;
     Error *local_err = NULL;
     char *mon_host = NULL;
     int r;
 
+    /* If we are given a filename, parse the filename, with precedence given to
+     * filename encoded options */
+    filename = qdict_get_try_str(options, "filename");
+    if (filename) {
+        qemu_rbd_parse_filename(filename, options, &local_err);
+        if (local_err) {
+            r = -EINVAL;
+            error_propagate(errp, local_err);
+            goto exit;
+        }
+    }
+
     opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
     qemu_opts_absorb_qdict(opts, options, &local_err);
     if (local_err) {
@@ -665,6 +681,7 @@ failed_shutdown:
 failed_opts:
     qemu_opts_del(opts);
     g_free(mon_host);
+exit:
     return r;
 }
 
Signature · 1 line
2.9.3
author
#2 lore raw

PATCH 2/2 block/iscsi: enable filename option and parsing

In reply to Jeff Cody

When enabling option parsing and blockdev-add for iscsi, we removed the 'filename' option. Unfortunately, this was a bit optimistic, as previous versions of QEMU allowed the use of the option in backing filenames via json. This means that without parsing this option, we cannot open existing images that used to work fine.

See bug: https://bugzilla.redhat.com/show_bug.cgi?id=1457088

---
 block/iscsi.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
block/iscsi.c +18 -1
index 5daa201..ba50e76 100644
@@ -1732,6 +1732,10 @@ static QemuOptsList runtime_opts = {
             .name = "timeout",
             .type = QEMU_OPT_NUMBER,
         },
+        {
+            .name = "filename",
+            .type = QEMU_OPT_STRING,
+        },
         { /* end of list */ }
     },
 };
@@ -1747,12 +1751,24 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
     char *initiator_name = NULL;
     QemuOpts *opts;
     Error *local_err = NULL;
-    const char *transport_name, *portal, *target;
+    const char *transport_name, *portal, *target, *filename;
 #if LIBISCSI_API_VERSION >= (20160603)
     enum iscsi_transport_type transport;
 #endif
     int i, ret = 0, timeout = 0, lun;
 
+    /* If we are given a filename, parse the filename, with precedence given to
+     * filename encoded options */
+    filename = qdict_get_try_str(options, "filename");
+    if (filename) {
+        iscsi_parse_filename(filename, options, &local_err);
+        if (local_err) {
+            ret = -EINVAL;
+            error_propagate(errp, local_err);
+            goto exit;
+        }
+    }
+
     opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
     qemu_opts_absorb_qdict(opts, options, &local_err);
     if (local_err) {
@@ -1967,6 +1983,7 @@ out:
         }
         memset(iscsilun, 0, sizeof(IscsiLun));
     }
+exit:
     return ret;
 }
 
Signature · 1 line
2.9.3