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 | struct kernfs_ops; | 32 | struct kernfs_ops; |
| 33 | struct kernfs_open_file; | 33 | struct kernfs_open_file; |
| 34 | struct seq_file; | 34 | struct seq_file; |
| 35 | struct poll_table_struct; | ||
| 35 | 36 | ||
| 36 | #define MAX_CGROUP_TYPE_NAMELEN 32 | 37 | #define MAX_CGROUP_TYPE_NAMELEN 32 |
| 37 | #define MAX_CGROUP_ROOT_NAMELEN 64 | 38 | #define MAX_CGROUP_ROOT_NAMELEN 64 |
| @@ -574,6 +575,9 @@ struct cftype { · 536 unmodified lines | |||
| 574 | ssize_t (*write)(struct kernfs_open_file *of, | 575 | ssize_t (*write)(struct kernfs_open_file *of, |
| 575 | char *buf, size_t nbytes, loff_t off); | 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 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 581 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 578 | struct lock_class_key lockdep_key; | 582 | struct lock_class_key lockdep_key; |
| 579 | #endif | 583 | #endif |
| @@ -3534,6 +3534,16 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, · 3533 unmodified lines | |||
| 3534 | return ret ?: nbytes; | 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 | static void *cgroup_seqfile_start(struct seq_file *seq, loff_t *ppos) | 3547 | static void *cgroup_seqfile_start(struct seq_file *seq, loff_t *ppos) |
| 3538 | { | 3548 | { |
| 3539 | return seq_cft(seq)->seq_start(seq, ppos); | 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 | .open = cgroup_file_open, | 3582 | .open = cgroup_file_open, |
| 3573 | .release = cgroup_file_release, | 3583 | .release = cgroup_file_release, |
| 3574 | .write = cgroup_file_write, | 3584 | .write = cgroup_file_write, |
| 3585 | .poll = cgroup_file_poll, | ||
| 3575 | .seq_show = cgroup_seqfile_show, | 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 | .open = cgroup_file_open, | 3591 | .open = cgroup_file_open, |
| 3581 | .release = cgroup_file_release, | 3592 | .release = cgroup_file_release, |
| 3582 | .write = cgroup_file_write, | 3593 | .write = cgroup_file_write, |
| 3594 | .poll = cgroup_file_poll, | ||
| 3583 | .seq_start = cgroup_seqfile_start, | 3595 | .seq_start = cgroup_seqfile_start, |
| 3584 | .seq_next = cgroup_seqfile_next, | 3596 | .seq_next = cgroup_seqfile_next, |
| 3585 | .seq_stop = cgroup_seqfile_stop, | 3597 | .seq_stop = cgroup_seqfile_stop, |