/* fall back to xml */
if (virshDomainGetXMLFromDom(ctl, dom, flags, &doc, &ctxt) < 0)
- goto cleanup;
+ return NULL;
if (title)
desc = virXPathString("string(./title[1])", ctxt);
if (!desc)
desc = g_strdup("");
- cleanup:
-
return desc;
}
virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
unsigned int nr_stats;
size_t i;
- bool ret = false;
int rv = 0;
int period = -1;
bool config = vshCommandOptBool(cmd, "config");
* This is not really an unsigned long, but it
*/
if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0)
- goto cleanup;
+ return false;
if (rv > 0) {
if (period < 0) {
vshError(ctl, _("Invalid collection period value '%d'"), period);
- goto cleanup;
+ return false;
}
if (virDomainSetMemoryStatsPeriod(dom, period, flags) < 0) {
vshError(ctl, "%s",
_("Unable to change balloon collection period."));
- } else {
- ret = true;
+ return false;
}
- goto cleanup;
+ return true;
}
nr_stats = virDomainMemoryStats(dom, stats, VIR_DOMAIN_MEMORY_STAT_NR, 0);
if (nr_stats == -1) {
vshError(ctl, _("Failed to get memory statistics for domain %s"), name);
- goto cleanup;
+ return false;
}
for (i = 0; i < nr_stats; i++) {
vshPrint(ctl, "hugetlb_pgfail %llu\n", stats[i].val);
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
static bool
cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
{
- bool ret = false;
unsigned int flags = 0;
g_autoptr(xmlDoc) xmldoc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
details = vshCommandOptBool(cmd, "details");
if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0)
- goto cleanup;
+ return false;
ndisks = virXPathNodeSet("./devices/disk", ctxt, &disks);
if (ndisks < 0)
- goto cleanup;
+ return false;
if (details)
table = vshTableNew(_("Type"), _("Device"), _("Target"), _("Source"), NULL);
table = vshTableNew(_("Target"), _("Source"), NULL);
if (!table)
- goto cleanup;
+ return false;
for (i = 0; i < ndisks; i++) {
g_autofree char *type = NULL;
device = virXPathString("string(./@device)", ctxt);
if (!type || !device) {
vshPrint(ctl, "unable to query block list details");
- goto cleanup;
+ return false;
}
}
target = virXPathString("string(./target/@dev)", ctxt);
if (!target) {
vshError(ctl, "unable to query block list");
- goto cleanup;
+ return false;
}
if (STREQ_NULLABLE(type, "nvme")) {
!(addrNode = virXPathNode("./source/address", ctxt)) ||
virPCIDeviceAddressParseXML(addrNode, &addr) < 0) {
vshError(ctl, "Unable to query NVMe disk address");
- goto cleanup;
+ return false;
}
source = g_strdup_printf("nvme://%04x:%02x:%02x.%d/%s",
if (details) {
if (vshTableRowAppend(table, type, device, target,
NULLSTR_MINUS(source), NULL) < 0)
- goto cleanup;
+ return false;
} else {
if (vshTableRowAppend(table, target,
NULLSTR_MINUS(source), NULL) < 0)
- goto cleanup;
+ return false;
}
}
vshTablePrintToStdout(table, ctl);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
static bool
cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
{
- bool ret = false;
unsigned int flags = 0;
g_autoptr(xmlDoc) xmldoc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
flags |= VIR_DOMAIN_XML_INACTIVE;
if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0)
- goto cleanup;
+ return false;
ninterfaces = virXPathNodeSet("./devices/interface", ctxt, &interfaces);
if (ninterfaces < 0)
- goto cleanup;
+ return false;
table = vshTableNew(_("Interface"), _("Type"),
_("Source"), _("Model"), _("MAC"), NULL);
if (!table)
- goto cleanup;
+ return false;
for (i = 0; i < ninterfaces; i++) {
g_autofree char *type = NULL;
model ? model : "-",
mac ? mac : "-",
NULL) < 0)
- goto cleanup;
+ return false;
}
vshTablePrintToStdout(table, ctl);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
g_autofree xmlNodePtr *interfaces = NULL;
int ninterfaces;
unsigned int flags = 0;
- bool ret = false;
if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0)
return false;
flags = VIR_DOMAIN_XML_INACTIVE;
if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0)
- goto cleanup;
+ return false;
/* normalize the mac addr */
if (virMacAddrParse(iface, &macaddr) == 0)
if ((ninterfaces = virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) {
vshError(ctl, _("Failed to extract interface information"));
- goto cleanup;
+ return false;
}
if (ninterfaces < 1) {
else
vshError(ctl, _("Interface (dev: %s) not found."), iface);
- goto cleanup;
+ return false;
} else if (ninterfaces > 1) {
vshError(ctl, _("multiple matching interfaces found"));
- goto cleanup;
+ return false;
}
ctxt->node = interfaces[0];
else
vshPrint(ctl, "%s up", iface);
- ret = true;
-
- cleanup:
-
- return ret;
+ return true;
}
/*
cmdDomControl(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = true;
virDomainControlInfo info;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
- if (virDomainGetControlInfo(dom, &info, 0) < 0) {
- ret = false;
- goto cleanup;
- }
+ if (virDomainGetControlInfo(dom, &info, 0) < 0)
+ return false;
if (info.state != VIR_DOMAIN_CONTROL_OK &&
info.state != VIR_DOMAIN_CONTROL_ERROR) {
virshDomainControlStateToString(info.state));
}
- cleanup:
- return ret;
+ return true;
}
/*
const char *field = NULL;
int rc, nparams = 0;
size_t i;
- bool ret = false;
bool human = vshCommandOptBool(cmd, "human"); /* human readable output */
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
API contract.
*/
if (vshCommandOptStringReq(ctl, cmd, "device", &device) < 0)
- goto cleanup;
+ return false;
if (!device)
device = "";
if (rc < 0) {
/* try older API if newer is not supported */
if (last_error->code != VIR_ERR_NO_SUPPORT)
- goto cleanup;
+ return false;
vshResetLibvirtError();
sizeof(stats)) == -1) {
vshError(ctl, _("Failed to get block stats %s %s"),
name, device);
- goto cleanup;
+ return false;
}
/* human friendly output */
params = g_new0(virTypedParameter, nparams);
if (virDomainBlockStatsFlags(dom, device, params, &nparams, 0) < 0) {
vshError(ctl, _("Failed to get block stats for domain '%s' device '%s'"), name, device);
- goto cleanup;
+ return false;
}
/* set for prettier output */
}
}
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
#undef DOMBLKSTAT_LEGACY_PRINT
g_autoptr(virshDomain) dom = NULL;
const char *name = NULL, *device = NULL;
virDomainInterfaceStatsStruct stats;
- bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
return false;
if (vshCommandOptStringReq(ctl, cmd, "interface", &device) < 0)
- goto cleanup;
+ return false;
if (virDomainInterfaceStats(dom, device, &stats, sizeof(stats)) == -1) {
vshError(ctl, _("Failed to get interface stats %s %s"), name, device);
- goto cleanup;
+ return false;
}
if (stats.rx_bytes >= 0)
if (stats.tx_drop >= 0)
vshPrint(ctl, "%s tx_drop %lld\n", device, stats.tx_drop);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
cmdDomstate(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = true;
bool showReason = vshCommandOptBool(cmd, "reason");
int state, reason;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
- if ((state = virshDomainState(ctl, dom, &reason)) < 0) {
- ret = false;
- goto cleanup;
- }
+ if ((state = virshDomainState(ctl, dom, &reason)) < 0)
+ return false;
if (showReason) {
vshPrint(ctl, "%s (%s)\n",
virshDomainStateToString(state));
}
- cleanup:
- return ret;
+ return true;
}
/*
cmdDomTime(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
bool now = vshCommandOptBool(cmd, "now");
bool pretty = vshCommandOptBool(cmd, "pretty");
bool rtcSync = vshCommandOptBool(cmd, "sync");
if (rv < 0) {
/* invalid integer format */
- goto cleanup;
+ return false;
} else if (rv > 0) {
/* valid integer to set */
doSet = true;
if (doSet || now || rtcSync) {
if (now && ((seconds = time(NULL)) == (time_t) -1)) {
vshError(ctl, _("Unable to get current time"));
- goto cleanup;
+ return false;
}
if (rtcSync)
flags |= VIR_DOMAIN_TIME_SYNC;
if (virDomainSetTime(dom, seconds, nseconds, flags) < 0)
- goto cleanup;
+ return false;
} else {
if (virDomainGetTime(dom, &seconds, &nseconds, flags) < 0)
- goto cleanup;
+ return false;
if (pretty) {
g_autoptr(GDateTime) then = NULL;
}
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
const char *from = NULL;
char *buffer;
int rv;
- bool ret = false;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
bool current = vshCommandOptBool(cmd, "current");
bool config = vshCommandOptBool(cmd, "config");
return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
- goto cleanup;
+ return false;
if (persistent &&
virDomainIsActive(dom) == 1)
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl);
- goto cleanup;
+ return false;
}
if (flags || current)
if (rv < 0) {
vshError(ctl, _("Failed to attach device from %s"), from);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, "%s", _("Device attached successfully\n"));
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
virNetDevBandwidthRate inbound, outbound;
virDomainNetType typ;
int ret;
- bool functionReturn = false;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autofree char *xml = NULL;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 ||
vshCommandOptStringReq(ctl, cmd, "inbound", &inboundStr) < 0 ||
vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0)
- goto cleanup;
+ return false;
/* check interface type */
if ((int)(typ = virDomainNetTypeFromString(type)) < 0) {
vshError(ctl, _("No support for %s in command 'attach-interface'"),
type);
- goto cleanup;
+ return false;
}
if (inboundStr) {
memset(&inbound, 0, sizeof(inbound));
if (virshParseRateStr(ctl, inboundStr, &inbound) < 0)
- goto cleanup;
+ return false;
if (!inbound.average && !inbound.floor) {
vshError(ctl, _("either inbound average or floor is mandatory"));
- goto cleanup;
+ return false;
}
}
if (outboundStr) {
memset(&outbound, 0, sizeof(outbound));
if (virshParseRateStr(ctl, outboundStr, &outbound) < 0)
- goto cleanup;
+ return false;
if (outbound.average == 0) {
vshError(ctl, _("outbound average is mandatory"));
- goto cleanup;
+ return false;
}
if (outbound.floor) {
vshError(ctl, _("outbound floor is unsupported yet"));
- goto cleanup;
+ return false;
}
}
if (virshAddressParse(pciaddrstr, false, &addr) < 0) {
vshError(ctl, _("cannot parse pci address '%s' for network interface"),
source);
- goto cleanup;
+ return false;
}
virBufferAddLit(&buf, "<source>\n");
case VIR_DOMAIN_NET_TYPE_LAST:
vshError(ctl, _("No support for %s in command 'attach-interface'"),
type);
- goto cleanup;
+ return false;
break;
}
if (vshCommandOptBool(cmd, "print-xml")) {
vshPrint(ctl, "%s", xml);
- functionReturn = true;
- goto cleanup;
+ return true;
}
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
- goto cleanup;
+ return false;
if (persistent &&
virDomainIsActive(dom) == 1)
if (ret != 0) {
vshError(ctl, "%s", _("Failed to attach interface"));
- } else {
- vshPrintExtra(ctl, "%s", _("Interface attached successfully\n"));
- functionReturn = true;
+ return false;
}
- cleanup:
- return functionReturn;
+ vshPrintExtra(ctl, "%s", _("Interface attached successfully\n"));
+
+ return true;
}
/*
VSH_EXCLUSIVE_OPTIONS_VAR(bytes, async);
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
- goto cleanup;
+ return false;
/* XXX Allow path to be optional to list info on all devices at once */
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
- goto cleanup;
+ return false;
if (bandwidth)
ret = virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes);
else
ret = virshBlockJobInfo(ctl, dom, path, raw, bytes);
- cleanup:
return ret;
}
cmdConsole(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
bool force = vshCommandOptBool(cmd, "force");
bool safe = vshCommandOptBool(cmd, "safe");
unsigned int flags = 0;
return false;
if (vshCommandOptStringReq(ctl, cmd, "devname", &name) < 0) /* sc_prohibit_devname */
- goto cleanup;
+ return false;
if (force)
flags |= VIR_DOMAIN_CONSOLE_FORCE;
if (safe)
flags |= VIR_DOMAIN_CONSOLE_SAFE;
- ret = cmdRunConsole(ctl, dom, name, flags);
-
- cleanup:
- return ret;
+ return cmdRunConsole(ctl, dom, name, flags);
}
#endif /* WIN32 */
const char *element;
const char *attr;
bool config;
- bool ret = false;
unsigned int flags = 0;
unsigned int xmlflags = 0;
size_t i;
if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0 ||
vshCommandOptStringReq(ctl, cmd, "state", &state) < 0)
- goto cleanup;
+ return false;
config = vshCommandOptBool(cmd, "config");
if (STRNEQ(state, "up") && STRNEQ(state, "down")) {
vshError(ctl, _("invalid link state '%s'"), state);
- goto cleanup;
+ return false;
}
if (config) {
flags = VIR_DOMAIN_AFFECT_CONFIG;
if (virshDomainGetXMLFromDom(ctl, dom, xmlflags, &xml, &ctxt) < 0)
- goto cleanup;
+ return false;
obj = xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt);
if (obj == NULL || obj->type != XPATH_NODESET ||
obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) {
vshError(ctl, _("Failed to extract interface information or no interfaces found"));
- goto cleanup;
+ return false;
}
if (virMacAddrParse(iface, &macaddr) == 0) {
}
vshError(ctl, _("interface (%s: %s) not found"), element, iface);
- goto cleanup;
+ return false;
hit:
/* find and modify/add link state node */
BAD_CAST "link",
NULL);
if (!cur)
- goto cleanup;
+ return false;
if (xmlNewProp(cur, BAD_CAST "state", BAD_CAST state) == NULL)
- goto cleanup;
+ return false;
}
if (!(xml_buf = virXMLNodeToString(xml, obj->nodesetval->nodeTab[i]))) {
vshSaveLibvirtError();
vshError(ctl, _("Failed to create XML"));
- goto cleanup;
+ return false;
}
if (virDomainUpdateDeviceFlags(dom, xml_buf, flags) < 0) {
vshError(ctl, _("Failed to update interface link state"));
- goto cleanup;
- } else {
- vshPrintExtra(ctl, "%s", _("Device updated successfully\n"));
- ret = true;
+ return false;
}
- cleanup:
+ vshPrintExtra(ctl, "%s", _("Device updated successfully\n"));
- return ret;
+ return true;
}
/* "domiftune" command
{
g_autoptr(virshDomain) dom = NULL;
const char *name;
- bool ret = false;
const char *target = NULL;
int suspendTarget;
unsigned long long duration = 0;
return false;
if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0)
- goto cleanup;
+ return false;
if ((suspendTarget = virshNodeSuspendTargetTypeFromString(target)) < 0) {
vshError(ctl, "%s", _("Invalid target"));
- goto cleanup;
+ return false;
}
if (virDomainPMSuspendForDuration(dom, suspendTarget, duration, 0) < 0) {
vshError(ctl, _("Domain '%s' could not be suspended"),
virDomainGetName(dom));
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("Domain '%s' successfully suspended"),
virDomainGetName(dom));
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
{
g_autoptr(virshDomain) dom = NULL;
const char *name;
- bool ret = false;
unsigned int flags = 0;
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
if (virDomainPMWakeup(dom, flags) < 0) {
vshError(ctl, _("Domain '%s' could not be woken up"),
virDomainGetName(dom));
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("Domain '%s' successfully woken up"),
virDomainGetName(dom));
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
cmdStart(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
#ifndef WIN32
bool console = vshCommandOptBool(cmd, "console");
#endif
if (virDomainGetID(dom) != (unsigned int)-1) {
vshError(ctl, "%s", _("Domain is already active"));
- goto cleanup;
+ return false;
}
if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptBool(cmd, "paused"))
flags |= VIR_DOMAIN_START_PAUSED;
if (last_error->code != VIR_ERR_NO_SUPPORT &&
last_error->code != VIR_ERR_INVALID_ARG) {
vshReportError(ctl);
- goto cleanup;
+ return false;
}
vshResetLibvirtError();
rc = virDomainHasManagedSaveImage(dom, 0);
} else if (rc > 0) {
if (virDomainManagedSaveRemove(dom, 0) < 0) {
vshReportError(ctl);
- goto cleanup;
+ return false;
}
}
flags &= ~VIR_DOMAIN_START_FORCE_BOOT;
(flags ? virDomainCreateWithFlags(dom, flags)
: virDomainCreate(dom))) < 0) {
vshError(ctl, _("Failed to start domain '%s'"), virDomainGetName(dom));
- goto cleanup;
+ return false;
}
started:
virDomainGetName(dom));
#ifndef WIN32
if (console && !cmdRunConsole(ctl, dom, NULL, 0))
- goto cleanup;
+ return false;
#endif
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd)
{
const char *file = NULL;
- bool ret = false;
unsigned int flags = 0;
g_autofree char *xml = NULL;
virshControl *priv = ctl->privData;
xml = virDomainSaveImageGetXMLDesc(priv->conn, file, flags);
if (!xml)
- goto cleanup;
+ return false;
vshPrint(ctl, "%s", xml);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd)
{
const char *file = NULL;
- bool ret = false;
const char *xmlfile = NULL;
g_autofree char *xml = NULL;
unsigned int flags = 0;
return false;
if (virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
- goto cleanup;
+ return false;
if (virDomainSaveImageDefineXML(priv->conn, file, xml, flags) < 0) {
vshError(ctl, _("Failed to update %s"), file);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("State file %s updated.\n"), file);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
{
g_autoptr(virshDomain) dom = NULL;
const char *name;
- bool ret = false;
int hassave;
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
hassave = virDomainHasManagedSaveImage(dom, 0);
if (hassave < 0) {
vshError(ctl, "%s", _("Failed to check for domain managed save image"));
- goto cleanup;
+ return false;
}
if (hassave) {
if (virDomainManagedSaveRemove(dom, 0) < 0) {
vshError(ctl, _("Failed to remove managed save image for domain '%s'"),
name);
- goto cleanup;
+ return false;
}
else
vshPrintExtra(ctl, _("Removed managedsave image for domain '%s'"), name);
vshPrintExtra(ctl, _("Domain '%s' has no manage save image; removal skipped"),
name);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
dom = virshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
- goto cleanup;
+ return false;
#define EDIT_GET_XML virDomainManagedSaveGetXMLDesc(dom, getxml_flags)
#define EDIT_NOT_CHANGED \
static bool
cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd)
{
- bool ret = false;
g_autoptr(virshDomain) dom = NULL;
unsigned int flags = 0;
g_autofree char *xml = NULL;
flags |= VIR_DOMAIN_XML_SECURE;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
- goto cleanup;
+ return false;
if (!(xml = virDomainManagedSaveGetXMLDesc(dom, flags)))
- goto cleanup;
+ return false;
vshPrint(ctl, "%s", xml);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
static bool
cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd)
{
- bool ret = false;
g_autoptr(virshDomain) dom = NULL;
const char *xmlfile = NULL;
g_autofree char *xml = NULL;
return false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
- goto cleanup;
+ return false;
if (virDomainManagedSaveDefineXML(dom, xml, flags) < 0) {
vshError(ctl, _("Failed to update %s XML configuration"),
virDomainGetName(dom));
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("Managed save state file of domain '%s' updated.\n"),
virDomainGetName(dom));
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
cmdRestore(vshControl *ctl, const vshCmd *cmd)
{
const char *from = NULL;
- bool ret = false;
unsigned int flags = 0;
const char *xmlfile = NULL;
g_autofree char *xml = NULL;
if (xmlfile &&
virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
- goto cleanup;
+ return false;
if (((flags || xml)
? virDomainRestoreFlags(priv->conn, from, xml, flags)
: virDomainRestore(priv->conn, from)) < 0) {
vshError(ctl, _("Failed to restore domain from %s"), from);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("Domain restored from %s\n"), from);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptBool(cmd, "verbose"))
verbose = true;
true,
doDump,
&data) < 0)
- goto cleanup;
+ return false;
virshWatchJob(ctl, dom, verbose, eventLoop,
&data.ret, 0, NULL, NULL, _("Dump"));
virThreadJoin(&workerThread);
- if (!data.ret)
- vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to);
+ if (data.ret)
+ return false;
- cleanup:
- return !data.ret;
+ vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to);
+
+ return true;
}
static const vshCmdInfo info_screenshot[] = {
const char *password = NULL;
const char *user = NULL;
unsigned int flags = 0;
- bool ret = false;
if (vshCommandOptBool(cmd, "encrypted"))
flags = VIR_DOMAIN_PASSWORD_ENCRYPTED;
return false;
if (virDomainSetUserPassword(dom, user, password, flags) < 0)
- goto cleanup;
+ return false;
vshPrintExtra(ctl, _("Password set successfully for %s in %s"), user, name);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
* "resume" command
cmdShutdown(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
const char *name;
const char *mode = NULL;
int flags = 0;
vshError(ctl, _("Unknown mode %s value, expecting "
"'acpi', 'agent', 'initctl', 'signal', "
"or 'paravirt'"), mode);
- goto cleanup;
+ return false;
}
tmp++;
}
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
- goto cleanup;
+ return false;
if (flags)
rv = virDomainShutdownFlags(dom, flags);
vshPrintExtra(ctl, _("Domain '%s' is being shutdown\n"), name);
} else {
vshError(ctl, _("Failed to shutdown domain '%s'"), name);
- goto cleanup;
+ return false;
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
cmdReboot(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
const char *name;
const char *mode = NULL;
int flags = 0;
vshError(ctl, _("Unknown mode %s value, expecting "
"'acpi', 'agent', 'initctl', 'signal' "
"or 'paravirt'"), mode);
- goto cleanup;
+ return false;
}
tmp++;
}
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
- goto cleanup;
+ return false;
if (virDomainReboot(dom, flags) == 0) {
vshPrintExtra(ctl, _("Domain '%s' is being rebooted\n"), name);
} else {
vshError(ctl, _("Failed to reboot domain '%s'"), name);
- goto cleanup;
+ return false;
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
bool maximum = vshCommandOptBool(cmd, "maximum");
bool active = vshCommandOptBool(cmd, "active");
bool config = vshCommandOptBool(cmd, "config");
VIR_DOMAIN_AFFECT_LIVE, true);
if (conf_max == -2 || conf_cur == -2 || live_max == -2 || live_cur == -2)
- goto cleanup;
+ return false;
#define PRINT_COUNT(VAR, WHICH, STATE) if (VAR > 0) \
vshPrint(ctl, "%-12s %-12s %3d\n", WHICH, STATE, VAR)
int count = virshCPUCountCollect(ctl, dom, flags, false);
if (count < 0)
- goto cleanup;
+ return false;
vshPrint(ctl, "%d\n", count);
}
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
{
g_autofree char *str = NULL;
size_t i;
- int ret = -1;
vshPrint(ctl, "%-15s ", _("CPU Affinity:"));
if (pretty) {
if (!(str = virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(maxcpu))))
- goto cleanup;
+ return -1;
vshPrint(ctl, _("%s (out of %d)"), str, maxcpu);
} else {
for (i = 0; i < maxcpu; i++)
}
vshPrint(ctl, "\n");
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
flags |= VIR_DOMAIN_XML_INACTIVE;
if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0)
- goto cleanup;
+ return NULL;
if (virXPathUInt("string(/domain/vcpu)", ctxt, &maxvcpus) < 0) {
vshError(ctl, "%s", _("Failed to retrieve maximum vcpu count"));
- goto cleanup;
+ return NULL;
}
ignore_value(virXPathUInt("string(/domain/vcpu/@current)", ctxt, &curvcpus));
for (i = 0; i < curvcpus; i++)
ignore_value(virBitmapSetBit(ret, i));
- goto cleanup;
+ return NULL;
}
for (i = 0; i < nnodes; i++) {
if (virBitmapCountBits(ret) != curvcpus) {
vshError(ctl, "%s", _("Failed to retrieve vcpu state bitmap"));
virBitmapFree(ret);
- ret = NULL;
+ return NULL;
}
- cleanup:
return ret;
}
int cpumaplen;
size_t i;
int ncpus;
- bool ret = false;
g_autoptr(vshTable) table = NULL;
if ((ncpus = virshCPUCountCollect(ctl, dom, countFlags, true)) < 0) {
else
vshError(ctl, "%s", _("cannot get vcpupin for transient domain"));
}
- goto cleanup;
+ return false;
}
if (got_vcpu && vcpu >= ncpus) {
vshError(ctl,
_("vcpu %d is out of range of persistent cpu count %d"),
vcpu, ncpus);
- goto cleanup;
+ return false;
}
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
cpumaplen, flags)) >= 0) {
table = vshTableNew(_("VCPU"), _("CPU Affinity"), NULL);
if (!table)
- goto cleanup;
+ return false;
for (i = 0; i < ncpus; i++) {
g_autofree char *pinInfo = NULL;
if (!(pinInfo = virBitmapDataFormat(VIR_GET_CPUMAP(cpumap, cpumaplen, i),
cpumaplen)))
- goto cleanup;
+ return false;
vcpuStr = g_strdup_printf("%zu", i);
if (vshTableRowAppend(table, vcpuStr, pinInfo, NULL) < 0)
- goto cleanup;
+ return false;
}
vshTablePrintToStdout(table, ctl);
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
g_autoptr(virshDomain) dom = NULL;
unsigned int vcpu = 0;
const char *cpulist = NULL;
- bool ret = false;
g_autofree unsigned char *cpumap = NULL;
int cpumaplen;
int maxcpu;
/* Query mode: show CPU affinity information then exit.*/
if (!cpulist) {
- ret = virshVcpuPinQuery(ctl, dom, vcpu, got_vcpu, maxcpu, flags);
- goto cleanup;
+ return virshVcpuPinQuery(ctl, dom, vcpu, got_vcpu, maxcpu, flags);
}
/* Pin mode: pinning specified vcpu to specified physical cpus */
if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
- goto cleanup;
+ return false;
/* use old API without any explicit flags */
if (flags == VIR_DOMAIN_AFFECT_CURRENT && !current) {
if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0)
- goto cleanup;
+ return false;
} else {
if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0)
- goto cleanup;
+ return false;
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
{
g_autoptr(virshDomain) dom = NULL;
const char *cpulist = NULL;
- bool ret = false;
g_autofree unsigned char *cpumap = NULL;
int cpumaplen;
int maxcpu;
/* Query mode: show CPU affinity information then exit.*/
if (query) {
+ bool ret = false;
+
/* When query mode and neither "live", "config" nor "current"
* is specified, set VIR_DOMAIN_AFFECT_CURRENT as flags */
if (flags == -1)
ret = virshPrintPinInfo(ctl, cpumap, cpumaplen);
vshPrint(ctl, "\n");
}
- goto cleanup;
+ return ret;
}
/* Pin mode: pinning emulator threads to specified physical cpus */
if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
- goto cleanup;
+ return false;
if (flags == -1)
flags = VIR_DOMAIN_AFFECT_LIVE;
if (virDomainPinEmulator(dom, cpumap, cpumaplen, flags) != 0)
- goto cleanup;
+ return false;
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
{
g_autoptr(virshDomain) dom = NULL;
unsigned int count = 0;
- bool ret = false;
bool maximum = vshCommandOptBool(cmd, "maximum");
bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live");
return false;
if (vshCommandOptUInt(ctl, cmd, "count", &count) < 0)
- goto cleanup;
+ return false;
if (count == 0) {
vshError(ctl, _("Can't set 0 processors for a VM"));
- goto cleanup;
+ return false;
}
/* none of the options were specified */
if (!current && flags == 0) {
if (virDomainSetVcpus(dom, count) != 0)
- goto cleanup;
+ return false;
} else {
if (virDomainSetVcpusFlags(dom, count, flags) < 0)
- goto cleanup;
+ return false;
}
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
bool live = vshCommandOptBool(cmd, "live");
const char *vcpulist = NULL;
int state = 0;
- bool ret = false;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
VSH_EXCLUSIVE_OPTIONS_VAR(enable, disable);
state = 1;
if (virDomainSetVcpu(dom, vcpulist, state, flags) < 0)
- goto cleanup;
-
- ret = true;
+ return false;
- cleanup:
- return ret;
+ return true;
}
unsigned long long threshold;
const char *dev = NULL;
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
if (vshCommandOptStringReq(ctl, cmd, "dev", &dev))
return false;
return false;
if (virDomainSetBlockThreshold(dom, dev, threshold, 0) < 0)
- goto cleanup;
-
- ret = true;
+ return false;
- cleanup:
- return ret;
+ return true;
}
bool current = vshCommandOptBool(cmd, "current");
unsigned int iothread_id = 0;
int maxcpu;
- bool ret = false;
g_autofree unsigned char *cpumap = NULL;
int cpumaplen;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
return false;
if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0)
- goto cleanup;
+ return false;
if ((maxcpu = virshNodeGetCPUCount(priv->conn)) < 0)
- goto cleanup;
+ return false;
if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
- goto cleanup;
+ return false;
if (virDomainPinIOThread(dom, iothread_id,
cpumap, cpumaplen, flags) != 0)
- goto cleanup;
-
- ret = true;
+ return false;
- cleanup:
- return ret;
+ return true;
}
/*
{
g_autoptr(virshDomain) dom = NULL;
int iothread_id = 0;
- bool ret = false;
bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live");
bool current = vshCommandOptBool(cmd, "current");
return false;
if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0)
- goto cleanup;
+ return false;
if (iothread_id <= 0) {
vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id);
- goto cleanup;
+ return false;
}
if (virDomainAddIOThread(dom, iothread_id, flags) < 0)
- goto cleanup;
-
- ret = true;
+ return false;
- cleanup:
- return ret;
+ return true;
}
{
g_autoptr(virshDomain) dom = NULL;
int iothread_id = 0;
- bool ret = false;
bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live");
bool current = vshCommandOptBool(cmd, "current");
return false;
if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0)
- goto cleanup;
+ return false;
if (iothread_id <= 0) {
vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id);
- goto cleanup;
+ return false;
}
if (virDomainDelIOThread(dom, iothread_id, flags) < 0)
- goto cleanup;
-
- ret = true;
+ return false;
- cleanup:
- return ret;
+ return true;
}
/*
{
g_autoptr(virshDomain) dom = NULL;
const char *from = NULL;
- bool ret = false;
g_autofree char *buffer = NULL;
#ifndef WIN32
bool console = vshCommandOptBool(cmd, "console");
return false;
if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptBool(cmd, "paused"))
flags |= VIR_DOMAIN_START_PAUSED;
if (!dom) {
vshError(ctl, _("Failed to create domain from %s"), from);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("Domain '%s' created from %s\n"),
if (console)
cmdRunConsole(ctl, dom, NULL, 0);
#endif
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
if (vshCommandOptStringReq(ctl, cmd, "uri", &uri) < 0 ||
vshCommandOptStringReq(ctl, cmd, "key", &key) < 0 ||
vshCommandOptStringReq(ctl, cmd, "set", &set) < 0)
- goto cleanup;
+ return false;
if ((set || edit) && !key) {
vshError(ctl, "%s",
_("namespace key is required when modifying metadata"));
- goto cleanup;
+ return false;
}
if (set || rem) {
if (virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT,
set, key, uri, flags))
- goto cleanup;
+ return false;
if (rem)
vshPrintExtra(ctl, "%s\n", _("Metadata removed"));
/* get */
if (!(data = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT,
uri, flags)))
- goto cleanup;
+ return false;
vshPrint(ctl, "%s\n", data);
}
cmdSendKey(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
const char *codeset_option;
int codeset;
unsigned int holdtime = 0;
codeset_option = "linux";
if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0)
- goto cleanup;
+ return false;
/* The qnum codeset was originally called rfb, so we need to keep
* accepting the old name for backwards compatibility reasons */
codeset = virKeycodeSetTypeFromString(codeset_option);
if (codeset < 0) {
vshError(ctl, _("unknown codeset: '%s'"), codeset_option);
- goto cleanup;
+ return false;
}
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
if (count == VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
vshError(ctl, _("too many keycodes"));
- goto cleanup;
+ return false;
}
if ((keycode = virshKeyCodeGetInt(opt->data)) < 0) {
if ((keycode = virKeycodeValueFromString(codeset, opt->data)) < 0) {
vshError(ctl, _("invalid keycode: '%s'"), opt->data);
- goto cleanup;
+ return false;
}
}
count++;
}
- if (!(virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0))
- ret = true;
+ if (virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0)
+ return false;
- cleanup:
- return ret;
+ return true;
}
/*
unsigned long long bytes = 0;
unsigned long long max;
unsigned long kibibytes = 0;
- bool ret = false;
bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live");
bool current = vshCommandOptBool(cmd, "current");
else
max = ULONG_MAX;
if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0)
- goto cleanup;
+ return false;
kibibytes = VIR_DIV_UP(bytes, 1024);
if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0)
- goto cleanup;
+ return false;
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
unsigned long long bytes = 0;
unsigned long long max;
unsigned long kibibytes = 0;
- bool ret = false;
bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live");
bool current = vshCommandOptBool(cmd, "current");
else
max = ULONG_MAX;
if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0)
- goto cleanup;
+ return false;
kibibytes = VIR_DIV_UP(bytes, 1024);
if (virDomainSetMemoryFlags(dom, kibibytes, flags | VIR_DOMAIN_MEM_MAXIMUM) < 0) {
vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
- goto cleanup;
+ return false;
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
const vshCmdOpt *opt = NULL;
g_autofree char **cmdargv = NULL;
size_t ncmdargv = 0;
dom = virshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
- goto cleanup;
+ return false;
if (vshCommandOptBool(cmd, "noseclabel"))
setlabel = false;
cmdargv[ncmdargv - 1] = NULL;
if ((nfdlist = virDomainLxcOpenNamespace(dom, &fdlist, 0)) < 0)
- goto cleanup;
+ return false;
if (setlabel) {
secmodel = g_new0(virSecurityModel, 1);
seclabel = g_new0(virSecurityLabel, 1);
if (virNodeGetSecurityModel(priv->conn, secmodel) < 0)
- goto cleanup;
+ return false;
if (virDomainGetSecurityLabel(dom, seclabel) < 0)
- goto cleanup;
+ return false;
}
/* Fork once because we don't want to affect
* can only be changed in single-threaded process
*/
if ((pid = virFork()) < 0)
- goto cleanup;
+ return false;
if (pid == 0) {
int status;
VIR_FREE(fdlist);
if (virProcessWait(pid, NULL, false) < 0) {
vshReportError(ctl);
- goto cleanup;
+ return false;
}
}
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
static bool
cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
{
- bool ret = false;
const char *format = NULL;
const char *xmlFile = NULL;
g_autofree char *configData = NULL;
xmlData = virDomainGetXMLDesc(dom, flags);
} else if (xmlFile) {
if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0)
- goto cleanup;
+ return false;
} else {
vshError(ctl, "%s", _("need either domain or domain XML"));
- goto cleanup;
+ return false;
}
if (!xmlData) {
vshError(ctl, "%s", _("failed to retrieve XML"));
- goto cleanup;
+ return false;
}
- if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags))) {
- goto cleanup;
- } else {
- vshPrint(ctl, "%s", configData);
- ret = true;
- }
+ if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags)))
+ return false;
- cleanup:
- return ret;
+ vshPrint(ctl, "%s", configData);
+
+ return true;
}
/*
{
g_autoptr(virshDomain) dom = NULL;
const char *new_name = NULL;
- bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
- return ret;
+ return false;
if (vshCommandOptStringReq(ctl, cmd, "new-name", &new_name) < 0)
- goto cleanup;
+ return false;
if (virDomainRename(dom, new_name, 0) < 0)
- goto cleanup;
+ return false;
vshPrintExtra(ctl, "Domain successfully renamed\n");
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
{
g_autoptr(virshDomain) dom = NULL;
unsigned long long downtime;
- bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (virDomainMigrateGetMaxDowntime(dom, &downtime, 0) < 0)
- goto done;
+ return false;
vshPrint(ctl, "%llu\n", downtime);
- ret = true;
-
- done:
- return ret;
+ return true;
}
{
g_autoptr(virshDomain) dom = NULL;
unsigned long long size = 0;
- bool ret = false;
const char *unit;
double value;
int rc;
rc = vshCommandOptULongLong(ctl, cmd, "size", &size);
if (rc < 0) {
- goto cleanup;
+ return false;
} else if (rc != 0) {
if (virDomainMigrateSetCompressionCache(dom, size, 0) < 0)
- goto cleanup;
+ return false;
}
if (virDomainMigrateGetCompressionCache(dom, &size, 0) < 0)
- goto cleanup;
+ return false;
value = vshPrettyCapacity(size, &unit);
vshPrint(ctl, _("Compression cache: %.3lf %s"), value, unit);
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
g_autoptr(virshDomain) dom = NULL;
unsigned long bandwidth = 0;
unsigned int flags = 0;
- bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0)
- goto done;
+ return false;
if (vshCommandOptBool(cmd, "postcopy"))
flags |= VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY;
if (virDomainMigrateSetMaxSpeed(dom, bandwidth, flags) < 0)
- goto done;
-
- ret = true;
+ return false;
- done:
- return ret;
+ return true;
}
/*
g_autoptr(virshDomain) dom = NULL;
unsigned long bandwidth;
unsigned int flags = 0;
- bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
flags |= VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY;
if (virDomainMigrateGetMaxSpeed(dom, &bandwidth, flags) < 0)
- goto done;
+ return false;
vshPrint(ctl, "%lu\n", bandwidth);
- ret = true;
-
- done:
- return ret;
+ return true;
}
/*
cmdMigratePostCopy(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (virDomainMigrateStartPostCopy(dom, 0) < 0)
- goto cleanup;
-
- ret = true;
+ return false;
- cleanup:
- return ret;
+ return true;
}
/*
g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
int port = 0;
g_autofree char *listen_addr = NULL;
/* Check if the domain is active and don't rely on -1 for this */
if (!virDomainIsActive(dom)) {
vshError(ctl, _("Domain is not running"));
- goto cleanup;
+ return false;
}
if (virshDomainGetXMLFromDom(ctl, dom, 0, &xml, &ctxt) < 0)
- goto cleanup;
+ return false;
/* Get the VNC port */
if (virXPathInt("string(/domain/devices/graphics[@type='vnc']/@port)",
ctxt, &port)) {
vshError(ctl, _("Failed to get VNC port. Is this domain using VNC?"));
- goto cleanup;
+ return false;
}
listen_addr = virXPathString("string(/domain/devices/graphics"
else
vshPrint(ctl, "%s:%d\n", listen_addr, port-5900);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
{
g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
- bool ret = false;
g_autofree char *tty = NULL;
if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0)
return false;
if (!(tty = virXPathString("string(/domain/devices/console/@tty)", ctxt)))
- goto cleanup;
+ return false;
vshPrint(ctl, "%s\n", tty);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live");
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
- bool ret = false;
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
return false;
if (vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0)
- goto cleanup;
+ return false;
if (virDomainDetachDeviceAlias(dom, alias, flags) < 0) {
vshError(ctl, _("Failed to detach device with alias %s"), alias);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, "%s", _("Device detach request sent successfully\n"));
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
g_autoptr(virshDomain) dom = NULL;
const char *from = NULL;
g_autofree char *buffer = NULL;
- bool ret = false;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
bool current = vshCommandOptBool(cmd, "current");
bool config = vshCommandOptBool(cmd, "config");
return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
- goto cleanup;
+ return false;
if (persistent &&
virDomainIsActive(dom) == 1)
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl);
- goto cleanup;
+ return false;
}
if (vshCommandOptBool(cmd, "force"))
if (virDomainUpdateDeviceFlags(dom, buffer, flags) < 0) {
vshError(ctl, _("Failed to update device from %s"), from);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, "%s", _("Device updated successfully\n"));
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
g_autoptr(xmlXPathObject) obj = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr cur = NULL;
- xmlNodePtr ret = NULL;
size_t i;
xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt);
if (!xml) {
vshError(NULL, "%s", _("Failed to get disk information"));
- goto cleanup;
+ return NULL;
}
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
obj->nodesetval == NULL ||
obj->nodesetval->nodeNr == 0) {
vshError(NULL, "%s", _("Failed to get disk information"));
- goto cleanup;
+ return NULL;
}
/* search disk using @path */
}
if (STREQ_NULLABLE(tmp, path)) {
- ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1);
+ xmlNodePtr ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1);
/* drop backing store since they are not needed here */
virshDiskDropBackingStore(ret);
- goto cleanup;
+ return ret;
}
}
cur = cur->next;
vshError(NULL, _("No disk found whose source path or target is %s"), path);
- cleanup:
- return ret;
+ return NULL;
}
typedef enum {
if (!(STREQ_NULLABLE(device_type, "cdrom") ||
STREQ_NULLABLE(device_type, "floppy"))) {
vshError(NULL, _("The disk device '%s' is not removable"), target);
- goto cleanup;
+ return NULL;
}
/* find the current source subelement */
if (type == VIRSH_UPDATE_DISK_XML_EJECT) {
if (!source) {
vshError(NULL, _("The disk device '%s' doesn't have media"), target);
- goto cleanup;
+ return NULL;
}
/* forcibly switch to empty file cdrom */
new_source = NULL;
} else if (!new_source) {
vshError(NULL, _("New disk media source was not specified"));
- goto cleanup;
+ return NULL;
}
if (source) {
if (source_path && type == VIRSH_UPDATE_DISK_XML_INSERT) {
vshError(NULL, _("The disk device '%s' already has media"), target);
- goto cleanup;
+ return NULL;
}
startupPolicy = virXMLPropString(source, "startupPolicy");
if (!(ret = virXMLNodeToString(NULL, disk_node))) {
vshSaveLibvirtError();
- goto cleanup;
+ return NULL;
}
- cleanup:
return ret;
}
cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
unsigned long long minimum = 0;
const char *mountPoint = NULL;
unsigned int flags = 0;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
- return ret;
+ return false;
if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptStringReq(ctl, cmd, "mountpoint", &mountPoint) < 0)
- goto cleanup;
+ return false;
if (virDomainFSTrim(dom, mountPoint, minimum, flags) < 0) {
vshError(ctl, _("Unable to invoke fstrim"));
- goto cleanup;
+ return false;
}
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
static const vshCmdInfo info_domfsfreeze[] = {
g_autoptr(virshDomain) dom = NULL;
int timeout = VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK;
const unsigned int flags = 0;
- bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (vshCommandOptInt(ctl, cmd, "timeout", &timeout) < 0)
- goto cleanup;
+ return false;
if (virDomainAgentSetResponseTimeout(dom, timeout, flags) < 0)
- goto cleanup;
+ return false;
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
int nkeys = 0;
size_t i;
const unsigned int flags = 0;
- bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0)
- goto cleanup;
+ return false;
nkeys = virDomainAuthorizedSSHKeysGet(dom, user, &keys, flags);
if (nkeys < 0)
- goto cleanup;
+ return false;
for (i = 0; i < nkeys; i++) {
vshPrint(ctl, "%s", keys[i]);
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
g_auto(GStrv) keys = NULL;
int nkeys = 0;
unsigned int flags = 0;
- bool ret = false;
VSH_REQUIRE_OPTION("remove", "file");
VSH_EXCLUSIVE_OPTIONS("reset", "remove");
return false;
if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptBool(cmd, "remove")) {
flags |= VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE;
if (!from) {
vshError(ctl, _("Option --file is required"));
- goto cleanup;
+ return false;
}
}
}
if (from) {
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshSaveLibvirtError();
- goto cleanup;
+ return false;
}
if (!(keys = g_strsplit(buffer, "\n", -1)))
- goto cleanup;
+ return false;
nkeys = g_strv_length(keys);
if (nkeys == 0) {
vshError(ctl, _("File %s contains no keys"), from);
- goto cleanup;
+ return false;
}
}
if (virDomainAuthorizedSSHKeysSet(dom, user,
(const char **) keys, nkeys, flags) < 0) {
- goto cleanup;
+ return false;
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
{
g_autoptr(virshDomain) dom = NULL;
int seconds = 1; /* the default value is 1 */
- bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (vshCommandOptInt(ctl, cmd, "seconds", &seconds) < 0)
- goto cleanup;
+ return false;
if (virDomainStartDirtyRateCalc(dom, seconds, 0) < 0)
- goto cleanup;
+ return false;
vshPrintExtra(ctl, _("Start to calculate domain's memory "
"dirty rate successfully.\n"));
- ret = true;
- cleanup:
- return ret;
+ return true;
}