[libvirt] [PATCH for 1.2.7] storage: create: Create files with correct mode

Peter Krempa pkrempa at redhat.com
Mon Jul 28 14:59:44 UTC 2014


Use correct mode when pre-creating files (for snapshots). The refactor
changing to storage driver usage caused a regression as some systems
created the file with 000 permissions forbidding qemu to write the file.

Pass mode to the creating functions to avoid the problem.

Regression since 185e07a5f82bc0692324f3ee13b4816d71b653c1.
---
 src/storage/storage_backend_fs.c      | 6 +++++-
 src/storage/storage_backend_gluster.c | 7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 378c553..b8f907a 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1390,8 +1390,12 @@ static int
 virStorageFileBackendFileCreate(virStorageSourcePtr src)
 {
     int fd = -1;
+    mode_t mode = S_IRUSR;

-    if ((fd = virFileOpenAs(src->path, O_WRONLY | O_TRUNC | O_CREAT, 0,
+    if (!src->readonly)
+        mode |= S_IWUSR;
+
+    if ((fd = virFileOpenAs(src->path, O_WRONLY | O_TRUNC | O_CREAT, mode,
                             src->drv->uid, src->drv->gid, 0)) < 0) {
         errno = -fd;
         return -1;
diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 38d02ac..8a7d7e5 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -638,8 +638,13 @@ virStorageFileBackendGlusterCreate(virStorageSourcePtr src)
 {
     virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
     glfs_fd_t *fd = NULL;
+    mode_t mode = S_IRUSR;

-    if (!(fd = glfs_open(priv->vol, src->path, O_CREAT | O_TRUNC | O_WRONLY)))
+    if (!src->readonly)
+        mode |= S_IWUSR;
+
+    if (!(fd = glfs_creat(priv->vol, src->path,
+                          O_CREAT | O_TRUNC | O_WRONLY, mode)))
         return -1;

     ignore_value(glfs_close(fd));
-- 
2.0.0




More information about the libvir-list mailing list