Cgroup has a standardized poll/notification mechanism for waking all pollers on all fds when a filesystem node changes. To allow polling for custom events, add a .poll callback that can override the default. This is in preparation for pollable cgroup pressure files which have per-fd trigger configurations.
Unified · Split
| @@ -32,6 +32,7 @@ struct kernfs_node; · 31 unmodified lines | ||
| 32 | 32 | struct kernfs_ops; |
| 33 | 33 | struct kernfs_open_file; |
| 34 | 34 | struct seq_file; |
| 35 | +struct poll_table_struct; | |
| 35 | 36 | |
| 36 | 37 | #define MAX_CGROUP_TYPE_NAMELEN 32 |
| 37 | 38 | #define MAX_CGROUP_ROOT_NAMELEN 64 |
| @@ -574,6 +575,9 @@ struct cftype { · 536 unmodified lines | ||
| 574 | 575 | ssize_t (*write)(struct kernfs_open_file *of, |
| 575 | 576 | char *buf, size_t nbytes, loff_t off); |
| 576 | 577 | |
| 578 | + __poll_t (*poll)(struct kernfs_open_file *of, | |
| 579 | + struct poll_table_struct *pt); | |
| 580 | + | |
| 577 | 581 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 578 | 582 | struct lock_class_key lockdep_key; |
| 579 | 583 | #endif |
| @@ -3534,6 +3534,16 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, · 3533 unmodified lines | ||
| 3534 | 3534 | return ret ?: nbytes; |
| 3535 | 3535 | } |
| 3536 | 3536 | |
| 3537 | +static __poll_t cgroup_file_poll(struct kernfs_open_file *of, poll_table *pt) | |
| 3538 | +{ | |
| 3539 | + struct cftype *cft = of->kn->priv; | |
| 3540 | + | |
| 3541 | + if (cft->poll) | |
| 3542 | + return cft->poll(of, pt); | |
| 3543 | + | |
| 3544 | + return kernfs_generic_poll(of, pt); | |
| 3545 | +} | |
| 3546 | + | |
| 3537 | 3547 | static void *cgroup_seqfile_start(struct seq_file *seq, loff_t *ppos) |
| 3538 | 3548 | { |
| 3539 | 3549 | return seq_cft(seq)->seq_start(seq, ppos); |
| @@ -3572,6 +3582,7 @@ static struct kernfs_ops cgroup_kf_single_ops = { · 32 unmodified lines | ||
| 3572 | 3582 | .open = cgroup_file_open, |
| 3573 | 3583 | .release = cgroup_file_release, |
| 3574 | 3584 | .write = cgroup_file_write, |
| 3585 | + .poll = cgroup_file_poll, | |
| 3575 | 3586 | .seq_show = cgroup_seqfile_show, |
| 3576 | 3587 | }; |
| 3577 | 3588 | |
| @@ -3580,6 +3591,7 @@ static struct kernfs_ops cgroup_kf_ops = { · 2 unmodified lines | ||
| 3580 | 3591 | .open = cgroup_file_open, |
| 3581 | 3592 | .release = cgroup_file_release, |
| 3582 | 3593 | .write = cgroup_file_write, |
| 3594 | + .poll = cgroup_file_poll, | |
| 3583 | 3595 | .seq_start = cgroup_seqfile_start, |
| 3584 | 3596 | .seq_next = cgroup_seqfile_next, |
| 3585 | 3597 | .seq_stop = cgroup_seqfile_stop, |