diff options
author | Ondrej Kozina <okozina@redhat.com> | 2020-02-21 12:45:33 +0100 |
---|---|---|
committer | Ondrej Kozina <okozina@redhat.com> | 2020-09-25 16:13:55 +0200 |
commit | eb7d9aa3919709a0cba8916145786721f96cc27f (patch) | |
tree | 0922eb4996d46c20b739f736ddf85411473fcf17 /src/cryptsetup/cryptsetup-generator.c | |
parent | cryptsetup-generator: use proper constant for uuid alphabet (diff) | |
download | systemd-eb7d9aa3919709a0cba8916145786721f96cc27f.tar.xz systemd-eb7d9aa3919709a0cba8916145786721f96cc27f.zip |
cryptsetup-generator: rename and extend device mount helpers.
Those functions will be used later also for (u)mounting LUKS
header devices.
Diffstat (limited to 'src/cryptsetup/cryptsetup-generator.c')
-rw-r--r-- | src/cryptsetup/cryptsetup-generator.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index dc80423eca..3b436ec967 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -99,11 +99,13 @@ static int split_keyspec(const char *keyspec, char **ret_keyfile, char **ret_key return 0; } -static int generate_keydev_mount( +static int generate_device_mount( const char *name, - const char *keydev, - const char *keydev_timeout, + const char *device, + const char *type_prefix, /* "keydev" or "headerdev" */ + const char *device_timeout, bool canfail, + bool readonly, char **unit, char **mount) { @@ -113,7 +115,7 @@ static int generate_keydev_mount( usec_t timeout_us; assert(name); - assert(keydev); + assert(device); assert(unit); assert(mount); @@ -129,7 +131,7 @@ static int generate_keydev_mount( if (!name_escaped) return -ENOMEM; - where = strjoin(arg_runtime_directory, "/keydev-", name_escaped); + where = strjoin(arg_runtime_directory, "/", type_prefix, "-", name_escaped); if (!where) return -ENOMEM; @@ -151,23 +153,23 @@ static int generate_keydev_mount( "[Mount]\n" "What=%s\n" "Where=%s\n" - "Options=ro%s\n", keydev, where, canfail ? ",nofail" : ""); + "Options=%s%s\n", device, where, readonly ? "ro" : "rw", canfail ? ",nofail" : ""); - if (keydev_timeout) { - r = parse_sec_fix_0(keydev_timeout, &timeout_us); + if (device_timeout) { + r = parse_sec_fix_0(device_timeout, &timeout_us); if (r >= 0) { - r = unit_name_from_path(keydev, ".device", &device_unit); + r = unit_name_from_path(device, ".device", &device_unit); if (r < 0) return log_error_errno(r, "Failed to generate unit name: %m"); r = write_drop_in_format(arg_dest, device_unit, 90, "device-timeout", "# Automatically generated by systemd-cryptsetup-generator \n\n" - "[Unit]\nJobRunningTimeoutSec=%s", keydev_timeout); + "[Unit]\nJobRunningTimeoutSec=%s", device_timeout); if (r < 0) return log_error_errno(r, "Failed to write device drop-in: %m"); } else - log_warning_errno(r, "Failed to parse %s, ignoring: %m", keydev_timeout); + log_warning_errno(r, "Failed to parse %s, ignoring: %m", device_timeout); } @@ -181,8 +183,9 @@ static int generate_keydev_mount( return 0; } -static int generate_keydev_umount(const char *name, - const char *keydev_mount, +static int generate_device_umount(const char *name, + const char *device_mount, + const char *type_prefix, /* "keydev" or "headerdev" */ char **ret_umount_unit) { _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *u = NULL, *name_escaped = NULL, *mount = NULL; @@ -195,11 +198,11 @@ static int generate_keydev_umount(const char *name, if (!name_escaped) return -ENOMEM; - u = strjoin("keydev-", name_escaped, "-umount.service"); + u = strjoin(type_prefix, "-", name_escaped, "-umount.service"); if (!u) return -ENOMEM; - r = unit_name_from_path(keydev_mount, ".mount", &mount); + r = unit_name_from_path(device_mount, ".mount", &mount); if (r < 0) return r; @@ -212,7 +215,7 @@ static int generate_keydev_umount(const char *name, "DefaultDependencies=no\n" "After=%s\n\n" "[Service]\n" - "ExecStart=-" UMOUNT_PATH " %s\n\n", mount, keydev_mount); + "ExecStart=-" UMOUNT_PATH " %s\n\n", mount, device_mount); r = fflush_and_check(f); if (r < 0) @@ -358,11 +361,19 @@ static int create_disk( if (keydev) { _cleanup_free_ char *unit = NULL, *umount_unit = NULL; - r = generate_keydev_mount(name, keydev, keyfile_timeout_value, keyfile_can_timeout > 0, &unit, &keydev_mount); + r = generate_device_mount( + name, + keydev, + "keydev", + keyfile_timeout_value, + /* canfail = */ keyfile_can_timeout > 0, + /* readonly= */ true, + &unit, + &keydev_mount); if (r < 0) return log_error_errno(r, "Failed to generate keydev mount unit: %m"); - r = generate_keydev_umount(name, keydev_mount, &umount_unit); + r = generate_device_umount(name, keydev_mount, "keydev", &umount_unit); if (r < 0) return log_error_errno(r, "Failed to generate keydev umount unit: %m"); |