[lxc-devel] [lxc/lxc] dfc0b3: attach: simplify lsm_openat()

GitHub noreply at github.com
Thu Dec 1 04:55:01 UTC 2016


  Branch: refs/heads/stable-2.0
  Home:   https://github.com/lxc/lxc
  Commit: dfc0b35fe373f76cfb2aa717ff0cf276d0d5c6cb
      https://github.com/lxc/lxc/commit/dfc0b35fe373f76cfb2aa717ff0cf276d0d5c6cb
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/attach.c

  Log Message:
  -----------
  attach: simplify lsm_openat()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 5b3214cabc793a51d9cdb0232a699c1530758f5e
      https://github.com/lxc/lxc/commit/5b3214cabc793a51d9cdb0232a699c1530758f5e
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/log.c

  Log Message:
  -----------
  log: use thread-safe localtime_r()

This fixes a race in liblxc logging which can lead to deadlocks. The reproducer
for this issue before this is to simply compile with --enable-tests and then
run:

    lxc-test-concurrent -j 20 -m create,start,stop,destroy -D

which should deadlock.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 31db998489b66029845d3dd5db92147702382a47
      https://github.com/lxc/lxc/commit/31db998489b66029845d3dd5db92147702382a47
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M configure.ac
    M src/lxc/log.c

  Log Message:
  -----------
  configure: check whether gettid() is declared

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 27e0a15145b9b8756de95b4dbcf5f01ec6dd2986
      https://github.com/lxc/lxc/commit/27e0a15145b9b8756de95b4dbcf5f01ec6dd2986
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/log.c

  Log Message:
  -----------
  log: fix race

localtime_r() can lead to deadlocks because it calls __tzset() and
__tzconvert() internally. The deadlock stems from an interaction between these
functions and the functions in monitor.c and commands.{c,h}. The latter
functions will write to the log independent of the container thread that is
currently running. Since the monitor fork()ed it seems to duplicate the mutex
states of the time functions mentioned above causing the deadlock.
As a short termm fix, I suggest to simply disable receiving the time when
monitor.c or command.{c,h} functions are called. This should be ok, since the
[lxc monitor] will only emit a few messages and thread-safety is currently more
important than beautiful logs. The rest of the log stays the same as it was
before.

Here is an example output from logs where I printed the pid and tid of the
process that is currently writing to the log:
       lxc 20161125170200.619 INFO     lxc_start:   18695-18695: - start.c:lxc_check_inherited:243 - Closed inherited fd: 23.
      lxc 20161125170200.640 DEBUG    lxc_start:   18677-18677: - start.c:__lxc_start:1334 - Not dropping CAP_SYS_BOOT or watching utmp.
      lxc 20161125170200.640 INFO     lxc_cgroup:  18677-18677: - cgroups/cgroup.c:cgroup_init:68 - cgroup driver cgroupfs-ng initing for lxc-test-concurrent-0

----------> lxc 20150427012246.000 INFO     lxc_monitor: 13017-18622: - monitor.c:lxc_monitor_sock_name:178 - using monitor sock name lxc/ad055575fe28ddd5//var/lib/lxc
       lxc 20161125170200.662 DEBUG    lxc_cgfsng:  18677-18677: - cgroups/cgfsng.c:filter_and_set_cpus:478 - No isolated cpus detected.
      lxc 20161125170200.662 DEBUG    lxc_cgfsng:  18677-18677: - cgroups/cgfsng.c:handle_cpuset_hierarchy:648 - "cgroup.clone_children" was already set to "1".

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 82630da5bf617b78a841cad8df116b15845ec014
      https://github.com/lxc/lxc/commit/82630da5bf617b78a841cad8df116b15845ec014
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/log.c

  Log Message:
  -----------
  log: use N/A if getpid() != gettid() when threaded

Sample log output:

    lxc 20161125201943.819 INFO     lxc_start - start.c:lxc_check_inherited:243 - Closed inherited fd: 54.
--> lxc N/A                INFO     lxc_monitor - monitor.c:lxc_monitor_sock_name:178 - using monitor sock name lxc/ad055575fe28ddd5//var/lib/lxc
    lxc 20161125201943.958 DEBUG    lxc_commands - commands.c:lxc_cmd_handler:893 - peer has disconnected
--> lxc N/A                DEBUG    lxc_commands - commands.c:lxc_cmd_get_state:579 - 'lxc-test-concurrent-0' is in 'RUNNING' state
    lxc 20161125201943.960 DEBUG    lxc_commands - commands.c:lxc_cmd_handler:893 - peer has disconnected
    lxc 20161125201944.009 INFO     lxc_start - start.c:lxc_check_inherited:243 - Closed inherited fd: 3.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 62eeccaca2b4bdb18b123f5c33b27b9206557822
      https://github.com/lxc/lxc/commit/62eeccaca2b4bdb18b123f5c33b27b9206557822
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M configure.ac

  Log Message:
  -----------
  configure: do not allow variable length arrays

There pointless and marked as optional since C11.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: d4d6b0ce697f31a0e8c79caebdcc850148fd7949
      https://github.com/lxc/lxc/commit/d4d6b0ce697f31a0e8c79caebdcc850148fd7949
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/tools/lxc_cgroup.c
    M src/lxc/tools/lxc_unshare.c
    M src/lxc/utils.c
    M src/tests/lxc-test-utils.c

  Log Message:
  -----------
  tree-wide: remove any variable length arrays

They are pointless and marked optional since C11.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 62c990f89ceef898b33ec2cbdccce7dbf0e9fe60
      https://github.com/lxc/lxc/commit/62c990f89ceef898b33ec2cbdccce7dbf0e9fe60
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/conf.c

  Log Message:
  -----------
  conf: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 038a2174c048fd74f9edda5c7362f9df9183e88d
      https://github.com/lxc/lxc/commit/038a2174c048fd74f9edda5c7362f9df9183e88d
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M configure.ac

  Log Message:
  -----------
  configure: check for memfd_create()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 19b5201a7cd14c4f879130209768754fe410e15d
      https://github.com/lxc/lxc/commit/19b5201a7cd14c4f879130209768754fe410e15d
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/conf.c
    M src/lxc/conf.h
    M src/lxc/criu.c

  Log Message:
  -----------
  conf, criu: add make_anonymous_mount_file()

Before we used tmpfile() to write out mount entries for the container. This
requires a writeable /tmp file system which can be a problem for systems where
this filesystem is not present. This commit switches from tmpfile() to using
the memfd_create() syscall. It allows us to create an anonymous tmpfs file (And
is somewhat similar to mmap().) which is automatically deleted as soon as any
references to it are dropped. In case we detect that syscall is not
implemented, we fallback to using tmpfile().

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 4be37478bc03ef8ca65c1145f51d92d050d62496
      https://github.com/lxc/lxc/commit/4be37478bc03ef8ca65c1145f51d92d050d62496
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/monitor.c

  Log Message:
  -----------
  monitor: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 8ee3d943c3fc79185ab396c740ea305a94687616
      https://github.com/lxc/lxc/commit/8ee3d943c3fc79185ab396c740ea305a94687616
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/monitor.c

  Log Message:
  -----------
  monitor: log which pipe fd is currently used

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 1b0c6b3cea6b7bcf533b8d84f06631fba61491b0
      https://github.com/lxc/lxc/commit/1b0c6b3cea6b7bcf533b8d84f06631fba61491b0
  Author: Serge Hallyn <serge at hallyn.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/bdev/lxclvm.c

  Log Message:
  -----------
  lvm: supress warnings about leaked files

Closes #1283

Signed-off-by: Serge Hallyn <serge at hallyn.com>


  Commit: 047fbbf56cfc3db61879c72c1dfffe64f68f0399
      https://github.com/lxc/lxc/commit/047fbbf56cfc3db61879c72c1dfffe64f68f0399
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M configure.ac

  Log Message:
  -----------
  configure: remove -Werror=vla

Because we include a header that uses a vla (/me scoffs at header).

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 8a76c27097d26f4457ea8e4e7e7b724ab44e4082
      https://github.com/lxc/lxc/commit/8a76c27097d26f4457ea8e4e7e7b724ab44e4082
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/monitor.c

  Log Message:
  -----------
  monitor: add more logging

Execing lxc-monitord is quite a crucial step so let's be very obsessive about
logging possible errors to guide us in debugging.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 0ecc9191be519f5b978dc17b4c55228bf9882da8
      https://github.com/lxc/lxc/commit/0ecc9191be519f5b978dc17b4c55228bf9882da8
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/commands.c

  Log Message:
  -----------
  commands: improve logging

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 7c51e617c9bee01b8b6e73e217edd549c8dc5bab
      https://github.com/lxc/lxc/commit/7c51e617c9bee01b8b6e73e217edd549c8dc5bab
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/lxc_monitord.c

  Log Message:
  -----------
  lxc_monitord: improve log + set log level to DEBUG

Setting loglevel to DEBUG will allow us to retrieve more useful information in
case something goes wrong. The total size of the log will not increase
significantly.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 94b5d51b779a2961ae145a3117453f458972407f
      https://github.com/lxc/lxc/commit/94b5d51b779a2961ae145a3117453f458972407f
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/lxc_monitord.c

  Log Message:
  -----------
  lxc_monitord: make lxc-monitord async signal safe

Before lxc_monitord called lxc_monitord_cleanup() from a signal handler.  This
function calls a bunch of async signal unsafe functions and basically begs for
deadlocks. This commit switches lxc-monitord to using sigsetjmp() and
siglongjmp() in the signal handler to jump to a cleanup label that call
lxc_monitord_cleanup(). In this way, we avoid using async signal unsafe
functions.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: f6e8a2918e9cc551df80364b1e5cfd4ce10a4eab
      https://github.com/lxc/lxc/commit/f6e8a2918e9cc551df80364b1e5cfd4ce10a4eab
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/conf.c

  Log Message:
  -----------
  conf: remove thread-unsafe strsignal + improve log

The thread-unsafe functions strsignal() is called in run_buffer() which in turn
is called in run_buffer_argv() which is responsible for running __all__ lxc
hooks. This is pretty dangerous for multi-threaded users like LXD.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: b101fb9b7ca3c9f1b425e2eb6fe2398832f8dbd9
      https://github.com/lxc/lxc/commit/b101fb9b7ca3c9f1b425e2eb6fe2398832f8dbd9
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/lxccontainer.c

  Log Message:
  -----------
  lxccontainer: log failure to send sig to init pid

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 03fb1aaaf66aca61eb1340892d9b429dfa455030
      https://github.com/lxc/lxc/commit/03fb1aaaf66aca61eb1340892d9b429dfa455030
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/utils.h

  Log Message:
  -----------
  utils: add macro __LXC_NUMSTRLEN

This macro can be used to set or allocate a string buffer that can hold any
64bit representable number.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 624cec1cf1e69c506144c1b43a755a0b250173d0
      https://github.com/lxc/lxc/commit/624cec1cf1e69c506144c1b43a755a0b250173d0
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/log.c
    M src/lxc/log.h

  Log Message:
  -----------
  log: drop all timezone conversion functions

Our log functions need to make extra sure that they are thread-safe. We had
some problems with that before. This especially involves time-conversion
functions. I don't want to find any localtime() or gmtime() functions or
relatives in here. Not even localtime_r() or gmtime_r() or relatives. They all
fiddle with global variables and locking in various libcs. They cause deadlocks
when liblxc is used multi-threaded and no matter how smart you think you are,
you __will__ cause trouble using them.
(As a short example how this can cause trouble: LXD uses forkstart to fork off
a new process that runs the container. At the same time the go runtime LXD
relies on does its own multi-threading thing which we can't control. The
fork()ing + threading then seems to mess with the locking states in these time
functions causing deadlocks.)
The current solution is to be good old unix people and use the Epoch as our
reference point and simply use the seconds and nanoseconds that have past since
then. This relies on clock_gettime() which is explicitly marked MT-Safe with no
restrictions! This way, anyone who is really strongly invested in getting the
actual time the log entry was created, can just convert it for themselves. Our
logging is mostly done for debugging purposes so don't try to make it pretty.
Pretty might cost you thread-safety.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 2bfafb07323e6111bc8a73d8868f9ab197289ea1
      https://github.com/lxc/lxc/commit/2bfafb07323e6111bc8a73d8868f9ab197289ea1
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/log.c

  Log Message:
  -----------
  log: add lxc_unix_epoch_to_utc()

Converts a unix time Epoch given by a struct timespec to a UTC string useable
in our logging functions. Maybe expanded to allow for more generic formatting.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 1d3fef81ba303a1fa76c0a3f933d74285d6f8347
      https://github.com/lxc/lxc/commit/1d3fef81ba303a1fa76c0a3f933d74285d6f8347
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/log.c

  Log Message:
  -----------
  log: use lxc_unix_epoch_to_utc()

This allows us to generate nice timestamps in a thread-safe manner without
relying on locale touching functions from any libc.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: bb1957a5af68b71e01c357541c756a92c3224c90
      https://github.com/lxc/lxc/commit/bb1957a5af68b71e01c357541c756a92c3224c90
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/log.c

  Log Message:
  -----------
  log: annotate lxc_unix_epoch_to_utc()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 8b79a8fec4127c754509d65faae1fe7f09515365
      https://github.com/lxc/lxc/commit/8b79a8fec4127c754509d65faae1fe7f09515365
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/attach.c
    M src/lxc/bdev/bdev.c
    M src/lxc/bdev/bdev.h
    M src/lxc/cgroups/cgfsng.c
    M src/lxc/commands.h
    M src/lxc/conf.c
    M src/lxc/genl.c
    M src/lxc/log.c
    M src/lxc/monitor.c
    M src/lxc/nl.h
    M src/lxc/tools/lxc_init.c
    M src/lxc/tools/lxc_ls.c
    M src/lxc/tools/lxc_start.c
    M src/lxc/tools/lxc_stop.c
    M src/lxc/tools/lxc_usernsexec.c
    M src/lxc/utils.c
    M src/lxc/utils.h
    M src/tests/concurrent.c
    M src/tests/lxc-test-utils.c

  Log Message:
  -----------
  tree-wide: random macro cleanups

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 5267c49f0d845b1c5a2e676f7167eaeeb02728b1
      https://github.com/lxc/lxc/commit/5267c49f0d845b1c5a2e676f7167eaeeb02728b1
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/log.c

  Log Message:
  -----------
  log: make sure that date is correctly formatted

- single digit months, days, hours, minutes, and seconds should always be
  preceded by a 0.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 47378d53894dedd49744ee3a16facadbdea54723
      https://github.com/lxc/lxc/commit/47378d53894dedd49744ee3a16facadbdea54723
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/lxc_monitord.c
    M src/lxc/mainloop.c
    M src/lxc/monitor.c

  Log Message:
  -----------
  monitord: close mainloop on exit if we opened it

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: b5705aa2ffec5366ce476c64704885674ed4fa02
      https://github.com/lxc/lxc/commit/b5705aa2ffec5366ce476c64704885674ed4fa02
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/state.c

  Log Message:
  -----------
  state: use async signal safe fun in lxc_wait()

gettimeofday() is not async signal safe. So let's switch to clock_gettime() to
be on the safe side.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


  Commit: 6cd073a250a1d1a16beacaa5cb5e6512d3021482
      https://github.com/lxc/lxc/commit/6cd073a250a1d1a16beacaa5cb5e6512d3021482
  Author: Stéphane Graber <stgraber at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/log.c

  Log Message:
  -----------
  Fix log.c for stable-2.0 logging style

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>


  Commit: d686e939b58675aba80a59c2b8e931c3e92776f9
      https://github.com/lxc/lxc/commit/d686e939b58675aba80a59c2b8e931c3e92776f9
  Author: Christian Brauner <christian.brauner at ubuntu.com>
  Date:   2016-11-30 (Wed, 30 Nov 2016)

  Changed paths:
    M src/lxc/attach.c

  Log Message:
  -----------
  attach: non-functional changes

- improve logging
- simplify functions

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>


Compare: https://github.com/lxc/lxc/compare/2dbff50f0dce...d686e939b586


More information about the lxc-devel mailing list