mirror of https://gitee.com/openkylin/libvirt.git
Report full errors from virCgroupNew*
Instead of returning raw errno values, report full libvirt errors in virCgroupNew* functions. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
f5384eed3f
commit
b64dabff27
|
@ -1156,6 +1156,7 @@ virCgroupAddTaskController;
|
||||||
virCgroupAllowDevice;
|
virCgroupAllowDevice;
|
||||||
virCgroupAllowDeviceMajor;
|
virCgroupAllowDeviceMajor;
|
||||||
virCgroupAllowDevicePath;
|
virCgroupAllowDevicePath;
|
||||||
|
virCgroupAvailable;
|
||||||
virCgroupControllerTypeFromString;
|
virCgroupControllerTypeFromString;
|
||||||
virCgroupControllerTypeToString;
|
virCgroupControllerTypeToString;
|
||||||
virCgroupDenyAllDevices;
|
virCgroupDenyAllDevices;
|
||||||
|
@ -1188,6 +1189,7 @@ virCgroupNewDomainDriver;
|
||||||
virCgroupNewDomainPartition;
|
virCgroupNewDomainPartition;
|
||||||
virCgroupNewDriver;
|
virCgroupNewDriver;
|
||||||
virCgroupNewEmulator;
|
virCgroupNewEmulator;
|
||||||
|
virCgroupNewIgnoreError;
|
||||||
virCgroupNewPartition;
|
virCgroupNewPartition;
|
||||||
virCgroupNewSelf;
|
virCgroupNewSelf;
|
||||||
virCgroupNewVcpu;
|
virCgroupNewVcpu;
|
||||||
|
|
|
@ -306,33 +306,29 @@ cleanup:
|
||||||
|
|
||||||
int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo)
|
int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = -1, rc;
|
||||||
virCgroupPtr cgroup;
|
virCgroupPtr cgroup;
|
||||||
|
|
||||||
ret = virCgroupNewSelf(&cgroup);
|
if (virCgroupNewSelf(&cgroup) < 0)
|
||||||
if (ret < 0) {
|
return -1;
|
||||||
virReportSystemError(-ret, "%s",
|
|
||||||
_("Unable to get cgroup for container"));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = virLXCCgroupGetMemStat(cgroup, meminfo);
|
rc = virLXCCgroupGetMemStat(cgroup, meminfo);
|
||||||
if (ret < 0) {
|
if (rc < 0) {
|
||||||
virReportSystemError(-ret, "%s",
|
virReportSystemError(-rc, "%s",
|
||||||
_("Unable to get memory cgroup stat info"));
|
_("Unable to get memory cgroup stat info"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virLXCCgroupGetMemTotal(cgroup, meminfo);
|
rc = virLXCCgroupGetMemTotal(cgroup, meminfo);
|
||||||
if (ret < 0) {
|
if (rc < 0) {
|
||||||
virReportSystemError(-ret, "%s",
|
virReportSystemError(-rc, "%s",
|
||||||
_("Unable to get memory cgroup total"));
|
_("Unable to get memory cgroup total"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virLXCCgroupGetMemUsage(cgroup, meminfo);
|
rc = virLXCCgroupGetMemUsage(cgroup, meminfo);
|
||||||
if (ret < 0) {
|
if (rc < 0) {
|
||||||
virReportSystemError(-ret, "%s",
|
virReportSystemError(-rc, "%s",
|
||||||
_("Unable to get memory cgroup stat usage"));
|
_("Unable to get memory cgroup stat usage"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -541,7 +537,6 @@ cleanup:
|
||||||
|
|
||||||
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup)
|
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup)
|
||||||
{
|
{
|
||||||
int rc;
|
|
||||||
virCgroupPtr parent = NULL;
|
virCgroupPtr parent = NULL;
|
||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
|
|
||||||
|
@ -569,50 +564,30 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup)
|
||||||
}
|
}
|
||||||
/* We only auto-create the default partition. In other
|
/* We only auto-create the default partition. In other
|
||||||
* cases we expec the sysadmin/app to have done so */
|
* cases we expec the sysadmin/app to have done so */
|
||||||
rc = virCgroupNewPartition(def->resource->partition,
|
if (virCgroupNewPartition(def->resource->partition,
|
||||||
STREQ(def->resource->partition, "/machine"),
|
STREQ(def->resource->partition, "/machine"),
|
||||||
-1,
|
-1,
|
||||||
&parent);
|
&parent) < 0)
|
||||||
if (rc != 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to initialize %s cgroup"),
|
|
||||||
def->resource->partition);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
rc = virCgroupNewDomainPartition(parent,
|
if (virCgroupNewDomainPartition(parent,
|
||||||
"lxc",
|
"lxc",
|
||||||
def->name,
|
def->name,
|
||||||
true,
|
true,
|
||||||
&cgroup);
|
&cgroup) < 0)
|
||||||
if (rc != 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to create cgroup for %s"),
|
|
||||||
def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
rc = virCgroupNewDriver("lxc",
|
if (virCgroupNewDriver("lxc",
|
||||||
true,
|
true,
|
||||||
-1,
|
-1,
|
||||||
&parent);
|
&parent) < 0)
|
||||||
if (rc != 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to create cgroup for %s"),
|
|
||||||
def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
rc = virCgroupNewDomainDriver(parent,
|
if (virCgroupNewDomainDriver(parent,
|
||||||
def->name,
|
def->name,
|
||||||
true,
|
true,
|
||||||
&cgroup);
|
&cgroup) < 0)
|
||||||
if (rc != 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to create cgroup for %s"),
|
|
||||||
def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
|
@ -1466,7 +1466,6 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
|
||||||
virSecurityManagerPtr securityDriver)
|
virSecurityManagerPtr securityDriver)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
int rc;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *sec_mount_options;
|
char *sec_mount_options;
|
||||||
char *stateDir = NULL;
|
char *stateDir = NULL;
|
||||||
|
@ -1478,11 +1477,8 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
|
||||||
|
|
||||||
/* Before pivoting we need to identify any
|
/* Before pivoting we need to identify any
|
||||||
* cgroups controllers that are mounted */
|
* cgroups controllers that are mounted */
|
||||||
if ((rc = virCgroupNewSelf(&cgroup)) != 0) {
|
if (virCgroupNewSelf(&cgroup) < 0)
|
||||||
virReportSystemError(-rc, "%s",
|
|
||||||
_("Cannot identify cgroup placement"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (virFileResolveAllLinks(LXC_STATE_DIR, &stateDir) < 0)
|
if (virFileResolveAllLinks(LXC_STATE_DIR, &stateDir) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
|
@ -139,8 +139,10 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
|
||||||
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
||||||
virBufferPtr new_meminfo = &buffer;
|
virBufferPtr new_meminfo = &buffer;
|
||||||
|
|
||||||
if ((res = virLXCCgroupGetMeminfo(&meminfo)) < 0)
|
if (virLXCCgroupGetMeminfo(&meminfo) < 0) {
|
||||||
return res;
|
virErrorSetErrnoFromLastError();
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
fd = fopen(hostpath, "r");
|
fd = fopen(hostpath, "r");
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
|
|
|
@ -731,6 +731,9 @@ qemuInitCgroup(virQEMUDriverPtr driver,
|
||||||
if (!cfg->privileged)
|
if (!cfg->privileged)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
if (!virCgroupAvailable())
|
||||||
|
goto done;
|
||||||
|
|
||||||
virCgroupFree(&priv->cgroup);
|
virCgroupFree(&priv->cgroup);
|
||||||
|
|
||||||
if (!vm->def->resource && startup) {
|
if (!vm->def->resource && startup) {
|
||||||
|
@ -757,64 +760,38 @@ qemuInitCgroup(virQEMUDriverPtr driver,
|
||||||
}
|
}
|
||||||
/* We only auto-create the default partition. In other
|
/* We only auto-create the default partition. In other
|
||||||
* cases we expec the sysadmin/app to have done so */
|
* cases we expec the sysadmin/app to have done so */
|
||||||
rc = virCgroupNewPartition(vm->def->resource->partition,
|
if (virCgroupNewPartition(vm->def->resource->partition,
|
||||||
STREQ(vm->def->resource->partition, "/machine"),
|
STREQ(vm->def->resource->partition, "/machine"),
|
||||||
cfg->cgroupControllers,
|
cfg->cgroupControllers,
|
||||||
&parent);
|
&parent) < 0) {
|
||||||
if (rc != 0) {
|
if (virCgroupNewIgnoreError())
|
||||||
if (rc == -ENXIO ||
|
|
||||||
rc == -EPERM ||
|
|
||||||
rc == -EACCES) { /* No cgroups mounts == success */
|
|
||||||
VIR_DEBUG("No cgroups present/configured/accessible, ignoring error");
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
|
||||||
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to initialize %s cgroup"),
|
|
||||||
vm->def->resource->partition);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = virCgroupNewDomainPartition(parent,
|
if (virCgroupNewDomainPartition(parent,
|
||||||
"qemu",
|
"qemu",
|
||||||
vm->def->name,
|
vm->def->name,
|
||||||
true,
|
true,
|
||||||
&priv->cgroup);
|
&priv->cgroup) < 0)
|
||||||
if (rc != 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to create cgroup for %s"),
|
|
||||||
vm->def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
rc = virCgroupNewDriver("qemu",
|
if (virCgroupNewDriver("qemu",
|
||||||
true,
|
true,
|
||||||
cfg->cgroupControllers,
|
cfg->cgroupControllers,
|
||||||
&parent);
|
&parent) < 0) {
|
||||||
if (rc != 0) {
|
if (virCgroupNewIgnoreError())
|
||||||
if (rc == -ENXIO ||
|
|
||||||
rc == -EPERM ||
|
|
||||||
rc == -EACCES) { /* No cgroups mounts == success */
|
|
||||||
VIR_DEBUG("No cgroups present/configured/accessible, ignoring error");
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
|
||||||
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to create cgroup for %s"),
|
|
||||||
vm->def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = virCgroupNewDomainDriver(parent,
|
if (virCgroupNewDomainDriver(parent,
|
||||||
vm->def->name,
|
vm->def->name,
|
||||||
true,
|
true,
|
||||||
&priv->cgroup);
|
&priv->cgroup) < 0)
|
||||||
if (rc != 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to create cgroup for %s"),
|
|
||||||
vm->def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
@ -994,14 +971,8 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < priv->nvcpupids; i++) {
|
for (i = 0; i < priv->nvcpupids; i++) {
|
||||||
rc = virCgroupNewVcpu(priv->cgroup, i, true, &cgroup_vcpu);
|
if (virCgroupNewVcpu(priv->cgroup, i, true, &cgroup_vcpu) < 0)
|
||||||
if (rc < 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to create vcpu cgroup for %s(vcpu:"
|
|
||||||
" %zu)"),
|
|
||||||
vm->def->name, i);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
/* move the thread for vcpu to sub dir */
|
/* move the thread for vcpu to sub dir */
|
||||||
rc = virCgroupAddTask(cgroup_vcpu, priv->vcpupids[i]);
|
rc = virCgroupAddTask(cgroup_vcpu, priv->vcpupids[i]);
|
||||||
|
@ -1061,7 +1032,7 @@ qemuSetupCgroupForEmulator(virQEMUDriverPtr driver,
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
unsigned long long period = vm->def->cputune.emulator_period;
|
unsigned long long period = vm->def->cputune.emulator_period;
|
||||||
long long quota = vm->def->cputune.emulator_quota;
|
long long quota = vm->def->cputune.emulator_quota;
|
||||||
int rc;
|
int rc = -1;
|
||||||
|
|
||||||
if ((period || quota) &&
|
if ((period || quota) &&
|
||||||
!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
|
!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
|
||||||
|
@ -1073,13 +1044,8 @@ qemuSetupCgroupForEmulator(virQEMUDriverPtr driver,
|
||||||
if (priv->cgroup == NULL)
|
if (priv->cgroup == NULL)
|
||||||
return 0; /* Not supported, so claim success */
|
return 0; /* Not supported, so claim success */
|
||||||
|
|
||||||
rc = virCgroupNewEmulator(priv->cgroup, true, &cgroup_emulator);
|
if (virCgroupNewEmulator(priv->cgroup, true, &cgroup_emulator) < 0)
|
||||||
if (rc < 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to create emulator cgroup for %s"),
|
|
||||||
vm->def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
rc = virCgroupMoveTask(priv->cgroup, cgroup_emulator);
|
rc = virCgroupMoveTask(priv->cgroup, cgroup_emulator);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
|
|
@ -3940,14 +3940,8 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
|
||||||
if (priv->cgroup) {
|
if (priv->cgroup) {
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
/* Create cgroup for the onlined vcpu */
|
/* Create cgroup for the onlined vcpu */
|
||||||
rv = virCgroupNewVcpu(priv->cgroup, i, true, &cgroup_vcpu);
|
if (virCgroupNewVcpu(priv->cgroup, i, true, &cgroup_vcpu) < 0)
|
||||||
if (rv < 0) {
|
|
||||||
virReportSystemError(-rv,
|
|
||||||
_("Unable to create vcpu cgroup for %s(vcpu:"
|
|
||||||
" %zu)"),
|
|
||||||
vm->def->name, i);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
/* Add vcpu thread to the cgroup */
|
/* Add vcpu thread to the cgroup */
|
||||||
rv = virCgroupAddTask(cgroup_vcpu, cpupids[i]);
|
rv = virCgroupAddTask(cgroup_vcpu, cpupids[i]);
|
||||||
|
@ -4008,16 +4002,8 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
|
||||||
virDomainVcpuPinDefPtr vcpupin = NULL;
|
virDomainVcpuPinDefPtr vcpupin = NULL;
|
||||||
|
|
||||||
if (priv->cgroup) {
|
if (priv->cgroup) {
|
||||||
int rv = -1;
|
if (virCgroupNewVcpu(priv->cgroup, i, false, &cgroup_vcpu) < 0)
|
||||||
|
|
||||||
rv = virCgroupNewVcpu(priv->cgroup, i, false, &cgroup_vcpu);
|
|
||||||
if (rv < 0) {
|
|
||||||
virReportSystemError(-rv,
|
|
||||||
_("Unable to access vcpu cgroup for %s(vcpu:"
|
|
||||||
" %zu)"),
|
|
||||||
vm->def->name, i);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove cgroup for the offlined vcpu */
|
/* Remove cgroup for the offlined vcpu */
|
||||||
virCgroupRemove(cgroup_vcpu);
|
virCgroupRemove(cgroup_vcpu);
|
||||||
|
@ -4358,8 +4344,9 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
|
||||||
|
|
||||||
/* Configure the corresponding cpuset cgroup before set affinity. */
|
/* Configure the corresponding cpuset cgroup before set affinity. */
|
||||||
if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
|
if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
|
||||||
if (virCgroupNewVcpu(priv->cgroup, vcpu, false, &cgroup_vcpu) == 0 &&
|
if (virCgroupNewVcpu(priv->cgroup, vcpu, false, &cgroup_vcpu) < 0)
|
||||||
qemuSetupCgroupVcpuPin(cgroup_vcpu, newVcpuPin, newVcpuPinNum, vcpu) < 0) {
|
goto cleanup;
|
||||||
|
if (qemuSetupCgroupVcpuPin(cgroup_vcpu, newVcpuPin, newVcpuPinNum, vcpu) < 0) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("failed to set cpuset.cpus in cgroup"
|
_("failed to set cpuset.cpus in cgroup"
|
||||||
" for vcpu %d"), vcpu);
|
" for vcpu %d"), vcpu);
|
||||||
|
@ -4620,16 +4607,15 @@ qemuDomainPinEmulator(virDomainPtr dom,
|
||||||
VIR_CGROUP_CONTROLLER_CPUSET)) {
|
VIR_CGROUP_CONTROLLER_CPUSET)) {
|
||||||
/*
|
/*
|
||||||
* Configure the corresponding cpuset cgroup.
|
* Configure the corresponding cpuset cgroup.
|
||||||
* If no cgroup for domain or hypervisor exists, do nothing.
|
|
||||||
*/
|
*/
|
||||||
if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_emulator) == 0) {
|
if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_emulator) < 0)
|
||||||
if (qemuSetupCgroupEmulatorPin(cgroup_emulator,
|
goto cleanup;
|
||||||
newVcpuPin[0]->cpumask) < 0) {
|
if (qemuSetupCgroupEmulatorPin(cgroup_emulator,
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
newVcpuPin[0]->cpumask) < 0) {
|
||||||
_("failed to set cpuset.cpus in cgroup"
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
" for emulator threads"));
|
_("failed to set cpuset.cpus in cgroup"
|
||||||
goto cleanup;
|
" for emulator threads"));
|
||||||
}
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (virProcessSetAffinity(pid, pcpumap) < 0) {
|
if (virProcessSetAffinity(pid, pcpumap) < 0) {
|
||||||
|
@ -8596,7 +8582,6 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupPtr cgroup,
|
||||||
size_t i;
|
size_t i;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virCgroupPtr cgroup_vcpu = NULL;
|
virCgroupPtr cgroup_vcpu = NULL;
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (period == 0 && quota == 0)
|
if (period == 0 && quota == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -8607,14 +8592,8 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupPtr cgroup,
|
||||||
*/
|
*/
|
||||||
if (priv->nvcpupids != 0 && priv->vcpupids[0] != vm->pid) {
|
if (priv->nvcpupids != 0 && priv->vcpupids[0] != vm->pid) {
|
||||||
for (i = 0; i < priv->nvcpupids; i++) {
|
for (i = 0; i < priv->nvcpupids; i++) {
|
||||||
rc = virCgroupNewVcpu(cgroup, i, false, &cgroup_vcpu);
|
if (virCgroupNewVcpu(cgroup, i, false, &cgroup_vcpu) < 0)
|
||||||
if (rc < 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to find vcpu cgroup for %s(vcpu:"
|
|
||||||
" %zu)"),
|
|
||||||
vm->def->name, i);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuSetupCgroupVcpuBW(cgroup_vcpu, period, quota) < 0)
|
if (qemuSetupCgroupVcpuBW(cgroup_vcpu, period, quota) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -8636,7 +8615,6 @@ qemuSetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr cgroup,
|
||||||
{
|
{
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virCgroupPtr cgroup_emulator = NULL;
|
virCgroupPtr cgroup_emulator = NULL;
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (period == 0 && quota == 0)
|
if (period == 0 && quota == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -8645,13 +8623,8 @@ qemuSetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr cgroup,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = virCgroupNewEmulator(cgroup, false, &cgroup_emulator);
|
if (virCgroupNewEmulator(cgroup, false, &cgroup_emulator) < 0)
|
||||||
if (rc < 0) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to find emulator cgroup for %s"),
|
|
||||||
vm->def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuSetupCgroupVcpuBW(cgroup_emulator, period, quota) < 0)
|
if (qemuSetupCgroupVcpuBW(cgroup_emulator, period, quota) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -8897,13 +8870,8 @@ qemuGetVcpusBWLive(virDomainObjPtr vm,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get period and quota for vcpu0 */
|
/* get period and quota for vcpu0 */
|
||||||
rc = virCgroupNewVcpu(priv->cgroup, 0, false, &cgroup_vcpu);
|
if (virCgroupNewVcpu(priv->cgroup, 0, false, &cgroup_vcpu) < 0)
|
||||||
if (!cgroup_vcpu) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to find vcpu cgroup for %s(vcpu: 0)"),
|
|
||||||
vm->def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
rc = qemuGetVcpuBWLive(cgroup_vcpu, period, quota);
|
rc = qemuGetVcpuBWLive(cgroup_vcpu, period, quota);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
|
@ -8935,13 +8903,8 @@ qemuGetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr cgroup,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get period and quota for emulator */
|
/* get period and quota for emulator */
|
||||||
rc = virCgroupNewEmulator(cgroup, false, &cgroup_emulator);
|
if (virCgroupNewEmulator(cgroup, false, &cgroup_emulator) < 0)
|
||||||
if (!cgroup_emulator) {
|
|
||||||
virReportSystemError(-rc,
|
|
||||||
_("Unable to find emulator cgroup for %s"),
|
|
||||||
vm->def->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
rc = qemuGetVcpuBWLive(cgroup_emulator, period, quota);
|
rc = qemuGetVcpuBWLive(cgroup_emulator, period, quota);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
|
@ -15537,11 +15500,8 @@ getSumVcpuPercpuStats(virDomainObjPtr vm,
|
||||||
unsigned long long tmp;
|
unsigned long long tmp;
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|
||||||
if (virCgroupNewVcpu(priv->cgroup, i, false, &group_vcpu) < 0) {
|
if (virCgroupNewVcpu(priv->cgroup, i, false, &group_vcpu) < 0)
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("error accessing cgroup cpuacct for vcpu"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (virCgroupGetCpuacctPercpuUsage(group_vcpu, &buf) < 0)
|
if (virCgroupGetCpuacctPercpuUsage(group_vcpu, &buf) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -46,6 +46,8 @@ enum {
|
||||||
|
|
||||||
VIR_ENUM_DECL(virCgroupController);
|
VIR_ENUM_DECL(virCgroupController);
|
||||||
|
|
||||||
|
bool virCgroupAvailable(void);
|
||||||
|
|
||||||
int virCgroupNewPartition(const char *path,
|
int virCgroupNewPartition(const char *path,
|
||||||
bool create,
|
bool create,
|
||||||
int controllers,
|
int controllers,
|
||||||
|
@ -84,6 +86,8 @@ int virCgroupNewEmulator(virCgroupPtr domain,
|
||||||
virCgroupPtr *group)
|
virCgroupPtr *group)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
|
||||||
|
|
||||||
|
bool virCgroupNewIgnoreError(void);
|
||||||
|
|
||||||
int virCgroupPathOfController(virCgroupPtr group,
|
int virCgroupPathOfController(virCgroupPtr group,
|
||||||
int controller,
|
int controller,
|
||||||
const char *key,
|
const char *key,
|
||||||
|
|
|
@ -136,6 +136,18 @@ cleanup:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# define ENSURE_ERRNO(en) \
|
||||||
|
do { \
|
||||||
|
if (!virLastErrorIsSystemErrno(en)) { \
|
||||||
|
virErrorPtr err = virGetLastError(); \
|
||||||
|
fprintf(stderr, "Did not get " #en " error code: %d:%d\n", \
|
||||||
|
err ? err->code : 0, err ? err->int1 : 0); \
|
||||||
|
goto cleanup; \
|
||||||
|
} } while (0)
|
||||||
|
|
||||||
|
/* Asking for impossible combination since CPU is co-mounted */
|
||||||
|
|
||||||
|
|
||||||
static int testCgroupNewForDriver(const void *args ATTRIBUTE_UNUSED)
|
static int testCgroupNewForDriver(const void *args ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
|
@ -160,26 +172,28 @@ static int testCgroupNewForDriver(const void *args ATTRIBUTE_UNUSED)
|
||||||
[VIR_CGROUP_CONTROLLER_BLKIO] = "/libvirt/lxc",
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/libvirt/lxc",
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((rv = virCgroupNewDriver("lxc", false, -1, &cgroup)) != -ENOENT) {
|
if ((rv = virCgroupNewDriver("lxc", false, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected found LXC cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected found LXC cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
/* Asking for impossible combination since CPU is co-mounted */
|
|
||||||
if ((rv = virCgroupNewDriver("lxc", true,
|
if ((rv = virCgroupNewDriver("lxc", true,
|
||||||
(1 << VIR_CGROUP_CONTROLLER_CPU),
|
(1 << VIR_CGROUP_CONTROLLER_CPU),
|
||||||
&cgroup)) != -EINVAL) {
|
&cgroup)) != -1) {
|
||||||
fprintf(stderr, "Should not have created LXC cgroup: %d\n", -rv);
|
fprintf(stderr, "Should not have created LXC cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(EINVAL);
|
||||||
|
|
||||||
/* Asking for impossible combination since devices is not mounted */
|
/* Asking for impossible combination since devices is not mounted */
|
||||||
if ((rv = virCgroupNewDriver("lxc", true,
|
if ((rv = virCgroupNewDriver("lxc", true,
|
||||||
(1 << VIR_CGROUP_CONTROLLER_DEVICES),
|
(1 << VIR_CGROUP_CONTROLLER_DEVICES),
|
||||||
&cgroup)) != -ENXIO) {
|
&cgroup)) != -1) {
|
||||||
fprintf(stderr, "Should not have created LXC cgroup: %d\n", -rv);
|
fprintf(stderr, "Should not have created LXC cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(ENXIO);
|
||||||
|
|
||||||
/* Asking for small combination since devices is not mounted */
|
/* Asking for small combination since devices is not mounted */
|
||||||
if ((rv = virCgroupNewDriver("lxc", true,
|
if ((rv = virCgroupNewDriver("lxc", true,
|
||||||
|
@ -264,26 +278,29 @@ static int testCgroupNewForPartition(const void *args ATTRIBUTE_UNUSED)
|
||||||
[VIR_CGROUP_CONTROLLER_BLKIO] = "/virtualmachines.partition",
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/virtualmachines.partition",
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/virtualmachines", false, -1, &cgroup)) != -ENOENT) {
|
if ((rv = virCgroupNewPartition("/virtualmachines", false, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected found /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected found /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
/* Asking for impossible combination since CPU is co-mounted */
|
/* Asking for impossible combination since CPU is co-mounted */
|
||||||
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
||||||
(1 << VIR_CGROUP_CONTROLLER_CPU),
|
(1 << VIR_CGROUP_CONTROLLER_CPU),
|
||||||
&cgroup)) != -EINVAL) {
|
&cgroup)) != -1) {
|
||||||
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(EINVAL);
|
||||||
|
|
||||||
/* Asking for impossible combination since devices is not mounted */
|
/* Asking for impossible combination since devices is not mounted */
|
||||||
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
||||||
(1 << VIR_CGROUP_CONTROLLER_DEVICES),
|
(1 << VIR_CGROUP_CONTROLLER_DEVICES),
|
||||||
&cgroup)) != -ENXIO) {
|
&cgroup)) != -1) {
|
||||||
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(ENXIO);
|
||||||
|
|
||||||
/* Asking for small combination since devices is not mounted */
|
/* Asking for small combination since devices is not mounted */
|
||||||
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
||||||
|
@ -324,16 +341,18 @@ static int testCgroupNewForPartitionNested(const void *args ATTRIBUTE_UNUSED)
|
||||||
[VIR_CGROUP_CONTROLLER_BLKIO] = "/deployment.partition/production.partition",
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/deployment.partition/production.partition",
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/deployment/production", false, -1, &cgroup)) != -ENOENT) {
|
if ((rv = virCgroupNewPartition("/deployment/production", false, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected found /deployment/production cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected found /deployment/production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
/* Should not work, since we require /deployment to be pre-created */
|
/* Should not work, since we require /deployment to be pre-created */
|
||||||
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != -ENOENT) {
|
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected created /deployment/production cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected created /deployment/production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/deployment", true, -1, &cgroup)) != 0) {
|
if ((rv = virCgroupNewPartition("/deployment", true, -1, &cgroup)) != 0) {
|
||||||
fprintf(stderr, "Failed to create /deployment cgroup: %d\n", -rv);
|
fprintf(stderr, "Failed to create /deployment cgroup: %d\n", -rv);
|
||||||
|
@ -370,16 +389,18 @@ static int testCgroupNewForPartitionNestedDeep(const void *args ATTRIBUTE_UNUSED
|
||||||
[VIR_CGROUP_CONTROLLER_BLKIO] = "/user/berrange.user/production.partition",
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/user/berrange.user/production.partition",
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/user/berrange.user/production", false, -1, &cgroup)) != -ENOENT) {
|
if ((rv = virCgroupNewPartition("/user/berrange.user/production", false, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected found /user/berrange.user/production cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected found /user/berrange.user/production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
/* Should not work, since we require /user/berrange.user to be pre-created */
|
/* Should not work, since we require /user/berrange.user to be pre-created */
|
||||||
if ((rv = virCgroupNewPartition("/user/berrange.user/production", true, -1, &cgroup)) != -ENOENT) {
|
if ((rv = virCgroupNewPartition("/user/berrange.user/production", true, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected created /user/berrange.user/production cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected created /user/berrange.user/production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/user", true, -1, &cgroup)) != 0) {
|
if ((rv = virCgroupNewPartition("/user", true, -1, &cgroup)) != 0) {
|
||||||
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
|
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
|
||||||
|
|
Loading…
Reference in New Issue