mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
util: storage: adapt to changes in JSON format for ceph/rbd
Since qemu 2.9 the options changed from a monolithic string into fine grained options for the json pseudo-protocol object.
This commit is contained in:
parent
35d23f90b2
commit
4fac5a1935
@ -3122,6 +3122,15 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
|
|||||||
int opaque ATTRIBUTE_UNUSED)
|
int opaque ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
const char *filename;
|
const char *filename;
|
||||||
|
const char *pool = virJSONValueObjectGetString(json, "pool");
|
||||||
|
const char *image = virJSONValueObjectGetString(json, "image");
|
||||||
|
const char *conf = virJSONValueObjectGetString(json, "conf");
|
||||||
|
const char *snapshot = virJSONValueObjectGetString(json, "snapshot");
|
||||||
|
virJSONValuePtr servers = virJSONValueObjectGetArray(json, "server");
|
||||||
|
char *fullname = NULL;
|
||||||
|
size_t nservers;
|
||||||
|
size_t i;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
src->type = VIR_STORAGE_TYPE_NETWORK;
|
src->type = VIR_STORAGE_TYPE_NETWORK;
|
||||||
src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD;
|
src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD;
|
||||||
@ -3130,11 +3139,44 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
|
|||||||
if ((filename = virJSONValueObjectGetString(json, "filename")))
|
if ((filename = virJSONValueObjectGetString(json, "filename")))
|
||||||
return virStorageSourceParseRBDColonString(filename, src);
|
return virStorageSourceParseRBDColonString(filename, src);
|
||||||
|
|
||||||
/* RBD currently supports only URI syntax passed in as filename */
|
if (!pool || !image) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
_("missing RBD filename in JSON backing volume definition"));
|
_("missing pool or image name in ceph backing volume "
|
||||||
|
"JSON specification"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
/* currently we need to store the pool name and image name together, since
|
||||||
|
* the rest of the code is not prepared for it */
|
||||||
|
if (virAsprintf(&fullname, "%s/%s", pool, image) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (VIR_STRDUP(src->snapshot, snapshot) < 0 ||
|
||||||
|
VIR_STRDUP(src->configFile, conf) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
VIR_STEAL_PTR(src->path, fullname);
|
||||||
|
|
||||||
|
if (servers) {
|
||||||
|
nservers = virJSONValueArraySize(servers);
|
||||||
|
|
||||||
|
if (VIR_ALLOC_N(src->hosts, nservers) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
src->nhosts = nservers;
|
||||||
|
|
||||||
|
for (i = 0; i < nservers; i++) {
|
||||||
|
if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts + i,
|
||||||
|
virJSONValueArrayGet(servers, i)) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(fullname);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1507,6 +1507,25 @@ mymain(void)
|
|||||||
"<source protocol='rbd' name='testshare'>\n"
|
"<source protocol='rbd' name='testshare'>\n"
|
||||||
" <host name='example.com'/>\n"
|
" <host name='example.com'/>\n"
|
||||||
"</source>\n");
|
"</source>\n");
|
||||||
|
TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"rbd\","
|
||||||
|
"\"image\":\"test\","
|
||||||
|
"\"pool\":\"libvirt\","
|
||||||
|
"\"conf\":\"/path/to/conf\","
|
||||||
|
"\"snapshot\":\"snapshotname\","
|
||||||
|
"\"server\":[ {\"host\":\"example.com\","
|
||||||
|
"\"port\":\"1234\""
|
||||||
|
"},"
|
||||||
|
"{\"host\":\"example2.com\""
|
||||||
|
"}"
|
||||||
|
"]"
|
||||||
|
"}"
|
||||||
|
"}",
|
||||||
|
"<source protocol='rbd' name='libvirt/test'>\n"
|
||||||
|
" <host name='example.com' port='1234'/>\n"
|
||||||
|
" <host name='example2.com'/>\n"
|
||||||
|
" <snapshot name='snapshotname'/>\n"
|
||||||
|
" <config file='/path/to/conf'/>\n"
|
||||||
|
"</source>\n");
|
||||||
TEST_BACKING_PARSE("json:{ \"file\": { "
|
TEST_BACKING_PARSE("json:{ \"file\": { "
|
||||||
"\"driver\": \"raw\","
|
"\"driver\": \"raw\","
|
||||||
"\"file\": {"
|
"\"file\": {"
|
||||||
|
Loading…
Reference in New Issue
Block a user