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

[libvirt] [PATCHv1 04/13] Separate virStorageFeatureFormat



For reuse in snapshot_conf.
---
 src/conf/storage_conf.c         | 23 +----------------------
 src/conf/storage_feature_conf.c | 25 +++++++++++++++++++++++++
 src/conf/storage_feature_conf.h |  3 +++
 3 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index a5b5c1b..ee3019a 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1544,28 +1544,7 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
 
     virBufferEscapeString(buf, "<compat>%s</compat>\n", def->compat);
 
-    if (def->features) {
-        size_t i;
-        bool empty = virBitmapIsAllClear(def->features);
-
-        if (empty) {
-            virBufferAddLit(buf, "<features/>\n");
-        } else {
-            virBufferAddLit(buf, "<features>\n");
-            virBufferAdjustIndent(buf, 2);
-        }
-
-        for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) {
-            if (virBitmapIsBitSet(def->features, i))
-                virBufferAsprintf(buf, "<%s/>\n",
-                                  virStorageFileFeatureTypeToString(i));
-        }
-        if (!empty) {
-            virBufferAdjustIndent(buf, -2);
-            virBufferAddLit(buf, "</features>\n");
-        }
-    }
-
+    virStorageFeaturesFormat(buf, def->features);
     virBufferAdjustIndent(buf, -2);
     virBufferAsprintf(buf, "</%s>\n", type);
     return 0;
diff --git a/src/conf/storage_feature_conf.c b/src/conf/storage_feature_conf.c
index 77e6406..2a4b3df 100644
--- a/src/conf/storage_feature_conf.c
+++ b/src/conf/storage_feature_conf.c
@@ -60,3 +60,28 @@ int virStorageFeaturesParse(xmlXPathContextPtr ctxt,
     VIR_FREE(feat_xpath);
     return ret;
 }
+
+void virStorageFeaturesFormat(virBufferPtr buf,
+                              virBitmapPtr features)
+{
+    size_t i;
+
+    if (!features)
+        return;
+
+    if (virBitmapIsAllClear(features)) {
+        virBufferAddLit(buf, "<features/>\n");
+        return;
+    }
+    virBufferAddLit(buf, "<features>\n");
+    virBufferAdjustIndent(buf, 2);
+
+    for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) {
+        if (virBitmapIsBitSet(features, i))
+            virBufferAsprintf(buf, "<%s/>\n",
+                              virStorageFileFeatureTypeToString(i));
+    }
+
+    virBufferAdjustIndent(buf, -2);
+    virBufferAddLit(buf, "</features>\n");
+}
diff --git a/src/conf/storage_feature_conf.h b/src/conf/storage_feature_conf.h
index a411b66..14de20e 100644
--- a/src/conf/storage_feature_conf.h
+++ b/src/conf/storage_feature_conf.h
@@ -12,11 +12,14 @@
 # include "internal.h"
 
 # include "virbitmap.h"
+# include "virbuffer.h"
 # include "virxml.h"
 
 int virStorageFeaturesParse(xmlXPathContextPtr ctxt,
                             const char *xpath,
                             char **compat,
                             virBitmapPtr *features);
+void virStorageFeaturesFormat(virBufferPtr buf,
+                              virBitmapPtr features);
 
 #endif /* __VIR_STORAGE_FEATURE_CONF_H__ */
-- 
2.0.5


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