remove virDomainCpuSetFormat and virDomainCpuSetParse

virBitmap is recommanded to store cpuset info, and
virBitmapFormat/virBitmapParse can do the format/parse
jobs.
This commit is contained in:
Hu Tao 2012-09-14 15:47:04 +08:00 committed by Laine Stump
parent 58d372d441
commit afe869819f
3 changed files with 0 additions and 205 deletions

View File

@ -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"
@ -11177,201 +11176,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

View File

@ -1930,13 +1930,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,

View File

@ -309,8 +309,6 @@ virDomainControllerRemove;
virDomainControllerTypeToString;
virDomainCpuPlacementModeTypeFromString;
virDomainCpuPlacementModeTypeToString;
virDomainCpuSetFormat;
virDomainCpuSetParse;
virDomainDefAddImplicitControllers;
virDomainDefCheckABIStability;
virDomainDefClearDeviceAliases;