[PATCH v3 3/4] conf: storage: Don't emit empty <permissions> block

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

 



---
v3:
    New patch

 src/conf/storage_conf.c                            | 42 +++++++++++++---------
 tests/storagepoolxml2xmlout/pool-netfs-gluster.xml |  2 --
 tests/storagevolxml2xmlout/vol-gluster-dir.xml     |  2 --
 tests/storagevolxml2xmlout/vol-sheepdog.xml        |  2 --
 4 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index a02e504..7857a5e 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1179,22 +1179,28 @@ virStoragePoolDefFormatBuf(virBufferPtr buf,
 
         virBufferEscapeString(buf, "<path>%s</path>\n", def->target.path);
 
-        virBufferAddLit(buf, "<permissions>\n");
-        virBufferAdjustIndent(buf, 2);
-        if (def->target.perms.mode != (mode_t) -1)
-            virBufferAsprintf(buf, "<mode>0%o</mode>\n",
-                              def->target.perms.mode);
-        if (def->target.perms.uid != (uid_t) -1)
-            virBufferAsprintf(buf, "<owner>%d</owner>\n",
-                              (int) def->target.perms.uid);
-        if (def->target.perms.gid != (gid_t) -1)
-            virBufferAsprintf(buf, "<group>%d</group>\n",
-                              (int) def->target.perms.gid);
-        virBufferEscapeString(buf, "<label>%s</label>\n",
-                              def->target.perms.label);
+        if (def->target.perms.mode != (mode_t) -1 ||
+            def->target.perms.uid != (uid_t) -1 ||
+            def->target.perms.gid != (gid_t) -1 ||
+            def->target.perms.label) {
+            virBufferAddLit(buf, "<permissions>\n");
+            virBufferAdjustIndent(buf, 2);
+            if (def->target.perms.mode != (mode_t) -1)
+                virBufferAsprintf(buf, "<mode>0%o</mode>\n",
+                                  def->target.perms.mode);
+            if (def->target.perms.uid != (uid_t) -1)
+                virBufferAsprintf(buf, "<owner>%d</owner>\n",
+                                  (int) def->target.perms.uid);
+            if (def->target.perms.gid != (gid_t) -1)
+                virBufferAsprintf(buf, "<group>%d</group>\n",
+                                  (int) def->target.perms.gid);
+            virBufferEscapeString(buf, "<label>%s</label>\n",
+                                  def->target.perms.label);
+
+            virBufferAdjustIndent(buf, -2);
+            virBufferAddLit(buf, "</permissions>\n");
+        }
 
-        virBufferAdjustIndent(buf, -2);
-        virBufferAddLit(buf, "</permissions>\n");
         virBufferAdjustIndent(buf, -2);
         virBufferAddLit(buf, "</target>\n");
     }
@@ -1513,7 +1519,11 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
         virBufferAsprintf(buf, "<format type='%s'/>\n", format);
     }
 
-    if (def->perms) {
+    if (def->perms &&
+        (def->perms->mode != (mode_t) -1 ||
+         def->perms->uid != (uid_t) -1 ||
+         def->perms->gid != (gid_t) -1 ||
+         def->perms->label)) {
         virBufferAddLit(buf, "<permissions>\n");
         virBufferAdjustIndent(buf, 2);
 
diff --git a/tests/storagepoolxml2xmlout/pool-netfs-gluster.xml b/tests/storagepoolxml2xmlout/pool-netfs-gluster.xml
index 9e36cb6..dd7ffb5 100644
--- a/tests/storagepoolxml2xmlout/pool-netfs-gluster.xml
+++ b/tests/storagepoolxml2xmlout/pool-netfs-gluster.xml
@@ -11,7 +11,5 @@
   </source>
   <target>
     <path>/mnt/gluster</path>
-    <permissions>
-    </permissions>
   </target>
 </pool>
diff --git a/tests/storagevolxml2xmlout/vol-gluster-dir.xml b/tests/storagevolxml2xmlout/vol-gluster-dir.xml
index 37400b9..d422248 100644
--- a/tests/storagevolxml2xmlout/vol-gluster-dir.xml
+++ b/tests/storagevolxml2xmlout/vol-gluster-dir.xml
@@ -8,7 +8,5 @@
   <target>
     <path>gluster://example.com/vol/dir</path>
     <format type='dir'/>
-    <permissions>
-    </permissions>
   </target>
 </volume>
diff --git a/tests/storagevolxml2xmlout/vol-sheepdog.xml b/tests/storagevolxml2xmlout/vol-sheepdog.xml
index fe1879f..e1d6a9e 100644
--- a/tests/storagevolxml2xmlout/vol-sheepdog.xml
+++ b/tests/storagevolxml2xmlout/vol-sheepdog.xml
@@ -7,7 +7,5 @@
   <target>
     <path>sheepdog:test2</path>
     <format type='unknown'/>
-    <permissions>
-    </permissions>
   </target>
 </volume>
-- 
2.4.1

--
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]