fs: consolidate dt_type() helper definitions
Subsystems (4)
PATCH 1/1 fs: consolidate dt_type() helper definitions
There are 4 functions named dt_type() in the kernel. Consolidate the 3 that are basically identical into one helper function in fs.h that takes a umode_t argument. The v9fs helper is renamed to distinguish it from the others.
--- fs/9p/vfs_dir.c | 6 +++--- fs/configfs/dir.c | 8 +------- fs/kernfs/dir.c | 8 +------- fs/libfs.c | 9 ++------- include/linux/fs.h | 6 ++++++ 5 files changed, 13 insertions(+), 24 deletions(-)
fs/9p/vfs_dir.c +3 -3
@@ -41,12 +41,12 @@ struct p9_rdir { };/** -* dt_type - return file type +* v9fs_dt_type - return file type * @mistat: mistat structure * */ -static inline int dt_type (struct p9_wstat *mistat) +static inline int v9fs_dt_type (struct p9_wstat *mistat) {unsigned long perm = mistat->mode;int rettype =DT_REG ;
@@ -128,7 +128,7 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) } over = !dir_emit (ctx, st.name,strlen (st.name), -v9fs_qid2ino (&st.qid),dt_type (&st)); +v9fs_qid2ino (&st.qid),v9fs_dt_type (&st));p9stat_free (&st);if (over)return 0 ;
fs/configfs/dir.c +1 -7
@@ -1599,12 +1599,6 @@ static int configfs_dir_close(struct inode *inode, struct file *file)return 0 ; } -/* Relationship between s_mode and the DT_xxx types */ -static inline unsigned char dt_type (struct configfs_dirent *sd) -{ -return (sd->s_mode >>12 ) &15 ; -} -static int configfs_readdir (struct file *file,struct dir_context *ctx) {struct dentry *dentry = file->f_path.dentry;
@@ -1654,7 +1648,7 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx) name =configfs_get_name (next); len =strlen (name); -if (!dir_emit (ctx, name, len, ino,dt_type (next))) +if (!dir_emit (ctx, name, len, ino,dt_type (next->s_mode)))return 0 ;spin_lock (&configfs_dirent_lock);
fs/kernfs/dir.c +1 -7
@@ -1748,12 +1748,6 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,return error; } -/* Relationship between mode and the DT_xxx types */ -static inline unsigned char dt_type (struct kernfs_node *kn) -{ -return (kn->mode >>12 ) &15 ; -} -static int kernfs_dir_fop_release (struct inode *inode,struct file *filp) {kernfs_put (filp->private_data);
@@ -1831,7 +1825,7 @@ static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx)pos ; pos = kernfs_dir_next_pos(ns, parent, ctx->pos, pos)) {const char *name = pos->name; -unsigned int type =dt_type (pos); +unsigned int type =dt_type (pos->mode);int len =strlen (name);ino_t ino =kernfs_ino (pos);
fs/libfs.c +2 -7
@@ -174,12 +174,6 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence) }EXPORT_SYMBOL (dcache_dir_lseek); -/* Relationship between i_mode and the DT_xxx types */ -static inline unsigned char dt_type (struct inode *inode) -{ -return (inode->i_mode >>12 ) &15 ; -} -/* * Directory is locked and all positive dentries in it are safe, since * for ramfs-type trees they can't go away without unlink() or rmdir(),
@@ -206,7 +200,8 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)while ((next =scan_positives (cursor, p,1 , next)) !=NULL ) {if (!dir_emit (ctx, next->d_name.name, next->d_name.len, -d_inode (next)->i_ino,dt_type (d_inode (next)))) +d_inode (next)->i_ino, +dt_type (d_inode (next)->i_mode)))break ; ctx->pos++; p = &next->d_child;
include/linux/fs.h +6 -0
@@ -2885,6 +2885,12 @@ extern void iterate_supers(void (*)(struct super_block *, void *), void *);extern void iterate_supers_type (struct file_system_type *,void (*)(struct super_block *,void *),void *); +/* Relationship between i_mode and the DT_xxx types */ +static inline unsigned char dt_type (umode_t mode) +{ +return (mode >>12 ) &15 ; +} +extern int dcache_dir_open (struct inode *,struct file *);extern int dcache_dir_close (struct inode *,struct file *);extern loff_t dcache_dir_lseek (struct file *,loff_t ,int );
Signature · 1 line
2.39.2
Re: [PATCH] consolidate dt_type() helper definitions
Quoted 11 lines · Jeff Layton
There are 4 functions named
dt_type()in the kernel. Consolidate the 3 that are basically identical into one helper function infs.hthat takes aumode_targument. The v9fs helper is renamed to distinguish it from the others.Cc Chuck Lever <[email protected]>Signed-off-by Jeff Layton <[email protected]>
One (non-blocking) comment below.
Quoted 120 lines
---
fs/9p/vfs_dir.c | 6 +++--- fs/configfs/dir.c | 8 +------- fs/kernfs/dir.c | 8 +------- fs/libfs.c | 9 ++------- include/linux/fs.h | 6 ++++++ 5 files changed, 13 insertions(+), 24 deletions(-)fs/9p/vfs_dir.c +3
-3@@ -41,12 +41,12 @@ struct p9_rdir { };/** -* dt_type - return file type +* v9fs_dt_type - return file type * @mistat: mistat structure * */ -static inline int dt_type (struct p9_wstat *mistat) +static inline int v9fs_dt_type (struct p9_wstat *mistat) {unsigned long perm = mistat->mode;int rettype =DT_REG ;@@ -128,7 +128,7 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) } over = !dir_emit (ctx, st.name,strlen (st.name), -v9fs_qid2ino (&st.qid),dt_type (&st)); +v9fs_qid2ino (&st.qid),v9fs_dt_type (&st));p9stat_free (&st);if (over)return 0 ;fs/configfs/dir.c +1
-7@@ -1599,12 +1599,6 @@ static int configfs_dir_close(struct inode *inode, struct file *file)return 0 ; } -/* Relationship between s_mode and the DT_xxx types */ -static inline unsigned char dt_type (struct configfs_dirent *sd) -{ -return (sd->s_mode >>12 ) &15 ; -} -static int configfs_readdir (struct file *file,struct dir_context *ctx) {struct dentry *dentry = file->f_path.dentry;@@ -1654,7 +1648,7 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx) name =configfs_get_name (next); len =strlen (name); -if (!dir_emit (ctx, name, len, ino,dt_type (next))) +if (!dir_emit (ctx, name, len, ino,dt_type (next->s_mode)))return 0 ;spin_lock (&configfs_dirent_lock);fs/kernfs/dir.c +1
-7@@ -1748,12 +1748,6 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,return error; } -/* Relationship between mode and the DT_xxx types */ -static inline unsigned char dt_type (struct kernfs_node *kn) -{ -return (kn->mode >>12 ) &15 ; -} -static int kernfs_dir_fop_release (struct inode *inode,struct file *filp) {kernfs_put (filp->private_data);@@ -1831,7 +1825,7 @@ static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx)pos ; pos = kernfs_dir_next_pos(ns, parent, ctx->pos, pos)) {const char *name = pos->name; -unsigned int type =dt_type (pos); +unsigned int type =dt_type (pos->mode);int len =strlen (name);ino_t ino =kernfs_ino (pos);fs/libfs.c +2
-7@@ -174,12 +174,6 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence) }EXPORT_SYMBOL (dcache_dir_lseek); -/* Relationship between i_mode and the DT_xxx types */ -static inline unsigned char dt_type (struct inode *inode) -{ -return (inode->i_mode >>12 ) &15 ; -} -/* * Directory is locked and all positive dentries in it are safe, since * for ramfs-type trees they can't go away without unlink() or rmdir(), @@ -206,7 +200,8 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)while ((next =scan_positives (cursor, p,1 , next)) !=NULL ) {if (!dir_emit (ctx, next->d_name.name, next->d_name.len, -d_inode (next)->i_ino,dt_type (d_inode (next)))) +d_inode (next)->i_ino, +dt_type (d_inode (next)->i_mode)))break ; ctx->pos++; p = &next->d_child;include/linux/fs.h +0
-0
include/linux/fs.h extern void iterate_supers(void (*)(struct super_block *, void *), void *); · line 2891
Quoted 7 lines
include/linux/fs.h +4
-0@@ -2885,6 +2885,12 @@ extern void iterate_supers(void (*)(struct super_block *, void *), void *);extern void iterate_supers_type (struct file_system_type *,void (*)(struct super_block *,void *),void *); +/* Relationship between i_mode and the DT_xxx types */ +static inline unsigned char dt_type (umode_t mode) +{ +return (mode >>12 ) &15 ;
Was wondering if there are appropriate symbolic constants that could be used instead of naked integers? NBD if not.
Quoted 8 lines
include/linux/fs.h +2
-0+} +extern int dcache_dir_open (struct inode *,struct file *);extern int dcache_dir_close (struct inode *,struct file *);extern loff_t dcache_dir_lseek (struct file *,loff_t ,int );Signature · 1 line
2.39.2
--
Chuck Lever
Re: [PATCH] consolidate dt_type() helper definitions
Quoted 139 lines · Chuck Lever III
Quoted 10 lines · Jeff Layton
There are 4 functions named
dt_type()in the kernel. Consolidate the 3 that are basically identical into one helper function infs.hthat takes aumode_targument. The v9fs helper is renamed to distinguish it from the others.Cc Chuck Lever <[email protected]>Signed-off-by Jeff Layton <[email protected]>Reviewed-by Chuck Lever <[email protected]>One (non-blocking) comment below.
Quoted 123 lines
---
fs/9p/vfs_dir.c | 6 +++--- fs/configfs/dir.c | 8 +------- fs/kernfs/dir.c | 8 +------- fs/libfs.c | 9 ++------- include/linux/fs.h | 6 ++++++ 5 files changed, 13 insertions(+), 24 deletions(-)fs/9p/vfs_dir.c +3
-3@@ -41,12 +41,12 @@ struct p9_rdir { };/** -* dt_type - return file type +* v9fs_dt_type - return file type * @mistat: mistat structure * */ -static inline int dt_type (struct p9_wstat *mistat) +static inline int v9fs_dt_type (struct p9_wstat *mistat) {unsigned long perm = mistat->mode;int rettype =DT_REG ;@@ -128,7 +128,7 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) } over = !dir_emit (ctx, st.name,strlen (st.name), -v9fs_qid2ino (&st.qid),dt_type (&st)); +v9fs_qid2ino (&st.qid),v9fs_dt_type (&st));p9stat_free (&st);if (over)return 0 ;fs/configfs/dir.c +1
-7@@ -1599,12 +1599,6 @@ static int configfs_dir_close(struct inode *inode, struct file *file)return 0 ; } -/* Relationship between s_mode and the DT_xxx types */ -static inline unsigned char dt_type (struct configfs_dirent *sd) -{ -return (sd->s_mode >>12 ) &15 ; -} -static int configfs_readdir (struct file *file,struct dir_context *ctx) {struct dentry *dentry = file->f_path.dentry;@@ -1654,7 +1648,7 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx) name =configfs_get_name (next); len =strlen (name); -if (!dir_emit (ctx, name, len, ino,dt_type (next))) +if (!dir_emit (ctx, name, len, ino,dt_type (next->s_mode)))return 0 ;spin_lock (&configfs_dirent_lock);fs/kernfs/dir.c +1
-7@@ -1748,12 +1748,6 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,return error; } -/* Relationship between mode and the DT_xxx types */ -static inline unsigned char dt_type (struct kernfs_node *kn) -{ -return (kn->mode >>12 ) &15 ; -} -static int kernfs_dir_fop_release (struct inode *inode,struct file *filp) {kernfs_put (filp->private_data);@@ -1831,7 +1825,7 @@ static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx)pos ; pos = kernfs_dir_next_pos(ns, parent, ctx->pos, pos)) {const char *name = pos->name; -unsigned int type =dt_type (pos); +unsigned int type =dt_type (pos->mode);int len =strlen (name);ino_t ino =kernfs_ino (pos);fs/libfs.c +2
-7@@ -174,12 +174,6 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence) }EXPORT_SYMBOL (dcache_dir_lseek); -/* Relationship between i_mode and the DT_xxx types */ -static inline unsigned char dt_type (struct inode *inode) -{ -return (inode->i_mode >>12 ) &15 ; -} -/* * Directory is locked and all positive dentries in it are safe, since * for ramfs-type trees they can't go away without unlink() or rmdir(), @@ -206,7 +200,8 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)while ((next =scan_positives (cursor, p,1 , next)) !=NULL ) {if (!dir_emit (ctx, next->d_name.name, next->d_name.len, -d_inode (next)->i_ino,dt_type (d_inode (next)))) +d_inode (next)->i_ino, +dt_type (d_inode (next)->i_mode)))break ; ctx->pos++; p = &next->d_child;include/linux/fs.h +0
-0@@ -2885,6 +2885,12 @@ extern void iterate_supers(void (*)(struct super_block *, void *), void *);extern void iterate_supers_type (struct file_system_type *,void (*)(struct super_block *,void *),void *);
Quoted 8 lines
include/linux/fs.h extern void iterate_supers(void (*)(struct super_block *, void *), void *); · line 2891
Quoted 4 lines
include/linux/fs.h +4
-0+/* Relationship between i_mode and the DT_xxx types */ +static inline unsigned char dt_type (umode_t mode) +{ +return (mode >>12 ) &15 ;Was wondering if there are appropriate symbolic constants that could be used instead of naked integers? NBD if not.
If there is a way to express that with well-known constants, I don't know it. It looks like Linus added this to libfs.c back in 2002 (from linux-fullhistory tree):
commit a12662634bf285a5350a2106301e754652875d2f
Author: Linus Torvalds <[email protected]> Date: Tue Jul 2 01:37:41 2002 -0700
Make ramfs/driverfs maintain directory nlink counts.
Make dcache filesystems export directory entry types to readdir.
Linus, are there symbolic constants that you know of that we could use here instead?
Quoted 14 lines
Quoted 9 lines
include/linux/fs.h +2
-0+} +extern int dcache_dir_open (struct inode *,struct file *);extern int dcache_dir_close (struct inode *,struct file *);extern loff_t dcache_dir_lseek (struct file *,loff_t ,int );Signature · 1 line
2.39.2--
Chuck Lever
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 7 lines · Jeff Layton
There are 4 functions named
dt_type()in the kernel. Consolidate the 3 that are basically identical into one helper function infs.hthat takes aumode_targument. The v9fs helper is renamed to distinguish it from the others.Cc Chuck Lever <[email protected]>Signed-off-by Jeff Layton <[email protected]>
Quoted 7 lines
--- fs/9p/vfs_dir.c | 6 +++--- fs/configfs/dir.c | 8 +------- fs/kernfs/dir.c | 8 +------- fs/libfs.c | 9 ++------- include/linux/fs.h | 6 ++++++ 5 files changed, 13 insertions(+), 24 deletions(-)