X Tutup
Skip to content

Commit c600357

Browse files
committed
mount: add ReadWriteOnly property to fail on read-only mounts
Systems where a mount point is expected to be read-write needs a way to fail mount units that fallback as read-only. Add a property to allow setting the -w option when calling mount(8).
1 parent 6eb35fd commit c600357

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

src/core/dbus-mount.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const sd_bus_vtable bus_mount_vtable[] = {
5151
SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool, offsetof(Mount, sloppy_options), SD_BUS_VTABLE_PROPERTY_CONST),
5252
SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool, offsetof(Mount, lazy_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
5353
SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool, offsetof(Mount, force_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
54+
SD_BUS_PROPERTY("ReadWriteOnly", "b", bus_property_get_bool, offsetof(Mount, read_write_only), SD_BUS_VTABLE_PROPERTY_CONST),
5455
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Mount, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
5556
SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
5657
SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
@@ -102,6 +103,9 @@ static int bus_mount_set_transient_property(
102103
if (streq(name, "ForceUnmount"))
103104
return bus_set_transient_bool(u, name, &m->force_unmount, message, flags, error);
104105

106+
if (streq(name, "ReadWriteOnly"))
107+
return bus_set_transient_bool(u, name, &m->read_write_only, message, flags, error);
108+
105109
return 0;
106110
}
107111

src/core/load-fragment-gperf.gperf.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ Mount.DirectoryMode, config_parse_mode, 0,
429429
Mount.SloppyOptions, config_parse_bool, 0, offsetof(Mount, sloppy_options)
430430
Mount.LazyUnmount, config_parse_bool, 0, offsetof(Mount, lazy_unmount)
431431
Mount.ForceUnmount, config_parse_bool, 0, offsetof(Mount, force_unmount)
432+
Mount.ReadWriteOnly, config_parse_bool, 0, offsetof(Mount, read_write_only)
432433
EXEC_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl
433434
CGROUP_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl
434435
KILL_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl

src/core/mount.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
752752
"%sSloppyOptions: %s\n"
753753
"%sLazyUnmount: %s\n"
754754
"%sForceUnmount: %s\n"
755+
"%sReadWriteOnly: %s\n"
755756
"%sTimeoutSec: %s\n",
756757
prefix, mount_state_to_string(m->state),
757758
prefix, mount_result_to_string(m->result),
@@ -767,6 +768,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
767768
prefix, yes_no(m->sloppy_options),
768769
prefix, yes_no(m->lazy_unmount),
769770
prefix, yes_no(m->force_unmount),
771+
prefix, yes_no(m->read_write_only),
770772
prefix, format_timespan(buf, sizeof(buf), m->timeout_usec, USEC_PER_SEC));
771773

772774
if (m->control_pid > 0)
@@ -998,6 +1000,8 @@ static void mount_enter_mounting(Mount *m) {
9981000
r = exec_command_set(m->control_command, MOUNT_PATH, p->what, m->where, NULL);
9991001
if (r >= 0 && m->sloppy_options)
10001002
r = exec_command_append(m->control_command, "-s", NULL);
1003+
if (r >= 0 && m->read_write_only)
1004+
r = exec_command_append(m->control_command, "-w", NULL);
10011005
if (r >= 0 && p->fstype)
10021006
r = exec_command_append(m->control_command, "-t", p->fstype, NULL);
10031007
if (r >= 0 && !isempty(opts))
@@ -1058,6 +1062,8 @@ static void mount_enter_remounting(Mount *m) {
10581062
"-o", o, NULL);
10591063
if (r >= 0 && m->sloppy_options)
10601064
r = exec_command_append(m->control_command, "-s", NULL);
1065+
if (r >= 0 && m->read_write_only)
1066+
r = exec_command_append(m->control_command, "-w", NULL);
10611067
if (r >= 0 && p->fstype)
10621068
r = exec_command_append(m->control_command, "-t", p->fstype, NULL);
10631069
} else

src/core/mount.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ struct Mount {
5959
bool lazy_unmount;
6060
bool force_unmount;
6161

62+
bool read_write_only;
63+
6264
MountResult result;
6365
MountResult reload_result;
6466
MountResult clean_result;

src/shared/bus-unit-util.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,8 @@ static int bus_append_mount_property(sd_bus_message *m, const char *field, const
14361436

14371437
if (STR_IN_SET(field, "SloppyOptions",
14381438
"LazyUnmount",
1439-
"ForceUnmount"))
1439+
"ForceUnmount",
1440+
"ReadwriteOnly"))
14401441
return bus_append_parse_boolean(m, field, eq);
14411442

14421443
return 0;

test/fuzz/fuzz-unit-file/directives.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ RateLimitIntervalSec=
856856
ReadKMsg=
857857
ReadOnly=
858858
ReadOnlyPaths=
859+
ReadWriteOnly=
859860
ReadWritePaths=
860861
RemoveIPC=
861862
ReserveVT=

0 commit comments

Comments
 (0)
X Tutup