1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2010 Lennart Poettering
7 #include "dbus-cgroup.h"
8 #include "dbus-execute.h"
10 #include "dbus-mount.h"
11 #include "dbus-util.h"
13 #include "string-util.h"
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
;
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
;
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
;
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
);
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
),
66 static int bus_mount_set_transient_property(
69 sd_bus_message
*message
,
71 sd_bus_error
*error
) {
79 flags
|= UNIT_PRIVATE
;
81 if (streq(name
, "Where"))
82 return bus_set_transient_path(u
, name
, &m
->where
, message
, flags
, error
);
84 if (streq(name
, "What"))
85 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.what
, message
, flags
, error
);
87 if (streq(name
, "Options"))
88 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.options
, message
, flags
, error
);
90 if (streq(name
, "Type"))
91 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.fstype
, message
, flags
, error
);
93 if (streq(name
, "TimeoutUSec"))
94 return bus_set_transient_usec_fix_0(u
, name
, &m
->timeout_usec
, message
, flags
, error
);
96 if (streq(name
, "DirectoryMode"))
97 return bus_set_transient_mode_t(u
, name
, &m
->directory_mode
, message
, flags
, error
);
99 if (streq(name
, "SloppyOptions"))
100 return bus_set_transient_bool(u
, name
, &m
->sloppy_options
, message
, flags
, error
);
102 if (streq(name
, "LazyUnmount"))
103 return bus_set_transient_bool(u
, name
, &m
->lazy_unmount
, message
, flags
, error
);
105 if (streq(name
, "ForceUnmount"))
106 return bus_set_transient_bool(u
, name
, &m
->force_unmount
, message
, flags
, error
);
111 int bus_mount_set_property(
114 sd_bus_message
*message
,
115 UnitWriteFlags flags
,
116 sd_bus_error
*error
) {
125 r
= bus_cgroup_set_property(u
, &m
->cgroup_context
, name
, message
, flags
, error
);
129 if (u
->transient
&& u
->load_state
== UNIT_STUB
) {
130 /* This is a transient unit, let's load a little more */
132 r
= bus_mount_set_transient_property(m
, name
, message
, flags
, error
);
136 r
= bus_exec_context_set_transient_property(u
, &m
->exec_context
, name
, message
, flags
, error
);
140 r
= bus_kill_context_set_transient_property(u
, &m
->kill_context
, name
, message
, flags
, error
);
148 int bus_mount_commit_properties(Unit
*u
) {
151 unit_update_cgroup_members_masks(u
);
152 unit_realize_cgroup(u
);