From patchwork Mon Apr 19 08:27:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12211097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC514C43460 for ; Mon, 19 Apr 2021 08:28:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8BA761159 for ; Mon, 19 Apr 2021 08:28:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229790AbhDSI2m (ORCPT ); Mon, 19 Apr 2021 04:28:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235023AbhDSI2l (ORCPT ); Mon, 19 Apr 2021 04:28:41 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2735FC061760 for ; Mon, 19 Apr 2021 01:28:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=K3RppyekugL1PaMFujNwLOEUJzJd6NyyQgLRyTzaotY=; b=dgRTF7bk2MgDczbZ5wgJG5T+gy V04C5hSGhsUpFvVxFkunFXnY/L6YySDGRv+PnyrkFYuBn9kFrWJY8H6kQrWnCzSFD7PQi/h8qdbJ+ /Nlkd+NhXwJQEAp2vXEzPMFA7MaReMkDZQLI58zogsxfWa5LWRXapiKpVOH1CouvDq1TB8KX87bNS 5YyjQ424Y0Fbw+5BQFPSoB6+yehIQpPezwcQFpy5rYs3AuyW2xPSM0zI79DEtxKELtm8ruM9ZqWdz G6h3y2rSdfx51hxIQ8GjlMTual1tccofwg6Zz7gH0dHzvtq/v+QbXbJAVrkMgz6sydooR8xulecpo 4+/DFZxQ==; Received: from [2001:4bb8:19b:f845:9ac9:3ef5:afc7:c325] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lYPGM-00BBdE-DW; Mon, 19 Apr 2021 08:28:10 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: "Gustavo A . R . Silva" Subject: [PATCH 1/7] xfs: remove the EFD size asserts in xlog_recover_efd_commit_pass2 Date: Mon, 19 Apr 2021 10:27:58 +0200 Message-Id: <20210419082804.2076124-2-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210419082804.2076124-1-hch@lst.de> References: <20210419082804.2076124-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org We never actually look at the extent array in the efd items, and should eventually stop writing them out at all when it is time for a incompat log change. Ѕo don't bother with the asserts at all, and thus with the the structures defined just to be used with it. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_log_format.h | 20 ++------------------ fs/xfs/xfs_extfree_item.c | 10 ++-------- fs/xfs/xfs_extfree_item.h | 2 +- fs/xfs/xfs_ondisk.h | 2 -- 4 files changed, 5 insertions(+), 29 deletions(-) diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index 8bd00da6d2a40f..ea0fe9f121adff 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -598,29 +598,13 @@ typedef struct xfs_efi_log_format_64 { * log. The efd_extents array is a variable size array whose * size is given by efd_nextents; */ -typedef struct xfs_efd_log_format { +struct xfs_efd_log_format { uint16_t efd_type; /* efd log item type */ uint16_t efd_size; /* size of this item */ uint32_t efd_nextents; /* # of extents freed */ uint64_t efd_efi_id; /* id of corresponding efi */ xfs_extent_t efd_extents[1]; /* array of extents freed */ -} xfs_efd_log_format_t; - -typedef struct xfs_efd_log_format_32 { - uint16_t efd_type; /* efd log item type */ - uint16_t efd_size; /* size of this item */ - uint32_t efd_nextents; /* # of extents freed */ - uint64_t efd_efi_id; /* id of corresponding efi */ - xfs_extent_32_t efd_extents[1]; /* array of extents freed */ -} __attribute__((packed)) xfs_efd_log_format_32_t; - -typedef struct xfs_efd_log_format_64 { - uint16_t efd_type; /* efd log item type */ - uint16_t efd_size; /* size of this item */ - uint32_t efd_nextents; /* # of extents freed */ - uint64_t efd_efi_id; /* id of corresponding efi */ - xfs_extent_64_t efd_extents[1]; /* array of extents freed */ -} xfs_efd_log_format_64_t; +}; /* * RUI/RUD (reverse mapping) log format definitions diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c index 93223ebb33721e..ac17fdb9283489 100644 --- a/fs/xfs/xfs_extfree_item.c +++ b/fs/xfs/xfs_extfree_item.c @@ -253,7 +253,7 @@ static inline int xfs_efd_item_sizeof( struct xfs_efd_log_item *efdp) { - return sizeof(xfs_efd_log_format_t) + + return sizeof(struct xfs_efd_log_format) + (efdp->efd_format.efd_nextents - 1) * sizeof(xfs_extent_t); } @@ -743,13 +743,7 @@ xlog_recover_efd_commit_pass2( struct xlog_recover_item *item, xfs_lsn_t lsn) { - struct xfs_efd_log_format *efd_formatp; - - efd_formatp = item->ri_buf[0].i_addr; - ASSERT((item->ri_buf[0].i_len == (sizeof(xfs_efd_log_format_32_t) + - ((efd_formatp->efd_nextents - 1) * sizeof(xfs_extent_32_t)))) || - (item->ri_buf[0].i_len == (sizeof(xfs_efd_log_format_64_t) + - ((efd_formatp->efd_nextents - 1) * sizeof(xfs_extent_64_t))))); + struct xfs_efd_log_format *efd_formatp = item->ri_buf[0].i_addr; xlog_recover_release_intent(log, XFS_LI_EFI, efd_formatp->efd_efi_id); return 0; diff --git a/fs/xfs/xfs_extfree_item.h b/fs/xfs/xfs_extfree_item.h index cd2860c875bf50..6b80452ad2a71b 100644 --- a/fs/xfs/xfs_extfree_item.h +++ b/fs/xfs/xfs_extfree_item.h @@ -61,7 +61,7 @@ struct xfs_efd_log_item { struct xfs_log_item efd_item; struct xfs_efi_log_item *efd_efip; uint efd_next_extent; - xfs_efd_log_format_t efd_format; + struct xfs_efd_log_format efd_format; }; /* diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h index 0aa87c2101049c..7328ff92e0ee8a 100644 --- a/fs/xfs/xfs_ondisk.h +++ b/fs/xfs/xfs_ondisk.h @@ -118,8 +118,6 @@ xfs_check_ondisk_structs(void) /* log structures */ XFS_CHECK_STRUCT_SIZE(struct xfs_buf_log_format, 88); XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat, 24); - XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32, 28); - XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64, 32); XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32, 28); XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64, 32); XFS_CHECK_STRUCT_SIZE(struct xfs_extent_32, 12); From patchwork Mon Apr 19 08:27:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12211099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFFC2C43461 for ; Mon, 19 Apr 2021 08:28:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4F6E61057 for ; Mon, 19 Apr 2021 08:28:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237771AbhDSI2n (ORCPT ); Mon, 19 Apr 2021 04:28:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235023AbhDSI2n (ORCPT ); Mon, 19 Apr 2021 04:28:43 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF88C06174A for ; Mon, 19 Apr 2021 01:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=5T56Nr6MPd2UGGDNtbyHRwvTCWBWU3X5/fFgYkDmweE=; b=eGK6Tj8zsSCV4g5aFg8BhsLNev wey1hgcPx57Sh9x5hf8yojZGwKAJk2UgltaafTvs7/TyiYVHrHTAC0TdTSN4WNzXU6h29rnPT4BzL lt5eZ0jf+QQUGnJ/h3q8IY9mu8Wck6kvkox8qNLt0CKLJZ3M0ES6O5KyFyhBFu4+wm0Sy2GSR/0SN kZVm2P6G7UKMdjg9SE3gWoSFQHEekbjfYmbatvNEetIUIV1aUQKdTwWEifmOqD5wnQpsfuruEA//G tKAyePDn+Virg8xJngR9ARbHrnhIoSZJN+sGCf5Teoutx8eHKMnd5qaOSs831klRXKtT+B4rVZLx1 /LQ4QFGw==; Received: from [2001:4bb8:19b:f845:9ac9:3ef5:afc7:c325] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lYPGP-00BBdI-AJ; Mon, 19 Apr 2021 08:28:13 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: "Gustavo A . R . Silva" Subject: [PATCH 2/7] xfs: clean up the EFI and EFD log format handling Date: Mon, 19 Apr 2021 10:27:59 +0200 Message-Id: <20210419082804.2076124-3-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210419082804.2076124-1-hch@lst.de> References: <20210419082804.2076124-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The extent structure embedded into the EFI and EFD items was originally defined as a structure with implicit padding, which makes it a mess to handle between 32-bit and 64-bit kernels as the 32-bit ABI packs them tight, while the 64-bit ABI implicitly adds an implicit 4-bye padding. Log recovery has been able to deal with both formats for a long time, although in a rather messy way where the default definition varies between the ABIs, but log recovery has two extra special cases for padded or unpadded variants. Change this to always write the properly fully padded EFI and EFD structures to the log, and only special case the unpadded one during recovery. Signed-off-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_log_format.h | 49 ++++++-------- fs/xfs/xfs_extfree_item.c | 115 ++++++++++++++------------------- fs/xfs/xfs_extfree_item.h | 2 +- fs/xfs/xfs_ondisk.h | 5 +- 4 files changed, 71 insertions(+), 100 deletions(-) diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index ea0fe9f121adff..639035052b4f65 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -542,56 +542,43 @@ xfs_blft_from_flags(struct xfs_buf_log_format *blf) /* * EFI/EFD log format definitions */ -typedef struct xfs_extent { - xfs_fsblock_t ext_start; - xfs_extlen_t ext_len; -} xfs_extent_t; -/* - * Since an xfs_extent_t has types (start:64, len: 32) - * there are different alignments on 32 bit and 64 bit kernels. - * So we provide the different variants for use by a - * conversion routine. - */ -typedef struct xfs_extent_32 { - uint64_t ext_start; - uint32_t ext_len; -} __attribute__((packed)) xfs_extent_32_t; - -typedef struct xfs_extent_64 { +struct xfs_extent { uint64_t ext_start; uint32_t ext_len; uint32_t ext_pad; -} xfs_extent_64_t; +}; /* * This is the structure used to lay out an efi log item in the * log. The efi_extents field is a variable size array whose * size is given by efi_nextents. */ -typedef struct xfs_efi_log_format { +struct xfs_efi_log_format { uint16_t efi_type; /* efi log item type */ uint16_t efi_size; /* size of this item */ uint32_t efi_nextents; /* # extents to free */ uint64_t efi_id; /* efi identifier */ - xfs_extent_t efi_extents[1]; /* array of extents to free */ -} xfs_efi_log_format_t; + struct xfs_extent efi_extents[1]; /* array of extents to free */ +}; -typedef struct xfs_efi_log_format_32 { - uint16_t efi_type; /* efi log item type */ - uint16_t efi_size; /* size of this item */ - uint32_t efi_nextents; /* # extents to free */ - uint64_t efi_id; /* efi identifier */ - xfs_extent_32_t efi_extents[1]; /* array of extents to free */ -} __attribute__((packed)) xfs_efi_log_format_32_t; +/* + * Version of the xfs_extent and xfs_efi_log_format structures that do not + * contain padding. These used to be written to the log by older 32-bit kernels + * and will be dealt with transparently by log recovery. + */ +struct xfs_extent_32 { + uint64_t ext_start; + uint32_t ext_len; +} __attribute__((packed)); -typedef struct xfs_efi_log_format_64 { +struct xfs_efi_log_format_32 { uint16_t efi_type; /* efi log item type */ uint16_t efi_size; /* size of this item */ uint32_t efi_nextents; /* # extents to free */ uint64_t efi_id; /* efi identifier */ - xfs_extent_64_t efi_extents[1]; /* array of extents to free */ -} xfs_efi_log_format_64_t; + struct xfs_extent_32 efi_extents[1]; /* array of extents to free */ +} __attribute__((packed)); /* * This is the structure used to lay out an efd log item in the @@ -603,7 +590,7 @@ struct xfs_efd_log_format { uint16_t efd_size; /* size of this item */ uint32_t efd_nextents; /* # of extents freed */ uint64_t efd_efi_id; /* id of corresponding efi */ - xfs_extent_t efd_extents[1]; /* array of extents freed */ + struct xfs_extent efd_extents[1]; /* array of extents freed */ }; /* diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c index ac17fdb9283489..ed8d0790908ea7 100644 --- a/fs/xfs/xfs_extfree_item.c +++ b/fs/xfs/xfs_extfree_item.c @@ -74,7 +74,7 @@ xfs_efi_item_sizeof( struct xfs_efi_log_item *efip) { return sizeof(struct xfs_efi_log_format) + - (efip->efi_format.efi_nextents - 1) * sizeof(xfs_extent_t); + (efip->efi_format.efi_nextents - 1) * sizeof(struct xfs_extent); } STATIC void @@ -158,7 +158,7 @@ xfs_efi_init( ASSERT(nextents > 0); if (nextents > XFS_EFI_MAX_FAST_EXTENTS) { size = (uint)(sizeof(struct xfs_efi_log_item) + - ((nextents - 1) * sizeof(xfs_extent_t))); + ((nextents - 1) * sizeof(struct xfs_extent))); efip = kmem_zalloc(size, 0); } else { efip = kmem_cache_zalloc(xfs_efi_zone, @@ -174,61 +174,6 @@ xfs_efi_init( return efip; } -/* - * Copy an EFI format buffer from the given buf, and into the destination - * EFI format structure. - * The given buffer can be in 32 bit or 64 bit form (which has different padding), - * one of which will be the native format for this kernel. - * It will handle the conversion of formats if necessary. - */ -STATIC int -xfs_efi_copy_format(xfs_log_iovec_t *buf, xfs_efi_log_format_t *dst_efi_fmt) -{ - xfs_efi_log_format_t *src_efi_fmt = buf->i_addr; - uint i; - uint len = sizeof(xfs_efi_log_format_t) + - (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_t); - uint len32 = sizeof(xfs_efi_log_format_32_t) + - (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_32_t); - uint len64 = sizeof(xfs_efi_log_format_64_t) + - (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_64_t); - - if (buf->i_len == len) { - memcpy((char *)dst_efi_fmt, (char*)src_efi_fmt, len); - return 0; - } else if (buf->i_len == len32) { - xfs_efi_log_format_32_t *src_efi_fmt_32 = buf->i_addr; - - dst_efi_fmt->efi_type = src_efi_fmt_32->efi_type; - dst_efi_fmt->efi_size = src_efi_fmt_32->efi_size; - dst_efi_fmt->efi_nextents = src_efi_fmt_32->efi_nextents; - dst_efi_fmt->efi_id = src_efi_fmt_32->efi_id; - for (i = 0; i < dst_efi_fmt->efi_nextents; i++) { - dst_efi_fmt->efi_extents[i].ext_start = - src_efi_fmt_32->efi_extents[i].ext_start; - dst_efi_fmt->efi_extents[i].ext_len = - src_efi_fmt_32->efi_extents[i].ext_len; - } - return 0; - } else if (buf->i_len == len64) { - xfs_efi_log_format_64_t *src_efi_fmt_64 = buf->i_addr; - - dst_efi_fmt->efi_type = src_efi_fmt_64->efi_type; - dst_efi_fmt->efi_size = src_efi_fmt_64->efi_size; - dst_efi_fmt->efi_nextents = src_efi_fmt_64->efi_nextents; - dst_efi_fmt->efi_id = src_efi_fmt_64->efi_id; - for (i = 0; i < dst_efi_fmt->efi_nextents; i++) { - dst_efi_fmt->efi_extents[i].ext_start = - src_efi_fmt_64->efi_extents[i].ext_start; - dst_efi_fmt->efi_extents[i].ext_len = - src_efi_fmt_64->efi_extents[i].ext_len; - } - return 0; - } - XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL); - return -EFSCORRUPTED; -} - static inline struct xfs_efd_log_item *EFD_ITEM(struct xfs_log_item *lip) { return container_of(lip, struct xfs_efd_log_item, efd_item); @@ -254,7 +199,7 @@ xfs_efd_item_sizeof( struct xfs_efd_log_item *efdp) { return sizeof(struct xfs_efd_log_format) + - (efdp->efd_format.efd_nextents - 1) * sizeof(xfs_extent_t); + (efdp->efd_format.efd_nextents - 1) * sizeof(struct xfs_extent); } STATIC void @@ -687,6 +632,36 @@ static const struct xfs_item_ops xfs_efi_item_ops = { .iop_relog = xfs_efi_item_relog, }; +/* + * Convert from an unpadded EFI log item written by old 32-bit kernels to the + * proper format. + */ +static int +xfs_efi_copy_format_32( + struct xfs_efi_log_format *dst, + struct xfs_log_iovec *buf) +{ + struct xfs_efi_log_format_32 *src = buf->i_addr; + unsigned int i; + + if (buf->i_len != sizeof(*src) + + (src->efi_nextents - 1) * sizeof(struct xfs_extent_32)) { + XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL); + return -EFSCORRUPTED; + } + + dst->efi_type = src->efi_type; + dst->efi_size = src->efi_size; + dst->efi_nextents = src->efi_nextents; + dst->efi_id = src->efi_id; + for (i = 0; i < dst->efi_nextents; i++) { + dst->efi_extents[i].ext_start = src->efi_extents[i].ext_start; + dst->efi_extents[i].ext_len = src->efi_extents[i].ext_len; + } + + return 0; +} + /* * This routine is called to create an in-core extent free intent * item from the efi format structure which was logged on disk. @@ -703,18 +678,22 @@ xlog_recover_efi_commit_pass2( { struct xfs_mount *mp = log->l_mp; struct xfs_efi_log_item *efip; - struct xfs_efi_log_format *efi_formatp; + struct xfs_log_iovec *buf = &item->ri_buf[0]; + struct xfs_efi_log_format *src = buf->i_addr; int error; - efi_formatp = item->ri_buf[0].i_addr; + efip = xfs_efi_init(mp, src->efi_nextents); - efip = xfs_efi_init(mp, efi_formatp->efi_nextents); - error = xfs_efi_copy_format(&item->ri_buf[0], &efip->efi_format); - if (error) { - xfs_efi_item_free(efip); - return error; + if (buf->i_len != sizeof(*src) + + (src->efi_nextents - 1) * sizeof(struct xfs_extent)) { + error = xfs_efi_copy_format_32(&efip->efi_format, buf); + if (error) + goto out_free_efi; + } else { + memcpy(&efip->efi_format, src, buf->i_len); } - atomic_set(&efip->efi_next_extent, efi_formatp->efi_nextents); + + atomic_set(&efip->efi_next_extent, efip->efi_format.efi_nextents); /* * Insert the intent into the AIL directly and drop one reference so * that finishing or canceling the work will drop the other. @@ -722,6 +701,10 @@ xlog_recover_efi_commit_pass2( xfs_trans_ail_insert(log->l_ailp, &efip->efi_item, lsn); xfs_efi_release(efip); return 0; + +out_free_efi: + xfs_efi_item_free(efip); + return error; } const struct xlog_recover_item_ops xlog_efi_item_ops = { diff --git a/fs/xfs/xfs_extfree_item.h b/fs/xfs/xfs_extfree_item.h index 6b80452ad2a71b..e09afd0f63ff59 100644 --- a/fs/xfs/xfs_extfree_item.h +++ b/fs/xfs/xfs_extfree_item.h @@ -49,7 +49,7 @@ struct xfs_efi_log_item { struct xfs_log_item efi_item; atomic_t efi_refcount; atomic_t efi_next_extent; - xfs_efi_log_format_t efi_format; + struct xfs_efi_log_format efi_format; }; /* diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h index 7328ff92e0ee8a..739476f7dffa21 100644 --- a/fs/xfs/xfs_ondisk.h +++ b/fs/xfs/xfs_ondisk.h @@ -118,10 +118,11 @@ xfs_check_ondisk_structs(void) /* log structures */ XFS_CHECK_STRUCT_SIZE(struct xfs_buf_log_format, 88); XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat, 24); + XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format, 32); + XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format, 32); XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32, 28); - XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64, 32); + XFS_CHECK_STRUCT_SIZE(struct xfs_extent, 16); XFS_CHECK_STRUCT_SIZE(struct xfs_extent_32, 12); - XFS_CHECK_STRUCT_SIZE(struct xfs_extent_64, 16); XFS_CHECK_STRUCT_SIZE(struct xfs_log_dinode, 176); XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log, 28); XFS_CHECK_STRUCT_SIZE(xfs_ictimestamp_t, 8); From patchwork Mon Apr 19 08:28:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12211101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB66FC433B4 for ; Mon, 19 Apr 2021 08:28:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FF9B61151 for ; Mon, 19 Apr 2021 08:28:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235023AbhDSI2q (ORCPT ); Mon, 19 Apr 2021 04:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237793AbhDSI2p (ORCPT ); Mon, 19 Apr 2021 04:28:45 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA31AC06174A for ; Mon, 19 Apr 2021 01:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=FqBsQpEwwDFf47/L/QYdNz4FeQbApUMOflynF/ZTZuA=; b=e5d2ADtCoZKpjw7KkgYRc/N4nU XUSa2mov2S5MwUvJbvHtQnrPMF87NItz51YqJihyctwEkKaeDDN9cKwCWIXVzLRowHLHnagUIcdSA Xd2xXNm+m3O/hyRi/XkWkEG5XoNjyyVfvcw/fOobkfhQ1xELZSCdDfV65zVT7VwkutzTQJuDTq2vF 07cPjAk7sCa9g/nqU/MU+35s55CrlBo5kG5g9ulu3kW+3MuxebsqbEq8vSVk69C86VIEttBRPZgcH wPKDuWe4t4lV3J5UW+hhVwD8A4ON42Vmx37ELqjH8sUnsxbtfvuyxADCnpSGKUbe89VLA3vhjs3gS rzYUKBeg==; Received: from [2001:4bb8:19b:f845:9ac9:3ef5:afc7:c325] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lYPGR-00BBdh-Up; Mon, 19 Apr 2021 08:28:16 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: "Gustavo A . R . Silva" Subject: [PATCH 3/7] xfs: pass a xfs_efi_log_item to xfs_efi_item_sizeof Date: Mon, 19 Apr 2021 10:28:00 +0200 Message-Id: <20210419082804.2076124-4-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210419082804.2076124-1-hch@lst.de> References: <20210419082804.2076124-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org xfs_efi_log_item only looks at the embedded xfs_efi_log_item structure, so pass that directly and rename the function to xfs_efi_log_item_sizeof. This allows using the helper in xlog_recover_efi_commit_pass2 as well. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_extfree_item.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c index ed8d0790908ea7..7ae570d1944590 100644 --- a/fs/xfs/xfs_extfree_item.c +++ b/fs/xfs/xfs_extfree_item.c @@ -70,11 +70,11 @@ xfs_efi_release( * structure. */ static inline int -xfs_efi_item_sizeof( - struct xfs_efi_log_item *efip) +xfs_efi_log_item_sizeof( + struct xfs_efi_log_format *elf) { - return sizeof(struct xfs_efi_log_format) + - (efip->efi_format.efi_nextents - 1) * sizeof(struct xfs_extent); + return sizeof(*elf) + + (elf->efi_nextents - 1) * sizeof(struct xfs_extent); } STATIC void @@ -84,7 +84,7 @@ xfs_efi_item_size( int *nbytes) { *nvecs += 1; - *nbytes += xfs_efi_item_sizeof(EFI_ITEM(lip)); + *nbytes += xfs_efi_log_item_sizeof(&EFI_ITEM(lip)->efi_format); } /* @@ -110,7 +110,7 @@ xfs_efi_item_format( xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_EFI_FORMAT, &efip->efi_format, - xfs_efi_item_sizeof(efip)); + xfs_efi_log_item_sizeof(&efip->efi_format)); } @@ -684,8 +684,7 @@ xlog_recover_efi_commit_pass2( efip = xfs_efi_init(mp, src->efi_nextents); - if (buf->i_len != sizeof(*src) + - (src->efi_nextents - 1) * sizeof(struct xfs_extent)) { + if (buf->i_len != xfs_efi_log_item_sizeof(src)) { error = xfs_efi_copy_format_32(&efip->efi_format, buf); if (error) goto out_free_efi; From patchwork Mon Apr 19 08:28:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12211103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40331C433B4 for ; Mon, 19 Apr 2021 08:28:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2675B61151 for ; Mon, 19 Apr 2021 08:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237785AbhDSI2s (ORCPT ); Mon, 19 Apr 2021 04:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237793AbhDSI2s (ORCPT ); Mon, 19 Apr 2021 04:28:48 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E793C06174A for ; Mon, 19 Apr 2021 01:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=EGIuZQS8nFxsan/Q4gwJB7xZ3TnCUbgtHaX+RaxuL6U=; b=eRlxYKJ8RksPwdNon1l6lHQth/ HIuZRTTsVPxrmlEQLn+P5GrgdGQdpm2RjmYip3pa5oy50oZrdHxGhzhcvE40srFs9ELiuBT+xumFK utYDZk4HfWBWp/BSI+l2g1p4JSBtLZfJ/nyLIBTk+8HS43AekRJb6zhYmjT2xwzw9MYw2MRR/hSpr JcUfNFVyJ5JwJTC8qiY5vTv61r+/AwbgbEWMLrcEW+Ssl3WweNT6CzuvkRjXOuLsJOL74e34tv8yI 0owvLSplYIx+wpd/1a3wzYray4ssYVHo2vs3ABb54mxKbgTtXcdqdjCuAuEH+THDGSCM4nEQJKS1s 7XqbgNQQ==; Received: from [2001:4bb8:19b:f845:9ac9:3ef5:afc7:c325] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lYPGU-00BBeY-HO; Mon, 19 Apr 2021 08:28:18 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: "Gustavo A . R . Silva" Subject: [PATCH 4/7] xfs: pass a xfs_efd_log_item to xfs_efd_item_sizeof Date: Mon, 19 Apr 2021 10:28:01 +0200 Message-Id: <20210419082804.2076124-5-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210419082804.2076124-1-hch@lst.de> References: <20210419082804.2076124-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org xfs_efd_log_item only looks at the embedded xfs_efd_log_item structure, so pass that directly and rename the function to xfs_efd_log_item_sizeof. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_extfree_item.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c index 7ae570d1944590..f15d6cfca6e2f1 100644 --- a/fs/xfs/xfs_extfree_item.c +++ b/fs/xfs/xfs_extfree_item.c @@ -195,11 +195,11 @@ xfs_efd_item_free(struct xfs_efd_log_item *efdp) * structure. */ static inline int -xfs_efd_item_sizeof( - struct xfs_efd_log_item *efdp) +xfs_efd_log_item_sizeof( + struct xfs_efd_log_format *elf) { return sizeof(struct xfs_efd_log_format) + - (efdp->efd_format.efd_nextents - 1) * sizeof(struct xfs_extent); + (elf->efd_nextents - 1) * sizeof(struct xfs_extent); } STATIC void @@ -209,7 +209,7 @@ xfs_efd_item_size( int *nbytes) { *nvecs += 1; - *nbytes += xfs_efd_item_sizeof(EFD_ITEM(lip)); + *nbytes += xfs_efd_log_item_sizeof(&EFD_ITEM(lip)->efd_format); } /* @@ -234,7 +234,7 @@ xfs_efd_item_format( xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_EFD_FORMAT, &efdp->efd_format, - xfs_efd_item_sizeof(efdp)); + xfs_efd_log_item_sizeof(&efdp->efd_format)); } /* From patchwork Mon Apr 19 08:28:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12211105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57F18C433ED for ; Mon, 19 Apr 2021 08:28:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3BA6D61151 for ; Mon, 19 Apr 2021 08:28:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237800AbhDSI2v (ORCPT ); Mon, 19 Apr 2021 04:28:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237793AbhDSI2v (ORCPT ); Mon, 19 Apr 2021 04:28:51 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0956C06174A for ; Mon, 19 Apr 2021 01:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=2NZEJPx3bmWJdRbgGXznjR5yFVm7sffKVztDkWG5Zq8=; b=jNbNdiGM1SyK2VaRGsyv47B6wU zHiYmYBLtgCovYqsUKeXD32k0W+BTeNsUqntpAMh8yUq8c14TZEhTZjKt5ZuEoPmEJkoL8FVlQ797 6jwqarZHMXooDe6p48/MqbnrAMELBUfqQnE4cIz91EQURQul1z5mtqNPDcqBlUeRHsZpWsAsyEx6m f4MqCJUABGZci2cqW0Hhk82FujY8+YalYsho27GoxTv8huSyHU/ylJ93APxTNGi4ICtbOQccE3cuZ nk1bqoBWGAADGmsaNoa8mYxhki21YQJ4gRMl48VM56UQYaqnDznhNIGRoFFsPJNlJBA3h3/rlUvaZ AGqdYn9g==; Received: from [2001:4bb8:19b:f845:9ac9:3ef5:afc7:c325] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lYPGX-00BBeg-4C; Mon, 19 Apr 2021 08:28:21 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: "Gustavo A . R . Silva" Subject: [PATCH 5/7] xfs: add a xfs_efi_item_sizeof helper Date: Mon, 19 Apr 2021 10:28:02 +0200 Message-Id: <20210419082804.2076124-6-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210419082804.2076124-1-hch@lst.de> References: <20210419082804.2076124-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Add a helper to calculate the size of an xfs_efi_log_item structure the specified number of extents. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_extfree_item.c | 10 +++------- fs/xfs/xfs_extfree_item.h | 6 ++++++ fs/xfs/xfs_super.c | 6 ++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c index f15d6cfca6e2f1..afd568d426c1f1 100644 --- a/fs/xfs/xfs_extfree_item.c +++ b/fs/xfs/xfs_extfree_item.c @@ -153,17 +153,13 @@ xfs_efi_init( { struct xfs_efi_log_item *efip; - uint size; ASSERT(nextents > 0); - if (nextents > XFS_EFI_MAX_FAST_EXTENTS) { - size = (uint)(sizeof(struct xfs_efi_log_item) + - ((nextents - 1) * sizeof(struct xfs_extent))); - efip = kmem_zalloc(size, 0); - } else { + if (nextents > XFS_EFI_MAX_FAST_EXTENTS) + efip = kmem_zalloc(xfs_efi_item_sizeof(nextents), 0); + else efip = kmem_cache_zalloc(xfs_efi_zone, GFP_KERNEL | __GFP_NOFAIL); - } xfs_log_item_init(mp, &efip->efi_item, XFS_LI_EFI, &xfs_efi_item_ops); efip->efi_format.efi_nextents = nextents; diff --git a/fs/xfs/xfs_extfree_item.h b/fs/xfs/xfs_extfree_item.h index e09afd0f63ff59..d2577d872de771 100644 --- a/fs/xfs/xfs_extfree_item.h +++ b/fs/xfs/xfs_extfree_item.h @@ -52,6 +52,12 @@ struct xfs_efi_log_item { struct xfs_efi_log_format efi_format; }; +static inline int xfs_efi_item_sizeof(unsigned int nextents) +{ + return sizeof(struct xfs_efi_log_item) + + (nextents - 1) * sizeof(struct xfs_extent); +} + /* * This is the "extent free done" log item. It is used to log * the fact that some extents earlier mentioned in an efi item diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index a2dab05332ac27..c93710cb5ce3f0 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1961,10 +1961,8 @@ xfs_init_zones(void) goto out_destroy_buf_item_zone; xfs_efi_zone = kmem_cache_create("xfs_efi_item", - (sizeof(struct xfs_efi_log_item) + - (XFS_EFI_MAX_FAST_EXTENTS - 1) * - sizeof(struct xfs_extent)), - 0, 0, NULL); + xfs_efi_item_sizeof(XFS_EFI_MAX_FAST_EXTENTS), + 0, 0, NULL); if (!xfs_efi_zone) goto out_destroy_efd_zone; From patchwork Mon Apr 19 08:28:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12211107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD1D1C433ED for ; Mon, 19 Apr 2021 08:28:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A679C61029 for ; Mon, 19 Apr 2021 08:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237802AbhDSI24 (ORCPT ); Mon, 19 Apr 2021 04:28:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237833AbhDSI2x (ORCPT ); Mon, 19 Apr 2021 04:28:53 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FB63C06174A for ; Mon, 19 Apr 2021 01:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=1MI0tpVG789FEab3cKjSBzY65/U/udZVHktMUqz17X4=; b=SYC1UIkulyJnUaJ7phzo7vOaYk C9SMzchanJopHjK1iW86WSJ6BqfV+qMu+lr0rZSoAeGMtTmBcc1HEJDEeXQw77EisA1yNMbA1HZRJ RQoFyy0yjZvEWPDoqJrXOzRVGAs5xYWAUA8O6eUW4R6Mj1hOlA1GDJR76rEoKoYOHrHrn9ehnAyU/ aiq+uYuUdo7qqAY3mLQwhHX6CrV5nfKPgnQfHwyhNijW/t+PtokcmjKvz69zA0mWFi8DjJOQC/Ty6 FB/ih1blU6Sx0/c1i6a6qVt/3/MBnXAweVB9I6JUKUdhKpmLTUNhU4V3YNjQZhLejoB70MKZcCPIE Ztv+B5jQ==; Received: from [2001:4bb8:19b:f845:9ac9:3ef5:afc7:c325] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lYPGZ-00BBem-Ld; Mon, 19 Apr 2021 08:28:24 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: "Gustavo A . R . Silva" Subject: [PATCH 6/7] xfs: add a xfs_efd_item_sizeof helper Date: Mon, 19 Apr 2021 10:28:03 +0200 Message-Id: <20210419082804.2076124-7-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210419082804.2076124-1-hch@lst.de> References: <20210419082804.2076124-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Add a helper to calculate the size of an xfs_efd_log_item structure the specified number of extents. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_extfree_item.c | 10 +++------- fs/xfs/xfs_extfree_item.h | 6 ++++++ fs/xfs/xfs_super.c | 6 ++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c index afd568d426c1f1..a2abdfd3d076bf 100644 --- a/fs/xfs/xfs_extfree_item.c +++ b/fs/xfs/xfs_extfree_item.c @@ -268,15 +268,11 @@ xfs_trans_get_efd( struct xfs_efd_log_item *efdp; ASSERT(nextents > 0); - - if (nextents > XFS_EFD_MAX_FAST_EXTENTS) { - efdp = kmem_zalloc(sizeof(struct xfs_efd_log_item) + - (nextents - 1) * sizeof(struct xfs_extent), - 0); - } else { + if (nextents > XFS_EFD_MAX_FAST_EXTENTS) + efdp = kmem_zalloc(xfs_efd_item_sizeof(nextents), 0); + else efdp = kmem_cache_zalloc(xfs_efd_zone, GFP_KERNEL | __GFP_NOFAIL); - } xfs_log_item_init(tp->t_mountp, &efdp->efd_item, XFS_LI_EFD, &xfs_efd_item_ops); diff --git a/fs/xfs/xfs_extfree_item.h b/fs/xfs/xfs_extfree_item.h index d2577d872de771..3bb62ef525f2e0 100644 --- a/fs/xfs/xfs_extfree_item.h +++ b/fs/xfs/xfs_extfree_item.h @@ -70,6 +70,12 @@ struct xfs_efd_log_item { struct xfs_efd_log_format efd_format; }; +static inline int xfs_efd_item_sizeof(unsigned int nextents) +{ + return sizeof(struct xfs_efd_log_item) + + (nextents - 1) * sizeof(struct xfs_extent); +} + /* * Max number of extents in fast allocation path. */ diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index c93710cb5ce3f0..f7f70438d98703 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1953,10 +1953,8 @@ xfs_init_zones(void) goto out_destroy_trans_zone; xfs_efd_zone = kmem_cache_create("xfs_efd_item", - (sizeof(struct xfs_efd_log_item) + - (XFS_EFD_MAX_FAST_EXTENTS - 1) * - sizeof(struct xfs_extent)), - 0, 0, NULL); + xfs_efd_item_sizeof(XFS_EFD_MAX_FAST_EXTENTS), + 0, 0, NULL); if (!xfs_efd_zone) goto out_destroy_buf_item_zone; From patchwork Mon Apr 19 08:28:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12211109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13761C433B4 for ; Mon, 19 Apr 2021 08:28:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE0C261185 for ; Mon, 19 Apr 2021 08:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237811AbhDSI24 (ORCPT ); Mon, 19 Apr 2021 04:28:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237570AbhDSI24 (ORCPT ); Mon, 19 Apr 2021 04:28:56 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1DEDC06174A for ; Mon, 19 Apr 2021 01:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=waW56BsVk68kwt+U2O/qRm3HCqG2X+jJpjmUvEiiONs=; b=IbK5EuPOFWkwMizgT+Ae2ISspe MJPwUqJ64F5uMFrXW5rXO2wzLPrae8j9OBzWPJeTYfOfdRWj4sCaw+FQ7OAuQFGD3YT0K1tPruUNW vOCn0+2MxJX2P06Jdkqb4AFXEr59rGsI6pAsY7z4aNCcujYmF8MKicFYIlBe8wtRm5asM3rTX5gcp G5kuthR6TOQjcfMTfyF+sY7qnC8uhKQ5+24kHzNnvUeEOW3gcANkMPeTpGkD0OCfR5I61GerBzalE WOxNgRMLZS83Z9eOuemcSgEBh31QrNj0z3Zp/8anVp5lCHB1MnIo+RYwa7P4tTzrH1s9yR6JMd71f RFN1HuDQ==; Received: from [2001:4bb8:19b:f845:9ac9:3ef5:afc7:c325] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lYPGc-00BBew-8A; Mon, 19 Apr 2021 08:28:26 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: "Gustavo A . R . Silva" Subject: [PATCH 7/7] xfs: Replace one-element arrays with flexible-array members Date: Mon, 19 Apr 2021 10:28:04 +0200 Message-Id: <20210419082804.2076124-8-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210419082804.2076124-1-hch@lst.de> References: <20210419082804.2076124-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: "Gustavo A. R. Silva" There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2]. Refactor the code according to the use of flexible-array members in multiple structures, instead of one-element arrays. Also, make use of the new struct_size() helper to properly calculate the size of some structures that contain flexible-array members. [1] https://en.wikipedia.org/wiki/Flexible_array_member [2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays Signed-off-by: Gustavo A. R. Silva [hch: rebased on top of the previous cleanups] Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Reviewed-by: Gustavo A. R. Silva --- fs/xfs/libxfs/xfs_log_format.h | 6 +++--- fs/xfs/xfs_extfree_item.c | 9 +++------ fs/xfs/xfs_extfree_item.h | 4 ++-- fs/xfs/xfs_ondisk.h | 6 +++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index 639035052b4f65..9b218c30659ad7 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -559,7 +559,7 @@ struct xfs_efi_log_format { uint16_t efi_size; /* size of this item */ uint32_t efi_nextents; /* # extents to free */ uint64_t efi_id; /* efi identifier */ - struct xfs_extent efi_extents[1]; /* array of extents to free */ + struct xfs_extent efi_extents[]; /* array of extents to free */ }; /* @@ -577,7 +577,7 @@ struct xfs_efi_log_format_32 { uint16_t efi_size; /* size of this item */ uint32_t efi_nextents; /* # extents to free */ uint64_t efi_id; /* efi identifier */ - struct xfs_extent_32 efi_extents[1]; /* array of extents to free */ + struct xfs_extent_32 efi_extents[]; /* array of extents to free */ } __attribute__((packed)); /* @@ -590,7 +590,7 @@ struct xfs_efd_log_format { uint16_t efd_size; /* size of this item */ uint32_t efd_nextents; /* # of extents freed */ uint64_t efd_efi_id; /* id of corresponding efi */ - struct xfs_extent efd_extents[1]; /* array of extents freed */ + struct xfs_extent efd_extents[]; /* array of extents freed */ }; /* diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c index a2abdfd3d076bf..8bea9c9ecf2042 100644 --- a/fs/xfs/xfs_extfree_item.c +++ b/fs/xfs/xfs_extfree_item.c @@ -73,8 +73,7 @@ static inline int xfs_efi_log_item_sizeof( struct xfs_efi_log_format *elf) { - return sizeof(*elf) + - (elf->efi_nextents - 1) * sizeof(struct xfs_extent); + return struct_size(elf, efi_extents, elf->efi_nextents); } STATIC void @@ -194,8 +193,7 @@ static inline int xfs_efd_log_item_sizeof( struct xfs_efd_log_format *elf) { - return sizeof(struct xfs_efd_log_format) + - (elf->efd_nextents - 1) * sizeof(struct xfs_extent); + return struct_size(elf, efd_extents, elf->efd_nextents); } STATIC void @@ -636,8 +634,7 @@ xfs_efi_copy_format_32( struct xfs_efi_log_format_32 *src = buf->i_addr; unsigned int i; - if (buf->i_len != sizeof(*src) + - (src->efi_nextents - 1) * sizeof(struct xfs_extent_32)) { + if (buf->i_len != struct_size(src, efi_extents, src->efi_nextents)) { XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL); return -EFSCORRUPTED; } diff --git a/fs/xfs/xfs_extfree_item.h b/fs/xfs/xfs_extfree_item.h index 3bb62ef525f2e0..a01ce86145bb64 100644 --- a/fs/xfs/xfs_extfree_item.h +++ b/fs/xfs/xfs_extfree_item.h @@ -55,7 +55,7 @@ struct xfs_efi_log_item { static inline int xfs_efi_item_sizeof(unsigned int nextents) { return sizeof(struct xfs_efi_log_item) + - (nextents - 1) * sizeof(struct xfs_extent); + nextents * sizeof(struct xfs_extent); } /* @@ -73,7 +73,7 @@ struct xfs_efd_log_item { static inline int xfs_efd_item_sizeof(unsigned int nextents) { return sizeof(struct xfs_efd_log_item) + - (nextents - 1) * sizeof(struct xfs_extent); + nextents * sizeof(struct xfs_extent); } /* diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h index 739476f7dffa21..fa4b590671bf58 100644 --- a/fs/xfs/xfs_ondisk.h +++ b/fs/xfs/xfs_ondisk.h @@ -118,9 +118,9 @@ xfs_check_ondisk_structs(void) /* log structures */ XFS_CHECK_STRUCT_SIZE(struct xfs_buf_log_format, 88); XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat, 24); - XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format, 32); - XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format, 32); - XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32, 28); + XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32, 16); XFS_CHECK_STRUCT_SIZE(struct xfs_extent, 16); XFS_CHECK_STRUCT_SIZE(struct xfs_extent_32, 12); XFS_CHECK_STRUCT_SIZE(struct xfs_log_dinode, 176);