homed: add helpers for checking reference status of homes
Just some refactoring to make things more readable.
This commit is contained in:
committed by
Yu Watanabe
parent
776c2b8e72
commit
64b74c86d0
+19
-8
@@ -402,11 +402,9 @@ static void home_maybe_stop_retry_deactivate(Home *h, HomeState state) {
|
||||
/* Free the deactivation retry event source if we won't need it anymore. Specifically, we'll free the
|
||||
* event source whenever the home directory is already deactivated (and we thus where successful) or
|
||||
* if we start executing an operation that indicates that the home directory is going to be used or
|
||||
* operated on again. Also, if the home is referenced again stop the timer */
|
||||
* operated on again. Also, if the home is referenced again stop the timer. */
|
||||
|
||||
if (HOME_STATE_MAY_RETRY_DEACTIVATE(state) &&
|
||||
!h->ref_event_source_dont_suspend &&
|
||||
!h->ref_event_source_please_suspend)
|
||||
if (HOME_STATE_MAY_RETRY_DEACTIVATE(state) && !home_is_referenced(h))
|
||||
return;
|
||||
|
||||
h->retry_deactivate_event_source = sd_event_source_disable_unref(h->retry_deactivate_event_source);
|
||||
@@ -454,7 +452,7 @@ static void home_start_retry_deactivate(Home *h) {
|
||||
return;
|
||||
|
||||
/* If the home directory is being used now don't start the timer */
|
||||
if (h->ref_event_source_dont_suspend || h->ref_event_source_please_suspend)
|
||||
if (home_is_referenced(h))
|
||||
return;
|
||||
|
||||
r = sd_event_add_time_relative(
|
||||
@@ -2616,7 +2614,7 @@ static int on_home_ref_eof(sd_event_source *s, int fd, uint32_t revents, void *u
|
||||
if (h->ref_event_source_dont_suspend == s)
|
||||
h->ref_event_source_dont_suspend = sd_event_source_disable_unref(h->ref_event_source_dont_suspend);
|
||||
|
||||
if (h->ref_event_source_dont_suspend || h->ref_event_source_please_suspend)
|
||||
if (home_is_referenced(h))
|
||||
return 0;
|
||||
|
||||
log_info("Got notification that all sessions of user %s ended, deactivating automatically.", h->user_name);
|
||||
@@ -2744,6 +2742,19 @@ static int home_dispatch_acquire(Home *h, Operation *o) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool home_is_referenced(Home *h) {
|
||||
assert(h);
|
||||
|
||||
return h->ref_event_source_dont_suspend || h->ref_event_source_please_suspend;
|
||||
}
|
||||
|
||||
bool home_shall_suspend(Home *h) {
|
||||
assert(h);
|
||||
|
||||
/* Suspend if there's at least one client referencing this home directory that wants a suspend and none who does not. */
|
||||
return h->ref_event_source_please_suspend && !h->ref_event_source_dont_suspend;
|
||||
}
|
||||
|
||||
static int home_dispatch_release(Home *h, Operation *o) {
|
||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
int r;
|
||||
@@ -2752,7 +2763,7 @@ static int home_dispatch_release(Home *h, Operation *o) {
|
||||
assert(o);
|
||||
assert(o->type == OPERATION_RELEASE);
|
||||
|
||||
if (h->ref_event_source_dont_suspend || h->ref_event_source_please_suspend)
|
||||
if (home_is_referenced(h))
|
||||
/* If there's now a reference again, then let's abort the release attempt */
|
||||
r = sd_bus_error_setf(&error, BUS_ERROR_HOME_BUSY, "Home %s is currently referenced.", h->user_name);
|
||||
else {
|
||||
@@ -2889,7 +2900,7 @@ static int home_dispatch_pipe_eof(Home *h, Operation *o) {
|
||||
assert(o);
|
||||
assert(o->type == OPERATION_PIPE_EOF);
|
||||
|
||||
if (h->ref_event_source_please_suspend || h->ref_event_source_dont_suspend)
|
||||
if (home_is_referenced(h))
|
||||
return 1; /* Hmm, there's a reference again, let's cancel this */
|
||||
|
||||
switch (home_get_state(h)) {
|
||||
|
||||
@@ -197,6 +197,8 @@ int home_unregister(Home *h, sd_bus_error *error);
|
||||
int home_lock(Home *h, sd_bus_error *error);
|
||||
int home_unlock(Home *h, UserRecord *secret, sd_bus_error *error);
|
||||
|
||||
bool home_is_referenced(Home *h);
|
||||
bool home_shall_suspend(Home *h);
|
||||
HomeState home_get_state(Home *h);
|
||||
|
||||
int home_get_disk_status(Home *h, uint64_t *ret_disk_size,uint64_t *ret_disk_usage, uint64_t *ret_disk_free, uint64_t *ret_disk_ceiling, uint64_t *ret_disk_floor, statfs_f_type_t *ret_fstype, mode_t *ret_access_mode);
|
||||
|
||||
@@ -595,10 +595,7 @@ static int method_lock_all_homes(sd_bus_message *message, void *userdata, sd_bus
|
||||
|
||||
HASHMAP_FOREACH(h, m->homes_by_name) {
|
||||
|
||||
/* Automatically suspend all homes that have at least one client referencing it that asked
|
||||
* for "please suspend", and no client that asked for "please do not suspend". */
|
||||
if (h->ref_event_source_dont_suspend ||
|
||||
!h->ref_event_source_please_suspend)
|
||||
if (!home_shall_suspend(h))
|
||||
continue;
|
||||
|
||||
if (!o) {
|
||||
|
||||
Reference in New Issue
Block a user