From nobody Sat Apr 12 15:46:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537848553073370.4393001683683; Mon, 24 Sep 2018 21:09:13 -0700 (PDT) Received: from localhost ([::1]:50662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4eeu-0000t3-0Y for importer@patchew.org; Tue, 25 Sep 2018 00:09:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4ea7-0005pz-Uf for qemu-devel@nongnu.org; Tue, 25 Sep 2018 00:04:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4eQr-0005j6-Ew for qemu-devel@nongnu.org; Mon, 24 Sep 2018 23:54:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58798) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g4eQo-0005h2-0U; Mon, 24 Sep 2018 23:54:38 -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 3D7F7356E5; Tue, 25 Sep 2018 03:54:37 +0000 (UTC) Received: from localhost (ovpn-116-254.phx2.redhat.com [10.3.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0767E19CBD; Tue, 25 Sep 2018 03:54:36 +0000 (UTC) From: Jeff Cody To: qemu-block@nongnu.org Date: Mon, 24 Sep 2018 23:54:31 -0400 Message-Id: <20180925035434.215114-3-jcody@redhat.com> In-Reply-To: <20180925035434.215114-1-jcody@redhat.com> References: <20180925035434.215114-1-jcody@redhat.com> 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.30]); Tue, 25 Sep 2018 03:54:37 +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] [PULL v2 2/5] 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: Kevin Wolf , peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. We do not support mixed modern usage alongside legacy keyvalue pair usage. A deprecation warning has been added, although care should be taken when actually deprecating since the impact is not limited to commandline or qapi usage, but also opening existing images. Reviewed-by: Eric Blake Signed-off-by: Jeff Cody Message-id: 15b332e5432ad069441f7275a46080f465d789a0.1536704901.git.jcody@r= edhat.com Signed-off-by: Jeff Cody --- block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index b199450f9f..014c68d629 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -678,6 +678,33 @@ static int qemu_rbd_convert_options(QDict *options, Bl= ockdevOptionsRbd **opts, return 0; } =20 +static int qemu_rbd_attempt_legacy_options(QDict *options, + BlockdevOptionsRbd **opts, + char **keypairs) +{ + char *filename; + int r; + + filename =3D g_strdup(qdict_get_try_str(options, "filename")); + if (!filename) { + return -EINVAL; + } + qdict_del(options, "filename"); + + qemu_rbd_parse_filename(filename, options, NULL); + + /* keypairs freed by caller */ + *keypairs =3D g_strdup(qdict_get_try_str(options, "=3Dkeyvalue-pairs")= ); + if (*keypairs) { + qdict_del(options, "=3Dkeyvalue-pairs"); + } + + r =3D qemu_rbd_convert_options(options, opts, NULL); + + g_free(filename); + return r; +} + static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { @@ -700,8 +727,31 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *= options, int flags, =20 r =3D qemu_rbd_convert_options(options, &opts, &local_err); if (local_err) { - error_propagate(errp, local_err); - goto out; + /* If keypairs are present, that means some options are present in + * the modern option format. Don't attempt to parse legacy option + * formats, as we won't support mixed usage. */ + if (keypairs) { + error_propagate(errp, local_err); + goto out; + } + + /* If the initial attempt to convert and process the options faile= d, + * we may be attempting to open an image file that has the rbd opt= ions + * 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. */ + r =3D qemu_rbd_attempt_legacy_options(options, &opts, &keypairs); + if (r < 0) { + /* Propagate the original error, not the legacy parsing fallba= ck + * error, as the latter was just a best-effort attempt. */ + error_propagate(errp, local_err); + goto out; + } + /* Take care whenever deciding to actually deprecate; once this ab= ility + * is removed, we will not be able to open any images with legacy-= styled + * backing image strings. */ + error_report("RBD options encoded in the filename as keyvalue pair= s " + "is deprecated"); } =20 /* Remove the processed options from the QDict (the visitor processes --=20 2.17.1