chiark / gitweb /
tmpfiles: add new line type 'v' for creating btrfs subvolumes
authorLennart Poettering <lennart@poettering.net>
Sat, 27 Dec 2014 17:46:36 +0000 (18:46 +0100)
committerLennart Poettering <lennart@poettering.net>
Sun, 28 Dec 2014 01:08:40 +0000 (02:08 +0100)
22 files changed:
man/tmpfiles.d.xml
src/core/main.c
src/core/namespace.c
src/core/socket.c
src/hostname/hostnamed.c
src/locale/localed.c
src/login/logind-dbus.c
src/resolve/resolved.c
src/shared/btrfs-util.c
src/shared/btrfs-util.h
src/shared/fileio-label.c
src/shared/label.c
src/shared/label.h
src/shared/socket-label.c
src/sysusers/sysusers.c
src/test/test-udev.c
src/timedate/timedated.c
src/tmpfiles/tmpfiles.c
src/udev/udev-node.c
src/udev/udevadm.c
src/udev/udevd.c
src/update-done/update-done.c

index 4f2e640..398b3f7 100644 (file)
@@ -168,6 +168,17 @@ L    /tmp/foobar -    -    -    -   /dev/null</programlisting>
                                 </varlistentry>
 
                                 <varlistentry>
+                                        <term><varname>v</varname></term>
+                                        <listitem><para>Create a
+                                        subvolume if the path does not
+                                        exist yet and the file system
+                                        supports this (btrfs). Otherwise
+                                        create a normal directory, in
+                                        the same way as
+                                        <varname>d</varname>.</para></listitem>
+                                </varlistentry>
+
+                                <varlistentry>
                                         <term><varname>p</varname></term>
                                         <term><varname>p+</varname></term>
                                         <listitem><para>Create a named
index 300567a..87d54ca 100644 (file)
@@ -42,9 +42,7 @@
 #include "sd-daemon.h"
 #include "sd-messages.h"
 #include "sd-bus.h"
-#include "manager.h"
 #include "log.h"
-#include "load-fragment.h"
 #include "fdset.h"
 #include "special.h"
 #include "conf-parser.h"
 #include "env-util.h"
 #include "clock-util.h"
 #include "fileio.h"
-#include "dbus-manager.h"
 #include "bus-error.h"
 #include "bus-util.h"
+#include "selinux-util.h"
+#include "manager.h"
+#include "dbus-manager.h"
+#include "load-fragment.h"
 
 #include "mount-setup.h"
 #include "loopback-setup.h"
index 4c41109..5b408e0 100644 (file)
@@ -35,7 +35,6 @@
 #include "strv.h"
 #include "util.h"
 #include "path-util.h"
-#include "namespace.h"
 #include "missing.h"
 #include "execute.h"
 #include "loopback-setup.h"
@@ -43,6 +42,8 @@
 #include "dev-setup.h"
 #include "def.h"
 #include "label.h"
+#include "selinux-util.h"
+#include "namespace.h"
 
 typedef enum MountMode {
         /* This is ordered by priority! */
index 8fa55e0..b671fff 100644 (file)
@@ -48,6 +48,7 @@
 #include "smack-util.h"
 #include "bus-util.h"
 #include "bus-error.h"
+#include "selinux-util.h"
 #include "dbus-socket.h"
 #include "unit.h"
 #include "socket.h"
index b230ff6..7cd4a1d 100644 (file)
@@ -33,6 +33,7 @@
 #include "label.h"
 #include "bus-util.h"
 #include "event-util.h"
+#include "selinux-util.h"
 
 #define VALID_DEPLOYMENT_CHARS (DIGITS LETTERS "-.:")
 
index 0723541..529a9ab 100644 (file)
@@ -39,6 +39,7 @@
 #include "bus-message.h"
 #include "event-util.h"
 #include "locale-util.h"
+#include "selinux-util.h"
 
 #ifdef HAVE_XKBCOMMON
 #include <xkbcommon/xkbcommon.h>
index c0d1309..26ce8fe 100644 (file)
 #include "audit.h"
 #include "bus-util.h"
 #include "bus-error.h"
-#include "logind.h"
 #include "bus-common-errors.h"
 #include "udev-util.h"
+#include "selinux-util.h"
+#include "logind.h"
 
 static int property_get_idle_hint(
                 sd_bus *bus,
index c0ab947..ce15a80 100644 (file)
@@ -24,6 +24,7 @@
 #include "mkdir.h"
 #include "label.h"
 #include "capability.h"
+#include "selinux-util.h"
 
 #include "resolved-manager.h"
 #include "resolved-conf.h"
index 84c8110..9b47330 100644 (file)
@@ -33,6 +33,8 @@
 #include "macro.h"
 #include "strv.h"
 #include "copy.h"
+#include "selinux-util.h"
+#include "smack-util.h"
 #include "btrfs-ctree.h"
 #include "btrfs-util.h"
 
@@ -184,6 +186,24 @@ int btrfs_subvol_make(const char *path) {
         return 0;
 }
 
+int btrfs_subvol_make_label(const char *path) {
+        int r;
+
+        assert(path);
+
+        r = mac_selinux_create_file_prepare(path, S_IFDIR);
+        if (r < 0)
+                return r;
+
+        r = btrfs_subvol_make(path);
+        mac_selinux_create_file_clear();
+
+        if (r < 0)
+                return r;
+
+        return mac_smack_fix(path, false, false);
+}
+
 int btrfs_subvol_remove(const char *path) {
         struct btrfs_ioctl_vol_args args = {};
         _cleanup_close_ int fd = -1;
index f51f37a..dff8c01 100644 (file)
@@ -37,6 +37,7 @@ typedef struct BtrfsSubvolInfo {
 int btrfs_is_snapshot(int fd);
 
 int btrfs_subvol_make(const char *path);
+int btrfs_subvol_make_label(const char *path);
 int btrfs_subvol_remove(const char *path);
 int btrfs_subvol_snapshot(const char *old_path, const char *new_path, bool read_only, bool fallback_copy);
 
index 294c9e6..5fd69e0 100644 (file)
 #include <sys/stat.h>
 #include <unistd.h>
 
-#include "fileio-label.h"
-#include "label.h"
 #include "util.h"
+#include "selinux-util.h"
+#include "label.h"
+#include "fileio-label.h"
 
 int write_string_file_atomic_label(const char *fn, const char *line) {
         int r;
index 0af41af..82f10b2 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "label.h"
+#include "selinux-util.h"
+#include "smack-util.h"
 #include "util.h"
+#include "label.h"
 
 int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
         int r, q;
index 3428a8b..8070bcb 100644 (file)
@@ -21,8 +21,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "selinux-util.h"
-#include "smack-util.h"
+#include <stdbool.h>
+#include <sys/types.h>
 
 int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs);
 
index b1ef19f..6806c51 100644 (file)
 #include "macro.h"
 #include "util.h"
 #include "mkdir.h"
-#include "socket-util.h"
 #include "missing.h"
 #include "label.h"
+#include "selinux-util.h"
+#include "socket-util.h"
 
 int socket_address_listen(
                 const SocketAddress *a,
index 0baa2c3..5d5f5ea 100644 (file)
@@ -39,6 +39,7 @@
 #include "label.h"
 #include "fileio-label.h"
 #include "uid-range.h"
+#include "selinux-util.h"
 
 typedef enum ItemType {
         ADD_USER = 'u',
index f2283ec..b57d275 100644 (file)
@@ -32,6 +32,7 @@
 #include <sys/signalfd.h>
 
 #include "missing.h"
+#include "selinux-util.h"
 #include "udev.h"
 #include "udev-util.h"
 
index d507200..753c3d1 100644 (file)
@@ -40,6 +40,7 @@
 #include "bus-error.h"
 #include "bus-common-errors.h"
 #include "event-util.h"
+#include "selinux-util.h"
 
 #define NULL_ADJTIME_UTC "0.0 0 0\n0\nUTC\n"
 #define NULL_ADJTIME_LOCAL "0.0 0 0\n0\nLOCAL\n"
index 44ea51e..b830850 100644 (file)
@@ -54,6 +54,8 @@
 #include "specifier.h"
 #include "build.h"
 #include "copy.h"
+#include "selinux-util.h"
+#include "btrfs-util.h"
 
 /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
  * them in the file system. This is intended to be used to create
@@ -66,6 +68,7 @@ typedef enum ItemType {
         TRUNCATE_FILE = 'F',
         CREATE_DIRECTORY = 'd',
         TRUNCATE_DIRECTORY = 'D',
+        CREATE_SUBVOLUME = 'v',
         CREATE_FIFO = 'p',
         CREATE_SYMLINK = 'L',
         CREATE_CHAR_DEVICE = 'c',
@@ -758,17 +761,27 @@ static int create_item(Item *i) {
 
                 break;
 
-        case TRUNCATE_DIRECTORY:
         case CREATE_DIRECTORY:
+        case TRUNCATE_DIRECTORY:
+        case CREATE_SUBVOLUME:
 
-                RUN_WITH_UMASK(0000) {
+                RUN_WITH_UMASK(0000)
                         mkdir_parents_label(i->path, 0755);
-                        r = mkdir_label(i->path, i->mode);
+
+                if (i->type == CREATE_SUBVOLUME) {
+                        RUN_WITH_UMASK((~i->mode) & 0777)
+                                r = btrfs_subvol_make(i->path);
+                } else
+                        r = 0;
+
+                if (i->type == CREATE_DIRECTORY || r == -ENOTTY) {
+                        RUN_WITH_UMASK(0000)
+                                r = mkdir_label(i->path, i->mode);
                 }
 
                 if (r < 0) {
                         if (r != -EEXIST)
-                                return log_error_errno(r, "Failed to create directory %s: %m", i->path);
+                                return log_error_errno(r, "Failed to create directory or subvolume %s: %m", i->path);
 
                         if (stat(i->path, &st) < 0)
                                 return log_error_errno(errno, "stat(%s) failed: %m", i->path);
@@ -970,6 +983,7 @@ static int remove_item_instance(Item *i, const char *instance) {
         case CREATE_FILE:
         case TRUNCATE_FILE:
         case CREATE_DIRECTORY:
+        case CREATE_SUBVOLUME:
         case CREATE_FIFO:
         case CREATE_SYMLINK:
         case CREATE_BLOCK_DEVICE:
@@ -1014,6 +1028,7 @@ static int remove_item(Item *i) {
         case CREATE_FILE:
         case TRUNCATE_FILE:
         case CREATE_DIRECTORY:
+        case CREATE_SUBVOLUME:
         case CREATE_FIFO:
         case CREATE_SYMLINK:
         case CREATE_CHAR_DEVICE:
@@ -1091,6 +1106,7 @@ static int clean_item(Item *i) {
 
         switch (i->type) {
         case CREATE_DIRECTORY:
+        case CREATE_SUBVOLUME:
         case TRUNCATE_DIRECTORY:
         case IGNORE_PATH:
         case COPY_FILES:
@@ -1289,6 +1305,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
         case CREATE_FILE:
         case TRUNCATE_FILE:
         case CREATE_DIRECTORY:
+        case CREATE_SUBVOLUME:
         case TRUNCATE_DIRECTORY:
         case CREATE_FIFO:
         case IGNORE_PATH:
@@ -1429,6 +1446,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
         } else
                 i->mode =
                         i->type == CREATE_DIRECTORY ||
+                        i->type == CREATE_SUBVOLUME ||
                         i->type == TRUNCATE_DIRECTORY ? 0755 : 0644;
 
         if (age && !streq(age, "-")) {
@@ -1636,7 +1654,7 @@ static int read_config_file(const char *fn, bool ignore_enoent) {
                         continue;
 
                 HASHMAP_FOREACH(j, items, iter) {
-                        if (j->type != CREATE_DIRECTORY && j->type != TRUNCATE_DIRECTORY)
+                        if (j->type != CREATE_DIRECTORY && j->type != TRUNCATE_DIRECTORY && j->type != CREATE_SUBVOLUME)
                                 continue;
 
                         if (path_equal(j->path, i->path)) {
index c30a428..499feef 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "udev.h"
 #include "smack-util.h"
+#include "selinux-util.h"
 
 static int node_symlink(struct udev_device *dev, const char *node, const char *slink) {
         struct stat stats;
index d9bd697..a957e92 100644 (file)
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <getopt.h>
 
+#include "selinux-util.h"
 #include "udev.h"
 
 static int adm_version(struct udev *udev, int argc, char *argv[]) {
index c367825..3edb29b 100644 (file)
 #include <sys/inotify.h>
 #include <sys/utsname.h>
 
-#include "udev.h"
-#include "udev-util.h"
-#include "rtnl-util.h"
 #include "sd-daemon.h"
+#include "rtnl-util.h"
 #include "cgroup-util.h"
 #include "dev-setup.h"
 #include "fileio.h"
+#include "selinux-util.h"
+#include "udev.h"
+#include "udev-util.h"
 
 static struct udev_rules *rules;
 static struct udev_ctrl *udev_ctrl;
index a910808..561963e 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "util.h"
 #include "label.h"
+#include "selinux-util.h"
 
 #define MESSAGE                                                         \
         "This file was created by systemd-update-done. Its only \n"     \