]> git.proxmox.com Git - mirror_lxcfs.git/log
mirror_lxcfs.git
6 years agobindings: record mount namespace
Christian Brauner [Thu, 2 Nov 2017 12:26:36 +0000 (13:26 +0100)]
bindings: record mount namespace

This will allows us to attach to the mount namespace in case we need to debug or
perform some action on update.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #220 from yuwang888/master
Serge Hallyn [Sat, 21 Oct 2017 17:02:46 +0000 (13:02 -0400)]
Merge pull request #220 from yuwang888/master

Fix wrong calc of swaptoal and swapfree

6 years agoFix wrong calc of swaptoal and swapfree
yuwang.yuwang [Fri, 20 Oct 2017 06:28:03 +0000 (14:28 +0800)]
Fix wrong calc of swaptoal and swapfree

it make the value of (memswlimit - memlimit) to be swaptotal,
it is wrong, because swapsize in cgroup/container can up to
[0,memswlimit], sometimes if the memsize(unless swap) of all tasks in
cgroup/container is very small, the swaptoal can to be memswlimit
so make the swaptotal to be min(host swtoal,memswlimit)

Signed-off-by: yuwang.yuwang <yuwang.yuwang@alibaba-inc.com>
6 years agoMerge pull request #216 from nagarathnam200/master
Serge Hallyn [Mon, 2 Oct 2017 19:06:10 +0000 (14:06 -0500)]
Merge pull request #216 from nagarathnam200/master

Fix the installation directory for liblxcfs to ${libdir}/lxcfs

6 years agoFix the installation directory for liblxcfs to ${libdir}/lxcfs
Nagarathnam Muthusamy [Tue, 26 Sep 2017 00:32:09 +0000 (17:32 -0700)]
Fix the installation directory for liblxcfs to ${libdir}/lxcfs

Signed-off-by: Nagarathnam Muthusamy <nagarathnam.muthusamy@oracle.com>
6 years agoMerge pull request #211 from cyphar/pam_cgfs-all-option
Christian Brauner [Fri, 15 Sep 2017 01:35:29 +0000 (18:35 -0700)]
Merge pull request #211 from cyphar/pam_cgfs-all-option

pam_cgfs: add an 'all' option for -c

6 years agopam_cgfs: add an 'all' option for -c
Aleksa Sarai [Fri, 15 Sep 2017 01:05:40 +0000 (11:05 +1000)]
pam_cgfs: add an 'all' option for -c

In order to not require a user to manually list all cgroup controllers
in their PAM configuration, add an "all" option that effectively just
sets all controllers as read-write.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
6 years agoMerge pull request #205 from bmiklautz/uptime_read
Christian Brauner [Thu, 3 Aug 2017 13:01:33 +0000 (09:01 -0400)]
Merge pull request #205 from bmiklautz/uptime_read

uptime: fix a problem with subsequent reads.

6 years agouptime: fix a problem with subsequent reads.
Bernhard Miklautz [Thu, 3 Aug 2017 11:37:37 +0000 (13:37 +0200)]
uptime: fix a problem with subsequent reads.

When doing subsequent reads of uptime on an open file handle
in the form:

read
lseek 0L, SEEK_SET
read

the second (and later) reads cause that the error
"failed to write to cache" was printed. This
happens for example with "top". top would print the error:

bad data in /proc/uptime

To fix this problem use the whole size of the buffer instead of the d->size
because this is set on the first read.

This behavior was introduced with commit 0ecddf023a4caf8e8d2fe7e9125d777a06c5ec12.

Signed-off-by: Bernhard Miklautz <bernhard.miklautz@shacknet.at>
6 years agoMerge pull request #198 from elianka/elianka-dev
Serge Hallyn [Tue, 4 Jul 2017 15:46:54 +0000 (10:46 -0500)]
Merge pull request #198 from elianka/elianka-dev

add common fallback dlopen for liblxcfs.so

6 years agoadd common fallback dlopen for liblxcfs.so
Daniel Kang [Sat, 1 Jul 2017 16:23:44 +0000 (00:23 +0800)]
add common fallback dlopen for liblxcfs.so

Signed-off-by: Daniel Kang <kangliang424@gmail.com>
6 years agoMerge pull request #196 from elianka/elianka-dev
Christian Brauner [Wed, 28 Jun 2017 11:55:59 +0000 (13:55 +0200)]
Merge pull request #196 from elianka/elianka-dev

enable debug option

6 years agoenable debug option
Daniel Kang [Wed, 28 Jun 2017 11:40:50 +0000 (19:40 +0800)]
enable debug option

Signed-off-by: Daniel Kang <kangliang424@gmail.com>
6 years agoMerge pull request #195 from evgeni/should-start-after-cgroupfs-mount
Christian Brauner [Thu, 22 Jun 2017 09:35:52 +0000 (11:35 +0200)]
Merge pull request #195 from evgeni/should-start-after-cgroupfs-mount

add cgroupfs-mount to Should-Start/Stop sysvinit LSB headers

6 years agoadd cgroupfs-mount to Should-Start/Stop sysvinit LSB headers
Evgeni Golov [Thu, 22 Jun 2017 06:22:07 +0000 (08:22 +0200)]
add cgroupfs-mount to Should-Start/Stop sysvinit LSB headers

otherwise init might try to start lxcfs before cgroupfs was mounted,
which will result in an empty /var/lib/lxcfs/cgroup and weird issues.

Debian-Bug: https://bugs.debian.org/859219
Signed-off-by: Evgeni Golov <evgeni@debian.org>
6 years agoMerge pull request #194 from brauner/2017-06-19/update_readme
Stéphane Graber [Mon, 19 Jun 2017 16:25:18 +0000 (12:25 -0400)]
Merge pull request #194 from brauner/2017-06-19/update_readme

README: update

6 years agoREADME: update
Christian Brauner [Mon, 19 Jun 2017 08:29:34 +0000 (10:29 +0200)]
README: update

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #192 from hallyn/revert-btime
Christian Brauner [Sun, 18 Jun 2017 20:53:10 +0000 (22:53 +0200)]
Merge pull request #192 from hallyn/revert-btime

(temporarily?) revert the virtualization of btime field in /proc/stat

6 years ago(temporarily?) revert the virtualization of btime field in /proc/stat
Serge Hallyn [Sun, 18 Jun 2017 19:43:22 +0000 (14:43 -0500)]
(temporarily?) revert the virtualization of btime field in /proc/stat

Closes #189

This seems to be responsible for corrupting STIME on processlist
inside containers.  Hopefully we can find a reasonable way to fix
both, but compared to unvirtualized btime field, bogus STIME field
is the greater evil here.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
6 years agoMerge pull request #190 from brauner/2017-06-12/bugfixes
Stéphane Graber [Mon, 12 Jun 2017 17:08:51 +0000 (13:08 -0400)]
Merge pull request #190 from brauner/2017-06-12/bugfixes

bugfixes

6 years agotests: fix invalid comparison
Christian Brauner [Mon, 12 Jun 2017 13:47:13 +0000 (15:47 +0200)]
tests: fix invalid comparison

We now follow the host's /proc/uptime in that we report two digits after the dot
too. Adapt the tests too.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agobindings: calculate btime correctly
Christian Brauner [Mon, 12 Jun 2017 12:45:44 +0000 (14:45 +0200)]
bindings: calculate btime correctly

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #186 from brauner/2017-05-22/user_starttime_for_uptime
Serge Hallyn [Fri, 26 May 2017 16:17:29 +0000 (11:17 -0500)]
Merge pull request #186 from brauner/2017-05-22/user_starttime_for_uptime

bindings: calculate uptime via proc/<pid>/stat

6 years agobindings: calculate uptime via proc/<pid>/stat
Christian Brauner [Fri, 26 May 2017 03:06:30 +0000 (05:06 +0200)]
bindings: calculate uptime via proc/<pid>/stat

Closes #165.
Closes #184.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #182 from brauner/2017-05-16/pam_cgv2_improvements
Serge Hallyn [Thu, 18 May 2017 21:46:27 +0000 (16:46 -0500)]
Merge pull request #182 from brauner/2017-05-16/pam_cgv2_improvements

pam: bugfixes

6 years agopam: chown cgroup.procs file on unified hierarchy
Christian Brauner [Mon, 15 May 2017 23:08:10 +0000 (01:08 +0200)]
pam: chown cgroup.procs file on unified hierarchy

On the unified hierarchy cgroup.procs must be owned by the user in order for him
to be able to move processes into other cgroups.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #183 from brauner/2017-05-17/add_unified_mount
Serge Hallyn [Wed, 17 May 2017 19:02:15 +0000 (14:02 -0500)]
Merge pull request #183 from brauner/2017-05-17/add_unified_mount

bindings: add mountpoint for unified hierarchy

6 years agobindings: add mountpoint for unified hierarchy
Christian Brauner [Wed, 17 May 2017 10:11:20 +0000 (12:11 +0200)]
bindings: add mountpoint for unified hierarchy

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agopam: report back we found the unified hierarchy
Christian Brauner [Mon, 15 May 2017 23:06:59 +0000 (01:06 +0200)]
pam: report back we found the unified hierarchy

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agopam: non-functional changes
Christian Brauner [Mon, 15 May 2017 23:06:24 +0000 (01:06 +0200)]
pam: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agoMerge pull request #179 from brauner/2017-03-11/bugfixes
Serge Hallyn [Sun, 12 Mar 2017 02:42:07 +0000 (20:42 -0600)]
Merge pull request #179 from brauner/2017-03-11/bugfixes

{pam_cgfs, bindings}: bugfixes

7 years agobindings: increase reserved buffer size a little
Christian Brauner [Sat, 11 Mar 2017 16:19:12 +0000 (17:19 +0100)]
bindings: increase reserved buffer size a little

So far, only proc_stat_read() is fully using BUF_RESERVE_SIZE so it doesn't
actually benefit from the additional memory assigned to it like all the other
files in proc do. So double the size and have proc_stat_read() only use half of
it.

Supposedly fixes #176.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agobindings: implement guest nice
Christian Brauner [Sat, 11 Mar 2017 13:51:58 +0000 (14:51 +0100)]
bindings: implement guest nice

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agopam_cgfs: remove dead assignment
Christian Brauner [Sat, 11 Mar 2017 13:04:47 +0000 (14:04 +0100)]
pam_cgfs: remove dead assignment

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agopam_cgfs: error out on failure in cgv2_init()
Christian Brauner [Sat, 11 Mar 2017 12:58:10 +0000 (13:58 +0100)]
pam_cgfs: error out on failure in cgv2_init()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agoMerge pull request #178 from brauner/2017-03-03/fix_trim
Serge Hallyn [Fri, 3 Mar 2017 00:16:04 +0000 (18:16 -0600)]
Merge pull request #178 from brauner/2017-03-03/fix_trim

pam_cgfs: make trim() safer

7 years agopam_cgfs: make trim() safer
Christian Brauner [Thu, 2 Mar 2017 23:35:07 +0000 (00:35 +0100)]
pam_cgfs: make trim() safer

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agoMerge pull request #174 from brauner/2017-02-09/bugfixes
Serge Hallyn [Thu, 9 Feb 2017 21:03:38 +0000 (15:03 -0600)]
Merge pull request #174 from brauner/2017-02-09/bugfixes

2017 02 09/bugfixes

7 years agobindings: Want space for ints? Call sizeof(int)!
Christian Brauner [Thu, 9 Feb 2017 10:49:04 +0000 (11:49 +0100)]
bindings: Want space for ints? Call sizeof(int)!

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agopam_cgfs: make sure that **p is not NULL
Christian Brauner [Thu, 9 Feb 2017 10:36:47 +0000 (11:36 +0100)]
pam_cgfs: make sure that **p is not NULL

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agopam_cgfs: return created directly
Christian Brauner [Thu, 9 Feb 2017 10:25:30 +0000 (11:25 +0100)]
pam_cgfs: return created directly

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agopam_cgfs: remove dead assignment
Christian Brauner [Thu, 9 Feb 2017 10:22:50 +0000 (11:22 +0100)]
pam_cgfs: remove dead assignment

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 years agoMerge pull request #169 from almostivan/btime
Serge Hallyn [Fri, 3 Feb 2017 06:00:12 +0000 (00:00 -0600)]
Merge pull request #169 from almostivan/btime

virtualize the 'btime' field of /proc/stat

7 years agoMerge pull request #172 from Blub/queue
Serge Hallyn [Thu, 2 Feb 2017 16:21:08 +0000 (10:21 -0600)]
Merge pull request #172 from Blub/queue

Limit memswlimit by TotalSwap

7 years agoMerge pull request #171 from Blub/trivial/false-vs-NULL
Serge Hallyn [Thu, 2 Feb 2017 16:16:38 +0000 (10:16 -0600)]
Merge pull request #171 from Blub/trivial/false-vs-NULL

cleanup: return false instead of NULL as bool

7 years agoLimit memswlimit by TotalSwap
Wolfgang Bumiller [Thu, 2 Feb 2017 08:36:46 +0000 (09:36 +0100)]
Limit memswlimit by TotalSwap

We do this for the memlimit when hitting MemTotal which
means if neither is limited we end up subtracting the
hosts's total memory from the 'unlimited' swap value in the
SwapTotal and SwapFree lines.

Fixes #170

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
7 years agocleanup: return false instead of NULL as bool
Wolfgang Bumiller [Wed, 1 Feb 2017 14:19:24 +0000 (15:19 +0100)]
cleanup: return false instead of NULL as bool

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
7 years agovirtualize the 'btime' field of /proc/stat
Jason Baron [Fri, 27 Jan 2017 21:57:54 +0000 (16:57 -0500)]
virtualize the 'btime' field of /proc/stat

Currently, the 'btime' of /proc/stat reflects the boot time of the host.
We would like it to reflect when the guest boots, so use the start time of
init.

Signed-off-by: Jason Baron <jbaron@akamai.com>
7 years agoMerge pull request #168 from Xeno22/master
Stéphane Graber [Fri, 27 Jan 2017 21:49:40 +0000 (16:49 -0500)]
Merge pull request #168 from Xeno22/master

Also check next variable for NULL on cg_rmdir

7 years agoAlso check next variable for NULL on cg_rmdir
Xeno [Fri, 27 Jan 2017 18:06:39 +0000 (19:06 +0100)]
Also check next variable for NULL on cg_rmdir

Signed-off-by: Martin Zwickel <martin.zwickel@googlemail.com>
7 years agoMerge pull request #166 from stgraber/master
Serge Hallyn [Wed, 25 Jan 2017 03:22:21 +0000 (21:22 -0600)]
Merge pull request #166 from stgraber/master

Remove unused variable

7 years agoRemove unused variable
Stéphane Graber [Wed, 25 Jan 2017 03:15:11 +0000 (22:15 -0500)]
Remove unused variable

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
7 years agoMerge pull request #162 from Fabian-Gruenbichler/swapfix
Serge Hallyn [Sat, 31 Dec 2016 23:19:54 +0000 (17:19 -0600)]
Merge pull request #162 from Fabian-Gruenbichler/swapfix

fix swap values with nested cgroups

7 years agofix swap values with nested cgroups
Fabian Grünbichler [Thu, 22 Dec 2016 12:12:04 +0000 (13:12 +0100)]
fix swap values with nested cgroups

the memory limit was already correctly set by looking at the
whole cgroup hierarchy and using the minimum value, refactor
that code to support arbitrary files in the memory cgroup
and reuse it for the memsw limit as well.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
7 years agoMerge pull request #161 from stgraber/master
Serge Hallyn [Sat, 3 Dec 2016 00:54:19 +0000 (18:54 -0600)]
Merge pull request #161 from stgraber/master

tests: Fix run on ppc64el

7 years agotests: Fix run on ppc64el
Stéphane Graber [Sat, 3 Dec 2016 00:45:18 +0000 (19:45 -0500)]
tests: Fix run on ppc64el

Turns out a MB of memory isn't quite enough to run things like cat on
some architectures, so lets bump to a more comfortable 64MB.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
7 years agoMerge pull request #147 from albatross0/fix_scanning_of_memstat
Serge Hallyn [Wed, 23 Nov 2016 19:37:10 +0000 (13:37 -0600)]
Merge pull request #147 from albatross0/fix_scanning_of_memstat

Fix wrong scanning of memory.stat

7 years agoMerge pull request #160 from brauner/2016-11-21/cgfsng_improve_isolcpus_handling
Serge Hallyn [Tue, 22 Nov 2016 01:05:40 +0000 (19:05 -0600)]
Merge pull request #160 from brauner/2016-11-21/cgfsng_improve_isolcpus_handling

cgfsng improve isolcpus handling

7 years agocgroups: handle non-existent isolcpus file
Christian Brauner [Tue, 22 Nov 2016 00:20:01 +0000 (01:20 +0100)]
cgroups: handle non-existent isolcpus file

If the file "/sys/devices/system/cpu/isolated" doesn't exist, we can't just
simply bail. We still need to check whether we need to copy the parents cpu
settings.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agopam_cgfs: improve cg_filter_and_set_cpus()
Christian Brauner [Tue, 22 Nov 2016 00:18:41 +0000 (01:18 +0100)]
pam_cgfs: improve cg_filter_and_set_cpus()

- add debugg logging
- simplify logic

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agoMerge pull request #159 from brauner/2016-11-19/pam_cgfs_handle_cpuset_v1
Serge Hallyn [Mon, 21 Nov 2016 16:05:47 +0000 (10:05 -0600)]
Merge pull request #159 from brauner/2016-11-19/pam_cgfs_handle_cpuset_v1

pam_cgfs: handle cgroupfs v1 cpuset controller

7 years agopam_cgfs: bugfixes
Christian Brauner [Mon, 21 Nov 2016 15:47:59 +0000 (16:47 +0100)]
pam_cgfs: bugfixes

- add missing free()s
- simplify logic
- add a comment to point out that most helpers stem from LXC

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agopam_cgfs: improve logging
Christian Brauner [Sat, 19 Nov 2016 14:38:55 +0000 (15:38 +0100)]
pam_cgfs: improve logging

- remove GNU specific %m specifier
- add more lxcfs_debug() calls

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agopam_cgfs: handle cgroupfs v1 cpuset controller
Christian Brauner [Sat, 19 Nov 2016 13:38:57 +0000 (14:38 +0100)]
pam_cgfs: handle cgroupfs v1 cpuset controller

If init has not placed us into our own cgroup on login we will reside in the
root cgroup. In this case cgroup.clone_children will not have been initialized
and so we need to do it. Otherwise users will not be able to start containers
with cpuset limits set.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agoMerge pull request #156 from brauner/2016-11-11/cgroupv2_support
Serge Hallyn [Fri, 18 Nov 2016 03:37:13 +0000 (21:37 -0600)]
Merge pull request #156 from brauner/2016-11-11/cgroupv2_support

pam_cgfs: reimplement and add cgroupfs v2 support

7 years agopam_cgfs: re-use cgroups that already belong to us
Christian Brauner [Thu, 17 Nov 2016 23:18:45 +0000 (00:18 +0100)]
pam_cgfs: re-use cgroups that already belong to us

When we detect an already existing cgroup that belongs to our uid and gid, we
simply re-use it. This allows us to avoid creating useless additional cgroups
when e.g. running multiple sudo commands in a script or when we login from
different ttys.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agopam_cgfs: bugfixes
Christian Brauner [Thu, 17 Nov 2016 23:00:54 +0000 (00:00 +0100)]
pam_cgfs: bugfixes

When we are placed in a systemd user slice, do not try to re-enter the cgroup
again.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agopam_cgfs: bugfixes
Christian Brauner [Thu, 17 Nov 2016 19:32:15 +0000 (20:32 +0100)]
pam_cgfs: bugfixes

- free(basecginfo) on failure
- correct check when parsing /proc/<pid>/mountinfo
- check for NULL when retrieving init cgroup

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agopam_cgfs: reimplement and add cgroupfs v2 support
Christian Brauner [Sun, 13 Nov 2016 05:07:58 +0000 (06:07 +0100)]
pam_cgfs: reimplement and add cgroupfs v2 support

This is a rewrite of pam_cgfs which leans on LXC's cgfsng.c. Various codepaths
have been adapted and made more appropriate.

The strategy of pam_cgfs v2 is to support cgroupfs v1, cgroupfs v2, and mixed
mounts where some controllers are mounted into a standard cgroupfs v1 hierarchy
location (/sys/fs/cgroup/<controller>) and other controllers are mounted into
the cgroupfs v2 hierarchy.

The functions and types for cgroupfs v1 and cgroupfs v2 have nearly all been
kept separately even if they do nearly the exact same job. This is on purpose!
Although marked non-experimental, cgroupfs v2 is too much of a moving target.
Extrapolating from currentl cgroupfs v2 standard behaviour seems risky and error
prone. Even more so when those assumptions complexify or simplify cgroupfs v1
assumptions when trying to handle both, cgroupfs v1 and cgroupfs v2, in one
function. In short, code duplication currently is on purpose so that we can
easily adapt to changes in cgroupfs v2 behaviour without having to touch any of
the functions or types that deal with the basically standardized cgroupfs v1
behaviour.

A quick run-through of what current pam_cgfs does (The same wording can be found
in the preamble/license to pam_cgfs.c.):

When a user logs in, this pam module will create cgroups which the user may
administer. It handles both pure cgroupfs v1 and pure cgroupfs v2, as well as
mixed mounts, where some controllers are mounted in a standard cgroupfs v1
hierarchy location (/sys/fs/cgroup/<controller>) and others are in the cgroupfs
v2 hierarchy.
Writeable cgroups are either created for all controllers or, if specified, for
any controllers listed on the command line.
The cgroup created will be "user/$user/0" for the first session, "user/$user/1"
for the second, etc.

Systems with a systemd init system are treated specially, both with respect to
cgroupfs v1 and cgroupfs v2. For both, cgroupfs v1 and cgroupfs v2, we check
whether systemd already placed us in a cgroup it created, e.g.

     user.slice/user-uid.slice/session-n.scope

by checking whether uid == our uid. If it did, we simply chown the last
part (session-n.scope). If it did not we create a cgroup as outlined above
(user/$user/n) and chown it to our uid.
The same holds for cgroupfs v2 where checking this assumption becomes crucial:
If we systemd already created and placed us in a cgroups, we __have to__ be
placed our under it on login, otherwise things like starting an xserver or
similar will not work.

All requested cgroups must be mounted under /sys/fs/cgroup/$controller,
no messing around with finding mountpoints.

Note, as of now, we currently do not yet necessarily deal correctly with weird
corner cases like not mounting the name=systemd cgroupfs v1 controller at
/sys/fs/cgroup/systemd but rather mounting an empty cgroupfs v2 hierarchy at the
same location which is used by systemd to track processes. This is left for
future commits.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agomacro: add header for shared macros
Christian Brauner [Sun, 13 Nov 2016 05:06:54 +0000 (06:06 +0100)]
macro: add header for shared macros

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agoMerge pull request #153 from Fabian-Gruenbichler/memactivefix
Serge Hallyn [Thu, 20 Oct 2016 00:32:21 +0000 (19:32 -0500)]
Merge pull request #153 from Fabian-Gruenbichler/memactivefix

fix Active/Inactive /proc/meminfo

7 years agofix Active/Inactive /proc/meminfo
Fabian Grünbichler [Wed, 19 Oct 2016 07:16:36 +0000 (09:16 +0200)]
fix Active/Inactive /proc/meminfo

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
7 years agoMerge pull request #151 from brauner/2016-10-08/getattr_from_wronly_files
Serge Hallyn [Sun, 9 Oct 2016 04:25:56 +0000 (23:25 -0500)]
Merge pull request #151 from brauner/2016-10-08/getattr_from_wronly_files

bindings: remove noop check

7 years agobindings: remove noop check
Christian Brauner [Sat, 8 Oct 2016 08:15:10 +0000 (10:15 +0200)]
bindings: remove noop check

Unless the file was created with chmod 000 the current check for
!O_RDONLY && !O_WRONLY will always be successful, making the current check
basically a noop. And even in the case where a file has chmod 000 we still want
the user to see that it has no permissions. So let's remove the check entirely.
Whether a user sees a file will be determined by a prior check for O_RDONLY on
the directory anyway.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agoMerge pull request #150 from brauner/2016-10-07/getattr_from_wronly_files
Stéphane Graber [Fri, 7 Oct 2016 06:19:31 +0000 (08:19 +0200)]
Merge pull request #150 from brauner/2016-10-07/getattr_from_wronly_files

bindings: allow getattr on O_WRONLY files

7 years agobindings: allow getattr on O_WRONLY files
Christian Brauner [Thu, 6 Oct 2016 22:59:53 +0000 (00:59 +0200)]
bindings: allow getattr on O_WRONLY files

We should only deny getting the attributes of a file if it neither contains
O_RDONLY permission nor O_WRONLY permissions. Otherwise ls -al will not show
attributes on O_WRONLY files. Such files are quite common under /proc or /sys.

BEFORE:
root@conventiont:~# ls -al /var/lib/lxcfs/cgroup/devices/
ls: cannot access '/var/lib/lxcfs/cgroup/devices/devices.allow': Permission denied
ls: cannot access '/var/lib/lxcfs/cgroup/devices/devices.deny': Permission denied
total 0
drwxr-xr-x 2 root root 0 Oct  7 01:00 .
drwxr-xr-x 2 root root 0 Oct  7 01:00 ..
-rw-r--r-- 1 root root 0 Oct  7 01:00 cgroup.clone_children
-rw-r--r-- 1 root root 0 Oct  7 01:00 cgroup.procs
-r--r--r-- 1 root root 0 Oct  7 01:00 cgroup.sane_behavior
?????????? ? ?    ?    ?            ? devices.allow
?????????? ? ?    ?    ?            ? devices.deny
-r--r--r-- 1 root root 0 Oct  7 01:00 devices.list
drwxr-xr-x 2 root root 0 Oct  7 01:00 init.scope
drwxr-xr-x 2 root root 0 Oct  7 01:00 lxc
-rw-r--r-- 1 root root 0 Oct  7 01:00 notify_on_release
-rw-r--r-- 1 root root 0 Oct  7 01:00 release_agent
drwxr-xr-x 2 root root 0 Oct  7 01:00 system.slice
-rw-r--r-- 1 root root 0 Oct  7 01:00 tasks
drwxr-xr-x 2 root root 0 Oct  7 01:00 user.slice

AFTER:
root@conventiont:~# ls -al /var/lib/lxcfs/cgroup/devices/
total 0
drwxr-xr-x 2 root root 0 Oct  7 01:01 .
drwxr-xr-x 2 root root 0 Oct  7 01:01 ..
-rw-r--r-- 1 root root 0 Oct  7 01:01 cgroup.clone_children
-rw-r--r-- 1 root root 0 Oct  7 01:01 cgroup.procs
-r--r--r-- 1 root root 0 Oct  7 01:01 cgroup.sane_behavior
--w------- 1 root root 0 Oct  7 01:01 devices.allow
--w------- 1 root root 0 Oct  7 01:01 devices.deny
-r--r--r-- 1 root root 0 Oct  7 01:01 devices.list
drwxr-xr-x 2 root root 0 Oct  7 01:01 init.scope
drwxr-xr-x 2 root root 0 Oct  7 01:01 lxc
-rw-r--r-- 1 root root 0 Oct  7 01:01 notify_on_release
-rw-r--r-- 1 root root 0 Oct  7 01:01 release_agent
drwxr-xr-x 2 root root 0 Oct  7 01:01 system.slice
-rw-r--r-- 1 root root 0 Oct  7 01:01 tasks
drwxr-xr-x 2 root root 0 Oct  7 01:01 user.slice

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
7 years agoAdd Documentation key to systemd unit
Stéphane Graber [Wed, 5 Oct 2016 12:39:45 +0000 (14:39 +0200)]
Add Documentation key to systemd unit

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
7 years agoFix wrong scanning of memory.stat
albatross0 [Thu, 29 Sep 2016 11:23:27 +0000 (20:23 +0900)]
Fix wrong scanning of memory.stat

Signed-off-by: KUWAZAWA Takuya <albatross0@gmail.com>
7 years agoMerge pull request #145 from brauner/2016-09-04/lxcfs_on_ramfs
Serge Hallyn [Tue, 6 Sep 2016 14:59:18 +0000 (09:59 -0500)]
Merge pull request #145 from brauner/2016-09-04/lxcfs_on_ramfs

lxcfs on ramfs

7 years agobindings: make pivot_enter() contain all its code
Christian Brauner [Mon, 5 Sep 2016 14:13:12 +0000 (16:13 +0200)]
bindings: make pivot_enter() contain all its code

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
7 years agobindings: fix type weirdness with statfs f_type
Christian Brauner [Sun, 4 Sep 2016 16:49:23 +0000 (18:49 +0200)]
bindings: fix type weirdness with statfs f_type

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
7 years agobindings: use chroot() on ramfs
Christian Brauner [Sun, 4 Sep 2016 16:07:01 +0000 (18:07 +0200)]
bindings: use chroot() on ramfs

- Detect whether we are on a ramfs. We first try via statfs and check for
  RAMFS_MAGIC. This may report TMPFS_MAGIC although it should better report
  RAMFS_MAGIC. In this case, parse /proc/self/mountinfo and check for
        - rootfs rootfs
  like we do in LXC.
- When we are on ramfs use chroot(), otherwise use pivot_root().

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
7 years agobindings: agnostic naming
Christian Brauner [Sun, 4 Sep 2016 15:42:22 +0000 (17:42 +0200)]
bindings: agnostic naming

- non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
7 years agobindings: add function to check fs type
Christian Brauner [Sun, 4 Sep 2016 15:33:09 +0000 (17:33 +0200)]
bindings: add function to check fs type

We use statfs directly because statvfs proved unreliable in my testing. It's
f_fsid field does not seem to work correctly with linux/magic.h macros.

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
7 years agoMerge pull request #140 from brauner/2016-08-30/add_avoid_version
Serge Hallyn [Wed, 31 Aug 2016 14:03:53 +0000 (09:03 -0500)]
Merge pull request #140 from brauner/2016-08-30/add_avoid_version

autotools: add -avoid-version

7 years agoMerge pull request #141 from brauner/2016-08-31/restore_cwd
Serge Hallyn [Wed, 31 Aug 2016 03:36:14 +0000 (22:36 -0500)]
Merge pull request #141 from brauner/2016-08-31/restore_cwd

bindings: restore original working directory

7 years agobindings: restore original working directory
Christian Brauner [Wed, 31 Aug 2016 00:20:09 +0000 (02:20 +0200)]
bindings: restore original working directory

Signed-off-by: Christian Brauner <cbrauner@suse.de>
7 years agoautotools: add -avoid-version
Christian Brauner [Tue, 30 Aug 2016 20:54:30 +0000 (22:54 +0200)]
autotools: add -avoid-version

Signed-off-by: Christian Brauner <cbrauner@suse.de>
7 years agoMerge pull request #139 from brauner/2016-08-30/fix_debug_macros
Serge Hallyn [Tue, 30 Aug 2016 19:21:25 +0000 (14:21 -0500)]
Merge pull request #139 from brauner/2016-08-30/fix_debug_macros

bindings: fix debug macro

7 years agobindings: fix debug macro
Christian Brauner [Tue, 30 Aug 2016 08:26:44 +0000 (10:26 +0200)]
bindings: fix debug macro

Signed-off-by: Christian Brauner <cbrauner@suse.de>
7 years agoMerge pull request #138 from brauner/2016-08-29/libtool_module
Serge Hallyn [Mon, 29 Aug 2016 18:45:24 +0000 (13:45 -0500)]
Merge pull request #138 from brauner/2016-08-29/libtool_module

2016 08 29/libtool module

7 years agobindings, lxcfs: improve debugging
Christian Brauner [Mon, 29 Aug 2016 08:33:49 +0000 (10:33 +0200)]
bindings, lxcfs: improve debugging

Signed-off-by: Christian Brauner <cbrauner@suse.de>
7 years agolibtool: do not link lxcfs against liblxcfs
Christian Brauner [Mon, 29 Aug 2016 08:12:27 +0000 (10:12 +0200)]
libtool: do not link lxcfs against liblxcfs

Make liblxcfs a libtool module. Also, stop linking lxcfs against liblxcfs. We do
not really need this since we call dlopen() anyway. Furthermore, this allows us
to make sure that functions marked with __attribute__(constructor) are not run
before we call dlopen() in main() in lxcfs. This has the advantage that we can
show help output without __attribute__(constructor) functions being run.

Signed-off-by: Christian Brauner <cbrauner@suse.de>
7 years agoMerge pull request #136 from brauner/2016-08-21/bugfixes
Serge Hallyn [Fri, 26 Aug 2016 14:49:07 +0000 (10:49 -0400)]
Merge pull request #136 from brauner/2016-08-21/bugfixes

bindings: revert cgroup check and improve fs behavior

7 years agobindings: make rmdir behave more consistently
Christian Brauner [Fri, 26 Aug 2016 14:26:27 +0000 (16:26 +0200)]
bindings: make rmdir behave more consistently

We should be able to safely return -EPERM for:

  if (!pick_controller_from_path())
                /* Someone's trying to delete "/cgroup". */

  if (!find_cgroup_in_path())
          /* Someone's trying to delete a controller e.g. "/blkio". */

  if (!get_cgdir_and_path()) {
  /* Someone's trying to delete a cgroup on the same level as the
   * "/lxc" cgroup e.g. rmdir "/cgroup/blkio/lxc" or
   * rmdir "/cgroup/blkio/init.slice".
   */
  }

All other interesting cases are caught further down.

Signed-off-by: Christian Brauner <cbrauner@suse.de>
7 years agobindings: improve returned errnos
Christian Brauner [Fri, 26 Aug 2016 08:32:32 +0000 (10:32 +0200)]
bindings: improve returned errnos

Signed-off-by: Christian Brauner <cbrauner@suse.de>
7 years agobindings: revert cgroup check
Christian Brauner [Thu, 25 Aug 2016 20:33:07 +0000 (22:33 +0200)]
bindings: revert cgroup check

We do not need to check whether mode & W_OK is passed in. Even if the cgroup
root mount is writeable operations like cg_mkdir() et al. will fail with e.g.
EPERM. Basically all operations will fail on the cgroup root mount point because
the first operation they perform is pick_controller_from_path(). That is to say
they try to e.g. pick "blkio" from /var/lib/lxcfs/cgroup/blkio/some/cgroups an
similiar for all other controllers. If pick_controller_from_path() fails they
all return an appropriate errno. For example, cg_mkdir() does:

        controller = pick_controller_from_path(fc, path);
        if (!controller)
                return errno == ENOENT ? -EPERM : -errno;

This means, we do not need to return an errno already in cg_access when
mode & W_OK is passed in. This has the advantage that users are still able to
descend into /var/lib/lxcfs/cgroup via:

        cd /var/lib/lxcfs/cgroup

but are still blocked from doing any write operations.

Signed-off-by: Christian Brauner <cbrauner@suse.de>
7 years agoMerge pull request #134 from evgeni/no-argv0-in-usage
Serge Hallyn [Fri, 26 Aug 2016 10:05:36 +0000 (06:05 -0400)]
Merge pull request #134 from evgeni/no-argv0-in-usage

don't use argv[0] in usage output

7 years agodon't use argv[0] in usage output
Evgeni Golov [Fri, 26 Aug 2016 07:33:09 +0000 (09:33 +0200)]
don't use argv[0] in usage output

otherwise this generates "funny" manpages like
  /home/remote/egolov/Devel/lxcfs/.libs/lt-lxcfs [-p pidfile] mountpoint
  /home/remote/egolov/Devel/lxcfs/.libs/lt-lxcfs -h
or
  /build/lxcfs-8lNGve/lxcfs-2.0/.1/.libs/lt-lxcfs [-p pidfile] mountpoint
  /build/lxcfs-8lNGve/lxcfs-2.0/.1/.libs/lt-lxcfs -h

Signed-off-by: Evgeni Golov <evgeni@debian.org>
7 years agoMerge pull request #127 from brauner/2016-08-21/bugfixes
Serge Hallyn [Fri, 26 Aug 2016 07:11:06 +0000 (03:11 -0400)]
Merge pull request #127 from brauner/2016-08-21/bugfixes

2016 08 21/bugfixes