mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-13 16:15:19 +00:00
storage: Store gluster volume name separately
The gluster volume name was previously stored as part of the source path string. This is unfortunate when we want to do operations on the path as the volume is used separately. Parse and store the volume name separately for gluster storage volumes and use the newly stored variable appropriately.
This commit is contained in:
parent
b8d6ba9bdc
commit
1115f975b4
@ -5002,6 +5002,27 @@ virDomainDiskSourceParse(xmlNodePtr node,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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) {
|
||||||
|
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);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
src->volume = src->path;
|
||||||
|
|
||||||
|
if (VIR_STRDUP(src->path, tmp) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
tmp[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
child = node->children;
|
child = node->children;
|
||||||
while (child != NULL) {
|
while (child != NULL) {
|
||||||
if (child->type == XML_ELEMENT_NODE &&
|
if (child->type == XML_ELEMENT_NODE &&
|
||||||
@ -14841,6 +14862,7 @@ virDomainDiskSourceFormat(virBufferPtr buf,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
|
char *path = NULL;
|
||||||
const char *startupPolicy = NULL;
|
const char *startupPolicy = NULL;
|
||||||
|
|
||||||
if (policy)
|
if (policy)
|
||||||
@ -14876,7 +14898,16 @@ virDomainDiskSourceFormat(virBufferPtr buf,
|
|||||||
case VIR_STORAGE_TYPE_NETWORK:
|
case VIR_STORAGE_TYPE_NETWORK:
|
||||||
virBufferAsprintf(buf, "<source protocol='%s'",
|
virBufferAsprintf(buf, "<source protocol='%s'",
|
||||||
virStorageNetProtocolTypeToString(src->protocol));
|
virStorageNetProtocolTypeToString(src->protocol));
|
||||||
virBufferEscapeString(buf, " name='%s'", src->path);
|
|
||||||
|
|
||||||
|
if (src->volume) {
|
||||||
|
if (virAsprintf(&path, "%s%s", src->volume, src->path) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
virBufferEscapeString(buf, " name='%s'", path ? path : src->path);
|
||||||
|
|
||||||
|
VIR_FREE(path);
|
||||||
|
|
||||||
if (src->nhosts == 0) {
|
if (src->nhosts == 0) {
|
||||||
virBufferAddLit(buf, "/>\n");
|
virBufferAddLit(buf, "/>\n");
|
||||||
|
@ -3058,6 +3058,7 @@ qemuNetworkDriveGetPort(int protocol,
|
|||||||
static char *
|
static char *
|
||||||
qemuBuildNetworkDriveURI(int protocol,
|
qemuBuildNetworkDriveURI(int protocol,
|
||||||
const char *src,
|
const char *src,
|
||||||
|
const char *volume,
|
||||||
size_t nhosts,
|
size_t nhosts,
|
||||||
virStorageNetHostDefPtr hosts,
|
virStorageNetHostDefPtr hosts,
|
||||||
const char *username,
|
const char *username,
|
||||||
@ -3157,11 +3158,18 @@ qemuBuildNetworkDriveURI(int protocol,
|
|||||||
if ((uri->port = qemuNetworkDriveGetPort(protocol, hosts->port)) < 0)
|
if ((uri->port = qemuNetworkDriveGetPort(protocol, hosts->port)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (src &&
|
if (src) {
|
||||||
virAsprintf(&uri->path, "%s%s",
|
if (volume) {
|
||||||
|
if (virAsprintf(&uri->path, "/%s%s",
|
||||||
|
volume, src) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
if (virAsprintf(&uri->path, "%s%s",
|
||||||
src[0] == '/' ? "" : "/",
|
src[0] == '/' ? "" : "/",
|
||||||
src) < 0)
|
src) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (hosts->socket &&
|
if (hosts->socket &&
|
||||||
virAsprintf(&uri->query, "socket=%s", hosts->socket) < 0)
|
virAsprintf(&uri->query, "socket=%s", hosts->socket) < 0)
|
||||||
@ -3323,6 +3331,7 @@ qemuGetDriveSourceString(virStorageSourcePtr src,
|
|||||||
case VIR_STORAGE_TYPE_NETWORK:
|
case VIR_STORAGE_TYPE_NETWORK:
|
||||||
if (!(*source = qemuBuildNetworkDriveURI(src->protocol,
|
if (!(*source = qemuBuildNetworkDriveURI(src->protocol,
|
||||||
src->path,
|
src->path,
|
||||||
|
src->volume,
|
||||||
src->nhosts,
|
src->nhosts,
|
||||||
src->hosts,
|
src->hosts,
|
||||||
username,
|
username,
|
||||||
|
@ -533,8 +533,6 @@ typedef virStorageFileBackendGlusterPriv *virStorageFileBackendGlusterPrivPtr;
|
|||||||
|
|
||||||
struct _virStorageFileBackendGlusterPriv {
|
struct _virStorageFileBackendGlusterPriv {
|
||||||
glfs_t *vol;
|
glfs_t *vol;
|
||||||
char *volname;
|
|
||||||
char *path;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -547,7 +545,6 @@ virStorageFileBackendGlusterDeinit(virStorageSourcePtr src)
|
|||||||
|
|
||||||
if (priv->vol)
|
if (priv->vol)
|
||||||
glfs_fini(priv->vol);
|
glfs_fini(priv->vol);
|
||||||
VIR_FREE(priv->volname);
|
|
||||||
|
|
||||||
VIR_FREE(priv);
|
VIR_FREE(priv);
|
||||||
src->drv->priv = NULL;
|
src->drv->priv = NULL;
|
||||||
@ -564,21 +561,14 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
|
|||||||
VIR_DEBUG("initializing gluster storage file %p(%s/%s)",
|
VIR_DEBUG("initializing gluster storage file %p(%s/%s)",
|
||||||
src, hostname, src->path);
|
src, hostname, src->path);
|
||||||
|
|
||||||
if (VIR_ALLOC(priv) < 0)
|
if (!src->volume) {
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (VIR_STRDUP(priv->volname, src->path) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(priv->path = strchr(priv->volname, '/'))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("invalid path of gluster volume: '%s'"),
|
_("missing gluster volume name for path '%s'"), src->path);
|
||||||
src->path);
|
return -1;
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*priv->path = '\0';
|
if (VIR_ALLOC(priv) < 0)
|
||||||
priv->path++;
|
return -1;
|
||||||
|
|
||||||
if (host->port &&
|
if (host->port &&
|
||||||
virStrToLong_i(host->port, NULL, 10, &port) < 0) {
|
virStrToLong_i(host->port, NULL, 10, &port) < 0) {
|
||||||
@ -591,7 +581,7 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
|
|||||||
if (host->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX)
|
if (host->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX)
|
||||||
hostname = host->socket;
|
hostname = host->socket;
|
||||||
|
|
||||||
if (!(priv->vol = glfs_new(priv->volname))) {
|
if (!(priv->vol = glfs_new(src->volume))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -617,7 +607,6 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(priv->volname);
|
|
||||||
if (priv->vol)
|
if (priv->vol)
|
||||||
glfs_fini(priv->vol);
|
glfs_fini(priv->vol);
|
||||||
VIR_FREE(priv);
|
VIR_FREE(priv);
|
||||||
@ -632,7 +621,7 @@ virStorageFileBackendGlusterUnlink(virStorageSourcePtr src)
|
|||||||
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
|
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = glfs_unlink(priv->vol, priv->path);
|
ret = glfs_unlink(priv->vol, src->path);
|
||||||
/* preserve errno */
|
/* preserve errno */
|
||||||
|
|
||||||
VIR_DEBUG("removing storage file %p(%s/%s): ret=%d, errno=%d",
|
VIR_DEBUG("removing storage file %p(%s/%s): ret=%d, errno=%d",
|
||||||
@ -648,7 +637,7 @@ virStorageFileBackendGlusterStat(virStorageSourcePtr src,
|
|||||||
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
|
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = glfs_stat(priv->vol, priv->path, st);
|
ret = glfs_stat(priv->vol, src->path, st);
|
||||||
/* preserve errno */
|
/* preserve errno */
|
||||||
|
|
||||||
VIR_DEBUG("stat of storage file %p(%s/%s): ret=%d, errno=%d",
|
VIR_DEBUG("stat of storage file %p(%s/%s): ret=%d, errno=%d",
|
||||||
|
@ -1757,6 +1757,7 @@ virStorageSourceClear(virStorageSourcePtr def)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
VIR_FREE(def->path);
|
VIR_FREE(def->path);
|
||||||
|
VIR_FREE(def->volume);
|
||||||
virStorageSourcePoolDefFree(def->srcpool);
|
virStorageSourcePoolDefFree(def->srcpool);
|
||||||
VIR_FREE(def->driverName);
|
VIR_FREE(def->driverName);
|
||||||
virBitmapFree(def->features);
|
virBitmapFree(def->features);
|
||||||
|
@ -212,6 +212,7 @@ struct _virStorageSource {
|
|||||||
int type; /* virStorageType */
|
int type; /* virStorageType */
|
||||||
char *path;
|
char *path;
|
||||||
int protocol; /* virStorageNetProtocol */
|
int protocol; /* virStorageNetProtocol */
|
||||||
|
char *volume; /* volume name for remote storage */
|
||||||
size_t nhosts;
|
size_t nhosts;
|
||||||
virStorageNetHostDefPtr hosts;
|
virStorageNetHostDefPtr hosts;
|
||||||
virStorageSourcePoolDefPtr srcpool;
|
virStorageSourcePoolDefPtr srcpool;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user