1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "bus-get-properties.h"
4 #include "dbus-cgroup.h"
5 #include "dbus-execute.h"
6 #include "dbus-kill.h"
7 #include "dbus-mount.h"
8 #include "dbus-util.h"
9 #include "mount.h"
10 #include "string-util.h"
11 #include "unit.h"
12
mount_get_what(const Mount * m)13 static const char *mount_get_what(const Mount *m) {
14 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
15 return m->parameters_proc_self_mountinfo.what;
16 if (m->from_fragment && m->parameters_fragment.what)
17 return m->parameters_fragment.what;
18 return NULL;
19 }
20
mount_get_options(const Mount * m)21 static const char *mount_get_options(const Mount *m) {
22 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
23 return m->parameters_proc_self_mountinfo.options;
24 if (m->from_fragment && m->parameters_fragment.options)
25 return m->parameters_fragment.options;
26 return NULL;
27 }
28
mount_get_fstype(const Mount * m)29 static const char *mount_get_fstype(const Mount *m) {
30 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
31 return m->parameters_proc_self_mountinfo.fstype;
32 else if (m->from_fragment && m->parameters_fragment.fstype)
33 return m->parameters_fragment.fstype;
34 return NULL;
35 }
36
37 static BUS_DEFINE_PROPERTY_GET(property_get_what, "s", Mount, mount_get_what);
38 static BUS_DEFINE_PROPERTY_GET(property_get_options, "s", Mount, mount_get_options);
39 static BUS_DEFINE_PROPERTY_GET(property_get_type, "s", Mount, mount_get_fstype);
40 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, mount_result, MountResult);
41
42 const sd_bus_vtable bus_mount_vtable[] = {
43 SD_BUS_VTABLE_START(0),
44 SD_BUS_PROPERTY("Where", "s", NULL, offsetof(Mount, where), SD_BUS_VTABLE_PROPERTY_CONST),
45 SD_BUS_PROPERTY("What", "s", property_get_what, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
46 SD_BUS_PROPERTY("Options","s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
47 SD_BUS_PROPERTY("Type", "s", property_get_type, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
48 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Mount, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
49 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Mount, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
50 SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Mount, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
51 SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool, offsetof(Mount, sloppy_options), SD_BUS_VTABLE_PROPERTY_CONST),
52 SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool, offsetof(Mount, lazy_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
53 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),
55 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Mount, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
56 SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
57 SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
58 BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
59 BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
60 BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
61 SD_BUS_VTABLE_END
62 };
63
bus_mount_set_transient_property(Mount * m,const char * name,sd_bus_message * message,UnitWriteFlags flags,sd_bus_error * error)64 static int bus_mount_set_transient_property(
65 Mount *m,
66 const char *name,
67 sd_bus_message *message,
68 UnitWriteFlags flags,
69 sd_bus_error *error) {
70
71 Unit *u = UNIT(m);
72
73 assert(m);
74 assert(name);
75 assert(message);
76
77 flags |= UNIT_PRIVATE;
78
79 if (streq(name, "Where"))
80 return bus_set_transient_path(u, name, &m->where, message, flags, error);
81
82 if (streq(name, "What"))
83 return bus_set_transient_string(u, name, &m->parameters_fragment.what, message, flags, error);
84
85 if (streq(name, "Options"))
86 return bus_set_transient_string(u, name, &m->parameters_fragment.options, message, flags, error);
87
88 if (streq(name, "Type"))
89 return bus_set_transient_string(u, name, &m->parameters_fragment.fstype, message, flags, error);
90
91 if (streq(name, "TimeoutUSec"))
92 return bus_set_transient_usec_fix_0(u, name, &m->timeout_usec, message, flags, error);
93
94 if (streq(name, "DirectoryMode"))
95 return bus_set_transient_mode_t(u, name, &m->directory_mode, message, flags, error);
96
97 if (streq(name, "SloppyOptions"))
98 return bus_set_transient_bool(u, name, &m->sloppy_options, message, flags, error);
99
100 if (streq(name, "LazyUnmount"))
101 return bus_set_transient_bool(u, name, &m->lazy_unmount, message, flags, error);
102
103 if (streq(name, "ForceUnmount"))
104 return bus_set_transient_bool(u, name, &m->force_unmount, message, flags, error);
105
106 if (streq(name, "ReadWriteOnly"))
107 return bus_set_transient_bool(u, name, &m->read_write_only, message, flags, error);
108
109 return 0;
110 }
111
bus_mount_set_property(Unit * u,const char * name,sd_bus_message * message,UnitWriteFlags flags,sd_bus_error * error)112 int bus_mount_set_property(
113 Unit *u,
114 const char *name,
115 sd_bus_message *message,
116 UnitWriteFlags flags,
117 sd_bus_error *error) {
118
119 Mount *m = MOUNT(u);
120 int r;
121
122 assert(m);
123 assert(name);
124 assert(message);
125
126 r = bus_cgroup_set_property(u, &m->cgroup_context, name, message, flags, error);
127 if (r != 0)
128 return r;
129
130 if (u->transient && u->load_state == UNIT_STUB) {
131 /* This is a transient unit, let's load a little more */
132
133 r = bus_mount_set_transient_property(m, name, message, flags, error);
134 if (r != 0)
135 return r;
136
137 r = bus_exec_context_set_transient_property(u, &m->exec_context, name, message, flags, error);
138 if (r != 0)
139 return r;
140
141 r = bus_kill_context_set_transient_property(u, &m->kill_context, name, message, flags, error);
142 if (r != 0)
143 return r;
144 }
145
146 return 0;
147 }
148
bus_mount_commit_properties(Unit * u)149 int bus_mount_commit_properties(Unit *u) {
150 assert(u);
151
152 unit_realize_cgroup(u);
153
154 return 0;
155 }
156