[PATCH v4 9/9] remove virDomainCpuSetFormat and virDomainCpuSetParse

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

 



virBitmap is recommanded to store cpuset info, and
virBitmapFormat/virBitmapParse can do the format/parse
jobs.
---
 src/conf/domain_conf.c   |  196 ----------------------------------------------
 src/conf/domain_conf.h   |    7 --
 src/libvirt_private.syms |    2 -
 3 files changed, 205 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6ecec54..5ecbe20 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -40,7 +40,6 @@
 #include "uuid.h"
 #include "util.h"
 #include "buf.h"
-#include "c-ctype.h"
 #include "logging.h"
 #include "nwfilter_conf.h"
 #include "storage_file.h"
@@ -10852,201 +10851,6 @@ int virDomainDefAddImplicitControllers(virDomainDefPtr def)
     return 0;
 }
 
-
-/************************************************************************
- *                                                                        *
- * Parser and converter for the CPUset strings used in libvirt                *
- *                                                                        *
- ************************************************************************/
-/**
- * virDomainCpuNumberParse
- * @str: pointer to the char pointer used
- * @maxcpu: maximum CPU number allowed
- *
- * Parse a CPU number
- *
- * Returns the CPU number or -1 in case of error. @str will be
- *         updated to skip the number.
- */
-static int
-virDomainCpuNumberParse(const char **str, int maxcpu)
-{
-    int ret = 0;
-    const char *cur = *str;
-
-    if (!c_isdigit(*cur))
-        return -1;
-
-    while (c_isdigit(*cur)) {
-        ret = ret * 10 + (*cur - '0');
-        if (ret >= maxcpu)
-            return -1;
-        cur++;
-    }
-    *str = cur;
-    return ret;
-}
-
-/**
- * virDomainCpuSetFormat:
- * @conn: connection
- * @cpuset: pointer to a char array for the CPU set
- * @maxcpu: number of elements available in @cpuset
- *
- * Serialize the cpuset to a string
- *
- * Returns the new string NULL in case of error. The string needs to be
- *         freed by the caller.
- */
-char *
-virDomainCpuSetFormat(char *cpuset, int maxcpu)
-{
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-    int start, cur;
-    int first = 1;
-
-    if (!cpuset || maxcpu <= 0 || maxcpu > 100000)
-        return NULL;
-
-    cur = 0;
-    start = -1;
-    while (cur < maxcpu) {
-        if (cpuset[cur]) {
-            if (start == -1)
-                start = cur;
-        } else if (start != -1) {
-            if (!first)
-                virBufferAddLit(&buf, ",");
-            else
-                first = 0;
-            if (cur == start + 1)
-                virBufferAsprintf(&buf, "%d", start);
-            else
-                virBufferAsprintf(&buf, "%d-%d", start, cur - 1);
-            start = -1;
-        }
-        cur++;
-    }
-    if (start != -1) {
-        if (!first)
-            virBufferAddLit(&buf, ",");
-        if (maxcpu == start + 1)
-            virBufferAsprintf(&buf, "%d", start);
-        else
-            virBufferAsprintf(&buf, "%d-%d", start, maxcpu - 1);
-    }
-
-    if (virBufferError(&buf)) {
-        virBufferFreeAndReset(&buf);
-        virReportOOMError();
-        return NULL;
-    }
-
-    return virBufferContentAndReset(&buf);
-}
-
-/**
- * virDomainCpuSetParse:
- * @conn: connection
- * @str: a CPU set string pointer
- * @sep: potential character used to mark the end of string if not 0
- * @cpuset: pointer to a char array for the CPU set
- * @maxcpu: number of elements available in @cpuset
- *
- * Parse the cpu set, it will set the value for enabled CPUs in the @cpuset
- * to 1, and 0 otherwise. The syntax allows comma separated entries; each
- * can be either a CPU number, ^N to unset that CPU, or N-M for ranges.
- *
- * Returns the number of CPU found in that set, or -1 in case of error.
- *         @cpuset is modified accordingly to the value parsed.
- */
-int
-virDomainCpuSetParse(const char *str, char sep,
-                     char *cpuset, int maxcpu)
-{
-    const char *cur;
-    int ret = 0;
-    int i, start, last;
-    int neg = 0;
-
-    if (!str || !cpuset || maxcpu <= 0 || maxcpu > 100000)
-        return -1;
-
-    cur = str;
-    virSkipSpaces(&cur);
-    if (*cur == 0)
-        goto parse_error;
-
-    /* initialize cpumap to all 0s */
-    for (i = 0; i < maxcpu; i++)
-        cpuset[i] = 0;
-    ret = 0;
-
-    while (*cur != 0 && *cur != sep) {
-        /*
-         * 3 constructs are allowed:
-         *     - N   : a single CPU number
-         *     - N-M : a range of CPU numbers with N < M
-         *     - ^N  : remove a single CPU number from the current set
-         */
-        if (*cur == '^') {
-            cur++;
-            neg = 1;
-        }
-
-        if (!c_isdigit(*cur))
-            goto parse_error;
-        start = virDomainCpuNumberParse(&cur, maxcpu);
-        if (start < 0)
-            goto parse_error;
-        virSkipSpaces(&cur);
-        if (*cur == ',' || *cur == 0 || *cur == sep) {
-            if (neg) {
-                if (cpuset[start] == 1) {
-                    cpuset[start] = 0;
-                    ret--;
-                }
-            } else {
-                if (cpuset[start] == 0) {
-                    cpuset[start] = 1;
-                    ret++;
-                }
-            }
-        } else if (*cur == '-') {
-            if (neg)
-                goto parse_error;
-            cur++;
-            virSkipSpaces(&cur);
-            last = virDomainCpuNumberParse(&cur, maxcpu);
-            if (last < start)
-                goto parse_error;
-            for (i = start; i <= last; i++) {
-                if (cpuset[i] == 0) {
-                    cpuset[i] = 1;
-                    ret++;
-                }
-            }
-            virSkipSpaces(&cur);
-        }
-        if (*cur == ',') {
-            cur++;
-            virSkipSpaces(&cur);
-            neg = 0;
-        } else if (*cur == 0 || *cur == sep) {
-            break;
-        } else {
-            goto parse_error;
-        }
-    }
-    return ret;
-
-  parse_error:
-    virReportError(VIR_ERR_INTERNAL_ERROR,
-                   "%s", _("topology cpuset syntax error"));
-    return -1;
-}
-
-
 /* Check if vcpupin with same vcpuid already exists.
  * Return 1 if exists, 0 if not. */
 int
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 042b518..bbec034 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1899,13 +1899,6 @@ int virDomainDefFormatInternal(virDomainDefPtr def,
 int virDomainDefCompatibleDevice(virDomainDefPtr def,
                                  virDomainDeviceDefPtr dev);
 
-int virDomainCpuSetParse(const char *str,
-                         char sep,
-                         char *cpuset,
-                         int maxcpu);
-char *virDomainCpuSetFormat(char *cpuset,
-                            int maxcpu);
-
 int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list,
                         int *nvcpupin,
                         unsigned char *cpumap,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b61157e..555b946 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -307,8 +307,6 @@ virDomainControllerRemove;
 virDomainControllerTypeToString;
 virDomainCpuPlacementModeTypeFromString;
 virDomainCpuPlacementModeTypeToString;
-virDomainCpuSetFormat;
-virDomainCpuSetParse;
 virDomainDefAddImplicitControllers;
 virDomainDefCheckABIStability;
 virDomainDefClearDeviceAliases;
-- 
1.7.10.2

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