Skip to content

Commit

Permalink
mount: replace three closely related mount flags into a proper flags …
Browse files Browse the repository at this point in the history
…enum

We pass these flags around, and even created a structure for them. Let's
fix things properly, and make them a flags value of its own.
  • Loading branch information
poettering committed Dec 7, 2018
1 parent b6418dc commit ec88d1e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 41 deletions.
61 changes: 25 additions & 36 deletions src/core/mount.c
Expand Up @@ -1447,28 +1447,22 @@ static int update_parameters_proc_self_mount_info(
return r > 0 || q > 0 || w > 0;
}

typedef struct {
bool is_mounted;
bool just_mounted;
bool just_changed;
} MountSetupFlags;

static int mount_setup_new_unit(
Manager *m,
const char *name,
const char *what,
const char *where,
const char *options,
const char *fstype,
MountSetupFlags *flags,
MountProcFlags *ret_flags,
Unit **ret) {

_cleanup_(unit_freep) Unit *u = NULL;
int r;

assert(m);
assert(name);
assert(flags);
assert(ret_flags);
assert(ret);

r = unit_new_for_name(m, sizeof(Mount), name, &u);
Expand Down Expand Up @@ -1496,10 +1490,7 @@ static int mount_setup_new_unit(
* loaded in now. */
unit_add_to_load_queue(u);

flags->is_mounted = true;
flags->just_mounted = true;
flags->just_changed = true;

*ret_flags = MOUNT_PROC_IS_MOUNTED | MOUNT_PROC_JUST_MOUNTED | MOUNT_PROC_JUST_CHANGED;
*ret = TAKE_PTR(u);
return 0;
}
Expand All @@ -1510,8 +1501,9 @@ static int mount_setup_existing_unit(
const char *where,
const char *options,
const char *fstype,
MountSetupFlags *flags) {
MountProcFlags *ret_flags) {

MountProcFlags flags = MOUNT_PROC_IS_MOUNTED;
int r;

assert(u);
Expand All @@ -1526,23 +1518,24 @@ static int mount_setup_existing_unit(
r = update_parameters_proc_self_mount_info(MOUNT(u), what, options, fstype);
if (r < 0)
return r;
if (r > 0)
flags |= MOUNT_PROC_JUST_CHANGED;

flags->just_changed = r > 0;
flags->is_mounted = true;
flags->just_mounted = !MOUNT(u)->from_proc_self_mountinfo || MOUNT(u)->just_mounted;

MOUNT(u)->from_proc_self_mountinfo = true;
if (!MOUNT(u)->from_proc_self_mountinfo) {
flags |= MOUNT_PROC_JUST_MOUNTED;
MOUNT(u)->from_proc_self_mountinfo = true;
}

if (IN_SET(u->load_state, UNIT_NOT_FOUND, UNIT_BAD_SETTING, UNIT_ERROR)) {
/* The unit was previously not found or otherwise not loaded. Now that the unit shows up in
* /proc/self/mountinfo we should reconsider it this, hence set it to UNIT_LOADED. */
u->load_state = UNIT_LOADED;
u->load_error = 0;

flags->just_changed = true;
flags |= MOUNT_PROC_JUST_CHANGED;
}

if (flags->just_changed) {
if (FLAGS_SET(flags, MOUNT_PROC_JUST_CHANGED)) {
/* If things changed, then make sure that all deps are regenerated. Let's
* first remove all automatic deps, and then add in the new ones. */

Expand All @@ -1553,6 +1546,7 @@ static int mount_setup_existing_unit(
return r;
}

*ret_flags = flags;
return 0;
}

Expand All @@ -1565,7 +1559,7 @@ static int mount_setup_unit(
bool set_flags) {

_cleanup_free_ char *e = NULL;
MountSetupFlags flags;
MountProcFlags flags;
Unit *u;
int r;

Expand Down Expand Up @@ -1601,15 +1595,13 @@ static int mount_setup_unit(
if (r < 0)
return log_warning_errno(r, "Failed to set up mount unit: %m");

if (set_flags) {
MOUNT(u)->is_mounted = flags.is_mounted;
MOUNT(u)->just_mounted = flags.just_mounted;
MOUNT(u)->just_changed = flags.just_changed;
}

if (flags.just_changed)
/* If the mount changed properties or state, let's notify our clients */
if (flags & (MOUNT_PROC_JUST_CHANGED|MOUNT_PROC_JUST_MOUNTED))
unit_add_to_dbus_queue(u);

if (set_flags)
MOUNT(u)->proc_flags = flags;

return 0;
}

Expand Down Expand Up @@ -1718,7 +1710,7 @@ static void mount_enumerate_perpetual(Manager *m) {
static bool mount_is_mounted(Mount *m) {
assert(m);

return UNIT(m)->perpetual || m->is_mounted;
return UNIT(m)->perpetual || FLAGS_SET(m->proc_flags, MOUNT_PROC_IS_MOUNTED);
}

static void mount_enumerate(Manager *m) {
Expand Down Expand Up @@ -1818,11 +1810,8 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
r = mount_load_proc_self_mountinfo(m, true);
if (r < 0) {
/* Reset flags, just in case, for later calls */
LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_MOUNT]) {
Mount *mount = MOUNT(u);

mount->is_mounted = mount->just_mounted = mount->just_changed = false;
}
LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_MOUNT])
MOUNT(u)->proc_flags = 0;

return 0;
}
Expand Down Expand Up @@ -1863,7 +1852,7 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
break;
}

} else if (mount->just_mounted || mount->just_changed) {
} else if (mount->proc_flags & (MOUNT_PROC_JUST_MOUNTED|MOUNT_PROC_JUST_CHANGED)) {

/* A mount point was added or changed */

Expand Down Expand Up @@ -1904,7 +1893,7 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
}

/* Reset the flags for later calls */
mount->is_mounted = mount->just_mounted = mount->just_changed = false;
mount->proc_flags = 0;
}

SET_FOREACH(what, gone, i) {
Expand Down
13 changes: 8 additions & 5 deletions src/core/mount.h
Expand Up @@ -34,6 +34,13 @@ typedef struct MountParameters {
char *fstype;
} MountParameters;

/* Used while looking for mount points that vanished or got added from/to /proc/self/mountinfo */
typedef enum MountProcFlags {
MOUNT_PROC_IS_MOUNTED = 1 << 0,
MOUNT_PROC_JUST_MOUNTED = 1 << 1,
MOUNT_PROC_JUST_CHANGED = 1 << 2,
} MountProcFlags;

struct Mount {
Unit meta;

Expand All @@ -45,11 +52,7 @@ struct Mount {
bool from_proc_self_mountinfo:1;
bool from_fragment:1;

/* Used while looking for mount points that vanished or got
* added from/to /proc/self/mountinfo */
bool is_mounted:1;
bool just_mounted:1;
bool just_changed:1;
MountProcFlags proc_flags;

bool sloppy_options;

Expand Down

0 comments on commit ec88d1e

Please sign in to comment.