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.
---
src/storage/storage_backend.h | 6 ++++++
src/storage/storage_backend_fs.c | 12 ++++++++++++
src/storage/storage_backend_gluster.c | 12 ++++++++++++
src/storage/storage_driver.c | 28 ++++++++++++++++++++++++++++
src/storage/storage_driver.h | 1 +
5 files changed, 59 insertions(+)
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index e48da5b..a93df5d 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -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__ */
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 40cc1f4..2af5ab5 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -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,
};
diff --git a/src/storage/storage_backend_gluster.c
b/src/storage/storage_backend_gluster.c
index 0f8f0f3..052f58d 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -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,
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 3830867..efd79b9 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -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,
diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h
index bd9e9ed..eefd766 100644
--- a/src/storage/storage_driver.h
+++ b/src/storage/storage_driver.h
@@ -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,
--
2.0.0