mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
lxc: remove unneeded cleanup labels
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
c5d86a9834
commit
64b8d27e9a
@ -37,29 +37,25 @@ VIR_LOG_INIT("lxc.lxc_cgroup");
|
|||||||
static int virLXCCgroupSetupCpuTune(virDomainDefPtr def,
|
static int virLXCCgroupSetupCpuTune(virDomainDefPtr def,
|
||||||
virCgroupPtr cgroup)
|
virCgroupPtr cgroup)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (def->cputune.sharesSpecified) {
|
if (def->cputune.sharesSpecified) {
|
||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0)
|
if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virCgroupGetCpuShares(cgroup, &val) < 0)
|
if (virCgroupGetCpuShares(cgroup, &val) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
def->cputune.shares = val;
|
def->cputune.shares = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->cputune.quota != 0 &&
|
if (def->cputune.quota != 0 &&
|
||||||
virCgroupSetCpuCfsQuota(cgroup, def->cputune.quota) < 0)
|
virCgroupSetCpuCfsQuota(cgroup, def->cputune.quota) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (def->cputune.period != 0 &&
|
if (def->cputune.period != 0 &&
|
||||||
virCgroupSetCpuCfsPeriod(cgroup, def->cputune.period) < 0)
|
virCgroupSetCpuCfsPeriod(cgroup, def->cputune.period) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -159,26 +155,22 @@ static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def,
|
|||||||
static int virLXCCgroupSetupMemTune(virDomainDefPtr def,
|
static int virLXCCgroupSetupMemTune(virDomainDefPtr def,
|
||||||
virCgroupPtr cgroup)
|
virCgroupPtr cgroup)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0)
|
if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virMemoryLimitIsSet(def->mem.hard_limit))
|
if (virMemoryLimitIsSet(def->mem.hard_limit))
|
||||||
if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0)
|
if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virMemoryLimitIsSet(def->mem.soft_limit))
|
if (virMemoryLimitIsSet(def->mem.soft_limit))
|
||||||
if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0)
|
if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virMemoryLimitIsSet(def->mem.swap_hard_limit))
|
if (virMemoryLimitIsSet(def->mem.swap_hard_limit))
|
||||||
if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit) < 0)
|
if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -306,7 +298,6 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
virCgroupPtr cgroup)
|
virCgroupPtr cgroup)
|
||||||
{
|
{
|
||||||
int capMknod = def->caps_features[VIR_DOMAIN_PROCES_CAPS_FEATURE_MKNOD];
|
int capMknod = def->caps_features[VIR_DOMAIN_PROCES_CAPS_FEATURE_MKNOD];
|
||||||
int ret = -1;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
static virLXCCgroupDevicePolicy devices[] = {
|
static virLXCCgroupDevicePolicy devices[] = {
|
||||||
{'c', LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_NULL},
|
{'c', LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_NULL},
|
||||||
@ -320,13 +311,13 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
{0, 0, 0}};
|
{0, 0, 0}};
|
||||||
|
|
||||||
if (virCgroupDenyAllDevices(cgroup) < 0)
|
if (virCgroupDenyAllDevices(cgroup) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* white list mknod if CAP_MKNOD has to be kept */
|
/* white list mknod if CAP_MKNOD has to be kept */
|
||||||
if (capMknod == VIR_TRISTATE_SWITCH_ON) {
|
if (capMknod == VIR_TRISTATE_SWITCH_ON) {
|
||||||
if (virCgroupAllowAllDevices(cgroup,
|
if (virCgroupAllowAllDevices(cgroup,
|
||||||
VIR_CGROUP_DEVICE_MKNOD) < 0)
|
VIR_CGROUP_DEVICE_MKNOD) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; devices[i].type != 0; i++) {
|
for (i = 0; devices[i].type != 0; i++) {
|
||||||
@ -336,7 +327,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
dev->major,
|
dev->major,
|
||||||
dev->minor,
|
dev->minor,
|
||||||
VIR_CGROUP_DEVICE_RWM) < 0)
|
VIR_CGROUP_DEVICE_RWM) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Allowing any disk block devs");
|
VIR_DEBUG("Allowing any disk block devs");
|
||||||
@ -351,7 +342,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
VIR_CGROUP_DEVICE_READ :
|
VIR_CGROUP_DEVICE_READ :
|
||||||
VIR_CGROUP_DEVICE_RW) |
|
VIR_CGROUP_DEVICE_RW) |
|
||||||
VIR_CGROUP_DEVICE_MKNOD, false) < 0)
|
VIR_CGROUP_DEVICE_MKNOD, false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Allowing any filesystem block devs");
|
VIR_DEBUG("Allowing any filesystem block devs");
|
||||||
@ -364,7 +355,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
def->fss[i]->readonly ?
|
def->fss[i]->readonly ?
|
||||||
VIR_CGROUP_DEVICE_READ :
|
VIR_CGROUP_DEVICE_READ :
|
||||||
VIR_CGROUP_DEVICE_RW, false) < 0)
|
VIR_CGROUP_DEVICE_RW, false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Allowing any hostdev block devs");
|
VIR_DEBUG("Allowing any hostdev block devs");
|
||||||
@ -382,12 +373,12 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
|
|
||||||
if ((usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device,
|
if ((usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device,
|
||||||
NULL)) == NULL)
|
NULL)) == NULL)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virUSBDeviceFileIterate(usb, virLXCSetupHostUSBDeviceCgroup,
|
if (virUSBDeviceFileIterate(usb, virLXCSetupHostUSBDeviceCgroup,
|
||||||
cgroup) < 0) {
|
cgroup) < 0) {
|
||||||
virUSBDeviceFree(usb);
|
virUSBDeviceFree(usb);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
virUSBDeviceFree(usb);
|
virUSBDeviceFree(usb);
|
||||||
break;
|
break;
|
||||||
@ -398,14 +389,14 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
hostdev->source.caps.u.storage.block,
|
hostdev->source.caps.u.storage.block,
|
||||||
VIR_CGROUP_DEVICE_RW |
|
VIR_CGROUP_DEVICE_RW |
|
||||||
VIR_CGROUP_DEVICE_MKNOD, false) < 0)
|
VIR_CGROUP_DEVICE_MKNOD, false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
|
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
|
||||||
if (virCgroupAllowDevicePath(cgroup,
|
if (virCgroupAllowDevicePath(cgroup,
|
||||||
hostdev->source.caps.u.misc.chardev,
|
hostdev->source.caps.u.misc.chardev,
|
||||||
VIR_CGROUP_DEVICE_RW |
|
VIR_CGROUP_DEVICE_RW |
|
||||||
VIR_CGROUP_DEVICE_MKNOD, false) < 0)
|
VIR_CGROUP_DEVICE_MKNOD, false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -417,13 +408,11 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
|
|
||||||
if (virCgroupAllowDevice(cgroup, 'c', LXC_DEV_MAJ_PTY, -1,
|
if (virCgroupAllowDevice(cgroup, 'c', LXC_DEV_MAJ_PTY, -1,
|
||||||
VIR_CGROUP_DEVICE_RWM) < 0)
|
VIR_CGROUP_DEVICE_RWM) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
VIR_DEBUG("Device whitelist complete");
|
VIR_DEBUG("Device whitelist complete");
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -481,25 +470,20 @@ int virLXCCgroupSetup(virDomainDefPtr def,
|
|||||||
virCgroupPtr cgroup,
|
virCgroupPtr cgroup,
|
||||||
virBitmapPtr nodemask)
|
virBitmapPtr nodemask)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (virLXCCgroupSetupCpuTune(def, cgroup) < 0)
|
if (virLXCCgroupSetupCpuTune(def, cgroup) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virLXCCgroupSetupCpusetTune(def, cgroup, nodemask) < 0)
|
if (virLXCCgroupSetupCpusetTune(def, cgroup, nodemask) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virLXCCgroupSetupBlkioTune(def, cgroup) < 0)
|
if (virLXCCgroupSetupBlkioTune(def, cgroup) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virLXCCgroupSetupMemTune(def, cgroup) < 0)
|
if (virLXCCgroupSetupMemTune(def, cgroup) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virLXCCgroupSetupDeviceACL(def, cgroup) < 0)
|
if (virLXCCgroupSetupDeviceACL(def, cgroup) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,6 @@ lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
|
|||||||
size_t nveths,
|
size_t nveths,
|
||||||
char **veths)
|
char **veths)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
const char *newname;
|
const char *newname;
|
||||||
virDomainNetDefPtr netDef;
|
virDomainNetDefPtr netDef;
|
||||||
@ -494,18 +493,18 @@ lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
|
|||||||
|
|
||||||
for (i = 0; i < nveths; i++) {
|
for (i = 0; i < nveths; i++) {
|
||||||
if (!(netDef = lxcContainerGetNetDef(vmDef, veths[i])))
|
if (!(netDef = lxcContainerGetNetDef(vmDef, veths[i])))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
newname = netDef->ifname_guest;
|
newname = netDef->ifname_guest;
|
||||||
if (!newname) {
|
if (!newname) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing device name for container-side veth"));
|
_("Missing device name for container-side veth"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Renaming %s to %s", veths[i], newname);
|
VIR_DEBUG("Renaming %s to %s", veths[i], newname);
|
||||||
if (virNetDevSetName(veths[i], newname) < 0)
|
if (virNetDevSetName(veths[i], newname) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* Only enable this device if there is a reason to do so (either
|
/* 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
|
* 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) {
|
netDef->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP) {
|
||||||
VIR_DEBUG("Enabling %s", newname);
|
VIR_DEBUG("Enabling %s", newname);
|
||||||
if (virNetDevSetOnline(newname, true) < 0)
|
if (virNetDevSetOnline(newname, true) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set IP addresses and routes */
|
/* set IP addresses and routes */
|
||||||
if (virNetDevIPInfoAddToDev(newname, &netDef->guestIP) < 0)
|
if (virNetDevIPInfoAddToDev(newname, &netDef->guestIP) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enable lo device only if there were other net devices */
|
/* enable lo device only if there were other net devices */
|
||||||
if ((veths || privNet) &&
|
if ((veths || privNet) &&
|
||||||
virNetDevSetOnline("lo", true) < 0)
|
virNetDevSetOnline("lo", true) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -358,7 +358,6 @@ static int virLXCControllerValidateNICs(virLXCControllerPtr ctrl)
|
|||||||
static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
|
static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
/* Gather the ifindexes of the "parent" veths for all interfaces
|
/* Gather the ifindexes of the "parent" veths for all interfaces
|
||||||
* implemented with a veth pair. These will be used when calling
|
* implemented with a veth pair. These will be used when calling
|
||||||
@ -383,11 +382,11 @@ static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
|
|||||||
continue;
|
continue;
|
||||||
if (virNetDevGetIndex(ctrl->def->nets[i]->ifname,
|
if (virNetDevGetIndex(ctrl->def->nets[i]->ifname,
|
||||||
&nicindex) < 0)
|
&nicindex) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
if (VIR_EXPAND_N(ctrl->nicindexes,
|
if (VIR_EXPAND_N(ctrl->nicindexes,
|
||||||
ctrl->nnicindexes,
|
ctrl->nnicindexes,
|
||||||
1) < 0)
|
1) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
VIR_DEBUG("Index %d for %s", nicindex,
|
VIR_DEBUG("Index %d for %s", nicindex,
|
||||||
ctrl->def->nets[i]->ifname);
|
ctrl->def->nets[i]->ifname);
|
||||||
ctrl->nicindexes[ctrl->nnicindexes-1] = nicindex;
|
ctrl->nicindexes[ctrl->nnicindexes-1] = nicindex;
|
||||||
@ -407,17 +406,15 @@ static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
|
|||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("Unsupported net type %s"),
|
_("Unsupported net type %s"),
|
||||||
virDomainNetTypeToString(actualType));
|
virDomainNetTypeToString(actualType));
|
||||||
goto cleanup;
|
return -1;
|
||||||
case VIR_DOMAIN_NET_TYPE_LAST:
|
case VIR_DOMAIN_NET_TYPE_LAST:
|
||||||
default:
|
default:
|
||||||
virReportEnumRangeError(virDomainNetType, actualType);
|
virReportEnumRangeError(virDomainNetType, actualType);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -606,7 +603,6 @@ static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl,
|
|||||||
static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
|
static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
VIR_DEBUG("Setting up loop devices for filesystems");
|
VIR_DEBUG("Setting up loop devices for filesystems");
|
||||||
|
|
||||||
@ -631,33 +627,33 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
|
|||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("fs format %s is not supported"),
|
_("fs format %s is not supported"),
|
||||||
virStorageFileFormatTypeToString(fs->format));
|
virStorageFileFormatTypeToString(fs->format));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = virLXCControllerSetupLoopDeviceFS(fs);
|
fd = virLXCControllerSetupLoopDeviceFS(fs);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
VIR_DEBUG("Saving loop fd %d", fd);
|
VIR_DEBUG("Saving loop fd %d", fd);
|
||||||
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
|
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
|
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
|
||||||
} else if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_NBD) {
|
} else if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_NBD) {
|
||||||
if (virLXCControllerSetupNBDDeviceFS(fs) < 0)
|
if (virLXCControllerSetupNBDDeviceFS(fs) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* The NBD device will be cleaned up while the cgroup will end.
|
/* 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
|
* For this we need to remember the qemu-nbd pid and add it to
|
||||||
* the cgroup*/
|
* the cgroup*/
|
||||||
if (virLXCControllerAppendNBDPids(ctrl, fs->src->path) < 0)
|
if (virLXCControllerAppendNBDPids(ctrl, fs->src->path) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("fs driver %s is not supported"),
|
_("fs driver %s is not supported"),
|
||||||
virDomainFSDriverTypeToString(fs->fsdriver));
|
virDomainFSDriverTypeToString(fs->fsdriver));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,7 +681,7 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
|
|||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("disk format %s is not supported"),
|
_("disk format %s is not supported"),
|
||||||
virStorageFileFormatTypeToString(format));
|
virStorageFileFormatTypeToString(format));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We treat 'none' as meaning 'raw' since we
|
/* We treat 'none' as meaning 'raw' since we
|
||||||
@ -694,12 +690,12 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
|
|||||||
*/
|
*/
|
||||||
fd = virLXCControllerSetupLoopDeviceDisk(disk);
|
fd = virLXCControllerSetupLoopDeviceDisk(disk);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
VIR_DEBUG("Saving loop fd %d", fd);
|
VIR_DEBUG("Saving loop fd %d", fd);
|
||||||
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
|
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
|
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
|
||||||
} else if (!driver || STREQ(driver, "nbd")) {
|
} else if (!driver || STREQ(driver, "nbd")) {
|
||||||
@ -708,29 +704,27 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
|
|||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("Disk cache mode %s is not supported"),
|
_("Disk cache mode %s is not supported"),
|
||||||
virDomainDiskCacheTypeToString(disk->cachemode));
|
virDomainDiskCacheTypeToString(disk->cachemode));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
if (virLXCControllerSetupNBDDeviceDisk(disk) < 0)
|
if (virLXCControllerSetupNBDDeviceDisk(disk) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* The NBD device will be cleaned up while the cgroup will end.
|
/* 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
|
* For this we need to remember the qemu-nbd pid and add it to
|
||||||
* the cgroup*/
|
* the cgroup*/
|
||||||
if (virLXCControllerAppendNBDPids(ctrl, virDomainDiskGetSource(disk)) < 0)
|
if (virLXCControllerAppendNBDPids(ctrl, virDomainDiskGetSource(disk)) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("disk driver %s is not supported"),
|
_("disk driver %s is not supported"),
|
||||||
driver);
|
driver);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Setup all loop devices");
|
VIR_DEBUG("Setup all loop devices");
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
return 0;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3428,7 +3428,7 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
case VIR_DOMAIN_DEVICE_NET:
|
case VIR_DOMAIN_DEVICE_NET:
|
||||||
net = dev->data.net;
|
net = dev->data.net;
|
||||||
if (virDomainNetInsert(vmdef, net) < 0)
|
if (virDomainNetInsert(vmdef, net) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
dev->data.net = NULL;
|
dev->data.net = NULL;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
@ -3452,7 +3452,6 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3470,7 +3469,7 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
case VIR_DOMAIN_DEVICE_NET:
|
case VIR_DOMAIN_DEVICE_NET:
|
||||||
net = dev->data.net;
|
net = dev->data.net;
|
||||||
if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
|
if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
oldDev.data.net = vmdef->nets[idx];
|
oldDev.data.net = vmdef->nets[idx];
|
||||||
if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev,
|
if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev,
|
||||||
@ -3493,7 +3492,6 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3523,7 +3521,7 @@ lxcDomainDetachDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
case VIR_DOMAIN_DEVICE_NET:
|
case VIR_DOMAIN_DEVICE_NET:
|
||||||
net = dev->data.net;
|
net = dev->data.net;
|
||||||
if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
|
if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* this is guaranteed to succeed */
|
/* this is guaranteed to succeed */
|
||||||
virDomainNetDefFree(virDomainNetRemove(vmdef, idx));
|
virDomainNetDefFree(virDomainNetRemove(vmdef, idx));
|
||||||
@ -3549,7 +3547,6 @@ lxcDomainDetachDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4480,12 +4477,12 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm,
|
|||||||
{
|
{
|
||||||
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virDomainHostdevDefPtr def = NULL;
|
virDomainHostdevDefPtr def = NULL;
|
||||||
int idx, ret = -1;
|
int idx;
|
||||||
|
|
||||||
if (!priv->initpid) {
|
if (!priv->initpid) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("Cannot attach disk until init PID is known"));
|
_("Cannot attach disk until init PID is known"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((idx = virDomainHostdevFind(vm->def,
|
if ((idx = virDomainHostdevFind(vm->def,
|
||||||
@ -4494,18 +4491,18 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm,
|
|||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("hostdev %s not found"),
|
_("hostdev %s not found"),
|
||||||
dev->data.hostdev->source.caps.u.storage.block);
|
dev->data.hostdev->source.caps.u.storage.block);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
|
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("devices cgroup isn't mounted"));
|
_("devices cgroup isn't mounted"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lxcDomainAttachDeviceUnlink(vm, def->source.caps.u.storage.block) < 0) {
|
if (lxcDomainAttachDeviceUnlink(vm, def->source.caps.u.storage.block) < 0) {
|
||||||
virDomainAuditHostdev(vm, def, "detach", false);
|
virDomainAuditHostdev(vm, def, "detach", false);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
virDomainAuditHostdev(vm, def, "detach", true);
|
virDomainAuditHostdev(vm, def, "detach", true);
|
||||||
|
|
||||||
@ -4517,10 +4514,7 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm,
|
|||||||
virDomainHostdevRemove(vm->def, idx);
|
virDomainHostdevRemove(vm->def, idx);
|
||||||
virDomainHostdevDefFree(def);
|
virDomainHostdevDefFree(def);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -4530,12 +4524,12 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm,
|
|||||||
{
|
{
|
||||||
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virDomainHostdevDefPtr def = NULL;
|
virDomainHostdevDefPtr def = NULL;
|
||||||
int idx, ret = -1;
|
int idx;
|
||||||
|
|
||||||
if (!priv->initpid) {
|
if (!priv->initpid) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("Cannot attach disk until init PID is known"));
|
_("Cannot attach disk until init PID is known"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((idx = virDomainHostdevFind(vm->def,
|
if ((idx = virDomainHostdevFind(vm->def,
|
||||||
@ -4544,18 +4538,18 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm,
|
|||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("hostdev %s not found"),
|
_("hostdev %s not found"),
|
||||||
dev->data.hostdev->source.caps.u.misc.chardev);
|
dev->data.hostdev->source.caps.u.misc.chardev);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
|
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("devices cgroup isn't mounted"));
|
_("devices cgroup isn't mounted"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lxcDomainAttachDeviceUnlink(vm, def->source.caps.u.misc.chardev) < 0) {
|
if (lxcDomainAttachDeviceUnlink(vm, def->source.caps.u.misc.chardev) < 0) {
|
||||||
virDomainAuditHostdev(vm, def, "detach", false);
|
virDomainAuditHostdev(vm, def, "detach", false);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
virDomainAuditHostdev(vm, def, "detach", true);
|
virDomainAuditHostdev(vm, def, "detach", true);
|
||||||
|
|
||||||
@ -4567,10 +4561,7 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm,
|
|||||||
virDomainHostdevRemove(vm->def, idx);
|
virDomainHostdevRemove(vm->def, idx);
|
||||||
virDomainHostdevDefFree(def);
|
virDomainHostdevDefFree(def);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -280,7 +280,6 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm,
|
|||||||
virDomainNetDefPtr net,
|
virDomainNetDefPtr net,
|
||||||
const char *brname)
|
const char *brname)
|
||||||
{
|
{
|
||||||
char *ret = NULL;
|
|
||||||
char *parentVeth;
|
char *parentVeth;
|
||||||
char *containerVeth = NULL;
|
char *containerVeth = NULL;
|
||||||
virNetDevVPortProfilePtr vport = virDomainNetGetActualVirtPortProfile(net);
|
virNetDevVPortProfilePtr vport = virDomainNetGetActualVirtPortProfile(net);
|
||||||
@ -288,45 +287,42 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm,
|
|||||||
VIR_DEBUG("calling vethCreate()");
|
VIR_DEBUG("calling vethCreate()");
|
||||||
parentVeth = net->ifname;
|
parentVeth = net->ifname;
|
||||||
if (virNetDevVethCreate(&parentVeth, &containerVeth) < 0)
|
if (virNetDevVethCreate(&parentVeth, &containerVeth) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
VIR_DEBUG("parentVeth: %s, containerVeth: %s", parentVeth, containerVeth);
|
VIR_DEBUG("parentVeth: %s, containerVeth: %s", parentVeth, containerVeth);
|
||||||
|
|
||||||
if (net->ifname == NULL)
|
if (net->ifname == NULL)
|
||||||
net->ifname = parentVeth;
|
net->ifname = parentVeth;
|
||||||
|
|
||||||
if (virNetDevSetMAC(containerVeth, &net->mac) < 0)
|
if (virNetDevSetMAC(containerVeth, &net->mac) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
if (brname) {
|
if (brname) {
|
||||||
if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
|
if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
|
||||||
if (virNetDevOpenvswitchAddPort(brname, parentVeth, &net->mac, vm->uuid,
|
if (virNetDevOpenvswitchAddPort(brname, parentVeth, &net->mac, vm->uuid,
|
||||||
vport, virDomainNetGetActualVlan(net)) < 0)
|
vport, virDomainNetGetActualVlan(net)) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
if (virNetDevBridgeAddPort(brname, parentVeth) < 0)
|
if (virNetDevBridgeAddPort(brname, parentVeth) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virNetDevSetOnline(parentVeth, true) < 0)
|
if (virNetDevSetOnline(parentVeth, true) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_ETHERNET) {
|
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_ETHERNET) {
|
||||||
/* Set IP info for the host side, but only if the type is
|
/* Set IP info for the host side, but only if the type is
|
||||||
* 'ethernet'.
|
* 'ethernet'.
|
||||||
*/
|
*/
|
||||||
if (virNetDevIPInfoAddToDev(parentVeth, &net->hostIP) < 0)
|
if (virNetDevIPInfoAddToDev(parentVeth, &net->hostIP) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net->filter &&
|
if (net->filter &&
|
||||||
virDomainConfNWFilterInstantiate(vm->name, vm->uuid, net, false) < 0)
|
virDomainConfNWFilterInstantiate(vm->name, vm->uuid, net, false) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
ret = containerVeth;
|
return containerVeth;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1032,7 +1028,6 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
|
|||||||
{
|
{
|
||||||
int retries = 10;
|
int retries = 10;
|
||||||
int got = 0;
|
int got = 0;
|
||||||
int ret = -1;
|
|
||||||
char *filter_next = buf;
|
char *filter_next = buf;
|
||||||
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
@ -1052,7 +1047,7 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
|
|||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Failure while reading log output"));
|
_("Failure while reading log output"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
got += bytes;
|
got += bytes;
|
||||||
@ -1074,13 +1069,11 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Out of space while reading log output: %s"),
|
_("Out of space while reading log output: %s"),
|
||||||
buf);
|
buf);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isdead) {
|
if (isdead)
|
||||||
ret = got;
|
return got;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_usleep(100*1000);
|
g_usleep(100*1000);
|
||||||
retries--;
|
retries--;
|
||||||
@ -1090,8 +1083,7 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
|
|||||||
_("Timed out while reading log output: %s"),
|
_("Timed out while reading log output: %s"),
|
||||||
buf);
|
buf);
|
||||||
|
|
||||||
cleanup:
|
return -1;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user