1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 07:59:00 +00:00

storage: Implement storage driver helper to chown disk images

Gluster storage works on a similar principle to NFS where it takes the
uid and gid of the actual process and uses it to access the storage
volume on the remote server. This introduces a need to chown storage
files on gluster via native API.
This commit is contained in:
Peter Krempa 2014-07-09 16:42:10 +02:00
parent 12926a7c39
commit 50f09651df
5 changed files with 59 additions and 0 deletions

View File

@ -244,6 +244,11 @@ typedef int
(*virStorageFileBackendAccess)(virStorageSourcePtr src,
int mode);
typedef int
(*virStorageFileBackendChown)(virStorageSourcePtr src,
uid_t uid,
gid_t gid);
virStorageFileBackendPtr virStorageFileBackendForType(int type, int protocol);
virStorageFileBackendPtr virStorageFileBackendForTypeInternal(int type,
int protocol,
@ -269,6 +274,7 @@ struct _virStorageFileBackend {
virStorageFileBackendUnlink storageFileUnlink;
virStorageFileBackendStat storageFileStat;
virStorageFileBackendAccess storageFileAccess;
virStorageFileBackendChown storageFileChown;
};
#endif /* __VIR_STORAGE_BACKEND_H__ */

View File

@ -1455,6 +1455,15 @@ virStorageFileBackendFileAccess(virStorageSourcePtr src,
}
static int
virStorageFileBackendFileChown(virStorageSourcePtr src,
uid_t uid,
gid_t gid)
{
return chown(src->path, uid, gid);
}
virStorageFileBackend virStorageFileBackendFile = {
.type = VIR_STORAGE_TYPE_FILE,
@ -1465,6 +1474,7 @@ virStorageFileBackend virStorageFileBackendFile = {
.storageFileStat = virStorageFileBackendFileStat,
.storageFileReadHeader = virStorageFileBackendFileReadHeader,
.storageFileAccess = virStorageFileBackendFileAccess,
.storageFileChown = virStorageFileBackendFileChown,
.storageFileGetUniqueIdentifier = virStorageFileBackendFileGetUniqueIdentifier,
};
@ -1479,6 +1489,7 @@ virStorageFileBackend virStorageFileBackendBlock = {
.storageFileStat = virStorageFileBackendFileStat,
.storageFileReadHeader = virStorageFileBackendFileReadHeader,
.storageFileAccess = virStorageFileBackendFileAccess,
.storageFileChown = virStorageFileBackendFileChown,
.storageFileGetUniqueIdentifier = virStorageFileBackendFileGetUniqueIdentifier,
};
@ -1491,6 +1502,7 @@ virStorageFileBackend virStorageFileBackendDir = {
.backendDeinit = virStorageFileBackendFileDeinit,
.storageFileAccess = virStorageFileBackendFileAccess,
.storageFileChown = virStorageFileBackendFileChown,
.storageFileGetUniqueIdentifier = virStorageFileBackendFileGetUniqueIdentifier,
};

View File

@ -762,6 +762,17 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src)
}
static int
virStorageFileBackendGlusterChown(virStorageSourcePtr src,
uid_t uid,
gid_t gid)
{
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
return glfs_chown(priv->vol, src->path, uid, gid);
}
virStorageFileBackend virStorageFileBackendGluster = {
.type = VIR_STORAGE_TYPE_NETWORK,
.protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER,
@ -773,6 +784,7 @@ virStorageFileBackend virStorageFileBackendGluster = {
.storageFileStat = virStorageFileBackendGlusterStat,
.storageFileReadHeader = virStorageFileBackendGlusterReadHeader,
.storageFileAccess = virStorageFileBackendGlusterAccess,
.storageFileChown = virStorageFileBackendGlusterChown,
.storageFileGetUniqueIdentifier = virStorageFileBackendGlusterGetUniqueIdentifier,

View File

@ -2613,6 +2613,34 @@ virStorageFileAccess(virStorageSourcePtr src,
}
/**
* virStorageFileChown: Change owner of a storage file
*
* @src: storage file to change owner of
* @uid: new owner id
* @gid: new group id
*
* Returns 0 on success, -1 on error and sets errno. No libvirt
* error is reported. Returns -2 if the operation isn't supported
* by libvirt storage backend.
*/
int
virStorageFileChown(virStorageSourcePtr src,
uid_t uid,
gid_t gid)
{
if (!virStorageFileIsInitialized(src) ||
!src->drv->backend->storageFileChown) {
errno = ENOSYS;
return -2;
}
VIR_DEBUG("chown of storage file %p to %d:%d", src, uid, gid);
return src->drv->backend->storageFileChown(src, uid, gid);
}
/* Recursive workhorse for virStorageFileGetMetadata. */
static int
virStorageFileGetMetadataRecurse(virStorageSourcePtr src,

View File

@ -43,6 +43,7 @@ ssize_t virStorageFileReadHeader(virStorageSourcePtr src,
char **buf);
const char *virStorageFileGetUniqueIdentifier(virStorageSourcePtr src);
int virStorageFileAccess(virStorageSourcePtr src, int mode);
int virStorageFileChown(virStorageSourcePtr src, uid_t uid, gid_t gid);
int virStorageFileGetMetadata(virStorageSourcePtr src,
uid_t uid, gid_t gid,