mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-11-18 07:35:12 +08:00
fs: seq_file - add event counter to simplify poll() support
Moving the event counter into the dynamically allocated 'struc seq_file' allows poll() support without the need to allocate its own tracking structure. All current users are switched over to use the new counter. Requested-by: Andrew Morton akpm@linux-foundation.org Acked-by: NeilBrown <neilb@suse.de> Tested-by: Lucas De Marchi lucas.demarchi@profusion.mobi Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
72c5052ddc
commit
f15146380d
@ -6394,16 +6394,11 @@ static void md_seq_stop(struct seq_file *seq, void *v)
|
|||||||
mddev_put(mddev);
|
mddev_put(mddev);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mdstat_info {
|
|
||||||
int event;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int md_seq_show(struct seq_file *seq, void *v)
|
static int md_seq_show(struct seq_file *seq, void *v)
|
||||||
{
|
{
|
||||||
mddev_t *mddev = v;
|
mddev_t *mddev = v;
|
||||||
sector_t sectors;
|
sector_t sectors;
|
||||||
mdk_rdev_t *rdev;
|
mdk_rdev_t *rdev;
|
||||||
struct mdstat_info *mi = seq->private;
|
|
||||||
struct bitmap *bitmap;
|
struct bitmap *bitmap;
|
||||||
|
|
||||||
if (v == (void*)1) {
|
if (v == (void*)1) {
|
||||||
@ -6415,7 +6410,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
|
|||||||
|
|
||||||
spin_unlock(&pers_lock);
|
spin_unlock(&pers_lock);
|
||||||
seq_printf(seq, "\n");
|
seq_printf(seq, "\n");
|
||||||
mi->event = atomic_read(&md_event_count);
|
seq->poll_event = atomic_read(&md_event_count);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (v == (void*)2) {
|
if (v == (void*)2) {
|
||||||
@ -6527,26 +6522,21 @@ static const struct seq_operations md_seq_ops = {
|
|||||||
|
|
||||||
static int md_seq_open(struct inode *inode, struct file *file)
|
static int md_seq_open(struct inode *inode, struct file *file)
|
||||||
{
|
{
|
||||||
|
struct seq_file *seq;
|
||||||
int error;
|
int error;
|
||||||
struct mdstat_info *mi = kmalloc(sizeof(*mi), GFP_KERNEL);
|
|
||||||
if (mi == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
error = seq_open(file, &md_seq_ops);
|
error = seq_open(file, &md_seq_ops);
|
||||||
if (error)
|
if (error)
|
||||||
kfree(mi);
|
return error;
|
||||||
else {
|
|
||||||
struct seq_file *p = file->private_data;
|
seq = file->private_data;
|
||||||
p->private = mi;
|
seq->poll_event = atomic_read(&md_event_count);
|
||||||
mi->event = atomic_read(&md_event_count);
|
|
||||||
}
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
|
static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
|
||||||
{
|
{
|
||||||
struct seq_file *m = filp->private_data;
|
struct seq_file *seq = filp->private_data;
|
||||||
struct mdstat_info *mi = m->private;
|
|
||||||
int mask;
|
int mask;
|
||||||
|
|
||||||
poll_wait(filp, &md_event_waiters, wait);
|
poll_wait(filp, &md_event_waiters, wait);
|
||||||
@ -6554,7 +6544,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
|
|||||||
/* always allow read */
|
/* always allow read */
|
||||||
mask = POLLIN | POLLRDNORM;
|
mask = POLLIN | POLLRDNORM;
|
||||||
|
|
||||||
if (mi->event != atomic_read(&md_event_count))
|
if (seq->poll_event != atomic_read(&md_event_count))
|
||||||
mask |= POLLERR | POLLPRI;
|
mask |= POLLERR | POLLPRI;
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
@ -934,8 +934,8 @@ int mnt_had_events(struct proc_mounts *p)
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
br_read_lock(vfsmount_lock);
|
br_read_lock(vfsmount_lock);
|
||||||
if (p->event != ns->event) {
|
if (p->m.poll_event != ns->event) {
|
||||||
p->event = ns->event;
|
p->m.poll_event = ns->event;
|
||||||
res = 1;
|
res = 1;
|
||||||
}
|
}
|
||||||
br_read_unlock(vfsmount_lock);
|
br_read_unlock(vfsmount_lock);
|
||||||
|
@ -673,7 +673,7 @@ static int mounts_open_common(struct inode *inode, struct file *file,
|
|||||||
p->m.private = p;
|
p->m.private = p;
|
||||||
p->ns = ns;
|
p->ns = ns;
|
||||||
p->root = root;
|
p->root = root;
|
||||||
p->event = ns->event;
|
p->m.poll_event = ns->event;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ struct proc_mounts {
|
|||||||
struct seq_file m; /* must be the first element */
|
struct seq_file m; /* must be the first element */
|
||||||
struct mnt_namespace *ns;
|
struct mnt_namespace *ns;
|
||||||
struct path root;
|
struct path root;
|
||||||
int event;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fs_struct;
|
struct fs_struct;
|
||||||
|
@ -23,6 +23,7 @@ struct seq_file {
|
|||||||
u64 version;
|
u64 version;
|
||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
const struct seq_operations *op;
|
const struct seq_operations *op;
|
||||||
|
int poll_event;
|
||||||
void *private;
|
void *private;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1681,19 +1681,14 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
||||||
struct proc_swaps {
|
|
||||||
struct seq_file seq;
|
|
||||||
int event;
|
|
||||||
};
|
|
||||||
|
|
||||||
static unsigned swaps_poll(struct file *file, poll_table *wait)
|
static unsigned swaps_poll(struct file *file, poll_table *wait)
|
||||||
{
|
{
|
||||||
struct proc_swaps *s = file->private_data;
|
struct seq_file *seq = file->private_data;
|
||||||
|
|
||||||
poll_wait(file, &proc_poll_wait, wait);
|
poll_wait(file, &proc_poll_wait, wait);
|
||||||
|
|
||||||
if (s->event != atomic_read(&proc_poll_event)) {
|
if (seq->poll_event != atomic_read(&proc_poll_event)) {
|
||||||
s->event = atomic_read(&proc_poll_event);
|
seq->poll_event = atomic_read(&proc_poll_event);
|
||||||
return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
|
return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1783,24 +1778,16 @@ static const struct seq_operations swaps_op = {
|
|||||||
|
|
||||||
static int swaps_open(struct inode *inode, struct file *file)
|
static int swaps_open(struct inode *inode, struct file *file)
|
||||||
{
|
{
|
||||||
struct proc_swaps *s;
|
struct seq_file *seq;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
s = kmalloc(sizeof(struct proc_swaps), GFP_KERNEL);
|
|
||||||
if (!s)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
file->private_data = s;
|
|
||||||
|
|
||||||
ret = seq_open(file, &swaps_op);
|
ret = seq_open(file, &swaps_op);
|
||||||
if (ret) {
|
if (ret)
|
||||||
kfree(s);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
s->seq.private = s;
|
seq = file->private_data;
|
||||||
s->event = atomic_read(&proc_poll_event);
|
seq->poll_event = atomic_read(&proc_poll_event);
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations proc_swaps_operations = {
|
static const struct file_operations proc_swaps_operations = {
|
||||||
|
Loading…
Reference in New Issue
Block a user