提交 64b8d27e 编写于 作者: D Daniel Henrique Barboza 提交者: Ján Tomko

lxc: remove unneeded cleanup labels

Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 c5d86a98
......@@ -37,29 +37,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;
}
......@@ -159,26 +155,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;
}
......@@ -306,7 +298,6 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
virCgroupPtr cgroup)
{
int capMknod = def->caps_features[VIR_DOMAIN_PROCES_CAPS_FEATURE_MKNOD];
int ret = -1;
size_t i;
static virLXCCgroupDevicePolicy devices[] = {
{'c', LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_NULL},
......@@ -320,13 +311,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++) {
......@@ -336,7 +327,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");
......@@ -351,7 +342,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");
......@@ -364,7 +355,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");
......@@ -382,12 +373,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;
......@@ -398,14 +389,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;
......@@ -417,13 +408,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;
}
......@@ -481,25 +470,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;
}
......@@ -485,7 +485,6 @@ lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
size_t nveths,
char **veths)
{
int ret = -1;
size_t i;
const char *newname;
virDomainNetDefPtr netDef;
......@@ -494,18 +493,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
......@@ -515,22 +514,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;
}
......
......@@ -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;
}
......@@ -606,7 +603,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");
......@@ -631,33 +627,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;
}
}
......@@ -685,7 +681,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
......@@ -694,12 +690,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")) {
......@@ -708,29 +704,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;
}
......
......@@ -3428,7 +3428,7 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
case VIR_DOMAIN_DEVICE_NET:
net = dev->data.net;
if (virDomainNetInsert(vmdef, net) < 0)
goto cleanup;
return -1;
dev->data.net = NULL;
ret = 0;
break;
......@@ -3452,7 +3452,6 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
break;
}
cleanup:
return ret;
}
......@@ -3470,7 +3469,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,
......@@ -3493,7 +3492,6 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
break;
}
cleanup:
return ret;
}
......@@ -3523,7 +3521,7 @@ lxcDomainDetachDeviceConfig(virDomainDefPtr vmdef,
case VIR_DOMAIN_DEVICE_NET:
net = dev->data.net;
if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
goto cleanup;
return -1;
/* this is guaranteed to succeed */
virDomainNetDefFree(virDomainNetRemove(vmdef, idx));
......@@ -3549,7 +3547,6 @@ lxcDomainDetachDeviceConfig(virDomainDefPtr vmdef,
break;
}
cleanup:
return ret;
}
......@@ -4480,12 +4477,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,
......@@ -4494,18 +4491,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);
......@@ -4517,10 +4514,7 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm,
virDomainHostdevRemove(vm->def, idx);
virDomainHostdevDefFree(def);
ret = 0;
cleanup:
return ret;
return 0;
}
......@@ -4530,12 +4524,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,
......@@ -4544,18 +4538,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);
......@@ -4567,10 +4561,7 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm,
virDomainHostdevRemove(vm->def, idx);
virDomainHostdevDefFree(def);
ret = 0;
cleanup:
return ret;
return 0;
}
......
......@@ -280,7 +280,6 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm,
virDomainNetDefPtr net,
const char *brname)
{
char *ret = NULL;
char *parentVeth;
char *containerVeth = NULL;
virNetDevVPortProfilePtr vport = virDomainNetGetActualVirtPortProfile(net);
......@@ -288,45 +287,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;
}
......@@ -1032,7 +1028,6 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
{
int retries = 10;
int got = 0;
int ret = -1;
char *filter_next = buf;
buf[0] = '\0';
......@@ -1052,7 +1047,7 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
if (bytes < 0) {
virReportSystemError(errno, "%s",
_("Failure while reading log output"));
goto cleanup;
return -1;
}
got += bytes;
......@@ -1074,13 +1069,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--;
......@@ -1090,8 +1083,7 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
_("Timed out while reading log output: %s"),
buf);
cleanup:
return ret;
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册