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