1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

Whiteclean/indentation cleanup/fixup. No functional change

This commit is contained in:
Daniel P. Berrange 2007-02-07 13:50:18 +00:00
parent 4a89182077
commit 85535863c5
2 changed files with 416 additions and 408 deletions

View File

@ -84,7 +84,7 @@ virshErrorHandler(void *unused, virErrorPtr error)
* bool_option = --optionname * bool_option = --optionname
* int_option = --optionname <number> * int_option = --optionname <number>
* string_option = --optionname <string> * string_option = --optionname <string>
* *
* keyword = [a-zA-Z] * keyword = [a-zA-Z]
* number = [0-9]+ * number = [0-9]+
* string = [^[:blank:]] | "[[:alnum:]]"$ * string = [^[:blank:]] | "[[:alnum:]]"$
@ -92,7 +92,7 @@ virshErrorHandler(void *unused, virErrorPtr error)
*/ */
/* /*
* vshCmdOptType - command option type * vshCmdOptType - command option type
*/ */
typedef enum { typedef enum {
VSH_OT_NONE = 0, /* none */ VSH_OT_NONE = 0, /* none */
@ -199,12 +199,12 @@ static int vshCommandOptBool(vshCmd * cmd, const char *name);
#define VSH_DOMBYNAME (1 << 3) #define VSH_DOMBYNAME (1 << 3)
static virDomainPtr vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd, static virDomainPtr vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd,
const char *optname, char **name, int flag); const char *optname, char **name, int flag);
/* default is lookup by Id, Name and UUID */ /* default is lookup by Id, Name and UUID */
#define vshCommandOptDomain(_ctl, _cmd, _optname, _name) \ #define vshCommandOptDomain(_ctl, _cmd, _optname, _name) \
vshCommandOptDomainBy(_ctl, _cmd, _optname, _name,\ vshCommandOptDomainBy(_ctl, _cmd, _optname, _name, \
VSH_DOMBYID|VSH_DOMBYUUID|VSH_DOMBYNAME) VSH_DOMBYID|VSH_DOMBYUUID|VSH_DOMBYNAME)
static void vshPrintExtra(vshControl * ctl, const char *format, ...); static void vshPrintExtra(vshControl * ctl, const char *format, ...);
static void vshDebug(vshControl * ctl, int level, const char *format, ...); static void vshDebug(vshControl * ctl, int level, const char *format, ...);
@ -232,7 +232,7 @@ static char *_vshStrdup(vshControl * ctl, const char *s, const char *filename, i
*/ */
/* /*
* "help" command * "help" command
*/ */
static vshCmdInfo info_help[] = { static vshCmdInfo info_help[] = {
{"syntax", "help [<command>]"}, {"syntax", "help [<command>]"},
@ -265,7 +265,7 @@ cmdHelp(vshControl * ctl, vshCmd * cmd)
} }
/* /*
* "connect" command * "connect" command
*/ */
static vshCmdInfo info_connect[] = { static vshCmdInfo info_connect[] = {
{"syntax", "connect [name] [--readonly]"}, {"syntax", "connect [name] [--readonly]"},
@ -285,7 +285,7 @@ static int
cmdConnect(vshControl * ctl, vshCmd * cmd) cmdConnect(vshControl * ctl, vshCmd * cmd)
{ {
int ro = vshCommandOptBool(cmd, "readonly"); int ro = vshCommandOptBool(cmd, "readonly");
if (ctl->conn) { if (ctl->conn) {
if (virConnectClose(ctl->conn) != 0) { if (virConnectClose(ctl->conn) != 0) {
vshError(ctl, FALSE, vshError(ctl, FALSE,
@ -294,7 +294,7 @@ cmdConnect(vshControl * ctl, vshCmd * cmd)
} }
ctl->conn = NULL; ctl->conn = NULL;
} }
if (ctl->name) if (ctl->name)
free(ctl->name); free(ctl->name);
ctl->name = vshStrdup(ctl, vshCommandOptString(cmd, "name", NULL)); ctl->name = vshStrdup(ctl, vshCommandOptString(cmd, "name", NULL));
@ -311,7 +311,7 @@ cmdConnect(vshControl * ctl, vshCmd * cmd)
} }
/* /*
* "console" command * "console" command
*/ */
static vshCmdInfo info_console[] = { static vshCmdInfo info_console[] = {
{"syntax", "console <domain>"}, {"syntax", "console <domain>"},
@ -344,11 +344,11 @@ cmdConsole(vshControl * ctl, vshCmd * cmd)
doc = virDomainGetXMLDesc(dom, 0); doc = virDomainGetXMLDesc(dom, 0);
if (!doc) if (!doc)
goto cleanup; goto cleanup;
xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL, xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOWARNING); XML_PARSE_NOWARNING);
free(doc); free(doc);
if (!xml) if (!xml)
goto cleanup; goto cleanup;
@ -358,7 +358,7 @@ cmdConsole(vshControl * ctl, vshCmd * cmd)
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/console/@tty)", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/devices/console/@tty)", ctxt);
if ((obj != NULL) && ((obj->type == XPATH_STRING) && if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0))) { (obj->stringval != NULL) && (obj->stringval[0] != 0))) {
if (vshRunConsole((const char *)obj->stringval) == 0) if (vshRunConsole((const char *)obj->stringval) == 0)
ret = TRUE; ret = TRUE;
} else { } else {
@ -393,20 +393,20 @@ static vshCmdOptDef opts_list[] = {
static int domidsorter(const void *a, const void *b) { static int domidsorter(const void *a, const void *b) {
const int *ia = (const int *)a; const int *ia = (const int *)a;
const int *ib = (const int *)b; const int *ib = (const int *)b;
if (*ia > *ib) if (*ia > *ib)
return 1; return 1;
else if (*ia < *ib) else if (*ia < *ib)
return -1; return -1;
return 0; return 0;
} }
static int domnamesorter(const void *a, const void *b) { static int domnamesorter(const void *a, const void *b) {
const char **sa = (const char**)a; const char **sa = (const char**)a;
const char **sb = (const char**)b; const char **sb = (const char**)b;
return strcasecmp(*sa, *sb); return strcasecmp(*sa, *sb);
} }
static int static int
cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED) cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
@ -421,46 +421,46 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (active) { if (active) {
maxid = virConnectNumOfDomains(ctl->conn); maxid = virConnectNumOfDomains(ctl->conn);
if (maxid < 0) { if (maxid < 0) {
vshError(ctl, FALSE, _("Failed to list active domains")); vshError(ctl, FALSE, _("Failed to list active domains"));
return FALSE; return FALSE;
} }
if (maxid) { if (maxid) {
ids = vshMalloc(ctl, sizeof(int) * maxid); ids = vshMalloc(ctl, sizeof(int) * maxid);
if ((maxid = virConnectListDomains(ctl->conn, &ids[0], maxid)) < 0) { if ((maxid = virConnectListDomains(ctl->conn, &ids[0], maxid)) < 0) {
vshError(ctl, FALSE, _("Failed to list active domains")); vshError(ctl, FALSE, _("Failed to list active domains"));
free(ids); free(ids);
return FALSE; return FALSE;
}
qsort(&ids[0], maxid, sizeof(int), domidsorter);
} }
qsort(&ids[0], maxid, sizeof(int), domidsorter);
}
} }
if (inactive) { if (inactive) {
maxname = virConnectNumOfDefinedDomains(ctl->conn); maxname = virConnectNumOfDefinedDomains(ctl->conn);
if (maxname < 0) { if (maxname < 0) {
vshError(ctl, FALSE, _("Failed to list inactive domains")); vshError(ctl, FALSE, _("Failed to list inactive domains"));
if (ids) if (ids)
free(ids); free(ids);
return FALSE; return FALSE;
}
if (maxname) {
names = vshMalloc(ctl, sizeof(char *) * maxname);
if ((maxname = virConnectListDefinedDomains(ctl->conn, names, maxname)) < 0) {
vshError(ctl, FALSE, _("Failed to list inactive domains"));
if (ids)
free(ids);
free(names);
return FALSE;
} }
if (maxname) {
names = vshMalloc(ctl, sizeof(char *) * maxname);
qsort(&names[0], maxname, sizeof(char*), domnamesorter); if ((maxname = virConnectListDefinedDomains(ctl->conn, names, maxname)) < 0) {
} vshError(ctl, FALSE, _("Failed to list inactive domains"));
if (ids)
free(ids);
free(names);
return FALSE;
}
qsort(&names[0], maxname, sizeof(char*), domnamesorter);
}
} }
vshPrintExtra(ctl, "%3s %-20s %s\n", _("Id"), _("Name"), _("State")); vshPrintExtra(ctl, "%3s %-20s %s\n", _("Id"), _("Name"), _("State"));
vshPrintExtra(ctl, "----------------------------------\n"); vshPrintExtra(ctl, "----------------------------------\n");
@ -490,28 +490,28 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
/* this kind of work with domains is not atomic operation */ /* this kind of work with domains is not atomic operation */
if (!dom) { if (!dom) {
free(names[i]); free(names[i]);
continue; continue;
} }
ret = virDomainGetInfo(dom, &info); ret = virDomainGetInfo(dom, &info);
id = virDomainGetID(dom); id = virDomainGetID(dom);
if (id == ((unsigned int)-1)) { if (id == ((unsigned int)-1)) {
vshPrint(ctl, "%3s %-20s %s\n", vshPrint(ctl, "%3s %-20s %s\n",
"-", "-",
names[i], names[i],
ret < ret <
0 ? "no state" : vshDomainStateToString(info.state)); 0 ? "no state" : vshDomainStateToString(info.state));
} else { } else {
vshPrint(ctl, "%3d %-20s %s\n", vshPrint(ctl, "%3d %-20s %s\n",
id, id,
names[i], names[i],
ret < ret <
0 ? "no state" : vshDomainStateToString(info.state)); 0 ? "no state" : vshDomainStateToString(info.state));
} }
virDomainFree(dom); virDomainFree(dom);
free(names[i]); free(names[i]);
} }
if (ids) if (ids)
free(ids); free(ids);
@ -789,7 +789,7 @@ cmdStart(vshControl * ctl, vshCmd * cmd)
vshPrint(ctl, _("Domain %s started\n"), vshPrint(ctl, _("Domain %s started\n"),
name); name);
} else { } else {
vshError(ctl, FALSE, _("Failed to start domain %s"), name); vshError(ctl, FALSE, _("Failed to start domain %s"), name);
ret = FALSE; ret = FALSE;
} }
return ret; return ret;
@ -1110,9 +1110,9 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd)
id = virDomainGetID(dom); id = virDomainGetID(dom);
if (id == ((unsigned int)-1)) if (id == ((unsigned int)-1))
vshPrint(ctl, "%-15s %s\n", _("Id:"), "-"); vshPrint(ctl, "%-15s %s\n", _("Id:"), "-");
else else
vshPrint(ctl, "%-15s %d\n", _("Id:"), id); vshPrint(ctl, "%-15s %d\n", _("Id:"), id);
vshPrint(ctl, "%-15s %s\n", _("Name:"), virDomainGetName(dom)); vshPrint(ctl, "%-15s %s\n", _("Name:"), virDomainGetName(dom));
if (virDomainGetUUIDString(dom, &uuid[0])==0) if (virDomainGetUUIDString(dom, &uuid[0])==0)
@ -1130,7 +1130,7 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd)
vshPrint(ctl, "%-15s %d\n", _("CPU(s):"), info.nrVirtCpu); vshPrint(ctl, "%-15s %d\n", _("CPU(s):"), info.nrVirtCpu);
if (info.cpuTime != 0) { if (info.cpuTime != 0) {
double cpuUsed = info.cpuTime; double cpuUsed = info.cpuTime;
cpuUsed /= 1000000000.0; cpuUsed /= 1000000000.0;
@ -1139,7 +1139,7 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd)
vshPrint(ctl, "%-15s %lu kB\n", _("Max memory:"), vshPrint(ctl, "%-15s %lu kB\n", _("Max memory:"),
info.maxMem); info.maxMem);
vshPrint(ctl, "%-15s %lu kB\n", _("Used memory:"), vshPrint(ctl, "%-15s %lu kB\n", _("Used memory:"),
info.memory); info.memory);
} else { } else {
@ -1185,7 +1185,7 @@ cmdVcpuinfo(vshControl * ctl, vshCmd * cmd)
if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) { if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
virDomainFree(dom); virDomainFree(dom);
return FALSE; return FALSE;
} }
if (virDomainGetInfo(dom, &info) != 0) { if (virDomainGetInfo(dom, &info) != 0) {
@ -1197,32 +1197,32 @@ cmdVcpuinfo(vshControl * ctl, vshCmd * cmd)
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo)); cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
cpumap = malloc(info.nrVirtCpu * cpumaplen); cpumap = malloc(info.nrVirtCpu * cpumaplen);
if ((ncpus = virDomainGetVcpus(dom, if ((ncpus = virDomainGetVcpus(dom,
cpuinfo, info.nrVirtCpu, cpuinfo, info.nrVirtCpu,
cpumap, cpumaplen)) >= 0) { cpumap, cpumaplen)) >= 0) {
int n; int n;
for (n = 0 ; n < ncpus ; n++) { for (n = 0 ; n < ncpus ; n++) {
unsigned int m; unsigned int m;
vshPrint(ctl, "%-15s %d\n", _("VCPU:"), n); vshPrint(ctl, "%-15s %d\n", _("VCPU:"), n);
vshPrint(ctl, "%-15s %d\n", _("CPU:"), cpuinfo[n].cpu); vshPrint(ctl, "%-15s %d\n", _("CPU:"), cpuinfo[n].cpu);
vshPrint(ctl, "%-15s %s\n", _("State:"), vshPrint(ctl, "%-15s %s\n", _("State:"),
_N(vshDomainVcpuStateToString(cpuinfo[n].state))); _N(vshDomainVcpuStateToString(cpuinfo[n].state)));
if (cpuinfo[n].cpuTime != 0) { if (cpuinfo[n].cpuTime != 0) {
double cpuUsed = cpuinfo[n].cpuTime; double cpuUsed = cpuinfo[n].cpuTime;
cpuUsed /= 1000000000.0; cpuUsed /= 1000000000.0;
vshPrint(ctl, "%-15s %.1lfs\n", _("CPU time:"), cpuUsed); vshPrint(ctl, "%-15s %.1lfs\n", _("CPU time:"), cpuUsed);
} }
vshPrint(ctl, "%-15s ", _("CPU Affinity:")); vshPrint(ctl, "%-15s ", _("CPU Affinity:"));
for (m = 0 ; m < VIR_NODEINFO_MAXCPUS(nodeinfo) ; m++) { for (m = 0 ; m < VIR_NODEINFO_MAXCPUS(nodeinfo) ; m++) {
vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumap, cpumaplen, n, m) ? 'y' : '-'); vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumap, cpumaplen, n, m) ? 'y' : '-');
} }
vshPrint(ctl, "\n"); vshPrint(ctl, "\n");
if (n < (ncpus - 1)) { if (n < (ncpus - 1)) {
vshPrint(ctl, "\n"); vshPrint(ctl, "\n");
} }
} }
} else { } else {
ret = FALSE; ret = FALSE;
} }
@ -1279,7 +1279,7 @@ cmdVcpupin(vshControl * ctl, vshCmd * cmd)
virDomainFree(dom); virDomainFree(dom);
return FALSE; return FALSE;
} }
if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) { if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
virDomainFree(dom); virDomainFree(dom);
return FALSE; return FALSE;
@ -1543,8 +1543,8 @@ cmdDomname(vshControl * ctl, vshCmd * cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL, if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
VSH_DOMBYID|VSH_DOMBYUUID))) VSH_DOMBYID|VSH_DOMBYUUID)))
return FALSE; return FALSE;
vshPrint(ctl, "%s\n", virDomainGetName(dom)); vshPrint(ctl, "%s\n", virDomainGetName(dom));
@ -1574,15 +1574,15 @@ cmdDomid(vshControl * ctl, vshCmd * cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL, if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
VSH_DOMBYNAME|VSH_DOMBYUUID))) VSH_DOMBYNAME|VSH_DOMBYUUID)))
return FALSE; return FALSE;
id = virDomainGetID(dom); id = virDomainGetID(dom);
if (id == ((unsigned int)-1)) if (id == ((unsigned int)-1))
vshPrint(ctl, "%s\n", "-"); vshPrint(ctl, "%s\n", "-");
else else
vshPrint(ctl, "%d\n", id); vshPrint(ctl, "%d\n", id);
virDomainFree(dom); virDomainFree(dom);
return TRUE; return TRUE;
} }
@ -1610,7 +1610,7 @@ cmdDomuuid(vshControl * ctl, vshCmd * cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL, if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
VSH_DOMBYNAME|VSH_DOMBYID))) VSH_DOMBYNAME|VSH_DOMBYID)))
return FALSE; return FALSE;
if (virDomainGetUUIDString(dom, uuid) != -1) if (virDomainGetUUIDString(dom, uuid) != -1)
@ -1736,11 +1736,11 @@ cmdVNCDisplay(vshControl * ctl, vshCmd * cmd)
doc = virDomainGetXMLDesc(dom, 0); doc = virDomainGetXMLDesc(dom, 0);
if (!doc) if (!doc)
goto cleanup; goto cleanup;
xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL, xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOWARNING); XML_PARSE_NOWARNING);
free(doc); free(doc);
if (!xml) if (!xml)
goto cleanup; goto cleanup;
@ -1750,18 +1750,18 @@ cmdVNCDisplay(vshControl * ctl, vshCmd * cmd)
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/graphics[@type='vnc']/@port)", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/devices/graphics[@type='vnc']/@port)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) || if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) { (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
goto cleanup; goto cleanup;
} }
port = strtol((const char *)obj->stringval, NULL, 10); port = strtol((const char *)obj->stringval, NULL, 10);
if (port == -1) { if (port == -1) {
goto cleanup; goto cleanup;
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/graphics[@type='vnc']/@listen)", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/devices/graphics[@type='vnc']/@listen)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) || if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) { (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
goto cleanup; goto cleanup;
} }
if (!strcmp((const char*)obj->stringval, "0.0.0.0")) { if (!strcmp((const char*)obj->stringval, "0.0.0.0")) {
@ -1774,7 +1774,7 @@ cmdVNCDisplay(vshControl * ctl, vshCmd * cmd)
cleanup: cleanup:
if (obj) if (obj)
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
if (ctxt) if (ctxt)
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
if (xml) if (xml)
@ -1905,7 +1905,7 @@ vshCommandCheckOpts(vshControl * ctl, vshCmd * cmd)
vshError(ctl, FALSE, vshError(ctl, FALSE,
d->type == VSH_OT_DATA ? d->type == VSH_OT_DATA ?
_("command '%s' requires <%s> option") : _("command '%s' requires <%s> option") :
_("command '%s' requires --%s option"), _("command '%s' requires --%s option"),
def->name, d->name); def->name, d->name);
err = 1; err = 1;
} }
@ -2070,7 +2070,7 @@ vshCommandOptBool(vshCmd * cmd, const char *name)
static virDomainPtr static virDomainPtr
vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd, const char *optname, vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd, const char *optname,
char **name, int flag) char **name, int flag)
{ {
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
char *n, *end = NULL; char *n, *end = NULL;
@ -2099,7 +2099,7 @@ vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd, const char *optname,
/* try it by UUID */ /* try it by UUID */
if (dom==NULL && (flag & VSH_DOMBYUUID) && strlen(n)==VIR_UUID_STRING_BUFLEN-1) { if (dom==NULL && (flag & VSH_DOMBYUUID) && strlen(n)==VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, 5, "%s: <%s> tring as domain UUID\n", vshDebug(ctl, 5, "%s: <%s> tring as domain UUID\n",
cmd->def->name, optname); cmd->def->name, optname);
dom = virDomainLookupByUUIDString(ctl->conn, n); dom = virDomainLookupByUUIDString(ctl->conn, n);
} }
/* try it by NAME */ /* try it by NAME */
@ -2359,7 +2359,7 @@ vshCommandParse(vshControl * ctl, char *cmdstr)
return TRUE; return TRUE;
syntaxError: syntaxError:
if (ctl->cmd) if (ctl->cmd)
vshCommandFree(ctl->cmd); vshCommandFree(ctl->cmd);
if (first) if (first)
@ -2371,27 +2371,27 @@ vshCommandParse(vshControl * ctl, char *cmdstr)
/* --------------- /* ---------------
* Misc utils * Misc utils
* --------------- * ---------------
*/ */
static const char * static const char *
vshDomainStateToString(int state) vshDomainStateToString(int state)
{ {
switch (state) { switch (state) {
case VIR_DOMAIN_RUNNING: case VIR_DOMAIN_RUNNING:
return gettext_noop("running"); return gettext_noop("running");
case VIR_DOMAIN_BLOCKED: case VIR_DOMAIN_BLOCKED:
return gettext_noop("blocked"); return gettext_noop("blocked");
case VIR_DOMAIN_PAUSED: case VIR_DOMAIN_PAUSED:
return gettext_noop("paused"); return gettext_noop("paused");
case VIR_DOMAIN_SHUTDOWN: case VIR_DOMAIN_SHUTDOWN:
return gettext_noop("in shutdown"); return gettext_noop("in shutdown");
case VIR_DOMAIN_SHUTOFF: case VIR_DOMAIN_SHUTOFF:
return gettext_noop("shut off"); return gettext_noop("shut off");
case VIR_DOMAIN_CRASHED: case VIR_DOMAIN_CRASHED:
return gettext_noop("crashed"); return gettext_noop("crashed");
default: default:
return gettext_noop("no state"); /* = dom0 state */ return gettext_noop("no state"); /* = dom0 state */
} }
return NULL; return NULL;
} }
@ -2400,14 +2400,14 @@ static const char *
vshDomainVcpuStateToString(int state) vshDomainVcpuStateToString(int state)
{ {
switch (state) { switch (state) {
case VIR_VCPU_OFFLINE: case VIR_VCPU_OFFLINE:
return gettext_noop("offline"); return gettext_noop("offline");
case VIR_VCPU_BLOCKED: case VIR_VCPU_BLOCKED:
return gettext_noop("blocked"); return gettext_noop("blocked");
case VIR_VCPU_RUNNING: case VIR_VCPU_RUNNING:
return gettext_noop("running"); return gettext_noop("running");
default: default:
return gettext_noop("no state"); return gettext_noop("no state");
} }
return NULL; return NULL;
} }
@ -2415,8 +2415,8 @@ vshDomainVcpuStateToString(int state)
static int static int
vshConnectionUsability(vshControl * ctl, virConnectPtr conn, int showerror) vshConnectionUsability(vshControl * ctl, virConnectPtr conn, int showerror)
{ {
/* TODO: use something like virConnectionState() to /* TODO: use something like virConnectionState() to
* check usability of the connection * check usability of the connection
*/ */
if (!conn) { if (!conn) {
if (showerror) if (showerror)
@ -2484,7 +2484,7 @@ _vshMalloc(vshControl * ctl, size_t size, const char *filename, int line)
if ((x = malloc(size))) if ((x = malloc(size)))
return x; return x;
vshError(ctl, TRUE, _("%s: %d: failed to allocate %d bytes"), vshError(ctl, TRUE, _("%s: %d: failed to allocate %d bytes"),
filename, line, (int) size); filename, line, (int) size);
return NULL; return NULL;
} }
@ -2496,7 +2496,7 @@ _vshCalloc(vshControl * ctl, size_t nmemb, size_t size, const char *filename, in
if ((x = calloc(nmemb, size))) if ((x = calloc(nmemb, size)))
return x; return x;
vshError(ctl, TRUE, _("%s: %d: failed to allocate %d bytes"), vshError(ctl, TRUE, _("%s: %d: failed to allocate %d bytes"),
filename, line, (int) (size*nmemb)); filename, line, (int) (size*nmemb));
return NULL; return NULL;
} }
@ -2508,7 +2508,7 @@ _vshStrdup(vshControl * ctl, const char *s, const char *filename, int line)
if ((x = strdup(s))) if ((x = strdup(s)))
return x; return x;
vshError(ctl, TRUE, _("%s: %d: failed to allocate %d bytes"), vshError(ctl, TRUE, _("%s: %d: failed to allocate %d bytes"),
filename, line, strlen(s)); filename, line, strlen(s));
return NULL; return NULL;
} }
@ -2545,10 +2545,10 @@ vshInit(vshControl * ctl)
* ----------------- * -----------------
*/ */
/* /*
* Generator function for command completion. STATE lets us * Generator function for command completion. STATE lets us
* know whether to start from scratch; without any state * know whether to start from scratch; without any state
* (i.e. STATE == 0), then we start at the top of the list. * (i.e. STATE == 0), then we start at the top of the list.
*/ */
static char * static char *
vshReadlineCommandGenerator(const char *text, int state) vshReadlineCommandGenerator(const char *text, int state)
@ -2558,7 +2558,7 @@ vshReadlineCommandGenerator(const char *text, int state)
/* If this is a new word to complete, initialize now. This /* If this is a new word to complete, initialize now. This
* includes saving the length of TEXT for efficiency, and * includes saving the length of TEXT for efficiency, and
* initializing the index variable to 0. * initializing the index variable to 0.
*/ */
if (!state) { if (!state) {
list_index = 0; list_index = 0;
@ -2566,7 +2566,7 @@ vshReadlineCommandGenerator(const char *text, int state)
} }
/* Return the next name which partially matches from the /* Return the next name which partially matches from the
* command list. * command list.
*/ */
while ((name = commands[list_index].name)) { while ((name = commands[list_index].name)) {
list_index++; list_index++;
@ -2681,19 +2681,19 @@ vshUsage(vshControl * ctl, const char *cmdname)
/* global help */ /* global help */
if (!cmdname) { if (!cmdname) {
fprintf(stdout, _("\n%s [options] [commands]\n\n" fprintf(stdout, _("\n%s [options] [commands]\n\n"
" options:\n" " options:\n"
" -c | --connect <uri> hypervisor connection URI\n" " -c | --connect <uri> hypervisor connection URI\n"
" -d | --debug <num> debug level [0-5]\n" " -d | --debug <num> debug level [0-5]\n"
" -h | --help this help\n" " -h | --help this help\n"
" -q | --quiet quiet mode\n" " -q | --quiet quiet mode\n"
" -t | --timing print timing information\n" " -t | --timing print timing information\n"
" -v | --version program version\n\n" " -v | --version program version\n\n"
" commands (non interactive mode):\n"), progname); " commands (non interactive mode):\n"), progname);
for (cmd = commands; cmd->name; cmd++) for (cmd = commands; cmd->name; cmd++)
fprintf(stdout, fprintf(stdout,
" %-15s %s\n", cmd->name, _N(vshCmddefGetInfo(cmd, " %-15s %s\n", cmd->name, _N(vshCmddefGetInfo(cmd,
"help"))); "help")));
fprintf(stdout, fprintf(stdout,
_("\n (specify --help <command> for details about the command)\n\n")); _("\n (specify --help <command> for details about the command)\n\n"));
@ -2762,28 +2762,28 @@ vshParseArgv(vshControl * ctl, int argc, char **argv)
/* standard (non-command) options */ /* standard (non-command) options */
while ((arg = getopt_long(end, argv, "d:hqtcv", opt, &idx)) != -1) { while ((arg = getopt_long(end, argv, "d:hqtcv", opt, &idx)) != -1) {
switch (arg) { switch (arg) {
case 'd': case 'd':
ctl->debug = atoi(optarg); ctl->debug = atoi(optarg);
break; break;
case 'h': case 'h':
help = 1; help = 1;
break; break;
case 'q': case 'q':
ctl->quiet = TRUE; ctl->quiet = TRUE;
break; break;
case 't': case 't':
ctl->timing = TRUE; ctl->timing = TRUE;
break; break;
case 'c': case 'c':
ctl->name = vshStrdup(ctl, optarg); ctl->name = vshStrdup(ctl, optarg);
break; break;
case 'v': case 'v':
fprintf(stdout, "%s\n", VERSION); fprintf(stdout, "%s\n", VERSION);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
default: default:
vshError(ctl, TRUE, vshError(ctl, TRUE,
_("unsupported option '-%c'. See --help."), arg); _("unsupported option '-%c'. See --help."), arg);
break; break;
} }
} }
@ -2828,15 +2828,15 @@ main(int argc, char **argv)
if (!setlocale(LC_ALL, "")) { if (!setlocale(LC_ALL, "")) {
perror("setlocale"); perror("setlocale");
return -1; return -1;
} }
if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR)) { if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR)) {
perror("bindtextdomain"); perror("bindtextdomain");
return -1; return -1;
} }
if (!textdomain(GETTEXT_PACKAGE)) { if (!textdomain(GETTEXT_PACKAGE)) {
perror("textdomain"); perror("textdomain");
return -1; return -1;
} }
if (!(progname = strrchr(argv[0], '/'))) if (!(progname = strrchr(argv[0], '/')))
@ -2848,7 +2848,7 @@ main(int argc, char **argv)
ctl->imode = TRUE; /* default is interactive mode */ ctl->imode = TRUE; /* default is interactive mode */
if ((defaultConn = getenv("VIRSH_DEFAULT_CONNECT_URI"))) { if ((defaultConn = getenv("VIRSH_DEFAULT_CONNECT_URI"))) {
ctl->name = strdup(defaultConn); ctl->name = strdup(defaultConn);
} }
if (!vshParseArgv(ctl, argc, argv)) if (!vshParseArgv(ctl, argc, argv))
@ -2867,7 +2867,7 @@ main(int argc, char **argv)
progname); progname);
vshPrint(ctl, vshPrint(ctl,
_("Type: 'help' for help with commands\n" _("Type: 'help' for help with commands\n"
" 'quit' to quit\n\n")); " 'quit' to quit\n\n"));
} }
vshReadlineInit(); vshReadlineInit();
do { do {
@ -2897,3 +2897,11 @@ main(int argc, char **argv)
* vim: set shiftwidth=4: * vim: set shiftwidth=4:
* vim: set expandtab: * vim: set expandtab:
*/ */
/*
* Local variables:
* indent-tabs-mode: nil
* c-indent-level: 4
* c-basic-offset: 4
* tab-width: 4
* End:
*/

426
src/xml.c
View File

@ -127,14 +127,14 @@ virBufferNew(unsigned int size)
return buf; return buf;
} }
void void
virBufferFree(virBufferPtr buf) virBufferFree(virBufferPtr buf)
{ {
if (buf) { if (buf) {
if (buf->content) if (buf->content)
free(buf->content); free(buf->content);
free(buf); free(buf);
} }
} }
@ -190,17 +190,17 @@ virBufferStrcat(virBufferPtr buf, ...)
{ {
va_list ap; va_list ap;
char *str; char *str;
va_start(ap, buf); va_start(ap, buf);
while ((str = va_arg(ap, char *)) != NULL) { while ((str = va_arg(ap, char *)) != NULL) {
unsigned int len = strlen(str); unsigned int len = strlen(str);
unsigned int needSize = buf->use + len + 2; unsigned int needSize = buf->use + len + 2;
if (needSize > buf->size) { if (needSize > buf->size) {
if (!virBufferGrow(buf, needSize)) if (!virBufferGrow(buf, needSize))
return -1; return -1;
} }
memcpy(&buf->content[buf->use], str, len); memcpy(&buf->content[buf->use], str, len);
buf->use += len; buf->use += len;
buf->content[buf->use] = 0; buf->content[buf->use] = 0;
@ -352,7 +352,7 @@ virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf)
virDomainGetXMLDevice(domain, buf, id); virDomainGetXMLDevice(domain, buf, id);
} }
done: done:
if (list != NULL) if (list != NULL)
free(list); free(list);
@ -450,7 +450,7 @@ virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf)
virDomainGetXMLInterface(domain, buf, id); virDomainGetXMLInterface(domain, buf, id);
} }
done: done:
if (list != NULL) if (list != NULL)
free(list); free(list);
@ -548,12 +548,12 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags)
virBufferVSprintf(&buf, " <name>%s</name>\n", virBufferVSprintf(&buf, " <name>%s</name>\n",
virDomainGetName(domain)); virDomainGetName(domain));
if (virDomainGetUUID(domain, &uuid[0]) == 0) { if (virDomainGetUUID(domain, &uuid[0]) == 0) {
virBufferVSprintf(&buf, virBufferVSprintf(&buf,
" <uuid>%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x</uuid>\n", " <uuid>%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x</uuid>\n",
uuid[0], uuid[1], uuid[2], uuid[3], uuid[0], uuid[1], uuid[2], uuid[3],
uuid[4], uuid[5], uuid[6], uuid[7], uuid[4], uuid[5], uuid[6], uuid[7],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[8], uuid[9], uuid[10], uuid[11],
uuid[12], uuid[13], uuid[14], uuid[15]); uuid[12], uuid[13], uuid[14], uuid[15]);
} }
virDomainGetXMLBoot(domain, &buf); virDomainGetXMLBoot(domain, &buf);
virBufferVSprintf(&buf, " <memory>%lu</memory>\n", info.maxMem); virBufferVSprintf(&buf, " <memory>%lu</memory>\n", info.maxMem);
@ -577,9 +577,9 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags)
* @buf: a buffer for the result S-Expr * @buf: a buffer for the result S-Expr
* @xendConfigVersion: xend configuration file format * @xendConfigVersion: xend configuration file format
* *
* Parse the graphics part of the XML description and add it to the S-Expr * Parse the graphics part of the XML description and add it to the S-Expr
* in buf. This is a temporary interface as the S-Expr interface will be * in buf. This is a temporary interface as the S-Expr interface will be
* replaced by XML-RPC in the future. However the XML format should stay * replaced by XML-RPC in the future. However the XML format should stay
* valid over time. * valid over time.
* *
* Returns 0 in case of success, -1 in case of error * Returns 0 in case of success, -1 in case of error
@ -634,9 +634,9 @@ static int virDomainParseXMLGraphicsDescImage(xmlNodePtr node, virBufferPtr buf,
* @node: node containing graphics description * @node: node containing graphics description
* @buf: a buffer for the result S-Expr * @buf: a buffer for the result S-Expr
* *
* Parse the graphics part of the XML description and add it to the S-Expr * Parse the graphics part of the XML description and add it to the S-Expr
* in buf. This is a temporary interface as the S-Expr interface will be * in buf. This is a temporary interface as the S-Expr interface will be
* replaced by XML-RPC in the future. However the XML format should stay * replaced by XML-RPC in the future. However the XML format should stay
* valid over time. * valid over time.
* *
* Returns 0 in case of success, -1 in case of error * Returns 0 in case of success, -1 in case of error
@ -719,13 +719,13 @@ virDomainParseXMLOSDescHVM(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
&& (xmlStrEqual(cur->name, BAD_CAST "type"))) { && (xmlStrEqual(cur->name, BAD_CAST "type"))) {
txt = cur->children; txt = cur->children;
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) && if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
(txt->next == NULL)) (txt->next == NULL))
type = txt->content; type = txt->content;
} else if ((loader == NULL) && } else if ((loader == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "loader"))) { (xmlStrEqual(cur->name, BAD_CAST "loader"))) {
txt = cur->children; txt = cur->children;
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) && if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
(txt->next == NULL)) (txt->next == NULL))
loader = txt->content; loader = txt->content;
} else if ((boot_dev == NULL) && } else if ((boot_dev == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "boot"))) { (xmlStrEqual(cur->name, BAD_CAST "boot"))) {
@ -741,10 +741,10 @@ virDomainParseXMLOSDescHVM(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
} }
virBufferAdd(buf, "(image (hvm ", 12); virBufferAdd(buf, "(image (hvm ", 12);
if (loader == NULL) { if (loader == NULL) {
virXMLError(VIR_ERR_NO_KERNEL, NULL, 0); virXMLError(VIR_ERR_NO_KERNEL, NULL, 0);
goto error; goto error;
} else { } else {
virBufferVSprintf(buf, "(kernel '%s')", (const char *) loader); virBufferVSprintf(buf, "(kernel '%s')", (const char *) loader);
} }
/* get the device emulation model */ /* get the device emulation model */
@ -762,104 +762,104 @@ virDomainParseXMLOSDescHVM(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
virBufferVSprintf(buf, "(vcpus %d)", vcpus); virBufferVSprintf(buf, "(vcpus %d)", vcpus);
if (boot_dev) { if (boot_dev) {
if (xmlStrEqual(boot_dev, BAD_CAST "fd")) { if (xmlStrEqual(boot_dev, BAD_CAST "fd")) {
virBufferVSprintf(buf, "(boot a)", (const char *) boot_dev); virBufferVSprintf(buf, "(boot a)", (const char *) boot_dev);
} else if (xmlStrEqual(boot_dev, BAD_CAST "cdrom")) { } else if (xmlStrEqual(boot_dev, BAD_CAST "cdrom")) {
virBufferVSprintf(buf, "(boot d)", (const char *) boot_dev); virBufferVSprintf(buf, "(boot d)", (const char *) boot_dev);
} else if (xmlStrEqual(boot_dev, BAD_CAST "hd")) { } else if (xmlStrEqual(boot_dev, BAD_CAST "hd")) {
virBufferVSprintf(buf, "(boot c)", (const char *) boot_dev); virBufferVSprintf(buf, "(boot c)", (const char *) boot_dev);
} else { } else {
/* Any other type of boot dev is unsupported right now */ /* Any other type of boot dev is unsupported right now */
virXMLError(VIR_ERR_XML_ERROR, NULL, 0); virXMLError(VIR_ERR_XML_ERROR, NULL, 0);
} }
/* get the 1st floppy device file */ /* get the 1st floppy device file */
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fda']/source", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fda']/source", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
cur = obj->nodesetval->nodeTab[0]; cur = obj->nodesetval->nodeTab[0];
virBufferVSprintf(buf, "(fda '%s')", virBufferVSprintf(buf, "(fda '%s')",
(const char *) xmlGetProp(cur, BAD_CAST "file")); (const char *) xmlGetProp(cur, BAD_CAST "file"));
cur = NULL; cur = NULL;
} }
if (obj) { if (obj) {
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = NULL; obj = NULL;
} }
/* get the 2nd floppy device file */ /* get the 2nd floppy device file */
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fdb']/source", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fdb']/source", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
xmlChar *fdfile = NULL; xmlChar *fdfile = NULL;
cur = obj->nodesetval->nodeTab[0]; cur = obj->nodesetval->nodeTab[0];
fdfile = xmlGetProp(cur, BAD_CAST "file"); fdfile = xmlGetProp(cur, BAD_CAST "file");
virBufferVSprintf(buf, "(fdb '%s')", virBufferVSprintf(buf, "(fdb '%s')",
(const char *) fdfile); (const char *) fdfile);
xmlFree(fdfile); xmlFree(fdfile);
cur = NULL; cur = NULL;
} }
if (obj) { if (obj) {
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = NULL; obj = NULL;
} }
/* get the cdrom device file */ /* get the cdrom device file */
/* Only XenD <= 3.0.2 wants cdrom config here */ /* Only XenD <= 3.0.2 wants cdrom config here */
if (xendConfigVersion == 1) { if (xendConfigVersion == 1) {
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='cdrom' and target/@dev='hdc']/source", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='cdrom' and target/@dev='hdc']/source", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
xmlChar *cdfile = NULL; xmlChar *cdfile = NULL;
cur = obj->nodesetval->nodeTab[0]; cur = obj->nodesetval->nodeTab[0];
cdfile = xmlGetProp(cur, BAD_CAST "file"); cdfile = xmlGetProp(cur, BAD_CAST "file");
virBufferVSprintf(buf, "(cdrom '%s')", virBufferVSprintf(buf, "(cdrom '%s')",
(const char *)cdfile); (const char *)cdfile);
xmlFree(cdfile); xmlFree(cdfile);
cur = NULL; cur = NULL;
} }
if (obj) { if (obj) {
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = NULL; obj = NULL;
} }
} }
obj = xmlXPathEval(BAD_CAST "/domain/features/acpi", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/features/acpi", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
virBufferAdd(buf, "(acpi 1)", 8); virBufferAdd(buf, "(acpi 1)", 8);
} }
if (obj) if (obj)
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "/domain/features/apic", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/features/apic", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
virBufferAdd(buf, "(apic 1)", 8); virBufferAdd(buf, "(apic 1)", 8);
} }
if (obj) if (obj)
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "/domain/features/pae", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/features/pae", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
virBufferAdd(buf, "(pae 1)", 7); virBufferAdd(buf, "(pae 1)", 7);
} }
if (obj) if (obj)
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = NULL; obj = NULL;
} }
obj = xmlXPathEval(BAD_CAST "count(domain/devices/console) > 0", ctxt); obj = xmlXPathEval(BAD_CAST "count(domain/devices/console) > 0", ctxt);
if ((obj == NULL) || (obj->type != XPATH_BOOLEAN)) { if ((obj == NULL) || (obj->type != XPATH_BOOLEAN)) {
virXMLError(VIR_ERR_XML_ERROR, NULL, 0); virXMLError(VIR_ERR_XML_ERROR, NULL, 0);
goto error; goto error;
} }
if (obj->boolval) { if (obj->boolval) {
virBufferAdd(buf, "(serial pty)", 12); virBufferAdd(buf, "(serial pty)", 12);
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = NULL; obj = NULL;
/* Is a graphics device specified? */ /* Is a graphics device specified? */
obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics[1]", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics[1]", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
@ -877,7 +877,7 @@ virDomainParseXMLOSDescHVM(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
xmlFree(boot_dev); xmlFree(boot_dev);
return (0); return (0);
error: error:
if (boot_dev) if (boot_dev)
xmlFree(boot_dev); xmlFree(boot_dev);
if (obj != NULL) if (obj != NULL)
@ -918,31 +918,31 @@ virDomainParseXMLOSDescPV(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
&& (xmlStrEqual(cur->name, BAD_CAST "type"))) { && (xmlStrEqual(cur->name, BAD_CAST "type"))) {
txt = cur->children; txt = cur->children;
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) && if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
(txt->next == NULL)) (txt->next == NULL))
type = txt->content; type = txt->content;
} else if ((kernel == NULL) && } else if ((kernel == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "kernel"))) { (xmlStrEqual(cur->name, BAD_CAST "kernel"))) {
txt = cur->children; txt = cur->children;
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) && if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
(txt->next == NULL)) (txt->next == NULL))
kernel = txt->content; kernel = txt->content;
} else if ((root == NULL) && } else if ((root == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "root"))) { (xmlStrEqual(cur->name, BAD_CAST "root"))) {
txt = cur->children; txt = cur->children;
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) && if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
(txt->next == NULL)) (txt->next == NULL))
root = txt->content; root = txt->content;
} else if ((initrd == NULL) && } else if ((initrd == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "initrd"))) { (xmlStrEqual(cur->name, BAD_CAST "initrd"))) {
txt = cur->children; txt = cur->children;
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) && if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
(txt->next == NULL)) (txt->next == NULL))
initrd = txt->content; initrd = txt->content;
} else if ((cmdline == NULL) && } else if ((cmdline == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "cmdline"))) { (xmlStrEqual(cur->name, BAD_CAST "cmdline"))) {
txt = cur->children; txt = cur->children;
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) && if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
(txt->next == NULL)) (txt->next == NULL))
cmdline = txt->content; cmdline = txt->content;
} }
} }
@ -955,10 +955,10 @@ virDomainParseXMLOSDescPV(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
} }
virBufferAdd(buf, "(image (linux ", 14); virBufferAdd(buf, "(image (linux ", 14);
if (kernel == NULL) { if (kernel == NULL) {
virXMLError(VIR_ERR_NO_KERNEL, NULL, 0); virXMLError(VIR_ERR_NO_KERNEL, NULL, 0);
return (-1); return (-1);
} else { } else {
virBufferVSprintf(buf, "(kernel '%s')", (const char *) kernel); virBufferVSprintf(buf, "(kernel '%s')", (const char *) kernel);
} }
if (initrd != NULL) if (initrd != NULL)
virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd); virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd);
@ -1003,7 +1003,7 @@ virCatchXMLParseError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
(ctxt->lastError.level == XML_ERR_FATAL) && (ctxt->lastError.level == XML_ERR_FATAL) &&
(ctxt->lastError.message != NULL)) { (ctxt->lastError.message != NULL)) {
virXMLError(VIR_ERR_XML_DETAIL, ctxt->lastError.message, virXMLError(VIR_ERR_XML_DETAIL, ctxt->lastError.message,
ctxt->lastError.line); ctxt->lastError.line);
} }
} }
@ -1066,7 +1066,7 @@ virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf, int hvm, int xendCo
} else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) { } else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
ro = 1; ro = 1;
} else if (xmlStrEqual(cur->name, BAD_CAST "shareable")) { } else if (xmlStrEqual(cur->name, BAD_CAST "shareable")) {
shareable = 1; shareable = 1;
} }
} }
cur = cur->next; cur = cur->next;
@ -1350,7 +1350,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion)
obj = xmlXPathEval(BAD_CAST "number(/domain/memory[1])", ctxt); obj = xmlXPathEval(BAD_CAST "number(/domain/memory[1])", ctxt);
if ((obj == NULL) || (obj->type != XPATH_NUMBER) || if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
(isnan(obj->floatval)) || (obj->floatval < 64000)) { (isnan(obj->floatval)) || (obj->floatval < 64000)) {
max_mem = 128; max_mem = 128;
} else { } else {
max_mem = (obj->floatval / 1024); max_mem = (obj->floatval / 1024);
} }
@ -1361,9 +1361,9 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion)
mem = max_mem; mem = max_mem;
} else { } else {
mem = (obj->floatval / 1024); mem = (obj->floatval / 1024);
if (mem > max_mem) { if (mem > max_mem) {
max_mem = mem; max_mem = mem;
} }
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
virBufferVSprintf(&buf, "(memory %lu)(maxmem %lu)", mem, max_mem); virBufferVSprintf(&buf, "(memory %lu)(maxmem %lu)", mem, max_mem);
@ -1378,7 +1378,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion)
obj = xmlXPathEval(BAD_CAST "string(/domain/uuid[1])", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/uuid[1])", ctxt);
if ((obj == NULL) || ((obj->type == XPATH_STRING) && if ((obj == NULL) || ((obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0))) { (obj->stringval != NULL) && (obj->stringval[0] != 0))) {
virBufferVSprintf(&buf, "(uuid '%s')", obj->stringval); virBufferVSprintf(&buf, "(uuid '%s')", obj->stringval);
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
@ -1386,84 +1386,84 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion)
obj = xmlXPathEval(BAD_CAST "string(/domain/bootloader[1])", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/bootloader[1])", ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING) && if ((obj != NULL) && (obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)) { (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
virBufferVSprintf(&buf, "(bootloader '%s')", obj->stringval); virBufferVSprintf(&buf, "(bootloader '%s')", obj->stringval);
/* /*
* if using pygrub, the kernel and initrd strings are not * if using pygrub, the kernel and initrd strings are not
* significant and should be discarded * significant and should be discarded
*/ */
if (xmlStrstr(obj->stringval, BAD_CAST "pygrub")) if (xmlStrstr(obj->stringval, BAD_CAST "pygrub"))
bootloader = 2; bootloader = 2;
else else
bootloader = 1; bootloader = 1;
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/on_poweroff[1])", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/on_poweroff[1])", ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING) && if ((obj != NULL) && (obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)) { (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
virBufferVSprintf(&buf, "(on_poweroff '%s')", obj->stringval); virBufferVSprintf(&buf, "(on_poweroff '%s')", obj->stringval);
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/on_reboot[1])", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/on_reboot[1])", ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING) && if ((obj != NULL) && (obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)) { (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
virBufferVSprintf(&buf, "(on_reboot '%s')", obj->stringval); virBufferVSprintf(&buf, "(on_reboot '%s')", obj->stringval);
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/on_crash[1])", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/on_crash[1])", ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING) && if ((obj != NULL) && (obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)) { (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
virBufferVSprintf(&buf, "(on_crash '%s')", obj->stringval); virBufferVSprintf(&buf, "(on_crash '%s')", obj->stringval);
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
if (bootloader != 2) { if (bootloader != 2) {
obj = xmlXPathEval(BAD_CAST "/domain/os[1]", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/os[1]", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
/* Analyze of the os description, based on HVM or PV. */ /* Analyze of the os description, based on HVM or PV. */
tmpobj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt); tmpobj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt);
if ((tmpobj != NULL) && if ((tmpobj != NULL) &&
((tmpobj->type != XPATH_STRING) || (tmpobj->stringval == NULL) ((tmpobj->type != XPATH_STRING) || (tmpobj->stringval == NULL)
|| (tmpobj->stringval[0] == 0))) { || (tmpobj->stringval[0] == 0))) {
xmlXPathFreeObject(tmpobj); xmlXPathFreeObject(tmpobj);
virXMLError(VIR_ERR_OS_TYPE, nam, 0); virXMLError(VIR_ERR_OS_TYPE, nam, 0);
goto error; goto error;
} }
if ((tmpobj == NULL) if ((tmpobj == NULL)
|| !xmlStrEqual(tmpobj->stringval, BAD_CAST "hvm")) { || !xmlStrEqual(tmpobj->stringval, BAD_CAST "hvm")) {
res = virDomainParseXMLOSDescPV(obj->nodesetval->nodeTab[0], res = virDomainParseXMLOSDescPV(obj->nodesetval->nodeTab[0],
&buf, ctxt, xendConfigVersion); &buf, ctxt, xendConfigVersion);
} else { } else {
hvm = 1; hvm = 1;
res = virDomainParseXMLOSDescHVM(obj->nodesetval->nodeTab[0], res = virDomainParseXMLOSDescHVM(obj->nodesetval->nodeTab[0],
&buf, ctxt, vcpus, xendConfigVersion); &buf, ctxt, vcpus, xendConfigVersion);
} }
xmlXPathFreeObject(tmpobj); xmlXPathFreeObject(tmpobj);
if (res != 0) if (res != 0)
goto error; goto error;
} else if (bootloader == 0) { } else if (bootloader == 0) {
virXMLError(VIR_ERR_NO_OS, nam, 0); virXMLError(VIR_ERR_NO_OS, nam, 0);
goto error; goto error;
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
} }
/* analyze of the devices */ /* analyze of the devices */
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
for (i = 0; i < obj->nodesetval->nodeNr; i++) { for (i = 0; i < obj->nodesetval->nodeNr; i++) {
res = virDomainParseXMLDiskDesc(obj->nodesetval->nodeTab[i], &buf, hvm, xendConfigVersion); res = virDomainParseXMLDiskDesc(obj->nodesetval->nodeTab[i], &buf, hvm, xendConfigVersion);
if (res != 0) { if (res != 0) {
goto error; goto error;
} }
} }
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
@ -1511,7 +1511,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion)
return (ret); return (ret);
error: error:
if (nam != NULL) if (nam != NULL)
free(nam); free(nam);
if (name != NULL) if (name != NULL)
@ -1550,33 +1550,33 @@ unsigned char *virParseUUID(char **ptr, const char *uuid) {
for (i = 0;i < VIR_UUID_BUFLEN;) { for (i = 0;i < VIR_UUID_BUFLEN;) {
rawuuid[i] = 0; rawuuid[i] = 0;
if (*cur == 0) if (*cur == 0)
goto error; goto error;
if ((*cur == '-') || (*cur == ' ')) { if ((*cur == '-') || (*cur == ' ')) {
cur++; cur++;
continue; continue;
} }
if ((*cur >= '0') && (*cur <= '9')) if ((*cur >= '0') && (*cur <= '9'))
rawuuid[i] = *cur - '0'; rawuuid[i] = *cur - '0';
else if ((*cur >= 'a') && (*cur <= 'f')) else if ((*cur >= 'a') && (*cur <= 'f'))
rawuuid[i] = *cur - 'a' + 10; rawuuid[i] = *cur - 'a' + 10;
else if ((*cur >= 'A') && (*cur <= 'F')) else if ((*cur >= 'A') && (*cur <= 'F'))
rawuuid[i] = *cur - 'A' + 10; rawuuid[i] = *cur - 'A' + 10;
else else
goto error; goto error;
rawuuid[i] *= 16; rawuuid[i] *= 16;
cur++; cur++;
if (*cur == 0) if (*cur == 0)
goto error; goto error;
if ((*cur >= '0') && (*cur <= '9')) if ((*cur >= '0') && (*cur <= '9'))
rawuuid[i] += *cur - '0'; rawuuid[i] += *cur - '0';
else if ((*cur >= 'a') && (*cur <= 'f')) else if ((*cur >= 'a') && (*cur <= 'f'))
rawuuid[i] += *cur - 'a' + 10; rawuuid[i] += *cur - 'a' + 10;
else if ((*cur >= 'A') && (*cur <= 'F')) else if ((*cur >= 'A') && (*cur <= 'F'))
rawuuid[i] += *cur - 'A' + 10; rawuuid[i] += *cur - 'A' + 10;
else else
goto error; goto error;
i++; i++;
cur++; cur++;
} }
dst_uuid = (unsigned char *) *ptr; dst_uuid = (unsigned char *) *ptr;
@ -1585,7 +1585,7 @@ unsigned char *virParseUUID(char **ptr, const char *uuid) {
for (i = 0; i < VIR_UUID_BUFLEN; i++) for (i = 0; i < VIR_UUID_BUFLEN; i++)
dst_uuid[i] = rawuuid[i] & 0xFF; dst_uuid[i] = rawuuid[i] & 0xFF;
error: error:
return(dst_uuid); return(dst_uuid);
} }
@ -1632,11 +1632,11 @@ virParseXMLDevice(char *xmldesc, int hvm, int xendConfigVersion)
if (virDomainParseXMLIfDesc(node, &buf, hvm) != 0) if (virDomainParseXMLIfDesc(node, &buf, hvm) != 0)
goto error; goto error;
} }
cleanup: cleanup:
if (xml != NULL) if (xml != NULL)
xmlFreeDoc(xml); xmlFreeDoc(xml);
return buf.content; return buf.content;
error: error:
free(buf.content); free(buf.content);
buf.content = NULL; buf.content = NULL;
goto cleanup; goto cleanup;
@ -1677,7 +1677,7 @@ virDomainXMLDevID(virDomainPtr domain, char *xmldesc, char *class, char *ref)
strcpy(class, "vbd"); strcpy(class, "vbd");
for (cur = node->children; cur != NULL; cur = cur->next) { for (cur = node->children; cur != NULL; cur = cur->next) {
if ((cur->type != XML_ELEMENT_NODE) || if ((cur->type != XML_ELEMENT_NODE) ||
(!xmlStrEqual(cur->name, BAD_CAST "target"))) continue; (!xmlStrEqual(cur->name, BAD_CAST "target"))) continue;
attr = xmlGetProp(cur, BAD_CAST "dev"); attr = xmlGetProp(cur, BAD_CAST "dev");
if (attr == NULL) if (attr == NULL)
goto error; goto error;
@ -1695,19 +1695,19 @@ virDomainXMLDevID(virDomainPtr domain, char *xmldesc, char *class, char *ref)
goto error; goto error;
xref = xenStoreDomainGetNetworkID(domain->conn, domain->id, xref = xenStoreDomainGetNetworkID(domain->conn, domain->id,
(char *) attr); (char *) attr);
if (xref != NULL) { if (xref != NULL) {
strcpy(ref, xref); strcpy(ref, xref);
free(xref); free(xref);
goto cleanup; goto cleanup;
} }
goto error; goto error;
} }
} }
error: error:
ret = -1; ret = -1;
cleanup: cleanup:
if (xml != NULL) if (xml != NULL)
xmlFreeDoc(xml); xmlFreeDoc(xml);
if (attr != NULL) if (attr != NULL)