From patchwork Wed Sep 4 02:08:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129127 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B8D91399 for ; Wed, 4 Sep 2019 02:10:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37F3C233A1 for ; Wed, 4 Sep 2019 02:10:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727701AbfIDCKR (ORCPT ); Tue, 3 Sep 2019 22:10:17 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5740 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727381AbfIDCKQ (ORCPT ); Tue, 3 Sep 2019 22:10:16 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 575B02FF21D1C15272DF; Wed, 4 Sep 2019 10:10:15 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:05 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 01/25] erofs: remove all the byte offset comments Date: Wed, 4 Sep 2019 10:08:48 +0800 Message-ID: <20190904020912.63925-2-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph suggested [1], "Please remove all the byte offset comments. that is something that can easily be checked with gdb or pahole." [1] https://lore.kernel.org/r/20190829095954.GB20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/erofs_fs.h | 105 +++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index afa7d45ca958..49335fff9d65 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -17,27 +17,28 @@ #define EROFS_REQUIREMENT_LZ4_0PADDING 0x00000001 #define EROFS_ALL_REQUIREMENTS EROFS_REQUIREMENT_LZ4_0PADDING +/* 128-byte erofs on-disk super block */ struct erofs_super_block { -/* 0 */__le32 magic; /* in the little endian */ -/* 4 */__le32 checksum; /* crc32c(super_block) */ -/* 8 */__le32 features; /* (aka. feature_compat) */ -/* 12 */__u8 blkszbits; /* support block_size == PAGE_SIZE only */ -/* 13 */__u8 reserved; - -/* 14 */__le16 root_nid; -/* 16 */__le64 inos; /* total valid ino # (== f_files - f_favail) */ - -/* 24 */__le64 build_time; /* inode v1 time derivation */ -/* 32 */__le32 build_time_nsec; -/* 36 */__le32 blocks; /* used for statfs */ -/* 40 */__le32 meta_blkaddr; -/* 44 */__le32 xattr_blkaddr; -/* 48 */__u8 uuid[16]; /* 128-bit uuid for volume */ -/* 64 */__u8 volume_name[16]; /* volume name */ -/* 80 */__le32 requirements; /* (aka. feature_incompat) */ - -/* 84 */__u8 reserved2[44]; -} __packed; /* 128 bytes */ + __le32 magic; /* file system magic number */ + __le32 checksum; /* crc32c(super_block) */ + __le32 features; /* (aka. feature_compat) */ + __u8 blkszbits; /* support block_size == PAGE_SIZE only */ + __u8 reserved; + + __le16 root_nid; /* nid of root directory */ + __le64 inos; /* total valid ino # (== f_files - f_favail) */ + + __le64 build_time; /* inode v1 time derivation */ + __le32 build_time_nsec; /* inode v1 time derivation in nano scale */ + __le32 blocks; /* used for statfs */ + __le32 meta_blkaddr; /* start block address of metadata area */ + __le32 xattr_blkaddr; /* start block address of shared xattr area */ + __u8 uuid[16]; /* 128-bit uuid for volume */ + __u8 volume_name[16]; /* volume name */ + __le32 requirements; /* (aka. feature_incompat) */ + + __u8 reserved2[44]; +} __packed; /* * erofs inode data mapping: @@ -73,16 +74,17 @@ static inline bool erofs_inode_is_data_compressed(unsigned int datamode) #define EROFS_I_VERSION_BIT 0 #define EROFS_I_DATA_MAPPING_BIT 1 +/* 32-byte reduced form of an ondisk inode */ struct erofs_inode_v1 { -/* 0 */__le16 i_advise; + __le16 i_advise; /* inode hints */ /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ -/* 2 */__le16 i_xattr_icount; -/* 4 */__le16 i_mode; -/* 6 */__le16 i_nlink; -/* 8 */__le32 i_size; -/* 12 */__le32 i_reserved; -/* 16 */union { + __le16 i_xattr_icount; + __le16 i_mode; + __le16 i_nlink; + __le32 i_size; + __le32 i_reserved; + union { /* file total compressed blocks for data mapping 1 */ __le32 compressed_blocks; __le32 raw_blkaddr; @@ -90,10 +92,10 @@ struct erofs_inode_v1 { /* for device files, used to indicate old/new device # */ __le32 rdev; } i_u __packed; -/* 20 */__le32 i_ino; /* only used for 32-bit stat compatibility */ -/* 24 */__le16 i_uid; -/* 26 */__le16 i_gid; -/* 28 */__le32 i_reserved2; + __le32 i_ino; /* only used for 32-bit stat compatibility */ + __le16 i_uid; + __le16 i_gid; + __le32 i_reserved2; } __packed; /* 32 bytes on-disk inode */ @@ -101,15 +103,16 @@ struct erofs_inode_v1 { /* 64 bytes on-disk inode */ #define EROFS_INODE_LAYOUT_V2 1 +/* 64-byte complete form of an ondisk inode */ struct erofs_inode_v2 { -/* 0 */__le16 i_advise; + __le16 i_advise; /* inode hints */ /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ -/* 2 */__le16 i_xattr_icount; -/* 4 */__le16 i_mode; -/* 6 */__le16 i_reserved; -/* 8 */__le64 i_size; -/* 16 */union { + __le16 i_xattr_icount; + __le16 i_mode; + __le16 i_reserved; + __le64 i_size; + union { /* file total compressed blocks for data mapping 1 */ __le32 compressed_blocks; __le32 raw_blkaddr; @@ -119,15 +122,15 @@ struct erofs_inode_v2 { } i_u __packed; /* only used for 32-bit stat compatibility */ -/* 20 */__le32 i_ino; - -/* 24 */__le32 i_uid; -/* 28 */__le32 i_gid; -/* 32 */__le64 i_ctime; -/* 40 */__le32 i_ctime_nsec; -/* 44 */__le32 i_nlink; -/* 48 */__u8 i_reserved2[16]; -} __packed; /* 64 bytes */ + __le32 i_ino; + + __le32 i_uid; + __le32 i_gid; + __le64 i_ctime; + __le32 i_ctime_nsec; + __le32 i_nlink; + __u8 i_reserved2[16]; +} __packed; #define EROFS_MAX_SHARED_XATTRS (128) /* h_shared_count between 129 ... 255 are special # */ @@ -264,7 +267,7 @@ struct z_erofs_vle_decompressed_index { * [1] - pointing to the tail cluster */ __le16 delta[2]; - } di_u __packed; /* 8 bytes */ + } di_u __packed; } __packed; #define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \ @@ -273,10 +276,10 @@ struct z_erofs_vle_decompressed_index { /* dirent sorts in alphabet order, thus we can do binary search */ struct erofs_dirent { - __le64 nid; /* 0, node number */ - __le16 nameoff; /* 8, start offset of file name */ - __u8 file_type; /* 10, file type */ - __u8 reserved; /* 11, reserved */ + __le64 nid; /* node number */ + __le16 nameoff; /* start offset of file name */ + __u8 file_type; /* file type */ + __u8 reserved; /* reserved */ } __packed; /* From patchwork Wed Sep 4 02:08:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46DCA17EF for ; Wed, 4 Sep 2019 02:10:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 265A1233A1 for ; Wed, 4 Sep 2019 02:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727664AbfIDCKQ (ORCPT ); Tue, 3 Sep 2019 22:10:16 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5739 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727348AbfIDCKQ (ORCPT ); Tue, 3 Sep 2019 22:10:16 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 525D9A02AB4F0FA6D09C; Wed, 4 Sep 2019 10:10:15 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:06 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 02/25] erofs: on-disk format should have explicitly assigned numbers Date: Wed, 4 Sep 2019 10:08:49 +0800 Message-ID: <20190904020912.63925-3-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph suggested [1], on-disk format should have explicitly assigned numbers. [1] https://lore.kernel.org/r/20190829095954.GB20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/erofs_fs.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index 49335fff9d65..d1f152a3670a 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -53,10 +53,10 @@ struct erofs_super_block { * 4~7 - reserved */ enum { - EROFS_INODE_FLAT_PLAIN, - EROFS_INODE_FLAT_COMPRESSION_LEGACY, - EROFS_INODE_FLAT_INLINE, - EROFS_INODE_FLAT_COMPRESSION, + EROFS_INODE_FLAT_PLAIN = 0, + EROFS_INODE_FLAT_COMPRESSION_LEGACY = 1, + EROFS_INODE_FLAT_INLINE = 2, + EROFS_INODE_FLAT_COMPRESSION = 3, EROFS_INODE_LAYOUT_MAX }; @@ -184,7 +184,7 @@ struct erofs_xattr_entry { /* available compression algorithm types */ enum { - Z_EROFS_COMPRESSION_LZ4, + Z_EROFS_COMPRESSION_LZ4 = 0, Z_EROFS_COMPRESSION_MAX }; @@ -242,10 +242,10 @@ struct z_erofs_map_header { * (di_advise could be 0, 1 or 2) */ enum { - Z_EROFS_VLE_CLUSTER_TYPE_PLAIN, - Z_EROFS_VLE_CLUSTER_TYPE_HEAD, - Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD, - Z_EROFS_VLE_CLUSTER_TYPE_RESERVED, + Z_EROFS_VLE_CLUSTER_TYPE_PLAIN = 0, + Z_EROFS_VLE_CLUSTER_TYPE_HEAD = 1, + Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD = 2, + Z_EROFS_VLE_CLUSTER_TYPE_RESERVED = 3, Z_EROFS_VLE_CLUSTER_TYPE_MAX }; From patchwork Wed Sep 4 02:08:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129129 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AC7317EF for ; Wed, 4 Sep 2019 02:10:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0528A2339D for ; Wed, 4 Sep 2019 02:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727709AbfIDCKT (ORCPT ); Tue, 3 Sep 2019 22:10:19 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6192 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727381AbfIDCKT (ORCPT ); Tue, 3 Sep 2019 22:10:19 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7F63A171F2FC74A1B58E; Wed, 4 Sep 2019 10:10:15 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:07 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 03/25] erofs: some macros are much more readable as a function Date: Wed, 4 Sep 2019 10:08:50 +0800 Message-ID: <20190904020912.63925-4-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph suggested [1], these macros are much more readable as a function. [1] https://lore.kernel.org/r/20190829095954.GB20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/erofs_fs.h | 22 ++++++++++++++-------- fs/erofs/inode.c | 4 ++-- fs/erofs/xattr.c | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index d1f152a3670a..c1220b0f26e0 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -171,16 +171,22 @@ struct erofs_xattr_entry { char e_name[0]; /* attribute name */ } __packed; -#define ondisk_xattr_ibody_size(count) ({\ - u32 __count = le16_to_cpu(count); \ - ((__count) == 0) ? 0 : \ - sizeof(struct erofs_xattr_ibody_header) + \ - sizeof(__u32) * ((__count) - 1); }) +static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount) +{ + if (!i_xattr_icount) + return 0; + + return sizeof(struct erofs_xattr_ibody_header) + + sizeof(__u32) * (le16_to_cpu(i_xattr_icount) - 1); +} #define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry)) -#define EROFS_XATTR_ENTRY_SIZE(entry) EROFS_XATTR_ALIGN( \ - sizeof(struct erofs_xattr_entry) + \ - (entry)->e_name_len + le16_to_cpu((entry)->e_value_size)) + +static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e) +{ + return EROFS_XATTR_ALIGN(sizeof(struct erofs_xattr_entry) + + e->e_name_len + le16_to_cpu(e->e_value_size)); +} /* available compression algorithm types */ enum { diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 8a0574530a0a..3fc4f764b387 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -29,7 +29,7 @@ static int read_inode(struct inode *inode, void *data) struct erofs_inode_v2 *v2 = data; vi->inode_isize = sizeof(struct erofs_inode_v2); - vi->xattr_isize = ondisk_xattr_ibody_size(v2->i_xattr_icount); + vi->xattr_isize = erofs_xattr_ibody_size(v2->i_xattr_icount); inode->i_mode = le16_to_cpu(v2->i_mode); if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || @@ -62,7 +62,7 @@ static int read_inode(struct inode *inode, void *data) struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); vi->inode_isize = sizeof(struct erofs_inode_v1); - vi->xattr_isize = ondisk_xattr_ibody_size(v1->i_xattr_icount); + vi->xattr_isize = erofs_xattr_ibody_size(v1->i_xattr_icount); inode->i_mode = le16_to_cpu(v1->i_mode); if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index d80f61dde72f..620cbc15f4d0 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -231,7 +231,7 @@ static int xattr_foreach(struct xattr_iter *it, */ entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); if (tlimit) { - unsigned int entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry); + unsigned int entry_sz = erofs_xattr_entry_size(&entry); /* xattr on-disk corruption: xattr entry beyond xattr_isize */ if (*tlimit < entry_sz) { From patchwork Wed Sep 4 02:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129125 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B3E61813 for ; Wed, 4 Sep 2019 02:10:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6CE2B233A1 for ; Wed, 4 Sep 2019 02:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727692AbfIDCKQ (ORCPT ); Tue, 3 Sep 2019 22:10:16 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5738 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726925AbfIDCKQ (ORCPT ); Tue, 3 Sep 2019 22:10:16 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4D35536BA690EBFB9591; Wed, 4 Sep 2019 10:10:15 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:08 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 04/25] erofs: kill __packed for on-disk structures Date: Wed, 4 Sep 2019 10:08:51 +0800 Message-ID: <20190904020912.63925-5-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph suggested "Please don't add __packed" [1], remove all __packed except struct erofs_dirent here. Note that all on-disk fields except struct erofs_dirent (12 bytes with a 8-byte nid) in EROFS are naturally aligned. [1] https://lore.kernel.org/r/20190829095954.GB20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/erofs_fs.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index c1220b0f26e0..59dcc2e8cb02 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -38,7 +38,7 @@ struct erofs_super_block { __le32 requirements; /* (aka. feature_incompat) */ __u8 reserved2[44]; -} __packed; +}; /* * erofs inode data mapping: @@ -91,12 +91,12 @@ struct erofs_inode_v1 { /* for device files, used to indicate old/new device # */ __le32 rdev; - } i_u __packed; + } i_u; __le32 i_ino; /* only used for 32-bit stat compatibility */ __le16 i_uid; __le16 i_gid; __le32 i_reserved2; -} __packed; +}; /* 32 bytes on-disk inode */ #define EROFS_INODE_LAYOUT_V1 0 @@ -119,7 +119,7 @@ struct erofs_inode_v2 { /* for device files, used to indicate old/new device # */ __le32 rdev; - } i_u __packed; + } i_u; /* only used for 32-bit stat compatibility */ __le32 i_ino; @@ -130,7 +130,7 @@ struct erofs_inode_v2 { __le32 i_ctime_nsec; __le32 i_nlink; __u8 i_reserved2[16]; -} __packed; +}; #define EROFS_MAX_SHARED_XATTRS (128) /* h_shared_count between 129 ... 255 are special # */ @@ -152,7 +152,7 @@ struct erofs_xattr_ibody_header { __u8 h_shared_count; __u8 h_reserved2[7]; __le32 h_shared_xattrs[0]; /* shared xattr id array */ -} __packed; +}; /* Name indexes */ #define EROFS_XATTR_INDEX_USER 1 @@ -169,7 +169,7 @@ struct erofs_xattr_entry { __le16 e_value_size; /* size of attribute value */ /* followed by e_name and e_value */ char e_name[0]; /* attribute name */ -} __packed; +}; static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount) { @@ -273,8 +273,8 @@ struct z_erofs_vle_decompressed_index { * [1] - pointing to the tail cluster */ __le16 delta[2]; - } di_u __packed; -} __packed; + } di_u; +}; #define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \ (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \ From patchwork Wed Sep 4 02:08:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E974217EF for ; Wed, 4 Sep 2019 02:10:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C72B623400 for ; Wed, 4 Sep 2019 02:10:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727828AbfIDCKW (ORCPT ); Tue, 3 Sep 2019 22:10:22 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:57228 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727381AbfIDCKW (ORCPT ); Tue, 3 Sep 2019 22:10:22 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5B6A46BC7B4DED72A622; Wed, 4 Sep 2019 10:10:20 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:09 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 05/25] erofs: update erofs_inode_is_data_compressed helper Date: Wed, 4 Sep 2019 10:08:52 +0800 Message-ID: <20190904020912.63925-6-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said, "This looks like a really obsfucated way to write: return datamode == EROFS_INODE_FLAT_COMPRESSION || datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY; " Although I had my own consideration, it's the right way for now. [1] https://lore.kernel.org/r/20190829095954.GB20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/erofs_fs.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index 59dcc2e8cb02..87d7ae82339a 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -62,9 +62,8 @@ enum { static inline bool erofs_inode_is_data_compressed(unsigned int datamode) { - if (datamode == EROFS_INODE_FLAT_COMPRESSION) - return true; - return datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY; + return datamode == EROFS_INODE_FLAT_COMPRESSION || + datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY; } /* bit definitions of inode i_advise */ From patchwork Wed Sep 4 02:08:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129135 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3241C1399 for ; Wed, 4 Sep 2019 02:10:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E18D23400 for ; Wed, 4 Sep 2019 02:10:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727860AbfIDCKX (ORCPT ); Tue, 3 Sep 2019 22:10:23 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:57234 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727716AbfIDCKW (ORCPT ); Tue, 3 Sep 2019 22:10:22 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 60BE85B9F2CE80E7185B; Wed, 4 Sep 2019 10:10:20 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:11 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 06/25] erofs: use feature_incompat rather than requirements Date: Wed, 4 Sep 2019 10:08:53 +0800 Message-ID: <20190904020912.63925-7-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said [1], "This is only cosmetic, why not stick to feature_compat and feature_incompat?" In my thought, requirements means "incompatible" instead of "feature" though. [1] https://lore.kernel.org/r/20190902125109.GA9826@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/decompressor.c | 3 ++- fs/erofs/erofs_fs.h | 12 ++++++------ fs/erofs/internal.h | 2 +- fs/erofs/super.c | 10 +++++----- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index df349888f911..555c04730f87 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -129,7 +129,8 @@ static int lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out) support_0padding = false; /* decompression inplace is only safe when 0padding is enabled */ - if (EROFS_SB(rq->sb)->requirements & EROFS_REQUIREMENT_LZ4_0PADDING) { + if (EROFS_SB(rq->sb)->feature_incompat & + EROFS_FEATURE_INCOMPAT_LZ4_0PADDING) { support_0padding = true; while (!src[inputmargin & ~PAGE_MASK]) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index 87d7ae82339a..b2aef3bc377d 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -11,17 +11,17 @@ #define EROFS_SUPER_OFFSET 1024 /* - * Any bits that aren't in EROFS_ALL_REQUIREMENTS should be - * incompatible with this kernel version. + * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should + * be incompatible with this kernel version. */ -#define EROFS_REQUIREMENT_LZ4_0PADDING 0x00000001 -#define EROFS_ALL_REQUIREMENTS EROFS_REQUIREMENT_LZ4_0PADDING +#define EROFS_FEATURE_INCOMPAT_LZ4_0PADDING 0x00000001 +#define EROFS_ALL_FEATURE_INCOMPAT EROFS_FEATURE_INCOMPAT_LZ4_0PADDING /* 128-byte erofs on-disk super block */ struct erofs_super_block { __le32 magic; /* file system magic number */ __le32 checksum; /* crc32c(super_block) */ - __le32 features; /* (aka. feature_compat) */ + __le32 feature_compat; __u8 blkszbits; /* support block_size == PAGE_SIZE only */ __u8 reserved; @@ -35,7 +35,7 @@ struct erofs_super_block { __le32 xattr_blkaddr; /* start block address of shared xattr area */ __u8 uuid[16]; /* 128-bit uuid for volume */ __u8 volume_name[16]; /* volume name */ - __le32 requirements; /* (aka. feature_incompat) */ + __le32 feature_incompat; __u8 reserved2[44]; }; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 141ea424587d..7ff36f404ec3 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -96,7 +96,7 @@ struct erofs_sb_info { u8 uuid[16]; /* 128-bit uuid for volume */ u8 volume_name[16]; /* volume name */ - u32 requirements; + u32 feature_incompat; unsigned int mount_opt; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 6603f0ba8905..6a7ab194783c 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -67,14 +67,14 @@ static void free_inode(struct inode *inode) static bool check_layout_compatibility(struct super_block *sb, struct erofs_super_block *layout) { - const unsigned int requirements = le32_to_cpu(layout->requirements); + const unsigned int feature = le32_to_cpu(layout->feature_incompat); - EROFS_SB(sb)->requirements = requirements; + EROFS_SB(sb)->feature_incompat = feature; /* check if current kernel meets all mandatory requirements */ - if (requirements & (~EROFS_ALL_REQUIREMENTS)) { - errln("unidentified requirements %x, please upgrade kernel version", - requirements & ~EROFS_ALL_REQUIREMENTS); + if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) { + errln("unidentified incompatible feature %x, please upgrade kernel version", + feature & ~EROFS_ALL_FEATURE_INCOMPAT); return false; } return true; From patchwork Wed Sep 4 02:08:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129137 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2F151813 for ; Wed, 4 Sep 2019 02:10:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D7DF22DBF for ; Wed, 4 Sep 2019 02:10:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727881AbfIDCKX (ORCPT ); Tue, 3 Sep 2019 22:10:23 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:59684 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727722AbfIDCKW (ORCPT ); Tue, 3 Sep 2019 22:10:22 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 8D21EBA2F371D9041CE6; Wed, 4 Sep 2019 10:10:20 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:12 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 07/25] erofs: better naming for erofs inode related stuffs Date: Wed, 4 Sep 2019 10:08:54 +0800 Message-ID: <20190904020912.63925-8-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org updates inode naming - kill is_inode_layout_compression [1] - kill magic underscores [2] [3] - better naming for datamode & data_mapping_mode [3] - better naming erofs_inode_{compact, extended} [4] [1] https://lore.kernel.org/r/20190829102426.GE20598@infradead.org/ [2] https://lore.kernel.org/r/20190829102426.GE20598@infradead.org/ [3] https://lore.kernel.org/r/20190902122627.GN15931@infradead.org/ [4] https://lore.kernel.org/r/20190902125438.GA17750@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/data.c | 9 ++-- fs/erofs/erofs_fs.h | 24 ++++----- fs/erofs/inode.c | 126 +++++++++++++++++++++++++------------------- fs/erofs/internal.h | 31 ++++++----- fs/erofs/super.c | 2 +- fs/erofs/zmap.c | 6 +-- 6 files changed, 108 insertions(+), 90 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 0983807737fd..4d9b07991d07 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -113,11 +113,12 @@ static int erofs_map_blocks_flatmode(struct inode *inode, erofs_blk_t nblocks, lastblk; u64 offset = map->m_la; struct erofs_vnode *vi = EROFS_V(inode); + bool tailendpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE); trace_erofs_map_blocks_flatmode_enter(inode, map, flags); nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE); - lastblk = nblocks - is_inode_flat_inline(inode); + lastblk = nblocks - tailendpacking; if (offset >= inode->i_size) { /* leave out-of-bound access unmapped */ @@ -132,7 +133,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode, if (offset < blknr_to_addr(lastblk)) { map->m_pa = blknr_to_addr(vi->raw_blkaddr) + map->m_la; map->m_plen = blknr_to_addr(lastblk) - offset; - } else if (is_inode_flat_inline(inode)) { + } else if (tailendpacking) { /* 2 - inode inline B: inode, [xattrs], inline last blk... */ struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); @@ -169,7 +170,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode, int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map, int flags) { - if (is_inode_layout_compression(inode)) { + if (erofs_inode_is_data_compressed(EROFS_V(inode)->datalayout)) { int err = z_erofs_map_blocks_iter(inode, map, flags); if (map->mpage) { @@ -403,7 +404,7 @@ static sector_t erofs_bmap(struct address_space *mapping, sector_t block) { struct inode *inode = mapping->host; - if (is_inode_flat_inline(inode)) { + if (EROFS_V(inode)->datalayout == EROFS_INODE_FLAT_INLINE) { erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE; if (block >> LOG_SECTORS_PER_BLOCK >= blks) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index b2aef3bc377d..18689e916e94 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -41,7 +41,7 @@ struct erofs_super_block { }; /* - * erofs inode data mapping: + * erofs inode datalayout: * 0 - inode plain without inline data A: * inode, [xattrs], ... | ... | no-holed data * 1 - inode VLE compression B (legacy): @@ -57,7 +57,7 @@ enum { EROFS_INODE_FLAT_COMPRESSION_LEGACY = 1, EROFS_INODE_FLAT_INLINE = 2, EROFS_INODE_FLAT_COMPRESSION = 3, - EROFS_INODE_LAYOUT_MAX + EROFS_INODE_DATALAYOUT_MAX }; static inline bool erofs_inode_is_data_compressed(unsigned int datamode) @@ -68,14 +68,14 @@ static inline bool erofs_inode_is_data_compressed(unsigned int datamode) /* bit definitions of inode i_advise */ #define EROFS_I_VERSION_BITS 1 -#define EROFS_I_DATA_MAPPING_BITS 3 +#define EROFS_I_DATALAYOUT_BITS 3 #define EROFS_I_VERSION_BIT 0 -#define EROFS_I_DATA_MAPPING_BIT 1 +#define EROFS_I_DATALAYOUT_BIT 1 /* 32-byte reduced form of an ondisk inode */ -struct erofs_inode_v1 { - __le16 i_advise; /* inode hints */ +struct erofs_inode_compact { + __le16 i_format; /* inode format hints */ /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ __le16 i_xattr_icount; @@ -98,13 +98,13 @@ struct erofs_inode_v1 { }; /* 32 bytes on-disk inode */ -#define EROFS_INODE_LAYOUT_V1 0 +#define EROFS_INODE_LAYOUT_COMPACT 0 /* 64 bytes on-disk inode */ -#define EROFS_INODE_LAYOUT_V2 1 +#define EROFS_INODE_LAYOUT_EXTENDED 1 /* 64-byte complete form of an ondisk inode */ -struct erofs_inode_v2 { - __le16 i_advise; /* inode hints */ +struct erofs_inode_extended { + __le16 i_format; /* inode format hints */ /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ __le16 i_xattr_icount; @@ -299,8 +299,8 @@ struct erofs_dirent { static inline void erofs_check_ondisk_layout_definitions(void) { BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128); - BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32); - BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64); + BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32); + BUILD_BUG_ON(sizeof(struct erofs_inode_extended) != 64); BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12); BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4); BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8); diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 3fc4f764b387..494b35e5830a 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -12,73 +12,90 @@ static int read_inode(struct inode *inode, void *data) { struct erofs_vnode *vi = EROFS_V(inode); - struct erofs_inode_v1 *v1 = data; - const unsigned int advise = le16_to_cpu(v1->i_advise); + struct erofs_inode_compact *dic = data; + struct erofs_inode_extended *die; + + const unsigned int ifmt = le16_to_cpu(dic->i_format); + struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); erofs_blk_t nblks = 0; - vi->datamode = __inode_data_mapping(advise); + vi->datalayout = erofs_inode_datalayout(ifmt); - if (vi->datamode >= EROFS_INODE_LAYOUT_MAX) { - errln("unsupported data mapping %u of nid %llu", - vi->datamode, vi->nid); + if (vi->datalayout >= EROFS_INODE_DATALAYOUT_MAX) { + errln("unsupported datalayout %u of nid %llu", + vi->datalayout, vi->nid); DBG_BUGON(1); return -EOPNOTSUPP; } - if (__inode_version(advise) == EROFS_INODE_LAYOUT_V2) { - struct erofs_inode_v2 *v2 = data; + switch (erofs_inode_version(ifmt)) { + case EROFS_INODE_LAYOUT_EXTENDED: + die = data; - vi->inode_isize = sizeof(struct erofs_inode_v2); - vi->xattr_isize = erofs_xattr_ibody_size(v2->i_xattr_icount); + vi->inode_isize = sizeof(struct erofs_inode_extended); + vi->xattr_isize = erofs_xattr_ibody_size(die->i_xattr_icount); - inode->i_mode = le16_to_cpu(v2->i_mode); - if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || - S_ISLNK(inode->i_mode)) - vi->raw_blkaddr = le32_to_cpu(v2->i_u.raw_blkaddr); - else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) + inode->i_mode = le16_to_cpu(die->i_mode); + switch (inode->i_mode & S_IFMT) { + case S_IFREG: + case S_IFDIR: + case S_IFLNK: + vi->raw_blkaddr = le32_to_cpu(die->i_u.raw_blkaddr); + break; + case S_IFCHR: + case S_IFBLK: inode->i_rdev = - new_decode_dev(le32_to_cpu(v2->i_u.rdev)); - else if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) + new_decode_dev(le32_to_cpu(die->i_u.rdev)); + break; + case S_IFIFO: + case S_IFSOCK: inode->i_rdev = 0; - else + break; + default: goto bogusimode; - - i_uid_write(inode, le32_to_cpu(v2->i_uid)); - i_gid_write(inode, le32_to_cpu(v2->i_gid)); - set_nlink(inode, le32_to_cpu(v2->i_nlink)); + } + i_uid_write(inode, le32_to_cpu(die->i_uid)); + i_gid_write(inode, le32_to_cpu(die->i_gid)); + set_nlink(inode, le32_to_cpu(die->i_nlink)); /* ns timestamp */ inode->i_mtime.tv_sec = inode->i_ctime.tv_sec = - le64_to_cpu(v2->i_ctime); + le64_to_cpu(die->i_ctime); inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = - le32_to_cpu(v2->i_ctime_nsec); + le32_to_cpu(die->i_ctime_nsec); - inode->i_size = le64_to_cpu(v2->i_size); + inode->i_size = le64_to_cpu(die->i_size); /* total blocks for compressed files */ - if (is_inode_layout_compression(inode)) - nblks = le32_to_cpu(v2->i_u.compressed_blocks); - } else if (__inode_version(advise) == EROFS_INODE_LAYOUT_V1) { - struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); - - vi->inode_isize = sizeof(struct erofs_inode_v1); - vi->xattr_isize = erofs_xattr_ibody_size(v1->i_xattr_icount); - - inode->i_mode = le16_to_cpu(v1->i_mode); - if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || - S_ISLNK(inode->i_mode)) - vi->raw_blkaddr = le32_to_cpu(v1->i_u.raw_blkaddr); - else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) + if (erofs_inode_is_data_compressed(vi->datalayout)) + nblks = le32_to_cpu(die->i_u.compressed_blocks); + break; + case EROFS_INODE_LAYOUT_COMPACT: + vi->inode_isize = sizeof(struct erofs_inode_compact); + vi->xattr_isize = erofs_xattr_ibody_size(dic->i_xattr_icount); + + inode->i_mode = le16_to_cpu(dic->i_mode); + switch (inode->i_mode & S_IFMT) { + case S_IFREG: + case S_IFDIR: + case S_IFLNK: + vi->raw_blkaddr = le32_to_cpu(dic->i_u.raw_blkaddr); + break; + case S_IFCHR: + case S_IFBLK: inode->i_rdev = - new_decode_dev(le32_to_cpu(v1->i_u.rdev)); - else if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) + new_decode_dev(le32_to_cpu(dic->i_u.rdev)); + break; + case S_IFIFO: + case S_IFSOCK: inode->i_rdev = 0; - else + break; + default: goto bogusimode; - - i_uid_write(inode, le16_to_cpu(v1->i_uid)); - i_gid_write(inode, le16_to_cpu(v1->i_gid)); - set_nlink(inode, le16_to_cpu(v1->i_nlink)); + } + i_uid_write(inode, le16_to_cpu(dic->i_uid)); + i_gid_write(inode, le16_to_cpu(dic->i_gid)); + set_nlink(inode, le16_to_cpu(dic->i_nlink)); /* use build time to derive all file time */ inode->i_mtime.tv_sec = inode->i_ctime.tv_sec = @@ -86,12 +103,13 @@ static int read_inode(struct inode *inode, void *data) inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = sbi->build_time_nsec; - inode->i_size = le32_to_cpu(v1->i_size); - if (is_inode_layout_compression(inode)) - nblks = le32_to_cpu(v1->i_u.compressed_blocks); - } else { + inode->i_size = le32_to_cpu(dic->i_size); + if (erofs_inode_is_data_compressed(vi->datalayout)) + nblks = le32_to_cpu(dic->i_u.compressed_blocks); + break; + default: errln("unsupported on-disk inode version %u of nid %llu", - __inode_version(advise), vi->nid); + erofs_inode_version(ifmt), vi->nid); DBG_BUGON(1); return -EOPNOTSUPP; } @@ -125,8 +143,8 @@ static int fill_inline_data(struct inode *inode, void *data, struct erofs_vnode *vi = EROFS_V(inode); struct erofs_sb_info *sbi = EROFS_I_SB(inode); - /* should be inode inline C */ - if (!is_inode_flat_inline(inode)) + /* should be tail-packing data inline */ + if (vi->datalayout != EROFS_INODE_FLAT_INLINE) return 0; /* fast symlink (following ext4) */ @@ -216,7 +234,7 @@ static int fill_inode(struct inode *inode, int isdir) goto out_unlock; } - if (is_inode_layout_compression(inode)) { + if (erofs_inode_is_data_compressed(vi->datalayout)) { err = z_erofs_fill_inode(inode); goto out_unlock; } @@ -299,7 +317,7 @@ int erofs_getattr(const struct path *path, struct kstat *stat, { struct inode *const inode = d_inode(path->dentry); - if (is_inode_layout_compression(inode)) + if (erofs_inode_is_data_compressed(EROFS_V(inode)->datalayout)) stat->attributes |= STATX_ATTR_COMPRESSED; stat->attributes |= STATX_ATTR_IMMUTABLE; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 7ff36f404ec3..0f5cbf0a7570 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -285,7 +285,7 @@ struct erofs_vnode { /* atomic flags (including bitlocks) */ unsigned long flags; - unsigned char datamode; + unsigned char datalayout; unsigned char inode_isize; unsigned short xattr_isize; @@ -310,31 +310,30 @@ struct erofs_vnode { #define EROFS_V(ptr) \ container_of(ptr, struct erofs_vnode, vfs_inode) -#define __inode_advise(x, bit, bits) \ - (((x) >> (bit)) & ((1 << (bits)) - 1)) - -#define __inode_version(advise) \ - __inode_advise(advise, EROFS_I_VERSION_BIT, \ - EROFS_I_VERSION_BITS) - -#define __inode_data_mapping(advise) \ - __inode_advise(advise, EROFS_I_DATA_MAPPING_BIT,\ - EROFS_I_DATA_MAPPING_BITS) - static inline unsigned long inode_datablocks(struct inode *inode) { /* since i_size cannot be changed */ return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); } -static inline bool is_inode_layout_compression(struct inode *inode) +static inline unsigned int erofs_bitrange(unsigned int value, unsigned int bit, + unsigned int bits) +{ + + return (value >> bit) & ((1 << bits) - 1); +} + + +static inline unsigned int erofs_inode_version(unsigned int value) { - return erofs_inode_is_data_compressed(EROFS_V(inode)->datamode); + return erofs_bitrange(value, EROFS_I_VERSION_BIT, + EROFS_I_VERSION_BITS); } -static inline bool is_inode_flat_inline(struct inode *inode) +static inline unsigned int erofs_inode_datalayout(unsigned int value) { - return EROFS_V(inode)->datamode == EROFS_INODE_FLAT_INLINE; + return erofs_bitrange(value, EROFS_I_DATALAYOUT_BIT, + EROFS_I_DATALAYOUT_BITS); } extern const struct super_operations erofs_sops; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 6a7ab194783c..8d9f38d56b3b 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -121,7 +121,7 @@ static int superblock_read(struct super_block *sb) #ifdef CONFIG_EROFS_FS_XATTR sbi->xattr_blkaddr = le32_to_cpu(layout->xattr_blkaddr); #endif - sbi->islotbits = ffs(sizeof(struct erofs_inode_v1)) - 1; + sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact)); sbi->root_nid = le16_to_cpu(layout->root_nid); sbi->inos = le64_to_cpu(layout->inos); diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 850e0e3d57a8..6a06fb80ef3f 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -12,7 +12,7 @@ int z_erofs_fill_inode(struct inode *inode) { struct erofs_vnode *const vi = EROFS_V(inode); - if (vi->datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY) { + if (vi->datalayout == EROFS_INODE_FLAT_COMPRESSION_LEGACY) { vi->z_advise = 0; vi->z_algorithmtype[0] = 0; vi->z_algorithmtype[1] = 0; @@ -46,7 +46,7 @@ static int fill_inode_lazy(struct inode *inode) if (test_bit(EROFS_V_Z_INITED_BIT, &vi->flags)) goto out_unlock; - DBG_BUGON(vi->datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY); + DBG_BUGON(vi->datalayout == EROFS_INODE_FLAT_COMPRESSION_LEGACY); pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize + vi->xattr_isize, 8); @@ -314,7 +314,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m, static int vle_load_cluster_from_disk(struct z_erofs_maprecorder *m, unsigned int lcn) { - const unsigned int datamode = EROFS_V(m->inode)->datamode; + const unsigned int datamode = EROFS_V(m->inode)->datalayout; if (datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY) return vle_legacy_load_cluster_from_disk(m, lcn); From patchwork Wed Sep 4 02:08:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FA601399 for ; Wed, 4 Sep 2019 02:10:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A4BB23402 for ; Wed, 4 Sep 2019 02:10:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727857AbfIDCKW (ORCPT ); Tue, 3 Sep 2019 22:10:22 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:59686 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727787AbfIDCKW (ORCPT ); Tue, 3 Sep 2019 22:10:22 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9480DE587523B9E9D287; Wed, 4 Sep 2019 10:10:20 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:13 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 08/25] erofs: kill erofs_{init,exit}_inode_cache Date: Wed, 4 Sep 2019 10:08:55 +0800 Message-ID: <20190904020912.63925-9-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said [1] "having this function seems entirely pointless", let's kill those. filesystem function name ext2,f2fs,ext4,isofs,squashfs,cifs,... init_inodecache In addition, add a necessary "rcu_barrier()" on exit_fs(); [1] https://lore.kernel.org/r/20190829101545.GC20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/super.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 8d9f38d56b3b..499dc7f5d0e6 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -23,21 +23,6 @@ static void init_once(void *ptr) inode_init_once(&vi->vfs_inode); } -static int __init erofs_init_inode_cache(void) -{ - erofs_inode_cachep = kmem_cache_create("erofs_inode", - sizeof(struct erofs_vnode), 0, - SLAB_RECLAIM_ACCOUNT, - init_once); - - return erofs_inode_cachep ? 0 : -ENOMEM; -} - -static void erofs_exit_inode_cache(void) -{ - kmem_cache_destroy(erofs_inode_cachep); -} - static struct inode *alloc_inode(struct super_block *sb) { struct erofs_vnode *vi = @@ -531,9 +516,14 @@ static int __init erofs_module_init(void) erofs_check_ondisk_layout_definitions(); infoln("initializing erofs " EROFS_VERSION); - err = erofs_init_inode_cache(); - if (err) + erofs_inode_cachep = kmem_cache_create("erofs_inode", + sizeof(struct erofs_vnode), 0, + SLAB_RECLAIM_ACCOUNT, + init_once); + if (!erofs_inode_cachep) { + err = -ENOMEM; goto icache_err; + } err = erofs_init_shrinker(); if (err) @@ -555,7 +545,7 @@ static int __init erofs_module_init(void) zip_err: erofs_exit_shrinker(); shrinker_err: - erofs_exit_inode_cache(); + kmem_cache_destroy(erofs_inode_cachep); icache_err: return err; } @@ -565,7 +555,10 @@ static void __exit erofs_module_exit(void) unregister_filesystem(&erofs_fs_type); z_erofs_exit_zip_subsystem(); erofs_exit_shrinker(); - erofs_exit_inode_cache(); + + /* Ensure all RCU free inodes are safe before cache is destroyed. */ + rcu_barrier(); + kmem_cache_destroy(erofs_inode_cachep); infoln("successfully finalize erofs"); } From patchwork Wed Sep 4 02:08:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129147 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78B491399 for ; Wed, 4 Sep 2019 02:10:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4FD242339D for ; Wed, 4 Sep 2019 02:10:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbfIDCK2 (ORCPT ); Tue, 3 Sep 2019 22:10:28 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:59892 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727891AbfIDCK1 (ORCPT ); Tue, 3 Sep 2019 22:10:27 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 78FD46BE553995AD2095; Wed, 4 Sep 2019 10:10:25 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:14 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 09/25] erofs: use erofs_inode naming Date: Wed, 4 Sep 2019 10:08:56 +0800 Message-ID: <20190904020912.63925-10-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph suggested [1], "Why is this called vnode instead of inode? That seems like a rather odd naming for a Linux file system." [1] https://lore.kernel.org/r/20190829101545.GC20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/data.c | 8 ++++---- fs/erofs/dir.c | 6 +++--- fs/erofs/inode.c | 12 ++++++------ fs/erofs/internal.h | 14 +++++++------- fs/erofs/namei.c | 2 +- fs/erofs/super.c | 10 +++++----- fs/erofs/xattr.c | 18 +++++++++--------- fs/erofs/xattr.h | 4 ++-- fs/erofs/zdata.c | 9 +++------ fs/erofs/zmap.c | 28 ++++++++++++++-------------- include/trace/events/erofs.h | 14 +++++++------- 11 files changed, 61 insertions(+), 64 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 4d9b07991d07..be11b5ea9d2e 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -112,7 +112,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode, int err = 0; erofs_blk_t nblocks, lastblk; u64 offset = map->m_la; - struct erofs_vnode *vi = EROFS_V(inode); + struct erofs_inode *vi = EROFS_I(inode); bool tailendpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE); trace_erofs_map_blocks_flatmode_enter(inode, map, flags); @@ -170,7 +170,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode, int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map, int flags) { - if (erofs_inode_is_data_compressed(EROFS_V(inode)->datalayout)) { + if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) { int err = z_erofs_map_blocks_iter(inode, map, flags); if (map->mpage) { @@ -365,7 +365,7 @@ static int erofs_raw_access_readpages(struct file *filp, if (IS_ERR(bio)) { pr_err("%s, readahead error at page %lu of nid %llu\n", __func__, page->index, - EROFS_V(mapping->host)->nid); + EROFS_I(mapping->host)->nid); bio = NULL; } @@ -404,7 +404,7 @@ static sector_t erofs_bmap(struct address_space *mapping, sector_t block) { struct inode *inode = mapping->host; - if (EROFS_V(inode)->datalayout == EROFS_INODE_FLAT_INLINE) { + if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) { erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE; if (block >> LOG_SECTORS_PER_BLOCK >= blks) diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c index 6a5b43f7fb29..a032c8217071 100644 --- a/fs/erofs/dir.c +++ b/fs/erofs/dir.c @@ -47,7 +47,7 @@ static int erofs_fill_dentries(struct inode *dir, struct dir_context *ctx, /* a corrupted entry is found */ if (nameoff + de_namelen > maxsize || de_namelen > EROFS_NAME_LEN) { - errln("bogus dirent @ nid %llu", EROFS_V(dir)->nid); + errln("bogus dirent @ nid %llu", EROFS_I(dir)->nid); DBG_BUGON(1); return -EFSCORRUPTED; } @@ -85,7 +85,7 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) break; } else if (IS_ERR(dentry_page)) { errln("fail to readdir of logical block %u of nid %llu", - i, EROFS_V(dir)->nid); + i, EROFS_I(dir)->nid); err = -EFSCORRUPTED; break; } @@ -97,7 +97,7 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) if (nameoff < sizeof(struct erofs_dirent) || nameoff >= PAGE_SIZE) { errln("%s, invalid de[0].nameoff %u @ nid %llu", - __func__, nameoff, EROFS_V(dir)->nid); + __func__, nameoff, EROFS_I(dir)->nid); err = -EFSCORRUPTED; goto skip_this; } diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 494b35e5830a..f6dfd0271261 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -11,7 +11,7 @@ /* no locking */ static int read_inode(struct inode *inode, void *data) { - struct erofs_vnode *vi = EROFS_V(inode); + struct erofs_inode *vi = EROFS_I(inode); struct erofs_inode_compact *dic = data; struct erofs_inode_extended *die; @@ -140,7 +140,7 @@ static int read_inode(struct inode *inode, void *data) static int fill_inline_data(struct inode *inode, void *data, unsigned int m_pofs) { - struct erofs_vnode *vi = EROFS_V(inode); + struct erofs_inode *vi = EROFS_I(inode); struct erofs_sb_info *sbi = EROFS_I_SB(inode); /* should be tail-packing data inline */ @@ -178,7 +178,7 @@ static int fill_inline_data(struct inode *inode, void *data, static int fill_inode(struct inode *inode, int isdir) { struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); - struct erofs_vnode *vi = EROFS_V(inode); + struct erofs_inode *vi = EROFS_I(inode); struct page *page; void *data; int err; @@ -260,7 +260,7 @@ static int erofs_ilookup_test_actor(struct inode *inode, void *opaque) { const erofs_nid_t nid = *(erofs_nid_t *)opaque; - return EROFS_V(inode)->nid == nid; + return EROFS_I(inode)->nid == nid; } static int erofs_iget_set_actor(struct inode *inode, void *opaque) @@ -297,7 +297,7 @@ struct inode *erofs_iget(struct super_block *sb, if (inode->i_state & I_NEW) { int err; - struct erofs_vnode *vi = EROFS_V(inode); + struct erofs_inode *vi = EROFS_I(inode); vi->nid = nid; @@ -317,7 +317,7 @@ int erofs_getattr(const struct path *path, struct kstat *stat, { struct inode *const inode = d_inode(path->dentry); - if (erofs_inode_is_data_compressed(EROFS_V(inode)->datalayout)) + if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) stat->attributes |= STATX_ATTR_COMPRESSED; stat->attributes |= STATX_ATTR_IMMUTABLE; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 0f5cbf0a7570..10497ee07cae 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -272,14 +272,14 @@ static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid) } /* atomic flag definitions */ -#define EROFS_V_EA_INITED_BIT 0 -#define EROFS_V_Z_INITED_BIT 1 +#define EROFS_I_EA_INITED_BIT 0 +#define EROFS_I_Z_INITED_BIT 1 /* bitlock definitions (arranged in reverse order) */ -#define EROFS_V_BL_XATTR_BIT (BITS_PER_LONG - 1) -#define EROFS_V_BL_Z_BIT (BITS_PER_LONG - 2) +#define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1) +#define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2) -struct erofs_vnode { +struct erofs_inode { erofs_nid_t nid; /* atomic flags (including bitlocks) */ @@ -307,8 +307,8 @@ struct erofs_vnode { struct inode vfs_inode; }; -#define EROFS_V(ptr) \ - container_of(ptr, struct erofs_vnode, vfs_inode) +#define EROFS_I(ptr) \ + container_of(ptr, struct erofs_inode, vfs_inode) static inline unsigned long inode_datablocks(struct inode *inode) { diff --git a/fs/erofs/namei.c b/fs/erofs/namei.c index c1068ad0535e..a6b6a4ab1403 100644 --- a/fs/erofs/namei.c +++ b/fs/erofs/namei.c @@ -117,7 +117,7 @@ static struct page *find_target_block_classic(struct inode *dir, kunmap_atomic(de); put_page(page); errln("corrupted dir block %d @ nid %llu", - mid, EROFS_V(dir)->nid); + mid, EROFS_I(dir)->nid); DBG_BUGON(1); page = ERR_PTR(-EFSCORRUPTED); goto out; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 499dc7f5d0e6..3986be582dbb 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -18,27 +18,27 @@ static struct kmem_cache *erofs_inode_cachep __read_mostly; static void init_once(void *ptr) { - struct erofs_vnode *vi = ptr; + struct erofs_inode *vi = ptr; inode_init_once(&vi->vfs_inode); } static struct inode *alloc_inode(struct super_block *sb) { - struct erofs_vnode *vi = + struct erofs_inode *vi = kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL); if (!vi) return NULL; /* zero out everything except vfs_inode */ - memset(vi, 0, offsetof(struct erofs_vnode, vfs_inode)); + memset(vi, 0, offsetof(struct erofs_inode, vfs_inode)); return &vi->vfs_inode; } static void free_inode(struct inode *inode) { - struct erofs_vnode *vi = EROFS_V(inode); + struct erofs_inode *vi = EROFS_I(inode); /* be careful RCU symlink path (see ext4_inode_info->i_data)! */ if (is_inode_fast_symlink(inode)) @@ -517,7 +517,7 @@ static int __init erofs_module_init(void) infoln("initializing erofs " EROFS_VERSION); erofs_inode_cachep = kmem_cache_create("erofs_inode", - sizeof(struct erofs_vnode), 0, + sizeof(struct erofs_inode), 0, SLAB_RECLAIM_ACCOUNT, init_once); if (!erofs_inode_cachep) { diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 620cbc15f4d0..d5b7fe0bee45 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -38,7 +38,7 @@ static inline void xattr_iter_end_final(struct xattr_iter *it) static int init_inode_xattrs(struct inode *inode) { - struct erofs_vnode *const vi = EROFS_V(inode); + struct erofs_inode *const vi = EROFS_I(inode); struct xattr_iter it; unsigned int i; struct erofs_xattr_ibody_header *ih; @@ -48,14 +48,14 @@ static int init_inode_xattrs(struct inode *inode) int ret = 0; /* the most case is that xattrs of this inode are initialized. */ - if (test_bit(EROFS_V_EA_INITED_BIT, &vi->flags)) + if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags)) return 0; - if (wait_on_bit_lock(&vi->flags, EROFS_V_BL_XATTR_BIT, TASK_KILLABLE)) + if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_XATTR_BIT, TASK_KILLABLE)) return -ERESTARTSYS; /* someone has initialized xattrs for us? */ - if (test_bit(EROFS_V_EA_INITED_BIT, &vi->flags)) + if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags)) goto out_unlock; /* @@ -136,10 +136,10 @@ static int init_inode_xattrs(struct inode *inode) } xattr_iter_end(&it, atomic_map); - set_bit(EROFS_V_EA_INITED_BIT, &vi->flags); + set_bit(EROFS_I_EA_INITED_BIT, &vi->flags); out_unlock: - clear_and_wake_up_bit(EROFS_V_BL_XATTR_BIT, &vi->flags); + clear_and_wake_up_bit(EROFS_I_BL_XATTR_BIT, &vi->flags); return ret; } @@ -184,7 +184,7 @@ static inline int xattr_iter_fixup(struct xattr_iter *it) static int inline_xattr_iter_begin(struct xattr_iter *it, struct inode *inode) { - struct erofs_vnode *const vi = EROFS_V(inode); + struct erofs_inode *const vi = EROFS_I(inode); struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb); unsigned int xattr_header_sz, inline_xattr_ofs; @@ -385,7 +385,7 @@ static int inline_getxattr(struct inode *inode, struct getxattr_iter *it) static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) { - struct erofs_vnode *const vi = EROFS_V(inode); + struct erofs_inode *const vi = EROFS_I(inode); struct super_block *const sb = inode->i_sb; struct erofs_sb_info *const sbi = EROFS_SB(sb); unsigned int i; @@ -608,7 +608,7 @@ static int inline_listxattr(struct listxattr_iter *it) static int shared_listxattr(struct listxattr_iter *it) { struct inode *const inode = d_inode(it->dentry); - struct erofs_vnode *const vi = EROFS_V(inode); + struct erofs_inode *const vi = EROFS_I(inode); struct super_block *const sb = inode->i_sb; struct erofs_sb_info *const sbi = EROFS_SB(sb); unsigned int i; diff --git a/fs/erofs/xattr.h b/fs/erofs/xattr.h index c5ca47d814dd..3585b84d2f20 100644 --- a/fs/erofs/xattr.h +++ b/fs/erofs/xattr.h @@ -16,8 +16,8 @@ static inline unsigned int inlinexattr_header_size(struct inode *inode) { - return sizeof(struct erofs_xattr_ibody_header) - + sizeof(u32) * EROFS_V(inode)->xattr_shared_count; + return sizeof(struct erofs_xattr_ibody_header) + + sizeof(u32) * EROFS_I(inode)->xattr_shared_count; } static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi, diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 653bde0a619a..f06a2fad7af2 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -421,7 +421,7 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, else pcl->algorithmformat = Z_EROFS_COMPRESSION_SHIFTED; - pcl->clusterbits = EROFS_V(inode)->z_physical_clusterbits[0]; + pcl->clusterbits = EROFS_I(inode)->z_physical_clusterbits[0]; pcl->clusterbits -= PAGE_SHIFT; /* new pclusters should be claimed as type 1, primary and followed */ @@ -1404,12 +1404,9 @@ static int z_erofs_vle_normalaccess_readpages(struct file *filp, head = (void *)page_private(page); err = z_erofs_do_read_page(&f, page, &pagepool); - if (err) { - struct erofs_vnode *vi = EROFS_V(inode); - + if (err) errln("%s, readahead error at page %lu of nid %llu", - __func__, page->index, vi->nid); - } + __func__, page->index, EROFS_I(inode)->nid); put_page(page); } diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 6a06fb80ef3f..30a5171637d7 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -10,7 +10,7 @@ int z_erofs_fill_inode(struct inode *inode) { - struct erofs_vnode *const vi = EROFS_V(inode); + struct erofs_inode *const vi = EROFS_I(inode); if (vi->datalayout == EROFS_INODE_FLAT_COMPRESSION_LEGACY) { vi->z_advise = 0; @@ -19,7 +19,7 @@ int z_erofs_fill_inode(struct inode *inode) vi->z_logical_clusterbits = LOG_BLOCK_SIZE; vi->z_physical_clusterbits[0] = vi->z_logical_clusterbits; vi->z_physical_clusterbits[1] = vi->z_logical_clusterbits; - set_bit(EROFS_V_Z_INITED_BIT, &vi->flags); + set_bit(EROFS_I_Z_INITED_BIT, &vi->flags); } inode->i_mapping->a_ops = &z_erofs_vle_normalaccess_aops; @@ -28,7 +28,7 @@ int z_erofs_fill_inode(struct inode *inode) static int fill_inode_lazy(struct inode *inode) { - struct erofs_vnode *const vi = EROFS_V(inode); + struct erofs_inode *const vi = EROFS_I(inode); struct super_block *const sb = inode->i_sb; int err; erofs_off_t pos; @@ -36,14 +36,14 @@ static int fill_inode_lazy(struct inode *inode) void *kaddr; struct z_erofs_map_header *h; - if (test_bit(EROFS_V_Z_INITED_BIT, &vi->flags)) + if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags)) return 0; - if (wait_on_bit_lock(&vi->flags, EROFS_V_BL_Z_BIT, TASK_KILLABLE)) + if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_Z_BIT, TASK_KILLABLE)) return -ERESTARTSYS; err = 0; - if (test_bit(EROFS_V_Z_INITED_BIT, &vi->flags)) + if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags)) goto out_unlock; DBG_BUGON(vi->datalayout == EROFS_INODE_FLAT_COMPRESSION_LEGACY); @@ -83,13 +83,13 @@ static int fill_inode_lazy(struct inode *inode) vi->z_physical_clusterbits[1] = vi->z_logical_clusterbits + ((h->h_clusterbits >> 5) & 7); - set_bit(EROFS_V_Z_INITED_BIT, &vi->flags); + set_bit(EROFS_I_Z_INITED_BIT, &vi->flags); unmap_done: kunmap_atomic(kaddr); unlock_page(page); put_page(page); out_unlock: - clear_and_wake_up_bit(EROFS_V_BL_Z_BIT, &vi->flags); + clear_and_wake_up_bit(EROFS_I_BL_Z_BIT, &vi->flags); return err; } @@ -142,7 +142,7 @@ static int vle_legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m, unsigned long lcn) { struct inode *const inode = m->inode; - struct erofs_vnode *const vi = EROFS_V(inode); + struct erofs_inode *const vi = EROFS_I(inode); const erofs_off_t ibase = iloc(EROFS_I_SB(inode), vi->nid); const erofs_off_t pos = Z_EROFS_VLE_LEGACY_INDEX_ALIGN(ibase + vi->inode_isize + @@ -196,7 +196,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m, unsigned int amortizedshift, unsigned int eofs) { - struct erofs_vnode *const vi = EROFS_V(m->inode); + struct erofs_inode *const vi = EROFS_I(m->inode); const unsigned int lclusterbits = vi->z_logical_clusterbits; const unsigned int lomask = (1 << lclusterbits) - 1; unsigned int vcnt, base, lo, encodebits, nblk; @@ -260,7 +260,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m, unsigned long lcn) { struct inode *const inode = m->inode; - struct erofs_vnode *const vi = EROFS_V(inode); + struct erofs_inode *const vi = EROFS_I(inode); const unsigned int lclusterbits = vi->z_logical_clusterbits; const erofs_off_t ebase = ALIGN(iloc(EROFS_I_SB(inode), vi->nid) + vi->inode_isize + vi->xattr_isize, 8) + @@ -314,7 +314,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m, static int vle_load_cluster_from_disk(struct z_erofs_maprecorder *m, unsigned int lcn) { - const unsigned int datamode = EROFS_V(m->inode)->datalayout; + const unsigned int datamode = EROFS_I(m->inode)->datalayout; if (datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY) return vle_legacy_load_cluster_from_disk(m, lcn); @@ -328,7 +328,7 @@ static int vle_load_cluster_from_disk(struct z_erofs_maprecorder *m, static int vle_extent_lookback(struct z_erofs_maprecorder *m, unsigned int lookback_distance) { - struct erofs_vnode *const vi = EROFS_V(m->inode); + struct erofs_inode *const vi = EROFS_I(m->inode); struct erofs_map_blocks *const map = m->map; const unsigned int lclusterbits = vi->z_logical_clusterbits; unsigned long lcn = m->lcn; @@ -374,7 +374,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map, int flags) { - struct erofs_vnode *const vi = EROFS_V(inode); + struct erofs_inode *const vi = EROFS_I(inode); struct z_erofs_maprecorder m = { .inode = inode, .map = map, diff --git a/include/trace/events/erofs.h b/include/trace/events/erofs.h index d239f39cbc8c..27f5caa6299a 100644 --- a/include/trace/events/erofs.h +++ b/include/trace/events/erofs.h @@ -41,7 +41,7 @@ TRACE_EVENT(erofs_lookup, TP_fast_assign( __entry->dev = dir->i_sb->s_dev; - __entry->nid = EROFS_V(dir)->nid; + __entry->nid = EROFS_I(dir)->nid; __entry->name = dentry->d_name.name; __entry->flags = flags; ), @@ -66,7 +66,7 @@ TRACE_EVENT(erofs_fill_inode, TP_fast_assign( __entry->dev = inode->i_sb->s_dev; - __entry->nid = EROFS_V(inode)->nid; + __entry->nid = EROFS_I(inode)->nid; __entry->blkaddr = erofs_blknr(iloc(EROFS_I_SB(inode), __entry->nid)); __entry->ofs = erofs_blkoff(iloc(EROFS_I_SB(inode), __entry->nid)); __entry->isdir = isdir; @@ -95,7 +95,7 @@ TRACE_EVENT(erofs_readpage, TP_fast_assign( __entry->dev = page->mapping->host->i_sb->s_dev; - __entry->nid = EROFS_V(page->mapping->host)->nid; + __entry->nid = EROFS_I(page->mapping->host)->nid; __entry->dir = S_ISDIR(page->mapping->host->i_mode); __entry->index = page->index; __entry->uptodate = PageUptodate(page); @@ -128,7 +128,7 @@ TRACE_EVENT(erofs_readpages, TP_fast_assign( __entry->dev = inode->i_sb->s_dev; - __entry->nid = EROFS_V(inode)->nid; + __entry->nid = EROFS_I(inode)->nid; __entry->start = page->index; __entry->nrpage = nrpage; __entry->raw = raw; @@ -157,7 +157,7 @@ DECLARE_EVENT_CLASS(erofs__map_blocks_enter, TP_fast_assign( __entry->dev = inode->i_sb->s_dev; - __entry->nid = EROFS_V(inode)->nid; + __entry->nid = EROFS_I(inode)->nid; __entry->la = map->m_la; __entry->llen = map->m_llen; __entry->flags = flags; @@ -203,7 +203,7 @@ DECLARE_EVENT_CLASS(erofs__map_blocks_exit, TP_fast_assign( __entry->dev = inode->i_sb->s_dev; - __entry->nid = EROFS_V(inode)->nid; + __entry->nid = EROFS_I(inode)->nid; __entry->flags = flags; __entry->la = map->m_la; __entry->pa = map->m_pa; @@ -247,7 +247,7 @@ TRACE_EVENT(erofs_destroy_inode, TP_fast_assign( __entry->dev = inode->i_sb->s_dev; - __entry->nid = EROFS_V(inode)->nid; + __entry->nid = EROFS_I(inode)->nid; ), TP_printk("dev = (%d,%d), nid = %llu", show_dev_nid(__entry)) From patchwork Wed Sep 4 02:08:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129141 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FE401813 for ; Wed, 4 Sep 2019 02:10:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B366233A1 for ; Wed, 4 Sep 2019 02:10:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727940AbfIDCK1 (ORCPT ); Tue, 3 Sep 2019 22:10:27 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:59850 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727884AbfIDCK0 (ORCPT ); Tue, 3 Sep 2019 22:10:26 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 745837A240A9C64E728E; Wed, 4 Sep 2019 10:10:25 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:15 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 10/25] erofs: update erofs_fs.h comments Date: Wed, 4 Sep 2019 10:08:57 +0800 Message-ID: <20190904020912.63925-11-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said [1] [2], update it now. [1] https://lore.kernel.org/r/20190902124521.GA22153@infradead.org/ [2] https://lore.kernel.org/r/20190902120548.GB15931@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/erofs_fs.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index 18689e916e94..b1ee5654750d 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */ /* + * EROFS (Enhanced ROM File System) on-disk format definition + * * Copyright (C) 2017-2018 HUAWEI, Inc. * http://www.huawei.com/ * Created by Gao Xiang @@ -7,7 +9,6 @@ #ifndef __EROFS_FS_H #define __EROFS_FS_H -/* Enhanced(Extended) ROM File System */ #define EROFS_SUPER_OFFSET 1024 /* @@ -41,7 +42,7 @@ struct erofs_super_block { }; /* - * erofs inode datalayout: + * erofs inode datalayout (i_format in on-disk inode): * 0 - inode plain without inline data A: * inode, [xattrs], ... | ... | no-holed data * 1 - inode VLE compression B (legacy): @@ -187,7 +188,7 @@ static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e) e->e_name_len + le16_to_cpu(e->e_value_size)); } -/* available compression algorithm types */ +/* available compression algorithm types (for h_algorithmtype) */ enum { Z_EROFS_COMPRESSION_LZ4 = 0, Z_EROFS_COMPRESSION_MAX @@ -222,7 +223,7 @@ struct z_erofs_map_header { #define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8 /* - * Z_EROFS Variable-sized Logical Extent cluster type: + * Fixed-sized output compression ondisk Logical Extent cluster type: * 0 - literal (uncompressed) cluster * 1 - compressed cluster (for the head logical cluster) * 2 - compressed cluster (for the other logical clusters) From patchwork Wed Sep 4 02:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129139 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 999761399 for ; Wed, 4 Sep 2019 02:10:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7981F23401 for ; Wed, 4 Sep 2019 02:10:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbfIDCK0 (ORCPT ); Tue, 3 Sep 2019 22:10:26 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:59800 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727722AbfIDCK0 (ORCPT ); Tue, 3 Sep 2019 22:10:26 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6F718D93F59080B35CF4; Wed, 4 Sep 2019 10:10:25 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:16 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 11/25] erofs: update comments in inode.c Date: Wed, 4 Sep 2019 10:08:58 +0800 Message-ID: <20190904020912.63925-12-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph suggested [1], update them all. [1] https://lore.kernel.org/r/20190829102426.GE20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/inode.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index f6dfd0271261..a42f5fc14df9 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -147,7 +147,7 @@ static int fill_inline_data(struct inode *inode, void *data, if (vi->datalayout != EROFS_INODE_FLAT_INLINE) return 0; - /* fast symlink (following ext4) */ + /* fast symlink */ if (S_ISLNK(inode->i_mode) && inode->i_size < PAGE_SIZE) { char *lnk = erofs_kmalloc(sbi, inode->i_size + 1, GFP_KERNEL); @@ -156,7 +156,7 @@ static int fill_inline_data(struct inode *inode, void *data, m_pofs += vi->inode_isize + vi->xattr_isize; - /* inline symlink data shouldn't across page boundary as well */ + /* inline symlink data shouldn't cross page boundary as well */ if (m_pofs + inode->i_size > PAGE_SIZE) { kfree(lnk); errln("inline data cross block boundary @ nid %llu", @@ -165,7 +165,6 @@ static int fill_inline_data(struct inode *inode, void *data, return -EFSCORRUPTED; } - /* get in-page inline data */ memcpy(lnk, data + m_pofs, inode->i_size); lnk[inode->i_size] = '\0'; From patchwork Wed Sep 4 02:08:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129143 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E10017EF for ; Wed, 4 Sep 2019 02:10:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 888742339D for ; Wed, 4 Sep 2019 02:10:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727946AbfIDCK1 (ORCPT ); Tue, 3 Sep 2019 22:10:27 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:59898 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727903AbfIDCK0 (ORCPT ); Tue, 3 Sep 2019 22:10:26 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8478ED1D934AB763232E; Wed, 4 Sep 2019 10:10:25 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:18 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 12/25] erofs: better erofs symlink stuffs Date: Wed, 4 Sep 2019 10:08:59 +0800 Message-ID: <20190904020912.63925-13-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Fix as Christoph suggested [1] [2], "remove is_inode_fast_symlink and just opencode it in the few places using it" and "Please just set the ops directly instead of obsfucating that in a single caller, single line inline function. And please set it instead of the normal symlink iops in the same place where you also set those." [1] https://lore.kernel.org/r/20190830163910.GB29603@infradead.org/ [2] https://lore.kernel.org/r/20190829102426.GE20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/inode.c | 68 ++++++++++++++++++--------------------------- fs/erofs/internal.h | 10 ------- fs/erofs/super.c | 5 ++-- 3 files changed, 29 insertions(+), 54 deletions(-) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index a42f5fc14df9..770f3259c862 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -127,50 +127,39 @@ static int read_inode(struct inode *inode, void *data) return -EFSCORRUPTED; } -/* - * try_lock can be required since locking order is: - * file data(fs_inode) - * meta(bd_inode) - * but the majority of the callers is "iget", - * in that case we are pretty sure no deadlock since - * no data operations exist. However I tend to - * try_lock since it takes no much overhead and - * will success immediately. - */ -static int fill_inline_data(struct inode *inode, void *data, - unsigned int m_pofs) +static int erofs_fill_symlink(struct inode *inode, void *data, + unsigned int m_pofs) { struct erofs_inode *vi = EROFS_I(inode); struct erofs_sb_info *sbi = EROFS_I_SB(inode); + char *lnk; - /* should be tail-packing data inline */ - if (vi->datalayout != EROFS_INODE_FLAT_INLINE) + /* if it cannot be handled with fast symlink scheme */ + if (vi->datalayout != EROFS_INODE_FLAT_INLINE || + inode->i_size >= PAGE_SIZE) { + inode->i_op = &erofs_symlink_iops; return 0; + } - /* fast symlink */ - if (S_ISLNK(inode->i_mode) && inode->i_size < PAGE_SIZE) { - char *lnk = erofs_kmalloc(sbi, inode->i_size + 1, GFP_KERNEL); - - if (!lnk) - return -ENOMEM; - - m_pofs += vi->inode_isize + vi->xattr_isize; + lnk = erofs_kmalloc(sbi, inode->i_size + 1, GFP_KERNEL); + if (!lnk) + return -ENOMEM; - /* inline symlink data shouldn't cross page boundary as well */ - if (m_pofs + inode->i_size > PAGE_SIZE) { - kfree(lnk); - errln("inline data cross block boundary @ nid %llu", - vi->nid); - DBG_BUGON(1); - return -EFSCORRUPTED; - } + m_pofs += vi->inode_isize + vi->xattr_isize; + /* inline symlink data shouldn't cross page boundary as well */ + if (m_pofs + inode->i_size > PAGE_SIZE) { + kfree(lnk); + errln("inline data cross block boundary @ nid %llu", + vi->nid); + DBG_BUGON(1); + return -EFSCORRUPTED; + } - memcpy(lnk, data + m_pofs, inode->i_size); - lnk[inode->i_size] = '\0'; + memcpy(lnk, data + m_pofs, inode->i_size); + lnk[inode->i_size] = '\0'; - inode->i_link = lnk; - set_inode_fast_symlink(inode); - } + inode->i_link = lnk; + inode->i_op = &erofs_fast_symlink_iops; return 0; } @@ -217,8 +206,9 @@ static int fill_inode(struct inode *inode, int isdir) inode->i_fop = &erofs_dir_fops; break; case S_IFLNK: - /* by default, page_get_link is used for symlink */ - inode->i_op = &erofs_symlink_iops; + err = erofs_fill_symlink(inode, data, ofs); + if (err) + goto out_unlock; inode_nohighmem(inode); break; case S_IFCHR: @@ -237,11 +227,7 @@ static int fill_inode(struct inode *inode, int isdir) err = z_erofs_fill_inode(inode); goto out_unlock; } - inode->i_mapping->a_ops = &erofs_raw_access_aops; - - /* fill last page if inline data is available */ - err = fill_inline_data(inode, data, ofs); } out_unlock: diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 10497ee07cae..cc1ea98c5c89 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -479,16 +479,6 @@ extern const struct inode_operations erofs_generic_iops; extern const struct inode_operations erofs_symlink_iops; extern const struct inode_operations erofs_fast_symlink_iops; -static inline void set_inode_fast_symlink(struct inode *inode) -{ - inode->i_op = &erofs_fast_symlink_iops; -} - -static inline bool is_inode_fast_symlink(struct inode *inode) -{ - return inode->i_op == &erofs_fast_symlink_iops; -} - struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir); int erofs_getattr(const struct path *path, struct kstat *stat, u32 request_mask, unsigned int query_flags); diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 3986be582dbb..b8b0e35f6621 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -40,10 +40,9 @@ static void free_inode(struct inode *inode) { struct erofs_inode *vi = EROFS_I(inode); - /* be careful RCU symlink path (see ext4_inode_info->i_data)! */ - if (is_inode_fast_symlink(inode)) + /* be careful of RCU symlink path */ + if (inode->i_op == &erofs_fast_symlink_iops) kfree(inode->i_link); - kfree(vi->xattr_shared_xattrs); kmem_cache_free(erofs_inode_cachep, vi); From patchwork Wed Sep 4 02:09:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129145 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08D821813 for ; Wed, 4 Sep 2019 02:10:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9322233A1 for ; Wed, 4 Sep 2019 02:10:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727938AbfIDCK1 (ORCPT ); Tue, 3 Sep 2019 22:10:27 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:59884 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727899AbfIDCK0 (ORCPT ); Tue, 3 Sep 2019 22:10:26 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7F8A3CC9CCE41AD6FC5E; Wed, 4 Sep 2019 10:10:25 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:19 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 13/25] erofs: use dsb instead of layout for ondisk super_block Date: Wed, 4 Sep 2019 10:09:00 +0800 Message-ID: <20190904020912.63925-14-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph pointed out [1], "Why is the variable name for the on-disk subperblock layout? We usually still calls this something with sb in the name, e.g. dsb. for disksuper block. " Let's fix it. [1] https://lore.kernel.org/r/20190829101545.GC20598@infradead.org/ Signed-off-by: Gao Xiang --- fs/erofs/super.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index b8b0e35f6621..63cb17a4073b 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -49,9 +49,9 @@ static void free_inode(struct inode *inode) } static bool check_layout_compatibility(struct super_block *sb, - struct erofs_super_block *layout) + struct erofs_super_block *dsb) { - const unsigned int feature = le32_to_cpu(layout->feature_incompat); + const unsigned int feature = le32_to_cpu(dsb->feature_incompat); EROFS_SB(sb)->feature_incompat = feature; @@ -68,7 +68,7 @@ static int superblock_read(struct super_block *sb) { struct erofs_sb_info *sbi; struct buffer_head *bh; - struct erofs_super_block *layout; + struct erofs_super_block *dsb; unsigned int blkszbits; int ret; @@ -80,16 +80,15 @@ static int superblock_read(struct super_block *sb) } sbi = EROFS_SB(sb); - layout = (struct erofs_super_block *)((u8 *)bh->b_data - + EROFS_SUPER_OFFSET); + dsb = (struct erofs_super_block *)(bh->b_data + EROFS_SUPER_OFFSET); ret = -EINVAL; - if (le32_to_cpu(layout->magic) != EROFS_SUPER_MAGIC_V1) { + if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) { errln("cannot find valid erofs superblock"); goto out; } - blkszbits = layout->blkszbits; + blkszbits = dsb->blkszbits; /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */ if (blkszbits != LOG_BLOCK_SIZE) { errln("blksize %u isn't supported on this platform", @@ -97,25 +96,25 @@ static int superblock_read(struct super_block *sb) goto out; } - if (!check_layout_compatibility(sb, layout)) + if (!check_layout_compatibility(sb, dsb)) goto out; - sbi->blocks = le32_to_cpu(layout->blocks); - sbi->meta_blkaddr = le32_to_cpu(layout->meta_blkaddr); + sbi->blocks = le32_to_cpu(dsb->blocks); + sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr); #ifdef CONFIG_EROFS_FS_XATTR - sbi->xattr_blkaddr = le32_to_cpu(layout->xattr_blkaddr); + sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr); #endif sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact)); - sbi->root_nid = le16_to_cpu(layout->root_nid); - sbi->inos = le64_to_cpu(layout->inos); + sbi->root_nid = le16_to_cpu(dsb->root_nid); + sbi->inos = le64_to_cpu(dsb->inos); - sbi->build_time = le64_to_cpu(layout->build_time); - sbi->build_time_nsec = le32_to_cpu(layout->build_time_nsec); + sbi->build_time = le64_to_cpu(dsb->build_time); + sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec); - memcpy(&sb->s_uuid, layout->uuid, sizeof(layout->uuid)); + memcpy(&sb->s_uuid, dsb->uuid, sizeof(dsb->uuid)); - ret = strscpy(sbi->volume_name, layout->volume_name, - sizeof(layout->volume_name)); + ret = strscpy(sbi->volume_name, dsb->volume_name, + sizeof(dsb->volume_name)); if (ret < 0) { /* -E2BIG */ errln("bad volume name without NIL terminator"); ret = -EFSCORRUPTED; From patchwork Wed Sep 4 02:09:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129155 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD48D1399 for ; Wed, 4 Sep 2019 02:10:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B763022CF8 for ; Wed, 4 Sep 2019 02:10:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727973AbfIDCKe (ORCPT ); Tue, 3 Sep 2019 22:10:34 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6195 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727949AbfIDCKc (ORCPT ); Tue, 3 Sep 2019 22:10:32 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 831EBCBCC46AB636AD74; Wed, 4 Sep 2019 10:10:30 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:20 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 14/25] erofs: kill verbose debug info in erofs_fill_super Date: Wed, 4 Sep 2019 10:09:01 +0800 Message-ID: <20190904020912.63925-15-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said [1], "That is some very verbose debug info. We usually don't add that and let people trace the function instead. " [1] https://lore.kernel.org/r/20190829101545.GC20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/super.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 63cb17a4073b..b64d69f18270 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -384,9 +384,6 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) struct erofs_sb_info *sbi; int err; - infoln("fill_super, device -> %s", sb->s_id); - infoln("options -> %s", (char *)data); - sb->s_magic = EROFS_SUPER_MAGIC; if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) { @@ -419,9 +416,6 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) if (err) return err; - if (!silent) - infoln("root inode @ nid %llu", ROOT_NID(sbi)); - if (test_opt(sbi, POSIX_ACL)) sb->s_flags |= SB_POSIXACL; else @@ -454,7 +448,8 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) return err; if (!silent) - infoln("mounted on %s with opts: %s.", sb->s_id, (char *)data); + infoln("mounted on %s with opts: %s, root inode @ nid %llu.", + sb->s_id, (char *)data, ROOT_NID(sbi)); return 0; } From patchwork Wed Sep 4 02:09:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129149 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D30F81399 for ; Wed, 4 Sep 2019 02:10:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE61123400 for ; Wed, 4 Sep 2019 02:10:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727959AbfIDCKc (ORCPT ); Tue, 3 Sep 2019 22:10:32 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6194 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727891AbfIDCKb (ORCPT ); Tue, 3 Sep 2019 22:10:31 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8E6641D8DF0B184D0233; Wed, 4 Sep 2019 10:10:30 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:21 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 15/25] erofs: localize erofs_grab_bio() Date: Wed, 4 Sep 2019 10:09:02 +0800 Message-ID: <20190904020912.63925-16-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph pointed out [1], "erofs_grab_bio tries to handle a bio_alloc failure, except that the function will not actually fail due the mempool backing it." Sorry about useless code, fix it now and localize erofs_grab_bio [2]. [1] https://lore.kernel.org/r/20190830162812.GA10694@infradead.org/ [2] https://lore.kernel.org/r/20190902122016.GL15931@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/data.c | 28 +++++++++++++++------------- fs/erofs/internal.h | 29 ----------------------------- fs/erofs/zdata.c | 10 +++++++--- 3 files changed, 22 insertions(+), 45 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index be11b5ea9d2e..0136ea117934 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -38,6 +38,19 @@ static inline void read_endio(struct bio *bio) bio_put(bio); } +static struct bio *erofs_grab_raw_bio(struct super_block *sb, + erofs_blk_t blkaddr, + unsigned int nr_pages) +{ + struct bio *bio = bio_alloc(GFP_NOIO, nr_pages); + + bio->bi_end_io = read_endio; + bio_set_dev(bio, sb->s_bdev); + bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK; + bio->bi_private = sb; + return bio; +} + /* prio -- true is used for dir */ struct page *__erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr, bool prio, bool nofail) @@ -62,12 +75,7 @@ struct page *__erofs_get_meta_page(struct super_block *sb, if (!PageUptodate(page)) { struct bio *bio; - bio = erofs_grab_bio(sb, blkaddr, 1, sb, read_endio, nofail); - if (IS_ERR(bio)) { - DBG_BUGON(nofail); - err = PTR_ERR(bio); - goto err_out; - } + bio = erofs_grab_raw_bio(sb, blkaddr, 1); if (bio_add_page(bio, page, PAGE_SIZE, 0) != PAGE_SIZE) { err = -EFAULT; @@ -276,13 +284,7 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, if (nblocks > BIO_MAX_PAGES) nblocks = BIO_MAX_PAGES; - bio = erofs_grab_bio(sb, blknr, nblocks, sb, - read_endio, false); - if (IS_ERR(bio)) { - err = PTR_ERR(bio); - bio = NULL; - goto err_out; - } + bio = erofs_grab_raw_bio(sb, blknr, nblocks); } err = bio_add_page(bio, page, PAGE_SIZE, 0); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index cc1ea98c5c89..000ea92b36a3 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -411,35 +411,6 @@ static inline int z_erofs_map_blocks_iter(struct inode *inode, #endif /* !CONFIG_EROFS_FS_ZIP */ /* data.c */ -static inline struct bio *erofs_grab_bio(struct super_block *sb, - erofs_blk_t blkaddr, - unsigned int nr_pages, - void *bi_private, bio_end_io_t endio, - bool nofail) -{ - const gfp_t gfp = GFP_NOIO; - struct bio *bio; - - do { - if (nr_pages == 1) { - bio = bio_alloc(gfp | (nofail ? __GFP_NOFAIL : 0), 1); - if (!bio) { - DBG_BUGON(nofail); - return ERR_PTR(-ENOMEM); - } - break; - } - bio = bio_alloc(gfp, nr_pages); - nr_pages /= 2; - } while (!bio); - - bio->bi_end_io = endio; - bio_set_dev(bio, sb->s_bdev); - bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK; - bio->bi_private = bi_private; - return bio; -} - static inline void __submit_bio(struct bio *bio, unsigned int op, unsigned int op_flags) { diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index f06a2fad7af2..21ade322cc81 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -1263,9 +1263,13 @@ static bool z_erofs_vle_submit_all(struct super_block *sb, } if (!bio) { - bio = erofs_grab_bio(sb, first_index + i, - BIO_MAX_PAGES, bi_private, - z_erofs_vle_read_endio, true); + bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES); + + bio->bi_end_io = z_erofs_vle_read_endio; + bio_set_dev(bio, sb->s_bdev); + bio->bi_iter.bi_sector = (sector_t)(first_index + i) << + LOG_SECTORS_PER_BLOCK; + bio->bi_private = bi_private; ++nr_bios; } From patchwork Wed Sep 4 02:09:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129151 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7476C1813 for ; Wed, 4 Sep 2019 02:10:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5679F23400 for ; Wed, 4 Sep 2019 02:10:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727968AbfIDCKc (ORCPT ); Tue, 3 Sep 2019 22:10:32 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6193 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727947AbfIDCKb (ORCPT ); Tue, 3 Sep 2019 22:10:31 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 88A9C8B5EE1071CFCEE2; Wed, 4 Sep 2019 10:10:30 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:22 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 16/25] erofs: kill prio and nofail of erofs_get_meta_page() Date: Wed, 4 Sep 2019 10:09:03 +0800 Message-ID: <20190904020912.63925-17-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph pointed out [1], "Why is there __erofs_get_meta_page with the two weird booleans instead of a single erofs_get_meta_page that gets and gfp_t for additional flags and an unsigned int for additional bio op flags." And since all callers can handle errors, let's kill prio and nofail and erofs_get_inline_page() now. [1] https://lore.kernel.org/r/20190830162812.GA10694@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/data.c | 25 ++++++------------------- fs/erofs/inode.c | 2 +- fs/erofs/internal.h | 18 +----------------- fs/erofs/xattr.c | 13 ++++++------- fs/erofs/zmap.c | 4 ++-- 5 files changed, 16 insertions(+), 46 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 0136ea117934..28eda71bb1a9 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -51,25 +51,19 @@ static struct bio *erofs_grab_raw_bio(struct super_block *sb, return bio; } -/* prio -- true is used for dir */ -struct page *__erofs_get_meta_page(struct super_block *sb, - erofs_blk_t blkaddr, bool prio, bool nofail) +struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr) { struct inode *const bd_inode = sb->s_bdev->bd_inode; struct address_space *const mapping = bd_inode->i_mapping; - /* prefer retrying in the allocator to blindly looping below */ - const gfp_t gfp = mapping_gfp_constraint(mapping, ~__GFP_FS) | - (nofail ? __GFP_NOFAIL : 0); - unsigned int io_retries = nofail ? EROFS_IO_MAX_RETRIES_NOFAIL : 0; + const gfp_t gfp = mapping_gfp_constraint(mapping, ~__GFP_FS); struct page *page; int err; repeat: page = find_or_create_page(mapping, blkaddr, gfp); - if (!page) { - DBG_BUGON(nofail); + if (!page) return ERR_PTR(-ENOMEM); - } + DBG_BUGON(!PageLocked(page)); if (!PageUptodate(page)) { @@ -82,14 +76,11 @@ struct page *__erofs_get_meta_page(struct super_block *sb, goto err_out; } - __submit_bio(bio, REQ_OP_READ, - REQ_META | (prio ? REQ_PRIO : 0)); - + __submit_bio(bio, REQ_OP_READ, REQ_META); lock_page(page); /* this page has been truncated by others */ if (page->mapping != mapping) { -unlock_repeat: unlock_page(page); put_page(page); goto repeat; @@ -97,10 +88,6 @@ struct page *__erofs_get_meta_page(struct super_block *sb, /* more likely a read error */ if (!PageUptodate(page)) { - if (io_retries) { - --io_retries; - goto unlock_repeat; - } err = -EIO; goto err_out; } @@ -251,7 +238,7 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, DBG_BUGON(map.m_plen > PAGE_SIZE); - ipage = erofs_get_meta_page(inode->i_sb, blknr, 0); + ipage = erofs_get_meta_page(inode->i_sb, blknr); if (IS_ERR(ipage)) { err = PTR_ERR(ipage); diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 770f3259c862..8d496adbeaea 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -182,7 +182,7 @@ static int fill_inode(struct inode *inode, int isdir) debugln("%s, reading inode nid %llu at %u of blkaddr %u", __func__, vi->nid, ofs, blkaddr); - page = erofs_get_meta_page(inode->i_sb, blkaddr, isdir); + page = erofs_get_meta_page(inode->i_sb, blkaddr); if (IS_ERR(page)) { errln("failed to get inode (nid: %llu) page, err %ld", diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 000ea92b36a3..90c62fb5f80d 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -258,8 +258,6 @@ static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp) #error erofs cannot be used in this platform #endif -#define EROFS_IO_MAX_RETRIES_NOFAIL 5 - #define ROOT_NID(sb) ((sb)->root_nid) #define erofs_blknr(addr) ((addr) / EROFS_BLKSIZ) @@ -418,24 +416,10 @@ static inline void __submit_bio(struct bio *bio, unsigned int op, submit_bio(bio); } -struct page *__erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr, - bool prio, bool nofail); - -static inline struct page *erofs_get_meta_page(struct super_block *sb, - erofs_blk_t blkaddr, bool prio) -{ - return __erofs_get_meta_page(sb, blkaddr, prio, false); -} +struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr); int erofs_map_blocks(struct inode *, struct erofs_map_blocks *, int); -static inline struct page *erofs_get_inline_page(struct inode *inode, - erofs_blk_t blkaddr) -{ - return erofs_get_meta_page(inode->i_sb, blkaddr, - S_ISDIR(inode->i_mode)); -} - /* inode.c */ static inline unsigned long erofs_inode_hash(erofs_nid_t nid) { diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index d5b7fe0bee45..dd445c81c41f 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -87,7 +87,7 @@ static int init_inode_xattrs(struct inode *inode) it.blkaddr = erofs_blknr(iloc(sbi, vi->nid) + vi->inode_isize); it.ofs = erofs_blkoff(iloc(sbi, vi->nid) + vi->inode_isize); - it.page = erofs_get_inline_page(inode, it.blkaddr); + it.page = erofs_get_meta_page(sb, it.blkaddr); if (IS_ERR(it.page)) { ret = PTR_ERR(it.page); goto out_unlock; @@ -117,8 +117,7 @@ static int init_inode_xattrs(struct inode *inode) DBG_BUGON(it.ofs != EROFS_BLKSIZ); xattr_iter_end(&it, atomic_map); - it.page = erofs_get_meta_page(sb, ++it.blkaddr, - S_ISDIR(inode->i_mode)); + it.page = erofs_get_meta_page(sb, ++it.blkaddr); if (IS_ERR(it.page)) { kfree(vi->xattr_shared_xattrs); vi->xattr_shared_xattrs = NULL; @@ -168,7 +167,7 @@ static inline int xattr_iter_fixup(struct xattr_iter *it) it->blkaddr += erofs_blknr(it->ofs); - it->page = erofs_get_meta_page(it->sb, it->blkaddr, false); + it->page = erofs_get_meta_page(it->sb, it->blkaddr); if (IS_ERR(it->page)) { int err = PTR_ERR(it->page); @@ -199,7 +198,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *it, it->blkaddr = erofs_blknr(iloc(sbi, vi->nid) + inline_xattr_ofs); it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs); - it->page = erofs_get_inline_page(inode, it->blkaddr); + it->page = erofs_get_meta_page(inode->i_sb, it->blkaddr); if (IS_ERR(it->page)) return PTR_ERR(it->page); @@ -401,7 +400,7 @@ static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) if (i) xattr_iter_end(&it->it, true); - it->it.page = erofs_get_meta_page(sb, blkaddr, false); + it->it.page = erofs_get_meta_page(sb, blkaddr); if (IS_ERR(it->it.page)) return PTR_ERR(it->it.page); @@ -623,7 +622,7 @@ static int shared_listxattr(struct listxattr_iter *it) if (i) xattr_iter_end(&it->it, true); - it->it.page = erofs_get_meta_page(sb, blkaddr, false); + it->it.page = erofs_get_meta_page(sb, blkaddr); if (IS_ERR(it->it.page)) return PTR_ERR(it->it.page); diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 30a5171637d7..9c141f145508 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -50,7 +50,7 @@ static int fill_inode_lazy(struct inode *inode) pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize + vi->xattr_isize, 8); - page = erofs_get_meta_page(sb, erofs_blknr(pos), false); + page = erofs_get_meta_page(sb, erofs_blknr(pos)); if (IS_ERR(page)) { err = PTR_ERR(page); goto out_unlock; @@ -127,7 +127,7 @@ static int z_erofs_reload_indexes(struct z_erofs_maprecorder *m, put_page(mpage); } - mpage = erofs_get_meta_page(sb, eblk, false); + mpage = erofs_get_meta_page(sb, eblk); if (IS_ERR(mpage)) { map->mpage = NULL; return PTR_ERR(mpage); From patchwork Wed Sep 4 02:09:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129153 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD9671399 for ; Wed, 4 Sep 2019 02:10:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B81F823400 for ; Wed, 4 Sep 2019 02:10:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727961AbfIDCKc (ORCPT ); Tue, 3 Sep 2019 22:10:32 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6196 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727950AbfIDCKb (ORCPT ); Tue, 3 Sep 2019 22:10:31 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 938614BD2A40AB5CB661; Wed, 4 Sep 2019 10:10:30 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:24 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 17/25] erofs: kill __submit_bio() Date: Wed, 4 Sep 2019 10:09:04 +0800 Message-ID: <20190904020912.63925-18-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph pointed out [1], " Why is there __submit_bio which really just obsfucates what is going on? Also why is __submit_bio using bio_set_op_attrs instead of opencode it as the comment right next to it asks you to? " Let's use submit_bio directly instead. [1] https://lore.kernel.org/r/20190830162812.GA10694@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/data.c | 21 +++++++++++++-------- fs/erofs/internal.h | 7 ------- fs/erofs/zdata.c | 6 ++++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 28eda71bb1a9..70b1e353756e 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -40,7 +40,8 @@ static inline void read_endio(struct bio *bio) static struct bio *erofs_grab_raw_bio(struct super_block *sb, erofs_blk_t blkaddr, - unsigned int nr_pages) + unsigned int nr_pages, + bool ismeta) { struct bio *bio = bio_alloc(GFP_NOIO, nr_pages); @@ -48,6 +49,11 @@ static struct bio *erofs_grab_raw_bio(struct super_block *sb, bio_set_dev(bio, sb->s_bdev); bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK; bio->bi_private = sb; + if (ismeta) + bio->bi_opf = REQ_OP_READ | REQ_META; + else + bio->bi_opf = REQ_OP_READ; + return bio; } @@ -69,14 +75,14 @@ struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr) if (!PageUptodate(page)) { struct bio *bio; - bio = erofs_grab_raw_bio(sb, blkaddr, 1); + bio = erofs_grab_raw_bio(sb, blkaddr, 1, true); if (bio_add_page(bio, page, PAGE_SIZE, 0) != PAGE_SIZE) { err = -EFAULT; goto err_out; } - __submit_bio(bio, REQ_OP_READ, REQ_META); + submit_bio(bio); lock_page(page); /* this page has been truncated by others */ @@ -201,7 +207,7 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, /* not continuous */ *last_block + 1 != current_block) { submit_bio_retry: - __submit_bio(bio, REQ_OP_READ, 0); + submit_bio(bio); bio = NULL; } @@ -271,7 +277,7 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, if (nblocks > BIO_MAX_PAGES) nblocks = BIO_MAX_PAGES; - bio = erofs_grab_raw_bio(sb, blknr, nblocks); + bio = erofs_grab_raw_bio(sb, blknr, nblocks, false); } err = bio_add_page(bio, page, PAGE_SIZE, 0); @@ -302,8 +308,7 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, /* if updated manually, continuous pages has a gap */ if (bio) submit_bio_out: - __submit_bio(bio, REQ_OP_READ, 0); - + submit_bio(bio); return err ? ERR_PTR(err) : NULL; } @@ -367,7 +372,7 @@ static int erofs_raw_access_readpages(struct file *filp, /* the rare case (end in gaps) */ if (bio) - __submit_bio(bio, REQ_OP_READ, 0); + submit_bio(bio); return 0; } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 90c62fb5f80d..13c8d841c43a 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -409,13 +409,6 @@ static inline int z_erofs_map_blocks_iter(struct inode *inode, #endif /* !CONFIG_EROFS_FS_ZIP */ /* data.c */ -static inline void __submit_bio(struct bio *bio, unsigned int op, - unsigned int op_flags) -{ - bio_set_op_attrs(bio, op, op_flags); - submit_bio(bio); -} - struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr); int erofs_map_blocks(struct inode *, struct erofs_map_blocks *, int); diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 21ade322cc81..3010fa3d1ac3 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -1258,7 +1258,7 @@ static bool z_erofs_vle_submit_all(struct super_block *sb, if (bio && force_submit) { submit_bio_retry: - __submit_bio(bio, REQ_OP_READ, 0); + submit_bio(bio); bio = NULL; } @@ -1270,6 +1270,8 @@ static bool z_erofs_vle_submit_all(struct super_block *sb, bio->bi_iter.bi_sector = (sector_t)(first_index + i) << LOG_SECTORS_PER_BLOCK; bio->bi_private = bi_private; + bio->bi_opf = REQ_OP_READ; + ++nr_bios; } @@ -1290,7 +1292,7 @@ static bool z_erofs_vle_submit_all(struct super_block *sb, } while (owned_head != Z_EROFS_PCLUSTER_TAIL); if (bio) - __submit_bio(bio, REQ_OP_READ, 0); + submit_bio(bio); if (postsubmit_is_all_bypassed(q, nr_bios, force_fg)) return true; From patchwork Wed Sep 4 02:09:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129161 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64DD11399 for ; Wed, 4 Sep 2019 02:10:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3ECD323400 for ; Wed, 4 Sep 2019 02:10:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728012AbfIDCKl (ORCPT ); Tue, 3 Sep 2019 22:10:41 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60186 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727949AbfIDCKk (ORCPT ); Tue, 3 Sep 2019 22:10:40 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 0AD1CC69E5F9172E0EE3; Wed, 4 Sep 2019 10:10:39 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:25 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 18/25] erofs: add "erofs_" prefix for common and short functions Date: Wed, 4 Sep 2019 10:09:05 +0800 Message-ID: <20190904020912.63925-19-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add erofs_ prefix to free_inode, alloc_inode, ... Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/data.c | 4 ++-- fs/erofs/decompressor.c | 22 +++++++++++----------- fs/erofs/inode.c | 8 ++++---- fs/erofs/internal.h | 2 +- fs/erofs/namei.c | 12 ++++++------ fs/erofs/super.c | 40 ++++++++++++++++++++-------------------- fs/erofs/zdata.c | 19 ++++++++++--------- 7 files changed, 54 insertions(+), 53 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 70b1e353756e..3ce87a88452a 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -9,7 +9,7 @@ #include -static inline void read_endio(struct bio *bio) +static void erofs_readendio(struct bio *bio) { struct super_block *const sb = bio->bi_private; struct bio_vec *bvec; @@ -45,7 +45,7 @@ static struct bio *erofs_grab_raw_bio(struct super_block *sb, { struct bio *bio = bio_alloc(GFP_NOIO, nr_pages); - bio->bi_end_io = read_endio; + bio->bi_end_io = erofs_readendio; bio_set_dev(bio, sb->s_bdev); bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK; bio->bi_private = sb; diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 555c04730f87..8ed38504a9f1 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -32,8 +32,8 @@ static bool use_vmap; module_param(use_vmap, bool, 0444); MODULE_PARM_DESC(use_vmap, "Use vmap() instead of vm_map_ram() (default 0)"); -static int lz4_prepare_destpages(struct z_erofs_decompress_req *rq, - struct list_head *pagepool) +static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq, + struct list_head *pagepool) { const unsigned int nr = PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; @@ -114,7 +114,7 @@ static void *generic_copy_inplace_data(struct z_erofs_decompress_req *rq, return tmp; } -static int lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out) +static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out) { unsigned int inputmargin, inlen; u8 *src; @@ -188,8 +188,8 @@ static struct z_erofs_decompressor decompressors[] = { .name = "shifted" }, [Z_EROFS_COMPRESSION_LZ4] = { - .prepare_destpages = lz4_prepare_destpages, - .decompress = lz4_decompress, + .prepare_destpages = z_erofs_lz4_prepare_destpages, + .decompress = z_erofs_lz4_decompress, .name = "lz4" }, }; @@ -247,8 +247,8 @@ static void erofs_vunmap(const void *mem, unsigned int count) vunmap(mem); } -static int decompress_generic(struct z_erofs_decompress_req *rq, - struct list_head *pagepool) +static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq, + struct list_head *pagepool) { const unsigned int nrpages_out = PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; @@ -308,8 +308,8 @@ static int decompress_generic(struct z_erofs_decompress_req *rq, return ret; } -static int shifted_decompress(const struct z_erofs_decompress_req *rq, - struct list_head *pagepool) +static int z_erofs_shifted_transform(const struct z_erofs_decompress_req *rq, + struct list_head *pagepool) { const unsigned int nrpages_out = PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; @@ -353,7 +353,7 @@ int z_erofs_decompress(struct z_erofs_decompress_req *rq, struct list_head *pagepool) { if (rq->alg == Z_EROFS_COMPRESSION_SHIFTED) - return shifted_decompress(rq, pagepool); - return decompress_generic(rq, pagepool); + return z_erofs_shifted_transform(rq, pagepool); + return z_erofs_decompress_generic(rq, pagepool); } diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 8d496adbeaea..384905e0677c 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -9,7 +9,7 @@ #include /* no locking */ -static int read_inode(struct inode *inode, void *data) +static int erofs_read_inode(struct inode *inode, void *data) { struct erofs_inode *vi = EROFS_I(inode); struct erofs_inode_compact *dic = data; @@ -163,7 +163,7 @@ static int erofs_fill_symlink(struct inode *inode, void *data, return 0; } -static int fill_inode(struct inode *inode, int isdir) +static int erofs_fill_inode(struct inode *inode, int isdir) { struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); struct erofs_inode *vi = EROFS_I(inode); @@ -193,7 +193,7 @@ static int fill_inode(struct inode *inode, int isdir) DBG_BUGON(!PageUptodate(page)); data = page_address(page); - err = read_inode(inode, data + ofs); + err = erofs_read_inode(inode, data + ofs); if (!err) { /* setup the new inode */ switch (inode->i_mode & S_IFMT) { @@ -286,7 +286,7 @@ struct inode *erofs_iget(struct super_block *sb, vi->nid = nid; - err = fill_inode(inode, isdir); + err = erofs_fill_inode(inode, isdir); if (!err) unlock_new_inode(inode); else { diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 13c8d841c43a..881eb2ee18b5 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -308,7 +308,7 @@ struct erofs_inode { #define EROFS_I(ptr) \ container_of(ptr, struct erofs_inode, vfs_inode) -static inline unsigned long inode_datablocks(struct inode *inode) +static inline unsigned long erofs_inode_datablocks(struct inode *inode) { /* since i_size cannot be changed */ return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); diff --git a/fs/erofs/namei.c b/fs/erofs/namei.c index a6b6a4ab1403..6debc1d88282 100644 --- a/fs/erofs/namei.c +++ b/fs/erofs/namei.c @@ -14,9 +14,9 @@ struct erofs_qstr { }; /* based on the end of qn is accurate and it must have the trailing '\0' */ -static inline int dirnamecmp(const struct erofs_qstr *qn, - const struct erofs_qstr *qd, - unsigned int *matched) +static inline int erofs_dirnamecmp(const struct erofs_qstr *qn, + const struct erofs_qstr *qd, + unsigned int *matched) { unsigned int i = *matched; @@ -71,7 +71,7 @@ static struct erofs_dirent *find_target_dirent(struct erofs_qstr *name, }; /* string comparison without already matched prefix */ - int ret = dirnamecmp(name, &dname, &matched); + int ret = erofs_dirnamecmp(name, &dname, &matched); if (!ret) { return de + mid; @@ -98,7 +98,7 @@ static struct page *find_target_block_classic(struct inode *dir, startprfx = endprfx = 0; head = 0; - back = inode_datablocks(dir) - 1; + back = erofs_inode_datablocks(dir) - 1; while (head <= back) { const int mid = head + (back - head) / 2; @@ -134,7 +134,7 @@ static struct page *find_target_block_classic(struct inode *dir, EROFS_BLKSIZ); /* string comparison without already matched prefix */ - diff = dirnamecmp(name, &dname, &matched); + diff = erofs_dirnamecmp(name, &dname, &matched); kunmap_atomic(de); if (!diff) { diff --git a/fs/erofs/super.c b/fs/erofs/super.c index b64d69f18270..36e569a79172 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -16,14 +16,14 @@ static struct kmem_cache *erofs_inode_cachep __read_mostly; -static void init_once(void *ptr) +static void erofs_inode_init_once(void *ptr) { struct erofs_inode *vi = ptr; inode_init_once(&vi->vfs_inode); } -static struct inode *alloc_inode(struct super_block *sb) +static struct inode *erofs_alloc_inode(struct super_block *sb) { struct erofs_inode *vi = kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL); @@ -36,7 +36,7 @@ static struct inode *alloc_inode(struct super_block *sb) return &vi->vfs_inode; } -static void free_inode(struct inode *inode) +static void erofs_free_inode(struct inode *inode) { struct erofs_inode *vi = EROFS_I(inode); @@ -64,7 +64,7 @@ static bool check_layout_compatibility(struct super_block *sb, return true; } -static int superblock_read(struct super_block *sb) +static int erofs_read_superblock(struct super_block *sb) { struct erofs_sb_info *sbi; struct buffer_head *bh; @@ -218,7 +218,7 @@ static int erofs_build_cache_strategy(struct erofs_sb_info *sbi, #endif /* set up default EROFS parameters */ -static void default_options(struct erofs_sb_info *sbi) +static void erofs_default_options(struct erofs_sb_info *sbi) { #ifdef CONFIG_EROFS_FS_ZIP sbi->cache_strategy = EROFS_ZIP_CACHE_READAROUND; @@ -252,7 +252,7 @@ static match_table_t erofs_tokens = { {Opt_err, NULL} }; -static int parse_options(struct super_block *sb, char *options) +static int erofs_parse_options(struct super_block *sb, char *options) { substring_t args[MAX_OPT_ARGS]; char *p; @@ -322,7 +322,7 @@ static int parse_options(struct super_block *sb, char *options) #ifdef CONFIG_EROFS_FS_ZIP static const struct address_space_operations managed_cache_aops; -static int managed_cache_releasepage(struct page *page, gfp_t gfp_mask) +static int erofs_managed_cache_releasepage(struct page *page, gfp_t gfp_mask) { int ret = 1; /* 0 - busy */ struct address_space *const mapping = page->mapping; @@ -336,9 +336,9 @@ static int managed_cache_releasepage(struct page *page, gfp_t gfp_mask) return ret; } -static void managed_cache_invalidatepage(struct page *page, - unsigned int offset, - unsigned int length) +static void erofs_managed_cache_invalidatepage(struct page *page, + unsigned int offset, + unsigned int length) { const unsigned int stop = length + offset; @@ -348,13 +348,13 @@ static void managed_cache_invalidatepage(struct page *page, DBG_BUGON(stop > PAGE_SIZE || stop < length); if (offset == 0 && stop == PAGE_SIZE) - while (!managed_cache_releasepage(page, GFP_NOFS)) + while (!erofs_managed_cache_releasepage(page, GFP_NOFS)) cond_resched(); } static const struct address_space_operations managed_cache_aops = { - .releasepage = managed_cache_releasepage, - .invalidatepage = managed_cache_invalidatepage, + .releasepage = erofs_managed_cache_releasepage, + .invalidatepage = erofs_managed_cache_invalidatepage, }; static int erofs_init_managed_cache(struct super_block *sb) @@ -396,7 +396,7 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) return -ENOMEM; sb->s_fs_info = sbi; - err = superblock_read(sb); + err = erofs_read_superblock(sb); if (err) return err; @@ -410,9 +410,9 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) sb->s_xattr = erofs_xattr_handlers; #endif /* set erofs default mount options */ - default_options(sbi); + erofs_default_options(sbi); - err = parse_options(sb, data); + err = erofs_parse_options(sb, data); if (err) return err; @@ -512,7 +512,7 @@ static int __init erofs_module_init(void) erofs_inode_cachep = kmem_cache_create("erofs_inode", sizeof(struct erofs_inode), 0, SLAB_RECLAIM_ACCOUNT, - init_once); + erofs_inode_init_once); if (!erofs_inode_cachep) { err = -ENOMEM; goto icache_err; @@ -619,7 +619,7 @@ static int erofs_remount(struct super_block *sb, int *flags, char *data) int err; DBG_BUGON(!sb_rdonly(sb)); - err = parse_options(sb, data); + err = erofs_parse_options(sb, data); if (err) goto out; @@ -639,8 +639,8 @@ static int erofs_remount(struct super_block *sb, int *flags, char *data) const struct super_operations erofs_sops = { .put_super = erofs_put_super, - .alloc_inode = alloc_inode, - .free_inode = free_inode, + .alloc_inode = erofs_alloc_inode, + .free_inode = erofs_free_inode, .statfs = erofs_statfs, .show_options = erofs_show_options, .remount_fs = erofs_remount, diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 3010fa3d1ac3..8587d6751c48 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -40,7 +40,7 @@ void z_erofs_exit_zip_subsystem(void) kmem_cache_destroy(pcluster_cachep); } -static inline int init_unzip_workqueue(void) +static inline int z_erofs_init_workqueue(void) { const unsigned int onlinecpus = num_possible_cpus(); const unsigned int flags = WQ_UNBOUND | WQ_HIGHPRI | WQ_CPU_INTENSIVE; @@ -54,7 +54,7 @@ static inline int init_unzip_workqueue(void) return z_erofs_workqueue ? 0 : -ENOMEM; } -static void init_once(void *ptr) +static void z_erofs_pcluster_init_once(void *ptr) { struct z_erofs_pcluster *pcl = ptr; struct z_erofs_collection *cl = z_erofs_primarycollection(pcl); @@ -67,7 +67,7 @@ static void init_once(void *ptr) pcl->compressed_pages[i] = NULL; } -static void init_always(struct z_erofs_pcluster *pcl) +static void z_erofs_pcluster_init_always(struct z_erofs_pcluster *pcl) { struct z_erofs_collection *cl = z_erofs_primarycollection(pcl); @@ -81,9 +81,10 @@ int __init z_erofs_init_zip_subsystem(void) { pcluster_cachep = kmem_cache_create("erofs_compress", Z_EROFS_WORKGROUP_SIZE, 0, - SLAB_RECLAIM_ACCOUNT, init_once); + SLAB_RECLAIM_ACCOUNT, + z_erofs_pcluster_init_once); if (pcluster_cachep) { - if (!init_unzip_workqueue()) + if (!z_erofs_init_workqueue()) return 0; kmem_cache_destroy(pcluster_cachep); @@ -272,8 +273,8 @@ int erofs_try_to_free_cached_page(struct address_space *mapping, } /* page_type must be Z_EROFS_PAGE_TYPE_EXCLUSIVE */ -static inline bool try_inplace_io(struct z_erofs_collector *clt, - struct page *page) +static inline bool z_erofs_try_inplace_io(struct z_erofs_collector *clt, + struct page *page) { struct z_erofs_pcluster *const pcl = clt->pcl; const unsigned int clusterpages = BIT(pcl->clusterbits); @@ -296,7 +297,7 @@ static int z_erofs_attach_page(struct z_erofs_collector *clt, /* give priority for inplaceio */ if (clt->mode >= COLLECT_PRIMARY && type == Z_EROFS_PAGE_TYPE_EXCLUSIVE && - try_inplace_io(clt, page)) + z_erofs_try_inplace_io(clt, page)) return 0; ret = z_erofs_pagevec_enqueue(&clt->vector, @@ -409,7 +410,7 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, if (!pcl) return ERR_PTR(-ENOMEM); - init_always(pcl); + z_erofs_pcluster_init_always(pcl); pcl->obj.index = map->m_pa >> PAGE_SHIFT; pcl->length = (map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) | From patchwork Wed Sep 4 02:09:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129165 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8EB311813 for ; Wed, 4 Sep 2019 02:10:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6BCC22341E for ; Wed, 4 Sep 2019 02:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728044AbfIDCKm (ORCPT ); Tue, 3 Sep 2019 22:10:42 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60184 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727979AbfIDCKk (ORCPT ); Tue, 3 Sep 2019 22:10:40 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EE6FA4F6F33C692D600A; Wed, 4 Sep 2019 10:10:38 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:26 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 19/25] erofs: kill all erofs specific fault injection Date: Wed, 4 Sep 2019 10:09:06 +0800 Message-ID: <20190904020912.63925-20-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph suggested [1], "Please just use plain kmalloc everywhere and let the normal kernel error injection code take care of injeting any errors." [1] https://lore.kernel.org/r/20190829102426.GE20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- Documentation/filesystems/erofs.txt | 5 --- fs/erofs/Kconfig | 7 --- fs/erofs/data.c | 7 --- fs/erofs/inode.c | 3 +- fs/erofs/internal.h | 65 --------------------------- fs/erofs/super.c | 70 ----------------------------- fs/erofs/zdata.c | 8 +--- 7 files changed, 2 insertions(+), 163 deletions(-) diff --git a/Documentation/filesystems/erofs.txt b/Documentation/filesystems/erofs.txt index 38aa9126ec98..c3b5f603b2b6 100644 --- a/Documentation/filesystems/erofs.txt +++ b/Documentation/filesystems/erofs.txt @@ -52,11 +52,6 @@ linux-erofs mailing list: Mount options ============= -fault_injection=%d Enable fault injection in all supported types with - specified injection rate. Supported injection type: - Type_Name Type_Value - FAULT_KMALLOC 0x000000001 - FAULT_READ_IO 0x000000002 (no)user_xattr Setup Extended User Attributes. Note: xattr is enabled by default if CONFIG_EROFS_FS_XATTR is selected. (no)acl Setup POSIX Access Control List. Note: acl is enabled diff --git a/fs/erofs/Kconfig b/fs/erofs/Kconfig index 16316d1adca3..9d634d3a1845 100644 --- a/fs/erofs/Kconfig +++ b/fs/erofs/Kconfig @@ -27,13 +27,6 @@ config EROFS_FS_DEBUG For daily use, say N. -config EROFS_FAULT_INJECTION - bool "EROFS fault injection facility" - depends on EROFS_FS - help - Test EROFS to inject faults such as ENOMEM, EIO, and so on. - If unsure, say N. - config EROFS_FS_XATTR bool "EROFS extended attributes" depends on EROFS_FS diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 3ce87a88452a..b5f5b8592d14 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -11,16 +11,10 @@ static void erofs_readendio(struct bio *bio) { - struct super_block *const sb = bio->bi_private; struct bio_vec *bvec; blk_status_t err = bio->bi_status; struct bvec_iter_all iter_all; - if (time_to_inject(EROFS_SB(sb), FAULT_READ_IO)) { - erofs_show_injection_info(FAULT_READ_IO); - err = BLK_STS_IOERR; - } - bio_for_each_segment_all(bvec, bio, iter_all) { struct page *page = bvec->bv_page; @@ -48,7 +42,6 @@ static struct bio *erofs_grab_raw_bio(struct super_block *sb, bio->bi_end_io = erofs_readendio; bio_set_dev(bio, sb->s_bdev); bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK; - bio->bi_private = sb; if (ismeta) bio->bi_opf = REQ_OP_READ | REQ_META; else diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 384905e0677c..8e53765a532c 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -131,7 +131,6 @@ static int erofs_fill_symlink(struct inode *inode, void *data, unsigned int m_pofs) { struct erofs_inode *vi = EROFS_I(inode); - struct erofs_sb_info *sbi = EROFS_I_SB(inode); char *lnk; /* if it cannot be handled with fast symlink scheme */ @@ -141,7 +140,7 @@ static int erofs_fill_symlink(struct inode *inode, void *data, return 0; } - lnk = erofs_kmalloc(sbi, inode->i_size + 1, GFP_KERNEL); + lnk = kmalloc(inode->i_size + 1, GFP_KERNEL); if (!lnk) return -ENOMEM; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 881eb2ee18b5..d659c1941f93 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -32,23 +32,6 @@ #define DBG_BUGON(x) ((void)(x)) #endif /* !CONFIG_EROFS_FS_DEBUG */ -enum { - FAULT_KMALLOC, - FAULT_READ_IO, - FAULT_MAX, -}; - -#ifdef CONFIG_EROFS_FAULT_INJECTION -extern const char *erofs_fault_name[FAULT_MAX]; -#define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) - -struct erofs_fault_info { - atomic_t inject_ops; - unsigned int inject_rate; - unsigned int inject_type; -}; -#endif /* CONFIG_EROFS_FAULT_INJECTION */ - /* EROFS_SUPER_MAGIC_V1 to represent the whole file system */ #define EROFS_SUPER_MAGIC EROFS_SUPER_MAGIC_V1 @@ -99,62 +82,14 @@ struct erofs_sb_info { u32 feature_incompat; unsigned int mount_opt; - -#ifdef CONFIG_EROFS_FAULT_INJECTION - struct erofs_fault_info fault_info; /* For fault injection */ -#endif }; -#ifdef CONFIG_EROFS_FAULT_INJECTION -#define erofs_show_injection_info(type) \ - infoln("inject %s in %s of %pS", erofs_fault_name[type], \ - __func__, __builtin_return_address(0)) - -static inline bool time_to_inject(struct erofs_sb_info *sbi, int type) -{ - struct erofs_fault_info *ffi = &sbi->fault_info; - - if (!ffi->inject_rate) - return false; - - if (!IS_FAULT_SET(ffi, type)) - return false; - - atomic_inc(&ffi->inject_ops); - if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { - atomic_set(&ffi->inject_ops, 0); - return true; - } - return false; -} -#else -static inline bool time_to_inject(struct erofs_sb_info *sbi, int type) -{ - return false; -} - -static inline void erofs_show_injection_info(int type) -{ -} -#endif /* !CONFIG_EROFS_FAULT_INJECTION */ - -static inline void *erofs_kmalloc(struct erofs_sb_info *sbi, - size_t size, gfp_t flags) -{ - if (time_to_inject(sbi, FAULT_KMALLOC)) { - erofs_show_injection_info(FAULT_KMALLOC); - return NULL; - } - return kmalloc(size, flags); -} - #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info) #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info) /* Mount flags set via mount options or defaults */ #define EROFS_MOUNT_XATTR_USER 0x00000010 #define EROFS_MOUNT_POSIX_ACL 0x00000020 -#define EROFS_MOUNT_FAULT_INJECTION 0x00000040 #define clear_opt(sbi, option) ((sbi)->mount_opt &= ~EROFS_MOUNT_##option) #define set_opt(sbi, option) ((sbi)->mount_opt |= EROFS_MOUNT_##option) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 36e569a79172..407c95854be1 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -126,63 +126,6 @@ static int erofs_read_superblock(struct super_block *sb) return ret; } -#ifdef CONFIG_EROFS_FAULT_INJECTION -const char *erofs_fault_name[FAULT_MAX] = { - [FAULT_KMALLOC] = "kmalloc", - [FAULT_READ_IO] = "read IO error", -}; - -static void __erofs_build_fault_attr(struct erofs_sb_info *sbi, - unsigned int rate) -{ - struct erofs_fault_info *ffi = &sbi->fault_info; - - if (rate) { - atomic_set(&ffi->inject_ops, 0); - ffi->inject_rate = rate; - ffi->inject_type = (1 << FAULT_MAX) - 1; - } else { - memset(ffi, 0, sizeof(struct erofs_fault_info)); - } - - set_opt(sbi, FAULT_INJECTION); -} - -static int erofs_build_fault_attr(struct erofs_sb_info *sbi, - substring_t *args) -{ - int rate = 0; - - if (args->from && match_int(args, &rate)) - return -EINVAL; - - __erofs_build_fault_attr(sbi, rate); - return 0; -} - -static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi) -{ - return sbi->fault_info.inject_rate; -} -#else -static void __erofs_build_fault_attr(struct erofs_sb_info *sbi, - unsigned int rate) -{ -} - -static int erofs_build_fault_attr(struct erofs_sb_info *sbi, - substring_t *args) -{ - infoln("fault_injection options not supported"); - return 0; -} - -static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi) -{ - return 0; -} -#endif - #ifdef CONFIG_EROFS_FS_ZIP static int erofs_build_cache_strategy(struct erofs_sb_info *sbi, substring_t *args) @@ -237,7 +180,6 @@ enum { Opt_nouser_xattr, Opt_acl, Opt_noacl, - Opt_fault_injection, Opt_cache_strategy, Opt_err }; @@ -247,7 +189,6 @@ static match_table_t erofs_tokens = { {Opt_nouser_xattr, "nouser_xattr"}, {Opt_acl, "acl"}, {Opt_noacl, "noacl"}, - {Opt_fault_injection, "fault_injection=%u"}, {Opt_cache_strategy, "cache_strategy=%s"}, {Opt_err, NULL} }; @@ -301,11 +242,6 @@ static int erofs_parse_options(struct super_block *sb, char *options) infoln("noacl options not supported"); break; #endif - case Opt_fault_injection: - err = erofs_build_fault_attr(EROFS_SB(sb), args); - if (err) - return err; - break; case Opt_cache_strategy: err = erofs_build_cache_strategy(EROFS_SB(sb), args); if (err) @@ -593,9 +529,6 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root) else seq_puts(seq, ",noacl"); #endif - if (test_opt(sbi, FAULT_INJECTION)) - seq_printf(seq, ",fault_injection=%u", - erofs_get_fault_rate(sbi)); #ifdef CONFIG_EROFS_FS_ZIP if (sbi->cache_strategy == EROFS_ZIP_CACHE_DISABLED) { seq_puts(seq, ",cache_strategy=disabled"); @@ -615,7 +548,6 @@ static int erofs_remount(struct super_block *sb, int *flags, char *data) { struct erofs_sb_info *sbi = EROFS_SB(sb); unsigned int org_mnt_opt = sbi->mount_opt; - unsigned int org_inject_rate = erofs_get_fault_rate(sbi); int err; DBG_BUGON(!sb_rdonly(sb)); @@ -631,9 +563,7 @@ static int erofs_remount(struct super_block *sb, int *flags, char *data) *flags |= SB_RDONLY; return 0; out: - __erofs_build_fault_attr(sbi, org_inject_rate); sbi->mount_opt = org_mnt_opt; - return err; } diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 8587d6751c48..ff8ab444172d 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -724,15 +724,9 @@ static inline void z_erofs_vle_read_endio(struct bio *bio) DBG_BUGON(PageUptodate(page)); DBG_BUGON(!page->mapping); - if (!sbi && !z_erofs_page_is_staging(page)) { + if (!sbi && !z_erofs_page_is_staging(page)) sbi = EROFS_SB(page->mapping->host->i_sb); - if (time_to_inject(sbi, FAULT_READ_IO)) { - erofs_show_injection_info(FAULT_READ_IO); - err = BLK_STS_IOERR; - } - } - /* sbi should already be gotten if the page is managed */ if (sbi) cachemngd = erofs_page_is_managed(sbi, page); From patchwork Wed Sep 4 02:09:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129157 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F53B17EF for ; Wed, 4 Sep 2019 02:10:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED8252339D for ; Wed, 4 Sep 2019 02:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727995AbfIDCKk (ORCPT ); Tue, 3 Sep 2019 22:10:40 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60196 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727065AbfIDCKk (ORCPT ); Tue, 3 Sep 2019 22:10:40 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 00D1C8FEB033617DA992; Wed, 4 Sep 2019 10:10:39 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:27 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 20/25] erofs: kill use_vmap module parameter Date: Wed, 4 Sep 2019 10:09:07 +0800 Message-ID: <20190904020912.63925-21-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said [1], "vm_map_ram is supposed to generally behave better. So if it doesn't please report that that to the arch maintainer and linux-mm so that they can look into the issue. Having user make choices of deep down kernel internals is just a horrible interface. Please talk to maintainers of other bits of the kernel if you see issues and / or need enhancements. " Let's redo the previous conclusion and kill the vmap approach. [1] https://lore.kernel.org/r/20190830165533.GA10909@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- Documentation/filesystems/erofs.txt | 4 --- fs/erofs/decompressor.c | 46 ++++++++--------------------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/Documentation/filesystems/erofs.txt b/Documentation/filesystems/erofs.txt index c3b5f603b2b6..b0c085326e2e 100644 --- a/Documentation/filesystems/erofs.txt +++ b/Documentation/filesystems/erofs.txt @@ -67,10 +67,6 @@ cache_strategy=%s Select a strategy for cached decompression from now on: It still does in-place I/O decompression for the rest compressed physical clusters. -Module parameters -================= -use_vmap=[0|1] Use vmap() instead of vm_map_ram() (default 0). - On-disk details =============== diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 8ed38504a9f1..37177d49d125 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -28,10 +28,6 @@ struct z_erofs_decompressor { char *name; }; -static bool use_vmap; -module_param(use_vmap, bool, 0444); -MODULE_PARM_DESC(use_vmap, "Use vmap() instead of vm_map_ram() (default 0)"); - static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq, struct list_head *pagepool) { @@ -221,32 +217,6 @@ static void copy_from_pcpubuf(struct page **out, const char *dst, } } -static void *erofs_vmap(struct page **pages, unsigned int count) -{ - int i = 0; - - if (use_vmap) - return vmap(pages, count, VM_MAP, PAGE_KERNEL); - - while (1) { - void *addr = vm_map_ram(pages, count, -1, PAGE_KERNEL); - - /* retry two more times (totally 3 times) */ - if (addr || ++i >= 3) - return addr; - vm_unmap_aliases(); - } - return NULL; -} - -static void erofs_vunmap(const void *mem, unsigned int count) -{ - if (!use_vmap) - vm_unmap_ram(mem, count); - else - vunmap(mem); -} - static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq, struct list_head *pagepool) { @@ -255,7 +225,7 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq, const struct z_erofs_decompressor *alg = decompressors + rq->alg; unsigned int dst_maptype; void *dst; - int ret; + int ret, i; if (nrpages_out == 1 && !rq->inplace_io) { DBG_BUGON(!*rq->out); @@ -293,9 +263,19 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq, goto dstmap_out; } - dst = erofs_vmap(rq->out, nrpages_out); + i = 0; + while (1) { + dst = vm_map_ram(rq->out, nrpages_out, -1, PAGE_KERNEL); + + /* retry two more times (totally 3 times) */ + if (dst || ++i >= 3) + break; + vm_unmap_aliases(); + } + if (!dst) return -ENOMEM; + dst_maptype = 2; dstmap_out: @@ -304,7 +284,7 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq, if (!dst_maptype) kunmap_atomic(dst); else if (dst_maptype == 2) - erofs_vunmap(dst, nrpages_out); + vm_unmap_ram(dst, nrpages_out); return ret; } From patchwork Wed Sep 4 02:09:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129159 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CB251813 for ; Wed, 4 Sep 2019 02:10:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 66F222339D for ; Wed, 4 Sep 2019 02:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727997AbfIDCKk (ORCPT ); Tue, 3 Sep 2019 22:10:40 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60204 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727992AbfIDCKk (ORCPT ); Tue, 3 Sep 2019 22:10:40 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 060AAA4F430BAAEEEBB4; Wed, 4 Sep 2019 10:10:39 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:28 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 21/25] erofs: save one level of indentation Date: Wed, 4 Sep 2019 10:09:08 +0800 Message-ID: <20190904020912.63925-22-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said [1], ".. and save one level of indentation." [1] https://lore.kernel.org/r/20190829102426.GE20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/inode.c | 65 ++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 8e53765a532c..5a6d3282fefb 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -193,41 +193,42 @@ static int erofs_fill_inode(struct inode *inode, int isdir) data = page_address(page); err = erofs_read_inode(inode, data + ofs); - if (!err) { - /* setup the new inode */ - switch (inode->i_mode & S_IFMT) { - case S_IFREG: - inode->i_op = &erofs_generic_iops; - inode->i_fop = &generic_ro_fops; - break; - case S_IFDIR: - inode->i_op = &erofs_dir_iops; - inode->i_fop = &erofs_dir_fops; - break; - case S_IFLNK: - err = erofs_fill_symlink(inode, data, ofs); - if (err) - goto out_unlock; - inode_nohighmem(inode); - break; - case S_IFCHR: - case S_IFBLK: - case S_IFIFO: - case S_IFSOCK: - inode->i_op = &erofs_generic_iops; - init_special_inode(inode, inode->i_mode, inode->i_rdev); - goto out_unlock; - default: - err = -EFSCORRUPTED; + if (err) + goto out_unlock; + + /* setup the new inode */ + switch (inode->i_mode & S_IFMT) { + case S_IFREG: + inode->i_op = &erofs_generic_iops; + inode->i_fop = &generic_ro_fops; + break; + case S_IFDIR: + inode->i_op = &erofs_dir_iops; + inode->i_fop = &erofs_dir_fops; + break; + case S_IFLNK: + err = erofs_fill_symlink(inode, data, ofs); + if (err) goto out_unlock; - } + inode_nohighmem(inode); + break; + case S_IFCHR: + case S_IFBLK: + case S_IFIFO: + case S_IFSOCK: + inode->i_op = &erofs_generic_iops; + init_special_inode(inode, inode->i_mode, inode->i_rdev); + goto out_unlock; + default: + err = -EFSCORRUPTED; + goto out_unlock; + } - if (erofs_inode_is_data_compressed(vi->datalayout)) { - err = z_erofs_fill_inode(inode); - goto out_unlock; - } - inode->i_mapping->a_ops = &erofs_raw_access_aops; + if (erofs_inode_is_data_compressed(vi->datalayout)) { + err = z_erofs_fill_inode(inode); + goto out_unlock; } + inode->i_mapping->a_ops = &erofs_raw_access_aops; out_unlock: unlock_page(page); From patchwork Wed Sep 4 02:09:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129171 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84A4917EF for ; Wed, 4 Sep 2019 02:10:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5A77321897 for ; Wed, 4 Sep 2019 02:10:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728046AbfIDCKo (ORCPT ); Tue, 3 Sep 2019 22:10:44 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5743 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727949AbfIDCKm (ORCPT ); Tue, 3 Sep 2019 22:10:42 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id B5D8EB7704581B3E7437; Wed, 4 Sep 2019 10:10:40 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:29 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 22/25] erofs: rename errln/infoln/debugln to erofs_{err,info,dbg} Date: Wed, 4 Sep 2019 10:09:09 +0800 Message-ID: <20190904020912.63925-23-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add prefix "erofs_" to these functions and print sb->s_id as a prefix to erofs_{err, info} so that the user knows which file system is affected. Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/data.c | 10 +++-- fs/erofs/decompressor.c | 5 +-- fs/erofs/dir.c | 17 +++++---- fs/erofs/inode.c | 31 ++++++++------- fs/erofs/internal.h | 14 +++++-- fs/erofs/namei.c | 9 +++-- fs/erofs/super.c | 83 +++++++++++++++++++++++++++-------------- fs/erofs/xattr.c | 8 ++-- fs/erofs/zdata.c | 13 ++++--- fs/erofs/zdata.h | 2 +- fs/erofs/zmap.c | 37 ++++++++++-------- 11 files changed, 139 insertions(+), 90 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index b5f5b8592d14..eb7bbae89ed0 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -137,8 +137,9 @@ static int erofs_map_blocks_flatmode(struct inode *inode, /* inline data should be located in one meta block */ if (erofs_blkoff(map->m_pa) + map->m_plen > PAGE_SIZE) { - errln("inline data cross block boundary @ nid %llu", - vi->nid); + erofs_err(inode->i_sb, + "inline data cross block boundary @ nid %llu", + vi->nid); DBG_BUGON(1); err = -EFSCORRUPTED; goto err_out; @@ -146,8 +147,9 @@ static int erofs_map_blocks_flatmode(struct inode *inode, map->m_flags |= EROFS_MAP_META; } else { - errln("internal error @ nid: %llu (size %llu), m_la 0x%llx", - vi->nid, inode->i_size, map->m_la); + erofs_err(inode->i_sb, + "internal error @ nid: %llu (size %llu), m_la 0x%llx", + vi->nid, inode->i_size, map->m_la); DBG_BUGON(1); err = -EIO; goto err_out; diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 37177d49d125..19f89f9fb10c 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -161,9 +161,8 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out) inlen, rq->outputsize, rq->outputsize); if (ret < 0) { - errln("%s, failed to decompress, in[%p, %u, %u] out[%p, %u]", - __func__, src + inputmargin, inlen, inputmargin, - out, rq->outputsize); + erofs_err(rq->sb, "failed to decompress, in[%u, %u] out[%u]", + inlen, inputmargin, rq->outputsize); WARN_ON(1); print_hex_dump(KERN_DEBUG, "[ in]: ", DUMP_PREFIX_OFFSET, 16, 1, src + inputmargin, inlen, true); diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c index a032c8217071..d28c623dfef9 100644 --- a/fs/erofs/dir.c +++ b/fs/erofs/dir.c @@ -16,8 +16,8 @@ static void debug_one_dentry(unsigned char d_type, const char *de_name, memcpy(dbg_namebuf, de_name, de_namelen); dbg_namebuf[de_namelen] = '\0'; - debugln("found dirent %s de_len %u d_type %d", dbg_namebuf, - de_namelen, d_type); + erofs_dbg("found dirent %s de_len %u d_type %d", dbg_namebuf, + de_namelen, d_type); #endif } @@ -47,7 +47,8 @@ static int erofs_fill_dentries(struct inode *dir, struct dir_context *ctx, /* a corrupted entry is found */ if (nameoff + de_namelen > maxsize || de_namelen > EROFS_NAME_LEN) { - errln("bogus dirent @ nid %llu", EROFS_I(dir)->nid); + erofs_err(dir->i_sb, "bogus dirent @ nid %llu", + EROFS_I(dir)->nid); DBG_BUGON(1); return -EFSCORRUPTED; } @@ -84,8 +85,9 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) err = -ENOMEM; break; } else if (IS_ERR(dentry_page)) { - errln("fail to readdir of logical block %u of nid %llu", - i, EROFS_I(dir)->nid); + erofs_err(dir->i_sb, + "fail to readdir of logical block %u of nid %llu", + i, EROFS_I(dir)->nid); err = -EFSCORRUPTED; break; } @@ -96,8 +98,9 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) if (nameoff < sizeof(struct erofs_dirent) || nameoff >= PAGE_SIZE) { - errln("%s, invalid de[0].nameoff %u @ nid %llu", - __func__, nameoff, EROFS_I(dir)->nid); + erofs_err(dir->i_sb, + "invalid de[0].nameoff %u @ nid %llu", + nameoff, EROFS_I(dir)->nid); err = -EFSCORRUPTED; goto skip_this; } diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 5a6d3282fefb..a0cec3c754cd 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -22,8 +22,8 @@ static int erofs_read_inode(struct inode *inode, void *data) vi->datalayout = erofs_inode_datalayout(ifmt); if (vi->datalayout >= EROFS_INODE_DATALAYOUT_MAX) { - errln("unsupported datalayout %u of nid %llu", - vi->datalayout, vi->nid); + erofs_err(inode->i_sb, "unsupported datalayout %u of nid %llu", + vi->datalayout, vi->nid); DBG_BUGON(1); return -EOPNOTSUPP; } @@ -108,8 +108,9 @@ static int erofs_read_inode(struct inode *inode, void *data) nblks = le32_to_cpu(dic->i_u.compressed_blocks); break; default: - errln("unsupported on-disk inode version %u of nid %llu", - erofs_inode_version(ifmt), vi->nid); + erofs_err(inode->i_sb, + "unsupported on-disk inode version %u of nid %llu", + erofs_inode_version(ifmt), vi->nid); DBG_BUGON(1); return -EOPNOTSUPP; } @@ -122,7 +123,8 @@ static int erofs_read_inode(struct inode *inode, void *data) return 0; bogusimode: - errln("bogus i_mode (%o) @ nid %llu", inode->i_mode, vi->nid); + erofs_err(inode->i_sb, "bogus i_mode (%o) @ nid %llu", + inode->i_mode, vi->nid); DBG_BUGON(1); return -EFSCORRUPTED; } @@ -148,8 +150,9 @@ static int erofs_fill_symlink(struct inode *inode, void *data, /* inline symlink data shouldn't cross page boundary as well */ if (m_pofs + inode->i_size > PAGE_SIZE) { kfree(lnk); - errln("inline data cross block boundary @ nid %llu", - vi->nid); + erofs_err(inode->i_sb, + "inline data cross block boundary @ nid %llu", + vi->nid); DBG_BUGON(1); return -EFSCORRUPTED; } @@ -164,7 +167,7 @@ static int erofs_fill_symlink(struct inode *inode, void *data, static int erofs_fill_inode(struct inode *inode, int isdir) { - struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); + struct super_block *sb = inode->i_sb; struct erofs_inode *vi = EROFS_I(inode); struct page *page; void *data; @@ -174,18 +177,18 @@ static int erofs_fill_inode(struct inode *inode, int isdir) erofs_off_t inode_loc; trace_erofs_fill_inode(inode, isdir); - inode_loc = iloc(sbi, vi->nid); + inode_loc = iloc(EROFS_SB(sb), vi->nid); blkaddr = erofs_blknr(inode_loc); ofs = erofs_blkoff(inode_loc); - debugln("%s, reading inode nid %llu at %u of blkaddr %u", - __func__, vi->nid, ofs, blkaddr); + erofs_dbg("%s, reading inode nid %llu at %u of blkaddr %u", + __func__, vi->nid, ofs, blkaddr); - page = erofs_get_meta_page(inode->i_sb, blkaddr); + page = erofs_get_meta_page(sb, blkaddr); if (IS_ERR(page)) { - errln("failed to get inode (nid: %llu) page, err %ld", - vi->nid, PTR_ERR(page)); + erofs_err(sb, "failed to get inode (nid: %llu) page, err %ld", + vi->nid, PTR_ERR(page)); return PTR_ERR(page); } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index d659c1941f93..544a453f3076 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -22,13 +22,19 @@ #undef pr_fmt #define pr_fmt(fmt) "erofs: " fmt -#define errln(x, ...) pr_err(x "\n", ##__VA_ARGS__) -#define infoln(x, ...) pr_info(x "\n", ##__VA_ARGS__) +__printf(3, 4) void _erofs_err(struct super_block *sb, + const char *function, const char *fmt, ...); +#define erofs_err(sb, fmt, ...) \ + _erofs_err(sb, __func__, fmt "\n", ##__VA_ARGS__) +__printf(3, 4) void _erofs_info(struct super_block *sb, + const char *function, const char *fmt, ...); +#define erofs_info(sb, fmt, ...) \ + _erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__) #ifdef CONFIG_EROFS_FS_DEBUG -#define debugln(x, ...) pr_debug(x "\n", ##__VA_ARGS__) +#define erofs_dbg(x, ...) pr_debug(x "\n", ##__VA_ARGS__) #define DBG_BUGON BUG_ON #else -#define debugln(x, ...) ((void)0) +#define erofs_dbg(x, ...) ((void)0) #define DBG_BUGON(x) ((void)(x)) #endif /* !CONFIG_EROFS_FS_DEBUG */ diff --git a/fs/erofs/namei.c b/fs/erofs/namei.c index 6debc1d88282..3abbecbf73de 100644 --- a/fs/erofs/namei.c +++ b/fs/erofs/namei.c @@ -116,8 +116,9 @@ static struct page *find_target_block_classic(struct inode *dir, if (!ndirents) { kunmap_atomic(de); put_page(page); - errln("corrupted dir block %d @ nid %llu", - mid, EROFS_I(dir)->nid); + erofs_err(dir->i_sb, + "corrupted dir block %d @ nid %llu", + mid, EROFS_I(dir)->nid); DBG_BUGON(1); page = ERR_PTR(-EFSCORRUPTED); goto out; @@ -233,8 +234,8 @@ static struct dentry *erofs_lookup(struct inode *dir, } else if (err) { inode = ERR_PTR(err); } else { - debugln("%s, %s (nid %llu) found, d_type %u", __func__, - dentry->d_name.name, nid, d_type); + erofs_dbg("%s, %s (nid %llu) found, d_type %u", __func__, + dentry->d_name.name, nid, d_type); inode = erofs_iget(dir->i_sb, nid, d_type == FT_DIR); } return d_splice_alias(inode, dentry); diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 407c95854be1..1d9880195ef0 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -16,6 +16,36 @@ static struct kmem_cache *erofs_inode_cachep __read_mostly; +void _erofs_err(struct super_block *sb, const char *function, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + va_start(args, fmt); + + vaf.fmt = fmt; + vaf.va = &args; + + pr_err("(device %s): %s: %pV", sb->s_id, function, &vaf); + va_end(args); +} + +void _erofs_info(struct super_block *sb, const char *function, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + va_start(args, fmt); + + vaf.fmt = fmt; + vaf.va = &args; + + pr_info("(device %s): %pV", sb->s_id, &vaf); + va_end(args); +} + static void erofs_inode_init_once(void *ptr) { struct erofs_inode *vi = ptr; @@ -57,8 +87,9 @@ static bool check_layout_compatibility(struct super_block *sb, /* check if current kernel meets all mandatory requirements */ if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) { - errln("unidentified incompatible feature %x, please upgrade kernel version", - feature & ~EROFS_ALL_FEATURE_INCOMPAT); + erofs_err(sb, + "unidentified incompatible feature %x, please upgrade kernel version", + feature & ~EROFS_ALL_FEATURE_INCOMPAT); return false; } return true; @@ -75,7 +106,7 @@ static int erofs_read_superblock(struct super_block *sb) bh = sb_bread(sb, 0); if (!bh) { - errln("cannot read erofs superblock"); + erofs_err(sb, "cannot read erofs superblock"); return -EIO; } @@ -84,15 +115,15 @@ static int erofs_read_superblock(struct super_block *sb) ret = -EINVAL; if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) { - errln("cannot find valid erofs superblock"); + erofs_err(sb, "cannot find valid erofs superblock"); goto out; } blkszbits = dsb->blkszbits; /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */ if (blkszbits != LOG_BLOCK_SIZE) { - errln("blksize %u isn't supported on this platform", - 1 << blkszbits); + erofs_err(sb, "blksize %u isn't supported on this platform", + 1 << blkszbits); goto out; } @@ -116,7 +147,7 @@ static int erofs_read_superblock(struct super_block *sb) ret = strscpy(sbi->volume_name, dsb->volume_name, sizeof(dsb->volume_name)); if (ret < 0) { /* -E2BIG */ - errln("bad volume name without NIL terminator"); + erofs_err(sb, "bad volume name without NIL terminator"); ret = -EFSCORRUPTED; goto out; } @@ -127,14 +158,15 @@ static int erofs_read_superblock(struct super_block *sb) } #ifdef CONFIG_EROFS_FS_ZIP -static int erofs_build_cache_strategy(struct erofs_sb_info *sbi, +static int erofs_build_cache_strategy(struct super_block *sb, substring_t *args) { + struct erofs_sb_info *sbi = EROFS_SB(sb); const char *cs = match_strdup(args); int err = 0; if (!cs) { - errln("Not enough memory to store cache strategy"); + erofs_err(sb, "Not enough memory to store cache strategy"); return -ENOMEM; } @@ -145,17 +177,17 @@ static int erofs_build_cache_strategy(struct erofs_sb_info *sbi, } else if (!strcmp(cs, "readaround")) { sbi->cache_strategy = EROFS_ZIP_CACHE_READAROUND; } else { - errln("Unrecognized cache strategy \"%s\"", cs); + erofs_err(sb, "Unrecognized cache strategy \"%s\"", cs); err = -EINVAL; } kfree(cs); return err; } #else -static int erofs_build_cache_strategy(struct erofs_sb_info *sbi, +static int erofs_build_cache_strategy(struct super_block *sb, substring_t *args) { - infoln("EROFS compression is disabled, so cache strategy is ignored"); + erofs_info(sb, "EROFS compression is disabled, so cache strategy is ignored"); return 0; } #endif @@ -221,10 +253,10 @@ static int erofs_parse_options(struct super_block *sb, char *options) break; #else case Opt_user_xattr: - infoln("user_xattr options not supported"); + erofs_info(sb, "user_xattr options not supported"); break; case Opt_nouser_xattr: - infoln("nouser_xattr options not supported"); + erofs_info(sb, "nouser_xattr options not supported"); break; #endif #ifdef CONFIG_EROFS_FS_POSIX_ACL @@ -236,19 +268,19 @@ static int erofs_parse_options(struct super_block *sb, char *options) break; #else case Opt_acl: - infoln("acl options not supported"); + erofs_info(sb, "acl options not supported"); break; case Opt_noacl: - infoln("noacl options not supported"); + erofs_info(sb, "noacl options not supported"); break; #endif case Opt_cache_strategy: - err = erofs_build_cache_strategy(EROFS_SB(sb), args); + err = erofs_build_cache_strategy(sb, args); if (err) return err; break; default: - errln("Unrecognized mount option \"%s\" or missing value", p); + erofs_err(sb, "Unrecognized mount option \"%s\" or missing value", p); return -EINVAL; } } @@ -323,7 +355,7 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) sb->s_magic = EROFS_SUPER_MAGIC; if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) { - errln("failed to set erofs blksize"); + erofs_err(sb, "failed to set erofs blksize"); return -EINVAL; } @@ -367,8 +399,8 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) return PTR_ERR(inode); if (!S_ISDIR(inode->i_mode)) { - errln("rootino(nid %llu) is not a directory(i_mode %o)", - ROOT_NID(sbi), inode->i_mode); + erofs_err(sb, "rootino(nid %llu) is not a directory(i_mode %o)", + ROOT_NID(sbi), inode->i_mode); iput(inode); return -EINVAL; } @@ -383,9 +415,8 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) if (err) return err; - if (!silent) - infoln("mounted on %s with opts: %s, root inode @ nid %llu.", - sb->s_id, (char *)data, ROOT_NID(sbi)); + erofs_info(sb, "mounted with opts: %s, root inode @ nid %llu.", + (char *)data, ROOT_NID(sbi)); return 0; } @@ -404,7 +435,6 @@ static void erofs_kill_sb(struct super_block *sb) struct erofs_sb_info *sbi; WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC); - infoln("unmounting for %s", sb->s_id); kill_block_super(sb); @@ -443,7 +473,6 @@ static int __init erofs_module_init(void) int err; erofs_check_ondisk_layout_definitions(); - infoln("initializing erofs " EROFS_VERSION); erofs_inode_cachep = kmem_cache_create("erofs_inode", sizeof(struct erofs_inode), 0, @@ -466,7 +495,6 @@ static int __init erofs_module_init(void) if (err) goto fs_err; - infoln("successfully to initialize erofs"); return 0; fs_err: @@ -488,7 +516,6 @@ static void __exit erofs_module_exit(void) /* Ensure all RCU free inodes are safe before cache is destroyed. */ rcu_barrier(); kmem_cache_destroy(erofs_inode_cachep); - infoln("successfully finalize erofs"); } /* get filesystem statistics */ diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index dd445c81c41f..a13a78725c57 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -67,13 +67,15 @@ static int init_inode_xattrs(struct inode *inode) * undefined right now (maybe use later with some new sb feature). */ if (vi->xattr_isize == sizeof(struct erofs_xattr_ibody_header)) { - errln("xattr_isize %d of nid %llu is not supported yet", - vi->xattr_isize, vi->nid); + erofs_err(inode->i_sb, + "xattr_isize %d of nid %llu is not supported yet", + vi->xattr_isize, vi->nid); ret = -EOPNOTSUPP; goto out_unlock; } else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) { if (vi->xattr_isize) { - errln("bogus xattr ibody @ nid %llu", vi->nid); + erofs_err(inode->i_sb, + "bogus xattr ibody @ nid %llu", vi->nid); DBG_BUGON(1); ret = -EFSCORRUPTED; goto out_unlock; /* xattr ondisk layout error */ diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index ff8ab444172d..96e34c90f814 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -600,7 +600,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, } /* go ahead the next map_blocks */ - debugln("%s: [out-of-range] pos %llu", __func__, offset + cur); + erofs_dbg("%s: [out-of-range] pos %llu", __func__, offset + cur); if (z_erofs_collector_end(clt)) fe->backmost = false; @@ -680,8 +680,8 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, out: z_erofs_onlinepage_endio(page); - debugln("%s, finish page: %pK spiltted: %u map->m_llen %llu", - __func__, page, spiltted, map->m_llen); + erofs_dbg("%s, finish page: %pK spiltted: %u map->m_llen %llu", + __func__, page, spiltted, map->m_llen); return err; /* if some error occurred while processing this page */ @@ -1340,7 +1340,7 @@ static int z_erofs_vle_normalaccess_readpage(struct file *file, z_erofs_submit_and_unzip(inode->i_sb, &f.clt, &pagepool, true); if (err) - errln("%s, failed to read, err [%d]", __func__, err); + erofs_err(inode->i_sb, "failed to read, err [%d]", err); if (f.map.mpage) put_page(f.map.mpage); @@ -1406,8 +1406,9 @@ static int z_erofs_vle_normalaccess_readpages(struct file *filp, err = z_erofs_do_read_page(&f, page, &pagepool); if (err) - errln("%s, readahead error at page %lu of nid %llu", - __func__, page->index, EROFS_I(inode)->nid); + erofs_err(inode->i_sb, + "readahead error at page %lu @ nid %llu", + page->index, EROFS_I(inode)->nid); put_page(page); } diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index 4fc547bc01f9..faf950189bd7 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -182,7 +182,7 @@ static inline void z_erofs_onlinepage_endio(struct page *page) SetPageUptodate(page); unlock_page(page); } - debugln("%s, page %p value %x", __func__, page, atomic_read(u.o)); + erofs_dbg("%s, page %p value %x", __func__, page, atomic_read(u.o)); } #define Z_EROFS_VMAP_ONSTACK_PAGES \ diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 9c141f145508..6a26c293ae2d 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -64,8 +64,8 @@ static int fill_inode_lazy(struct inode *inode) vi->z_algorithmtype[1] = h->h_algorithmtype >> 4; if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX) { - errln("unknown compression format %u for nid %llu, please upgrade kernel", - vi->z_algorithmtype[0], vi->nid); + erofs_err(sb, "unknown compression format %u for nid %llu, please upgrade kernel", + vi->z_algorithmtype[0], vi->nid); err = -EOPNOTSUPP; goto unmap_done; } @@ -75,8 +75,8 @@ static int fill_inode_lazy(struct inode *inode) ((h->h_clusterbits >> 3) & 3); if (vi->z_physical_clusterbits[0] != LOG_BLOCK_SIZE) { - errln("unsupported physical clusterbits %u for nid %llu, please upgrade kernel", - vi->z_physical_clusterbits[0], vi->nid); + erofs_err(sb, "unsupported physical clusterbits %u for nid %llu, please upgrade kernel", + vi->z_physical_clusterbits[0], vi->nid); err = -EOPNOTSUPP; goto unmap_done; } @@ -335,7 +335,8 @@ static int vle_extent_lookback(struct z_erofs_maprecorder *m, int err; if (lcn < lookback_distance) { - errln("bogus lookback distance @ nid %llu", vi->nid); + erofs_err(m->inode->i_sb, + "bogus lookback distance @ nid %llu", vi->nid); DBG_BUGON(1); return -EFSCORRUPTED; } @@ -349,8 +350,9 @@ static int vle_extent_lookback(struct z_erofs_maprecorder *m, switch (m->type) { case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: if (!m->delta[0]) { - errln("invalid lookback distance 0 at nid %llu", - vi->nid); + erofs_err(m->inode->i_sb, + "invalid lookback distance 0 @ nid %llu", + vi->nid); DBG_BUGON(1); return -EFSCORRUPTED; } @@ -362,8 +364,9 @@ static int vle_extent_lookback(struct z_erofs_maprecorder *m, map->m_la = (lcn << lclusterbits) | m->clusterofs; break; default: - errln("unknown type %u at lcn %lu of nid %llu", - m->type, lcn, vi->nid); + erofs_err(m->inode->i_sb, + "unknown type %u @ lcn %lu of nid %llu", + m->type, lcn, vi->nid); DBG_BUGON(1); return -EOPNOTSUPP; } @@ -421,8 +424,9 @@ int z_erofs_map_blocks_iter(struct inode *inode, } /* m.lcn should be >= 1 if endoff < m.clusterofs */ if (!m.lcn) { - errln("invalid logical cluster 0 at nid %llu", - vi->nid); + erofs_err(inode->i_sb, + "invalid logical cluster 0 at nid %llu", + vi->nid); err = -EFSCORRUPTED; goto unmap_out; } @@ -437,8 +441,9 @@ int z_erofs_map_blocks_iter(struct inode *inode, goto unmap_out; break; default: - errln("unknown type %u at offset %llu of nid %llu", - m.type, ofs, vi->nid); + erofs_err(inode->i_sb, + "unknown type %u @ offset %llu of nid %llu", + m.type, ofs, vi->nid); err = -EOPNOTSUPP; goto unmap_out; } @@ -453,9 +458,9 @@ int z_erofs_map_blocks_iter(struct inode *inode, kunmap_atomic(m.kaddr); out: - debugln("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o", - __func__, map->m_la, map->m_pa, - map->m_llen, map->m_plen, map->m_flags); + erofs_dbg("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o", + __func__, map->m_la, map->m_pa, + map->m_llen, map->m_plen, map->m_flags); trace_z_erofs_map_blocks_iter_exit(inode, map, flags, err); From patchwork Wed Sep 4 02:09:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129167 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD3361399 for ; Wed, 4 Sep 2019 02:10:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C786222CF8 for ; Wed, 4 Sep 2019 02:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728045AbfIDCKm (ORCPT ); Tue, 3 Sep 2019 22:10:42 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5744 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728023AbfIDCKl (ORCPT ); Tue, 3 Sep 2019 22:10:41 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id BCE90E5B70EC5FF3B70F; Wed, 4 Sep 2019 10:10:40 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:31 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 23/25] erofs: use read_mapping_page instead of sb_bread Date: Wed, 4 Sep 2019 10:09:10 +0800 Message-ID: <20190904020912.63925-24-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said [1], "This seems to be your only direct use of buffer heads, which while not deprecated are a bit of an ugly step child. So if you can easily avoid creating a buffer_head dependency in a new filesystem I think you should avoid it. " [1] https://lore.kernel.org/r/20190902125109.GA9826@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/super.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 1d9880195ef0..caf9a95173b0 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -98,20 +98,22 @@ static bool check_layout_compatibility(struct super_block *sb, static int erofs_read_superblock(struct super_block *sb) { struct erofs_sb_info *sbi; - struct buffer_head *bh; + struct page *page; struct erofs_super_block *dsb; unsigned int blkszbits; + void *data; int ret; - bh = sb_bread(sb, 0); - - if (!bh) { + page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL); + if (!page) { erofs_err(sb, "cannot read erofs superblock"); return -EIO; } sbi = EROFS_SB(sb); - dsb = (struct erofs_super_block *)(bh->b_data + EROFS_SUPER_OFFSET); + + data = kmap_atomic(page); + dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET); ret = -EINVAL; if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) { @@ -153,7 +155,8 @@ static int erofs_read_superblock(struct super_block *sb) } ret = 0; out: - brelse(bh); + kunmap_atomic(data); + put_page(page); return ret; } From patchwork Wed Sep 4 02:09:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129163 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 195641399 for ; Wed, 4 Sep 2019 02:10:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 032C72339D for ; Wed, 4 Sep 2019 02:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728031AbfIDCKm (ORCPT ); Tue, 3 Sep 2019 22:10:42 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5741 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728006AbfIDCKl (ORCPT ); Tue, 3 Sep 2019 22:10:41 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id AAD3C2CB4D783838F6DE; Wed, 4 Sep 2019 10:10:40 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:32 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 24/25] erofs: always use iget5_locked Date: Wed, 4 Sep 2019 10:09:11 +0800 Message-ID: <20190904020912.63925-25-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said [1] [2], "Just use the slightly more complicated 32-bit version everywhere so that you have a single actually tested code path. And then remove this helper. " [1] https://lore.kernel.org/r/20190829102426.GE20598@infradead.org/ [2] https://lore.kernel.org/r/20190902125320.GA16726@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/inode.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index a0cec3c754cd..3350ab65d892 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -243,7 +243,6 @@ static int erofs_fill_inode(struct inode *inode, int isdir) * erofs nid is 64bits, but i_ino is 'unsigned long', therefore * we should do more for 32-bit platform to find the right inode. */ -#if BITS_PER_LONG == 32 static int erofs_ilookup_test_actor(struct inode *inode, void *opaque) { const erofs_nid_t nid = *(erofs_nid_t *)opaque; @@ -258,20 +257,14 @@ static int erofs_iget_set_actor(struct inode *inode, void *opaque) inode->i_ino = erofs_inode_hash(nid); return 0; } -#endif static inline struct inode *erofs_iget_locked(struct super_block *sb, erofs_nid_t nid) { const unsigned long hashval = erofs_inode_hash(nid); -#if BITS_PER_LONG >= 64 - /* it is safe to use iget_locked for >= 64-bit platform */ - return iget_locked(sb, hashval); -#else return iget5_locked(sb, hashval, erofs_ilookup_test_actor, erofs_iget_set_actor, &nid); -#endif } struct inode *erofs_iget(struct super_block *sb, From patchwork Wed Sep 4 02:09:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11129169 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 506A718A6 for ; Wed, 4 Sep 2019 02:10:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3AD722339E for ; Wed, 4 Sep 2019 02:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728042AbfIDCKm (ORCPT ); Tue, 3 Sep 2019 22:10:42 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5742 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728021AbfIDCKl (ORCPT ); Tue, 3 Sep 2019 22:10:41 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id B042EC183FF5ADEC2FEC; Wed, 4 Sep 2019 10:10:40 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 4 Sep 2019 10:10:33 +0800 From: Gao Xiang To: Chao Yu , Greg Kroah-Hartman , Christoph Hellwig , CC: , , Chao Yu , Miao Xie , Gao Xiang Subject: [PATCH v2 25/25] erofs: use read_cache_page_gfp for erofs_get_meta_page Date: Wed, 4 Sep 2019 10:09:12 +0800 Message-ID: <20190904020912.63925-26-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904020912.63925-1-gaoxiang25@huawei.com> References: <20190901055130.30572-1-hsiangkao@aol.com> <20190904020912.63925-1-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As Christoph said [1], "I'd much prefer to just use read_cache_page_gfp, and live with the fact that this allocates bufferheads behind you for now. I'll try to speed up my attempts to get rid of the buffer heads on the block device mapping instead. " This simplifies the code a lot and a minor thing is "no REQ_META (e.g. for blktrace) on metadata at all..." [1] https://lore.kernel.org/r/20190903153704.GA2201@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/data.c | 70 +++++++------------------------------------------ 1 file changed, 9 insertions(+), 61 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index eb7bbae89ed0..8a9fcbd0e8ac 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -32,71 +32,13 @@ static void erofs_readendio(struct bio *bio) bio_put(bio); } -static struct bio *erofs_grab_raw_bio(struct super_block *sb, - erofs_blk_t blkaddr, - unsigned int nr_pages, - bool ismeta) -{ - struct bio *bio = bio_alloc(GFP_NOIO, nr_pages); - - bio->bi_end_io = erofs_readendio; - bio_set_dev(bio, sb->s_bdev); - bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK; - if (ismeta) - bio->bi_opf = REQ_OP_READ | REQ_META; - else - bio->bi_opf = REQ_OP_READ; - - return bio; -} - struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr) { struct inode *const bd_inode = sb->s_bdev->bd_inode; struct address_space *const mapping = bd_inode->i_mapping; - const gfp_t gfp = mapping_gfp_constraint(mapping, ~__GFP_FS); - struct page *page; - int err; - -repeat: - page = find_or_create_page(mapping, blkaddr, gfp); - if (!page) - return ERR_PTR(-ENOMEM); - - DBG_BUGON(!PageLocked(page)); - - if (!PageUptodate(page)) { - struct bio *bio; - - bio = erofs_grab_raw_bio(sb, blkaddr, 1, true); - - if (bio_add_page(bio, page, PAGE_SIZE, 0) != PAGE_SIZE) { - err = -EFAULT; - goto err_out; - } - - submit_bio(bio); - lock_page(page); - /* this page has been truncated by others */ - if (page->mapping != mapping) { - unlock_page(page); - put_page(page); - goto repeat; - } - - /* more likely a read error */ - if (!PageUptodate(page)) { - err = -EIO; - goto err_out; - } - } - return page; - -err_out: - unlock_page(page); - put_page(page); - return ERR_PTR(err); + return read_cache_page_gfp(mapping, blkaddr, + mapping_gfp_constraint(mapping, ~__GFP_FS)); } static int erofs_map_blocks_flatmode(struct inode *inode, @@ -272,7 +214,13 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, if (nblocks > BIO_MAX_PAGES) nblocks = BIO_MAX_PAGES; - bio = erofs_grab_raw_bio(sb, blknr, nblocks, false); + bio = bio_alloc(GFP_NOIO, nblocks); + + bio->bi_end_io = erofs_readendio; + bio_set_dev(bio, sb->s_bdev); + bio->bi_iter.bi_sector = (sector_t)blknr << + LOG_SECTORS_PER_BLOCK; + bio->bi_opf = REQ_OP_READ; } err = bio_add_page(bio, page, PAGE_SIZE, 0);