Blame SOURCES/kvm-block-rbd-Attempt-to-parse-legacy-filenames.patch

357786
From ba592010c82c1302c611f6023d4abda24ee3b689 Mon Sep 17 00:00:00 2001
357786
From: Jeffrey Cody <jcody@redhat.com>
357786
Date: Wed, 12 Sep 2018 13:45:43 +0200
357786
Subject: [PATCH 04/49] block/rbd: Attempt to parse legacy filenames
357786
357786
RH-Author: Jeffrey Cody <jcody@redhat.com>
357786
Message-id: <819d451b971d87d47d5bc73feaf20be5bf42e6ef.1536759805.git.jcody@redhat.com>
357786
Patchwork-id: 82140
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 2/3] block/rbd: Attempt to parse legacy filenames
357786
Bugzilla: 1610605
357786
RH-Acked-by: Eric Blake <eblake@redhat.com>
357786
RH-Acked-by: John Snow <jsnow@redhat.com>
357786
RH-Acked-by: Fam Zheng <famz@redhat.com>
357786
357786
When we converted rbd to get rid of the older key/value-centric
357786
encoding format, we broke compatibility with image files with backing
357786
file strings encoded in the old format.
357786
357786
This leaves a bit of an ugly conundrum, and a hacky solution.
357786
357786
If the initial attempt to parse the "proper" options fails, it assumes
357786
that we may have an older key/value encoded filename.  Fall back to
357786
attempting to parse the filename, and extract the required options from
357786
it.  If that fails, pass along the original error message.
357786
357786
We do not support mixed modern usage alongside legacy keyvalue pair
357786
usage.
357786
357786
A deprecation warning has been added, although care should be taken
357786
when actually deprecating since the impact is not limited to
357786
commandline or qapi usage, but also opening existing images.
357786
357786
Reviewed-by: Eric Blake <eblake@redhat.com>
357786
Signed-off-by: Jeff Cody <jcody@redhat.com>
357786
Message-id: 15b332e5432ad069441f7275a46080f465d789a0.1536704901.git.jcody@redhat.com
357786
Signed-off-by: Jeff Cody <jcody@redhat.com>
357786
(cherry picked from commit 866543123c3cd190c44b4caf7c9ed82844c0bcc6)
357786
Signed-off-by: Jeff Cody <jcody@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 block/rbd.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
357786
 1 file changed, 51 insertions(+), 2 deletions(-)
357786
357786
diff --git a/block/rbd.c b/block/rbd.c
357786
index 1e4d339..8f81fbc 100644
357786
--- a/block/rbd.c
357786
+++ b/block/rbd.c
357786
@@ -671,6 +671,33 @@ static int qemu_rbd_convert_options(QDict *options, BlockdevOptionsRbd **opts,
357786
     return 0;
357786
 }
357786
 
357786
+static int qemu_rbd_attempt_legacy_options(QDict *options,
357786
+                                           BlockdevOptionsRbd **opts,
357786
+                                           char **keypairs)
357786
+{
357786
+    char *filename;
357786
+    int r;
357786
+
357786
+    filename = g_strdup(qdict_get_try_str(options, "filename"));
357786
+    if (!filename) {
357786
+        return -EINVAL;
357786
+    }
357786
+    qdict_del(options, "filename");
357786
+
357786
+    qemu_rbd_parse_filename(filename, options, NULL);
357786
+
357786
+    /* keypairs freed by caller */
357786
+    *keypairs = g_strdup(qdict_get_try_str(options, "=keyvalue-pairs"));
357786
+    if (*keypairs) {
357786
+        qdict_del(options, "=keyvalue-pairs");
357786
+    }
357786
+
357786
+    r = qemu_rbd_convert_options(options, opts, NULL);
357786
+
357786
+    g_free(filename);
357786
+    return r;
357786
+}
357786
+
357786
 static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
357786
                          Error **errp)
357786
 {
357786
@@ -693,8 +720,30 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
357786
 
357786
     r = qemu_rbd_convert_options(options, &opts, &local_err);
357786
     if (local_err) {
357786
-        error_propagate(errp, local_err);
357786
-        goto out;
357786
+        /* If keypairs are present, that means some options are present in
357786
+         * the modern option format.  Don't attempt to parse legacy option
357786
+         * formats, as we won't support mixed usage. */
357786
+        if (keypairs) {
357786
+            error_propagate(errp, local_err);
357786
+            goto out;
357786
+        }
357786
+
357786
+        /* If the initial attempt to convert and process the options failed,
357786
+         * we may be attempting to open an image file that has the rbd options
357786
+         * specified in the older format consisting of all key/value pairs
357786
+         * encoded in the filename.  Go ahead and attempt to parse the
357786
+         * filename, and see if we can pull out the required options. */
357786
+        r = qemu_rbd_attempt_legacy_options(options, &opts, &keypairs);
357786
+        if (r < 0) {
357786
+            error_propagate(errp, local_err);
357786
+            goto out;
357786
+        }
357786
+        /* Take care whenever deciding to actually deprecate; once this ability
357786
+         * is removed, we will not be able to open any images with legacy-styled
357786
+         * backing image strings. */
357786
+        error_report("RBD options encoded in the filename as keyvalue pairs "
357786
+                     "is deprecated.  Future versions may cease to parse "
357786
+                     "these options in the future.");
357786
     }
357786
 
357786
     /* Remove the processed options from the QDict (the visitor processes
357786
-- 
357786
1.8.3.1
357786