History

kernel: cgroup: add poll file operation

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.

Johannes Weiner committed 7 years ago

Commit dc505371 parent 147e1a92 files · +16 −0Browse files

Unified · Split

2 files
  1. include/linux/cgroup-defs.h +4 −0
  2. kernel/cgroup/cgroup.c +12 −0
include/linux/cgroup-defs.h+4−0
@@ -32,6 +32,7 @@ struct kernfs_node; · 31 unmodified lines
3232 struct kernfs_ops;
3333 struct kernfs_open_file;
3434 struct seq_file;
35+struct poll_table_struct;
3536
3637 #define MAX_CGROUP_TYPE_NAMELEN 32
3738 #define MAX_CGROUP_ROOT_NAMELEN 64
@@ -574,6 +575,9 @@ struct cftype { · 536 unmodified lines
574575 ssize_t (*write)(struct kernfs_open_file *of,
575576 char *buf, size_t nbytes, loff_t off);
576577
578+ __poll_t (*poll)(struct kernfs_open_file *of,
579+ struct poll_table_struct *pt);
580+
577581 #ifdef CONFIG_DEBUG_LOCK_ALLOC
578582 struct lock_class_key lockdep_key;
579583 #endif
kernel/cgroup/cgroup.c+12−0
@@ -3534,6 +3534,16 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, · 3533 unmodified lines
35343534 return ret ?: nbytes;
35353535 }
35363536
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+
35373547 static void *cgroup_seqfile_start(struct seq_file *seq, loff_t *ppos)
35383548 {
35393549 return seq_cft(seq)->seq_start(seq, ppos);
@@ -3572,6 +3582,7 @@ static struct kernfs_ops cgroup_kf_single_ops = { · 32 unmodified lines
35723582 .open = cgroup_file_open,
35733583 .release = cgroup_file_release,
35743584 .write = cgroup_file_write,
3585+ .poll = cgroup_file_poll,
35753586 .seq_show = cgroup_seqfile_show,
35763587 };
35773588
@@ -3580,6 +3591,7 @@ static struct kernfs_ops cgroup_kf_ops = { · 2 unmodified lines
35803591 .open = cgroup_file_open,
35813592 .release = cgroup_file_release,
35823593 .write = cgroup_file_write,
3594+ .poll = cgroup_file_poll,
35833595 .seq_start = cgroup_seqfile_start,
35843596 .seq_next = cgroup_seqfile_next,
35853597 .seq_stop = cgroup_seqfile_stop,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t