linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Theodore Ts'o <tytso@mit.edu>, Dave Chinner <david@fromorbit.com>,
	Chris Mason <clm@fb.com>
Cc: Jan Kara <jack@suse.com>,
	"Darrick J . Wong" <darrick.wong@oracle.com>,
	Boaz Harrosh <boaz@plexistor.com>,
	Jaegeuk Kim <jaegeuk@kernel.org>,
	Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>,
	Mark Fasheh <mfasheh@versity.com>,
	Evgeniy Dushistov <dushistov@mail.ru>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org
Subject: [RFC][PATCH v2 11/11] xfs: use common file type conversion
Date: Wed, 21 Dec 2016 12:12:08 +0200	[thread overview]
Message-ID: <1482315128-27549-1-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <CAOQ4uxgBV8DdD88XWJJN+5xHE7PeCA=z8PbVdh2mzbb3yL1xGA@mail.gmail.com>

Deduplicate the common bits of the file type conversion implementation.

Use private conversion tables to convert from fs common FT_* file types
to on-disk file types and from on-disk file types to readdir(2) DT_* file
types.

NOTE that the common_to_dir3_ftype table is an indentity transformation -
the common FT_* values are an exact reflection of the v3 on-disk values.
The dir3_ftype_to_dtype table is identical to the common fs_dtype_by_ftype
table in linux/file_type.h with an additional single entry for the
never used value of XFS_DIR3_FT_WHT.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/xfs/libxfs/xfs_dir2.c  | 48 +++++++++++++++++++++++++++++++++++------------
 fs/xfs/libxfs/xfs_dir2.h  |  4 ++--
 fs/xfs/xfs_dir2_readdir.c |  7 +------
 fs/xfs/xfs_iops.c         |  2 +-
 4 files changed, 40 insertions(+), 21 deletions(-)

Ted, Chris and Dave,

I would appreciate a NACK or ACK on this xfs example implementation.
If the major fs maintainers are on board, I will apply this approach
to all other fs.

This is a draft for the mid grounds approach suggested by Dave, which
keeps the control of on-disk bits in the hands of the the file system
code and still uses some of the common implementation.

As a code deduplication patch, one can argue that it does a pretty lousy
job, removing only a single line of common code (#define S_SHIFT 12), but
I do think that the result is cleaner without all the open coded >> S_SHIFT
conversions.

In any case, all for all the small file systems, this cleanup should be a
win (exofs ACKed already), so it would be nice to get feedback from more
maintainers.

Amir.

Extra food for thought:
=======================
Beyond the obvious open coded bits cleanup, going forward, this schema
will allow adding more common FT_ values and for file systems to catch up
with them at will. For example, if FT_WHT were to be added to the common
file types, xfs could join the party with existing v3 format by adding
a single line to private conversion table:
       [FT_WHT]    = XFS_DIR3_FT_WHT,
and other fs could join the FT_WHT party after sorting out whatever
feature flags that need to be sorted out.

I envision adding some opaque 'hint bits' to common ftype -
file systems that will support the opaque hint bits will store them as is
on-disk and repair tools will mask them out when comparing to inode mode.
Think of those bits as a way to white list or black list objects on a
file system for a very fast low-level directory tree iteration.

There is one such use case for overlayfs, but I am sure there are more.
The hint bits are not supposed to be set nor cleared during the life time
of the directory entry. Setting a file type hint bit should only be possible
at directory entry creation time (i.e. create,mknod,mkdir,symlink,rename).


v2:
- add private conversion from common to on-disk values

v1:
- use common conversion functions to get on-disk values

diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c
index c58d72c..ae711ad 100644
--- a/fs/xfs/libxfs/xfs_dir2.c
+++ b/fs/xfs/libxfs/xfs_dir2.c
@@ -37,21 +37,45 @@ struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR };
 
 /*
  * @mode, if set, indicates that the type field needs to be set up.
- * This uses the transformation from file mode to DT_* as defined in linux/fs.h
- * for file type specification. This will be propagated into the directory
- * structure if appropriate for the given operation and filesystem config.
+ * readdir(2) DT_* file types and fs common FT_* file types are defined
+ * in linux/file_type.h.
+ *
+ * These tables define the transformation from common FT_* file types to on-disk
+ * file types and from on-disk file types to readdir(2) DT_* file types.
+ *
+ * The on-disk file types will be propagated into the directory structure if
+ * appropriate for the given operation and filesystem config.
+ *
+ * NOTE that the common_to_dir3_ftype table is an indentity transformation -
+ * the common values are an exact reflection on the xfs v3 on-disk values.
+ * The dir3_ftype_to_dtype table is identical to the common fs_dtype_by_ftype
+ * table in linux/file_type.h with an additional single entry for the
+ * never used value of XFS_DIR3_FT_WHT.
  */
-const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = {
-	[0]			= XFS_DIR3_FT_UNKNOWN,
-	[S_IFREG >> S_SHIFT]    = XFS_DIR3_FT_REG_FILE,
-	[S_IFDIR >> S_SHIFT]    = XFS_DIR3_FT_DIR,
-	[S_IFCHR >> S_SHIFT]    = XFS_DIR3_FT_CHRDEV,
-	[S_IFBLK >> S_SHIFT]    = XFS_DIR3_FT_BLKDEV,
-	[S_IFIFO >> S_SHIFT]    = XFS_DIR3_FT_FIFO,
-	[S_IFSOCK >> S_SHIFT]   = XFS_DIR3_FT_SOCK,
-	[S_IFLNK >> S_SHIFT]    = XFS_DIR3_FT_SYMLINK,
+const unsigned char xfs_common_to_dir3_ftype[FT_MAX] = {
+	[FT_UNKNOWN]	= XFS_DIR3_FT_UNKNOWN,
+	[FT_REG_FILE]	= XFS_DIR3_FT_REG_FILE,
+	[FT_DIR]	= XFS_DIR3_FT_DIR,
+	[FT_CHRDEV]	= XFS_DIR3_FT_CHRDEV,
+	[FT_BLKDEV]	= XFS_DIR3_FT_BLKDEV,
+	[FT_FIFO]	= XFS_DIR3_FT_FIFO,
+	[FT_SOCK]	= XFS_DIR3_FT_SOCK,
+	[FT_SYMLINK]	= XFS_DIR3_FT_SYMLINK,
 };
 
+const unsigned char xfs_dir3_ftype_to_dtype[XFS_DIR3_FT_MAX] = {
+	[XFS_DIR3_FT_UNKNOWN]	= DT_UNKNOWN,
+	[XFS_DIR3_FT_REG_FILE]	= DT_REG,
+	[XFS_DIR3_FT_DIR]	= DT_DIR,
+	[XFS_DIR3_FT_CHRDEV]	= DT_CHR,
+	[XFS_DIR3_FT_BLKDEV]	= DT_BLK,
+	[XFS_DIR3_FT_FIFO]	= DT_FIFO,
+	[XFS_DIR3_FT_SOCK]	= DT_SOCK,
+	[XFS_DIR3_FT_SYMLINK]	= DT_LNK,
+	[XFS_DIR3_FT_WHT]	= DT_WHT,
+};
+
+
 /*
  * ASCII case-insensitive (ie. A-Z) support for directories that was
  * used in IRIX.
diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h
index 0197590..5018850 100644
--- a/fs/xfs/libxfs/xfs_dir2.h
+++ b/fs/xfs/libxfs/xfs_dir2.h
@@ -34,8 +34,8 @@ extern struct xfs_name	xfs_name_dotdot;
 /*
  * directory filetype conversion tables.
  */
-#define S_SHIFT 12
-extern const unsigned char xfs_mode_to_ftype[];
+extern const unsigned char xfs_common_to_dir3_ftype[];
+extern const unsigned char xfs_dir3_ftype_to_dtype[];
 
 /*
  * directory operations vector for encode/decode routines
diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
index 003a99b..6d8a741 100644
--- a/fs/xfs/xfs_dir2_readdir.c
+++ b/fs/xfs/xfs_dir2_readdir.c
@@ -36,11 +36,6 @@
 /*
  * Directory file type support functions
  */
-static unsigned char xfs_dir3_filetype_table[] = {
-	DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK,
-	DT_FIFO, DT_SOCK, DT_LNK, DT_WHT,
-};
-
 static unsigned char
 xfs_dir3_get_dtype(
 	struct xfs_mount	*mp,
@@ -52,7 +47,7 @@ xfs_dir3_get_dtype(
 	if (filetype >= XFS_DIR3_FT_MAX)
 		return DT_UNKNOWN;
 
-	return xfs_dir3_filetype_table[filetype];
+	return xfs_dir3_ftype_to_dtype[filetype];
 }
 
 STATIC int
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index 308bebb..36742fb 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -103,7 +103,7 @@ xfs_dentry_to_name(
 {
 	namep->name = dentry->d_name.name;
 	namep->len = dentry->d_name.len;
-	namep->type = xfs_mode_to_ftype[(mode & S_IFMT) >> S_SHIFT];
+	namep->type = xfs_common_to_dir3_ftype[fs_umode_to_ftype(mode)];
 }
 
 STATIC void
-- 
2.7.4


  reply	other threads:[~2016-12-21 10:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19 20:10 [RFC][PATCH 00/11] common implementation of dirent file types Amir Goldstein
2016-12-19 20:10 ` [RFC][PATCH 01/11] fs: common implementation of file type conversions Amir Goldstein
2016-12-19 21:13   ` Darrick J. Wong
2016-12-20  5:01     ` Amir Goldstein
2016-12-20  7:37   ` [RFC][PATCH v2 " Amir Goldstein
2016-12-19 20:10 ` [RFC][PATCH 02/11] ufs: use fs_umode_to_dtype() helper Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 03/11] hfsplus: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 04/11] ext2: use common file type conversion Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 05/11] exofs: " Amir Goldstein
2016-12-19 21:50   ` Boaz Harrosh
2016-12-19 20:11 ` [RFC][PATCH 06/11] ext4: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 07/11] ocfs2: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 08/11] f2fs: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 09/11] nilfs2: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 10/11] btrfs: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 11/11] xfs: " Amir Goldstein
2016-12-19 21:55   ` Darrick J. Wong
2016-12-20  6:17     ` Amir Goldstein
2016-12-20 14:07       ` Amir Goldstein
2016-12-20  0:28   ` Darrick J. Wong
2016-12-20  5:20     ` Amir Goldstein
2016-12-21  5:23       ` Dave Chinner
2016-12-21  6:37         ` Amir Goldstein
2016-12-21 10:12           ` Amir Goldstein [this message]
2016-12-21 18:01             ` [PATCH v3 " Amir Goldstein
2016-12-22 21:07               ` [PATCH v4] xfs: fix the size of xfs_mode_to_ftype table Amir Goldstein
2016-12-23 21:01                 ` Darrick J. Wong
2016-12-24  7:31                   ` Amir Goldstein
2016-12-24 14:11                 ` Brian Foster
2016-12-21 15:06         ` [RFC][PATCH 11/11] xfs: use common file type conversion Theodore Ts'o
2016-12-21 16:37           ` Amir Goldstein
2016-12-21 22:56             ` Theodore Ts'o
2016-12-22  5:54               ` Amir Goldstein
2016-12-22 20:30                 ` Amir Goldstein
2016-12-21 16:59           ` Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482315128-27549-1-git-send-email-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=boaz@plexistor.com \
    --cc=clm@fb.com \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=dushistov@mail.ru \
    --cc=jack@suse.com \
    --cc=jaegeuk@kernel.org \
    --cc=konishi.ryusuke@lab.ntt.co.jp \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mfasheh@versity.com \
    --cc=miklos@szeredi.hu \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).