From patchwork Tue Mar 26 21:39:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10872201 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 5750D139A for ; Tue, 26 Mar 2019 21:39:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42A9D285FF for ; Tue, 26 Mar 2019 21:39:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37062286D1; Tue, 26 Mar 2019 21:39:20 +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 C2715285FF for ; Tue, 26 Mar 2019 21:39:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731770AbfCZVjT (ORCPT ); Tue, 26 Mar 2019 17:39:19 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55069 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730605AbfCZVjT (ORCPT ); Tue, 26 Mar 2019 17:39:19 -0400 Received: by mail-wm1-f67.google.com with SMTP id f3so14269369wmj.4 for ; Tue, 26 Mar 2019 14:39:17 -0700 (PDT) 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=vQBAScoNuRnYibOoHWg5SI5bSdTQxp5ujvyxiTvSB/g=; b=YDtywrOTV6q+wWrF5lyDB06Sr79fYhNfKVpnVauAmkLX1SoWPByTnIzSe1RZfwH3xy ic69Y5nu5VvE9hRux2RgofyB1Q9/0ZBNZu9T1clrIK8rnZFEOldoFaoljN3+8Th+8kNf T+C9AOD/9zuxCx1RSmG50lB43kTsc57oXAdwcwmpVvwebCPpEukLCOhPsWVqTvgm/cm/ lViio6ebrX+B6rHMbaYnpsWjr23WGdxmz7CvTKpMOsrBkJKiN80SEArV74wHUe0nhjTM GsFbDH1uObaf61YWpYNUYqJDU6YDSUEIRgEFFLRYXAoyQsaVia/NSoStWwrkXTafhMWe MH8Q== 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=vQBAScoNuRnYibOoHWg5SI5bSdTQxp5ujvyxiTvSB/g=; b=A5FT2mOgBUHgVptpVL7/lQOxyXtAzH3eNdBueZ8bgYlk/t0H66jRkA7GqH5Ixpp+qp zdAt0eLQKsAJVLCdAjfjBvGsugFUOJJ6Cbe3apS+gsTCiEavXYeoOQYU/uuuuBrythIX OHrKjbVWQYSTfQgROkyNvq1YHZXShJaxVDDhNopcpNc9CEAXWz8UvnWG9mttLoEG9RGy JGJNFX/gBz1FdO/8WbfErX3wBjMrj2Rc872l28AW63Q7UYKZ+IB0CAPPtFPOsXzcNsHl qVhPSdz3N/kt4cQYkZBF3p/JqYe/c0wdKqIXbaQGidTsFx53ancVdKCHWZk3mqyB3f4t 2zNA== X-Gm-Message-State: APjAAAXD2LdUPxgq2pm2yQPJ47HYGyQQhrnJuPaM1KrqdNn5zryueG7H /a2Q6oB6I2QT+X4+R7pxUd0zWw== X-Google-Smtp-Source: APXvYqzMgAwjRIJ27KKwTBUHJ6rUUFrYnDNInzCMql8tNSnlbtwOySzHDmc8bGVynpp9RcCqIUe/1g== X-Received: by 2002:a7b:c403:: with SMTP id k3mr16599100wmi.58.1553636356735; Tue, 26 Mar 2019 14:39:16 -0700 (PDT) Received: from pathfinder ([90.195.158.41]) by smtp.gmail.com with ESMTPSA id n4sm30583861wrx.39.2019.03.26.14.39.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 26 Mar 2019 14:39:16 -0700 (PDT) Date: Tue, 26 Mar 2019 21:39:13 +0000 From: Phillip Potter To: dushistov@mail.ru Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [PATCH v6 01/07] ufs: use fs_umode_to_dtype() helper Message-ID: <20190326213913.GA20876@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) 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 Replace switch statement with common lookup table 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 Common implementation can be found via commit: bbe7449e2599 "fs: common implementation of file type" Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/ufs/util.h | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/fs/ufs/util.h b/fs/ufs/util.h index 1fd3011ea623..8c7759860739 100644 --- a/fs/ufs/util.h +++ b/fs/ufs/util.h @@ -158,34 +158,7 @@ ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode) if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) != UFS_DE_44BSD) return; - /* - * TODO turn this into a table lookup - */ - switch (mode & S_IFMT) { - case S_IFSOCK: - de->d_u.d_44.d_type = DT_SOCK; - break; - case S_IFLNK: - de->d_u.d_44.d_type = DT_LNK; - break; - case S_IFREG: - de->d_u.d_44.d_type = DT_REG; - break; - case S_IFBLK: - de->d_u.d_44.d_type = DT_BLK; - break; - case S_IFDIR: - de->d_u.d_44.d_type = DT_DIR; - break; - case S_IFCHR: - de->d_u.d_44.d_type = DT_CHR; - break; - case S_IFIFO: - de->d_u.d_44.d_type = DT_FIFO; - break; - default: - de->d_u.d_44.d_type = DT_UNKNOWN; - } + de->d_u.d_44.d_type = fs_umode_to_dtype(mode); } static inline u32 From patchwork Tue Mar 26 21:39:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10872203 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 81639925 for ; Tue, 26 Mar 2019 21:39:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CE82285FF for ; Tue, 26 Mar 2019 21:39:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60939286D1; Tue, 26 Mar 2019 21:39:23 +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 4E39D285FF for ; Tue, 26 Mar 2019 21:39:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732042AbfCZVjV (ORCPT ); Tue, 26 Mar 2019 17:39:21 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40108 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730605AbfCZVjV (ORCPT ); Tue, 26 Mar 2019 17:39:21 -0400 Received: by mail-wr1-f67.google.com with SMTP id h4so488377wre.7 for ; Tue, 26 Mar 2019 14:39:20 -0700 (PDT) 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=fso/CmjrDmR/TYRQ7oatno8Hu+n/5/Yo84v6uQ+zvxE=; b=fCH4n6IZuxdMmByDFS1lQTLvjgxelpp4jXHVhEXiA+VCVdWiWfCsJrUBLgeqL+qUwH YfajB3wCr8VhLF6kvvWzvYw40EtVX9CREttvjRDVu/C1vCNozvMyXYXkQNIo5xfK4HFl xzgzqo3FyVYQV0cgbPvaN/xzhNc+cZQOmvU4m2gxCJTeR6ct46TWH0FzYdaboYx4k5xI igoQXOOCb2jrLYYMjVLJ1my5qDdUpp1kLKOSctJgP4RmLEKxEnvKHfj+/ET3UPt5hVsz 5eA0LSuI4ulBQy2rdftTEFSc+ieWVY0qV8PU0SJQLTtXWLLY5Il5knzsqK07FAkiuD7M vJGQ== 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=fso/CmjrDmR/TYRQ7oatno8Hu+n/5/Yo84v6uQ+zvxE=; b=EydWtIjCpByKq6OiUcEwdk0cb0KkAbp1ZUHWSlc8lv3YqKUPko6ujmQZu3jteyfINi 9CsANT9AYKl6VNI28bOb18qKPDnqMi69/Q6IVfWLEHGP4ukvuxnlZ8w898f7rW7QCAio sCY4q0hhVLZPNjp4GBAYUcFy/EJlnXr5hOGPLILe1yOob6mUFCfjwrI8lzw2Khp64oTh DrMcZzP7y02WyMad7C9kP7JtpC7taXhm6oeAqeTy4kmtiODYDv7DW91H245iGcVJrzBM 4XszQcHMgmz2+X0w06frt0f6QoesyohqkaT3NaWY3piiaStz92wI1QaIbnyRya4kvwBG FZ0Q== X-Gm-Message-State: APjAAAW2EsMLR4Dy036stnqCOMrm18g8jwOBl3dT16wFjeH7QboO856T Hv64UFYoMlmX299n4vYLd6oq9UmmOQovDw== X-Google-Smtp-Source: APXvYqwEBlu3OA/ZV0n6S/z2ENwvalhzP78mn9S8bv7nAulbVNlNXFkKDdMR9/S0l5Lg9ybeiTuABw== X-Received: by 2002:adf:ebc8:: with SMTP id v8mr20974078wrn.172.1553636359173; Tue, 26 Mar 2019 14:39:19 -0700 (PDT) Received: from pathfinder ([90.195.158.41]) by smtp.gmail.com with ESMTPSA id h18sm24090322wrt.97.2019.03.26.14.39.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 26 Mar 2019 14:39:18 -0700 (PDT) Date: Tue, 26 Mar 2019 21:39:16 +0000 From: Phillip Potter To: linux-fsdevel@vger.kernel.org Cc: ernesto.mnd.fernandez@gmail.com, akpm@linux-foundation.org, amir73il@gmail.com, viro@zeniv.linux.org.uk, slava@dubeyko.com Subject: [PATCH v6 02/07] hfsplus: use fs_umode_to_dtype() helper Message-ID: <20190326213916.GA20877@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) 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 Replace if/else statements with common lookup table 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 Common implementation can be found via commit: bbe7449e2599 "fs: common implementation of file type" Reviewed-by: Vyacheslav Dubeyko Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/hfsplus/dir.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c index 29a9dcfbe81f..c61a4faec2ae 100644 --- a/fs/hfsplus/dir.c +++ b/fs/hfsplus/dir.c @@ -223,7 +223,6 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx) break; } else if (type == HFSPLUS_FILE) { u16 mode; - unsigned type = DT_UNKNOWN; if (fd.entrylength < sizeof(struct hfsplus_cat_file)) { pr_err("small file entry\n"); @@ -232,21 +231,10 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx) } mode = be16_to_cpu(entry.file.permissions.mode); - if (S_ISREG(mode)) - type = DT_REG; - else if (S_ISLNK(mode)) - type = DT_LNK; - else if (S_ISFIFO(mode)) - type = DT_FIFO; - else if (S_ISCHR(mode)) - type = DT_CHR; - else if (S_ISBLK(mode)) - type = DT_BLK; - else if (S_ISSOCK(mode)) - type = DT_SOCK; if (!dir_emit(ctx, strbuf, len, - be32_to_cpu(entry.file.id), type)) + be32_to_cpu(entry.file.id), + fs_umode_to_dtype(mode))) break; } else { pr_err("bad catalog entry type\n"); From patchwork Tue Mar 26 21:39:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10872205 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 21F04139A for ; Tue, 26 Mar 2019 21:39:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BB76285FF for ; Tue, 26 Mar 2019 21:39:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0055A286D1; Tue, 26 Mar 2019 21:39:25 +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 7327A285FF for ; Tue, 26 Mar 2019 21:39:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732157AbfCZVjZ (ORCPT ); Tue, 26 Mar 2019 17:39:25 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36874 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730605AbfCZVjY (ORCPT ); Tue, 26 Mar 2019 17:39:24 -0400 Received: by mail-wr1-f68.google.com with SMTP id w10so16140895wrm.4 for ; Tue, 26 Mar 2019 14:39:22 -0700 (PDT) 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=75YLOy7JeQH7vqxr3AFFH3hqJjIyubkCZ9oJ6Z5+4AE=; b=VdFNv4Sw+bVfSGLcibGZpxmt4I4ocE7b3Pff2X+zaGV7nlOMvMQzd+4Pt4ecKIjmI3 PjlIAx165/+rf3c2rberxMSZFjWHAb4J6tujiTVXH4ux6mmRXBoHXqvfPBBE872N3fvb 9Dog1iEorQKSW4Sj3z5A/lNUGDsfw7dU2V0Vq8e1KkYZnGeSKQbcy3C5hzouZe689YJ6 RsPhzzn9TZbUm3npZaT4Kujfnid12cF19tkRjtply15c+XmkdqlDE2de+/Kx5mCnVl7X 6e4aR6/J3J4v2VXOiCE00nPLgCjXYE0AhuqYGskRzN9c4CnAmsLfGMl6uSO0ut/cWkol FpRQ== 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=75YLOy7JeQH7vqxr3AFFH3hqJjIyubkCZ9oJ6Z5+4AE=; b=OA2SkuE6moyJkRoSbJUu6ARXZi0xop2qjzWJgRpaxyyHCEQkcNTNkWxwzkkpfODJbl 2pPDwo8xo3gjzs3/Uw+fDQBp05H4Oi5fR06dZDe4gNGEuQODCiE2dxz+B/YpiGL/WR10 Lq13035jg/5oBrO/+piBNez2Mii5hCawZRX7vZLH0T7iLODF2+mNTvdkKBZu9GF5splk 3Ew1P8ehlxUuW/zDqXWWKdGQMo5l55sOHD4AItq26Oh1CtdF091QQNdtIZ8sAd7kunq8 8htrGFSxK/ckzOWeCr9oHLdcHrWcFjbVF9rVhbVh3MnFAUVwqyrTBCIythdLcmdOx4sX 3T0g== X-Gm-Message-State: APjAAAWhobcET6PD6CfBWQer+vCOVgZtMah4JHAiCmrSUtQIidj3BJP+ 6ORNzuoyGTmBX7bh2Pw/6ZA43A== X-Google-Smtp-Source: APXvYqxiOlnb/BiiHTuBVZLxZ1hnfeLzi7iTLn1SR6TAaxV2A1fC4vxFlMHSwnlo9inWLo3Htdp4Dw== X-Received: by 2002:adf:e949:: with SMTP id m9mr11272330wrn.237.1553636362060; Tue, 26 Mar 2019 14:39:22 -0700 (PDT) Received: from pathfinder ([90.195.158.41]) by smtp.gmail.com with ESMTPSA id c18sm15550053wmk.47.2019.03.26.14.39.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 26 Mar 2019 14:39:21 -0700 (PDT) Date: Tue, 26 Mar 2019 21:39:19 +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: [PATCH v6 03/07] ocfs2: use common file type conversion Message-ID: <20190326213919.GA20878@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) 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 and remove OCFS2_FT_* definitions - 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 Common implementation can be found via commit: bbe7449e2599 "fs: common implementation of file type" Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/ocfs2/dir.c | 20 ++++---------------- fs/ocfs2/ocfs2_fs.h | 28 +--------------------------- 2 files changed, 5 insertions(+), 43 deletions(-) diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index c121abbdfc7d..85f21caaa6ec 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, @@ -1718,7 +1714,7 @@ int __ocfs2_add_entry(handle_t *handle, de->rec_len = cpu_to_le16(OCFS2_DIR_REC_LEN(de->name_len)); de = de1; } - de->file_type = OCFS2_FT_UNKNOWN; + de->file_type = FT_UNKNOWN; if (blkno) { de->inode = cpu_to_le64(blkno); ocfs2_set_de_type(de, inode->i_mode); @@ -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..b86bf5e74348 100644 --- a/fs/ocfs2/ocfs2_fs.h +++ b/fs/ocfs2/ocfs2_fs.h @@ -391,21 +391,6 @@ static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = { #define OCFS2_HB_LOCAL "heartbeat=local" #define OCFS2_HB_GLOBAL "heartbeat=global" -/* - * OCFS2 directory file types. Only the low 3 bits are used. The - * other bits are reserved for now. - */ -#define OCFS2_FT_UNKNOWN 0 -#define OCFS2_FT_REG_FILE 1 -#define OCFS2_FT_DIR 2 -#define OCFS2_FT_CHRDEV 3 -#define OCFS2_FT_BLKDEV 4 -#define OCFS2_FT_FIFO 5 -#define OCFS2_FT_SOCK 6 -#define OCFS2_FT_SYMLINK 7 - -#define OCFS2_FT_MAX 8 - /* * OCFS2_DIR_PAD defines the directory entries boundaries * @@ -424,17 +409,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 +1603,7 @@ 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]; + de->file_type = fs_umode_to_ftype(mode); } static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd) From patchwork Tue Mar 26 21:39:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10872211 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 5CCD7139A for ; Tue, 26 Mar 2019 21:39:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 479C4285FF for ; Tue, 26 Mar 2019 21:39:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AFEA286D1; Tue, 26 Mar 2019 21:39:37 +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 C1331285FF for ; Tue, 26 Mar 2019 21:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732792AbfCZVjf (ORCPT ); Tue, 26 Mar 2019 17:39:35 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34950 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730605AbfCZVj0 (ORCPT ); Tue, 26 Mar 2019 17:39:26 -0400 Received: by mail-wr1-f68.google.com with SMTP id w1so16170011wrp.2 for ; Tue, 26 Mar 2019 14:39:24 -0700 (PDT) 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=T0sVxNadLS4ldXRvSM1qi/M1cretRrhP/GEGOI8U9Ag=; b=QVAhLwAGewObcu/jijkF4czAcclYJWoDA3szv/xvqUVrLvpPrL/6pJ7E0q9c+0G45n lCCvITP2ys9DgFIrQ7BuNkxkQhdd/p+cbvXxyyIKGgUqCUQjUu5ezM9IbTtNSAVCD3/E tB0BtTK956/Hf1yWtWhMC0MOE+0AUzYbmI+EIOJQdjUnjrTIhViDVy1qkjqtQlGLI2xi VG2xkMOVXbzQMYuqdwyUp9zqx9tYDMZH9Nr6q+4Qoi5LIh4MYdRgE2Ys8F4R+jcp5JxH s75E03DZdeAimnuXUoay4IbqKIKG9HVMDYcziqrnmsqygq8qa5XnEmWkz8C2az8NgWQ+ 6r7w== 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=T0sVxNadLS4ldXRvSM1qi/M1cretRrhP/GEGOI8U9Ag=; b=aVkLcnt5qRQy1ekyIv47jMydIELwnJhEmt5942ea2WS1hKr7xk6z/PKuR1ztcYW6Os 8ZG8DknBToxHx0c2C/BYRYQNeVynMZ8Hf935jXuucNhfbXAXzGv7igc0Zm2a7DoPYJpb F0l+SzMmZ7jiYcwRJHwPUVxLB5OtXvyaEpU+I5Ak5VlpppfzMF2018iPlEaQMWPiOman NXGCJeIhRBV6gYTlholkokyg+nlAAx7PlfPaVymYEmRPxzPssXCTA56soZccDZzxlja4 KQy6uzbzo7HC/ggW2niYoxQ8dBw+SIeX5XQCYOb4Bcp79WeaFaH/0zHw8zxNRmznvY1V vAhA== X-Gm-Message-State: APjAAAVlmPbF12ItL42oUEE6jd7Rptu70yNfmfntsgOH4W+GGDgKEQHl nLuiwBIsMA6GwxTpPeFIZiHT/paPPxaVfw== X-Google-Smtp-Source: APXvYqzuR8Pq5gl5vwHImVN0VwxXdN9qgv09nvrTDLJK2H8qSNGqAI0Z5JGE6H9U8NjSI6RZmDPqFg== X-Received: by 2002:adf:f60e:: with SMTP id t14mr18407514wrp.39.1553636364324; Tue, 26 Mar 2019 14:39:24 -0700 (PDT) Received: from pathfinder ([90.195.158.41]) by smtp.gmail.com with ESMTPSA id g19sm7660274wmh.17.2019.03.26.14.39.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 26 Mar 2019 14:39:23 -0700 (PDT) Date: Tue, 26 Mar 2019 21:39:22 +0000 From: Phillip Potter To: jaegeuk@kernel.org Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, yuchao0@huawei.com, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Subject: [PATCH v6 04/07] f2fs: use common file type conversion Message-ID: <20190326213922.GA20879@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) 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 f2fs file type conversion implementation and remove F2FS_FT_* definitions - 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 Common implementation can be found via commit: bbe7449e2599 "fs: common implementation of file type" Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Chao Yu Reviewed-by: Jan Kara --- fs/f2fs/dir.c | 27 ++------------------------- fs/f2fs/inline.c | 2 +- include/linux/f2fs_fs.h | 15 --------------- 3 files changed, 3 insertions(+), 41 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 59bc46017855..bcac1bb7fad2 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -36,37 +36,14 @@ static unsigned int bucket_blocks(unsigned int level) return 4; } -static unsigned char f2fs_filetype_table[F2FS_FT_MAX] = { - [F2FS_FT_UNKNOWN] = DT_UNKNOWN, - [F2FS_FT_REG_FILE] = DT_REG, - [F2FS_FT_DIR] = DT_DIR, - [F2FS_FT_CHRDEV] = DT_CHR, - [F2FS_FT_BLKDEV] = DT_BLK, - [F2FS_FT_FIFO] = DT_FIFO, - [F2FS_FT_SOCK] = DT_SOCK, - [F2FS_FT_SYMLINK] = DT_LNK, -}; - -static unsigned char f2fs_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = F2FS_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = F2FS_FT_DIR, - [S_IFCHR >> S_SHIFT] = F2FS_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = F2FS_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = F2FS_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = F2FS_FT_SOCK, - [S_IFLNK >> S_SHIFT] = F2FS_FT_SYMLINK, -}; - static void set_de_type(struct f2fs_dir_entry *de, umode_t mode) { - de->file_type = f2fs_type_by_mode[(mode & S_IFMT) >> S_SHIFT]; + de->file_type = fs_umode_to_ftype(mode); } unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de) { - if (de->file_type < F2FS_FT_MAX) - return f2fs_filetype_table[de->file_type]; - return DT_UNKNOWN; + return fs_ftype_to_dtype(de->file_type); } static unsigned long dir_block_index(unsigned int level, diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index bb6a152310ef..cd935329e2d1 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -458,7 +458,7 @@ static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry) new_name.len = le16_to_cpu(de->name_len); ino = le32_to_cpu(de->ino); - fake_mode = f2fs_get_de_type(de) << S_SHIFT; + fake_mode = f2fs_get_de_type(de) << S_DT_SHIFT; err = f2fs_add_regular_entry(dir, &new_name, NULL, NULL, ino, fake_mode); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index f5740423b002..2f85d4d739b0 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -526,21 +526,6 @@ struct f2fs_dentry_block { __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; } __packed; -/* file types used in inode_info->flags */ -enum { - F2FS_FT_UNKNOWN, - F2FS_FT_REG_FILE, - F2FS_FT_DIR, - F2FS_FT_CHRDEV, - F2FS_FT_BLKDEV, - F2FS_FT_FIFO, - F2FS_FT_SOCK, - F2FS_FT_SYMLINK, - F2FS_FT_MAX -}; - -#define S_SHIFT 12 - #define F2FS_DEF_PROJID 0 /* default project ID */ #endif /* _LINUX_F2FS_FS_H */ From patchwork Tue Mar 26 21:39:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10872207 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 59B8B139A for ; Tue, 26 Mar 2019 21:39:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44DC1285FF for ; Tue, 26 Mar 2019 21:39:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38B7A286D1; Tue, 26 Mar 2019 21:39:31 +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 BC9F7285FF for ; Tue, 26 Mar 2019 21:39:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732785AbfCZVj3 (ORCPT ); Tue, 26 Mar 2019 17:39:29 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33663 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731840AbfCZVj2 (ORCPT ); Tue, 26 Mar 2019 17:39:28 -0400 Received: by mail-wr1-f65.google.com with SMTP id q1so16152818wrp.0 for ; Tue, 26 Mar 2019 14:39:27 -0700 (PDT) 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=giE9oMpXmpevw0T86z+Qz19u88nE7l1bF9K6tKNcF6w=; b=uha0P9CkNsk8vC+XPUaNLlIIfbIESxx+1WAi6rWp51ffR50G8hg+UISN6x3+7pgsTH 3297mkmXv9HvSERyLX9IPK/2534pnvZgmaC5KA1IjwC7EcgP1LjsVNhv2XJl3wbv82T1 wXIOGVfDmYxoXmzdhq1nZjo5p05/IBE0XYstwDBZwq8roGISKYLNXdY1hsIToK9k8lKS baCDb/3thVw/uyz+XpngiN/X6eUrTAtLtaXYz3NUBp4+uq1LAr2CqWaNvpp6KV171ygS 7l2ZlKX9NCqtEBQ4Cr7nqlTGhH95WlHGMRQEeSesKkumsXquf1SXCflEYa+uc2WpQRdv ZEZg== 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=giE9oMpXmpevw0T86z+Qz19u88nE7l1bF9K6tKNcF6w=; b=lC/0WImo8hkGkBR4uWMCAA6o7pLa8dM7ijFy8JC1gwP/1ITYYP9pzREohuoHSpjQSb I6XsV4xfLLgpXS67KI7q67Qrme7xvOf+u4oxCcLnWi+4IKTIsozX20CVdQIZmc0CrIcD NPEeCrJbAtbwYjqE78aZ9F0AOBdM3p6Hd5MHdX127JjthV8ys6t827eLiI1zknWZIRVp fwCFkYDFcCUL6qqTusM4SXd2/DpXW/J6CLnXYUrkLGcYh5T2Kadk5Hkdz9OWCQmgCWUv TkDwRAtmZVd4v04CnNtrH0j1qDfWT+NrHBRfsN4nwHDx949TKOvrb3c/flVi4H5eQY+i z/Jw== X-Gm-Message-State: APjAAAXa7GErYmOGwkKd3m2rCeGeRSQb/kz7lBTN2BTNdqP0sl60IBz4 HTpJWzyzyqCb5MP1L6k0BiFBTboAucurIQ== X-Google-Smtp-Source: APXvYqxT/Pq2RE0AOqMdrR/82C+x94EMS+ix0HlhmlG7rBez2SO8dZN4szlFOPELuXbTueJg4bEHiQ== X-Received: by 2002:adf:fd88:: with SMTP id d8mr15003127wrr.320.1553636366584; Tue, 26 Mar 2019 14:39:26 -0700 (PDT) Received: from pathfinder ([90.195.158.41]) by smtp.gmail.com with ESMTPSA id a9sm20322687wrt.29.2019.03.26.14.39.24 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 26 Mar 2019 14:39:25 -0700 (PDT) Date: Tue, 26 Mar 2019 21:39:24 +0000 From: Phillip Potter To: tytso@mit.edu Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v6 05/07] ext4: use common file type conversion Message-ID: <20190326213924.GA20880@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) 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 ext4 file type conversion implementation and define EXT4_FT_* to match shared FT_* - 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 Common implementation can be found via commit: bbe7449e2599 "fs: common implementation of file type" Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 82ffdacdc7fa..0bf97f21804f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1932,16 +1932,16 @@ struct ext4_dir_entry_tail { * Ext4 directory file types. Only the low 3 bits are used. The * other bits are reserved for now. */ -#define EXT4_FT_UNKNOWN 0 -#define EXT4_FT_REG_FILE 1 -#define EXT4_FT_DIR 2 -#define EXT4_FT_CHRDEV 3 -#define EXT4_FT_BLKDEV 4 -#define EXT4_FT_FIFO 5 -#define EXT4_FT_SOCK 6 -#define EXT4_FT_SYMLINK 7 +#define EXT4_FT_UNKNOWN FT_UNKNOWN +#define EXT4_FT_REG_FILE FT_REG_FILE +#define EXT4_FT_DIR FT_DIR +#define EXT4_FT_CHRDEV FT_CHRDEV +#define EXT4_FT_BLKDEV FT_BLKDEV +#define EXT4_FT_FIFO FT_FIFO +#define EXT4_FT_SOCK FT_SOCK +#define EXT4_FT_SYMLINK FT_SYMLINK -#define EXT4_FT_MAX 8 +#define EXT4_FT_MAX FT_MAX #define EXT4_FT_DIR_CSUM 0xDE @@ -2359,16 +2359,13 @@ static inline void ext4_update_dx_flag(struct inode *inode) if (!ext4_has_feature_dir_index(inode->i_sb)) ext4_clear_inode_flag(inode, EXT4_INODE_INDEX); } -static const unsigned char ext4_filetype_table[] = { - DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK -}; static inline unsigned char get_dtype(struct super_block *sb, int filetype) { - if (!ext4_has_feature_filetype(sb) || filetype >= EXT4_FT_MAX) + if (!ext4_has_feature_filetype(sb)) return DT_UNKNOWN; - return ext4_filetype_table[filetype]; + return fs_ftype_to_dtype(filetype); } extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, void *buf, int buf_size); @@ -3066,22 +3063,12 @@ extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t, extern int ext4_handle_dirty_dirent_node(handle_t *handle, struct inode *inode, struct buffer_head *bh); -#define S_SHIFT 12 -static const unsigned char ext4_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = { - [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR, - [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK, - [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK, -}; static inline void ext4_set_de_type(struct super_block *sb, struct ext4_dir_entry_2 *de, umode_t mode) { if (ext4_has_feature_filetype(sb)) - de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; + de->file_type = fs_umode_to_ftype(mode); } /* readpages.c */ From patchwork Tue Mar 26 21:39:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10872209 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 AA6D7925 for ; Tue, 26 Mar 2019 21:39:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94CD42861E for ; Tue, 26 Mar 2019 21:39:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8948128725; Tue, 26 Mar 2019 21:39:33 +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 1C8272861E for ; Tue, 26 Mar 2019 21:39:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731617AbfCZVjb (ORCPT ); Tue, 26 Mar 2019 17:39:31 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42877 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732792AbfCZVja (ORCPT ); Tue, 26 Mar 2019 17:39:30 -0400 Received: by mail-wr1-f68.google.com with SMTP id g3so12633242wrx.9 for ; Tue, 26 Mar 2019 14:39:29 -0700 (PDT) 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=fqttwbkefYLhjgLOmUnmIhg9tAwVEXC65nqj4TIeBL8=; b=WBLFnF5JnKRWzvcENFcBdyhjweG7WkOyaOLYGmmQgsbQ26BuxMZ/7Se16Qi1ju9wE/ clbQwATjNdbMBzsPINuA9hdM3OESW1ZUflE1zsgTrhcx11dddOGtT9nI6LDutHHG6cXL oLRid9WpdVdBKEzWvQSX7fNAQE7QGSRO2twt9Oqebx/iTjoesp5W0BXiE1p8yu88PSZ+ uZdfH1lcTg4NQswOm5md4ENCHg+9bKwuPhdHtM8xtBKbsdKGuvDxDpQyZyos7Gi/F1BK QaEeGxxf3nglrgwlAo733Ij/VWI6ANgofa7Jjf3yauYr2J4ES5oQscrqyME0YdCN9l4u /Uxg== 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=fqttwbkefYLhjgLOmUnmIhg9tAwVEXC65nqj4TIeBL8=; b=Q6vYWJxYv25y1nHaqIkLIb0rcOXw5v/6cBUwHUwgX+UOHkpUO961UBh1/HYuOQ2JN8 V+TS0Zz1aQYeYpqPnQIfRTkYFbPrSWUKsaDWfaxONNvruKx5Z4cvHfOTM0TU4jy7T6ci h0/KbmRIRDS6siY4Z+2575hd4AU7+bOP7fYMf1EP5FpnD4PfcfPpPOeDXsEAQq/18iS0 lG22Lo0KpjlbOZHh4NS7Uht8jduz1WllSa39zHRVHZ59evJhc1vGjgev1/bYPx7gszqI RlcQMUV6Vf/ZgFVlwtvLfuOFoiLxFMMYLWXEJ+DYNOkl1d4ugp8SzAJ8h+Gk4GHjnCM9 1waA== X-Gm-Message-State: APjAAAWbG0jI8Chow+cUBGUMr/yEi4KhKtoUuNITNN3tAU6VUfVh1K7p 5FbkFHAgY43n3HFKgUQSlnGLWQ== X-Google-Smtp-Source: APXvYqxYZw8+0/l8Ok7jA9W3pPs1H8NHmHlJDo6it9yNYtnLUG6W67Ls88dAuGGE+KaPRajVPBAT4w== X-Received: by 2002:a5d:6b4a:: with SMTP id x10mr20559290wrw.63.1553636368584; Tue, 26 Mar 2019 14:39:28 -0700 (PDT) Received: from pathfinder ([90.195.158.41]) by smtp.gmail.com with ESMTPSA id h84sm2008897wmf.15.2019.03.26.14.39.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 26 Mar 2019 14:39:27 -0700 (PDT) Date: Tue, 26 Mar 2019 21:39:26 +0000 From: Phillip Potter To: linux-nilfs@vger.kernel.org Cc: konishi.ryusuke@lab.ntt.co.jp, amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [PATCH v6 06/07] nilfs2: use common file type conversion Message-ID: <20190326213926.GA20881@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) 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 nilfs2 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 Common implementation can be found via commit: bbe7449e2599 "fs: common implementation of file type" Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/nilfs2/dir.c | 52 ++++++++++-------------------- include/uapi/linux/nilfs2_ondisk.h | 1 + 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c index 81394e22d0a0..f1c297ca8ec5 100644 --- a/fs/nilfs2/dir.c +++ b/fs/nilfs2/dir.c @@ -229,35 +229,23 @@ static struct nilfs_dir_entry *nilfs_next_entry(struct nilfs_dir_entry *p) nilfs_rec_len_from_disk(p->rec_len)); } -static unsigned char -nilfs_filetype_table[NILFS_FT_MAX] = { - [NILFS_FT_UNKNOWN] = DT_UNKNOWN, - [NILFS_FT_REG_FILE] = DT_REG, - [NILFS_FT_DIR] = DT_DIR, - [NILFS_FT_CHRDEV] = DT_CHR, - [NILFS_FT_BLKDEV] = DT_BLK, - [NILFS_FT_FIFO] = DT_FIFO, - [NILFS_FT_SOCK] = DT_SOCK, - [NILFS_FT_SYMLINK] = DT_LNK, -}; - -#define S_SHIFT 12 -static unsigned char -nilfs_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = NILFS_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = NILFS_FT_DIR, - [S_IFCHR >> S_SHIFT] = NILFS_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = NILFS_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = NILFS_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = NILFS_FT_SOCK, - [S_IFLNK >> S_SHIFT] = NILFS_FT_SYMLINK, -}; - static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode *inode) { - umode_t mode = inode->i_mode; - - de->file_type = nilfs_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; + /* + * compile-time asserts that generic FT_* types still match + * NILFS_FT_* types + */ + BUILD_BUG_ON(NILFS_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(NILFS_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(NILFS_FT_DIR != FT_DIR); + BUILD_BUG_ON(NILFS_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(NILFS_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(NILFS_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(NILFS_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(NILFS_FT_SYMLINK != FT_SYMLINK); + BUILD_BUG_ON(NILFS_FT_MAX != FT_MAX); + + de->file_type = fs_umode_to_ftype(inode->i_mode); } static int nilfs_readdir(struct file *file, struct dir_context *ctx) @@ -293,15 +281,9 @@ static int nilfs_readdir(struct file *file, struct dir_context *ctx) return -EIO; } if (de->inode) { - unsigned char t; - - if (de->file_type < NILFS_FT_MAX) - t = nilfs_filetype_table[de->file_type]; - else - t = DT_UNKNOWN; - if (!dir_emit(ctx, de->name, de->name_len, - le64_to_cpu(de->inode), t)) { + le64_to_cpu(de->inode), + fs_ftype_to_dtype(de->file_type))) { nilfs_put_page(page); return 0; } diff --git a/include/uapi/linux/nilfs2_ondisk.h b/include/uapi/linux/nilfs2_ondisk.h index a7e66ab11d1d..9223b616766b 100644 --- a/include/uapi/linux/nilfs2_ondisk.h +++ b/include/uapi/linux/nilfs2_ondisk.h @@ -309,6 +309,7 @@ struct nilfs_dir_entry { /* * NILFS directory file types. Only the low 3 bits are used. The * other bits are reserved for now. + * Values must match common file type values in fs_types.h. */ enum { NILFS_FT_UNKNOWN, From patchwork Tue Mar 26 21:39:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10872215 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 DF2FD186D for ; Tue, 26 Mar 2019 21:39:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD8E2285FF for ; Tue, 26 Mar 2019 21:39:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C20D228725; Tue, 26 Mar 2019 21:39:41 +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=unavailable 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 3BFD6285FF for ; Tue, 26 Mar 2019 21:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732804AbfCZVjj (ORCPT ); Tue, 26 Mar 2019 17:39:39 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41763 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731840AbfCZVjj (ORCPT ); Tue, 26 Mar 2019 17:39:39 -0400 Received: by mail-wr1-f66.google.com with SMTP id r4so8439475wrq.8 for ; Tue, 26 Mar 2019 14:39:37 -0700 (PDT) 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=Y8qHN2e/LSRSsoZ5oUVQLg6J0+syCMcTY6xQrqKRL70=; b=wWkff93g4DFq1gBlxPjvW3Fq9jBSHxOkADg0pK9uLw2RBj7JEc0YgAxsMKiKgK+LgG MDh+a3isAOjQUTVLq2ZWceob/P5veK7J+5SNm/aGi7xaXUrmcrYbqrPqhjLhgtIwXujs kYVKRqvy2U/PvM7TDgyS40/JphaOFoTHYMMBC+kRPo1Ot3RMqk8L2zWK09o2g/lPAwlL Fj+Wr7+FiPIWJLntGcX18OeOMYdRE994DdoibZjLflxmH0HxyEg9SxUM9TjDN4sj78og H49evmewJpCBrMAL5Wwww1KagYkF5MpbdZ5S862edZhZUUKyssdzNUIIYwzXRaQPSba5 FzkQ== 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=Y8qHN2e/LSRSsoZ5oUVQLg6J0+syCMcTY6xQrqKRL70=; b=gx09mIvGqjJL9cJD7GD3KtIyElUjKPNnk5hiQwFgLmG7nUUYa/OaTWHDWGGItc0HoD pcEIYYY5/LxNJyPeodl4XR7zK7tK73+uMUq+J/UNPQ98VcuwgXgcyU9rdg4BGXRCrj/j YDnfYWaDZ+4t5yxqu1tBeYxQxL7uKxYkVfkBOMZ0B+aXgm6OpKviHhQeBH2bjSZIkWmR kFu8s07YWuXZRiZdoagds8cpyyaDdtVwDzsPtPih8nbNYMI9PsIMvLNPXFDnSsto4/Nh Ysja4fW2zYFZ/ldUp7GSNh+eXazSmjT+U9BYAM4gfbV0L/G0ETFRY/01gMl1AK+Pak7o WiUQ== X-Gm-Message-State: APjAAAUY6zmi3Z7uoaJPhvNgMIKvRvXpfDrNfMtSs0UtnH/rDnP+tH5S kCWEHYjxoqOA5aLjfZqLKsD+SQ== X-Google-Smtp-Source: APXvYqyRX2nOJB0M5GOgMqtRmKBqo9tQrXtO2TT89VgjEsGEeN2SnDWmoltcpKRQSoejT8UqX/bQTg== X-Received: by 2002:a5d:6b0d:: with SMTP id v13mr22875690wrw.284.1553636376719; Tue, 26 Mar 2019 14:39:36 -0700 (PDT) Received: from pathfinder ([90.195.158.41]) by smtp.gmail.com with ESMTPSA id k4sm13704832wro.33.2019.03.26.14.39.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 26 Mar 2019 14:39:36 -0700 (PDT) Date: Tue, 26 Mar 2019 21:39:34 +0000 From: Phillip Potter To: clm@fb.com Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, jbacik@fb.com, dsterba@suse.com, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH v6 07/07] btrfs: use common file type conversion Message-ID: <20190326213934.GA20882@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) 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 btrfs 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 Common implementation can be found via commit: bbe7449e2599 "fs: common implementation of file type" Acked-by: David Sterba Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/btrfs/btrfs_inode.h | 2 -- fs/btrfs/delayed-inode.c | 2 +- fs/btrfs/inode.c | 32 +++++++++++++++----------------- include/uapi/linux/btrfs_tree.h | 2 ++ 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 6f5d07415dab..b16c13d51be0 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -203,8 +203,6 @@ struct btrfs_inode { struct inode vfs_inode; }; -extern unsigned char btrfs_filetype_table[]; - static inline struct btrfs_inode *BTRFS_I(const struct inode *inode) { return container_of(inode, struct btrfs_inode, vfs_inode); diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index c669f250d4a0..e61947f5eb76 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -1692,7 +1692,7 @@ int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, name = (char *)(di + 1); name_len = btrfs_stack_dir_name_len(di); - d_type = btrfs_filetype_table[di->type]; + d_type = fs_ftype_to_dtype(di->type); btrfs_disk_key_to_cpu(&location, &di->location); over = !dir_emit(ctx, name, name_len, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 82fdda8ff5ab..047609c27913 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -73,17 +73,6 @@ struct kmem_cache *btrfs_trans_handle_cachep; struct kmem_cache *btrfs_path_cachep; struct kmem_cache *btrfs_free_space_cachep; -#define S_SHIFT 12 -static const unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR, - [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK, - [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK, -}; - static int btrfs_setsize(struct inode *inode, struct iattr *attr); static int btrfs_truncate(struct inode *inode, bool skip_writeback); static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); @@ -5797,10 +5786,6 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry, return d_splice_alias(inode, dentry); } -unsigned char btrfs_filetype_table[] = { - DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK -}; - /* * All this infrastructure exists because dir_emit can fault, and we are holding * the tree lock when doing readdir. For now just allocate a buffer and copy @@ -5939,7 +5924,7 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) name_ptr = (char *)(entry + 1); read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1), name_len); - put_unaligned(btrfs_filetype_table[btrfs_dir_type(leaf, di)], + put_unaligned(fs_ftype_to_dtype(btrfs_dir_type(leaf, di)), &entry->type); btrfs_dir_item_key_to_cpu(leaf, di, &location); put_unaligned(location.objectid, &entry->ino); @@ -6344,7 +6329,20 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, static inline u8 btrfs_inode_type(struct inode *inode) { - return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT]; + /* + * compile-time asserts that generic FT_* types still match + * BTRFS_FT_* types + */ + BUILD_BUG_ON(BTRFS_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(BTRFS_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(BTRFS_FT_DIR != FT_DIR); + BUILD_BUG_ON(BTRFS_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(BTRFS_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(BTRFS_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(BTRFS_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(BTRFS_FT_SYMLINK != FT_SYMLINK); + + return fs_umode_to_ftype(inode->i_mode); } /* diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index e974f4bb5378..421239b98db2 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -307,6 +307,8 @@ * * Used by: * struct btrfs_dir_item.type + * + * Values 0..7 must match common file type values in fs_types.h. */ #define BTRFS_FT_UNKNOWN 0 #define BTRFS_FT_REG_FILE 1