]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Introduce virBitmapParseSeparator
authorJán Tomko <jtomko@redhat.com>
Fri, 17 Jun 2016 12:38:11 +0000 (14:38 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 20 Jun 2016 10:09:39 +0000 (12:09 +0200)
This will be used for the caller that needs to specify a separator.
Currently identical to virBitmapParse.

Also change one test case to use the new function.

src/libvirt_private.syms
src/util/virbitmap.c
src/util/virbitmap.h
src/xen/xend_internal.c
tests/virbitmaptest.c

index f62dd705f66a68e50d7bf88771146609eba01a12..0106afe8a2f625813d7547b237578c9c2b7bbc19 100644 (file)
@@ -1207,6 +1207,7 @@ virBitmapNextClearBit;
 virBitmapNextSetBit;
 virBitmapOverlaps;
 virBitmapParse;
+virBitmapParseSeparator;
 virBitmapSetAll;
 virBitmapSetBit;
 virBitmapSetBitExpand;
index 7e9f3fd199b4891ca17e0311efd3732768fcb0cd..139e3ba18a27caf39ba71f42035f6723f2598999 100644 (file)
@@ -400,7 +400,7 @@ char *virBitmapFormat(virBitmapPtr bitmap)
 }
 
 /**
- * virBitmapParse:
+ * virBitmapParseSeparator:
  * @str: points to a string representing a human-readable bitmap
  * @terminator: character separating the bitmap to parse
  * @bitmap: a bitmap created from @str
@@ -422,10 +422,10 @@ char *virBitmapFormat(virBitmapPtr bitmap)
  * Returns 0 on success, or -1 in case of error.
  */
 int
-virBitmapParse(const char *str,
-               char terminator,
-               virBitmapPtr *bitmap,
-               size_t bitmapSize)
+virBitmapParseSeparator(const char *str,
+                        char terminator,
+                        virBitmapPtr *bitmap,
+                        size_t bitmapSize)
 {
     bool neg = false;
     const char *cur = str;
@@ -519,6 +519,37 @@ virBitmapParse(const char *str,
     return -1;
 }
 
+/**
+ * virBitmapParse:
+ * @str: points to a string representing a human-readable bitmap
+ * @terminator: character separating the bitmap to parse
+ * @bitmap: a bitmap created from @str
+ * @bitmapSize: the upper limit of num of bits in created bitmap
+ *
+ * This function is the counterpart of virBitmapFormat. This function creates
+ * a bitmap, in which bits are set according to the content of @str.
+ *
+ * @str is a comma separated string of fields N, which means a number of bit
+ * to set, and ^N, which means to unset the bit, and N-M for ranges of bits
+ * to set.
+ *
+ * To allow parsing of bitmaps within larger strings it is possible to set
+ * a termination character in the argument @terminator. When the character
+ * in @terminator is encountered in @str, the parsing of the bitmap stops.
+ * Pass 0 as @terminator if it is not needed. Whitespace characters may not
+ * be used as terminators.
+ *
+ * Returns 0 on success, or -1 in case of error.
+ */
+int
+virBitmapParse(const char *str,
+               char terminator,
+               virBitmapPtr *bitmap,
+               size_t bitmapSize)
+{
+    return virBitmapParseSeparator(str, terminator, bitmap, bitmapSize);
+}
+
 /**
  * virBitmapNewCopy:
  * @src: the source bitmap.
index 79f53dd37832f0bcf50a8c0a28df06c95611a102..79922ea782d9484c8ac0bdbd433200bccd8c959f 100644 (file)
@@ -90,6 +90,11 @@ int virBitmapParse(const char *str,
                    virBitmapPtr *bitmap,
                    size_t bitmapSize)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
+int
+virBitmapParseSeparator(const char *str,
+                        char terminator,
+                        virBitmapPtr *bitmap,
+                        size_t bitmapSize);
 
 virBitmapPtr virBitmapNewCopy(virBitmapPtr src) ATTRIBUTE_NONNULL(1);
 
index 21ccff93c3ec6fd345e956abddc8a6e585064a4e..605c3cdccf2adb8ea4acdff6ddc1953611f6b474 100644 (file)
@@ -1049,7 +1049,7 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps)
             if (!(cpuset = virBitmapNew(numCpus)))
                 goto error;
         } else {
-            if (virBitmapParse(cur, 'n', &cpuset, numCpus) < 0)
+            if (virBitmapParseSeparator(cur, 'n', &cpuset, numCpus) < 0)
                 goto error;
 
             nb_cpus = virBitmapCountBits(cpuset);
index 00369aff10db0c03b383b0d81ee441f13b2e66d0..5fa13c27ff4867bb22a50639897865be3c9400af 100644 (file)
@@ -526,7 +526,7 @@ test10(const void *opaque ATTRIBUTE_UNUSED)
     int ret = -1;
     virBitmapPtr b1 = NULL, b2 = NULL, b3 = NULL, b4 = NULL;
 
-    if (virBitmapParse("0-3,5-8,11-15", 0, &b1, 20) < 0 ||
+    if (virBitmapParseSeparator("0-3,5-8,11-15f16", 'f', &b1, 20) < 0 ||
         virBitmapParse("4,9,10,16-19", 0, &b2, 20) < 0 ||
         virBitmapParse("15", 0, &b3, 20) < 0 ||
         virBitmapParse("0,^0", 0, &b4, 20) < 0)