[PATCH 1/8] storage: Implement storage driver helper to chown disk images

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 76c1afa..1a80aef 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -202,6 +202,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,
@@ -227,6 +232,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 c93fc1e..693ebd3 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1435,6 +1435,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,

@@ -1445,6 +1454,7 @@ virStorageFileBackend virStorageFileBackendFile = {
     .storageFileStat = virStorageFileBackendFileStat,
     .storageFileReadHeader = virStorageFileBackendFileReadHeader,
     .storageFileAccess = virStorageFileBackendFileAccess,
+    .storageFileChown = virStorageFileBackendFileChown,

     .storageFileGetUniqueIdentifier = virStorageFileBackendFileGetUniqueIdentifier,
 };
@@ -1459,6 +1469,7 @@ virStorageFileBackend virStorageFileBackendBlock = {
     .storageFileStat = virStorageFileBackendFileStat,
     .storageFileReadHeader = virStorageFileBackendFileReadHeader,
     .storageFileAccess = virStorageFileBackendFileAccess,
+    .storageFileChown = virStorageFileBackendFileChown,

     .storageFileGetUniqueIdentifier = virStorageFileBackendFileGetUniqueIdentifier,
 };
@@ -1471,6 +1482,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 76d2461..edb0511 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -754,6 +754,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,
@@ -765,6 +776,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 ae86c69..928fadf 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2823,6 +2823,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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]