From: Karel Zak Date: Mon, 18 May 2015 10:30:37 +0000 (+0200) Subject: fstab-generator: add x-systemd.requires and x-systemd.requires-mounts-for X-Git-Tag: v226.4~1^2~379 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=9796c5f831c49eb68a61edd992ac7565f5b17b9c fstab-generator: add x-systemd.requires and x-systemd.requires-mounts-for Currently we have no way how to specify dependencies between fstab entries (or another units) in the /etc/fstab. It means that users are forced to bypass fstab and write .mount units manually. The patch introduces new systemd fstab options: x-systemd.requires= - to specify dependence an another mount (PATH is translated to unit name) x-systemd.requires= - to specify dependence on arbitrary UNIT x-systemd.requires-mounts-for= - to specify dependence on another paths, implemented by RequiresMountsFor=. The option may be specified more than once. For example two bind mounts where B depends on A: /mnt/test/A /mnt/test/A none bind,defaults /mnt/test/A /mnt/test/B none bind,x-systemd.requires=/mnt/test/A More complex example with overlay FS where one mount point depends on "low" and "upper" directories: /dev/sdc1 /mnt/low ext4 defaults /dev/sdc2 /mnt/high ext4 defaults overlay /mnt/merged overlay lowerdir=/mnt/low,upperdir=/mnt/high/data,workdir=/mnt/high/work,x-systemd.requires-mounts-for=/mnt/low,x-systemd.requires-mounts-for=mnt/high https://bugzilla.redhat.com/show_bug.cgi?id=812826 https://bugzilla.redhat.com/show_bug.cgi?id=1164334 --- diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index cf317e17b..e231a0ff8 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -125,6 +125,36 @@ answer: return !!n; } +int fstab_extract_values(const char *opts, const char *name, char ***values) { + _cleanup_strv_free_ char **optsv = NULL, **res = NULL; + char **s; + + assert(opts); + assert(name); + assert(values); + + optsv = strv_split(opts, ","); + if (!optsv) + return -ENOMEM; + + STRV_FOREACH(s, optsv) { + char *arg; + int r; + + arg = startswith(*s, name); + if (!arg || *arg != '=') + continue; + r = strv_extend(&res, arg + 1); + if (r < 0) + return r; + } + + *values = res; + res = NULL; + + return !!*values; +} + int fstab_find_pri(const char *options, int *ret) { _cleanup_free_ char *opt = NULL; int r; diff --git a/src/shared/fstab-util.h b/src/shared/fstab-util.h index 9f6b32eaf..387c562a9 100644 --- a/src/shared/fstab-util.h +++ b/src/shared/fstab-util.h @@ -28,6 +28,8 @@ int fstab_filter_options(const char *opts, const char *names, const char **namefound, char **value, char **filtered); +int fstab_extract_values(const char *opts, const char *name, char ***values); + static inline bool fstab_test_option(const char *opts, const char *names) { return !!fstab_filter_options(opts, names, NULL, NULL, NULL); }