* [PATCH] mtd: convert to seq_file interface
@ 2011-05-13 20:34 Alexey Dobriyan
2011-05-13 20:57 ` Mike Frysinger
2011-05-16 13:25 ` Artem Bityutskiy
0 siblings, 2 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2011-05-13 20:34 UTC (permalink / raw)
To: dwmw2; +Cc: akpm, linux-mtd
->read_proc interface is going away, switch to seq_file.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
drivers/mtd/mtdcore.c | 50 +++++++++++++++++++-------------------------------
1 file changed, 19 insertions(+), 31 deletions(-)
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -24,6 +24,7 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/ptrace.h>
+#include <linux/seq_file.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/major.h>
@@ -656,44 +657,32 @@ EXPORT_SYMBOL_GPL(default_mtd_writev);
static struct proc_dir_entry *proc_mtd;
-static inline int mtd_proc_info(char *buf, struct mtd_info *this)
-{
- return sprintf(buf, "mtd%d: %8.8llx %8.8x \"%s\"\n", this->index,
- (unsigned long long)this->size,
- this->erasesize, this->name);
-}
-
-static int mtd_read_proc (char *page, char **start, off_t off, int count,
- int *eof, void *data_unused)
+static int mtd_proc_show(struct seq_file *m, void *v)
{
struct mtd_info *mtd;
- int len, l;
- off_t begin = 0;
+ seq_puts(m, "dev: size erasesize name\n");
mutex_lock(&mtd_table_mutex);
-
- len = sprintf(page, "dev: size erasesize name\n");
mtd_for_each_device(mtd) {
- l = mtd_proc_info(page + len, mtd);
- len += l;
- if (len+begin > off+count)
- goto done;
- if (len+begin < off) {
- begin += len;
- len = 0;
- }
+ seq_printf(m, "mtd%d: %8.8llx %8.8x \"%s\"\n",
+ mtd->index, (unsigned long long)mtd->size,
+ mtd->erasesize, mtd->name);
}
-
- *eof = 1;
-
-done:
mutex_unlock(&mtd_table_mutex);
- if (off >= len+begin)
- return 0;
- *start = page + (off-begin);
- return ((count < begin+len-off) ? count : begin+len-off);
+ return 0;
}
+static int mtd_proc_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, mtd_proc_show, NULL);
+}
+
+static const struct file_operations mtd_proc_ops = {
+ .open = mtd_proc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
#endif /* CONFIG_PROC_FS */
/*====================================================================*/
@@ -734,8 +723,7 @@ static int __init init_mtd(void)
goto err_bdi3;
#ifdef CONFIG_PROC_FS
- if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
- proc_mtd->read_proc = mtd_read_proc;
+ proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
#endif /* CONFIG_PROC_FS */
return 0;
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mtd: convert to seq_file interface
2011-05-13 20:34 [PATCH] mtd: convert to seq_file interface Alexey Dobriyan
@ 2011-05-13 20:57 ` Mike Frysinger
2011-05-13 21:03 ` Alexey Dobriyan
2011-05-13 21:09 ` Alexey Dobriyan
2011-05-16 13:25 ` Artem Bityutskiy
1 sibling, 2 replies; 6+ messages in thread
From: Mike Frysinger @ 2011-05-13 20:57 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: linux-mtd, akpm, dwmw2
On Fri, May 13, 2011 at 16:34, Alexey Dobriyan wrote:
> ->read_proc interface is going away, switch to seq_file.
while i like converting to seq_file in general, i'm not sure this
conversion is correct ... or maybe it's just incomplete ?
> +static int mtd_proc_show(struct seq_file *m, void *v)
> {
> struct mtd_info *mtd;
>
> + seq_puts(m, "dev: size erasesize name\n");
> mutex_lock(&mtd_table_mutex);
> mtd_for_each_device(mtd) {
> + seq_printf(m, "mtd%d: %8.8llx %8.8x \"%s\"\n",
> + mtd->index, (unsigned long long)mtd->size,
> + mtd->erasesize, mtd->name);
> }
> mutex_unlock(&mtd_table_mutex);
> + return 0;
> }
this is the new version of the func. the old one handled
offsets/seeks while the new one doesnt seem to. am i mistaken ?
in particular, it seems like this is missing the seq_operations set of
funcs for walking the list of mtd devices ...
-mike
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mtd: convert to seq_file interface
2011-05-13 20:57 ` Mike Frysinger
@ 2011-05-13 21:03 ` Alexey Dobriyan
2011-05-13 21:09 ` Alexey Dobriyan
1 sibling, 0 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2011-05-13 21:03 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd, akpm, dwmw2
On Fri, May 13, 2011 at 04:57:41PM -0400, Mike Frysinger wrote:
> On Fri, May 13, 2011 at 16:34, Alexey Dobriyan wrote:
> > ->read_proc interface is going away, switch to seq_file.
>
> while i like converting to seq_file in general, i'm not sure this
> conversion is correct ... or maybe it's just incomplete ?
>
> > +static int mtd_proc_show(struct seq_file *m, void *v)
> > {
> > struct mtd_info *mtd;
> >
> > + seq_puts(m, "dev: size erasesize name\n");
> > mutex_lock(&mtd_table_mutex);
> > mtd_for_each_device(mtd) {
> > + seq_printf(m, "mtd%d: %8.8llx %8.8x \"%s\"\n",
> > + mtd->index, (unsigned long long)mtd->size,
> > + mtd->erasesize, mtd->name);
> > }
> > mutex_unlock(&mtd_table_mutex);
> > + return 0;
> > }
>
> this is the new version of the func. the old one handled
> offsets/seeks while the new one doesnt seem to. am i mistaken ?
seq_file does all this for developer, see fs/seq_file.c
All you have to do is to fill buffer with data, this is why it's so cool.
> in particular, it seems like this is missing the seq_operations set of
> funcs for walking the list of mtd devices ...
Yes and no.
seq_operations aren't mandatory, because it doesn't matter much
how exactly buffer is filled. In this case we go for simpler code.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mtd: convert to seq_file interface
2011-05-13 20:57 ` Mike Frysinger
2011-05-13 21:03 ` Alexey Dobriyan
@ 2011-05-13 21:09 ` Alexey Dobriyan
2011-05-13 21:10 ` Mike Frysinger
1 sibling, 1 reply; 6+ messages in thread
From: Alexey Dobriyan @ 2011-05-13 21:09 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd, akpm, dwmw2
On Fri, May 13, 2011 at 04:57:41PM -0400, Mike Frysinger wrote:
> On Fri, May 13, 2011 at 16:34, Alexey Dobriyan wrote:
> > ->read_proc interface is going away, switch to seq_file.
>
> while i like converting to seq_file in general, i'm not sure this
> conversion is correct ... or maybe it's just incomplete ?
>
> > +static int mtd_proc_show(struct seq_file *m, void *v)
> > {
> > struct mtd_info *mtd;
> >
> > + seq_puts(m, "dev: size erasesize name\n");
> > mutex_lock(&mtd_table_mutex);
> > mtd_for_each_device(mtd) {
> > + seq_printf(m, "mtd%d: %8.8llx %8.8x \"%s\"\n",
> > + mtd->index, (unsigned long long)mtd->size,
> > + mtd->erasesize, mtd->name);
> > }
> > mutex_unlock(&mtd_table_mutex);
> > + return 0;
> > }
>
> this is the new version of the func. the old one handled
> offsets/seeks while the new one doesnt seem to. am i mistaken ?
>
> in particular, it seems like this is missing the seq_operations set of
> funcs for walking the list of mtd devices ...
seq_operations are mostly needed when read(2) is going to be short
enough to not require walking full object list to fill necessary amount.
Seeing that bash reads 32 KB by default, we go for simpler code.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mtd: convert to seq_file interface
2011-05-13 21:09 ` Alexey Dobriyan
@ 2011-05-13 21:10 ` Mike Frysinger
0 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2011-05-13 21:10 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: linux-mtd, akpm, dwmw2
On Fri, May 13, 2011 at 17:09, Alexey Dobriyan wrote:
> On Fri, May 13, 2011 at 04:57:41PM -0400, Mike Frysinger wrote:
>> On Fri, May 13, 2011 at 16:34, Alexey Dobriyan wrote:
>> > ->read_proc interface is going away, switch to seq_file.
>>
>> while i like converting to seq_file in general, i'm not sure this
>> conversion is correct ... or maybe it's just incomplete ?
>>
>> > +static int mtd_proc_show(struct seq_file *m, void *v)
>> > {
>> > struct mtd_info *mtd;
>> >
>> > + seq_puts(m, "dev: size erasesize name\n");
>> > mutex_lock(&mtd_table_mutex);
>> > mtd_for_each_device(mtd) {
>> > + seq_printf(m, "mtd%d: %8.8llx %8.8x \"%s\"\n",
>> > + mtd->index, (unsigned long long)mtd->size,
>> > + mtd->erasesize, mtd->name);
>> > }
>> > mutex_unlock(&mtd_table_mutex);
>> > + return 0;
>> > }
>>
>> this is the new version of the func. the old one handled
>> offsets/seeks while the new one doesnt seem to. am i mistaken ?
>>
>> in particular, it seems like this is missing the seq_operations set of
>> funcs for walking the list of mtd devices ...
>
> seq_operations are mostly needed when read(2) is going to be short
> enough to not require walking full object list to fill necessary amount.
> Seeing that bash reads 32 KB by default, we go for simpler code.
np. thanks for the info. i can probably convert some of my code to
simpler seq_file logic ;).
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mtd: convert to seq_file interface
2011-05-13 20:34 [PATCH] mtd: convert to seq_file interface Alexey Dobriyan
2011-05-13 20:57 ` Mike Frysinger
@ 2011-05-16 13:25 ` Artem Bityutskiy
1 sibling, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2011-05-16 13:25 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: linux-mtd, akpm, dwmw2
On Fri, 2011-05-13 at 23:34 +0300, Alexey Dobriyan wrote:
> ->read_proc interface is going away, switch to seq_file.
>
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
>
> drivers/mtd/mtdcore.c | 50 +++++++++++++++++++-------------------------------
> 1 file changed, 19 insertions(+), 31 deletions(-)
Pushed to l2-mtd-2.6.git, thanks!
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-05-16 13:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-13 20:34 [PATCH] mtd: convert to seq_file interface Alexey Dobriyan
2011-05-13 20:57 ` Mike Frysinger
2011-05-13 21:03 ` Alexey Dobriyan
2011-05-13 21:09 ` Alexey Dobriyan
2011-05-13 21:10 ` Mike Frysinger
2011-05-16 13:25 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).