Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

genirq: switch /proc/irq/*/smp_affinity et al to seqfiles

Switch /proc/irq/*/smp_affinity , /proc/irq/default_smp_affinity to
seq_files.

cat(1) reads with 1024 chunks by default, with high enough NR_CPUS, there
will be -EINVAL.

As side effect, there are now two less users of the ->read_proc interface.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Paul Jackson <pj@sgi.com>
Cc: Mike Travis <travis@sgi.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Alexey Dobriyan and committed by
Linus Torvalds
f18e439d 50ac2d69

+51 -45
+51 -45
kernel/irq/proc.c
··· 8 8 9 9 #include <linux/irq.h> 10 10 #include <linux/proc_fs.h> 11 + #include <linux/seq_file.h> 11 12 #include <linux/interrupt.h> 12 13 13 14 #include "internals.h" ··· 17 16 18 17 #ifdef CONFIG_SMP 19 18 20 - static int irq_affinity_read_proc(char *page, char **start, off_t off, 21 - int count, int *eof, void *data) 19 + static int irq_affinity_proc_show(struct seq_file *m, void *v) 22 20 { 23 - struct irq_desc *desc = irq_desc + (long)data; 21 + struct irq_desc *desc = irq_desc + (long)m->private; 24 22 cpumask_t *mask = &desc->affinity; 25 - int len; 26 23 27 24 #ifdef CONFIG_GENERIC_PENDING_IRQ 28 25 if (desc->status & IRQ_MOVE_PENDING) 29 26 mask = &desc->pending_mask; 30 27 #endif 31 - len = cpumask_scnprintf(page, count, *mask); 32 - 33 - if (count - len < 2) 34 - return -EINVAL; 35 - len += sprintf(page + len, "\n"); 36 - return len; 28 + seq_cpumask(m, mask); 29 + seq_putc(m, '\n'); 30 + return 0; 37 31 } 38 32 39 33 #ifndef is_affinity_mask_valid ··· 36 40 #endif 37 41 38 42 int no_irq_affinity; 39 - static int irq_affinity_write_proc(struct file *file, const char __user *buffer, 40 - unsigned long count, void *data) 43 + static ssize_t irq_affinity_proc_write(struct file *file, 44 + const char __user *buffer, size_t count, loff_t *pos) 41 45 { 42 - unsigned int irq = (int)(long)data, full_count = count, err; 46 + unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data; 43 47 cpumask_t new_value; 48 + int err; 44 49 45 50 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity || 46 51 irq_balancing_disabled(irq)) ··· 62 65 if (!cpus_intersects(new_value, cpu_online_map)) 63 66 /* Special case for empty set - allow the architecture 64 67 code to set default SMP affinity. */ 65 - return irq_select_affinity(irq) ? -EINVAL : full_count; 68 + return irq_select_affinity(irq) ? -EINVAL : count; 66 69 67 70 irq_set_affinity(irq, new_value); 68 71 69 - return full_count; 72 + return count; 70 73 } 71 74 72 - static int default_affinity_read(char *page, char **start, off_t off, 73 - int count, int *eof, void *data) 75 + static int irq_affinity_proc_open(struct inode *inode, struct file *file) 74 76 { 75 - int len = cpumask_scnprintf(page, count, irq_default_affinity); 76 - if (count - len < 2) 77 - return -EINVAL; 78 - len += sprintf(page + len, "\n"); 79 - return len; 77 + return single_open(file, irq_affinity_proc_show, PDE(inode)->data); 80 78 } 81 79 82 - static int default_affinity_write(struct file *file, const char __user *buffer, 83 - unsigned long count, void *data) 80 + static const struct file_operations irq_affinity_proc_fops = { 81 + .open = irq_affinity_proc_open, 82 + .read = seq_read, 83 + .llseek = seq_lseek, 84 + .release = single_release, 85 + .write = irq_affinity_proc_write, 86 + }; 87 + 88 + static int default_affinity_show(struct seq_file *m, void *v) 84 89 { 85 - unsigned int full_count = count, err; 90 + seq_cpumask(m, &irq_default_affinity); 91 + seq_putc(m, '\n'); 92 + return 0; 93 + } 94 + 95 + static ssize_t default_affinity_write(struct file *file, 96 + const char __user *buffer, size_t count, loff_t *ppos) 97 + { 86 98 cpumask_t new_value; 99 + int err; 87 100 88 101 err = cpumask_parse_user(buffer, count, new_value); 89 102 if (err) ··· 112 105 113 106 irq_default_affinity = new_value; 114 107 115 - return full_count; 108 + return count; 116 109 } 110 + 111 + static int default_affinity_open(struct inode *inode, struct file *file) 112 + { 113 + return single_open(file, default_affinity_show, NULL); 114 + } 115 + 116 + static const struct file_operations default_affinity_proc_fops = { 117 + .open = default_affinity_open, 118 + .read = seq_read, 119 + .llseek = seq_lseek, 120 + .release = single_release, 121 + .write = default_affinity_write, 122 + }; 117 123 #endif 118 124 119 125 static int irq_spurious_read(char *page, char **start, off_t off, ··· 198 178 irq_desc[irq].dir = proc_mkdir(name, root_irq_dir); 199 179 200 180 #ifdef CONFIG_SMP 201 - { 202 - /* create /proc/irq/<irq>/smp_affinity */ 203 - entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir); 204 - 205 - if (entry) { 206 - entry->data = (void *)(long)irq; 207 - entry->read_proc = irq_affinity_read_proc; 208 - entry->write_proc = irq_affinity_write_proc; 209 - } 210 - } 181 + /* create /proc/irq/<irq>/smp_affinity */ 182 + proc_create_data("smp_affinity", 0600, irq_desc[irq].dir, 183 + &irq_affinity_proc_fops, (void *)(long)irq); 211 184 #endif 212 185 213 186 entry = create_proc_entry("spurious", 0444, irq_desc[irq].dir); ··· 221 208 void register_default_affinity_proc(void) 222 209 { 223 210 #ifdef CONFIG_SMP 224 - struct proc_dir_entry *entry; 225 - 226 - /* create /proc/irq/default_smp_affinity */ 227 - entry = create_proc_entry("default_smp_affinity", 0600, root_irq_dir); 228 - if (entry) { 229 - entry->data = NULL; 230 - entry->read_proc = default_affinity_read; 231 - entry->write_proc = default_affinity_write; 232 - } 211 + proc_create("irq/default_smp_affinity", 0600, NULL, 212 + &default_affinity_proc_fops); 233 213 #endif 234 214 } 235 215