2010-12-16 16:10:54 +00:00
|
|
|
/*
|
|
|
|
* qemu_cgroup.c: QEMU cgroup management
|
|
|
|
*
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
* Copyright (C) 2006-2011 Red Hat, Inc.
|
2010-12-16 16:10:54 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "qemu_cgroup.h"
|
|
|
|
#include "cgroup.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "virterror_internal.h"
|
|
|
|
#include "util.h"
|
2011-02-16 02:35:43 +00:00
|
|
|
#include "qemu_audit.h"
|
2010-12-16 16:10:54 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
|
|
|
static const char *const defaultDeviceACL[] = {
|
|
|
|
"/dev/null", "/dev/full", "/dev/zero",
|
|
|
|
"/dev/random", "/dev/urandom",
|
|
|
|
"/dev/ptmx", "/dev/kvm", "/dev/kqemu",
|
2011-03-09 22:05:00 +00:00
|
|
|
"/dev/rtc", "/dev/hpet",
|
2010-12-16 16:10:54 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
#define DEVICE_PTY_MAJOR 136
|
|
|
|
#define DEVICE_SND_MAJOR 116
|
|
|
|
|
2011-05-03 20:19:06 +00:00
|
|
|
bool qemuCgroupControllerActive(struct qemud_driver *driver,
|
|
|
|
int controller)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
|
|
|
if (driver->cgroup == NULL)
|
2011-05-03 20:19:06 +00:00
|
|
|
return false;
|
2010-12-16 16:10:54 +00:00
|
|
|
if (!virCgroupMounted(driver->cgroup, controller))
|
2011-05-03 20:19:06 +00:00
|
|
|
return false;
|
|
|
|
if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST)
|
|
|
|
return false;
|
2010-12-16 16:10:54 +00:00
|
|
|
if (driver->cgroupControllers & (1 << controller))
|
2011-05-03 20:19:06 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2011-02-16 02:18:40 +00:00
|
|
|
static int
|
2011-03-09 03:13:18 +00:00
|
|
|
qemuSetupDiskPathAllow(virDomainDiskDefPtr disk,
|
2011-02-16 02:18:40 +00:00
|
|
|
const char *path,
|
|
|
|
size_t depth ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
2011-02-16 02:18:40 +00:00
|
|
|
qemuCgroupData *data = opaque;
|
2010-12-16 16:10:54 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
VIR_DEBUG("Process path %s for disk", path);
|
2011-03-09 03:13:18 +00:00
|
|
|
rc = virCgroupAllowDevicePath(data->cgroup, path,
|
|
|
|
(disk->readonly ? VIR_CGROUP_DEVICE_READ
|
|
|
|
: VIR_CGROUP_DEVICE_RW));
|
2011-03-09 03:06:26 +00:00
|
|
|
qemuAuditCgroupPath(data->vm, data->cgroup, "allow", path,
|
|
|
|
disk->readonly ? "r" : "rw", rc);
|
2011-02-17 00:05:54 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
if (rc == -EACCES) { /* Get this for root squash NFS */
|
2010-12-16 16:10:54 +00:00
|
|
|
VIR_DEBUG("Ignoring EACCES for %s", path);
|
|
|
|
} else {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to allow access for disk path %s"),
|
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuSetupDiskCgroup(struct qemud_driver *driver,
|
2011-02-16 02:18:40 +00:00
|
|
|
virDomainObjPtr vm,
|
2010-12-16 16:10:54 +00:00
|
|
|
virCgroupPtr cgroup,
|
|
|
|
virDomainDiskDefPtr disk)
|
|
|
|
{
|
2011-02-16 02:18:40 +00:00
|
|
|
qemuCgroupData data = { vm, cgroup };
|
2010-12-16 16:10:54 +00:00
|
|
|
return virDomainDiskDefForeachPath(disk,
|
|
|
|
driver->allowDiskFormatProbing,
|
|
|
|
true,
|
|
|
|
qemuSetupDiskPathAllow,
|
2011-02-16 02:18:40 +00:00
|
|
|
&data);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-16 02:18:40 +00:00
|
|
|
static int
|
|
|
|
qemuTeardownDiskPathDeny(virDomainDiskDefPtr disk ATTRIBUTE_UNUSED,
|
|
|
|
const char *path,
|
|
|
|
size_t depth ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
2011-02-16 02:18:40 +00:00
|
|
|
qemuCgroupData *data = opaque;
|
2010-12-16 16:10:54 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
VIR_DEBUG("Process path %s for disk", path);
|
2011-03-09 03:13:18 +00:00
|
|
|
rc = virCgroupDenyDevicePath(data->cgroup, path,
|
|
|
|
VIR_CGROUP_DEVICE_RWM);
|
2011-03-09 03:06:26 +00:00
|
|
|
qemuAuditCgroupPath(data->vm, data->cgroup, "deny", path, "rwm", rc);
|
2011-02-17 00:05:54 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
if (rc == -EACCES) { /* Get this for root squash NFS */
|
2010-12-16 16:10:54 +00:00
|
|
|
VIR_DEBUG("Ignoring EACCES for %s", path);
|
|
|
|
} else {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to deny access for disk path %s"),
|
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuTeardownDiskCgroup(struct qemud_driver *driver,
|
2011-02-16 02:18:40 +00:00
|
|
|
virDomainObjPtr vm,
|
2010-12-16 16:10:54 +00:00
|
|
|
virCgroupPtr cgroup,
|
|
|
|
virDomainDiskDefPtr disk)
|
|
|
|
{
|
2011-02-16 02:18:40 +00:00
|
|
|
qemuCgroupData data = { vm, cgroup };
|
2010-12-16 16:10:54 +00:00
|
|
|
return virDomainDiskDefForeachPath(disk,
|
|
|
|
driver->allowDiskFormatProbing,
|
|
|
|
true,
|
|
|
|
qemuTeardownDiskPathDeny,
|
2011-02-16 02:18:40 +00:00
|
|
|
&data);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-16 02:18:40 +00:00
|
|
|
static int
|
|
|
|
qemuSetupChardevCgroup(virDomainDefPtr def,
|
|
|
|
virDomainChrDefPtr dev,
|
|
|
|
void *opaque)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
2011-02-16 02:18:40 +00:00
|
|
|
qemuCgroupData *data = opaque;
|
2010-12-16 16:10:54 +00:00
|
|
|
int rc;
|
|
|
|
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
if (dev->source.type != VIR_DOMAIN_CHR_TYPE_DEV)
|
2010-12-16 16:10:54 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
VIR_DEBUG("Process path '%s' for disk", dev->source.data.file.path);
|
2011-03-09 03:13:18 +00:00
|
|
|
rc = virCgroupAllowDevicePath(data->cgroup, dev->source.data.file.path,
|
|
|
|
VIR_CGROUP_DEVICE_RW);
|
2011-03-07 23:17:26 +00:00
|
|
|
qemuAuditCgroupPath(data->vm, data->cgroup, "allow",
|
2011-03-09 03:06:26 +00:00
|
|
|
dev->source.data.file.path, "rw", rc);
|
2011-02-17 00:05:54 +00:00
|
|
|
if (rc < 0) {
|
2010-12-16 16:10:54 +00:00
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to allow device %s for %s"),
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
dev->source.data.file.path, def->name);
|
2010-12-16 16:10:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuSetupHostUsbDeviceCgroup(usbDevice *dev ATTRIBUTE_UNUSED,
|
|
|
|
const char *path,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2011-02-16 02:18:40 +00:00
|
|
|
qemuCgroupData *data = opaque;
|
2010-12-16 16:10:54 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
VIR_DEBUG("Process path '%s' for USB device", path);
|
2011-03-09 03:13:18 +00:00
|
|
|
rc = virCgroupAllowDevicePath(data->cgroup, path,
|
|
|
|
VIR_CGROUP_DEVICE_RW);
|
2011-03-09 03:06:26 +00:00
|
|
|
qemuAuditCgroupPath(data->vm, data->cgroup, "allow", path, "rw", rc);
|
2011-02-17 00:05:54 +00:00
|
|
|
if (rc < 0) {
|
2010-12-16 16:10:54 +00:00
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to allow device %s"),
|
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuSetupCgroup(struct qemud_driver *driver,
|
|
|
|
virDomainObjPtr vm)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
int rc;
|
|
|
|
unsigned int i;
|
|
|
|
const char *const *deviceACL =
|
|
|
|
driver->cgroupDeviceACL ?
|
|
|
|
(const char *const *)driver->cgroupDeviceACL :
|
|
|
|
defaultDeviceACL;
|
|
|
|
|
|
|
|
if (driver->cgroup == NULL)
|
|
|
|
return 0; /* Not supported, so claim success */
|
|
|
|
|
|
|
|
rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 1);
|
|
|
|
if (rc != 0) {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to create cgroup for %s"),
|
|
|
|
vm->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) {
|
2011-02-16 02:18:40 +00:00
|
|
|
qemuCgroupData data = { vm, cgroup };
|
2010-12-16 16:10:54 +00:00
|
|
|
rc = virCgroupDenyAllDevices(cgroup);
|
2011-03-07 23:17:26 +00:00
|
|
|
qemuAuditCgroup(vm, cgroup, "deny", "all", rc == 0);
|
2010-12-16 16:10:54 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
if (rc == -EPERM) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("Group devices ACL is not accessible, disabling whitelisting");
|
2010-12-16 16:10:54 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to deny all devices for %s"), vm->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < vm->def->ndisks ; i++) {
|
2011-02-16 02:18:40 +00:00
|
|
|
if (qemuSetupDiskCgroup(driver, vm, cgroup, vm->def->disks[i]) < 0)
|
2010-12-16 16:10:54 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:13:18 +00:00
|
|
|
rc = virCgroupAllowDeviceMajor(cgroup, 'c', DEVICE_PTY_MAJOR,
|
|
|
|
VIR_CGROUP_DEVICE_RW);
|
2011-03-07 23:17:26 +00:00
|
|
|
qemuAuditCgroupMajor(vm, cgroup, "allow", DEVICE_PTY_MAJOR,
|
2011-03-09 03:06:26 +00:00
|
|
|
"pty", "rw", rc == 0);
|
2010-12-16 16:10:54 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
virReportSystemError(-rc, "%s",
|
|
|
|
_("unable to allow /dev/pts/ devices"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-02-25 18:55:44 +00:00
|
|
|
if (vm->def->nsounds &&
|
|
|
|
(!vm->def->ngraphics ||
|
|
|
|
((vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
|
|
|
|
driver->vncAllowHostAudio) ||
|
|
|
|
(vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL)))) {
|
2011-03-09 03:13:18 +00:00
|
|
|
rc = virCgroupAllowDeviceMajor(cgroup, 'c', DEVICE_SND_MAJOR,
|
|
|
|
VIR_CGROUP_DEVICE_RW);
|
2011-03-07 23:17:26 +00:00
|
|
|
qemuAuditCgroupMajor(vm, cgroup, "allow", DEVICE_SND_MAJOR,
|
2011-03-09 03:06:26 +00:00
|
|
|
"sound", "rw", rc == 0);
|
2010-12-16 16:10:54 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
virReportSystemError(-rc, "%s",
|
|
|
|
_("unable to allow /dev/snd/ devices"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; deviceACL[i] != NULL ; i++) {
|
2011-03-09 03:13:18 +00:00
|
|
|
rc = virCgroupAllowDevicePath(cgroup, deviceACL[i],
|
|
|
|
VIR_CGROUP_DEVICE_RW);
|
2011-03-09 03:06:26 +00:00
|
|
|
qemuAuditCgroupPath(vm, cgroup, "allow", deviceACL[i], "rw", rc);
|
2010-12-16 16:10:54 +00:00
|
|
|
if (rc < 0 &&
|
|
|
|
rc != -ENOENT) {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("unable to allow device %s"),
|
|
|
|
deviceACL[i]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainChrDefForeach(vm->def,
|
|
|
|
true,
|
|
|
|
qemuSetupChardevCgroup,
|
2011-02-16 02:18:40 +00:00
|
|
|
&data) < 0)
|
2010-12-16 16:10:54 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < vm->def->nhostdevs; i++) {
|
|
|
|
virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
|
|
|
|
usbDevice *usb;
|
|
|
|
|
|
|
|
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
|
|
|
continue;
|
|
|
|
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
|
|
|
|
hostdev->source.subsys.u.usb.device)) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-02-16 02:18:40 +00:00
|
|
|
if (usbDeviceFileIterate(usb, qemuSetupHostUsbDeviceCgroup,
|
|
|
|
&data) < 0)
|
2010-12-16 16:10:54 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 03:41:33 +00:00
|
|
|
if (vm->def->blkio.weight != 0) {
|
|
|
|
if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
|
2011-02-08 06:59:38 +00:00
|
|
|
rc = virCgroupSetBlkioWeight(cgroup, vm->def->blkio.weight);
|
|
|
|
if(rc != 0) {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to set io weight for domain %s"),
|
|
|
|
vm->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-04-01 03:41:33 +00:00
|
|
|
} else {
|
|
|
|
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Block I/O tuning is not available on this host"));
|
2011-02-08 06:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 03:41:33 +00:00
|
|
|
if (vm->def->mem.hard_limit != 0 ||
|
|
|
|
vm->def->mem.soft_limit != 0 ||
|
|
|
|
vm->def->mem.swap_hard_limit != 0) {
|
2011-05-03 20:19:06 +00:00
|
|
|
if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY)) {
|
2011-04-01 03:41:33 +00:00
|
|
|
if (vm->def->mem.hard_limit != 0) {
|
|
|
|
rc = virCgroupSetMemoryHardLimit(cgroup, vm->def->mem.hard_limit);
|
|
|
|
if (rc != 0) {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to set memory hard limit for domain %s"),
|
|
|
|
vm->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
2011-04-01 03:41:33 +00:00
|
|
|
if (vm->def->mem.soft_limit != 0) {
|
|
|
|
rc = virCgroupSetMemorySoftLimit(cgroup, vm->def->mem.soft_limit);
|
|
|
|
if (rc != 0) {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to set memory soft limit for domain %s"),
|
|
|
|
vm->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 03:41:33 +00:00
|
|
|
if (vm->def->mem.swap_hard_limit != 0) {
|
|
|
|
rc = virCgroupSetMemSwapHardLimit(cgroup, vm->def->mem.swap_hard_limit);
|
|
|
|
if (rc != 0) {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to set swap hard limit for domain %s"),
|
|
|
|
vm->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
2011-04-01 03:41:33 +00:00
|
|
|
} else {
|
|
|
|
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Memory cgroup is not available on this host"));
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 03:41:33 +00:00
|
|
|
if (vm->def->cputune.shares != 0) {
|
|
|
|
if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
|
2011-03-29 13:41:25 +00:00
|
|
|
rc = virCgroupSetCpuShares(cgroup, vm->def->cputune.shares);
|
|
|
|
if(rc != 0) {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("Unable to set io cpu shares for domain %s"),
|
|
|
|
vm->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-04-01 03:41:33 +00:00
|
|
|
} else {
|
|
|
|
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("CPU tuning is not available on this host"));
|
2011-03-29 13:41:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-16 16:10:54 +00:00
|
|
|
done:
|
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (cgroup) {
|
|
|
|
virCgroupRemove(cgroup);
|
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuRemoveCgroup(struct qemud_driver *driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
int quiet)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (driver->cgroup == NULL)
|
|
|
|
return 0; /* Not supported, so claim success */
|
|
|
|
|
|
|
|
rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0);
|
|
|
|
if (rc != 0) {
|
|
|
|
if (!quiet)
|
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
2011-01-28 03:39:44 +00:00
|
|
|
_("Unable to find cgroup for %s"),
|
2010-12-16 16:10:54 +00:00
|
|
|
vm->def->name);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = virCgroupRemove(cgroup);
|
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuAddToCgroup(struct qemud_driver *driver,
|
|
|
|
virDomainDefPtr def)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (driver->cgroup == NULL)
|
|
|
|
return 0; /* Not supported, so claim success */
|
|
|
|
|
|
|
|
rc = virCgroupForDomain(driver->cgroup, def->name, &cgroup, 0);
|
|
|
|
if (rc != 0) {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("unable to find cgroup for domain %s"),
|
|
|
|
def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = virCgroupAddTask(cgroup, getpid());
|
|
|
|
if (rc != 0) {
|
|
|
|
virReportSystemError(-rc,
|
|
|
|
_("unable to add domain %s task %d to cgroup"),
|
|
|
|
def->name, getpid());
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|