Skip to content

Commit

Permalink
Merge tag 'trace-seq-file-cleanup' of git://git.kernel.org/pub/scm/li…
Browse files Browse the repository at this point in the history
…nux/kernel/git/rostedt/linux-trace into for-next

Pull the beginning of seq_file cleanup from Steven:
  "I'm looking to clean up the seq_file code and to eventually merge the
  trace_seq code with seq_file as well, since they basically do the same thing.

  Part of this process is to remove the return code of seq_printf() and friends
  as they are rather inconsistent. It is better to use the new function
  seq_has_overflowed() if you want to stop processing when the buffer
  is full. Note, if the buffer is full, the seq_file code will throw away
  the contents, allocate a bigger buffer, and then call your code again
  to fill in the data. The only thing that breaking out of the function
  early does is to save a little time which is probably never noticed.

  I started with patches from Joe Perches and modified them as well.
  There's many more places that need to be updated before we can convert
  seq_printf() and friends to return void. But this patch set introduces
  the seq_has_overflowed() and does some initial updates."
  • Loading branch information
Al Viro committed Nov 19, 2014
2 parents 78d28e6 + 9761536 commit 8ce74dd
Show file tree
Hide file tree
Showing 38 changed files with 410 additions and 437 deletions.
2 changes: 1 addition & 1 deletion Documentation/filesystems/debugfs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ file.
struct dentry *parent,
struct debugfs_regset32 *regset);

int debugfs_print_regs32(struct seq_file *s, struct debugfs_reg32 *regs,
void debugfs_print_regs32(struct seq_file *s, struct debugfs_reg32 *regs,
int nregs, void __iomem *base, char *prefix);

The "base" argument may be 0, but you may want to build the reg32 array
Expand Down
22 changes: 13 additions & 9 deletions Documentation/filesystems/seq_file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,19 @@ output must be passed to the seq_file code. Some utility functions have
been defined which make this task easy.

Most code will simply use seq_printf(), which works pretty much like
printk(), but which requires the seq_file pointer as an argument. It is
common to ignore the return value from seq_printf(), but a function
producing complicated output may want to check that value and quit if
something non-zero is returned; an error return means that the seq_file
buffer has been filled and further output will be discarded.
printk(), but which requires the seq_file pointer as an argument.

For straight character output, the following functions may be used:

int seq_putc(struct seq_file *m, char c);
int seq_puts(struct seq_file *m, const char *s);
int seq_escape(struct seq_file *m, const char *s, const char *esc);
seq_putc(struct seq_file *m, char c);
seq_puts(struct seq_file *m, const char *s);
seq_escape(struct seq_file *m, const char *s, const char *esc);

The first two output a single character and a string, just like one would
expect. seq_escape() is like seq_puts(), except that any character in s
which is in the string esc will be represented in octal form in the output.

There is also a pair of functions for printing filenames:
There are also a pair of functions for printing filenames:

int seq_path(struct seq_file *m, struct path *path, char *esc);
int seq_path_root(struct seq_file *m, struct path *path,
Expand All @@ -209,6 +205,14 @@ root is desired, it can be used with seq_path_root(). Note that, if it
turns out that path cannot be reached from root, the value of root will be
changed in seq_file_root() to a root which *does* work.

A function producing complicated output may want to check
bool seq_has_overflowed(struct seq_file *m);
and avoid further seq_<output> calls if true is returned.

A true return from seq_has_overflowed means that the seq_file buffer will
be discarded and the seq_show function will attempt to allocate a larger
buffer and retry printing.


Making it all work

Expand Down
2 changes: 1 addition & 1 deletion Documentation/filesystems/vfs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ struct file_operations {
ssize_t (*splice_read)(struct file *, struct pipe_inode_info *, size_t, unsigned int);
int (*setlease)(struct file *, long arg, struct file_lock **, void **);
long (*fallocate)(struct file *, int mode, loff_t offset, loff_t len);
int (*show_fdinfo)(struct seq_file *m, struct file *f);
void (*show_fdinfo)(struct seq_file *m, struct file *f);
};

Again, all methods are called without any locks being held, unless
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -2209,7 +2209,7 @@ static int tun_chr_close(struct inode *inode, struct file *file)
}

#ifdef CONFIG_PROC_FS
static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
static void tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
{
struct tun_struct *tun;
struct ifreq ifr;
Expand All @@ -2225,7 +2225,7 @@ static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
if (tun)
tun_put(tun);

return seq_printf(m, "iff:\t%s\n", ifr.ifr_name);
seq_printf(m, "iff:\t%s\n", ifr.ifr_name);
}
#endif

Expand Down
15 changes: 8 additions & 7 deletions fs/debugfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,18 +692,19 @@ EXPORT_SYMBOL_GPL(debugfs_create_u32_array);
* because some peripherals have several blocks of identical registers,
* for example configuration of dma channels
*/
int debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
int nregs, void __iomem *base, char *prefix)
void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
int nregs, void __iomem *base, char *prefix)
{
int i, ret = 0;
int i;

for (i = 0; i < nregs; i++, regs++) {
if (prefix)
ret += seq_printf(s, "%s", prefix);
ret += seq_printf(s, "%s = 0x%08x\n", regs->name,
readl(base + regs->offset));
seq_printf(s, "%s", prefix);
seq_printf(s, "%s = 0x%08x\n", regs->name,
readl(base + regs->offset));
if (seq_has_overflowed(s))
break;
}
return ret;
}
EXPORT_SYMBOL_GPL(debugfs_print_regs32);

Expand Down
Loading

0 comments on commit 8ce74dd

Please sign in to comment.