Skip to contentSkip to conversation

fs: consolidate duplicate dt_type helpers

PATCH In review Jeff Layton 3 participants 8 messages Mar 30, 2023 – Apr 3, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: consolidate duplicate dt_type helpers

There are three copies of the same dt_type helper sprinkled around the tree. Convert them to use the common fs_umode_to_dtype function instead, which has the added advantage of properly returning DT_UNKNOWN when given a mode that contains an unrecognized type.

---
 fs/configfs/dir.c | 9 ++-------
 fs/kernfs/dir.c   | 8 +-------
 fs/libfs.c        | 9 ++-------
 3 files changed, 5 insertions(+), 21 deletions(-)

v2: consolidate S_DT helper as well
v3: switch existing dt_type helpers to use fs_umode_to_dtype
drop v9fs hunks since they're no longer needed

fs/configfs/dir.c +2 -7
index 4afcbbe63e68..18677cd4e62f 100644
@@ -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,8 @@ 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,
+			      fs_umode_to_dtype(next->s_mode)))
 			return 0;
 
 		spin_lock(&configfs_dirent_lock);
fs/kernfs/dir.c +1 -7
index ef00b5fe8cee..90de0e498371 100644
@@ -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 = fs_umode_to_dtype(pos->mode);
 		int len = strlen(name);
 		ino_t ino = kernfs_ino(pos);
 
fs/libfs.c +2 -7
index 4eda519c3002..89cf614a3271 100644
@@ -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,
+			      fs_umode_to_dtype(d_inode(next)->i_mode)))
 			break;
 		ctx->pos++;
 		p = &next->d_child;
Signature · 1 line
2.39.2
#1 lore raw
Quoted 15 lines · Jeff Layton

There are three copies of the same dt_type helper sprinkled around the tree. Convert them to use the common fs_umode_to_dtype function instead, which has the added advantage of properly returning DT_UNKNOWN when given a mode that contains an unrecognized type.

---
 fs/configfs/dir.c | 9 ++-------
 fs/kernfs/dir.c   | 8 +-------
 fs/libfs.c        | 9 ++-------
 3 files changed, 5 insertions(+), 21 deletions(-)
Quoted 3 lines

v2: consolidate S_DT helper as well
v3: switch existing dt_type helpers to use fs_umode_to_dtype
drop v9fs hunks since they're no longer needed

You forgot the "v3" in the subject line :(

#2 lore raw
Quoted 16 lines · Greg Kroah-Hartman
Quoted 15 lines · Jeff Layton

There are three copies of the same dt_type helper sprinkled around the tree. Convert them to use the common fs_umode_to_dtype function instead, which has the added advantage of properly returning DT_UNKNOWN when given a mode that contains an unrecognized type.

---
 fs/configfs/dir.c | 9 ++-------
 fs/kernfs/dir.c   | 8 +-------
 fs/libfs.c        | 9 ++-------
 3 files changed, 5 insertions(+), 21 deletions(-)
Quoted 6 lines
Quoted 3 lines

v2: consolidate S_DT helper as well
v3: switch existing dt_type helpers to use fs_umode_to_dtype
drop v9fs hunks since they're no longer needed

You forgot the "v3" in the subject line :(

Yeah, I noticed, sorry. It's the attention to detail that makes me such a successful kernel developer! ;)

Signature · 1 line
Jeff Layton <[email protected]>
#3 lore raw
Quoted 21 lines · Jeff Layton
Quoted 20 lines · Greg Kroah-Hartman
Quoted 18 lines · Jeff Layton

There are three copies of the same dt_type helper sprinkled around the tree. Convert them to use the common fs_umode_to_dtype function instead, which has the added advantage of properly returning DT_UNKNOWN when given a mode that contains an unrecognized type.

---
 fs/configfs/dir.c | 9 ++-------
 fs/kernfs/dir.c   | 8 +-------
 fs/libfs.c        | 9 ++-------
 3 files changed, 5 insertions(+), 21 deletions(-)

v2: consolidate S_DT helper as well
v3: switch existing dt_type helpers to use fs_umode_to_dtype
drop v9fs hunks since they're no longer needed

Quoted 5 lines
Quoted 2 lines

You forgot the "v3" in the subject line :(

Yeah, I noticed, sorry. It's the attention to detail that makes me such a successful kernel developer! ;)

/me hides from his own syzbot "good morning" message from earlier today...

But honestly, I don't think it's worth resending just to add v3.

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Jeff Layton
Quoted 10 lines · Jeff Layton

There are three copies of the same dt_type helper sprinkled around the tree. Convert them to use the common fs_umode_to_dtype function instead, which has the added advantage of properly returning DT_UNKNOWN when given a mode that contains an unrecognized type.

---

Looks good to me,

#5 lore raw
In reply to Jeff Layton
Quoted 10 lines · Jeff Layton

There are three copies of the same dt_type helper sprinkled around the tree. Convert them to use the common fs_umode_to_dtype function instead, which has the added advantage of properly returning DT_UNKNOWN when given a mode that contains an unrecognized type.

---

Greg, Christoph, if you have a minute could you please take a look again and re-add your acks?

maintainer Acked-by
#6 lore raw
Quoted 6 lines · Christian Brauner
Quoted 5 lines · Jeff Layton

There are three copies of the same dt_type helper sprinkled around the tree. Convert them to use the common fs_umode_to_dtype function instead, which has the added advantage of properly returning DT_UNKNOWN when given a mode that contains an unrecognized type.

Quoted 8 lines
Quoted 5 lines

---

Greg, Christoph, if you have a minute could you please take a look again and re-add your acks?

#7 lore raw
In reply to Jeff Layton
Quoted 6 lines · Jeff Layton

There are three copies of the same dt_type helper sprinkled around the tree. Convert them to use the common fs_umode_to_dtype function instead, which has the added advantage of properly returning DT_UNKNOWN when given a mode that contains an unrecognized type.

I've picked this up now,

tree: git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping.git
branch: fs.misc
[1/1] fs: consolidate duplicate dt_type helpers

      commit: 364595a6851bf64e1c38224ae68f5dd6651906d1