From: Mike Yuan Date: Sat, 15 Feb 2025 17:42:31 +0000 (+0100) Subject: mount-tool: never bind to device on explicit x-systemd.device-bound=no X-Git-Tag: v258-rc1~1201^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb12d57cd5f3e9033b51e1656f3fef81f06a8f01;p=thirdparty%2Fsystemd.git mount-tool: never bind to device on explicit x-systemd.device-bound=no --- diff --git a/man/systemd-mount.xml b/man/systemd-mount.xml index 9723af64d66..effcf82dd6b 100644 --- a/man/systemd-mount.xml +++ b/man/systemd-mount.xml @@ -263,15 +263,22 @@ - This option only has an effect in automount mode, - and controls whether the automount unit shall be bound to the backing device's lifetime. If set, the - automount unit will be stopped automatically when the backing device vanishes. By default, the automount unit - stays around, and subsequent accesses will block until backing device is replugged. This option has no effect - in case of non-device mounts, such as network or virtual file system mounts. + Controls whether the generated mount/automount unit shall be bound to the backing device's + lifetime. This setting is especially useful in automount mode. If set, the units will be stopped automatically + when the backing device vanishes. By default, the automount unit stays around, and subsequent accesses + will block until backing device is replugged. This option has no effect in case of non-device mounts, + such as network or virtual file system mounts. - Note that if is used (or only a single argument passed, which implies - , see above), and the file system block device is detected to be removable, this - option is implied. + If is used (or only a single argument passed, which implies + , see above), and the file system block device is detected to be removable, + this option is implied. + + Note that mount units by default gain a Requires= dependency on + the backing device. This behavior can be controlled via + mount option, see systemd.mount5 + for details. In particular, takes precedence over this option, + which suppresses device dependencies both in the generated mount units and what's implied by service manager. + diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index 40056eeeb0b..bda1e3a3beb 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -502,6 +502,24 @@ static int parse_argv(int argc, char *argv[]) { if (arg_discover && arg_transport != BUS_TRANSPORT_LOCAL) return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Automatic mount location discovery is only supported locally."); + + _cleanup_free_ char *dev_bound = NULL; + r = fstab_filter_options(arg_mount_options, "x-systemd.device-bound\0", + /* ret_namefound = */ NULL, &dev_bound, /* ret_values = */ NULL, /* ret_filtered = */ NULL); + if (r < 0) + return log_error_errno(r, "Failed to parse mount options for x-systemd.device-bound=: %m"); + if (r > 0 && !isempty(dev_bound)) { + /* If x-systemd.device-bound=no is explicitly specified, never bind automount unit + * to device either. */ + r = parse_boolean(dev_bound); + if (r < 0) + return log_error_errno(r, "Invalid x-systemd.device-bound= option: %s", dev_bound); + if (r == 0) { + log_full(arg_bind_device > 0 ? LOG_NOTICE : LOG_DEBUG, + "x-systemd.device-bound=no set, automatically disabling --bind-device."); + arg_bind_device = false; + } + } } return 1;