Commit 4e434314 authored by Lennart Poettering's avatar Lennart Poettering

swap: listen for POLLPRI events on /proc/swaps if available

parent 5a33f657
......@@ -48,8 +48,6 @@
* system.conf/session.conf man page
* exec /sbin/poweroff as PID 1 and do the shutdown
* suspend, resume
* passphrase agent https://bugs.freedesktop.org/show_bug.cgi?id=30038
......@@ -84,14 +82,14 @@ External:
* patch kernel for cpu feature modalias for autoloading aes/kvm/...
* patch fsck to support --lock
* place /etc/inittab with explaining blurb.
* pam_securetty should honour console=
* procps, psmisc, sysvinit-tools, hostname → util-linux-ng
* nologin nach /var/run https://bugzilla.redhat.com/show_bug.cgi?id=624489
* make sysinit honour forcefsck/fastboot from the kernel command line fsck.mode=auto|force|skip
* pam: fix double sudo session cleanup:
......
......@@ -216,7 +216,7 @@ int manager_new(ManagerRunningAs running_as, Manager **_m) {
m->audit_fd = -1;
#endif
m->signal_watch.fd = m->mount_watch.fd = m->udev_watch.fd = m->epoll_fd = m->dev_autofs_fd = -1;
m->signal_watch.fd = m->mount_watch.fd = m->udev_watch.fd = m->epoll_fd = m->dev_autofs_fd = m->swap_watch.fd = -1;
m->current_job_id = 1; /* start as id #1, so that we can leave #0 around as "null-like" value */
if (!(m->environment = strv_copy(environ)))
......@@ -2171,6 +2171,11 @@ static int process_event(Manager *m, struct epoll_event *ev) {
mount_fd_event(m, ev->events);
break;
case WATCH_SWAP:
/* Some swap table change, intended for the swap subsystem */
swap_fd_event(m, ev->events);
break;
case WATCH_UDEV:
/* Some notification from udev, intended for the device subsystem */
device_fd_event(m, ev->events);
......
......@@ -64,6 +64,7 @@ enum WatchType {
WATCH_UNIT_TIMER,
WATCH_JOB_TIMER,
WATCH_MOUNT,
WATCH_SWAP,
WATCH_UDEV,
WATCH_DBUS_WATCH,
WATCH_DBUS_TIMEOUT
......@@ -161,6 +162,7 @@ struct Manager {
FILE *proc_swaps;
Hashmap *swaps_by_proc_swaps;
bool request_reload;
Watch swap_watch;
/* Data specific to the D-Bus subsystem */
DBusConnection *api_bus, *system_bus;
......
......@@ -1526,7 +1526,7 @@ static int mount_enumerate(Manager *m) {
m->mount_watch.fd = fileno(m->proc_self_mountinfo);
zero(ev);
ev.events = EPOLLERR;
ev.events = EPOLLPRI;
ev.data.ptr = &m->mount_watch;
if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->mount_watch.fd, &ev) < 0)
......@@ -1551,7 +1551,7 @@ void mount_fd_event(Manager *m, int events) {
int r;
assert(m);
assert(events == EPOLLERR);
assert(events & EPOLLPRI);
/* The manager calls this for every fd event happening on the
* /proc/self/mountinfo file, which informs us about mounting
......
......@@ -1056,16 +1056,23 @@ static int swap_load_proc_swaps(Manager *m, bool set_flags) {
}
int swap_dispatch_reload(Manager *m) {
Meta *meta;
int r;
assert(m);
/* This function should go as soon as the kernel properly notifies us */
if (_likely_(!m->request_reload))
return 0;
m->request_reload = false;
return swap_fd_event(m, EPOLLPRI);
}
int swap_fd_event(Manager *m, int events) {
Meta *meta;
int r;
assert(m);
assert(events & EPOLLPRI);
if ((r == swap_load_proc_swaps(m, true)) < 0) {
log_error("Failed to reread /proc/swaps: %s", strerror(-r));
......@@ -1169,12 +1176,24 @@ static void swap_shutdown(Manager *m) {
static int swap_enumerate(Manager *m) {
int r;
struct epoll_event ev;
assert(m);
if (!m->proc_swaps)
if (!m->proc_swaps) {
if (!(m->proc_swaps = fopen("/proc/swaps", "re")))
return -errno;
m->swap_watch.type = WATCH_SWAP;
m->swap_watch.fd = fileno(m->proc_swaps);
zero(ev);
ev.events = EPOLLPRI;
ev.data.ptr = &m->swap_watch;
if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->swap_watch.fd, &ev) < 0)
return -errno;
}
/* We rely on mount.c to load /etc/fstab for us */
if ((r = swap_load_proc_swaps(m, false)) < 0)
......
......@@ -103,6 +103,7 @@ int swap_add_one(Manager *m, const char *what, const char *what_proc_swaps, int
int swap_add_one_mount_link(Swap *s, Mount *m);
int swap_dispatch_reload(Manager *m);
int swap_fd_event(Manager *m, int events);
const char* swap_state_to_string(SwapState i);
SwapState swap_state_from_string(const char *s);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment