vfs: add file_path() helper
Subsystems (14)
PATCH 1/2 vfs: add file_path() helper
From: Miklos Szeredi <[email protected]>
Turn
d_path(&file->f_path, ...); into file_path(file, ...);
Signed-off-by Miklos Szeredi <[email protected]>
--- arch/arc/kernel/troubleshoot.c | 10 +++------- arch/blackfin/kernel/trace.c | 2 +- arch/tile/kernel/stack.c | 2 +- arch/tile/mm/elf.c | 2 +- drivers/block/loop.c | 2 +- drivers/md/bitmap.c | 2 +- drivers/md/md.c | 2 +- drivers/usb/gadget/function/f_mass_storage.c | 2 +- drivers/usb/gadget/function/storage_common.c | 2 +- fs/binfmt_elf.c | 4 ++-- fs/coredump.c | 2 +- fs/ext4/super.c | 2 +- fs/open.c | 6 ++++++ include/linux/fs.h | 2 ++ kernel/events/core.c | 2 +- mm/memory.c | 2 +- 16 files changed, 25 insertions(+), 21 deletions(-)
arch/arc/kernel/troubleshoot.c +3 -7
@@ -67,15 +67,12 @@ static void print_task_path_n_nm(structmmput (mm);if (exe_file) { - path = exe_file->f_path; -path_get (&exe_file->f_path); + path_nm =file_path (exe_file, buf,255 );fput (exe_file); - path_nm =d_path (&path, buf,255 ); -path_put (&path); } done: -pr_info ("Path: %s\n" , path_nm); +pr_info ("Path: %s\n" , !IS_ERR (path_nm) ? path_nm :"?" ); }static void show_faulting_vma (unsigned long address,char *buf)
@@ -99,8 +96,7 @@ static void show_faulting_vma(unsigned lif (vma && (vma->vm_start <= address)) {struct file *file = vma->vm_file;if (file) { -struct path *path = &file->f_path; - nm =d_path (path, buf,PAGE_SIZE -1 ); + nm =file_path (file, buf,PAGE_SIZE -1 ); inode =file_inode (vma->vm_file); dev = inode->i_sb->s_dev; ino = inode->i_ino;
arch/blackfin/kernel/trace.c +1 -1
@@ -136,7 +136,7 @@ void decode_address(char *buf, unsignedstruct file *file = vma->vm_file;if (file) { -char *d_name =d_path (&file->f_path, _tmpbuf, +char *d_name =file_path (file, _tmpbuf,sizeof (_tmpbuf));if (!IS_ERR (d_name)) name = d_name;
arch/tile/kernel/stack.c +1 -1
@@ -334,7 +334,7 @@ static void describe_addr(struct KBacktr }if (vma->vm_file) { - p =d_path (&vma->vm_file->f_path, buf, bufsize); + p =file_path (vma->vm_file, buf, bufsize);if (IS_ERR (p)) p ="?" ; name =kbasename (p);
arch/tile/mm/elf.c +1 -1
@@ -56,7 +56,7 @@ static int notify_exec(struct mm_structif (exe_file ==NULL ) goto done_free; - path =d_path (&exe_file->f_path, buf,PAGE_SIZE ); + path =file_path (exe_file, buf,PAGE_SIZE );if (IS_ERR (path)) goto done_put;
drivers/md/bitmap.c +1 -1
@@ -839,7 +839,7 @@ static void bitmap_file_kick(struct bitmif (bitmap->storage.file) { path =kmalloc (PAGE_SIZE ,GFP_KERNEL );if (path) - ptr =d_path (&bitmap->storage.file->f_path, + ptr =file_path (bitmap->storage.file, path,PAGE_SIZE ); printk(KERN_ALERT
include/linux/fs.h +2 -0
@@ -2501,6 +2501,8 @@ extern struct file * open_exec(const chaextern int is_subdir (struct dentry *,struct dentry *);extern int path_is_under (struct path *,struct path *); +extern char *file_path (struct file *,char *,int ); +#include <linux/err.h> /* needed for stackable file system support */
drivers/usb/gadget/function/f_mass_storage.c +1 -1
@@ -2936,7 +2936,7 @@ int fsg_common_create_lun(struct fsg_comif (fsg_lun_is_open (lun)) { p ="(error)" ;if (pathbuf) { - p =d_path (&lun->filp->f_path, pathbuf,PATH_MAX ); + p =file_path (lun->filp, pathbuf,PATH_MAX );if (IS_ERR (p)) p ="(error)" ; }
drivers/usb/gadget/function/storage_common.c +1 -1
@@ -341,7 +341,7 @@ ssize_t fsg_show_file(struct fsg_lun *cudown_read (filesem);if (fsg_lun_is_open (curlun)) {/* Get the complete pathname */ - p =d_path (&curlun->filp->f_path, buf,PAGE_SIZE -1 ); + p =file_path (curlun->filp, buf,PAGE_SIZE -1 );if (IS_ERR (p)) rc =PTR_ERR (p);else {
fs/binfmt_elf.c +2 -2
@@ -1530,7 +1530,7 @@ static int fill_files_note(struct memelf file = vma->vm_file;if (!file)continue ; - filename =d_path (&file->f_path, name_curpos, remaining); + filename =file_path (file, name_curpos, remaining);if (IS_ERR (filename)) {if (PTR_ERR (filename) == -ENAMETOOLONG ) {vfree (data);
@@ -1540,7 +1540,7 @@ static int fill_files_note(struct memelfcontinue ; } -/* d_path() fills at the end, move name down */ +/* file_path() fills at the end, move name down */ /* n = strlen(filename) + 1: */ n = (name_curpos + remaining) - filename; remaining = filename - name_curpos;
fs/coredump.c +1 -1
@@ -138,7 +138,7 @@ static int cn_print_exe_file(struct core goto put_exe_file; } - path =d_path (&exe_file->f_path, pathbuf,PATH_MAX ); + path =file_path (exe_file, pathbuf,PATH_MAX );if (IS_ERR (path)) { ret =PTR_ERR (path); goto free_buf;
fs/ext4/super.c +1 -1
@@ -451,7 +451,7 @@ void __ext4_error_file(struct file *file es =EXT4_SB (inode->i_sb)->s_es; es->s_last_error_ino =cpu_to_le32 (inode->i_ino);if (ext4_error_ratelimit (inode->i_sb)) { - path =d_path (&(file->f_path), pathname,sizeof (pathname)); + path =file_path (file, pathname,sizeof (pathname));if (IS_ERR (path)) path ="(unknown)" ;va_start (args, fmt);
kernel/events/core.c +1 -1
@@ -5812,7 +5812,7 @@ static void perf_event_mmap_event(struct* need to add enough zero bytes after the string to handle * the 64bit alignment we do later. */ - name =d_path (&file->f_path, buf,PATH_MAX -sizeof (u64)); + name =file_path (file, buf,PATH_MAX -sizeof (u64));if (IS_ERR (name)) { name ="//toolong" ; goto cpy_name;
mm/memory.c +1 -1
@@ -3724,7 +3724,7 @@ void print_vma_addr(char *prefix, unsignif (buf) {char *p; - p =d_path (&f->f_path, buf,PAGE_SIZE ); + p =file_path (f, buf,PAGE_SIZE );if (IS_ERR (p)) p ="?" ; printk("%s%s[%lx+%lx]", prefix, kbasename(p),
drivers/md/md.c +1 -1
@@ -5744,7 +5744,7 @@ static int get_bitmap_file(struct mddev/* bitmap disabled, zero the first byte and copy out */ if (!mddev->bitmap_info.file) file->pathname[0 ] ='\0' ; -else if ((ptr =d_path (&mddev->bitmap_info.file->f_path, +else if ((ptr =file_path (mddev->bitmap_info.file, file->pathname,sizeof (file->pathname))),IS_ERR (ptr)) err =PTR_ERR (ptr);
drivers/block/loop.c +1 -1
@@ -568,7 +568,7 @@ static ssize_t loop_attr_backing_file_shspin_lock_irq (&lo->lo_lock);if (lo->lo_backing_file) - p =d_path (&lo->lo_backing_file->f_path, buf,PAGE_SIZE -1 ); + p =file_path (lo->lo_backing_file, buf,PAGE_SIZE -1 );spin_unlock_irq (&lo->lo_lock);if (IS_ERR_OR_NULL (p))
fs/open.c +6 -0
@@ -853,6 +853,12 @@ struct file *dentry_open(const struct pa }EXPORT_SYMBOL (dentry_open); +char *file_path (struct file *filp,char *buf,int buflen) +{ +return d_path (&filp->f_path, buf, buflen); +} +EXPORT_SYMBOL (file_path); +/** * vfs_open - open the file at the given path * @path: path to open
PATCH 2/2 vfs: add seq_file_path() helper
From: Miklos Szeredi <[email protected]>
Turn
seq_path(..., &file->f_path, ...); into seq_file_path(..., file, ...);
Signed-off-by Miklos Szeredi <[email protected]>
--- drivers/md/bitmap.c | 2 +- fs/proc/nommu.c | 2 +- fs/proc/task_mmu.c | 4 ++-- fs/proc/task_nommu.c | 2 +- fs/seq_file.c | 14 ++++++++++++++ include/linux/seq_file.h | 1 + mm/swapfile.c | 2 +- 7 files changed, 21 insertions(+), 6 deletions(-)
drivers/md/bitmap.c +1 -1
@@ -1927,7 +1927,7 @@ void bitmap_status(struct seq_file *seq, chunk_kb ? "KB" : "B");if (bitmap->storage.file) {seq_printf (seq,", file: " ); -seq_path (seq, &bitmap->storage.file->f_path," \t\n" ); +seq_file_path (seq, bitmap->storage.file," \t\n" ); }seq_printf (seq,"\n" );
fs/proc/nommu.c +1 -1
@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_if (file) {seq_pad (m,' ' ); -seq_path (m, &file->f_path,"" ); +seq_file_path (m, file,"" ); }seq_putc (m,'\n' );
fs/proc/task_mmu.c +2 -2
@@ -310,7 +310,7 @@ show_map_vma(struct seq_file *m, struct*/ if (file) {seq_pad (m,' ' ); -seq_path (m, &file->f_path,"\n" ); +seq_file_path (m, file,"\n" ); goto done; }
@@ -1509,7 +1509,7 @@ static int show_numa_map(struct seq_fileif (file) {seq_puts (m," file=" ); -seq_path (m, &file->f_path,"\n\t= " ); +seq_file_path (m, file,"\n\t= " ); }else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {seq_puts (m," heap" ); }else {
fs/proc/task_nommu.c +1 -1
@@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_filif (file) {seq_pad (m,' ' ); -seq_path (m, &file->f_path,"" ); +seq_file_path (m, file,"" ); }else if (mm) {pid_t tid =pid_of_stack (priv, vma, is_pid);
fs/seq_file.c +14 -0
@@ -487,6 +487,20 @@ int seq_path(struct seq_file *m, const s }EXPORT_SYMBOL (seq_path); +/** +* seq_file_path - seq_file interface to print a pathname of a file +* @m: the seq_file handle +* @file: the struct file to print +* @esc: set of characters to escape in the output +* +* return the absolute path to the file. +*/ +int seq_file_path (struct seq_file *m,struct file *file,const char *esc) +{ +return seq_path (m, &file->f_path, esc); +} +EXPORT_SYMBOL (seq_file_path); +/* * Same as seq_path, but relative to supplied root. */
include/linux/seq_file.h +1 -0
@@ -123,6 +123,7 @@ __printf(2, 3) int seq_printf(struct seq __printf(2, 0) int seq_vprintf(struct seq_file *, const char *, va_list args);int seq_path (struct seq_file *,const struct path *,const char *); +int seq_file_path (struct seq_file *,struct file *,const char *);int seq_dentry (struct seq_file *,struct dentry *,const char *);int seq_path_root (struct seq_file *m,const struct path *path,const struct path *root,const char *esc);
mm/swapfile.c +1 -1
@@ -2032,7 +2032,7 @@ static int swap_show(struct seq_file *sw } file = si->swap_file; - len =seq_path (swap, &file->f_path," \t\n\\" ); + len =seq_file_path (swap, file," \t\n\\" ); seq_printf(swap, "%*s%s\t%u\t%u\t%d\n", len < 40 ? 40 - len : 1, " ", S_ISBLK(file_inode(file)->i_mode) ?
Al Viro
maintainerRe: [PATCH 2/2] vfs: add seq_file_path() helper
Quoted 6 lines · Miklos Szeredi
From: Miklos Szeredi <[email protected]>
Turn
seq_path(..., &file->f_path, ...); into seq_file_path(..., file, ...);
Both applied.
Re: [PATCH 2/2] vfs: add seq_file_path() helper
In reply to Miklos SzerediQuoted 8 lines · Miklos Szeredi
From: Miklos Szeredi <[email protected]>
Turn
seq_path(..., &file->f_path, ...); into seq_file_path(..., file, ...);Signed-off-by Miklos Szeredi <[email protected]>
Acked-by David Howells <[email protected]>
Al Viro
maintainerQuoted 6 lines · Miklos Szeredi
From: Miklos Szeredi <[email protected]>
Turn
d_path(&file->f_path, ...); into file_path(file, ...);
Makes sense.
Quoted 8 lines · Miklos Szeredi
From: Miklos Szeredi <[email protected]>
Turn
d_path(&file->f_path, ...); into file_path(file, ...);Signed-off-by Miklos Szeredi <[email protected]>
Acked-by David Howells <[email protected]>
fs/open.c struct file *dentry_open(const struct pa · line 860
Quoted 5 lines · Miklos Szeredi
fs/open.c +5
-0+char *file_path (struct file *filp,char *buf,int buflen) +{ +return d_path (&filp->f_path, buf, buflen); +} +EXPORT_SYMBOL (file_path);
Inline it?
David