From 2a48252bb57a3eaa11907e8f295b2114504e4ff6 Mon Sep 17 00:00:00 2001 From: Ashish Mittal Date: Wed, 30 Aug 2017 09:46:50 -0400 Subject: [PATCH] util: storage: Add JSON backing volume parse for VxHS Add the backing parse and a test case to verify parsing of VxHS backing storage. Signed-off-by: Ashish Mittal Signed-off-by: John Ferlan --- src/util/virstoragefile.c | 37 +++++++++++++++++++++++++++++++++++++ tests/virstoragetest.c | 11 +++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index ca306c27ba..ba2045369c 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3212,6 +3212,40 @@ virStorageSourceParseBackingJSONRaw(virStorageSourcePtr src, return virStorageSourceParseBackingJSONInternal(src, json); } + +static int +virStorageSourceParseBackingJSONVxHS(virStorageSourcePtr src, + virJSONValuePtr json, + int opaque ATTRIBUTE_UNUSED) +{ + const char *vdisk_id = virJSONValueObjectGetString(json, "vdisk-id"); + virJSONValuePtr server = virJSONValueObjectGetObject(json, "server"); + + if (!vdisk_id || !server) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'vdisk-id' or 'server' attribute in " + "JSON backing definition for VxHS volume")); + return -1; + } + + src->type = VIR_STORAGE_TYPE_NETWORK; + src->protocol = VIR_STORAGE_NET_PROTOCOL_VXHS; + + if (VIR_STRDUP(src->path, vdisk_id) < 0) + return -1; + + if (VIR_ALLOC_N(src->hosts, 1) < 0) + return -1; + src->nhosts = 1; + + if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts, + server) < 0) + return -1; + + return 0; +} + + struct virStorageSourceJSONDriverParser { const char *drvname; int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque); @@ -3234,6 +3268,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = { {"ssh", virStorageSourceParseBackingJSONSSH, 0}, {"rbd", virStorageSourceParseBackingJSONRBD, 0}, {"raw", virStorageSourceParseBackingJSONRaw, 0}, + {"vxhs", virStorageSourceParseBackingJSONVxHS, 0}, }; @@ -3995,6 +4030,8 @@ virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol) return 0; case VIR_STORAGE_NET_PROTOCOL_VXHS: + return 9999; + case VIR_STORAGE_NET_PROTOCOL_LAST: case VIR_STORAGE_NET_PROTOCOL_NONE: return 0; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 60e3164b0a..ffebd4dc1d 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1592,6 +1592,17 @@ mymain(void) "\n" " \n" "\n"); + TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"vxhs\"," + "\"vdisk-id\":\"c6718f6b-0401-441d-a8c3-1f0064d75ee0\"," + "\"server\": { \"type\":\"tcp\"," + "\"host\":\"example.com\"," + "\"port\":\"9999\"" + "}" + "}" + "}", + "\n" + " \n" + "\n"); #endif /* WITH_YAJL */ cleanup: -- 2.47.2