static char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-static char *editWriteToTempFile (vshControl *ctl, const char *doc);
-static int editFile (vshControl *ctl, const char *filename);
-static char *editReadBackFile (vshControl *ctl, const char *filename);
+static char *editWriteToTempFile(vshControl *ctl, const char *doc);
+static int editFile(vshControl *ctl, const char *filename);
+static char *editReadBackFile(vshControl *ctl, const char *filename);
/* Typedefs, function prototypes for job progress reporting.
* There are used by some long lingering commands like
*/
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++;
}
goto cleanup;
}
- if ((persistent && !optPersistent) ||
- (!persistent && !optTransient)) {
+ if (!(persistent ? optPersistent : optTransient)) {
virDomainFree(dom);
dom = NULL;
continue;
if (vshCommandOptString(cmd, "file", &to) <= 0)
goto cleanup;
- if (vshCommandOptBool (cmd, "verbose"))
+ if (vshCommandOptBool(cmd, "verbose"))
verbose = true;
if (pipe(p) < 0)
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return false;
- if (vshCommandOptBool (cmd, "verbose"))
+ if (vshCommandOptBool(cmd, "verbose"))
verbose = true;
if (pipe(p) < 0)
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
goto out;
- if (vshCommandOptBool (cmd, "live"))
+ if (vshCommandOptBool(cmd, "live"))
flags |= VIR_DUMP_LIVE;
- if (vshCommandOptBool (cmd, "crash"))
+ if (vshCommandOptBool(cmd, "crash"))
flags |= VIR_DUMP_CRASH;
if (vshCommandOptBool(cmd, "bypass-cache"))
flags |= VIR_DUMP_BYPASS_CACHE;
if (vshCommandOptString(cmd, "file", &to) <= 0)
return false;
- if (vshCommandOptBool (cmd, "verbose"))
+ if (vshCommandOptBool(cmd, "verbose"))
verbose = true;
if (pipe(p) < 0)
}
virSkipSpaces(&cur);
- if ((*cur == ',') || (*cur == 0)) {
+ if (*cur == ',' || *cur == 0) {
if (unuse) {
VIR_UNUSE_CPU(cpumap, cpu);
} else {
*/
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}
};
*/
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}
};
*/
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}
goto out;
}
- if (vshCommandOptBool (cmd, "live"))
+ if (vshCommandOptBool(cmd, "live"))
flags |= VIR_MIGRATE_LIVE;
- if (vshCommandOptBool (cmd, "p2p"))
+ if (vshCommandOptBool(cmd, "p2p"))
flags |= VIR_MIGRATE_PEER2PEER;
- if (vshCommandOptBool (cmd, "tunnelled"))
+ if (vshCommandOptBool(cmd, "tunnelled"))
flags |= VIR_MIGRATE_TUNNELLED;
- if (vshCommandOptBool (cmd, "persistent"))
+ if (vshCommandOptBool(cmd, "persistent"))
flags |= VIR_MIGRATE_PERSIST_DEST;
- if (vshCommandOptBool (cmd, "undefinesource"))
+ if (vshCommandOptBool(cmd, "undefinesource"))
flags |= VIR_MIGRATE_UNDEFINE_SOURCE;
- if (vshCommandOptBool (cmd, "suspend"))
+ if (vshCommandOptBool(cmd, "suspend"))
flags |= VIR_MIGRATE_PAUSED;
- if (vshCommandOptBool (cmd, "copy-storage-all"))
+ if (vshCommandOptBool(cmd, "copy-storage-all"))
flags |= VIR_MIGRATE_NON_SHARED_DISK;
- if (vshCommandOptBool (cmd, "copy-storage-inc"))
+ if (vshCommandOptBool(cmd, "copy-storage-inc"))
flags |= VIR_MIGRATE_NON_SHARED_INC;
- if (vshCommandOptBool (cmd, "change-protection"))
+ if (vshCommandOptBool(cmd, "change-protection"))
flags |= VIR_MIGRATE_CHANGE_PROTECTION;
if (vshCommandOptBool(cmd, "unsafe"))
}
if ((flags & VIR_MIGRATE_PEER2PEER) ||
- vshCommandOptBool (cmd, "direct")) {
+ vshCommandOptBool(cmd, "direct")) {
/* For peer2peer migration or direct migration we only expect one URI
* a libvirt URI, or a hypervisor specific URI. */
if (pollfd.revents & POLLIN &&
saferead(pipe_fd, &retchar, sizeof(retchar)) > 0 &&
retchar == '0') {
- if (verbose) {
- /* print [100 %] */
- print_job_progress(label, 0, 1);
- }
- break;
+ if (verbose) {
+ /* print [100 %] */
+ print_job_progress(label, 0, 1);
+ }
+ break;
}
goto cleanup;
}
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)
}
static bool
-cmdMigrate (vshControl *ctl, const vshCmd *cmd)
+cmdMigrate(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
int p[2] = {-1, -1};
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
- if (vshCommandOptBool (cmd, "verbose"))
+ if (vshCommandOptBool(cmd, "verbose"))
verbose = true;
- if (vshCommandOptBool (cmd, "live"))
+ if (vshCommandOptBool(cmd, "live"))
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;
}
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;
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;
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 = ¶ms[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC,
i++;
}
- if ((i < nparams) && (vshCommandOptBool(cmd, "read-bytes-sec"))) {
+ if (i < nparams && vshCommandOptBool(cmd, "read-bytes-sec")) {
temp = ¶ms[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC,
i++;
}
- if ((i < nparams) && (vshCommandOptBool(cmd, "write-bytes-sec"))) {
+ if (i < nparams && vshCommandOptBool(cmd, "write-bytes-sec")) {
temp = ¶ms[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC,
i++;
}
- if ((i < nparams) && (vshCommandOptBool(cmd, "total-iops-sec"))) {
+ if (i < nparams && vshCommandOptBool(cmd, "total-iops-sec")) {
temp = ¶ms[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC,
i++;
}
- if ((i < nparams) && (vshCommandOptBool(cmd, "read-iops-sec"))) {
+ if (i < nparams && vshCommandOptBool(cmd, "read-iops-sec")) {
temp = ¶ms[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC,
i++;
}
- if ((i < nparams) && (vshCommandOptBool(cmd, "write-iops-sec"))) {
+ if (i < nparams && vshCommandOptBool(cmd, "write-iops-sec")) {
temp = ¶ms[i];
temp->type = VIR_TYPED_PARAM_ULLONG;
strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC,
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;
if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
return false;
- inactive = vshCommandOptBool (cmd, "inactive");
+ inactive = vshCommandOptBool(cmd, "inactive");
if (inactive)
flags |= VIR_NETWORK_XML_INACTIVE;
/* Everything checks out, so redefine the interface. */
virInterfaceFree (iface);
- iface = virInterfaceDefineXML (ctl->conn, doc_edited, 0);
+ iface = virInterfaceDefineXML(ctl->conn, doc_edited, 0);
if (!iface)
goto cleanup;
/* Everything checks out, so redefine the interface. */
virNWFilterFree (nwfilter);
- nwfilter = virNWFilterDefineXML (ctl->conn, doc_edited);
+ nwfilter = virNWFilterDefineXML(ctl->conn, doc_edited);
if (!nwfilter)
goto cleanup;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
return false;
- if (vshCommandOptBool (cmd, "no-overwrite")) {
+ if (vshCommandOptBool(cmd, "no-overwrite")) {
flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE;
}
- if (vshCommandOptBool (cmd, "overwrite")) {
+ if (vshCommandOptBool(cmd, "overwrite")) {
flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE;
}
/* 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);
/* Add the inactive storage pools to the end of the name list */
if (inactive) {
- if ((virConnectListDefinedStoragePools(ctl->conn,
- &poolNames[numActivePools],
- numInactivePools)) < 0) {
+ if (virConnectListDefinedStoragePools(ctl->conn,
+ &poolNames[numActivePools],
+ numInactivePools) < 0) {
vshError(ctl, "%s", _("Failed to list inactive pools"));
VIR_FREE(poolInfoTexts);
VIR_FREE(poolNames);
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 ||
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);
};
static bool
-cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)
+cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
{
const char *name = NULL;
virNodeDevicePtr device;
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)
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 {
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);
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;
(isFile) ? "file" : "block");
if (type)
virBufferAsprintf(&buf, " device='%s'", type);
- if (vshCommandOptBool (cmd, "rawio"))
+ if (vshCommandOptBool(cmd, "rawio"))
virBufferAddLit(&buf, " rawio='yes'");
virBufferAddLit(&buf, ">\n");
}
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;
}
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]);
}
{
char *ret;
- if (virFileReadAll (filename, VIRSH_MAX_XML_FILE, &ret) == -1) {
+ if (virFileReadAll(filename, VIRSH_MAX_XML_FILE, &ret) == -1) {
vshError(ctl,
_("%s: failed to read temporary file: %s"),
filename, strerror(errno));
/* Everything checks out, so redefine the domain. */
virDomainFree (dom);
- dom = virDomainDefineXML (ctl->conn, doc_edited);
+ dom = virDomainDefineXML(ctl->conn, doc_edited);
if (!dom)
goto cleanup;
else
vshPrintExtra(ctl, " %-20s %-25s %s",
_("Name"), _("Creation Time"), _("State"));
- vshPrintExtra(ctl, "\n\
-------------------------------------------------------------\n");
+ vshPrintExtra(ctl, "\n"
+"------------------------------------------------------------\n");
}
if (!numsnaps) {
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
*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);
*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);
*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);
*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);
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);