]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: also add a way to configure additional mount options via a JSON user record...
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Nov 2021 14:27:56 +0000 (15:27 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 12 Nov 2021 21:22:06 +0000 (22:22 +0100)
Fixes: #15120
src/home/homework-luks.c
src/home/homework-mount.c
src/home/homework-mount.h
src/shared/user-record-show.c
src/shared/user-record.c
src/shared/user-record.h

index 41cdac9cc4015be941853ae1beff5bd0c2120b01..1e2c3e55fde69135edf431e524a994860ef69f8f 100644 (file)
@@ -1352,7 +1352,7 @@ int home_setup_luks(
                 if (r < 0)
                         return r;
 
-                r = home_unshare_and_mount(setup->dm_node, fstype, user_record_luks_discard(h), user_record_mount_flags(h));
+                r = home_unshare_and_mount(setup->dm_node, fstype, user_record_luks_discard(h), user_record_mount_flags(h), h->luks_extra_mount_options);
                 if (r < 0)
                         return r;
 
@@ -2223,7 +2223,7 @@ int home_create_luks(
 
         log_info("Formatting file system completed.");
 
-        r = home_unshare_and_mount(setup->dm_node, fstype, user_record_luks_discard(h), user_record_mount_flags(h));
+        r = home_unshare_and_mount(setup->dm_node, fstype, user_record_luks_discard(h), user_record_mount_flags(h), h->luks_extra_mount_options);
         if (r < 0)
                 return r;
 
@@ -2413,7 +2413,13 @@ static int can_resize_fs(int fd, uint64_t old_size, uint64_t new_size) {
         return CAN_RESIZE_ONLINE;
 }
 
-static int ext4_offline_resize_fs(HomeSetup *setup, uint64_t new_size, bool discard, unsigned long flags) {
+static int ext4_offline_resize_fs(
+                HomeSetup *setup,
+                uint64_t new_size,
+                bool discard,
+                unsigned long flags,
+                const char *extra_mount_options) {
+
         _cleanup_free_ char *size_str = NULL;
         bool re_open = false, re_mount = false;
         pid_t resize_pid, fsck_pid;
@@ -2488,7 +2494,7 @@ static int ext4_offline_resize_fs(HomeSetup *setup, uint64_t new_size, bool disc
 
         /* Re-establish mounts and reopen the directory */
         if (re_mount) {
-                r = home_mount_node(setup->dm_node, "ext4", discard, flags);
+                r = home_mount_node(setup->dm_node, "ext4", discard, flags, extra_mount_options);
                 if (r < 0)
                         return r;
 
@@ -2930,7 +2936,7 @@ int home_resize_luks(
                 if (r < 0)
                         return log_error_errno(r, "Failed to resize file system: %m");
         } else {
-                r = ext4_offline_resize_fs(setup, new_fs_size, user_record_luks_discard(h), user_record_mount_flags(h));
+                r = ext4_offline_resize_fs(setup, new_fs_size, user_record_luks_discard(h), user_record_mount_flags(h), h->luks_extra_mount_options);
                 if (r < 0)
                         return r;
         }
index 82b461a9873616aed05e7ec71a7a78d6f54edbec..fadd5aae866c6de35f01db40bf939799ae53d3b8 100644 (file)
@@ -29,28 +29,35 @@ static const char *mount_options_for_fstype(const char *fstype) {
         return NULL;
 }
 
-int home_mount_node(const char *node, const char *fstype, bool discard, unsigned long flags) {
+int home_mount_node(
+                const char *node,
+                const char *fstype,
+                bool discard,
+                unsigned long flags,
+                const char *extra_mount_options) {
+
         _cleanup_free_ char *joined = NULL;
-        const char *options, *discard_option;
+        const char *default_options;
         int r;
 
         assert(node);
         assert(fstype);
 
-        options = mount_options_for_fstype(fstype);
+        default_options = mount_options_for_fstype(fstype);
+        if (default_options) {
+                if (!strextend_with_separator(&joined, ",", default_options))
+                        return log_oom();
+        }
 
-        discard_option = discard ? "discard" : "nodiscard";
+        if (!strextend_with_separator(&joined, ",", discard ? "discard" : "nodiscard"))
+                return log_oom();
 
-        if (options) {
-                joined = strjoin(options, ",", discard_option);
-                if (!joined)
+        if (extra_mount_options) {
+                if (!strextend_with_separator(&joined, ",", extra_mount_options))
                         return log_oom();
+        }
 
-                options = joined;
-        } else
-                options = discard_option;
-
-        r = mount_nofollow_verbose(LOG_ERR, node, HOME_RUNTIME_WORK_DIR, fstype, flags|MS_RELATIME, strempty(options));
+        r = mount_nofollow_verbose(LOG_ERR, node, HOME_RUNTIME_WORK_DIR, fstype, flags|MS_RELATIME, joined);
         if (r < 0)
                 return r;
 
@@ -74,7 +81,13 @@ int home_unshare_and_mkdir(void) {
         return 0;
 }
 
-int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags) {
+int home_unshare_and_mount(
+                const char *node,
+                const char *fstype,
+                bool discard,
+                unsigned long flags,
+                const char *extra_mount_options) {
+
         int r;
 
         assert(node);
@@ -84,7 +97,7 @@ int home_unshare_and_mount(const char *node, const char *fstype, bool discard, u
         if (r < 0)
                 return r;
 
-        r = home_mount_node(node, fstype, discard, flags);
+        r = home_mount_node(node, fstype, discard, flags, extra_mount_options);
         if (r < 0)
                 return r;
 
index c9190ae7228691e40bbdb2722bd3cde31e8a36c3..255df26c9ae572037cde926fccf91ae7a29322f2 100644 (file)
@@ -3,8 +3,8 @@
 
 #include <stdbool.h>
 
-int home_mount_node(const char *node, const char *fstype, bool discard, unsigned long flags);
+int home_mount_node(const char *node, const char *fstype, bool discard, unsigned long flags, const char *extra_mount_options);
 int home_unshare_and_mkdir(void);
-int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags);
+int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags, const char *extra_mount_options);
 int home_move_mount(const char *user_name_and_realm, const char *target);
 int home_shift_uid(int dir_fd, const char *target, uid_t stored_uid, uid_t exposed_uid, int *ret_mount_fd);
index b7ea7e9f07d4abfaafd807e667996b6156e8ac32..c733654b20af767c49fc5853989f2819397ef324 100644 (file)
@@ -284,6 +284,9 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) {
                 if (hr->file_system_type)
                         printf(" File System: %s\n", user_record_file_system_type(hr));
 
+                if (hr->luks_extra_mount_options)
+                        printf("LUKS MntOpts: %s\n", hr->luks_extra_mount_options);
+
                 if (hr->luks_cipher)
                         printf(" LUKS Cipher: %s\n", hr->luks_cipher);
                 if (hr->luks_cipher_mode)
index 49febade2a3dcfacf8d9d8aba54987bc053f465e..6413fc904d1b26a76918513ac2ed5639100799c0 100644 (file)
@@ -285,6 +285,7 @@ static UserRecord* user_record_free(UserRecord *h) {
         free(h->luks_cipher_mode);
         free(h->luks_pbkdf_hash_algorithm);
         free(h->luks_pbkdf_type);
+        free(h->luks_extra_mount_options);
 
         free(h->state);
         free(h->service);
@@ -1287,6 +1288,7 @@ static int dispatch_per_machine(const char *name, JsonVariant *variant, JsonDisp
                 { "luksPbkdfTimeCostUSec",      JSON_VARIANT_UNSIGNED,      json_dispatch_uint64,                 offsetof(UserRecord, luks_pbkdf_time_cost_usec),     0         },
                 { "luksPbkdfMemoryCost",        JSON_VARIANT_UNSIGNED,      json_dispatch_uint64,                 offsetof(UserRecord, luks_pbkdf_memory_cost),        0         },
                 { "luksPbkdfParallelThreads",   JSON_VARIANT_UNSIGNED,      json_dispatch_uint64,                 offsetof(UserRecord, luks_pbkdf_parallel_threads),   0         },
+                { "luksExtraMountOptions",      JSON_VARIANT_STRING,        json_dispatch_string,                 offsetof(UserRecord, luks_extra_mount_options),      0         },
                 { "dropCaches",                 JSON_VARIANT_BOOLEAN,       json_dispatch_tristate,               offsetof(UserRecord, drop_caches),                   0         },
                 { "rateLimitIntervalUSec",      JSON_VARIANT_UNSIGNED,      json_dispatch_uint64,                 offsetof(UserRecord, ratelimit_interval_usec),       0         },
                 { "rateLimitBurst",             JSON_VARIANT_UNSIGNED,      json_dispatch_uint64,                 offsetof(UserRecord, ratelimit_burst),               0         },
@@ -1634,6 +1636,7 @@ int user_record_load(UserRecord *h, JsonVariant *v, UserRecordLoadFlags load_fla
                 { "luksPbkdfTimeCostUSec",      JSON_VARIANT_UNSIGNED,      json_dispatch_uint64,                 offsetof(UserRecord, luks_pbkdf_time_cost_usec),     0         },
                 { "luksPbkdfMemoryCost",        JSON_VARIANT_UNSIGNED,      json_dispatch_uint64,                 offsetof(UserRecord, luks_pbkdf_memory_cost),        0         },
                 { "luksPbkdfParallelThreads",   JSON_VARIANT_UNSIGNED,      json_dispatch_uint64,                 offsetof(UserRecord, luks_pbkdf_parallel_threads),   0         },
+                { "luksExtraMountOptions",      JSON_VARIANT_STRING,        json_dispatch_string,                 offsetof(UserRecord, luks_extra_mount_options),      0         },
                 { "dropCaches",                 JSON_VARIANT_BOOLEAN,       json_dispatch_tristate,               offsetof(UserRecord, drop_caches),                   0         },
                 { "service",                    JSON_VARIANT_STRING,        json_dispatch_string,                 offsetof(UserRecord, service),                       JSON_SAFE },
                 { "rateLimitIntervalUSec",      JSON_VARIANT_UNSIGNED,      json_dispatch_uint64,                 offsetof(UserRecord, ratelimit_interval_usec),       0         },
index acf2cdc9d4d1bbaf225b32c7e8358163014f1e6b..bc160a0a5ec2267e8f902f7d4395206e4116c4b0 100644 (file)
@@ -331,6 +331,7 @@ typedef struct UserRecord {
         uint64_t luks_pbkdf_time_cost_usec;
         uint64_t luks_pbkdf_memory_cost;
         uint64_t luks_pbkdf_parallel_threads;
+        char *luks_extra_mount_options;
 
         uint64_t disk_usage;
         uint64_t disk_free;