[PATCH 2/3] virNodeDeviceCapStorageDefFormat: Extract formatting of block size data

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

 



Unfortunately the XML is designed in a weird way, where based on whether
media in the device is removable the sizing is either part of a
subelement or placed directly on top level. The logic itself is
identical so it can be extracted into a function to simplify the
formatter.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/node_device_conf.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 64bece59aa..3af5c3b7ed 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -536,6 +536,20 @@ virNodeDeviceCapSCSIDefFormat(virBuffer *buf,
 }


+static void
+virNodeDeviceCapStorageDefFormatBlocksize(virBuffer *buf,
+                                          const virNodeDevCapData *data)
+{
+    if (data->storage.logical_block_size > 0)
+        virBufferAsprintf(buf, "<logical_block_size>%llu</logical_block_size>\n",
+                          data->storage.logical_block_size);
+
+    if (data->storage.num_blocks > 0)
+        virBufferAsprintf(buf, "<num_blocks>%llu</num_blocks>\n",
+                          data->storage.num_blocks);
+}
+
+
 static void
 virNodeDeviceCapStorageDefFormat(virBuffer *buf,
                                  const virNodeDevCapData *data)
@@ -557,27 +571,14 @@ virNodeDeviceCapStorageDefFormat(virBuffer *buf,
         virBufferAsprintf(buf, "<media_size>%llu</media_size>\n",
                           data->storage.removable_media_size);
         virBufferEscapeString(buf, "<media_label>%s</media_label>\n", data->storage.media_label);
-        if (data->storage.logical_block_size > 0)
-            virBufferAsprintf(buf, "<logical_block_size>%llu"
-                              "</logical_block_size>\n",
-                              data->storage.logical_block_size);
-        if (data->storage.num_blocks > 0)
-            virBufferAsprintf(buf,
-                              "<num_blocks>%llu</num_blocks>\n",
-                              data->storage.num_blocks);
+        virNodeDeviceCapStorageDefFormatBlocksize(buf, data);
         virBufferAdjustIndent(buf, -2);
         virBufferAddLit(buf, "</capability>\n");
     } else {
-        virBufferAsprintf(buf, "<size>%llu</size>\n",
-                          data->storage.size);
-        if (data->storage.logical_block_size > 0)
-            virBufferAsprintf(buf, "<logical_block_size>%llu"
-                              "</logical_block_size>\n",
-                              data->storage.logical_block_size);
-        if (data->storage.num_blocks > 0)
-            virBufferAsprintf(buf, "<num_blocks>%llu</num_blocks>\n",
-                              data->storage.num_blocks);
+        virBufferAsprintf(buf, "<size>%llu</size>\n", data->storage.size);
+        virNodeDeviceCapStorageDefFormatBlocksize(buf, data);
     }
+
     if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE)
         virBufferAddLit(buf, "<capability type='hotpluggable'/>\n");
 }
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




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

  Powered by Linux