static int automount_dispatch_expire(sd_event_source *source, usec_t usec, void *userdata) { Automount *a = AUTOMOUNT(userdata); _cleanup_(expire_data_freep) struct expire_data *data = NULL; int r; assert(a); assert(source == a->expire_event_source); data = new0(struct expire_data, 1); if (!data) return log_oom(); data->ioctl_fd = -1; data->dev_autofs_fd = fcntl(UNIT(a)->manager->dev_autofs_fd, F_DUPFD_CLOEXEC, 3); if (data->dev_autofs_fd < 0) return log_unit_error_errno(UNIT(a), errno, "Failed to duplicate autofs fd: %m"); data->ioctl_fd = open_ioctl_fd(UNIT(a)->manager->dev_autofs_fd, a->where, a->dev_id); if (data->ioctl_fd < 0) return log_unit_error_errno(UNIT(a), data->ioctl_fd, "Couldn't open autofs ioctl fd: %m"); r = asynchronous_job(expire_thread, data); if (r < 0) return log_unit_error_errno(UNIT(a), r, "Failed to start expire job: %m"); data = NULL; return automount_start_expire(a); }
static int automount_coldplug(Unit *u) { Automount *a = AUTOMOUNT(u); int r; assert(a); assert(a->state == AUTOMOUNT_DEAD); if (a->deserialized_state != a->state) { r = open_dev_autofs(u->manager); if (r < 0) return r; if (a->deserialized_state == AUTOMOUNT_WAITING || a->deserialized_state == AUTOMOUNT_RUNNING) { assert(a->pipe_fd >= 0); r = sd_event_add_io(u->manager->event, &a->pipe_event_source, a->pipe_fd, EPOLLIN, automount_dispatch_io, u); if (r < 0) return r; (void) sd_event_source_set_description(a->pipe_event_source, "automount-io"); if (a->deserialized_state == AUTOMOUNT_RUNNING) { r = automount_start_expire(a); if (r < 0) log_unit_warning_errno(UNIT(a), r, "Failed to start expiration timer, ignoring: %m"); } } automount_set_state(a, a->deserialized_state); } return 0; }
int automount_update_mount(Automount *a, MountState old_state, MountState state) { int r; assert(a); switch (state) { case MOUNT_MOUNTED: case MOUNT_REMOUNTING: automount_send_ready(a, a->tokens, 0); r = automount_start_expire(a); if (r < 0) log_unit_warning_errno(UNIT(a), r, "Failed to start expiration timer, ignoring: %m"); break; case MOUNT_DEAD: case MOUNT_UNMOUNTING: case MOUNT_MOUNTING_SIGTERM: case MOUNT_MOUNTING_SIGKILL: case MOUNT_REMOUNTING_SIGTERM: case MOUNT_REMOUNTING_SIGKILL: case MOUNT_UNMOUNTING_SIGTERM: case MOUNT_UNMOUNTING_SIGKILL: case MOUNT_FAILED: if (old_state != state) automount_send_ready(a, a->tokens, -ENODEV); (void) sd_event_source_set_enabled(a->expire_event_source, SD_EVENT_OFF); break; default: break; } switch (state) { case MOUNT_DEAD: automount_send_ready(a, a->expire_tokens, 0); break; case MOUNT_MOUNTING: case MOUNT_MOUNTING_DONE: case MOUNT_MOUNTING_SIGTERM: case MOUNT_MOUNTING_SIGKILL: case MOUNT_REMOUNTING_SIGTERM: case MOUNT_REMOUNTING_SIGKILL: case MOUNT_UNMOUNTING_SIGTERM: case MOUNT_UNMOUNTING_SIGKILL: case MOUNT_FAILED: if (old_state != state) automount_send_ready(a, a->expire_tokens, -ENODEV); break; default: break; } return 0; }
static void automount_trigger_notify(Unit *u, Unit *other) { Automount *a = AUTOMOUNT(u); int r; assert(a); assert(other); /* Filter out invocations with bogus state */ if (other->load_state != UNIT_LOADED || other->type != UNIT_MOUNT) return; /* Don't propagate state changes from the mount if we are already down */ if (!IN_SET(a->state, AUTOMOUNT_WAITING, AUTOMOUNT_RUNNING)) return; /* Propagate start limit hit state */ if (other->start_limit_hit) { automount_enter_dead(a, AUTOMOUNT_FAILURE_MOUNT_START_LIMIT_HIT); return; } /* Don't propagate anything if there's still a job queued */ if (other->job) return; /* The mount is successfully established */ if (IN_SET(MOUNT(other)->state, MOUNT_MOUNTED, MOUNT_REMOUNTING)) { (void) automount_send_ready(a, a->tokens, 0); r = automount_start_expire(a); if (r < 0) log_unit_warning_errno(UNIT(a), r, "Failed to start expiration timer, ignoring: %m"); automount_set_state(a, AUTOMOUNT_RUNNING); } if (IN_SET(MOUNT(other)->state, MOUNT_MOUNTING, MOUNT_MOUNTING_DONE, MOUNT_MOUNTED, MOUNT_REMOUNTING, MOUNT_MOUNTING_SIGTERM, MOUNT_MOUNTING_SIGKILL, MOUNT_REMOUNTING_SIGTERM, MOUNT_REMOUNTING_SIGKILL, MOUNT_UNMOUNTING_SIGTERM, MOUNT_UNMOUNTING_SIGKILL, MOUNT_FAILED)) { (void) automount_send_ready(a, a->expire_tokens, -ENODEV); } if (MOUNT(other)->state == MOUNT_DEAD) (void) automount_send_ready(a, a->expire_tokens, 0); /* The mount is in some unhappy state now, let's unfreeze any waiting clients */ if (IN_SET(MOUNT(other)->state, MOUNT_DEAD, MOUNT_UNMOUNTING, MOUNT_MOUNTING_SIGTERM, MOUNT_MOUNTING_SIGKILL, MOUNT_REMOUNTING_SIGTERM, MOUNT_REMOUNTING_SIGKILL, MOUNT_UNMOUNTING_SIGTERM, MOUNT_UNMOUNTING_SIGKILL, MOUNT_FAILED)) { (void) automount_send_ready(a, a->tokens, -ENODEV); automount_set_state(a, AUTOMOUNT_WAITING); } }