From nobody Sun Feb 8 17:03:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 15809755642571020.7129961902544; Wed, 5 Feb 2020 23:52:44 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-233-7LoirxayOyesBvEppDa5cA-1; Thu, 06 Feb 2020 02:52:40 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0480101FC67; Thu, 6 Feb 2020 07:52:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7D425DA84; Thu, 6 Feb 2020 07:52:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8C25F18089D7; Thu, 6 Feb 2020 07:52:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0167qEKA009932 for ; Thu, 6 Feb 2020 02:52:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2DB6B1001B09; Thu, 6 Feb 2020 07:52:14 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAB101001B07 for ; Thu, 6 Feb 2020 07:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580975563; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rNWFYJIeLL02qG2+BS2oIFMtH1Fi5TO3FKfIeB7w5CA=; b=OWk10Cjq5p8BuemveMV4SfDrYifOdluCmqUByxkOH5DJgucINBz4v0mHtcIzC7d1YDnLJq F6udBBt11ciOsNYYBXhT0YTkRPVJTRm4+Vi1ELT9ULo2f1eDTlic/ejuXMszlC6NzxjUwC d79lxdoEXH6ndbA+x/DFlNah+wfcPSg= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/15] virStorageSourceParseBackingJSON: Allow 'json:' pseudo URIs without 'file' wrapper Date: Thu, 6 Feb 2020 08:51:56 +0100 Message-Id: <2ece964f71f8a9e228180fe100f406f25df4965d.1580975374.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: 7LoirxayOyesBvEppDa5cA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are two possibilities: 1) json:{"file":{"driver":...}} 2) json:{"driver":...} Our code didn't work properly with the second one as it was expecting the 'file' wrapper. Conditionalize the removal to only the situation when the top level doesn't have "driver". Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 41 +++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 565ba08319..ddf837c3b3 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3521,10 +3521,17 @@ virStorageSourceParseBackingJSONRaw(virStorageSourc= ePtr src, const char *jsonstr, int opaque G_GNUC_UNUSED) { - /* There are no interesting attributes in raw driver. - * Treat it as pass-through. - */ - return virStorageSourceParseBackingJSONInternal(src, json, jsonstr); + virJSONValuePtr file; + + /* 'raw' is a format driver so it can have protocol driver children */ + if (!(file =3D virJSONValueObjectGetObject(json, "file"))) { + virReportError(VIR_ERR_INVALID_ARG, + _("JSON backing volume definition '%s' lacks 'file'= object"), + jsonstr); + return -1; + } + + return virStorageSourceParseBackingJSONInternal(src, file, jsonstr); } @@ -3601,18 +3608,10 @@ virStorageSourceParseBackingJSONInternal(virStorage= SourcePtr src, virJSONValuePtr json, const char *jsonstr) { - virJSONValuePtr file; const char *drvname; size_t i; - if (!(file =3D virJSONValueObjectGetObject(json, "file"))) { - virReportError(VIR_ERR_INVALID_ARG, - _("JSON backing volume definition '%s' lacks 'file'= object"), - jsonstr); - return -1; - } - - if (!(drvname =3D virJSONValueObjectGetString(file, "driver"))) { + if (!(drvname =3D virJSONValueObjectGetString(json, "driver"))) { virReportError(VIR_ERR_INVALID_ARG, _("JSON backing volume definition '%s' lacks driver= name"), jsonstr); @@ -3621,7 +3620,7 @@ virStorageSourceParseBackingJSONInternal(virStorageSo= urcePtr src, for (i =3D 0; i < G_N_ELEMENTS(jsonParsers); i++) { if (STREQ(drvname, jsonParsers[i].drvname)) - return jsonParsers[i].func(src, file, jsonstr, jsonParsers[i].= opaque); + return jsonParsers[i].func(src, json, jsonstr, jsonParsers[i].= opaque); } virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3637,6 +3636,7 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr = src, { g_autoptr(virJSONValue) root =3D NULL; g_autoptr(virJSONValue) deflattened =3D NULL; + virJSONValuePtr file =3D NULL; if (!(root =3D virJSONValueFromString(json))) return -1; @@ -3644,7 +3644,18 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr= src, if (!(deflattened =3D virJSONValueObjectDeflatten(root))) return -1; - return virStorageSourceParseBackingJSONInternal(src, deflattened, json= ); + /* There are 2 possible syntaxes: + * 1) json:{"file":{"driver":...}} + * 2) json:{"driver":...} + * Remove the 'file' wrapper object in case 1. + */ + if (!virJSONValueObjectHasKey(deflattened, "driver")) + file =3D virJSONValueObjectGetObject(deflattened, "file"); + + if (!file) + file =3D deflattened; + + return virStorageSourceParseBackingJSONInternal(src, file, json); } --=20 2.24.1