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