lib: Drop needless one line labels

In some cases we have a label that contains nothing but a return
statement. The amount of such labels rises as we use automagic
cleanup. Anyway, such labels are pointless and can be dropped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik
2021-11-04 15:26:07 +01:00
parent 3010a69226
commit 784e9e2b62
27 changed files with 196 additions and 320 deletions

View File

@@ -4453,7 +4453,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
goto cleanup;
return false;
if (vshCommandOptBool(cmd, "verbose"))
verbose = true;
@@ -4462,7 +4462,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
true,
doSave,
&data) < 0)
goto cleanup;
return false;
virshWatchJob(ctl, dom, verbose, eventLoop,
&data.ret, 0, NULL, NULL, _("Save"));
@@ -4472,7 +4472,6 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
if (!data.ret)
vshPrintExtra(ctl, _("\nDomain '%s' saved to %s\n"), name, to);
cleanup:
return !data.ret;
}
@@ -4770,7 +4769,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
true,
doManagedsave,
&data) < 0)
goto cleanup;
return false;
virshWatchJob(ctl, dom, verbose, eventLoop,
&data.ret, 0, NULL, NULL, _("Managedsave"));
@@ -4780,7 +4779,6 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
if (!data.ret)
vshPrintExtra(ctl, _("\nDomain '%s' state saved by libvirt\n"), name);
cleanup:
return !data.ret;
}

View File

@@ -1070,7 +1070,7 @@ vshExtractCPUDefXMLs(vshControl *ctl,
int n;
if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &buffer) < 0)
goto error;
return NULL;
/* Strip possible XML declaration */
if (STRPREFIX(buffer, "<?xml") && (doc = strstr(buffer, "?>")))
@@ -1081,7 +1081,7 @@ vshExtractCPUDefXMLs(vshControl *ctl,
xmlStr = g_strdup_printf("<container>%s</container>", doc);
if (!(xml = virXMLParseStringCtxt(xmlStr, xmlFile, &ctxt)))
goto error;
return NULL;
n = virXPathNodeSet("/container/cpu|"
"/container/domain/cpu|"
@@ -1090,13 +1090,13 @@ vshExtractCPUDefXMLs(vshControl *ctl,
"mode[@name='host-model' and @supported='yes']",
ctxt, &nodes);
if (n < 0)
goto error;
return NULL;
if (n == 0) {
vshError(ctl, _("File '%s' does not contain any <cpu> element or "
"valid domain XML, host capabilities XML, or "
"domain capabilities XML"), xmlFile);
goto error;
return NULL;
}
cpus = g_new0(char *, n + 1);
@@ -1111,22 +1111,18 @@ vshExtractCPUDefXMLs(vshControl *ctl,
vshError(ctl,
_("Cannot extract CPU definition from domain "
"capabilities XML"));
goto error;
return NULL;
}
}
}
if (!(cpus[i] = virXMLNodeToString(xml, nodes[i]))) {
vshSaveLibvirtError();
goto error;
return NULL;
}
}
cleanup:
return g_steal_pointer(&cpus);
error:
goto cleanup;
}

View File

@@ -141,7 +141,6 @@ static bool
cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
const char *device_value = NULL;
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
@@ -149,18 +148,16 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
dev = vshFindNodeDevice(ctl, device_value);
if (!dev)
goto cleanup;
return false;
if (virNodeDeviceDestroy(dev) == 0) {
vshPrintExtra(ctl, _("Destroyed node device '%s'\n"), device_value);
} else {
vshError(ctl, _("Failed to destroy node device '%s'"), device_value);
goto cleanup;
return false;
}
ret = true;
cleanup:
return ret;
return true;
}
struct virshNodeList {
@@ -578,7 +575,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshNodeDevice) device = NULL;
g_autofree char *xml = NULL;
const char *device_value = NULL;
bool ret = false;
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
return false;
@@ -586,16 +582,13 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
device = vshFindNodeDevice(ctl, device_value);
if (!device)
goto cleanup;
return false;
if (!(xml = virNodeDeviceGetXMLDesc(device, 0)))
goto cleanup;
return false;
vshPrint(ctl, "%s\n", xml);
ret = true;
cleanup:
return ret;
return true;
}
/*
@@ -1013,7 +1006,6 @@ static bool
cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{
g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
const char *device_value = NULL;
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
@@ -1022,17 +1014,15 @@ cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
dev = vshFindNodeDevice(ctl, device_value);
if (!dev)
goto cleanup;
return false;
if (virNodeDeviceUndefine(dev, 0) < 0) {
vshError(ctl, _("Failed to undefine node device '%s'"), device_value);
goto cleanup;
return false;
}
vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
ret = true;
cleanup:
return ret;
return true;
}
@@ -1163,7 +1153,6 @@ static bool
cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
const char *name = NULL;
int autostart;
@@ -1172,7 +1161,8 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
dev = vshFindNodeDevice(ctl, name);
if (!dev) goto cleanup;
if (!dev)
return false;
autostart = !vshCommandOptBool(cmd, "disable");
@@ -1181,7 +1171,7 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, _("failed to mark device %s as autostarted"), name);
else
vshError(ctl, _("failed to unmark device %s as autostarted"), name);
goto cleanup;
return false;
}
if (autostart)
@@ -1189,9 +1179,7 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
else
vshPrintExtra(ctl, _("Device %s unmarked as autostarted\n"), name);
ret = true;
cleanup:
return ret;
return true;
}
@@ -1224,7 +1212,6 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshNodeDevice) device = NULL;
const char *device_value = NULL;
bool ret = false;
int autostart;
const char *parent = NULL;
@@ -1234,7 +1221,7 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
device = vshFindNodeDevice(ctl, device_value);
if (!device)
goto cleanup;
return false;
parent = virNodeDeviceGetParent(device);
vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(device));
@@ -1248,9 +1235,7 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
else
vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : _("no"));
ret = true;
cleanup:
return ret;
return true;
}

View File

@@ -238,7 +238,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
unsigned long flags = 0;
virshControl *priv = ctl->privData;
bool ret = false;
if (vshCommandOptBool(cmd, "prealloc-metadata"))
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
@@ -247,27 +246,27 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
return false;
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
goto cleanup;
return false;
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
goto cleanup;
return false;
if (virshVolSize(capacityStr, &capacity) < 0) {
vshError(ctl, _("Malformed size %s"), capacityStr);
goto cleanup;
return false;
}
if (vshCommandOptStringQuiet(ctl, cmd, "allocation", &allocationStr) > 0 &&
virshVolSize(allocationStr, &allocation) < 0) {
vshError(ctl, _("Malformed size %s"), allocationStr);
goto cleanup;
return false;
}
if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 ||
vshCommandOptStringReq(ctl, cmd, "backing-vol", &snapshotStrVol) < 0 ||
vshCommandOptStringReq(ctl, cmd, "backing-vol-format",
&snapshotStrFormat) < 0)
goto cleanup;
return false;
virBufferAddLit(&buf, "<volume>\n");
virBufferAdjustIndent(&buf, 2);
@@ -325,11 +324,11 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
}
if (snapVol == NULL) {
vshError(ctl, _("failed to get vol '%s'"), snapshotStrVol);
goto cleanup;
return false;
}
if ((snapshotStrVolPath = virStorageVolGetPath(snapVol)) == NULL) {
goto cleanup;
return false;
}
/* Create XML for the backing store */
@@ -353,15 +352,12 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
} else {
if (!(vol = virStorageVolCreateXML(pool, xml, flags))) {
vshError(ctl, _("Failed to create vol %s"), name);
goto cleanup;
return false;
}
vshPrintExtra(ctl, _("Vol %s created\n"), name);
}
ret = true;
cleanup:
return ret;
return true;
}
/*
@@ -393,7 +389,6 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshStoragePool) pool = NULL;
g_autoptr(virshStorageVol) vol = NULL;
const char *from = NULL;
bool ret = false;
unsigned int flags = 0;
g_autofree char *buffer = NULL;
@@ -404,23 +399,21 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
goto cleanup;
return false;
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshSaveLibvirtError();
goto cleanup;
return false;
}
if (!(vol = virStorageVolCreateXML(pool, buffer, flags))) {
vshError(ctl, _("Failed to create vol from %s"), from);
goto cleanup;
return false;
}
vshPrintExtra(ctl, _("Vol %s created from %s\n"),
virStorageVolGetName(vol), from);
ret = true;
cleanup:
return ret;
return true;
}
/*
@@ -463,12 +456,11 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshStorageVol) newvol = NULL;
g_autoptr(virshStorageVol) inputvol = NULL;
const char *from = NULL;
bool ret = false;
g_autofree char *buffer = NULL;
unsigned int flags = 0;
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
goto cleanup;
return false;
if (vshCommandOptBool(cmd, "prealloc-metadata"))
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
@@ -477,28 +469,26 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
flags |= VIR_STORAGE_VOL_CREATE_REFLINK;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
goto cleanup;
return false;
if (!(inputvol = virshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL)))
goto cleanup;
return false;
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl);
goto cleanup;
return false;
}
newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags);
if (!newvol) {
vshError(ctl, _("Failed to create vol from %s"), from);
goto cleanup;
return false;
}
vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"),
virStorageVolGetName(newvol), virStorageVolGetName(inputvol));
ret = true;
cleanup:
return ret;
return true;
}
static xmlChar *
@@ -653,7 +643,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
{
const char *file = NULL;
g_autoptr(virshStorageVol) vol = NULL;
bool ret = false;
VIR_AUTOCLOSE fd = -1;
g_autoptr(virshStream) st = NULL;
const char *name = NULL;
@@ -673,16 +662,16 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
goto cleanup;
return false;
if ((fd = open(file, O_RDONLY)) < 0) {
vshError(ctl, _("cannot read %s"), file);
goto cleanup;
return false;
}
if (fstat(fd, &sb) < 0) {
vshError(ctl, _("unable to stat %s"), file);
goto cleanup;
return false;
}
cbData.ctl = ctl;
@@ -694,12 +683,12 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
if (!(st = virStreamNew(priv->conn, 0))) {
vshError(ctl, _("cannot create a new stream"));
goto cleanup;
return false;
}
if (virStorageVolUpload(vol, st, offset, length, flags) < 0) {
vshError(ctl, _("cannot upload to volume %s"), name);
goto cleanup;
return false;
}
if (flags & VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM) {
@@ -707,30 +696,27 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
virshStreamInData,
virshStreamSourceSkip, &cbData) < 0) {
vshError(ctl, _("cannot send data to volume %s"), name);
goto cleanup;
return false;
}
} else {
if (virStreamSendAll(st, virshStreamSource, &cbData) < 0) {
vshError(ctl, _("cannot send data to volume %s"), name);
goto cleanup;
return false;
}
}
if (VIR_CLOSE(fd) < 0) {
vshError(ctl, _("cannot close file %s"), file);
virStreamAbort(st);
goto cleanup;
return false;
}
if (virStreamFinish(st) < 0) {
vshError(ctl, _("cannot close volume %s"), name);
goto cleanup;
return false;
}
ret = true;
cleanup:
return ret;
return true;
}
/*
@@ -931,7 +917,6 @@ static bool
cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshStorageVol) vol = NULL;
bool ret = false;
const char *name;
const char *algorithm_str = NULL;
int algorithm = VIR_STORAGE_VOL_WIPE_ALG_ZERO;
@@ -941,12 +926,12 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
return false;
if (vshCommandOptStringReq(ctl, cmd, "algorithm", &algorithm_str) < 0)
goto out;
return false;
if (algorithm_str &&
(algorithm = virshStorageVolWipeAlgorithmTypeFromString(algorithm_str)) < 0) {
vshError(ctl, _("Unsupported algorithm '%s'"), algorithm_str);
goto out;
return false;
}
if ((funcRet = virStorageVolWipePattern(vol, algorithm, 0)) < 0) {
@@ -957,13 +942,11 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
if (funcRet < 0) {
vshError(ctl, _("Failed to wipe vol %s"), name);
goto out;
return false;
}
vshPrintExtra(ctl, _("Vol %s wiped\n"), name);
ret = true;
out:
return ret;
return true;
}
@@ -1111,7 +1094,6 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
const char *capacityStr = NULL;
unsigned long long capacity = 0;
unsigned int flags = 0;
bool ret = false;
bool delta = vshCommandOptBool(cmd, "delta");
if (vshCommandOptBool(cmd, "allocate"))
@@ -1123,7 +1105,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
return false;
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
goto cleanup;
return false;
virSkipSpaces(&capacityStr);
if (*capacityStr == '-') {
/* The API always requires a positive value; but we allow a
@@ -1134,7 +1116,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
} else {
vshError(ctl, "%s",
_("negative size requires --shrink"));
goto cleanup;
return false;
}
}
@@ -1143,7 +1125,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
if (virshVolSize(capacityStr, &capacity) < 0) {
vshError(ctl, _("Malformed size %s"), capacityStr);
goto cleanup;
return false;
}
if (virStorageVolResize(vol, capacity, flags) < 0) {
@@ -1151,16 +1133,14 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
delta ? _("Failed to change size of volume '%s' by %s")
: _("Failed to change size of volume '%s' to %s"),
virStorageVolGetName(vol), capacityStr);
goto cleanup;
return false;
}
vshPrintExtra(ctl,
delta ? _("Size of volume '%s' successfully changed by %s\n")
: _("Size of volume '%s' successfully changed to %s\n"),
virStorageVolGetName(vol), capacityStr);
ret = true;
cleanup:
return ret;
return true;
}
/*