Commit Graph

25 Commits

Author SHA1 Message Date
Lai Jiangshan
41b2cee2a8 qemu_driver: add virCgroupMounted
When we mount any cgroup without "-o devices", we will fail to start vms:

error: Failed to start domain vm1
error: Unable to deny all devices for vm1: No such file or directory

When we mount any cgroup without "-o cpu", we will fail to get schedinfo:
Scheduler      : posix
error: unable to get cpu shares tunable: No such file or directory

We should only use the cgroup controllers which are mounted on host.
So I add virCgroupMounted() for qemuCgroupControllerActive()

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2010-10-29 09:46:25 -06:00
Nikunj A. Dadhania
5f481e4df1 Implement cgroup memory controller tunables
Provides interfaces for setting/getting memory tunables like hard_limit,
soft_limit and swap_hard_limit
2010-10-12 19:26:09 +02:00
Ryota Ozaki
29da015aac cgroup: Fix compilation broken on MinGW due to dirent->d_type
As pointed out by Eric Blake, using dirent->d_type breaks
compilation on MinGW. This patch addresses this by using
'#if defined' as same as doing for virCgroupForDriver.
2010-06-30 08:32:23 -06:00
Ryota Ozaki
adc796c8eb cgroup: Add missing errno == ENOENT check in virCgroupRemoveRecursively
ENOENT happens normally when a subsystem is enabled with any other
subsystems and the directory of the target group has already removed
in a prior loop. In that case, the function should just return without
leaving an error message.

NB this is the same behavior as before introducing virCgroupRemoveRecursively.
2010-06-29 12:16:51 -06:00
Daniel P. Berrange
2bad82f71e Set labelling for character devices in security drivers
When configuring serial, parallel, console or channel devices
with a file, dev or pipe backend type, it is necessary to label
the file path in the security drivers. For char devices of type
file, it is neccessary to pre-create (touch) the file if it does
not already exist since QEMU won't be allowed todo so itself.
dev/pipe configs already require the admin to pre-create before
starting the guest.

* src/qemu/qemu_security_dac.c: set file ownership for character
  devices
* src/security/security_selinux.c: Set file labeling for character
  devices
* src/qemu/qemu_driver.c: Add character devices to cgroup ACL
2010-06-25 14:39:54 +01:00
Ryota Ozaki
4a4eb13e7a cgroup: Enable memory.use_hierarchy of cgroup for domain
Through conversation with Kumar L Srikanth-B22348, I found
that the function of getting memory usage (e.g., virsh dominfo)
doesn't work for lxc with ns subsystem of cgroup enabled.

This is because of features of ns and memory subsystems.
Ns creates child cgroup on every process fork and as a result
processes in a container are not assigned in a cgroup for
domain (e.g., libvirt/lxc/test1/). For example, libvirt_lxc
and init (or somewhat specified in XML) are assigned into
libvirt/lxc/test1/8839/ and libvirt/lxc/test1/8839/8849/,
respectively. On the other hand, memory subsystem accounts
memory usage within a group of processes by default, i.e.,
it does not take any child (and descendant) groups into
account. With the two features, virsh dominfo which just
checks memory usage of a cgroup for domain always returns
zero because the cgroup has no process.

Setting memory.use_hierarchy of a group allows to account
(and limit) memory usage of every descendant groups of the group.
By setting it of a cgroup for domain, we can get proper memory
usage of lxc with ns subsystem enabled. (To be exact, the
setting is required only when memory and ns subsystems are
enabled at the same time, e.g., mount -t cgroup none /cgroup.)
2010-06-23 14:31:38 -06:00
Ryota Ozaki
842b51ff5d cgroup: Change virCgroupRemove to remove all descendant groups at first
As same as normal directories, a cgroup cannot be removed if it
contains sub groups. This patch changes virCgroupRemove to remove
all descendant groups (subdirectories) of a target group before
removing the target group.

The handling is required when we run lxc with ns subsystem of cgroup.
Ns subsystem automatically creates child cgroups on every process
forks, but unfortunately the groups are not removed on process exits,
so we have to remove them by ourselves.

With this patch, such child (and descendant) groups are surely removed
at lxc shutdown, i.e., lxcVmCleanup which calls virCgroupRemove.
2010-06-23 14:30:19 -06:00
Jim Meyering
2d3208029b maint: mark translatable string args of VIR_ERROR
Run this:
  git grep -l 'VIR_ERROR\s*("'|xargs perl -pi -e \
    's/(VIR_ERROR)\s*\((".*?"),/$1(_($2),/'
2010-05-20 21:36:25 +02:00
Jim Meyering
8d63d82e5c maint: mark translatable string args of VIR_ERROR0
Run this:
  git grep -l 'VIR_ERROR0\s*("'|xargs perl -pi -e \
    's/(VIR_ERROR0)\s*\((".*?")\)/$1(_($2))/'
2010-05-20 21:36:25 +02:00
Ryota Ozaki
c4157e5272 cgroup: Fix possible memory leak in virCgroupMakeGroup
* src/util/cgroup.c: free temporal path string before breaking loop
2010-05-03 15:01:12 -06:00
Matthias Bolte
40648b156b cygwin: Check explicitly for getmntent_r
Cygwin has mntent.h but lacks getmntent_r. Update preprocessor
checks to catch this combination.
2010-04-23 20:15:53 +02:00
Matthias Bolte
73b45bfbff cgroup: Replace sscanf with virStrToLong_ll
The switch from %lli to %lld in virCgroupGetValueI64 is intended,
as virCgroupGetValueU64 uses base 10 too, and virCgroupSetValueI64
uses %lld to format the number to string.

Parsing is stricter now and doesn't accept trailing characters
after the actual value anymore.
2010-04-01 12:53:41 +02:00
Jim Fehlig
09fafa1e21 Avoid libvirtd crash when cgroups is not configured on host
Invoking virDomainSetMemory() on lxc driver results in libvirtd
segfault when cgroups has not been configured on the host.

Ensure driver->cgroup is non-null before invoking
virCgroupForDomain().  To prevent similar segfaults in the future,
ensure driver parameter to virCgroupForDomain() is non-null before
dereferencing.
2010-03-22 09:42:14 -06:00
Eric Blake
36d8e7d8d7 build: consistently indent preprocessor directives
* global: patch created by running:
for f in $(git ls-files '*.[ch]') ; do
    cppi $f > $f.t && mv $f.t $f
done
2010-03-09 19:22:28 +01:00
Daniel P. Berrange
ede3bc1128 Avoid creating top level cgroups if just querying for existance
When getting the driver/domain cgroup it is possible to specify
whether it should be auto created. If auto-creation was turned
off, libvirt still mistakenly created its own top level cgroup

* src/util/cgroup.c: Honour autocreate flag for top level cgroup
2010-03-05 15:00:58 +00:00
Matthias Bolte
f972dc2d5c Remove conn parameter from util functions
It was used for error reporting only.
2010-02-09 01:04:54 +01:00
Jim Meyering
fd10c4e1ee cgroup.c: don't leak mem+FD upon OOM
* src/util/cgroup.c (virCgroupDetectPlacement): Close the mapping
FILE* also upon error.
2010-02-04 20:00:07 +01:00
Jim Meyering
a16a96942d cgroup.c: avoid unconditional leaks
* src/util/cgroup.c (virCgroupCpuSetInherit) [HAVE_MNTENT_H]:
Don't leak CPU-set inheritance value strings.
2010-02-04 20:00:07 +01:00
Daniel P. Berrange
d11d93f406 Fix check for existance of cgroups at creation
In the scenario where the cgroups were mounted but the
particular group did not exist, and the caller had not
requested auto-creation, the code would fail to return
an error condition. This caused the lxc_controller to
think the cgroup existed, and it then later failed when
attempting to use it

* src/util/cgroup.c: Raise an error if the cgroup path does not
  exist
2009-11-13 11:50:12 +00:00
Ryota Ozaki
41fa653f32 LXC fix virCgroupGetValueStr problem with \n
A cgroup file returns integer value terminated with '\n' and remaining
it has sometimes harmful effects, for example it leads virStrToLong_ull
to fail.
* src/util/cgroup.c: strip out terminating \n when reading a value
2009-10-19 14:29:42 +02:00
Cole Robinson
f5c65fa192 cgroup: Fix -Werror breakage 2009-10-08 10:26:42 -04:00
Daniel P. Berrange
7b1fe89a5c Misc win32 build fixes
* daemon/Makefile.am: Fix missing sasl rule
* src/datatypes.c: Add unistd.h to avoid gnulib bug
* src/util/cgroup.c: Disable mntent if not available
2009-10-08 11:56:06 +01:00
Ryota Ozaki
3a05dc09ec LXC implement memory control APIs
The patch implements the missing memory control APIs for lxc, i.e.,
domainGetMaxMemory, domainSetMaxMemory, domainSetMemory, and improves
domainGetInfo to return proper amount of used memory via cgroup.

* src/libvirt_private.syms: Export virCgroupGetMemoryUsage
  and add missing virCgroupSetMemory
* src/lxc/lxc_driver.c: Implement missing memory functions
* src/util/cgroup.c, src/util/cgroup.h: Add the function
  to get used memory
2009-10-07 15:26:23 +02:00
Ryota Ozaki
c8c9ef2757 lxc: suspend/resume support
* src/conf/domain_conf.c: Don't assume all virDomainObjPtr have
  a non-NULL monitor_chr field in virDomainObjFormat.
* src/lxc/lxc_driver.c: Implement suspend/resume driver APis
* src/util/cgroup.c, src/util/cgroup.h: Support the 'freezer'
  cgroup controller
* src/libvirt_private.syms: Export virCgroupSetFreezerState
  and virCgroupGetFreezerState
2009-09-22 11:30:06 +01:00
Daniel P. Berrange
1355e0552e Move all shared utility files to src/util/
* src/bridge.c, src/bridge.h, src/buf.c, src/buf.h, src/cgroup.c,
  src/cgroup.h, src/conf.c, src/conf.h, src/event.c, src/event.h,
  src/hash.c, src/hash.h, src/hostusb.c, src/hostusb.h,
  src/iptables.c, src/iptables.h, src/logging.c, src/logging.h,
  src/memory.c, src/memory.h, src/pci.c, src/pci.h, src/qparams.c,
  src/qparams.h, src/stats_linux.c, src/stats_linux.h,
  src/threads-pthread.c, src/threads-pthread.h, src/threads-win32.c,
  src/threads-win32.h, src/threads.c, src/threads.h, src/util.c,
  src/util.h, src/uuid.c, src/uuid.h, src/virterror.c,
  src/virterror_internal.h, src/xml.c, src/xml.h: Move all files
  into src/util/
* daemon/Makefile.am: Add -Isrc/util/ to build flags
* src/Makefile.am: Add -Isrc/util/ to build flags and update for
  moved files
* src/libvirt_private.syms: Export cgroup APIs since they're now
  in util rather than linking directly to drivers
* src/xen/xs_internal.c: Disable bogus virEventRemoveHandle call
  when built under PROXY
* proxy/Makefile.am: Update for changed file locations. Remove
  bogus build of event.c
* tools/Makefile.am, tests/Makefile.am: Add -Isrc/util/ to build flags
2009-09-21 14:41:47 +01:00