]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-mount.c
hashmap: be a bit more conservative with pre-allocating hash tables and items
[thirdparty/systemd.git] / src / core / dbus-mount.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4139c1b2
LP
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
4139c1b2
LP
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 16 Lesser General Public License for more details.
4139c1b2 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
4139c1b2
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
4e85aff4
LP
22#include <errno.h>
23
4139c1b2 24#include "dbus-unit.h"
4139c1b2 25#include "dbus-execute.h"
4ad49000
LP
26#include "dbus-kill.h"
27#include "dbus-cgroup.h"
bfebab7f 28#include "dbus-common.h"
cad45ba1 29#include "selinux-access.h"
4ad49000 30#include "dbus-mount.h"
4139c1b2 31
4288f619
LP
32#define BUS_MOUNT_INTERFACE \
33 " <interface name=\"org.freedesktop.systemd1.Mount\">\n" \
34 " <property name=\"Where\" type=\"s\" access=\"read\"/>\n" \
35 " <property name=\"What\" type=\"s\" access=\"read\"/>\n" \
36 " <property name=\"Options\" type=\"s\" access=\"read\"/>\n" \
37 " <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
38 " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
d7550a67 39 BUS_UNIT_CGROUP_INTERFACE \
fe68089d
LP
40 BUS_EXEC_COMMAND_INTERFACE("ExecMount") \
41 BUS_EXEC_COMMAND_INTERFACE("ExecUnmount") \
42 BUS_EXEC_COMMAND_INTERFACE("ExecRemount") \
4288f619 43 BUS_EXEC_CONTEXT_INTERFACE \
4819ff03 44 BUS_KILL_CONTEXT_INTERFACE \
6a95dff8 45 BUS_CGROUP_CONTEXT_INTERFACE \
4288f619 46 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
5bd07073 47 " <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
9d2f5178 48 " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
4288f619
LP
49 " </interface>\n"
50
51#define INTROSPECTION \
52 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
53 "<node>\n" \
54 BUS_UNIT_INTERFACE \
55 BUS_MOUNT_INTERFACE \
56 BUS_PROPERTIES_INTERFACE \
c4e2ceae 57 BUS_PEER_INTERFACE \
4288f619
LP
58 BUS_INTROSPECTABLE_INTERFACE \
59 "</node>\n"
60
05feefe0
LP
61#define INTERFACES_LIST \
62 BUS_UNIT_INTERFACES_LIST \
63 "org.freedesktop.systemd1.Mount\0"
64
ca2871d9 65const char bus_mount_interface[] = BUS_MOUNT_INTERFACE;
4139c1b2 66
c4e2ceae
LP
67const char bus_mount_invalidating_properties[] =
68 "What\0"
69 "Options\0"
70 "Type\0"
71 "ExecMount\0"
72 "ExecUnmount\0"
73 "ExecRemount\0"
9d2f5178
LP
74 "ControlPID\0"
75 "Result\0";
c4e2ceae 76
bfebab7f 77static int bus_mount_append_what(DBusMessageIter *i, const char *property, void *data) {
4e85aff4
LP
78 Mount *m = data;
79 const char *d;
80
4e85aff4
LP
81 assert(i);
82 assert(property);
83 assert(m);
84
85 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
86 d = m->parameters_proc_self_mountinfo.what;
87 else if (m->from_fragment && m->parameters_fragment.what)
88 d = m->parameters_fragment.what;
4e85aff4
LP
89 else
90 d = "";
91
92 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
93 return -ENOMEM;
94
95 return 0;
96}
97
bfebab7f 98static int bus_mount_append_options(DBusMessageIter *i, const char *property, void *data) {
4e85aff4
LP
99 Mount *m = data;
100 const char *d;
101
4e85aff4
LP
102 assert(i);
103 assert(property);
104 assert(m);
105
106 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
107 d = m->parameters_proc_self_mountinfo.options;
108 else if (m->from_fragment && m->parameters_fragment.options)
109 d = m->parameters_fragment.options;
4e85aff4
LP
110 else
111 d = "";
112
113 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
114 return -ENOMEM;
115
116 return 0;
117}
118
bfebab7f 119static int bus_mount_append_type(DBusMessageIter *i, const char *property, void *data) {
4e85aff4
LP
120 Mount *m = data;
121 const char *d;
122
4e85aff4
LP
123 assert(i);
124 assert(property);
125 assert(m);
126
127 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
128 d = m->parameters_proc_self_mountinfo.fstype;
129 else if (m->from_fragment && m->parameters_fragment.fstype)
130 d = m->parameters_fragment.fstype;
4e85aff4
LP
131 else
132 d = "";
133
134 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
135 return -ENOMEM;
136
137 return 0;
138}
139
9d2f5178
LP
140static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_mount_append_mount_result, mount_result, MountResult);
141
d200735e
MS
142static const BusProperty bus_mount_properties[] = {
143 { "Where", bus_property_append_string, "s", offsetof(Mount, where), true },
144 { "What", bus_mount_append_what, "s", 0 },
145 { "Options", bus_mount_append_options, "s", 0 },
146 { "Type", bus_mount_append_type, "s", 0 },
147 { "TimeoutUSec", bus_property_append_usec, "t", offsetof(Mount, timeout_usec) },
148 BUS_EXEC_COMMAND_PROPERTY("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), false),
149 BUS_EXEC_COMMAND_PROPERTY("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), false),
150 BUS_EXEC_COMMAND_PROPERTY("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), false),
151 { "ControlPID", bus_property_append_pid, "u", offsetof(Mount, control_pid) },
152 { "DirectoryMode", bus_property_append_mode, "u", offsetof(Mount, directory_mode) },
9d2f5178 153 { "Result", bus_mount_append_mount_result, "s", offsetof(Mount, result) },
d200735e
MS
154 { NULL, }
155};
156
5e8d1c9a 157DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
ac155bb8 158 Mount *m = MOUNT(u);
d200735e
MS
159
160 const BusBoundProperties bps[] = {
4ad49000 161 { "org.freedesktop.systemd1.Unit", bus_unit_properties, u },
d7550a67 162 { "org.freedesktop.systemd1.Mount", bus_unit_cgroup_properties, u },
4ad49000
LP
163 { "org.freedesktop.systemd1.Mount", bus_mount_properties, m },
164 { "org.freedesktop.systemd1.Mount", bus_exec_context_properties, &m->exec_context },
165 { "org.freedesktop.systemd1.Mount", bus_kill_context_properties, &m->kill_context },
166 { "org.freedesktop.systemd1.Mount", bus_cgroup_context_properties, &m->cgroup_context },
d200735e 167 { NULL, }
4139c1b2
LP
168 };
169
cad45ba1
LP
170 SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
171
d200735e 172 return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps );
4139c1b2 173}
74c964d3
LP
174
175int bus_mount_set_property(
176 Unit *u,
177 const char *name,
178 DBusMessageIter *i,
179 UnitSetPropertiesMode mode,
180 DBusError *error) {
181
182 Mount *m = MOUNT(u);
183 int r;
184
185 assert(name);
186 assert(u);
187 assert(i);
188
189 r = bus_cgroup_set_property(u, &m->cgroup_context, name, i, mode, error);
190 if (r != 0)
191 return r;
192
193 return 0;
194}
195
196int bus_mount_commit_properties(Unit *u) {
197 assert(u);
198
199 unit_realize_cgroup(u);
200 return 0;
201}