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