[PATCH 13/n] conf: tweak volume target struct details

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

 



Some preparatory work before consolidating storage volume
structs with the rest of virstoragefile.  Making these
changes allows a volume target to be much closer to the
virStorageSource struct.

* src/conf/storage_conf.h (_virStorageVolTarget): Change perms to
pointer, enhance comments.
* src/conf/storage_conf.c (virStorageVolDefFree)
(virStorageVolDefParseXML, virStorageVolTargetDefFormat): Update
clients.
* src/storage/storage_backend_fs.c (createFileDir): Likewise.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(virStorageBackendCreateRaw, virStorageBackendCreateExecCommand)
(virStorageBackendUpdateVolTargetInfoFD): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskPartTypeToCreate): Likewise.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/conf/storage_conf.c               | 26 ++++++++++++------
 src/conf/storage_conf.h               |  7 ++---
 src/storage/storage_backend.c         | 50 ++++++++++++++++++++---------------
 src/storage/storage_backend_disk.c    | 14 +++++-----
 src/storage/storage_backend_fs.c      |  6 ++---
 src/storage/storage_backend_logical.c |  6 ++---
 6 files changed, 63 insertions(+), 46 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index a300476..49b790d 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -332,11 +332,17 @@ virStorageVolDefFree(virStorageVolDefPtr def)
     VIR_FREE(def->target.compat);
     virBitmapFree(def->target.features);
     VIR_FREE(def->target.path);
-    VIR_FREE(def->target.perms.label);
+    if (def->target.perms) {
+        VIR_FREE(def->target.perms->label);
+        VIR_FREE(def->target.perms);
+    }
     VIR_FREE(def->target.timestamps);
     virStorageEncryptionFree(def->target.encryption);
     VIR_FREE(def->backingStore.path);
-    VIR_FREE(def->backingStore.perms.label);
+    if (def->backingStore.perms) {
+        VIR_FREE(def->backingStore.perms->label);
+        VIR_FREE(def->backingStore.perms);
+    }
     VIR_FREE(def->backingStore.timestamps);
     virStorageEncryptionFree(def->backingStore.encryption);
     VIR_FREE(def);
@@ -1355,7 +1361,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
         VIR_FREE(format);
     }

-    if (virStorageDefParsePerms(ctxt, &ret->target.perms,
+    if (VIR_ALLOC(ret->target.perms) < 0)
+        goto error;
+    if (virStorageDefParsePerms(ctxt, ret->target.perms,
                                 "./target/permissions",
                                 DEFAULT_VOL_PERM_MODE) < 0)
         goto error;
@@ -1424,7 +1432,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
         VIR_FREE(nodes);
     }

-    if (virStorageDefParsePerms(ctxt, &ret->backingStore.perms,
+    if (VIR_ALLOC(ret->backingStore.perms) < 0)
+        goto error;
+    if (virStorageDefParsePerms(ctxt, ret->backingStore.perms,
                                 "./backingStore/permissions",
                                 DEFAULT_VOL_PERM_MODE) < 0)
         goto error;
@@ -1541,15 +1551,15 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
     virBufferAdjustIndent(buf, 2);

     virBufferAsprintf(buf, "<mode>0%o</mode>\n",
-                      def->perms.mode);
+                      def->perms->mode);
     virBufferAsprintf(buf, "<owner>%u</owner>\n",
-                      (unsigned int) def->perms.uid);
+                      (unsigned int) def->perms->uid);
     virBufferAsprintf(buf, "<group>%u</group>\n",
-                      (unsigned int) def->perms.gid);
+                      (unsigned int) def->perms->gid);


     virBufferEscapeString(buf, "<label>%s</label>\n",
-                          def->perms.label);
+                          def->perms->label);

     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</permissions>\n");
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index b811046..76d6c9c 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -81,10 +81,11 @@ typedef struct _virStorageVolTarget virStorageVolTarget;
 typedef virStorageVolTarget *virStorageVolTargetPtr;
 struct _virStorageVolTarget {
     char *path;
-    int format;
-    virStoragePerms perms;
+    int format; /* enum virStorageFileFormat */
+    virStoragePermsPtr perms;
     virStorageTimestampsPtr timestamps;
-    int type; /* only used by disk backend for partition type */
+    int partType; /* enum virStorageVolTypeDisk, only used by disk
+                   * backend for partition type */
     /* The next three are currently only used in vol->target,
      * not in vol->backingStore. */
     virStorageEncryptionPtr encryption;
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index a4481b2..00066da 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -301,8 +301,10 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED,
                              vol->target.path);
         goto cleanup;
     }
-    uid = (vol->target.perms.uid != st.st_uid) ? vol->target.perms.uid : (uid_t) -1;
-    gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : (gid_t) -1;
+    uid = (vol->target.perms->uid != st.st_uid) ? vol->target.perms->uid
+        : (uid_t) -1;
+    gid = (vol->target.perms->gid != st.st_gid) ? vol->target.perms->gid
+        : (gid_t) -1;
     if (((uid != (uid_t) -1) || (gid != (gid_t) -1))
         && (fchown(fd, uid, gid) < 0)) {
         virReportSystemError(errno,
@@ -311,10 +313,10 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED,
                              (unsigned int) gid);
         goto cleanup;
     }
-    if (fchmod(fd, vol->target.perms.mode) < 0) {
+    if (fchmod(fd, vol->target.perms->mode) < 0) {
         virReportSystemError(errno,
                              _("cannot set mode of '%s' to %04o"),
-                             vol->target.path, vol->target.perms.mode);
+                             vol->target.path, vol->target.perms->mode);
         goto cleanup;
     }
     if (VIR_CLOSE(fd) < 0) {
@@ -439,9 +441,9 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,

     if ((fd = virFileOpenAs(vol->target.path,
                             O_RDWR | O_CREAT | O_EXCL,
-                            vol->target.perms.mode,
-                            vol->target.perms.uid,
-                            vol->target.perms.gid,
+                            vol->target.perms->mode,
+                            vol->target.perms->uid,
+                            vol->target.perms->gid,
                             operation_flags)) < 0) {
         virReportSystemError(-fd,
                              _("Failed to create file '%s'"),
@@ -578,13 +580,13 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,

     if ((pool->def->type == VIR_STORAGE_POOL_NETFS)
         && (((geteuid() == 0)
-             && (vol->target.perms.uid != (uid_t) -1)
-             && (vol->target.perms.uid != 0))
-            || ((vol->target.perms.gid != (gid_t) -1)
-                && (vol->target.perms.gid != getegid())))) {
+             && (vol->target.perms->uid != (uid_t) -1)
+             && (vol->target.perms->uid != 0))
+            || ((vol->target.perms->gid != (gid_t) -1)
+                && (vol->target.perms->gid != getegid())))) {

-        virCommandSetUID(cmd, vol->target.perms.uid);
-        virCommandSetGID(cmd, vol->target.perms.gid);
+        virCommandSetUID(cmd, vol->target.perms->uid);
+        virCommandSetGID(cmd, vol->target.perms->gid);

         if (virCommandRun(cmd, NULL) == 0) {
             /* command was successfully run, check if the file was created */
@@ -608,8 +610,10 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
         }
     }

-    uid = (vol->target.perms.uid != st.st_uid) ? vol->target.perms.uid : (uid_t) -1;
-    gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : (gid_t) -1;
+    uid = (vol->target.perms->uid != st.st_uid) ? vol->target.perms->uid
+        : (uid_t) -1;
+    gid = (vol->target.perms->gid != st.st_gid) ? vol->target.perms->gid
+        : (gid_t) -1;
     if (((uid != (uid_t) -1) || (gid != (gid_t) -1))
         && (chown(vol->target.path, uid, gid) < 0)) {
         virReportSystemError(errno,
@@ -618,10 +622,10 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
                              (unsigned int) gid);
         return -1;
     }
-    if (chmod(vol->target.path, vol->target.perms.mode) < 0) {
+    if (chmod(vol->target.path, vol->target.perms->mode) < 0) {
         virReportSystemError(errno,
                              _("cannot set mode of '%s' to %04o"),
-                             vol->target.path, vol->target.perms.mode);
+                             vol->target.path, vol->target.perms->mode);
         return -1;
     }
     return 0;
@@ -1425,9 +1429,11 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
         }
     }

-    target->perms.mode = sb->st_mode & S_IRWXUGO;
-    target->perms.uid = sb->st_uid;
-    target->perms.gid = sb->st_gid;
+    if (!target->perms && VIR_ALLOC(target->perms) < 0)
+        return -1;
+    target->perms->mode = sb->st_mode & S_IRWXUGO;
+    target->perms->uid = sb->st_uid;
+    target->perms->gid = sb->st_gid;

     if (!target->timestamps && VIR_ALLOC(target->timestamps) < 0)
         return -1;
@@ -1436,7 +1442,7 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
     target->timestamps->ctime = get_stat_ctime(sb);
     target->timestamps->mtime = get_stat_mtime(sb);

-    VIR_FREE(target->perms.label);
+    VIR_FREE(target->perms->label);

 #if WITH_SELINUX
     /* XXX: make this a security driver call */
@@ -1449,7 +1455,7 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
                 return -1;
             }
         } else {
-            if (VIR_STRDUP(target->perms.label, filecon) < 0) {
+            if (VIR_STRDUP(target->perms->label, filecon) < 0) {
                 freecon(filecon);
                 return -1;
             }
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 8276c96..bfc2e65 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend_disk.c: storage backend for disk handling
  *
- * Copyright (C) 2007-2008, 2010-2013 Red Hat, Inc.
+ * Copyright (C) 2007-2014 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -118,13 +118,13 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,

     /* set partition type */
     if (STREQ(groups[1], "normal"))
-       vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_PRIMARY;
+       vol->target.partType = VIR_STORAGE_VOL_DISK_TYPE_PRIMARY;
     else if (STREQ(groups[1], "logical"))
-       vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_LOGICAL;
+       vol->target.partType = VIR_STORAGE_VOL_DISK_TYPE_LOGICAL;
     else if (STREQ(groups[1], "extended"))
-       vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_EXTENDED;
+       vol->target.partType = VIR_STORAGE_VOL_DISK_TYPE_EXTENDED;
     else
-       vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_NONE;
+       vol->target.partType = VIR_STORAGE_VOL_DISK_TYPE_NONE;

     vol->type = VIR_STORAGE_VOL_BLOCK;

@@ -444,8 +444,8 @@ virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool)
         size_t i;
         int count = 0;
         for (i = 0; i < pool->volumes.count; i++) {
-             if (pool->volumes.objs[i]->target.type == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY ||
-                 pool->volumes.objs[i]->target.type == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) {
+             if (pool->volumes.objs[i]->target.partType == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY ||
+                 pool->volumes.objs[i]->target.partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) {
                      count++;
              }
         }
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 084ae56..fd03ca4 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1037,9 +1037,9 @@ static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED,
         return -1;
     }

-    if ((err = virDirCreate(vol->target.path, vol->target.perms.mode,
-                            vol->target.perms.uid,
-                            vol->target.perms.gid,
+    if ((err = virDirCreate(vol->target.path, vol->target.perms->mode,
+                            vol->target.perms->uid,
+                            vol->target.perms->gid,
                             VIR_DIR_CREATE_FORCE_PERMS |
                             (pool->def->type == VIR_STORAGE_POOL_NETFS
                              ? VIR_DIR_CREATE_AS_UID : 0))) < 0) {
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index f90d373..874ebf6 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend_logical.c: storage backend for logical volume handling
  *
- * Copyright (C) 2007-2009, 2011, 2013 Red Hat, Inc.
+ * Copyright (C) 2007-2014 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -764,14 +764,14 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,

     /* We can only chown/grp if root */
     if (geteuid() == 0) {
-        if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
+        if (fchown(fd, vol->target.perms->uid, vol->target.perms->gid) < 0) {
             virReportSystemError(errno,
                                  _("cannot set file owner '%s'"),
                                  vol->target.path);
             goto error;
         }
     }
-    if (fchmod(fd, vol->target.perms.mode) < 0) {
+    if (fchmod(fd, vol->target.perms->mode) < 0) {
         virReportSystemError(errno,
                              _("cannot set file mode '%s'"),
                              vol->target.path);
-- 
1.9.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]