summaryrefslogtreecommitdiff
path: root/src/tmpfiles
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-16 15:25:42 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-16 15:25:42 +0100
commit2904e949f23aeb17b7e21a2a0f8c43f959a07f98 (patch)
tree741b948bb870113c5bdd21783cc3948555b609d7 /src/tmpfiles
parentab32771aa0c2c2ab70248e7e0a4be92fd73512ad (diff)
tmpfiles: create subvolumes for "v", "q", and "Q" only if / is a subvolume
It's not a good idea to create subvolumes for parts of the OS tree (such as /home, or /var) if the root directory is not a subvolume too. We shouldn't assume control of "heavier" objects such as subvolumes, if the originating object (the root directory) is a "light-weight" object, i.e. a plain directory. Effectively this means that chroot() environments that are run on a plain directory do not have to deal with problems around systemd creating subvolumes that cannot be removed with a simple "rm" anymore. However, if the chroot manager creates a proper subvolume for such an environment it will also get further subvolumes placed in there, under the assumption that the manager understands the concept of subvolumes in that case.
Diffstat (limited to 'src/tmpfiles')
-rw-r--r--src/tmpfiles/tmpfiles.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 74b6b91593..f9a759e223 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1226,8 +1226,28 @@ static int create_item(Item *i) {
mkdir_parents_label(i->path, 0755);
if (IN_SET(i->type, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA)) {
- RUN_WITH_UMASK((~i->mode) & 0777)
- r = btrfs_subvol_make(i->path);
+
+ if (btrfs_is_subvol(isempty(arg_root) ? "/" : arg_root) <= 0)
+
+ /* Don't create a subvolume unless the
+ * root directory is one, too. We do
+ * this under the assumption that if
+ * the root directory is just a plain
+ * directory (i.e. very light-weight),
+ * we shouldn't try to split it up
+ * into subvolumes (i.e. more
+ * heavy-weight). Thus, chroot()
+ * environments and suchlike will get
+ * a full brtfs subvolume set up below
+ * their tree only if they
+ * specifically set up a btrfs
+ * subvolume for the root dir too. */
+
+ r = -ENOTTY;
+ else {
+ RUN_WITH_UMASK((~i->mode) & 0777)
+ r = btrfs_subvol_make(i->path);
+ }
} else
r = 0;