|
|
a41c76 |
From 52f32252c985693be402c5a1fba79d21807a53cb Mon Sep 17 00:00:00 2001
|
|
|
a41c76 |
Message-Id: <52f32252c985693be402c5a1fba79d21807a53cb@dist-git>
|
|
|
a41c76 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
Date: Tue, 24 Mar 2020 16:26:08 +0100
|
|
|
a41c76 |
Subject: [PATCH] storage: Parse 'nvme' disk source properties from json:{}
|
|
|
a41c76 |
pseudo-uri
|
|
|
a41c76 |
MIME-Version: 1.0
|
|
|
a41c76 |
Content-Type: text/plain; charset=UTF-8
|
|
|
a41c76 |
Content-Transfer-Encoding: 8bit
|
|
|
a41c76 |
|
|
|
a41c76 |
Our code allows snapshots of NVMe based disks which means we create
|
|
|
a41c76 |
overlay file with a 'json:{}' pseudo-uri refering to the NVME device.
|
|
|
a41c76 |
Our parser code doesn't handle them though. Add the parser and test it
|
|
|
a41c76 |
via the XML->json->XML round-trip and reference data.
|
|
|
a41c76 |
|
|
|
a41c76 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
a41c76 |
(cherry picked from commit 1b84dd190c16695710a714305517ed24afdd4573)
|
|
|
a41c76 |
|
|
|
a41c76 |
https://bugzilla.redhat.com/show_bug.cgi?id=1804617
|
|
|
a41c76 |
Message-Id: <8460aa915dbc8b4030aacf31cc39fbb7aee07d87.1585063415.git.pkrempa@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
a41c76 |
---
|
|
|
a41c76 |
src/util/virstoragefile.c | 30 ++++++++++++++++++++++++++++++
|
|
|
a41c76 |
tests/qemublocktest.c | 5 +++++
|
|
|
a41c76 |
tests/virstoragetest.c | 9 +++++++++
|
|
|
a41c76 |
3 files changed, 44 insertions(+)
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
|
|
|
a41c76 |
index 5423f0b955..3eb32edc2a 100644
|
|
|
a41c76 |
--- a/src/util/virstoragefile.c
|
|
|
a41c76 |
+++ b/src/util/virstoragefile.c
|
|
|
a41c76 |
@@ -3806,6 +3806,35 @@ virStorageSourceParseBackingJSONVxHS(virStorageSourcePtr src,
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
|
|
|
a41c76 |
+static int
|
|
|
a41c76 |
+virStorageSourceParseBackingJSONNVMe(virStorageSourcePtr src,
|
|
|
a41c76 |
+ virJSONValuePtr json,
|
|
|
a41c76 |
+ const char *jsonstr G_GNUC_UNUSED,
|
|
|
a41c76 |
+ int opaque G_GNUC_UNUSED)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ g_autoptr(virStorageSourceNVMeDef) nvme = g_new0(virStorageSourceNVMeDef, 1);
|
|
|
a41c76 |
+ const char *device = virJSONValueObjectGetString(json, "device");
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!device || virPCIDeviceAddressParse((char *) device, &nvme->pciAddr) < 0) {
|
|
|
a41c76 |
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
a41c76 |
+ _("missing or malformed 'device' field of 'nvme' storage"));
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virJSONValueObjectGetNumberUlong(json, "namespace", &nvme->namespc) < 0 ||
|
|
|
a41c76 |
+ nvme->namespc == 0) {
|
|
|
a41c76 |
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
a41c76 |
+ _("missing or malformed 'namespace' field of 'nvme' storage"));
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ src->type = VIR_STORAGE_TYPE_NVME;
|
|
|
a41c76 |
+ src->nvme = g_steal_pointer(&nvme);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return 0;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
struct virStorageSourceJSONDriverParser {
|
|
|
a41c76 |
const char *drvname;
|
|
|
a41c76 |
bool formatdriver;
|
|
|
a41c76 |
@@ -3837,6 +3866,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
|
|
|
a41c76 |
{"rbd", false, virStorageSourceParseBackingJSONRBD, 0},
|
|
|
a41c76 |
{"raw", true, virStorageSourceParseBackingJSONRaw, 0},
|
|
|
a41c76 |
{"vxhs", false, virStorageSourceParseBackingJSONVxHS, 0},
|
|
|
a41c76 |
+ {"nvme", false, virStorageSourceParseBackingJSONNVMe, 0},
|
|
|
a41c76 |
};
|
|
|
a41c76 |
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
|
|
|
a41c76 |
index 8b7a50712d..e461b3a23d 100644
|
|
|
a41c76 |
--- a/tests/qemublocktest.c
|
|
|
a41c76 |
+++ b/tests/qemublocktest.c
|
|
|
a41c76 |
@@ -1096,6 +1096,11 @@ mymain(void)
|
|
|
a41c76 |
/* type VIR_STORAGE_TYPE_BLOCK is not tested since it parses back to 'file' */
|
|
|
a41c76 |
/* type VIR_STORAGE_TYPE_DIR it is a 'format' driver in qemu */
|
|
|
a41c76 |
|
|
|
a41c76 |
+ TEST_JSON_FORMAT(VIR_STORAGE_TYPE_NVME,
|
|
|
a41c76 |
+ "<source type='pci' namespace='1'>\n"
|
|
|
a41c76 |
+ " <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>\n"
|
|
|
a41c76 |
+ "</source>\n");
|
|
|
a41c76 |
+
|
|
|
a41c76 |
TEST_JSON_FORMAT_NET("<source protocol='http' name=''>\n"
|
|
|
a41c76 |
" <host name='example.com' port='80'/>\n"
|
|
|
a41c76 |
"</source>\n");
|
|
|
a41c76 |
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
|
|
|
a41c76 |
index a61522965b..d9244fdfe8 100644
|
|
|
a41c76 |
--- a/tests/virstoragetest.c
|
|
|
a41c76 |
+++ b/tests/virstoragetest.c
|
|
|
a41c76 |
@@ -1637,6 +1637,15 @@ mymain(void)
|
|
|
a41c76 |
" <timeout seconds='2000'/>\n"
|
|
|
a41c76 |
"</source>\n", 0);
|
|
|
a41c76 |
|
|
|
a41c76 |
+ TEST_BACKING_PARSE("json:{\"file\":{\"driver\": \"nvme\","
|
|
|
a41c76 |
+ "\"device\": \"0000:01:00.0\","
|
|
|
a41c76 |
+ "\"namespace\": 1"
|
|
|
a41c76 |
+ "}"
|
|
|
a41c76 |
+ "}",
|
|
|
a41c76 |
+ "<source type='pci' namespace='1'>\n"
|
|
|
a41c76 |
+ " <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>\n"
|
|
|
a41c76 |
+ "</source>\n");
|
|
|
a41c76 |
+
|
|
|
a41c76 |
#endif /* WITH_YAJL */
|
|
|
a41c76 |
|
|
|
a41c76 |
cleanup:
|
|
|
a41c76 |
--
|
|
|
a41c76 |
2.26.0
|
|
|
a41c76 |
|