summaryrefslogtreecommitdiff
path: root/src/core/mount.c
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2016-12-16 17:13:58 +0100
committerLennart Poettering <lennart@poettering.net>2016-12-16 17:13:58 +0100
commitebc8968bc0b6fc460099041f5ae1262ca17eeb6e (patch)
treea1c3593e691fae26283c8bf2f38649c1e33b15d8 /src/core/mount.c
parentd6ccb4f9428102ac784f8ebd5d937d5363146c1d (diff)
core: make mount units from /proc/self/mountinfo possibly bind to a device (#4515)
Since commit 9d06297, mount units from mountinfo are not bound to their devices anymore (they use the "Requires" dependency instead). This has the following drawback: if a media is mounted and the eject button is pressed then the media is unconditionally ejected leaving some inconsistent states. Since udev is the component that is reacting (no matter if the device is used or not) to the eject button, users expect that udev at least try to unmount the media properly. This patch introduces a new property "SYSTEMD_MOUNT_DEVICE_BOUND". When set on a block device, all units that requires this device will see their "Requires" dependency upgraded to a "BindTo" one. This is currently only used by cdrom devices. This patch also gives the possibility to the user to restore the previous behavior that is bind a mount unit to a device. This is achieved by passing the "x-systemd.device-bound" option to mount(8). Please note that currently this is not working because libmount treats the x-* options has comments therefore they're not available in utab for later application retrievals.
Diffstat (limited to 'src/core/mount.c')
-rw-r--r--src/core/mount.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/core/mount.c b/src/core/mount.c
index 997dbe3837..daf7f5697b 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -135,6 +135,16 @@ static bool mount_state_active(MountState state) {
MOUNT_REMOUNTING_SIGKILL);
}
+static bool mount_is_bound_to_device(const Mount *m) {
+ const MountParameters *p;
+
+ if (m->from_fragment)
+ return true;
+
+ p = &m->parameters_proc_self_mountinfo;
+ return fstab_test_option(p->options, "x-systemd.device-bound\0");
+}
+
static bool needs_quota(const MountParameters *p) {
assert(p);
@@ -324,6 +334,7 @@ static int mount_add_mount_links(Mount *m) {
static int mount_add_device_links(Mount *m) {
MountParameters *p;
bool device_wants_mount = false;
+ UnitDependency dep;
int r;
assert(m);
@@ -353,7 +364,14 @@ static int mount_add_device_links(Mount *m) {
if (mount_is_auto(p) && !mount_is_automount(p) && MANAGER_IS_SYSTEM(UNIT(m)->manager))
device_wants_mount = true;
- r = unit_add_node_link(UNIT(m), p->what, device_wants_mount, m->from_fragment ? UNIT_BINDS_TO : UNIT_REQUIRES);
+ /* Mount units from /proc/self/mountinfo are not bound to devices
+ * by default since they're subject to races when devices are
+ * unplugged. But the user can still force this dep with an
+ * appropriate option (or udev property) so the mount units are
+ * automatically stopped when the device disappears suddenly. */
+ dep = mount_is_bound_to_device(m) ? UNIT_BINDS_TO : UNIT_REQUIRES;
+
+ r = unit_add_node_link(UNIT(m), p->what, device_wants_mount, dep);
if (r < 0)
return r;