From patchwork Wed Dec 21 10:12:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9482801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A59F760772 for ; Wed, 21 Dec 2016 10:12:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9387428467 for ; Wed, 21 Dec 2016 10:12:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87E552846F; Wed, 21 Dec 2016 10:12:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1B9D28467 for ; Wed, 21 Dec 2016 10:12:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751628AbcLUKMy (ORCPT ); Wed, 21 Dec 2016 05:12:54 -0500 Received: from mail-wj0-f194.google.com ([209.85.210.194]:32863 "EHLO mail-wj0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751154AbcLUKMw (ORCPT ); Wed, 21 Dec 2016 05:12:52 -0500 Received: by mail-wj0-f194.google.com with SMTP id kp2so31343676wjc.0 for ; Wed, 21 Dec 2016 02:12:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MXGuuvDrCInHzVDp6Zranw6T4VJgtEtUx69SXMICh6w=; b=X3iz6JJIEY3xg8JIQc0+AZUXw9RTYAiL1JCe3svqYmKiwed+E76Vjmi79Ha2f0eUrw +UhfkCzsim+A8hA3KNAOkFTCMOO+I1kSW0y0KlkNXv31V4HTcR7/b2Zbw8/gptEW+3X0 VmeuERg35qe4RRASqSFrXfPVddRR93B6rRePP2mMq38pWUsP11ta7zAbH0lDEXfXLfnp aSUp0kc+toiAdZaMhmys4Jww3mmqbY60ThKs/ZSL8izZ5BoAwzvANImLe+A5xPxwF+nY p971xQKe6t1gBxu5jqm3KSrFpZM62jxkAsr2Da3BYNIhGA+siCawKrOLoVJuf6mrw0nS Kxog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MXGuuvDrCInHzVDp6Zranw6T4VJgtEtUx69SXMICh6w=; b=QG6FCGHaqTHVV2i/LHEGQHDkA9xRgU2WPIpPqHFHpqK+32w/EOjNVODq8gXXYi9qxY jqVJbNxjl1DtR6J9hELFzk7HtAxqx4Wr3oZMwlxGa4N4CSFRxkHGrH9JoC2xpwfXST5K oYOgiTZdDkOT9Lz58T8UtP1XoVQTKfQNGKgLP+NGAIYIK3uTDhwvv6TbiJWe1kMltLO1 OZOSek+t5TglGIkW7Odc/IFNePpdnIceXMh8ZlrDV+6p/3KG/pE34ZyLtDvY4J8y3nvl L+hzsP2I6I6nkUxUDa96CQMsvhbZmNjnh8E2onDcmZvLONB4sXYNFFAUx8RLnXzcDdoN gxsw== X-Gm-Message-State: AIkVDXKF0G/BNzjpoD3YW/6VqAwj8CVazi0Zmkp9lx69/08HeZLEOc0KxiFVEl1/K0NWpA== X-Received: by 10.194.198.196 with SMTP id je4mr3364234wjc.25.1482315170272; Wed, 21 Dec 2016 02:12:50 -0800 (PST) Received: from amir-VirtualBox.ctera.local (bzq-82-81-193-202.cablep.bezeqint.net. [82.81.193.202]) by smtp.gmail.com with ESMTPSA id bf2sm29643113wjc.48.2016.12.21.02.12.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Dec 2016 02:12:49 -0800 (PST) From: Amir Goldstein To: Theodore Ts'o , Dave Chinner , Chris Mason Cc: Jan Kara , "Darrick J . Wong" , Boaz Harrosh , Jaegeuk Kim , Ryusuke Konishi , Mark Fasheh , Evgeniy Dushistov , Miklos Szeredi , Al Viro , 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 Message-Id: <1482315128-27549-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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