1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

storage: Store RBD image name as pool and image name

Similarly to how we store gluster names, split the name into a pool and
image portions when paring the XML and store them separately.
This commit is contained in:
Peter Krempa 2017-10-23 16:23:45 +02:00
parent bb14d9897b
commit 90521d0754
7 changed files with 23 additions and 22 deletions

View File

@ -8388,16 +8388,17 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
src->tlsFromConfig = !!tlsCfgVal;
}
/* for historical reasons the volume name for gluster volume is stored
* as a part of the path. This is hard to work with when dealing with
* relative names. Split out the volume into a separate variable */
if (src->path && src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER) {
/* for historical reasons we store the volume and image name in one XML
* element although it complicates thing when attempting to access them. */
if (src->path &&
(src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER ||
src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD)) {
char *tmp;
if (!(tmp = strchr(src->path, '/')) ||
tmp == src->path) {
virReportError(VIR_ERR_XML_ERROR,
_("missing volume name or file name in "
"gluster source path '%s'"), src->path);
_("can't split path '%s' into pool name and image "
"name"), src->path);
goto cleanup;
}

View File

@ -657,7 +657,7 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src,
goto cleanup;
}
virBufferStrcat(&buf, "rbd:", src->path, NULL);
virBufferStrcat(&buf, "rbd:", src->volume, "/", src->path, NULL);
if (username) {
virBufferEscape(&buf, '\\', ":", ":id=%s", username);

View File

@ -951,7 +951,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
goto cleanup;
}
virBufferStrcat(&buf, "rbd:", src->path, NULL);
virBufferStrcat(&buf, "rbd:", src->volume, "/", src->path, NULL);
if (src->snapshot)
virBufferEscape(&buf, '\\', ":", "@%s", src->snapshot);

View File

@ -2545,6 +2545,14 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
*p = '\0';
}
/* pool vs. image name */
if ((p = strchr(src->path, '/'))) {
VIR_STEAL_PTR(src->volume, src->path);
if (VIR_STRDUP(src->path, p + 1) < 0)
goto error;
*p = '\0';
}
/* options */
if (!options)
return 0; /* all done */
@ -3178,7 +3186,6 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
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;
@ -3197,17 +3204,12 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
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 ||
if (VIR_STRDUP(src->volume, pool) < 0 ||
VIR_STRDUP(src->path, image) < 0 ||
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);
@ -3225,8 +3227,6 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
ret = 0;
cleanup:
VIR_FREE(fullname);
return ret;
}

View File

@ -1040,7 +1040,7 @@ xenFormatXLDiskSrcNet(virStorageSourcePtr src)
goto cleanup;
}
virBufferStrcat(&buf, "rbd:", src->path, NULL);
virBufferStrcat(&buf, "rbd:", src->volume, "/", src->path, NULL);
virBufferAddLit(&buf, ":auth_supported=none");

View File

@ -24,7 +24,7 @@
</source>
</disk>
<disk name='hdh' snapshot='external' type='network'>
<source protocol='rbd' name='name'>
<source protocol='rbd' name='vol/name'>
<host name='host' port='1234'/>
<host name='host2' port='1234' transport='rdma'/>
<host name='host3' port='1234'/>

View File

@ -23,7 +23,7 @@
</source>
</disk>
<disk name='hdh' snapshot='external' type='network'>
<source protocol='rbd' name='name'>
<source protocol='rbd' name='vol/name'>
<host name='host' port='1234'/>
<host name='host2' port='1234' transport='rdma'/>
<host name='host3' port='1234'/>