[systemd-devel] [PATCH 4/6] systemd: add mount id to MountParameters
Ian Kent
ikent at redhat.com
Mon Jul 27 04:58:24 UTC 2020
From: Ian Kent <raven at themaw.net>
When kernelwatch notification handling is added it will be necessary
to find the Mount unit from the mount id to update individual Mount
state, so add the mount id to MountParameters.
Signed-off-by: Ian Kent <raven at themaw.net>
---
src/core/mount.c | 29 +++++++++++++++++++++--------
src/core/mount.h | 1 +
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/core/mount.c b/src/core/mount.c
index 632aa73e1f..92a73f4cdb 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -54,7 +54,7 @@ static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {
static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
static void mount_update_unit_state(Mount *m, Set *gone, Set *around);
-static int mount_setup_unit(Manager *m, const char *what, const char *where, const char *options, const char *fstype, bool set_flags);
+static int mount_setup_unit(Manager *m, int mnt_id, const char *what, const char *where, const char *options, const char *fstype, bool set_flags);
static int mount_process_proc_self_mountinfo(Manager *m);
static bool MOUNT_STATE_WITH_PROCESS(MountState state) {
@@ -212,6 +212,7 @@ static void mount_unwatch_control_pid(Mount *m) {
static void mount_parameters_done(MountParameters *p) {
assert(p);
+ p->mnt_id = -1;
p->what = mfree(p->what);
p->options = mfree(p->options);
p->fstype = mfree(p->fstype);
@@ -258,6 +259,7 @@ static MountParameters* get_mount_parameters(Mount *m) {
static int update_parameters_proc_self_mountinfo(
Mount *m,
+ int mnt_id,
const char *what,
const char *options,
const char *fstype) {
@@ -267,6 +269,8 @@ static int update_parameters_proc_self_mountinfo(
p = &m->parameters_proc_self_mountinfo;
+ p->mnt_id = mnt_id;
+
r = free_and_strdup(&p->what, what);
if (r < 0)
return r;
@@ -774,6 +778,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
"%sResult: %s\n"
"%sClean Result: %s\n"
"%sWhere: %s\n"
+ "%sMount id: %d\n"
"%sWhat: %s\n"
"%sFile System Type: %s\n"
"%sOptions: %s\n"
@@ -790,6 +795,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
prefix, mount_result_to_string(m->result),
prefix, mount_result_to_string(m->clean_result),
prefix, m->where,
+ prefix, p->mnt_id,
prefix, p ? strna(p->what) : "n/a",
prefix, p ? strna(p->fstype) : "n/a",
prefix, p ? strna(p->options) : "n/a",
@@ -1362,6 +1368,7 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
struct libmnt_fs *fs;
const char *what;
Iterator i;
+ int mnt_id;
fs = mnt_new_fs();
if (!fs) {
@@ -1372,13 +1379,14 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
mnt_fs_set_target(fs, m->where);
mnt_fs_enable_fsinfo(fs, 1);
+ mnt_id = mnt_fs_get_id(fs);
device = mnt_fs_get_source(fs);
options = mnt_fs_get_options(fs);
fstype = mnt_fs_get_fstype(fs);
if (device && fstype) {
device_found_node(u->manager, device, DEVICE_FOUND_MOUNT, DEVICE_FOUND_MOUNT);
- (void) mount_setup_unit(u->manager, device, m->where, options, fstype, true);
+ (void) mount_setup_unit(u->manager, mnt_id, device, m->where, options, fstype, true);
}
mnt_unref_fs(fs);
@@ -1581,6 +1589,7 @@ static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *user
static int mount_setup_new_unit(
Manager *m,
const char *name,
+ int mnt_id,
const char *what,
const char *where,
const char *options,
@@ -1608,7 +1617,7 @@ static int mount_setup_new_unit(
if (r < 0)
return r;
- r = update_parameters_proc_self_mountinfo(MOUNT(u), what, options, fstype);
+ r = update_parameters_proc_self_mountinfo(MOUNT(u), mnt_id, what, options, fstype);
if (r < 0)
return r;
@@ -1628,6 +1637,7 @@ static int mount_setup_new_unit(
static int mount_setup_existing_unit(
Unit *u,
+ int mnt_id,
const char *what,
const char *where,
const char *options,
@@ -1652,7 +1662,7 @@ static int mount_setup_existing_unit(
MountProcFlags flags =
MOUNT(u)->proc_flags | MOUNT_PROC_IS_MOUNTED;
- r = update_parameters_proc_self_mountinfo(MOUNT(u), what, options, fstype);
+ r = update_parameters_proc_self_mountinfo(MOUNT(u), mnt_id, what, options, fstype);
if (r < 0)
return r;
if (r > 0)
@@ -1696,6 +1706,7 @@ static int mount_setup_existing_unit(
static int mount_setup_unit(
Manager *m,
+ int mnt_id,
const char *what,
const char *where,
const char *options,
@@ -1752,11 +1763,11 @@ static int mount_setup_unit(
u = manager_get_unit(m, e);
if (u)
- r = mount_setup_existing_unit(u, what, where, options, fstype, &flags);
+ r = mount_setup_existing_unit(u, mnt_id, what, where, options, fstype, &flags);
else
/* First time we see this mount point meaning that it's not been initiated by a mount unit but rather
* by the sysadmin having called mount(8) directly. */
- r = mount_setup_new_unit(m, e, what, where, options, fstype, &flags, &u);
+ r = mount_setup_new_unit(m, e, mnt_id, what, where, options, fstype, &flags, &u);
if (r < 0)
return log_warning_errno(r, "Failed to set up mount unit for '%s': %m", where);
@@ -1786,6 +1797,7 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
for (;;) {
struct libmnt_fs *fs;
const char *device, *path, *options, *fstype;
+ int mnt_id;
r = mnt_table_next_fs(table, iter, &fs);
if (r == 1)
@@ -1793,6 +1805,7 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
if (r < 0)
return log_error_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
+ mnt_id = mnt_fs_get_id(fs);
device = mnt_fs_get_source(fs);
path = mnt_fs_get_target(fs);
options = mnt_fs_get_options(fs);
@@ -1803,7 +1816,7 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
device_found_node(m, device, DEVICE_FOUND_MOUNT, DEVICE_FOUND_MOUNT);
- (void) mount_setup_unit(m, device, path, options, fstype, set_flags);
+ (void) mount_setup_unit(m, mnt_id, device, path, options, fstype, set_flags);
}
return 0;
@@ -1968,7 +1981,7 @@ static void mount_update_unit_state(Mount *mount, Set *gone, Set *around) {
}
mount->from_proc_self_mountinfo = false;
- assert_se(update_parameters_proc_self_mountinfo(mount, NULL, NULL, NULL) >= 0);
+ assert_se(update_parameters_proc_self_mountinfo(mount, -1, NULL, NULL, NULL) >= 0);
switch (mount->state) {
diff --git a/src/core/mount.h b/src/core/mount.h
index a1bc2d71a6..8c5abf9775 100644
--- a/src/core/mount.h
+++ b/src/core/mount.h
@@ -29,6 +29,7 @@ typedef enum MountResult {
} MountResult;
typedef struct MountParameters {
+ int mnt_id;
char *what;
char *options;
char *fstype;
More information about the systemd-devel
mailing list