[PATCH 1/6] conf: Introduce virStoragePoolDefFormatBuf

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

 



When modifying config/status XML, it might be handy to include some
additional XML elements (e.g. <poolstatus>). In order to do so,
introduce new formatting function virStoragePoolDefFormatBuf and make
virStoragePoolDefFormat call it.
---
 src/conf/storage_conf.c | 78 +++++++++++++++++++++++++++++--------------------
 1 file changed, 46 insertions(+), 32 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index b070448..a8e9876 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1150,76 +1150,90 @@ virStoragePoolSourceFormat(virBufferPtr buf,
 }
 
 
-char *
-virStoragePoolDefFormat(virStoragePoolDefPtr def)
+static int
+virStoragePoolDefFormatBuf(virBufferPtr buf,
+                           virStoragePoolDefPtr def)
 {
     virStoragePoolOptionsPtr options;
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-    const char *type;
     char uuid[VIR_UUID_STRING_BUFLEN];
+    const char *type;
 
     options = virStoragePoolOptionsForPoolType(def->type);
     if (options == NULL)
-        return NULL;
+        goto error;
 
     type = virStoragePoolTypeToString(def->type);
     if (!type) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("unexpected pool type"));
-        goto cleanup;
+        goto error;
     }
-    virBufferAsprintf(&buf, "<pool type='%s'>\n", type);
-    virBufferAdjustIndent(&buf, 2);
-    virBufferEscapeString(&buf, "<name>%s</name>\n", def->name);
+    virBufferAsprintf(buf, "<pool type='%s'>\n", type);
+    virBufferAdjustIndent(buf, 2);
+    virBufferEscapeString(buf, "<name>%s</name>\n", def->name);
 
     virUUIDFormat(def->uuid, uuid);
-    virBufferAsprintf(&buf, "<uuid>%s</uuid>\n", uuid);
+    virBufferAsprintf(buf, "<uuid>%s</uuid>\n", uuid);
 
-    virBufferAsprintf(&buf, "<capacity unit='bytes'>%llu</capacity>\n",
+    virBufferAsprintf(buf, "<capacity unit='bytes'>%llu</capacity>\n",
                       def->capacity);
-    virBufferAsprintf(&buf, "<allocation unit='bytes'>%llu</allocation>\n",
+    virBufferAsprintf(buf, "<allocation unit='bytes'>%llu</allocation>\n",
                       def->allocation);
-    virBufferAsprintf(&buf, "<available unit='bytes'>%llu</available>\n",
+    virBufferAsprintf(buf, "<available unit='bytes'>%llu</available>\n",
                       def->available);
 
-    if (virStoragePoolSourceFormat(&buf, options, &def->source) < 0)
-        goto cleanup;
+    if (virStoragePoolSourceFormat(buf, options, &def->source) < 0)
+        goto error;
 
     /* RBD, Sheepdog, and Gluster devices are not local block devs nor
      * files, so they don't have a target */
     if (def->type != VIR_STORAGE_POOL_RBD &&
         def->type != VIR_STORAGE_POOL_SHEEPDOG &&
         def->type != VIR_STORAGE_POOL_GLUSTER) {
-        virBufferAddLit(&buf, "<target>\n");
-        virBufferAdjustIndent(&buf, 2);
+        virBufferAddLit(buf, "<target>\n");
+        virBufferAdjustIndent(buf, 2);
 
-        virBufferEscapeString(&buf, "<path>%s</path>\n", def->target.path);
+        virBufferEscapeString(buf, "<path>%s</path>\n", def->target.path);
 
-        virBufferAddLit(&buf, "<permissions>\n");
-        virBufferAdjustIndent(&buf, 2);
-        virBufferAsprintf(&buf, "<mode>0%o</mode>\n",
+        virBufferAddLit(buf, "<permissions>\n");
+        virBufferAdjustIndent(buf, 2);
+        virBufferAsprintf(buf, "<mode>0%o</mode>\n",
                           def->target.perms.mode);
-        virBufferAsprintf(&buf, "<owner>%d</owner>\n",
+        virBufferAsprintf(buf, "<owner>%d</owner>\n",
                           (int) def->target.perms.uid);
-        virBufferAsprintf(&buf, "<group>%d</group>\n",
+        virBufferAsprintf(buf, "<group>%d</group>\n",
                           (int) def->target.perms.gid);
-        virBufferEscapeString(&buf, "<label>%s</label>\n",
+        virBufferEscapeString(buf, "<label>%s</label>\n",
                               def->target.perms.label);
 
-        virBufferAdjustIndent(&buf, -2);
-        virBufferAddLit(&buf, "</permissions>\n");
-        virBufferAdjustIndent(&buf, -2);
-        virBufferAddLit(&buf, "</target>\n");
+        virBufferAdjustIndent(buf, -2);
+        virBufferAddLit(buf, "</permissions>\n");
+        virBufferAdjustIndent(buf, -2);
+        virBufferAddLit(buf, "</target>\n");
     }
-    virBufferAdjustIndent(&buf, -2);
-    virBufferAddLit(&buf, "</pool>\n");
+    virBufferAdjustIndent(buf, -2);
+    virBufferAddLit(buf, "</pool>\n");
+
+    return 0;
+
+ error:
+    return -1;
+}
+
+char *
+virStoragePoolDefFormat(virStoragePoolDefPtr def)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    if (virStoragePoolDefFormatBuf(&buf, def) < 0)
+        goto error;
 
     if (virBufferCheckError(&buf) < 0)
-        goto cleanup;
+        goto error;
 
     return virBufferContentAndReset(&buf);
 
- cleanup:
+ error:
     virBufferFreeAndReset(&buf);
     return NULL;
 }
-- 
1.9.3

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