From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD0ADC282DB for ; Mon, 21 Jan 2019 08:12:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A06B921738 for ; Mon, 21 Jan 2019 08:12:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=philpotter-co-uk.20150623.gappssmtp.com header.i=@philpotter-co-uk.20150623.gappssmtp.com header.b="yznp0mJC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727867AbfAUIMh (ORCPT ); Mon, 21 Jan 2019 03:12:37 -0500 Received: from mail-wr1-f49.google.com ([209.85.221.49]:40439 "EHLO mail-wr1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727633AbfAUIMg (ORCPT ); Mon, 21 Jan 2019 03:12:36 -0500 Received: by mail-wr1-f49.google.com with SMTP id p4so22132247wrt.7 for ; Mon, 21 Jan 2019 00:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=vXKX8O1ubeONd+BhQY9Ns257AnTz1uiNeyGz1jz8/rw=; b=yznp0mJC42n9GsnbPUWTd8ozqd7LSXyan4bcrggSQK5t4S3c6EJo5AB9b2B9Lp2VKw FCRKTvzAjZIyo8M4Aa7FGAe3Qz8TJJXKufq9lJeF6if5cglaVwsGCP39/KAnJ+lfu+Ox zKp8FYcMB//hJpnVXCk9mqRbpsITQryf4S908/uNlDyqebW13TwpdaC7aX00bPOc/DUZ uogpF1AKCsfaT/cTxJzh+Og+kYoMoJmVgAPFq5KTNQac0mtdo2ZQNRxdMuoaRAE+bqqk kAVYwkp2gVtC29W6MaNNEGbMOllVeZu70uJmY2/O7J4YbMOk2BgIA4ehxF1mq5TbLbDP x2Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=vXKX8O1ubeONd+BhQY9Ns257AnTz1uiNeyGz1jz8/rw=; b=FrrKitXobndqLmQMmI/j1NCAb1pld7CCgSGtfqw/kMpRDmwCWx39Q2tsD5E6CNRoF9 ksYNd9NKekwp9RD3KfN6ZmyOBgmSe6z/3zSasjYCzZ56wYCM1K82/HbrsZM62eMi/qrQ krEZP0slmU4U3IxqHuBNrZl4DVXgamciBYKc5o2G96oSdrZDCAuYGoQl3diUJdudU4dQ 3pG4DakIDEP2yB/A9+lbCUZWqvkCV2VQmUsLH2HhsqJ8bXLX0GuMo31/jiBIFKN/NlVn sBXJ51Nw3PK7AM0X5NXlRVtNGhNIDPxqbfy+u4sZeTI/S46nJyJHrBmJlUSdrHZykbLA Ztww== X-Gm-Message-State: AJcUukcBod2th9a/dmPGx45ChbfojnkKB9x15aN8fAl4Cer/o38t1FB+ k13P9vgNCkuRAXUFwQMwjNRRzXrvm7d1vg== X-Google-Smtp-Source: ALg8bN7JzQGYt9EdAJO4tZH130bmaWgyyXXO6vFVh/ldr9Z9BqL2TnKRZmRt4bOYRRZ7OEaQtgWM1Q== X-Received: by 2002:adf:81c4:: with SMTP id 62mr24118376wra.266.1548032067657; Sun, 20 Jan 2019 16:54:27 -0800 (PST) Received: from pathfinder ([90.222.17.17]) by smtp.gmail.com with ESMTPSA id w80sm69704792wme.38.2019.01.20.16.54.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 20 Jan 2019 16:54:26 -0800 (PST) Date: Mon, 21 Jan 2019 00:54:25 +0000 From: Phillip Potter To: viro@zeniv.linux.org.uk Cc: jack@suse.cz, amir73il@gmail.com, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v5 00/09] common implementation of dirent file types Message-ID: <20190121005425.GA32315@pathfinder> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This cleanup series is a respin of Amir Goldstein's work, created in late 2016. It removes several instances of duplicated code. Most of the duplication dates back to git pre-historic era. The controversial aspect of this cleanup is that it uses common code to handle file system specific on-disk format bits. The previous series handled this aspect by placing compile-time checks to catch cases where the fs specific definitions deviated from the common ones. Linus Torvalds mentioned that he was not happy with the concept of two sets of definitions having to stay in sync, and the code that goes along with that. It was agreed that if the values must stay the same forever, it is better to keep the common definitions and remove the filesystem specific ones. This discussion can be followed at: https://marc.info/?l=linux-fsdevel&m=154758043730079&w=2 All 6 file systems use a single byte to store dirent file type on-disk and all of them use the same conversion routines from i_mode to 4bits DT_* constants to 3bits on-disk FT_* constants. Patch 1 places a common implementation in fs_types.c with some useful conversion helpers. The corresponding header fs_types.h contains related macros and definitions, as well as helper declarations. Patches 2-3 make use of the helpers in ufs and hfsplus without any on-disk implications. Patches 4-9 replace the specific implementations in ext2, ocfs2, f2fs, ext4, nilfs2 and btrfs with the common implementation. The ext2 implementation appears to have been copied as a basis of the others, and in particular, for code that tries to access the ext2_type_by_mode array there is a bug that this patch series fixes. Essentially, it is defined with size S_IFMT >> S_SHIFT, so 15. This means that it is possible with a malformed inode to get an index of 15, as the array is always accessed with: ext2_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; These patches mostly no longer include compile-time checks to ensure the filesystem specific on-disk bits are equivalent to the common implementation FT_* bits, and instead op to remove the filesystem specific definitions entirely where possible, as a result of the referenced discussion above. With the ext4 patch, the EXT4_FT_* definitions are instead defined to be FT_*, to give less code churn with the same result (no need to modify fs/ext4/namei.c). Also, the nilfs2 and btrfs filesystems keep their filesystem specific definitions in the include/uapi/linux directory, so these cannot be changed trivially without breaking userspace. For this reason, the compile time checks remain in these two filesystems. In addition, I've checked that the patches apply and build with the newest 5.0-rc2 kernel sources, and that they work. Each patch is independent of the others, except for the common implementation itself which they all depend on. General motivations for the patch (other than the bugfix above) are the fact that it reduces the amount of code for the covered filesystems: ufs: -27 lines hfsplus: -12 lines ext2: -39 lines ocfs2: -38 lines f2fs: -38 lines ext4: -13 lines nilsfs2: -17 lines btrfs: -2 lines It also makes it easier to add hypothetical future filesystems which wish to reuse these POSIX-type definitions and on-disk formats, as they can simply now use the common implementation. I welcome feedback, and thank those who have already provided it. Hopefully, the relevant maintainers will see fit to merge this work. v5: - Added extra comment wording in the common implementation patch to make it clear that the FT_* definitions must never change, as they are now being depended on by multiple filesystems - Removed compile-time checks from ext2, ext4, ocfs2 and f2fs patches - Modified ext2, ocfs2 and f2fs patches to remove the filesystem specific **_FT_* definitions completely - Modified ext4 patch to define EXT4_FT_* as FT_*. This results in less code churn and no need to modify fs/ext4/namei.c - Reapplied and tested against 5.0-rc2 - Removed some Acked-by and Reviewed-by tags due to refactoring and the subsequent desire for rechecking by maintainers. v4: - Removed exofs patch from series, as there is ongoing discussion on whether or not exofs should be removed from the kernel tree - happy to add it back should exofs end up staying, particularly as Boaz acked my patch. - Reapplied and tested against 4.20-rc3 - Moved compile-time checks in btrfs patch to more consistent location - Incorporated Acked-by and Reviewed-by tags received so far v3: - Moved compile-time checks to better locations, and shortened comments, as well as formatting to 80 columns - Renamed header to fs_types.h, and placed comment regarding DT_* constants relation to POSIX and glibc dirent.h - Changed "should" to "must" in comments mentioning the need for fs specific values to match the common values in fs_types.h - Split functions and lookup tables to separate C file (fs/fs_types.c) - Added kernel-doc comments for all three utility functions, and removed therefore unnecessary lines from comment in fs_types.h - Tweaked commit messages slightly to explain that file systems using POSIX file types now don't need to define their own conversion routines - Renamed fs_dtype function to fs_ftype_to_dtype for consistency with other helper functions - Tweaked fs_ftype_to_dtype to take unsigned int argument, to prevent out of bounds access of memory - Added additional text to comment in fs_types.h explaining the definitions must never change - Changed DT_* types in fs_types.h to explicit constants as they can't change anyway - 80 line violation in the ext2 patch - left as is due to the fact the code would look worse if fixed, other patches tweaked slightly to keep within 80 line limit (by moving last parameter in various if statements) v2: - Rebased against Linux 4.19 by Phillip Potter - This version does not remove filesystem specific XXX_FT_* definitions, as these values are now used in compile-time checks added by Phillip Potter to make sure they remain the same as the generic FT_* values - Removed xfs patch (a variant of original patch has already been applied) - Added SPDX tag to new header file and included it in MAINTAINERS v1: - Initial implementation by Amir Goldstein: https://marc.info/?l=linux-fsdevel&m=148217829301701&w=2 Phillip Potter (9): fs: common implementation of file type conversions ufs: use fs_umode_to_dtype() helper hfsplus: use fs_umode_to_dtype() helper ext2: use common file type conversion ocfs2: use common file type conversion f2fs: use common file type conversion ext4: use common file type conversion nilfs2: use common file type conversion btrfs: use common file type conversion MAINTAINERS | 1 + fs/Makefile | 3 +- fs/btrfs/btrfs_inode.h | 2 - fs/btrfs/delayed-inode.c | 2 +- fs/btrfs/inode.c | 32 +++++---- fs/ext2/dir.c | 35 ++-------- fs/ext2/ext2.h | 16 ----- fs/ext4/ext4.h | 37 ++++------ fs/f2fs/dir.c | 27 +------- fs/f2fs/inline.c | 2 +- fs/fs_types.c | 105 +++++++++++++++++++++++++++++ fs/hfsplus/dir.c | 16 +---- fs/nilfs2/dir.c | 52 +++++--------- fs/ocfs2/dir.c | 20 ++---- fs/ocfs2/ocfs2_fs.h | 28 +------- fs/ufs/util.h | 29 +------- include/linux/f2fs_fs.h | 15 ----- include/linux/fs.h | 17 +---- include/linux/fs_types.h | 75 +++++++++++++++++++++ include/uapi/linux/btrfs_tree.h | 2 + include/uapi/linux/nilfs2_ondisk.h | 1 + 21 files changed, 249 insertions(+), 268 deletions(-) create mode 100644 fs/fs_types.c create mode 100644 include/linux/fs_types.h -- 2.19.1