[PATCH 2/5] Introduce virBitmapParseSeparator

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

 



This will be used for the caller that needs to specify a separator.
Currently identical to virBitmapParse.
---
 src/libvirt_private.syms |  1 +
 src/util/virbitmap.c     | 41 ++++++++++++++++++++++++++++++++++++-----
 src/util/virbitmap.h     |  5 +++++
 src/xen/xend_internal.c  |  2 +-
 tests/virbitmaptest.c    |  2 +-
 5 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index af30476..a88a3d1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1206,6 +1206,7 @@ virBitmapNextClearBit;
 virBitmapNextSetBit;
 virBitmapOverlaps;
 virBitmapParse;
+virBitmapParseSeparator;
 virBitmapSetAll;
 virBitmapSetBit;
 virBitmapSetBitExpand;
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index 7e9f3fd..139e3ba 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -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;
@@ -520,6 +520,37 @@ virBitmapParse(const char *str,
 }
 
 /**
+ * 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.
  *
diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h
index 79f53dd..79922ea 100644
--- a/src/util/virbitmap.h
+++ b/src/util/virbitmap.h
@@ -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);
 
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 21ccff9..605c3cd 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -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);
diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c
index 00369af..5fa13c2 100644
--- a/tests/virbitmaptest.c
+++ b/tests/virbitmaptest.c
@@ -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)
-- 
2.7.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]