]> git.proxmox.com Git - systemd.git/blame - src/core/dbus-mount.c
Imported Upstream version 229
[systemd.git] / src / core / dbus-mount.c
CommitLineData
663996b3
MS
1/***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
19
db2df898
MP
20#include "bus-util.h"
21#include "dbus-cgroup.h"
663996b3 22#include "dbus-execute.h"
14228c0d 23#include "dbus-kill.h"
14228c0d 24#include "dbus-mount.h"
db2df898
MP
25#include "mount.h"
26#include "string-util.h"
27#include "unit.h"
60f067b4
JS
28
29static int property_get_what(
30 sd_bus *bus,
31 const char *path,
32 const char *interface,
33 const char *property,
34 sd_bus_message *reply,
35 void *userdata,
36 sd_bus_error *error) {
37
38 Mount *m = userdata;
663996b3
MS
39 const char *d;
40
60f067b4
JS
41 assert(bus);
42 assert(reply);
663996b3
MS
43 assert(m);
44
45 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
46 d = m->parameters_proc_self_mountinfo.what;
47 else if (m->from_fragment && m->parameters_fragment.what)
48 d = m->parameters_fragment.what;
49 else
50 d = "";
51
60f067b4 52 return sd_bus_message_append(reply, "s", d);
663996b3
MS
53}
54
60f067b4
JS
55static int property_get_options(
56 sd_bus *bus,
57 const char *path,
58 const char *interface,
59 const char *property,
60 sd_bus_message *reply,
61 void *userdata,
62 sd_bus_error *error) {
63
64 Mount *m = userdata;
663996b3
MS
65 const char *d;
66
60f067b4
JS
67 assert(bus);
68 assert(reply);
663996b3
MS
69 assert(m);
70
71 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
72 d = m->parameters_proc_self_mountinfo.options;
73 else if (m->from_fragment && m->parameters_fragment.options)
74 d = m->parameters_fragment.options;
75 else
76 d = "";
77
60f067b4 78 return sd_bus_message_append(reply, "s", d);
663996b3
MS
79}
80
60f067b4
JS
81static int property_get_type(
82 sd_bus *bus,
83 const char *path,
84 const char *interface,
85 const char *property,
86 sd_bus_message *reply,
87 void *userdata,
88 sd_bus_error *error) {
89
90 Mount *m = userdata;
663996b3
MS
91 const char *d;
92
60f067b4
JS
93 assert(bus);
94 assert(reply);
663996b3
MS
95 assert(m);
96
97 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
98 d = m->parameters_proc_self_mountinfo.fstype;
99 else if (m->from_fragment && m->parameters_fragment.fstype)
100 d = m->parameters_fragment.fstype;
101 else
102 d = "";
103
60f067b4 104 return sd_bus_message_append(reply, "s", d);
663996b3
MS
105}
106
60f067b4
JS
107static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, mount_result, MountResult);
108
109const sd_bus_vtable bus_mount_vtable[] = {
110 SD_BUS_VTABLE_START(0),
111 SD_BUS_PROPERTY("Where", "s", NULL, offsetof(Mount, where), SD_BUS_VTABLE_PROPERTY_CONST),
112 SD_BUS_PROPERTY("What", "s", property_get_what, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
113 SD_BUS_PROPERTY("Options","s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
114 SD_BUS_PROPERTY("Type", "s", property_get_type, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
115 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Mount, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
116 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Mount, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
117 SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Mount, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
e842803a 118 SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool, offsetof(Mount, sloppy_options), SD_BUS_VTABLE_PROPERTY_CONST),
60f067b4
JS
119 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Mount, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
120 BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
121 BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
122 BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
123 SD_BUS_VTABLE_END
663996b3
MS
124};
125
60f067b4
JS
126static int bus_mount_set_transient_property(
127 Mount *m,
128 const char *name,
129 sd_bus_message *message,
130 UnitSetPropertiesMode mode,
131 sd_bus_error *error) {
132
133 const char *new_property;
134 char **property;
135 char *p;
136 int r;
137
138 assert(m);
139 assert(name);
140 assert(message);
141
142 if (streq(name, "What"))
143 property = &m->parameters_fragment.what;
144 else if (streq(name, "Options"))
145 property = &m->parameters_fragment.options;
146 else if (streq(name, "Type"))
147 property = &m->parameters_fragment.fstype;
148 else
149 return 0;
150
151 r = sd_bus_message_read(message, "s", &new_property);
152 if (r < 0)
153 return r;
663996b3 154
60f067b4
JS
155 if (mode != UNIT_CHECK) {
156 p = strdup(new_property);
157 if (!p)
158 return -ENOMEM;
663996b3 159
60f067b4
JS
160 free(*property);
161 *property = p;
162 }
663996b3 163
60f067b4 164 return 1;
663996b3 165}
14228c0d
MB
166
167int bus_mount_set_property(
168 Unit *u,
169 const char *name,
60f067b4 170 sd_bus_message *message,
14228c0d 171 UnitSetPropertiesMode mode,
60f067b4 172 sd_bus_error *error) {
14228c0d
MB
173
174 Mount *m = MOUNT(u);
175 int r;
176
60f067b4 177 assert(m);
14228c0d 178 assert(name);
60f067b4 179 assert(message);
14228c0d 180
60f067b4 181 r = bus_cgroup_set_property(u, &m->cgroup_context, name, message, mode, error);
14228c0d
MB
182 if (r != 0)
183 return r;
184
60f067b4
JS
185 if (u->transient && u->load_state == UNIT_STUB) {
186 /* This is a transient unit, let's load a little more */
187
188 r = bus_mount_set_transient_property(m, name, message, mode, error);
189 if (r != 0)
190 return r;
191
192 r = bus_exec_context_set_transient_property(u, &m->exec_context, name, message, mode, error);
193 if (r != 0)
194 return r;
195
196 r = bus_kill_context_set_transient_property(u, &m->kill_context, name, message, mode, error);
197 if (r != 0)
198 return r;
199 }
200
14228c0d
MB
201 return 0;
202}
203
204int bus_mount_commit_properties(Unit *u) {
205 assert(u);
206
60f067b4 207 unit_update_cgroup_members_masks(u);
14228c0d 208 unit_realize_cgroup(u);
60f067b4 209
14228c0d
MB
210 return 0;
211}