Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/lxc/lxc_cgroup.c | 70 ++++++++++++++++------------------------
src/lxc/lxc_container.c | 17 ++++------
src/lxc/lxc_controller.c | 44 +++++++++++--------------
src/lxc/lxc_driver.c | 39 +++++++++-------------
src/lxc/lxc_process.c | 34 ++++++++-----------
5 files changed, 81 insertions(+), 123 deletions(-)
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 5efb495b56..549595f538 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -38,29 +38,25 @@ VIR_LOG_INIT("lxc.lxc_cgroup");
static int virLXCCgroupSetupCpuTune(virDomainDefPtr def,
virCgroupPtr cgroup)
{
- int ret = -1;
-
if (def->cputune.sharesSpecified) {
unsigned long long val;
if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0)
- goto cleanup;
+ return -1;
if (virCgroupGetCpuShares(cgroup, &val) < 0)
- goto cleanup;
+ return -1;
def->cputune.shares = val;
}
if (def->cputune.quota != 0 &&
virCgroupSetCpuCfsQuota(cgroup, def->cputune.quota) < 0)
- goto cleanup;
+ return -1;
if (def->cputune.period != 0 &&
virCgroupSetCpuCfsPeriod(cgroup, def->cputune.period) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -160,26 +156,22 @@ static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def,
static int virLXCCgroupSetupMemTune(virDomainDefPtr def,
virCgroupPtr cgroup)
{
- int ret = -1;
-
if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0)
- goto cleanup;
+ return -1;
if (virMemoryLimitIsSet(def->mem.hard_limit))
if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0)
- goto cleanup;
+ return -1;
if (virMemoryLimitIsSet(def->mem.soft_limit))
if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0)
- goto cleanup;
+ return -1;
if (virMemoryLimitIsSet(def->mem.swap_hard_limit))
if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -307,7 +299,6 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
virCgroupPtr cgroup)
{
int capMknod = def->caps_features[VIR_DOMAIN_CAPS_FEATURE_MKNOD];
- int ret = -1;
size_t i;
static virLXCCgroupDevicePolicy devices[] = {
{'c', LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_NULL},
@@ -321,13 +312,13 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
{0, 0, 0}};
if (virCgroupDenyAllDevices(cgroup) < 0)
- goto cleanup;
+ return -1;
/* white list mknod if CAP_MKNOD has to be kept */
if (capMknod == VIR_TRISTATE_SWITCH_ON) {
if (virCgroupAllowAllDevices(cgroup,
VIR_CGROUP_DEVICE_MKNOD) < 0)
- goto cleanup;
+ return -1;
}
for (i = 0; devices[i].type != 0; i++) {
@@ -337,7 +328,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
dev->major,
dev->minor,
VIR_CGROUP_DEVICE_RWM) < 0)
- goto cleanup;
+ return -1;
}
VIR_DEBUG("Allowing any disk block devs");
@@ -352,7 +343,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
VIR_CGROUP_DEVICE_READ :
VIR_CGROUP_DEVICE_RW) |
VIR_CGROUP_DEVICE_MKNOD, false) < 0)
- goto cleanup;
+ return -1;
}
VIR_DEBUG("Allowing any filesystem block devs");
@@ -365,7 +356,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
def->fss[i]->readonly ?
VIR_CGROUP_DEVICE_READ :
VIR_CGROUP_DEVICE_RW, false) < 0)
- goto cleanup;
+ return -1;
}
VIR_DEBUG("Allowing any hostdev block devs");
@@ -383,12 +374,12 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
if ((usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device,
NULL)) == NULL)
- goto cleanup;
+ return -1;
if (virUSBDeviceFileIterate(usb, virLXCSetupHostUSBDeviceCgroup,
cgroup) < 0) {
virUSBDeviceFree(usb);
- goto cleanup;
+ return -1;
}
virUSBDeviceFree(usb);
break;
@@ -399,14 +390,14 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
hostdev->source.caps.u.storage.block,
VIR_CGROUP_DEVICE_RW |
VIR_CGROUP_DEVICE_MKNOD, false) < 0)
- goto cleanup;
+ return -1;
break;
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
if (virCgroupAllowDevicePath(cgroup,
hostdev->source.caps.u.misc.chardev,
VIR_CGROUP_DEVICE_RW |
VIR_CGROUP_DEVICE_MKNOD, false) < 0)
- goto cleanup;
+ return -1;
break;
default:
break;
@@ -418,13 +409,11 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
if (virCgroupAllowDevice(cgroup, 'c', LXC_DEV_MAJ_PTY, -1,
VIR_CGROUP_DEVICE_RWM) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Device whitelist complete");
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -482,25 +471,20 @@ int virLXCCgroupSetup(virDomainDefPtr def,
virCgroupPtr cgroup,
virBitmapPtr nodemask)
{
- int ret = -1;
-
if (virLXCCgroupSetupCpuTune(def, cgroup) < 0)
- goto cleanup;
+ return -1;
if (virLXCCgroupSetupCpusetTune(def, cgroup, nodemask) < 0)
- goto cleanup;
+ return -1;
if (virLXCCgroupSetupBlkioTune(def, cgroup) < 0)
- goto cleanup;
+ return -1;
if (virLXCCgroupSetupMemTune(def, cgroup) < 0)
- goto cleanup;
+ return -1;
if (virLXCCgroupSetupDeviceACL(def, cgroup) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 88dc2e2bdf..61b4622d7b 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -488,7 +488,6 @@ lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
size_t nveths,
char **veths)
{
- int ret = -1;
size_t i;
const char *newname;
virDomainNetDefPtr netDef;
@@ -497,18 +496,18 @@ lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
for (i = 0; i < nveths; i++) {
if (!(netDef = lxcContainerGetNetDef(vmDef, veths[i])))
- goto cleanup;
+ return -1;
newname = netDef->ifname_guest;
if (!newname) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing device name for container-side veth"));
- goto cleanup;
+ return -1;
}
VIR_DEBUG("Renaming %s to %s", veths[i], newname);
if (virNetDevSetName(veths[i], newname) < 0)
- goto cleanup;
+ return -1;
/* Only enable this device if there is a reason to do so (either
* at least one IP was specified, or link state was set to up in
@@ -518,22 +517,20 @@ lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
netDef->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP) {
VIR_DEBUG("Enabling %s", newname);
if (virNetDevSetOnline(newname, true) < 0)
- goto cleanup;
+ return -1;
}
/* set IP addresses and routes */
if (virNetDevIPInfoAddToDev(newname, &netDef->guestIP) < 0)
- goto cleanup;
+ return -1;
}
/* enable lo device only if there were other net devices */
if ((veths || privNet) &&
virNetDevSetOnline("lo", true) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 0c5b9e713d..dda7b375cb 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -358,7 +358,6 @@ static int virLXCControllerValidateNICs(virLXCControllerPtr ctrl)
static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
{
size_t i;
- int ret = -1;
/* Gather the ifindexes of the "parent" veths for all interfaces
* implemented with a veth pair. These will be used when calling
@@ -383,11 +382,11 @@ static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
continue;
if (virNetDevGetIndex(ctrl->def->nets[i]->ifname,
&nicindex) < 0)
- goto cleanup;
+ return -1;
if (VIR_EXPAND_N(ctrl->nicindexes,
ctrl->nnicindexes,
1) < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Index %d for %s", nicindex,
ctrl->def->nets[i]->ifname);
ctrl->nicindexes[ctrl->nnicindexes-1] = nicindex;
@@ -407,17 +406,15 @@ static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported net type %s"),
virDomainNetTypeToString(actualType));
- goto cleanup;
+ return -1;
case VIR_DOMAIN_NET_TYPE_LAST:
default:
virReportEnumRangeError(virDomainNetType, actualType);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -605,7 +602,6 @@ static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl,
static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
{
size_t i;
- int ret = -1;
VIR_DEBUG("Setting up loop devices for filesystems");
@@ -630,33 +626,33 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr
ctrl)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("fs format %s is not supported"),
virStorageFileFormatTypeToString(fs->format));
- goto cleanup;
+ return -1;
}
fd = virLXCControllerSetupLoopDeviceFS(fs);
if (fd < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Saving loop fd %d", fd);
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
VIR_FORCE_CLOSE(fd);
- goto cleanup;
+ return -1;
}
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
} else if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_NBD) {
if (virLXCControllerSetupNBDDeviceFS(fs) < 0)
- goto cleanup;
+ return -1;
/* The NBD device will be cleaned up while the cgroup will end.
* For this we need to remember the qemu-nbd pid and add it to
* the cgroup*/
if (virLXCControllerAppendNBDPids(ctrl, fs->src->path) < 0)
- goto cleanup;
+ return -1;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("fs driver %s is not supported"),
virDomainFSDriverTypeToString(fs->fsdriver));
- goto cleanup;
+ return -1;
}
}
@@ -684,7 +680,7 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk format %s is not supported"),
virStorageFileFormatTypeToString(format));
- goto cleanup;
+ return -1;
}
/* We treat 'none' as meaning 'raw' since we
@@ -693,12 +689,12 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr
ctrl)
*/
fd = virLXCControllerSetupLoopDeviceDisk(disk);
if (fd < 0)
- goto cleanup;
+ return -1;
VIR_DEBUG("Saving loop fd %d", fd);
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
VIR_FORCE_CLOSE(fd);
- goto cleanup;
+ return -1;
}
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
} else if (!driver || STREQ(driver, "nbd")) {
@@ -707,29 +703,27 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr
ctrl)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Disk cache mode %s is not supported"),
virDomainDiskCacheTypeToString(disk->cachemode));
- goto cleanup;
+ return -1;
}
if (virLXCControllerSetupNBDDeviceDisk(disk) < 0)
- goto cleanup;
+ return -1;
/* The NBD device will be cleaned up while the cgroup will end.
* For this we need to remember the qemu-nbd pid and add it to
* the cgroup*/
if (virLXCControllerAppendNBDPids(ctrl, virDomainDiskGetSource(disk)) <
0)
- goto cleanup;
+ return -1;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk driver %s is not supported"),
driver);
- goto cleanup;
+ return -1;
}
}
VIR_DEBUG("Setup all loop devices");
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 41a6a446bd..5caef1a472 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3440,7 +3440,7 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
case VIR_DOMAIN_DEVICE_NET:
net =
dev->data.net;
if (virDomainNetInsert(vmdef, net) < 0)
- goto cleanup;
+ return ret;
dev->data.net = NULL;
ret = 0;
break;
@@ -3464,7 +3464,6 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
break;
}
- cleanup:
return ret;
}
@@ -3482,7 +3481,7 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
case VIR_DOMAIN_DEVICE_NET:
net =
dev->data.net;
if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
- goto cleanup;
+ return -1;
oldDev.data.net = vmdef->nets[idx];
if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev,
@@ -3505,7 +3504,6 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
break;
}
- cleanup:
return ret;
}
@@ -3535,7 +3533,7 @@ lxcDomainDetachDeviceConfig(virDomainDefPtr vmdef,
case VIR_DOMAIN_DEVICE_NET:
net =
dev->data.net;
if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
- goto cleanup;
+ return ret;
/* this is guaranteed to succeed */
virDomainNetDefFree(virDomainNetRemove(vmdef, idx));
@@ -3561,7 +3559,6 @@ lxcDomainDetachDeviceConfig(virDomainDefPtr vmdef,
break;
}
- cleanup:
return ret;
}
@@ -4499,12 +4496,12 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm,
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = NULL;
- int idx, ret = -1;
+ int idx;
if (!priv->initpid) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Cannot attach disk until init PID is known"));
- goto cleanup;
+ return -1;
}
if ((idx = virDomainHostdevFind(vm->def,
@@ -4513,18 +4510,18 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm,
virReportError(VIR_ERR_OPERATION_FAILED,
_("hostdev %s not found"),
dev->data.hostdev->source.caps.u.storage.block);
- goto cleanup;
+ return -1;
}
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
- goto cleanup;
+ return -1;
}
if (lxcDomainAttachDeviceUnlink(vm, def->source.caps.u.storage.block) < 0) {
virDomainAuditHostdev(vm, def, "detach", false);
- goto cleanup;
+ return -1;
}
virDomainAuditHostdev(vm, def, "detach", true);
@@ -4536,10 +4533,7 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm,
virDomainHostdevRemove(vm->def, idx);
virDomainHostdevDefFree(def);
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
@@ -4549,12 +4543,12 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm,
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = NULL;
- int idx, ret = -1;
+ int idx;
if (!priv->initpid) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Cannot attach disk until init PID is known"));
- goto cleanup;
+ return -1;
}
if ((idx = virDomainHostdevFind(vm->def,
@@ -4563,18 +4557,18 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm,
virReportError(VIR_ERR_OPERATION_FAILED,
_("hostdev %s not found"),
dev->data.hostdev->source.caps.u.misc.chardev);
- goto cleanup;
+ return -1;
}
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
- goto cleanup;
+ return -1;
}
if (lxcDomainAttachDeviceUnlink(vm, def->source.caps.u.misc.chardev) < 0) {
virDomainAuditHostdev(vm, def, "detach", false);
- goto cleanup;
+ return -1;
}
virDomainAuditHostdev(vm, def, "detach", true);
@@ -4586,10 +4580,7 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm,
virDomainHostdevRemove(vm->def, idx);
virDomainHostdevDefFree(def);
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 450053d163..9549b70372 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -281,7 +281,6 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm,
virDomainNetDefPtr net,
const char *brname)
{
- char *ret = NULL;
char *parentVeth;
char *containerVeth = NULL;
virNetDevVPortProfilePtr vport = virDomainNetGetActualVirtPortProfile(net);
@@ -289,45 +288,42 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm,
VIR_DEBUG("calling vethCreate()");
parentVeth = net->ifname;
if (virNetDevVethCreate(&parentVeth, &containerVeth) < 0)
- goto cleanup;
+ return NULL;
VIR_DEBUG("parentVeth: %s, containerVeth: %s", parentVeth, containerVeth);
if (net->ifname == NULL)
net->ifname = parentVeth;
if (virNetDevSetMAC(containerVeth, &net->mac) < 0)
- goto cleanup;
+ return NULL;
if (brname) {
if (vport && vport->virtPortType ==
VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
if (virNetDevOpenvswitchAddPort(brname, parentVeth, &net->mac,
vm->uuid,
vport, virDomainNetGetActualVlan(net)) <
0)
- goto cleanup;
+ return NULL;
} else {
if (virNetDevBridgeAddPort(brname, parentVeth) < 0)
- goto cleanup;
+ return NULL;
}
}
if (virNetDevSetOnline(parentVeth, true) < 0)
- goto cleanup;
+ return NULL;
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_ETHERNET) {
/* Set IP info for the host side, but only if the type is
* 'ethernet'.
*/
if (virNetDevIPInfoAddToDev(parentVeth, &net->hostIP) < 0)
- goto cleanup;
+ return NULL;
}
if (net->filter &&
virDomainConfNWFilterInstantiate(vm->name, vm->uuid, net, false) < 0)
- goto cleanup;
-
- ret = containerVeth;
+ return NULL;
- cleanup:
- return ret;
+ return containerVeth;
}
@@ -1044,7 +1040,6 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
{
int retries = 10;
int got = 0;
- int ret = -1;
char *filter_next = buf;
buf[0] = '\0';
@@ -1064,7 +1059,7 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
if (bytes < 0) {
virReportSystemError(errno, "%s",
_("Failure while reading log output"));
- goto cleanup;
+ return -1;
}
got += bytes;
@@ -1086,13 +1081,11 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Out of space while reading log output: %s"),
buf);
- goto cleanup;
+ return -1;
}
- if (isdead) {
- ret = got;
- goto cleanup;
- }
+ if (isdead)
+ return got;
g_usleep(100*1000);
retries--;
@@ -1102,8 +1095,7 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
_("Timed out while reading log output: %s"),
buf);
- cleanup:
- return ret;
+ return -1;
}
--
2.21.0