virsh: minor syntactic cleanups

No semantic change.

* tools/virsh.c: Fix some spacing issues, {} usage, long lines,
and redundant ().
This commit is contained in:
Eric Blake 2012-04-14 16:35:22 -06:00
parent 78345c68c9
commit 4f06777e5b

View File

@ -604,7 +604,7 @@ static int disconnected = 0; /* we may have been disconnected */
*/
static void vshCatchDisconnect(int sig, siginfo_t *siginfo,
void *context ATTRIBUTE_UNUSED) {
if ((sig == SIGPIPE) ||
if (sig == SIGPIPE ||
(SA_SIGINFO && siginfo->si_signo == SIGPIPE))
disconnected++;
}
@ -1044,8 +1044,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
goto cleanup;
}
if ((persistent && !optPersistent) ||
(!persistent && !optTransient)) {
if (!(persistent ? optPersistent : optTransient)) {
virDomainFree(dom);
dom = NULL;
continue;
@ -5394,7 +5393,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
}
virSkipSpaces(&cur);
if ((*cur == ',') || (*cur == 0)) {
if (*cur == ',' || *cur == 0) {
if (unuse) {
VIR_UNUSE_CPU(cpumap, cpu);
} else {
@ -5995,9 +5994,9 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
*/
static const vshCmdInfo info_blkiotune[] = {
{"help", N_("Get or set blkio parameters")},
{"desc", N_("Get or set the current blkio parameters for a guest" \
" domain.\n" \
" To get the blkio parameters use following command: \n\n" \
{"desc", N_("Get or set the current blkio parameters for a guest"
" domain.\n"
" To get the blkio parameters use following command: \n\n"
" virsh # blkiotune <domain>")},
{NULL, NULL}
};
@ -6143,9 +6142,9 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
*/
static const vshCmdInfo info_memtune[] = {
{"help", N_("Get or set memory parameters")},
{"desc", N_("Get or set the current memory parameters for a guest" \
" domain.\n" \
" To get the memory parameters use following command: \n\n" \
{"desc", N_("Get or set the current memory parameters for a guest"
" domain.\n"
" To get the memory parameters use following command: \n\n"
" virsh # memtune <domain>")},
{NULL, NULL}
};
@ -6335,9 +6334,9 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd)
*/
static const vshCmdInfo info_numatune[] = {
{"help", N_("Get or set numa parameters")},
{"desc", N_("Get or set the current numa parameters for a guest" \
" domain.\n" \
" To get the numa parameters use following command: \n\n" \
{"desc", N_("Get or set the current numa parameters for a guest"
" domain.\n"
" To get the numa parameters use following command: \n\n"
" virsh # numatune <domain>")},
{NULL, NULL}
@ -7288,15 +7287,17 @@ repoll:
if (intCaught) {
virDomainAbortJob(dom);
intCaught = 0;
} else
} else {
goto repoll;
}
}
goto cleanup;
}
GETTIMEOFDAY(&curr);
if ( timeout && ((int)(curr.tv_sec - start.tv_sec) * 1000 + \
(int)(curr.tv_usec - start.tv_usec) / 1000) > timeout * 1000 ) {
if (timeout && (((int)(curr.tv_sec - start.tv_sec) * 1000 +
(int)(curr.tv_usec - start.tv_usec) / 1000) >
timeout * 1000)) {
/* suspend the domain when migration timeouts. */
vshDebug(ctl, VSH_ERR_DEBUG, "%s timeout", label);
if (timeout_func)
@ -7343,7 +7344,8 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
live_flag = true;
if (vshCommandOptInt(cmd, "timeout", &timeout) > 0) {
if (! live_flag) {
vshError(ctl, "%s", _("migrate: Unexpected timeout for offline migration"));
vshError(ctl, "%s",
_("migrate: Unexpected timeout for offline migration"));
goto cleanup;
}
@ -7896,7 +7898,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
if (nparams == 0) {
if ((virDomainGetBlockIoTune(dom, NULL, NULL, &nparams, flags)) != 0) {
if (virDomainGetBlockIoTune(dom, NULL, NULL, &nparams, flags) != 0) {
vshError(ctl, "%s",
_("Unable to get number of block I/O throttle parameters"));
goto cleanup;
@ -7909,7 +7911,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
params = vshCalloc(ctl, nparams, sizeof(*params));
if ((virDomainGetBlockIoTune(dom, disk, params, &nparams, flags)) != 0) {
if (virDomainGetBlockIoTune(dom, disk, params, &nparams, flags) != 0) {
vshError(ctl, "%s",
_("Unable to get block I/O throttle parameters"));
goto cleanup;
@ -7928,7 +7930,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
params = vshCalloc(ctl, nparams, sizeof(*params));
i = 0;
if ((i < nparams) && (vshCommandOptBool(cmd, "total-bytes-sec"))) {
if (i < nparams && vshCommandOptBool(cmd, "total-bytes-sec")) {
temp = &params[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC,
@ -7937,7 +7939,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
i++;
}
if ((i < nparams) && (vshCommandOptBool(cmd, "read-bytes-sec"))) {
if (i < nparams && vshCommandOptBool(cmd, "read-bytes-sec")) {
temp = &params[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC,
@ -7946,7 +7948,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
i++;
}
if ((i < nparams) && (vshCommandOptBool(cmd, "write-bytes-sec"))) {
if (i < nparams && vshCommandOptBool(cmd, "write-bytes-sec")) {
temp = &params[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC,
@ -7955,7 +7957,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
i++;
}
if ((i < nparams) && (vshCommandOptBool(cmd, "total-iops-sec"))) {
if (i < nparams && vshCommandOptBool(cmd, "total-iops-sec")) {
temp = &params[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC,
@ -7964,7 +7966,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
i++;
}
if ((i < nparams) && (vshCommandOptBool(cmd, "read-iops-sec"))) {
if (i < nparams && vshCommandOptBool(cmd, "read-iops-sec")) {
temp = &params[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC,
@ -7973,7 +7975,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
i++;
}
if ((i < nparams) && (vshCommandOptBool(cmd, "write-iops-sec"))) {
if (i < nparams && vshCommandOptBool(cmd, "write-iops-sec")) {
temp = &params[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC,
@ -7981,7 +7983,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
temp->value.ul = write_iops_sec;
}
if ((virDomainSetBlockIoTune(dom, disk, params, nparams, flags)) < 0) {
if (virDomainSetBlockIoTune(dom, disk, params, nparams, flags) < 0) {
vshError(ctl, "%s",
_("Unable to change block I/O throttle"));
goto cleanup;
@ -10451,8 +10453,8 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
/* Retrieve a list of active storage pool names */
if (active) {
if ((virConnectListStoragePools(ctl->conn,
poolNames, numActivePools)) < 0) {
if (virConnectListStoragePools(ctl->conn,
poolNames, numActivePools) < 0) {
vshError(ctl, "%s", _("Failed to list active pools"));
VIR_FREE(poolInfoTexts);
VIR_FREE(poolNames);
@ -10462,9 +10464,9 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
/* Add the inactive storage pools to the end of the name list */
if (inactive) {
if ((virConnectListDefinedStoragePools(ctl->conn,
if (virConnectListDefinedStoragePools(ctl->conn,
&poolNames[numActivePools],
numInactivePools)) < 0) {
numInactivePools) < 0) {
vshError(ctl, "%s", _("Failed to list inactive pools"));
VIR_FREE(poolInfoTexts);
VIR_FREE(poolNames);
@ -11139,8 +11141,8 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
if (vshVolSize(capacityStr, &capacity) < 0)
vshError(ctl, _("Malformed size %s"), capacityStr);
if ((vshCommandOptString(cmd, "allocation", &allocationStr) > 0) &&
(vshVolSize(allocationStr, &allocation) < 0))
if (vshCommandOptString(cmd, "allocation", &allocationStr) > 0 &&
vshVolSize(allocationStr, &allocation) < 0)
vshError(ctl, _("Malformed size %s"), allocationStr);
if (vshCommandOptString(cmd, "format", &format) < 0 ||
@ -11464,8 +11466,8 @@ makeCloneXML(const char *origxml, const char *newname)
goto cleanup;
obj = xmlXPathEval(BAD_CAST "/volume/name", ctxt);
if ((obj == NULL) || (obj->nodesetval == NULL) ||
(obj->nodesetval->nodeTab == NULL))
if (obj == NULL || obj->nodesetval == NULL ||
obj->nodesetval->nodeTab == NULL)
goto cleanup;
xmlNodeSetContent(obj->nodesetval->nodeTab[0], (const xmlChar *)newname);
@ -13382,8 +13384,8 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/graphics[@type='vnc']/@port)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
if (obj == NULL || obj->type != XPATH_STRING ||
obj->stringval == NULL || obj->stringval[0] == 0) {
goto cleanup;
}
if (virStrToLong_i((const char *)obj->stringval, NULL, 10, &port) || port < 0)
@ -13391,8 +13393,8 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/graphics[@type='vnc']/@listen)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0) ||
if (obj == NULL || obj->type != XPATH_STRING ||
obj->stringval == NULL || obj->stringval[0] == 0 ||
STREQ((const char*)obj->stringval, "0.0.0.0")) {
vshPrint(ctl, ":%d\n", port-5900);
} else {
@ -13450,8 +13452,8 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/console/@tty)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
if (obj == NULL || obj->type != XPATH_STRING ||
obj->stringval == NULL || obj->stringval[0] == 0) {
goto cleanup;
}
vshPrint(ctl, "%s\n", (const char *)obj->stringval);
@ -14175,13 +14177,13 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
snprintf(buf, sizeof(buf), "/domain/devices/interface[@type='%s']", type);
obj = xmlXPathEval(BAD_CAST buf, ctxt);
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr == 0)) {
if (obj == NULL || obj->type != XPATH_NODESET ||
obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) {
vshError(ctl, _("No found interface whose type is %s"), type);
goto cleanup;
}
if ((!mac) && (obj->nodesetval->nodeNr > 1)) {
if (!mac && obj->nodesetval->nodeNr > 1) {
vshError(ctl, _("Domain has %d interfaces. Please specify which one "
"to detach using --mac"), obj->nodesetval->nodeNr);
goto cleanup;
@ -14637,10 +14639,10 @@ vshFindDisk(const char *doc,
}
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
if ((obj == NULL) ||
(obj->type != XPATH_NODESET) ||
(obj->nodesetval == NULL) ||
(obj->nodesetval->nodeNr == 0)) {
if (obj == NULL ||
obj->type != XPATH_NODESET ||
obj->nodesetval == NULL ||
obj->nodesetval->nodeNr == 0) {
vshError(NULL, "%s", _("Failed to get disk information"));
goto cleanup;
}
@ -15219,7 +15221,7 @@ cleanup:
xmlFreeDoc(xml);
xmlBufferFree(xml_buf);
VIR_FREE(result);
if ((list != NULL) && (count > 0)) {
if (list != NULL && count > 0) {
for (i = 0; i < count; i++)
VIR_FREE(list[i]);
}
@ -16454,8 +16456,8 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
else
vshPrintExtra(ctl, " %-20s %-25s %s",
_("Name"), _("Creation Time"), _("State"));
vshPrintExtra(ctl, "\n\
------------------------------------------------------------\n");
vshPrintExtra(ctl, "\n"
"------------------------------------------------------------\n");
}
if (!numsnaps) {
@ -17874,7 +17876,7 @@ vshCommandOptInt(const vshCmd *cmd, const char *name, int *value)
}
num = strtol(arg->data, &end_p, 10);
if ((arg->data != end_p) && (*end_p == 0)) {
if (arg->data != end_p && *end_p == 0) {
*value = num;
return 1;
}
@ -17909,7 +17911,7 @@ vshCommandOptUInt(const vshCmd *cmd, const char *name, unsigned int *value)
}
num = strtoul(arg->data, &end_p, 10);
if ((arg->data != end_p) && (*end_p == 0)) {
if (arg->data != end_p && *end_p == 0) {
*value = num;
return 1;
}
@ -17944,7 +17946,7 @@ vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value)
}
num = strtoul(arg->data, &end_p, 10);
if ((arg->data != end_p) && (*end_p == 0)) {
if (arg->data != end_p && *end_p == 0) {
*value = num;
return 1;
}
@ -18013,7 +18015,7 @@ vshCommandOptLongLong(const vshCmd *cmd, const char *name,
}
num = strtoll(arg->data, &end_p, 10);
if ((arg->data != end_p) && (*end_p == 0)) {
if (arg->data != end_p && *end_p == 0) {
*value = num;
return 1;
}
@ -18048,7 +18050,7 @@ vshCommandOptULongLong(const vshCmd *cmd, const char *name,
}
num = strtoull(arg->data, &end_p, 10);
if ((arg->data != end_p) && (*end_p == 0)) {
if (arg->data != end_p && *end_p == 0) {
*value = num;
return 1;
}
@ -18220,7 +18222,7 @@ vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
*name = n;
/* try it by UUID */
if ((flag & VSH_BYUUID) && (strlen(n) == VIR_UUID_STRING_BUFLEN-1)) {
if ((flag & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network UUID\n",
cmd->def->name, optname);
network = virNetworkLookupByUUIDString(ctl->conn, n);
@ -18259,7 +18261,7 @@ vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
*name = n;
/* try it by UUID */
if ((flag & VSH_BYUUID) && (strlen(n) == VIR_UUID_STRING_BUFLEN-1)) {
if ((flag & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter UUID\n",
cmd->def->name, optname);
nwfilter = virNWFilterLookupByUUIDString(ctl->conn, n);
@ -18300,13 +18302,13 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
*name = n;
/* try it by NAME */
if ((flag & VSH_BYNAME)) {
if (flag & VSH_BYNAME) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface NAME\n",
cmd->def->name, optname);
iface = virInterfaceLookupByName(ctl->conn, n);
}
/* try it by MAC */
if ((iface == NULL) && (flag & VSH_BYMAC)) {
if (iface == NULL && (flag & VSH_BYMAC)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface MAC\n",
cmd->def->name, optname);
iface = virInterfaceLookupByMACString(ctl->conn, n);
@ -18335,7 +18337,7 @@ vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
*name = n;
/* try it by UUID */
if ((flag & VSH_BYUUID) && (strlen(n) == VIR_UUID_STRING_BUFLEN-1)) {
if ((flag & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool UUID\n",
cmd->def->name, optname);
pool = virStoragePoolLookupByUUIDString(ctl->conn, n);
@ -19629,9 +19631,10 @@ vshReadlineDeinit (vshControl *ctl)
char ebuf[1024];
vshError(ctl, _("Failed to create '%s': %s"),
ctl->historydir, virStrerror(errno, ebuf, sizeof(ebuf)));
} else
} else {
write_history(ctl->historyfile);
}
}
VIR_FREE(ctl->historydir);
VIR_FREE(ctl->historyfile);