]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemublocktest: Extract printing of nodename list
authorPeter Krempa <pkrempa@redhat.com>
Tue, 2 Jun 2020 07:11:36 +0000 (09:11 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 22 Jun 2020 14:04:30 +0000 (16:04 +0200)
There will be multiple places where we'll need to print nodenames from a
GSList of virStorageSource for testing purposes. Extract the code into a
function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
tests/qemublocktest.c

index 28cbaeba38dde0e778f4f448015da34c3a1dfa45..0ed9b99bc4c3332633ff6d2408df2a129c5baafa 100644 (file)
@@ -647,6 +647,23 @@ testQemuDetectBitmaps(const void *opaque)
 }
 
 
+static void
+testQemuBitmapListPrint(const char *title,
+                        GSList *next,
+                        virBufferPtr buf)
+{
+    if (!next)
+        return;
+
+    virBufferAsprintf(buf, "%s\n", title);
+
+    for (; next; next = next->next) {
+        virStorageSourcePtr src = next->data;
+        virBufferAsprintf(buf, "%s\n", src->nodeformat);
+    }
+}
+
+
 static virStorageSourcePtr
 testQemuBackupIncrementalBitmapCalculateGetFakeImage(size_t idx)
 {
@@ -829,7 +846,6 @@ testQemuCheckpointDeleteMerge(const void *opaque)
     g_autoptr(virHashTable) nodedata = NULL;
     g_autoptr(GSList) reopenimages = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    GSList *tmp;
 
     expectpath = g_strdup_printf("%s/%s%s-out.json", abs_srcdir,
                                  checkpointDeletePrefix, data->name);
@@ -858,14 +874,7 @@ testQemuCheckpointDeleteMerge(const void *opaque)
         virBufferAddLit(&buf, "NULL\n");
     }
 
-    if (reopenimages) {
-        virBufferAddLit(&buf, "reopen nodes:\n");
-
-        for (tmp = reopenimages; tmp; tmp = tmp->next) {
-            virStorageSourcePtr src = tmp->data;
-            virBufferAsprintf(&buf, "%s\n", src->nodeformat);
-        }
-    }
+    testQemuBitmapListPrint("reopen nodes:", reopenimages, &buf);
 
     actual = virBufferContentAndReset(&buf);