1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-23 02:04:16 +03:00

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 <Ashish.Mittal@veritas.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Ashish Mittal 2017-08-30 09:46:50 -04:00 committed by John Ferlan
parent e6a7fa2670
commit 2a48252bb5
2 changed files with 48 additions and 0 deletions

View File

@ -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;

View File

@ -1592,6 +1592,17 @@ mymain(void)
"<source protocol='sheepdog' name='Alice'>\n"
" <host name='10.10.10.10' port='7000'/>\n"
"</source>\n");
TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"vxhs\","
"\"vdisk-id\":\"c6718f6b-0401-441d-a8c3-1f0064d75ee0\","
"\"server\": { \"type\":\"tcp\","
"\"host\":\"example.com\","
"\"port\":\"9999\""
"}"
"}"
"}",
"<source protocol='vxhs' name='c6718f6b-0401-441d-a8c3-1f0064d75ee0'>\n"
" <host name='example.com' port='9999'/>\n"
"</source>\n");
#endif /* WITH_YAJL */
cleanup: