{
virLXCDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
- virCgroupPtr cgroup = NULL;
int ret = -1, rc;
+ virLXCDomainObjPrivatePtr priv;
lxcDriverLock(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
goto cleanup;
}
+ priv = vm->privateData;
+
info->state = virDomainObjGetState(vm, NULL);
- if (!virDomainObjIsActive(vm) || driver->cgroup == NULL) {
+ if (!virDomainObjIsActive(vm)) {
info->cpuTime = 0;
info->memory = vm->def->mem.cur_balloon;
} else {
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to get cgroup for %s"), vm->def->name);
- goto cleanup;
- }
-
- if (virCgroupGetCpuacctUsage(cgroup, &(info->cpuTime)) < 0) {
+ if (virCgroupGetCpuacctUsage(priv->cgroup, &(info->cpuTime)) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("Cannot read cputime for domain"));
goto cleanup;
}
- if ((rc = virCgroupGetMemoryUsage(cgroup, &(info->memory))) < 0) {
+ if ((rc = virCgroupGetMemoryUsage(priv->cgroup, &(info->memory))) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("Cannot read memory usage for domain"));
if (rc == -ENOENT) {
cleanup:
lxcDriverUnlock(driver);
- if (cgroup)
- virCgroupFree(&cgroup);
if (vm)
virObjectUnlock(vm);
return ret;
static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
virLXCDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
- virCgroupPtr cgroup = NULL;
int ret = -1;
+ virLXCDomainObjPrivatePtr priv;
lxcDriverLock(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup;
}
+ priv = vm->privateData;
if (newmem > vm->def->mem.max_balloon) {
virReportError(VIR_ERR_INVALID_ARG,
goto cleanup;
}
- if (driver->cgroup == NULL) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("cgroups must be configured on the host"));
- goto cleanup;
- }
-
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to get cgroup for %s"), vm->def->name);
- goto cleanup;
- }
-
- if (virCgroupSetMemory(cgroup, newmem) < 0) {
+ if (virCgroupSetMemory(priv->cgroup, newmem) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("Failed to set memory for domain"));
goto cleanup;
cleanup:
if (vm)
virObjectUnlock(vm);
- if (cgroup)
- virCgroupFree(&cgroup);
return ret;
}
{
virLXCDriverPtr driver = dom->conn->privateData;
int i;
- virCgroupPtr cgroup = NULL;
virDomainObjPtr vm = NULL;
int ret = -1;
int rc;
+ virLXCDomainObjPrivatePtr priv;
virCheckFlags(0, -1);
if (virTypedParameterArrayValidate(params, nparams,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup;
}
-
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
+ priv = vm->privateData;
ret = 0;
for (i = 0; i < nparams; i++) {
virTypedParameterPtr param = ¶ms[i];
if (STREQ(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT)) {
- rc = virCgroupSetMemoryHardLimit(cgroup, params[i].value.ul);
+ rc = virCgroupSetMemoryHardLimit(priv->cgroup, params[i].value.ul);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to set memory hard_limit tunable"));
ret = -1;
}
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT)) {
- rc = virCgroupSetMemorySoftLimit(cgroup, params[i].value.ul);
+ rc = virCgroupSetMemorySoftLimit(priv->cgroup, params[i].value.ul);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to set memory soft_limit tunable"));
ret = -1;
}
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT)) {
- rc = virCgroupSetMemSwapHardLimit(cgroup, params[i].value.ul);
+ rc = virCgroupSetMemSwapHardLimit(priv->cgroup, params[i].value.ul);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to set swap_hard_limit tunable"));
}
cleanup:
- if (cgroup)
- virCgroupFree(&cgroup);
if (vm)
virObjectUnlock(vm);
lxcDriverUnlock(driver);
{
virLXCDriverPtr driver = dom->conn->privateData;
int i;
- virCgroupPtr cgroup = NULL;
virDomainObjPtr vm = NULL;
unsigned long long val;
int ret = -1;
int rc;
+ virLXCDomainObjPrivatePtr priv;
virCheckFlags(0, -1);
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup;
}
+ priv = vm->privateData;
if ((*nparams) == 0) {
/* Current number of memory parameters supported by cgroups */
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to get cgroup for %s"), vm->def->name);
- goto cleanup;
- }
-
for (i = 0; i < LXC_NB_MEM_PARAM && i < *nparams; i++) {
virTypedParameterPtr param = ¶ms[i];
val = 0;
switch (i) {
case 0: /* fill memory hard limit here */
- rc = virCgroupGetMemoryHardLimit(cgroup, &val);
+ rc = virCgroupGetMemoryHardLimit(priv->cgroup, &val);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to get memory hard limit"));
goto cleanup;
break;
case 1: /* fill memory soft limit here */
- rc = virCgroupGetMemorySoftLimit(cgroup, &val);
+ rc = virCgroupGetMemorySoftLimit(priv->cgroup, &val);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to get memory soft limit"));
goto cleanup;
break;
case 2: /* fill swap hard limit here */
- rc = virCgroupGetMemSwapHardLimit(cgroup, &val);
+ rc = virCgroupGetMemSwapHardLimit(priv->cgroup, &val);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to get swap hard limit"));
ret = 0;
cleanup:
- if (cgroup)
- virCgroupFree(&cgroup);
if (vm)
virObjectUnlock(vm);
lxcDriverUnlock(driver);
void *opaque ATTRIBUTE_UNUSED)
{
char *ld;
- int rc;
/* Valgrind gets very annoyed when we clone containers, so
* disable LXC when under valgrind
lxc_driver->log_libvirtd = 0; /* by default log to container logfile */
lxc_driver->have_netns = lxcCheckNetNsSupport();
- rc = virCgroupForDriver("lxc", &lxc_driver->cgroup, privileged, 1, -1);
- if (rc < 0) {
- char buf[1024] ATTRIBUTE_UNUSED;
- VIR_DEBUG("Unable to create cgroup for LXC driver: %s",
- virStrerror(-rc, buf, sizeof(buf)));
- /* Don't abort startup. We will explicitly report to
- * the user when they try to start a VM
- */
- }
-
/* Call function to load lxc driver configuration information */
if (lxcLoadDriverConfig(lxc_driver) < 0)
goto cleanup;
}
-static bool lxcCgroupControllerActive(virLXCDriverPtr driver,
- int controller)
-{
- return virCgroupHasController(driver->cgroup, controller);
-}
-
-
-
-static char *lxcGetSchedulerType(virDomainPtr domain,
+static char *lxcGetSchedulerType(virDomainPtr dom,
int *nparams)
{
- virLXCDriverPtr driver = domain->conn->privateData;
+ virLXCDriverPtr driver = dom->conn->privateData;
char *ret = NULL;
int rc;
+ virDomainObjPtr vm;
+ virLXCDomainObjPrivatePtr priv;
lxcDriverLock(driver);
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
+ vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
+ if (vm == NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("No such domain %s"), dom->uuid);
+ goto cleanup;
+ }
+ priv = vm->privateData;
+
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cgroup CPU controller is not mounted"));
goto cleanup;
}
if (nparams) {
- rc = lxcGetCpuBWStatus(driver->cgroup);
+ rc = lxcGetCpuBWStatus(priv->cgroup);
if (rc < 0)
goto cleanup;
else if (rc == 0)
virReportOOMError();
cleanup:
+ if (vm)
+ virObjectUnlock(vm);
lxcDriverUnlock(driver);
return ret;
}
{
virLXCDriverPtr driver = dom->conn->privateData;
int i;
- virCgroupPtr group = NULL;
virDomainObjPtr vm = NULL;
virDomainDefPtr vmdef = NULL;
int ret = -1;
int rc;
+ virLXCDomainObjPrivatePtr priv;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
_("No such domain %s"), dom->uuid);
goto cleanup;
}
+ priv = vm->privateData;
if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlopt,
vm, &flags, &vmdef) < 0)
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cgroup CPU controller is not mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"),
- vm->def->name);
- goto cleanup;
- }
}
for (i = 0; i < nparams; i++) {
if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- rc = virCgroupSetCpuShares(group, params[i].value.ul);
+ rc = virCgroupSetCpuShares(priv->cgroup, params[i].value.ul);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to set cpu shares tunable"));
}
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- rc = lxcSetVcpuBWLive(group, params[i].value.ul, 0);
+ rc = lxcSetVcpuBWLive(priv->cgroup, params[i].value.ul, 0);
if (rc != 0)
goto cleanup;
}
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- rc = lxcSetVcpuBWLive(group, 0, params[i].value.l);
+ rc = lxcSetVcpuBWLive(priv->cgroup, 0, params[i].value.l);
if (rc != 0)
goto cleanup;
cleanup:
virDomainDefFree(vmdef);
- virCgroupFree(&group);
if (vm)
virObjectUnlock(vm);
lxcDriverUnlock(driver);
unsigned int flags)
{
virLXCDriverPtr driver = dom->conn->privateData;
- virCgroupPtr group = NULL;
virDomainObjPtr vm = NULL;
virDomainDefPtr persistentDef;
unsigned long long shares = 0;
int rc;
bool cpu_bw_status = false;
int saved_nparams = 0;
+ virLXCDomainObjPrivatePtr priv;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
lxcDriverLock(driver);
- if (*nparams > 1) {
- rc = lxcGetCpuBWStatus(driver->cgroup);
- if (rc < 0)
- goto cleanup;
- cpu_bw_status = !!rc;
- }
-
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
if (vm == NULL) {
_("No such domain %s"), dom->uuid);
goto cleanup;
}
+ priv = vm->privateData;
+
+ if (*nparams > 1) {
+ rc = lxcGetCpuBWStatus(priv->cgroup);
+ if (rc < 0)
+ goto cleanup;
+ cpu_bw_status = !!rc;
+ }
if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlopt,
vm, &flags, &persistentDef) < 0)
goto out;
}
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cgroup CPU controller is not mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
- rc = virCgroupGetCpuShares(group, &shares);
+ rc = virCgroupGetCpuShares(priv->cgroup, &shares);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to get cpu shares tunable"));
}
if (*nparams > 1 && cpu_bw_status) {
- rc = lxcGetVcpuBWLive(group, &period, "a);
+ rc = lxcGetVcpuBWLive(priv->cgroup, &period, "a);
if (rc != 0)
goto cleanup;
}
ret = 0;
cleanup:
- virCgroupFree(&group);
if (vm)
virObjectUnlock(vm);
lxcDriverUnlock(driver);
{
virLXCDriverPtr driver = dom->conn->privateData;
int i;
- virCgroupPtr group = NULL;
virDomainObjPtr vm = NULL;
virDomainDefPtr persistentDef = NULL;
int ret = -1;
+ virLXCDomainObjPrivatePtr priv;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
_("No such domain %s"), dom->uuid);
goto cleanup;
}
+ priv = vm->privateData;
if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlopt,
vm, &flags, &persistentDef) < 0)
goto cleanup;
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("blkio cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
for (i = 0; i < nparams; i++) {
virTypedParameterPtr param = ¶ms[i];
goto cleanup;
}
- rc = virCgroupSetBlkioWeight(group, params[i].value.ui);
+ rc = virCgroupSetBlkioWeight(priv->cgroup, params[i].value.ui);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to set blkio weight tunable"));
ret = 0;
cleanup:
- virCgroupFree(&group);
if (vm)
virObjectUnlock(vm);
lxcDriverUnlock(driver);
{
virLXCDriverPtr driver = dom->conn->privateData;
int i;
- virCgroupPtr group = NULL;
virDomainObjPtr vm = NULL;
virDomainDefPtr persistentDef = NULL;
unsigned int val;
int ret = -1;
int rc;
+ virLXCDomainObjPrivatePtr priv;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
_("No such domain %s"), dom->uuid);
goto cleanup;
}
+ priv = vm->privateData;
if ((*nparams) == 0) {
/* Current number of blkio parameters supported by cgroups */
goto cleanup;
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("blkio cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
for (i = 0; i < *nparams && i < LXC_NB_BLKIO_PARAM; i++) {
virTypedParameterPtr param = ¶ms[i];
val = 0;
switch (i) {
case 0: /* fill blkio weight here */
- rc = virCgroupGetBlkioWeight(group, &val);
+ rc = virCgroupGetBlkioWeight(priv->cgroup, &val);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to get blkio weight"));
ret = 0;
cleanup:
- if (group)
- virCgroupFree(&group);
if (vm)
virObjectUnlock(vm);
lxcDriverUnlock(driver);
return ret;
}
-static int lxcFreezeContainer(virLXCDriverPtr driver, virDomainObjPtr vm)
+static int lxcFreezeContainer(virDomainObjPtr vm)
{
int timeout = 1000; /* In milliseconds */
int check_interval = 1; /* In milliseconds */
int waited_time = 0;
int ret = -1;
char *state = NULL;
- virCgroupPtr cgroup = NULL;
-
- if (!(driver->cgroup &&
- virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) == 0))
- return -1;
-
- /* From here on, we know that cgroup != NULL. */
+ virLXCDomainObjPrivatePtr priv = vm->privateData;
while (waited_time < timeout) {
int r;
* to "FROZEN".
* (see linux-2.6/Documentation/cgroups/freezer-subsystem.txt)
*/
- r = virCgroupSetFreezerState(cgroup, "FROZEN");
+ r = virCgroupSetFreezerState(priv->cgroup, "FROZEN");
/*
* Returning EBUSY explicitly indicates that the group is
*/
usleep(check_interval * 1000);
- r = virCgroupGetFreezerState(cgroup, &state);
+ r = virCgroupGetFreezerState(priv->cgroup, &state);
if (r < 0) {
VIR_DEBUG("Reading freezer.state failed with errno: %d", r);
* activate the group again and return an error.
* This is likely to fall the group back again gracefully.
*/
- virCgroupSetFreezerState(cgroup, "THAWED");
+ virCgroupSetFreezerState(priv->cgroup, "THAWED");
ret = -1;
cleanup:
- virCgroupFree(&cgroup);
VIR_FREE(state);
return ret;
}
}
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
- if (lxcFreezeContainer(driver, vm) < 0) {
+ if (lxcFreezeContainer(vm) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("Suspend operation failed"));
goto cleanup;
return ret;
}
-static int lxcUnfreezeContainer(virLXCDriverPtr driver, virDomainObjPtr vm)
-{
- int ret;
- virCgroupPtr cgroup = NULL;
-
- if (!(driver->cgroup &&
- virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) == 0))
- return -1;
-
- ret = virCgroupSetFreezerState(cgroup, "THAWED");
-
- virCgroupFree(&cgroup);
- return ret;
-}
-
static int lxcDomainResume(virDomainPtr dom)
{
virLXCDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
virDomainEventPtr event = NULL;
int ret = -1;
+ virLXCDomainObjPrivatePtr priv;
lxcDriverLock(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
goto cleanup;
}
+ priv = vm->privateData;
+
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("Domain is not running"));
}
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
- if (lxcUnfreezeContainer(driver, vm) < 0) {
+ if (virCgroupSetFreezerState(priv->cgroup, "THAWED") < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("Resume operation failed"));
goto cleanup;
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainDiskDefPtr def = dev->data.disk;
- virCgroupPtr group = NULL;
int ret = -1;
char *dst = NULL;
struct stat sb;
vm->def, def) < 0)
goto cleanup;
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
- if (virCgroupAllowDevicePath(group, def->src,
+ if (virCgroupAllowDevicePath(priv->cgroup, def->src,
(def->readonly ?
VIR_CGROUP_DEVICE_READ :
VIR_CGROUP_DEVICE_RW) |
cleanup:
def->src = tmpsrc;
virDomainAuditDisk(vm, NULL, def->src, "attach", ret == 0);
- if (group)
- virCgroupFree(&group);
if (dst && created && ret < 0)
unlink(dst);
return ret;
mode_t mode;
bool created = false;
virUSBDevicePtr usb = NULL;
- virCgroupPtr group = NULL;
if (virDomainHostdevFind(vm->def, def, NULL) >= 0) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
goto cleanup;
}
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
if (!(usb = virUSBDeviceNew(def->source.subsys.u.usb.bus,
def->source.subsys.u.usb.device, vroot)))
goto cleanup;
goto cleanup;
if (virUSBDeviceFileIterate(usb,
- virLXCSetupHostUsbDeviceCgroup,
- &group) < 0)
+ virLXCSetupHostUsbDeviceCgroup,
+ &priv->cgroup) < 0)
goto cleanup;
ret = 0;
unlink(dstfile);
virUSBDeviceFree(usb);
- virCgroupFree(&group);
VIR_FREE(src);
VIR_FREE(dstfile);
VIR_FREE(dstdir);
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = dev->data.hostdev;
- virCgroupPtr group = NULL;
int ret = -1;
char *dst = NULL;
char *vroot = NULL;
vm->def, def, vroot) < 0)
goto cleanup;
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
- if (virCgroupAllowDevicePath(group, def->source.caps.u.storage.block,
+ if (virCgroupAllowDevicePath(priv->cgroup, def->source.caps.u.storage.block,
VIR_CGROUP_DEVICE_RW |
VIR_CGROUP_DEVICE_MKNOD) != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
cleanup:
virDomainAuditHostdev(vm, def, "attach", ret == 0);
- if (group)
- virCgroupFree(&group);
if (dst && created && ret < 0)
unlink(dst);
VIR_FREE(dst);
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = dev->data.hostdev;
- virCgroupPtr group = NULL;
int ret = -1;
char *dst = NULL;
char *vroot = NULL;
vm->def, def, vroot) < 0)
goto cleanup;
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
- if (virCgroupAllowDevicePath(group, def->source.caps.u.misc.chardev,
+ if (virCgroupAllowDevicePath(priv->cgroup, def->source.caps.u.misc.chardev,
VIR_CGROUP_DEVICE_RW |
VIR_CGROUP_DEVICE_MKNOD) != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
cleanup:
virDomainAuditHostdev(vm, def, "attach", ret == 0);
- if (group)
- virCgroupFree(&group);
if (dst && created && ret < 0)
unlink(dst);
VIR_FREE(dst);
static int
-lxcDomainDetachDeviceDiskLive(virLXCDriverPtr driver,
- virDomainObjPtr vm,
+lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainDiskDefPtr def = NULL;
- virCgroupPtr group = NULL;
int i, ret = -1;
char *dst = NULL;
goto cleanup;
}
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
VIR_DEBUG("Unlinking %s (backed by %s)", dst, def->src);
if (unlink(dst) < 0 && errno != ENOENT) {
virDomainAuditDisk(vm, def->src, NULL, "detach", false);
}
virDomainAuditDisk(vm, def->src, NULL, "detach", true);
- if (virCgroupDenyDevicePath(group, def->src, VIR_CGROUP_DEVICE_RWM) != 0)
+ if (virCgroupDenyDevicePath(priv->cgroup, def->src, VIR_CGROUP_DEVICE_RWM) != 0)
VIR_WARN("cannot deny device %s for domain %s",
def->src, vm->def->name);
cleanup:
VIR_FREE(dst);
- if (group)
- virCgroupFree(&group);
return ret;
}
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = NULL;
- virCgroupPtr group = NULL;
int idx, ret = -1;
char *dst = NULL;
char *vroot;
goto cleanup;
}
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
if (!(usb = virUSBDeviceNew(def->source.subsys.u.usb.bus,
def->source.subsys.u.usb.device, vroot)))
goto cleanup;
virDomainAuditHostdev(vm, def, "detach", true);
if (virUSBDeviceFileIterate(usb,
- virLXCTeardownHostUsbDeviceCgroup,
- &group) < 0)
+ virLXCTeardownHostUsbDeviceCgroup,
+ &priv->cgroup) < 0)
VIR_WARN("cannot deny device %s for domain %s",
dst, vm->def->name);
cleanup:
virUSBDeviceFree(usb);
VIR_FREE(dst);
- virCgroupFree(&group);
return ret;
}
static int
-lxcDomainDetachDeviceHostdevStorageLive(virLXCDriverPtr driver,
- virDomainObjPtr vm,
+lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = NULL;
- virCgroupPtr group = NULL;
int i, ret = -1;
char *dst = NULL;
goto cleanup;
}
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
VIR_DEBUG("Unlinking %s", dst);
if (unlink(dst) < 0 && errno != ENOENT) {
virDomainAuditHostdev(vm, def, "detach", false);
}
virDomainAuditHostdev(vm, def, "detach", true);
- if (virCgroupDenyDevicePath(group, def->source.caps.u.storage.block, VIR_CGROUP_DEVICE_RWM) != 0)
+ if (virCgroupDenyDevicePath(priv->cgroup, def->source.caps.u.storage.block, VIR_CGROUP_DEVICE_RWM) != 0)
VIR_WARN("cannot deny device %s for domain %s",
def->source.caps.u.storage.block, vm->def->name);
cleanup:
VIR_FREE(dst);
- if (group)
- virCgroupFree(&group);
return ret;
}
static int
-lxcDomainDetachDeviceHostdevMiscLive(virLXCDriverPtr driver,
- virDomainObjPtr vm,
+lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = NULL;
- virCgroupPtr group = NULL;
int i, ret = -1;
char *dst = NULL;
goto cleanup;
}
- if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
+ if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("devices cgroup isn't mounted"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find cgroup for domain %s"), vm->def->name);
- goto cleanup;
- }
-
VIR_DEBUG("Unlinking %s", dst);
if (unlink(dst) < 0 && errno != ENOENT) {
virDomainAuditHostdev(vm, def, "detach", false);
}
virDomainAuditHostdev(vm, def, "detach", true);
- if (virCgroupDenyDevicePath(group, def->source.caps.u.misc.chardev, VIR_CGROUP_DEVICE_RWM) != 0)
+ if (virCgroupDenyDevicePath(priv->cgroup, def->source.caps.u.misc.chardev, VIR_CGROUP_DEVICE_RWM) != 0)
VIR_WARN("cannot deny device %s for domain %s",
def->source.caps.u.misc.chardev, vm->def->name);
cleanup:
VIR_FREE(dst);
- if (group)
- virCgroupFree(&group);
return ret;
}
static int
-lxcDomainDetachDeviceHostdevCapsLive(virLXCDriverPtr driver,
- virDomainObjPtr vm,
- virDomainDeviceDefPtr dev)
+lxcDomainDetachDeviceHostdevCapsLive(virDomainObjPtr vm,
+ virDomainDeviceDefPtr dev)
{
switch (dev->data.hostdev->source.caps.type) {
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
- return lxcDomainDetachDeviceHostdevStorageLive(driver, vm, dev);
+ return lxcDomainDetachDeviceHostdevStorageLive(vm, dev);
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
- return lxcDomainDetachDeviceHostdevMiscLive(driver, vm, dev);
+ return lxcDomainDetachDeviceHostdevMiscLive(vm, dev);
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
return lxcDomainDetachDeviceHostdevSubsysLive(driver, vm, dev);
case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
- return lxcDomainDetachDeviceHostdevCapsLive(driver, vm, dev);
+ return lxcDomainDetachDeviceHostdevCapsLive(vm, dev);
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
- ret = lxcDomainDetachDeviceDiskLive(driver, vm, dev);
+ ret = lxcDomainDetachDeviceDiskLive(vm, dev);
break;
case VIR_DOMAIN_DEVICE_NET: