diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-08-14 16:39:39 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-08-14 18:46:08 +0200 |
commit | c55a97f1fd879f08052729f901fb899c3d8dfd52 (patch) | |
tree | 053ea51c332dbf42996959dd21e2160571d3cba0 /src/basic/mkdir.c | |
parent | copy: Add support for creating subvolumes to copy_tree_at() (diff) | |
download | systemd-c55a97f1fd879f08052729f901fb899c3d8dfd52.tar.xz systemd-c55a97f1fd879f08052729f901fb899c3d8dfd52.zip |
mkdir: Add support for creating subvolumes to mkdir_p_root()
We pass in the paths which should be subvolumes and try to create
those as subvolumes if we can.
Diffstat (limited to 'src/basic/mkdir.c')
-rw-r--r-- | src/basic/mkdir.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c index 41af1482bc..c770e5ed32 100644 --- a/src/basic/mkdir.c +++ b/src/basic/mkdir.c @@ -5,6 +5,7 @@ #include <string.h> #include "alloc-util.h" +#include "btrfs.h" #include "chase.h" #include "fd-util.h" #include "format-util.h" @@ -209,7 +210,7 @@ int mkdir_p_safe(const char *prefix, const char *path, mode_t mode, uid_t uid, g return mkdir_p_internal(prefix, path, mode, uid, gid, flags, mkdirat_errno_wrapper); } -int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m) { +int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m, char **subvolumes) { _cleanup_free_ char *pp = NULL, *bn = NULL; _cleanup_close_ int dfd = -EBADF; int r; @@ -227,7 +228,7 @@ int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m return r; else { /* Extracting the parent dir worked, hence we aren't top-level? Recurse up first. */ - r = mkdir_p_root(root, pp, uid, gid, m); + r = mkdir_p_root(root, pp, uid, gid, m, subvolumes); if (r < 0) return r; @@ -242,11 +243,15 @@ int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m if (r < 0) return r; - if (mkdirat(dfd, bn, m) < 0) { - if (errno == EEXIST) + if (path_strv_contains(subvolumes, p)) + r = btrfs_subvol_make_fallback(dfd, bn, m); + else + r = RET_NERRNO(mkdirat(dfd, bn, m)); + if (r < 0) { + if (r == -EEXIST) return 0; - return -errno; + return r; } if (uid_is_valid(uid) || gid_is_valid(gid)) { |