From patchwork Wed Nov 21 19:06:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693093 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 855D113BF for ; Wed, 21 Nov 2018 19:07:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70C832B68D for ; Wed, 21 Nov 2018 19:07:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64BB22BDB2; Wed, 21 Nov 2018 19:07:02 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 EB7852B68D for ; Wed, 21 Nov 2018 19:07:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387644AbeKVFmc (ORCPT ); Thu, 22 Nov 2018 00:42:32 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43053 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387566AbeKVFmc (ORCPT ); Thu, 22 Nov 2018 00:42:32 -0500 Received: by mail-wr1-f68.google.com with SMTP id r10so6817874wrs.10 for ; Wed, 21 Nov 2018 11:06:58 -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=Dw6w3uY1DDyQl8IcoLCwjiDDoSj/lFO6lm1g9LcDF4E=; b=fyO8aUX3dv+PTPuZg/hR3f9m0MwRzKNrcwiCR7jZDN0NgwpILQFvmC6M91uMsW+Qvd 3nb176jbbRdhtjFhlRfJEh8VeQ6tgY1Upc2JGCzt+7Rzb///yYHI5TnAhpLaY1HflMsG Y9dlFs46lUzlbrH14RYcDdsT7u7YxbFKz+LGFfDTjPgVfmUj7L+x0d1tlhIVKJYXfiuf jkhCakJ2Wwsc37jZ69o+STiT3siMN6Axl3C4DOCCEAQi9wbuzN9NmgGomdEf06dDRUTO 9O98EuS6a8H5y9+0XpK+HEXwhsAdMMVdJOww8jrxrmfvtQoWhzS27NUsu3m8Y5Qegpww gcrg== 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=Dw6w3uY1DDyQl8IcoLCwjiDDoSj/lFO6lm1g9LcDF4E=; b=msFm6FAG7D/CfQ+CRbCLeVDGT/N3bVC/7ay5e82CpfKSFPfC1ITvXSgNQe0IK15ere CXpQHYZtxnZkgXG05WItTZwXwFfKLx1WuxrjdsMghIq5di723rUjCvOAsrUfTUHi+VAK opb4+sQ4SBJkIhKbHFgKnYj1vIvsmnBuPGJeMDxCip9Ujb8ymhvt4rdramzPwm0sNAYj XKtn/ArPacspyxmK47UfN2dggwe421s1uy/lvY7q9aNJ8spyrRb1SVg+9DY/3q6T5OvZ K9LeYp3FPUhyVaGdvqxLOYuxDMgxxJqoGPh3LsidPvHUsNNyOUbcHJNHczJwwJl7HBzb Rg9g== X-Gm-Message-State: AA+aEWZBEmhBEn4VtCcwGBC2EStV+4hC073NtoQ2YTlXl1xLIG1eh85k ARxRhh1rmFiipPQRw6W3eBtNww== X-Google-Smtp-Source: AFSGD/U7B5sS0ALZmYBU6unQGVqCRN7RkpMvGeoqmZfgMJl3+Yq18PiUTI4PJ2+0SjURb/ca8Sp95w== X-Received: by 2002:adf:b109:: with SMTP id l9-v6mr4560111wra.290.1542827217962; Wed, 21 Nov 2018 11:06:57 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id i13sm28850181wrw.32.2018.11.21.11.06.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:57 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:56 +0000 From: Phillip Potter To: mark@fasheh.com Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, jlbec@evilplan.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Subject: [RFC][PATCH v4 06/09] ocfs2: use common file type conversion Message-ID: <20181121190656.GA7724@pathfinder> MIME-Version: 1.0 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 X-Virus-Scanned: ClamAV using ClamSMTP Deduplicate the ocfs2 file type conversion implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/ocfs2/dir.c | 18 +++--------------- fs/ocfs2/ocfs2_fs.h | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index c121abbdfc7d..9e6dea014ab9 100644 --- a/fs/ocfs2/dir.c +++ b/fs/ocfs2/dir.c @@ -69,10 +69,6 @@ #define NAMEI_RA_BLOCKS 4 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS) -static unsigned char ocfs2_filetype_table[] = { - DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK -}; - static int ocfs2_do_extend_dir(struct super_block *sb, handle_t *handle, struct inode *dir, @@ -1803,13 +1799,9 @@ static int ocfs2_dir_foreach_blk_id(struct inode *inode, } offset += le16_to_cpu(de->rec_len); if (le64_to_cpu(de->inode)) { - unsigned char d_type = DT_UNKNOWN; - - if (de->file_type < OCFS2_FT_MAX) - d_type = ocfs2_filetype_table[de->file_type]; - if (!dir_emit(ctx, de->name, de->name_len, - le64_to_cpu(de->inode), d_type)) + le64_to_cpu(de->inode), + fs_ftype_to_dtype(de->file_type))) goto out; } ctx->pos += le16_to_cpu(de->rec_len); @@ -1900,14 +1892,10 @@ static int ocfs2_dir_foreach_blk_el(struct inode *inode, break; } if (le64_to_cpu(de->inode)) { - unsigned char d_type = DT_UNKNOWN; - - if (de->file_type < OCFS2_FT_MAX) - d_type = ocfs2_filetype_table[de->file_type]; if (!dir_emit(ctx, de->name, de->name_len, le64_to_cpu(de->inode), - d_type)) { + fs_ftype_to_dtype(de->file_type))) { brelse(bh); return 0; } diff --git a/fs/ocfs2/ocfs2_fs.h b/fs/ocfs2/ocfs2_fs.h index 7071ad0dec90..daf836e5df43 100644 --- a/fs/ocfs2/ocfs2_fs.h +++ b/fs/ocfs2/ocfs2_fs.h @@ -424,17 +424,6 @@ static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = { #define OCFS2_LINKS_HI_SHIFT 16 #define OCFS2_DX_ENTRIES_MAX (0xffffffffU) -#define S_SHIFT 12 -static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR, - [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK, - [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK, -}; - /* * Convenience casts @@ -1629,7 +1618,21 @@ static inline int ocfs2_sprintf_system_inode_name(char *buf, int len, static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de, umode_t mode) { - de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; + /* + * compile-time asserts that generic FT_x types still match + * OCFS2_FT_x types + */ + BUILD_BUG_ON(OCFS2_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(OCFS2_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(OCFS2_FT_DIR != FT_DIR); + BUILD_BUG_ON(OCFS2_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(OCFS2_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(OCFS2_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(OCFS2_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(OCFS2_FT_SYMLINK != FT_SYMLINK); + BUILD_BUG_ON(OCFS2_FT_MAX != FT_MAX); + + de->file_type = fs_umode_to_ftype(mode); } static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)