From nobody Sun Feb 8 17:42:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584987178; cv=none; d=zohomail.com; s=zohoarc; b=XbUBkV3cXJmbv+Rt+/hchnggZD6z5S9FNPJN9RcRAWk32BAz/KO/XI4F5mjFmihUg0uANlrdRIY7dLlKvMf/wYGX3TDRyVtTFIew6qECSm5El4xwk/25P92RbY4JVrFo6BU5tABW0WyHLI53EIlM7ZTTnmQP0FYh5wy+C5CiXho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584987178; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yr3eksglgyRKMkdJrmDnmdTUpY+o+4gX4oQ7BEnQkdA=; b=PO/WrImZ03SuQwakEV6MxzNcokQqkF5sIUCn+g1PeYlGMuYdaE//am6jqs/dq/SQTY2Afh7WzE64FSX7LBRPopBzeDPo4MRMsUcnNxphSznekOz91zebi0Bd+HX8u7/+wLl6pFW2mbP/kNOmqGmV1HGNRFzzKPSEUNtmdtCHyyM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584987178820931.8239412106526; Mon, 23 Mar 2020 11:12:58 -0700 (PDT) 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-262-uIe7ZEd6No-P8fvoJVNqGg-1; Mon, 23 Mar 2020 14:12:55 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DAA978010CA; Mon, 23 Mar 2020 18:12:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B09BD196AE; Mon, 23 Mar 2020 18:12:49 +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 601E4863A8; Mon, 23 Mar 2020 18:12:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02NICKuJ009545 for ; Mon, 23 Mar 2020 14:12:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id D582491290; Mon, 23 Mar 2020 18:12:20 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A3D58D574 for ; Mon, 23 Mar 2020 18:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584987177; 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=yr3eksglgyRKMkdJrmDnmdTUpY+o+4gX4oQ7BEnQkdA=; b=AIN4TcbmqjqqAJsXKBLOmX4LpehdfbZYnH6dbCwTlFvkax0CP37Rg6MFFLorerO22+M+Oq ljUbBfInxNJEEi5PegNF7tNWNHDUVh+oIKw8mGUTil9kb1PypkPK07RtelLzrRNtSIKkBH L/a9KimCZuvCE9EGJ7JyePm9Yy7cJPk= X-MC-Unique: uIe7ZEd6No-P8fvoJVNqGg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/14] storage: Parse 'nvme' disk source properties from json:{} pseudo-uri Date: Mon, 23 Mar 2020 19:12:04 +0100 Message-Id: <8d4db0d195ef034676a7a532acfc4c7b7f2ae225.1584986997.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.84 on 10.5.11.23 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" Our code allows snapshots of NVMe based disks which means we create overlay file with a 'json:{}' pseudo-uri refering to the NVME device. Our parser code doesn't handle them though. Add the parser and test it via the XML->json->XML round-trip and reference data. Signed-off-by: Peter Krempa --- src/util/virstoragefile.c | 30 ++++++++++++++++++++++++++++++ tests/qemublocktest.c | 5 +++++ tests/virstoragetest.c | 9 +++++++++ 3 files changed, 44 insertions(+) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index fa04ff74e1..d81ed70a97 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3806,6 +3806,35 @@ virStorageSourceParseBackingJSONVxHS(virStorageSourc= ePtr src, } +static int +virStorageSourceParseBackingJSONNVMe(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + g_autoptr(virStorageSourceNVMeDef) nvme =3D g_new0(virStorageSourceNVM= eDef, 1); + const char *device =3D virJSONValueObjectGetString(json, "device"); + + if (!device || virPCIDeviceAddressParse((char *) device, &nvme->pciAdd= r) < 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing or malformed 'device' field of 'nvme' st= orage")); + return -1; + } + + if (virJSONValueObjectGetNumberUlong(json, "namespace", &nvme->namespc= ) < 0 || + nvme->namespc =3D=3D 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing or malformed 'namespace' field of 'nvme'= storage")); + return -1; + } + + src->type =3D VIR_STORAGE_TYPE_NVME; + src->nvme =3D g_steal_pointer(&nvme); + + return 0; +} + + struct virStorageSourceJSONDriverParser { const char *drvname; bool formatdriver; @@ -3837,6 +3866,7 @@ static const struct virStorageSourceJSONDriverParser = jsonParsers[] =3D { {"rbd", false, virStorageSourceParseBackingJSONRBD, 0}, {"raw", true, virStorageSourceParseBackingJSONRaw, 0}, {"vxhs", false, virStorageSourceParseBackingJSONVxHS, 0}, + {"nvme", false, virStorageSourceParseBackingJSONNVMe, 0}, }; diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 8640b72116..124eaea752 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -1096,6 +1096,11 @@ mymain(void) /* type VIR_STORAGE_TYPE_BLOCK is not tested since it parses back to '= file' */ /* type VIR_STORAGE_TYPE_DIR it is a 'format' driver in qemu */ + TEST_JSON_FORMAT(VIR_STORAGE_TYPE_NVME, + "\n" + "
\n" + "\n"); + TEST_JSON_FORMAT_NET("\n" " \n" "\n"); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 209d0c37d3..10d5421150 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1656,6 +1656,15 @@ mymain(void) " \n" "\n", 0); + TEST_BACKING_PARSE("json:{\"file\":{\"driver\": \"nvme\"," + "\"device\": \"0000:01:00.0\"," + "\"namespace\": 1" + "}" + "}", + "\n" + "
\n" + "\n"); + #endif /* WITH_YAJL */ cleanup: --=20 2.24.1