summaryrefslogtreecommitdiffstats
path: root/src/core/cgroup.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-06-12 12:53:37 +0200
committerGitHub <noreply@github.com>2018-06-12 12:53:37 +0200
commit24d169e092b31c7f54fa49a86b8167aac4385ed3 (patch)
treef085c41ad9e41e9d1c8790e6a02f0e3c74cd98c2 /src/core/cgroup.c
parentjournal: forward messages from /dev/log unmodified to syslog.socket (diff)
parenttree-wide: use PATH_STARTSWITH_SET() at two more places (diff)
downloadsystemd-24d169e092b31c7f54fa49a86b8167aac4385ed3.tar.xz
systemd-24d169e092b31c7f54fa49a86b8167aac4385ed3.zip
Merge pull request #9255 from poettering/block-dev-fixes
some block device handling fixes
Diffstat (limited to 'src/core/cgroup.c')
-rw-r--r--src/core/cgroup.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 0da49544e6..20f0e3c18d 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -11,6 +11,7 @@
#include "alloc-util.h"
#include "blockdev-util.h"
#include "bpf-firewall.h"
+#include "btrfs-util.h"
#include "bus-error.h"
#include "cgroup-util.h"
#include "cgroup.h"
@@ -306,30 +307,36 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
}
}
-static int lookup_block_device(const char *p, dev_t *dev) {
+static int lookup_block_device(const char *p, dev_t *ret) {
struct stat st;
+ int r;
assert(p);
- assert(dev);
+ assert(ret);
if (stat(p, &st) < 0)
- return log_warning_errno(errno, "Couldn't stat device %s: %m", p);
+ return log_warning_errno(errno, "Couldn't stat device '%s': %m", p);
if (S_ISBLK(st.st_mode))
- *dev = st.st_rdev;
- else if (major(st.st_dev) != 0) {
- /* If this is not a device node then find the block
- * device this file is stored on */
- *dev = st.st_dev;
-
- /* If this is a partition, try to get the originating
- * block device */
- (void) block_get_whole_disk(*dev, dev);
- } else {
- log_warning("%s is not a block device and file system block device cannot be determined or is not local.", p);
- return -ENODEV;
+ *ret = st.st_rdev;
+ else if (major(st.st_dev) != 0)
+ *ret = st.st_dev; /* If this is not a device node then use the block device this file is stored on */
+ else {
+ /* If this is btrfs, getting the backing block device is a bit harder */
+ r = btrfs_get_block_device(p, ret);
+ if (r < 0 && r != -ENOTTY)
+ return log_warning_errno(r, "Failed to determine block device backing btrfs file system '%s': %m", p);
+ if (r == -ENOTTY) {
+ log_warning("'%s' is not a block device node, and file system block device cannot be determined or is not local.", p);
+ return -ENODEV;
+ }
}
+ /* If this is a LUKS device, try to get the originating block device */
+ (void) block_get_originating(*ret, ret);
+
+ /* If this is a partition, try to get the originating block device */
+ (void) block_get_whole_disk(*ret, ret);
return 0;
}