From patchwork Tue Sep 11 05:15:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 10595045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFB0E1575 for ; Tue, 11 Sep 2018 05:20:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0EED292D8 for ; Tue, 11 Sep 2018 05:20:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C1B8292DB; Tue, 11 Sep 2018 05:20:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2FD46292B6 for ; Tue, 11 Sep 2018 05:20:27 +0000 (UTC) Received: from localhost ([::1]:55445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzb60-0005uz-Dh for patchwork-qemu-devel@patchwork.kernel.org; Tue, 11 Sep 2018 01:20:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzb3r-0004qH-8R for qemu-devel@nongnu.org; Tue, 11 Sep 2018 01:18:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzb1q-0004bN-65 for qemu-devel@nongnu.org; Tue, 11 Sep 2018 01:15:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60948) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fzb1p-0004Yk-2r; Tue, 11 Sep 2018 01:15:57 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6DFBB30832EA; Tue, 11 Sep 2018 05:15:56 +0000 (UTC) Received: from localhost (ovpn-116-183.phx2.redhat.com [10.3.116.183]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB628600D1; Tue, 11 Sep 2018 05:15:52 +0000 (UTC) From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 11 Sep 2018 01:15:48 -0400 Message-Id: <78d2f47b07325fce34a03b115159830f662b7f90.1536642773.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 11 Sep 2018 05:15:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] block/rbd: pull out qemu_rbd_convert_options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jsnow@redhat.com, qemu-stable@nongnu.org, qemu-block@nongnu.org, armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Code movement to pull the conversion from Qdict to BlockdevOptionsRbd into a helper function. Signed-off-by: Jeff Cody Reviewed-by: Eric Blake Reviewed-by: John Snow --- block/rbd.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index ca8e5bbace..a8e79d01d2 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -655,12 +655,34 @@ failed_opts: return r; } +static int qemu_rbd_convert_options(BlockDriverState *bs, QDict *options, + BlockdevOptionsRbd **opts, Error **errp) +{ + Visitor *v; + Error *local_err = NULL; + + /* Convert the remaining options into a QAPI object */ + v = qobject_input_visitor_new_flat_confused(options, errp); + if (!v) { + return -EINVAL; + } + + visit_type_BlockdevOptionsRbd(v, NULL, opts, &local_err); + visit_free(v); + + if (local_err) { + error_propagate(errp, local_err); + return -EINVAL; + } + + return 0; +} + static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVRBDState *s = bs->opaque; BlockdevOptionsRbd *opts = NULL; - Visitor *v; const QDictEntry *e; Error *local_err = NULL; char *keypairs, *secretid; @@ -676,19 +698,9 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, qdict_del(options, "password-secret"); } - /* Convert the remaining options into a QAPI object */ - v = qobject_input_visitor_new_flat_confused(options, errp); - if (!v) { - r = -EINVAL; - goto out; - } - - visit_type_BlockdevOptionsRbd(v, NULL, &opts, &local_err); - visit_free(v); - + r = qemu_rbd_convert_options(bs, options, &opts, &local_err); if (local_err) { error_propagate(errp, local_err); - r = -EINVAL; goto out; } From patchwork Tue Sep 11 05:15:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 10595043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01C0D109C for ; Tue, 11 Sep 2018 05:20:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2051292DC for ; Tue, 11 Sep 2018 05:20:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C698A2929E; Tue, 11 Sep 2018 05:20:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5B7132929E for ; Tue, 11 Sep 2018 05:20:26 +0000 (UTC) Received: from localhost ([::1]:55452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzb64-0006dj-8x for patchwork-qemu-devel@patchwork.kernel.org; Tue, 11 Sep 2018 01:20:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzb3n-0004Tx-82 for qemu-devel@nongnu.org; Tue, 11 Sep 2018 01:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzb1t-0004hw-Ry for qemu-devel@nongnu.org; Tue, 11 Sep 2018 01:16:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42258) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fzb1s-0004eD-Kg; Tue, 11 Sep 2018 01:16:00 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AB1EC058CA6; Tue, 11 Sep 2018 05:15:59 +0000 (UTC) Received: from localhost (ovpn-116-183.phx2.redhat.com [10.3.116.183]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23B7120165D7; Tue, 11 Sep 2018 05:15:57 +0000 (UTC) From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 11 Sep 2018 01:15:49 -0400 Message-Id: <570e8585c94d6f1bd7406ce5d35f68a82b6ea28c.1536642773.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 11 Sep 2018 05:15:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] block/rbd: Attempt to parse legacy filenames X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jsnow@redhat.com, qemu-stable@nongnu.org, qemu-block@nongnu.org, armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When we converted rbd to get rid of the older key/value-centric encoding format, we broke compatibility with image files with backing file strings encoded in the old format. This leaves a bit of an ugly conundrum, and a hacky solution. If the initial attempt to parse the "proper" options fails, it assumes that we may have an older key/value encoded filename. Fall back to attempting to parse the filename, and extract the required options from it. If that fails, pass along the original error message. This approach has a potential drawback: if for some reason there are some options supplied the new way, and some the old way, we may not catch all the old options if they are not required options (since it won't cause the initial failure). Signed-off-by: Jeff Cody --- block/rbd.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index a8e79d01d2..bce86b8bde 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -685,7 +685,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, BlockdevOptionsRbd *opts = NULL; const QDictEntry *e; Error *local_err = NULL; - char *keypairs, *secretid; + char *keypairs, *secretid, *filename; int r; keypairs = g_strdup(qdict_get_try_str(options, "=keyvalue-pairs")); @@ -700,8 +700,32 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, r = qemu_rbd_convert_options(bs, options, &opts, &local_err); if (local_err) { - error_propagate(errp, local_err); - goto out; + /* If the initial attempt to convert and process the options failed, + * we may be attempting to open an image file that has the rbd options + * specified in the older format consisting of all key/value pairs + * encoded in the filename. Go ahead and attempt to parse the + * filename, and see if we can pull out the required options */ + Error *parse_err = NULL; + + filename = g_strdup(qdict_get_try_str(options, "filename")); + qdict_del(options, "filename"); + + qemu_rbd_parse_filename(filename, options, NULL); + + g_free(keypairs); + keypairs = g_strdup(qdict_get_try_str(options, "=keyvalue-pairs")); + if (keypairs) { + qdict_del(options, "=keyvalue-pairs"); + } + + r = qemu_rbd_convert_options(bs, options, &opts, &parse_err); + if (parse_err) { + /* if the second attempt failed, pass along the original error + * message for the current format */ + error_propagate(errp, local_err); + error_free(parse_err); + goto out; + } } /* Remove the processed options from the QDict (the visitor processes