From patchwork Mon Jan 11 13:22:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12010627 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 1CA22C433E0 for ; Mon, 11 Jan 2021 13:25:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DCA0D21919 for ; Mon, 11 Jan 2021 13:25:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730642AbhAKNZK (ORCPT ); Mon, 11 Jan 2021 08:25:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38380 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730718AbhAKNZJ (ORCPT ); Mon, 11 Jan 2021 08:25:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610371423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FizVXYcr2F+sihFxuiWdzCHXvCwM5WHSqlJvIw9kkQE=; b=ABxbcVGeuCrBcO3XtsrY3p2BX1yTHIQUxMclzBnbEhCO65y8hMqF0y0OlN/R+SqJaE/jf2 PVK2Db0DLgza9CEUlCieNOObxAVADoHZDqWOwYixe0koBqWs3ZYWGl2TVNwlBUX/2I6UC0 7yJIl6VtuoWCjqSb9ltpxiqRHPLFDxg= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-492-RNf2hqWgNBy2rNFW9Knu7A-1; Mon, 11 Jan 2021 08:23:41 -0500 X-MC-Unique: RNf2hqWgNBy2rNFW9Knu7A-1 Received: by mail-pl1-f200.google.com with SMTP id l11so9263162plt.2 for ; Mon, 11 Jan 2021 05:23:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FizVXYcr2F+sihFxuiWdzCHXvCwM5WHSqlJvIw9kkQE=; b=eR4YFMWz5MM+EeVgiCSQEN0jwbzghJ6apxzzPgO4HoMeDv6RWkkuK9+lYx6ltm+WK7 cqFxwQc7onTWh6ITrQLf65zTy7ues7sYO0QMx/98zgsc70SPQUgk9f0hPZF1H/X5RRox 6T5Ye6FYkLRNt7oNQBoVtc+1PTRaXYFbY8rI+MvnrLK3PzX6tQ/AwIsU6wFbqwrIhdO3 HS85lIGY/ADTYvOaUPCFyccMxeF2cju0Hf8c/pAfknx3UbEMkYM1zzCWBEDPGHFfw3LD o9FyvJ6+xA1UD2wz+ta39JtqrZeAkiEagBpB9HRVcuUhR6/6GuJwBZF9ho9tHtbTkaDc xEmw== X-Gm-Message-State: AOAM531l1p/Noe+UKFTOh2/EB1IuW666AQkojYQxI223P3l0fXRuVo0T lyMhQy8uEeTIU2RnScYvLn3Xt7B9qXxjR3sqi8UZTLSGdlMLvTR6tgkVRjWJSo6lAq7jf/ruZaF W9XXrk4MUIxegXGg+lycv4DP2/wU0DnmptPQ1mD+GtW+x4npWXRCGplbi8s6n7NCXs/xc1xmF+w == X-Received: by 2002:a63:a506:: with SMTP id n6mr11187023pgf.397.1610371420495; Mon, 11 Jan 2021 05:23:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdibuXD3UXgdwrTGORJRa54QKF3hwqlqYXvTn3HxZw+XRqImgKXsNSIn3JU2aIAqhAp/BElA== X-Received: by 2002:a63:a506:: with SMTP id n6mr11187000pgf.397.1610371420186; Mon, 11 Jan 2021 05:23:40 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id cu4sm16179355pjb.18.2021.01.11.05.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jan 2021 05:23:39 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Gao Xiang Subject: [PATCH v4 1/4] xfs: rename `new' to `delta' in xfs_growfs_data_private() Date: Mon, 11 Jan 2021 21:22:40 +0800 Message-Id: <20210111132243.1180013-2-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210111132243.1180013-1-hsiangkao@redhat.com> References: <20210111132243.1180013-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org It actually means the delta block count of growfs. Rename it in order to make it clear. Also introduce nb_div to avoid reusing `delta`. Signed-off-by: Gao Xiang Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_fsops.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 5870db855e8b..6ad31e6b4a04 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -32,8 +32,8 @@ xfs_growfs_data_private( int error; xfs_agnumber_t nagcount; xfs_agnumber_t nagimax = 0; - xfs_rfsblock_t nb, nb_mod; - xfs_rfsblock_t new; + xfs_rfsblock_t nb, nb_div, nb_mod; + xfs_rfsblock_t delta; xfs_agnumber_t oagcount; xfs_trans_t *tp; struct aghdr_init_data id = {}; @@ -50,16 +50,16 @@ xfs_growfs_data_private( return error; xfs_buf_relse(bp); - new = nb; /* use new as a temporary here */ - nb_mod = do_div(new, mp->m_sb.sb_agblocks); - nagcount = new + (nb_mod != 0); + nb_div = nb; + nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks); + nagcount = nb_div + (nb_mod != 0); if (nb_mod && nb_mod < XFS_MIN_AG_BLOCKS) { nagcount--; nb = (xfs_rfsblock_t)nagcount * mp->m_sb.sb_agblocks; if (nb < mp->m_sb.sb_dblocks) return -EINVAL; } - new = nb - mp->m_sb.sb_dblocks; + delta = nb - mp->m_sb.sb_dblocks; oagcount = mp->m_sb.sb_agcount; /* allocate the new per-ag structures */ @@ -89,7 +89,7 @@ xfs_growfs_data_private( INIT_LIST_HEAD(&id.buffer_list); for (id.agno = nagcount - 1; id.agno >= oagcount; - id.agno--, new -= id.agsize) { + id.agno--, delta -= id.agsize) { if (id.agno == nagcount - 1) id.agsize = nb - @@ -110,8 +110,8 @@ xfs_growfs_data_private( xfs_trans_agblocks_delta(tp, id.nfree); /* If there are new blocks in the old last AG, extend it. */ - if (new) { - error = xfs_ag_extend_space(mp, tp, &id, new); + if (delta) { + error = xfs_ag_extend_space(mp, tp, &id, delta); if (error) goto out_trans_cancel; } @@ -143,7 +143,7 @@ xfs_growfs_data_private( * If we expanded the last AG, free the per-AG reservation * so we can reinitialize it with the new size. */ - if (new) { + if (delta) { struct xfs_perag *pag; pag = xfs_perag_get(mp, id.agno); From patchwork Mon Jan 11 13:22:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12010629 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 6E2CDC433DB for ; Mon, 11 Jan 2021 13:25:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 417A121919 for ; Mon, 11 Jan 2021 13:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731150AbhAKNZR (ORCPT ); Mon, 11 Jan 2021 08:25:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55414 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730680AbhAKNZP (ORCPT ); Mon, 11 Jan 2021 08:25:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610371428; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PZvpmG5or3JBdwdJ/ieTMuoFTtfP6U9OT9Q2X/rBLzA=; b=HkpXqQWLoSJbiXLaDYLZfeMLNkFll7dMZR1jhmowJTor4aDs7utyOp2m29XJZ6wHfzAFno w8u4jEFU3TB3Yg8SR2ub9B+wgAUcn5Hqb8p0ae55s4AeTKIlC7XljvjmayP+t0xjg1llsC k7lLwUL2d9NtKpMekHR8UMtlr5x5Gs0= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-71-WZa_tJsnO2S2YIH3V2x2Uw-1; Mon, 11 Jan 2021 08:23:46 -0500 X-MC-Unique: WZa_tJsnO2S2YIH3V2x2Uw-1 Received: by mail-pl1-f198.google.com with SMTP id y5so9252298plr.19 for ; Mon, 11 Jan 2021 05:23:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PZvpmG5or3JBdwdJ/ieTMuoFTtfP6U9OT9Q2X/rBLzA=; b=m6Kf2qKiTCUKB32HSPHIisxhPKm6fhtUjV4gflVS+5D3P3pNUacoWTcg9jymPTzCc2 B4TP8KD9GBfYSoWa8uHh8ocnPeR76hLLtv7Kfg+xC0x84A2hNDNnAlF5aHVKgJXSNmQK 1cy5xGux++hBKd7yTjRVH/yAFqpBVEnYrdC0B529kKqv+eFwFpo3rH5R8kXyOfoj+fur pn//enwsCwlc0OyqKWhSTDH7MtI5epRprJgT5m6hme5evt2GQSrZKETztQdJB4+ReU6l Zn6QXmnTmQsCP+O1El0UatwEkkjfyYuK2UME10c2krTtdiPnifINekSKX+W2JwXIDjw8 tAig== X-Gm-Message-State: AOAM532tIegPU4IajOrd6UnNVVF4SBNajeAa6boVQhIqSNbJR39r3DJk +7yX86stq9X1fe8BtOpUGRNqgjE8nPVyfBW9axfbxgvFogsDHPJEgzPjsN635gctU0w4BEipJ3C FRMp7M9aKs2xhtpYun42ZiNc+lNd9+alTty89zqx4XnyFD9Si1Lcqkt3hatlfYVA23Ij1ShPdbg == X-Received: by 2002:a17:90b:228e:: with SMTP id kx14mr18483790pjb.210.1610371425187; Mon, 11 Jan 2021 05:23:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWqLcDXdUbGN0VMrqZ49vM3xGElXxfU5sZ/17wUke8gFbHvNDw/2akJ9J9FdkDdXFTcV1a6A== X-Received: by 2002:a17:90b:228e:: with SMTP id kx14mr18483760pjb.210.1610371424932; Mon, 11 Jan 2021 05:23:44 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id cu4sm16179355pjb.18.2021.01.11.05.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jan 2021 05:23:44 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Gao Xiang , Eric Sandeen Subject: [PATCH v4 2/4] xfs: get rid of xfs_growfs_{data,log}_t Date: Mon, 11 Jan 2021 21:22:41 +0800 Message-Id: <20210111132243.1180013-3-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210111132243.1180013-1-hsiangkao@redhat.com> References: <20210111132243.1180013-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Such usage isn't encouraged by the kernel coding style. Leave the definitions alone in case of userspace users. Reviewed-by: Darrick J. Wong Reviewed-by: Eric Sandeen Signed-off-by: Gao Xiang --- fs/xfs/xfs_fsops.c | 12 ++++++------ fs/xfs/xfs_fsops.h | 4 ++-- fs/xfs/xfs_ioctl.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 6ad31e6b4a04..0bc9c5ebd199 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -25,8 +25,8 @@ */ static int xfs_growfs_data_private( - xfs_mount_t *mp, /* mount point for filesystem */ - xfs_growfs_data_t *in) /* growfs data input struct */ + struct xfs_mount *mp, /* mount point for filesystem */ + struct xfs_growfs_data *in) /* growfs data input struct */ { struct xfs_buf *bp; int error; @@ -35,7 +35,7 @@ xfs_growfs_data_private( xfs_rfsblock_t nb, nb_div, nb_mod; xfs_rfsblock_t delta; xfs_agnumber_t oagcount; - xfs_trans_t *tp; + struct xfs_trans *tp; struct aghdr_init_data id = {}; nb = in->newblocks; @@ -170,8 +170,8 @@ xfs_growfs_data_private( static int xfs_growfs_log_private( - xfs_mount_t *mp, /* mount point for filesystem */ - xfs_growfs_log_t *in) /* growfs log input struct */ + struct xfs_mount *mp, /* mount point for filesystem */ + struct xfs_growfs_log *in) /* growfs log input struct */ { xfs_extlen_t nb; @@ -268,7 +268,7 @@ xfs_growfs_data( int xfs_growfs_log( xfs_mount_t *mp, - xfs_growfs_log_t *in) + struct xfs_growfs_log *in) { int error; diff --git a/fs/xfs/xfs_fsops.h b/fs/xfs/xfs_fsops.h index 92869f6ec8d3..2cffe51a31e8 100644 --- a/fs/xfs/xfs_fsops.h +++ b/fs/xfs/xfs_fsops.h @@ -6,8 +6,8 @@ #ifndef __XFS_FSOPS_H__ #define __XFS_FSOPS_H__ -extern int xfs_growfs_data(xfs_mount_t *mp, xfs_growfs_data_t *in); -extern int xfs_growfs_log(xfs_mount_t *mp, xfs_growfs_log_t *in); +extern int xfs_growfs_data(struct xfs_mount *mp, struct xfs_growfs_data *in); +extern int xfs_growfs_log(struct xfs_mount *mp, struct xfs_growfs_log *in); extern void xfs_fs_counts(xfs_mount_t *mp, xfs_fsop_counts_t *cnt); extern int xfs_reserve_blocks(xfs_mount_t *mp, uint64_t *inval, xfs_fsop_resblks_t *outval); diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 3fbd98f61ea5..a62520f49ec5 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -2260,7 +2260,7 @@ xfs_file_ioctl( } case XFS_IOC_FSGROWFSDATA: { - xfs_growfs_data_t in; + struct xfs_growfs_data in; if (copy_from_user(&in, arg, sizeof(in))) return -EFAULT; @@ -2274,7 +2274,7 @@ xfs_file_ioctl( } case XFS_IOC_FSGROWFSLOG: { - xfs_growfs_log_t in; + struct xfs_growfs_log in; if (copy_from_user(&in, arg, sizeof(in))) return -EFAULT; From patchwork Mon Jan 11 13:22:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12010631 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 9D478C433E9 for ; Mon, 11 Jan 2021 13:25:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77DC621919 for ; Mon, 11 Jan 2021 13:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730007AbhAKNZX (ORCPT ); Mon, 11 Jan 2021 08:25:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59849 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731175AbhAKNZT (ORCPT ); Mon, 11 Jan 2021 08:25:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610371432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ojFT1PhIb+FaXuvRr1SxUCplyTRyIPBcMEzZQECx4RA=; b=gPM11U2O4d6Yy0fCeNgCJODTM9v1mUjH4rY32cxPglj34GeEXl9fcKCBCgLTQWw5Rvbsd+ 0rP32dmHFM/Ex64Ld6UuZSONgZCPHDJgDB+Jx+TwMGTImSSL6knWkpwfFgLhfk2o7hLhl0 RHt+K7vypjG1f3EtJYEKgffPPFjtxe8= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-423-DKuOiozQNgGUeVYlDAHCBQ-1; Mon, 11 Jan 2021 08:23:50 -0500 X-MC-Unique: DKuOiozQNgGUeVYlDAHCBQ-1 Received: by mail-pl1-f200.google.com with SMTP id d6so9256117plr.17 for ; Mon, 11 Jan 2021 05:23:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ojFT1PhIb+FaXuvRr1SxUCplyTRyIPBcMEzZQECx4RA=; b=B94dj6KJ486UkALRmukamh1hhR/zDRvnW0ZuquWB1jW3psgCWhsPvXE/3ufis54w0j z7JNRusDIxW1/D+xj3DQQvlYdlQbCPqTI4Bq1Hey/+pZolvNq1RdNGagXURIVJtbETuo BND5natjqd8bHC57ZWuBj0nbnVrUObiGxz26XjKxRvaPDtow4TgQQx9z6u3DnVsunHk6 3PBlndERvr0weDSWEA4T7wjd50/jI0P98tUhgEo6ATv5raoJh5D729mE6AX7fkqQsigg bf+o2QEQ1WDYO+N1y4wmV+NAH9e8tpRQDwOgMRtkig2Ruh2jpI/S/oM8T0rx2f9KNnk8 iqEA== X-Gm-Message-State: AOAM533wfLEt4mfxTxW0W3J45J3/V/vxj4QhobrGFYOVwX2PPBQQOXet /ixU90sZE7xrKp5nTITjgHboRQA+64Q09Ke/UlDAuKjTXMnBZiVDBVzWjTOPUGKHnPBRWyY3lOK H2zARCx5QuHfsifQmFwYao0d2k6PkeXTRLEV+wCZGTVrfT+Q6EB+dlDlo36cf3euOgUrKrQLv+A == X-Received: by 2002:a63:c04b:: with SMTP id z11mr19643848pgi.74.1610371429579; Mon, 11 Jan 2021 05:23:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7XpcWgCBKOxnyzGsat5U6mLCasKLTpKO+XORTstuMeYo7+ylDSMQ58R5NTStPRjmhvBH+jQ== X-Received: by 2002:a63:c04b:: with SMTP id z11mr19643822pgi.74.1610371429267; Mon, 11 Jan 2021 05:23:49 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id cu4sm16179355pjb.18.2021.01.11.05.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jan 2021 05:23:48 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Gao Xiang Subject: [PATCH v4 3/4] xfs: hoist out xfs_resizefs_init_new_ags() Date: Mon, 11 Jan 2021 21:22:42 +0800 Message-Id: <20210111132243.1180013-4-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210111132243.1180013-1-hsiangkao@redhat.com> References: <20210111132243.1180013-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Move out related logic for initializing new added AGs to a new helper in preparation for shrinking. No logic changes. Reviewed-by: Darrick J. Wong Signed-off-by: Gao Xiang --- fs/xfs/xfs_fsops.c | 74 +++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 0bc9c5ebd199..8fde7a2989ce 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -20,6 +20,49 @@ #include "xfs_ag.h" #include "xfs_ag_resv.h" +static int +xfs_resizefs_init_new_ags( + xfs_mount_t *mp, + struct aghdr_init_data *id, + xfs_agnumber_t oagcount, + xfs_agnumber_t nagcount, + xfs_rfsblock_t *delta) +{ + xfs_rfsblock_t nb = mp->m_sb.sb_dblocks + *delta; + int error; + + /* + * Write new AG headers to disk. Non-transactional, but need to be + * written and completed prior to the growfs transaction being logged. + * To do this, we use a delayed write buffer list and wait for + * submission and IO completion of the list as a whole. This allows the + * IO subsystem to merge all the AG headers in a single AG into a single + * IO and hide most of the latency of the IO from us. + * + * This also means that if we get an error whilst building the buffer + * list to write, we can cancel the entire list without having written + * anything. + */ + INIT_LIST_HEAD(&id->buffer_list); + for (id->agno = nagcount - 1; + id->agno >= oagcount; + id->agno--, *delta -= id->agsize) { + + if (id->agno == nagcount - 1) + id->agsize = nb - (id->agno * + (xfs_rfsblock_t)mp->m_sb.sb_agblocks); + else + id->agsize = mp->m_sb.sb_agblocks; + + error = xfs_ag_init_headers(mp, id); + if (error) { + xfs_buf_delwri_cancel(&id->buffer_list); + return error; + } + } + return xfs_buf_delwri_submit(&id->buffer_list); +} + /* * growfs operations */ @@ -74,36 +117,7 @@ xfs_growfs_data_private( if (error) return error; - /* - * Write new AG headers to disk. Non-transactional, but need to be - * written and completed prior to the growfs transaction being logged. - * To do this, we use a delayed write buffer list and wait for - * submission and IO completion of the list as a whole. This allows the - * IO subsystem to merge all the AG headers in a single AG into a single - * IO and hide most of the latency of the IO from us. - * - * This also means that if we get an error whilst building the buffer - * list to write, we can cancel the entire list without having written - * anything. - */ - INIT_LIST_HEAD(&id.buffer_list); - for (id.agno = nagcount - 1; - id.agno >= oagcount; - id.agno--, delta -= id.agsize) { - - if (id.agno == nagcount - 1) - id.agsize = nb - - (id.agno * (xfs_rfsblock_t)mp->m_sb.sb_agblocks); - else - id.agsize = mp->m_sb.sb_agblocks; - - error = xfs_ag_init_headers(mp, &id); - if (error) { - xfs_buf_delwri_cancel(&id.buffer_list); - goto out_trans_cancel; - } - } - error = xfs_buf_delwri_submit(&id.buffer_list); + error = xfs_resizefs_init_new_ags(mp, &id, oagcount, nagcount, &delta); if (error) goto out_trans_cancel; From patchwork Mon Jan 11 13:22:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12010633 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 A79A3C43381 for ; Mon, 11 Jan 2021 13:25:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D50F223E8 for ; Mon, 11 Jan 2021 13:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728812AbhAKNZ1 (ORCPT ); Mon, 11 Jan 2021 08:25:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:29738 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731180AbhAKNZY (ORCPT ); Mon, 11 Jan 2021 08:25:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610371436; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MqfKg4j4L++6ruXjR8/liGk5w+wThWhjU4NhKwLT5m4=; b=WzQP9LLcNjDtQeXuOAwRh3Cedh0n1lT6wZypc7a424LytEbCIGmh/Vv7xzeKTV0PG0IMbv s9XEyqu+8msUU8W7DHQwg4TO327lP4mdkfarJwbd7hVRRzhyKFWVee9sLZV0NFscJjpaQK p8quI6v2Pt3fzFebL3yJ1LO2zeAg5qw= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-478-gzmuTNBBNBKwvbYjW9DXnQ-1; Mon, 11 Jan 2021 08:23:55 -0500 X-MC-Unique: gzmuTNBBNBKwvbYjW9DXnQ-1 Received: by mail-pj1-f70.google.com with SMTP id g7so11200030pji.0 for ; Mon, 11 Jan 2021 05:23:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MqfKg4j4L++6ruXjR8/liGk5w+wThWhjU4NhKwLT5m4=; b=PJdAhm81Gv32IFcBLZhDrqskp103zFA9w4HpXDSNvcIN6PsGzA3LvAB5Hfgx3RG9wC fvZ3ROfLkRqPOJQCtA474shlpWSTCkcd8RgChZ4C8yofh92Jc6y3FtmbY6bvimL3666p JDZOpxpXuGBP6D5w0j0fXZYKClrQcvypHycrbtzbDhnsKtFDH/G9fgavkoquenECt6fC W4vYMZXvUuzqm+Q+LtzwqxDKV9Hbs5tyXjLey1sE9ouYwC3PpndAnsS6l+C9AQWAHZHP EmwIyTwd3QRcBHqU3HITSCT1+ytodV2uZb9iNytWDSVcKayHLkY8l2qJVNOxqHWSHcpn iAtw== X-Gm-Message-State: AOAM530YHWVKpHkKhtYlGTcDvxtbJw9VDBZpfNb3AEIm+oFtYfXjo7CO eizJLhou6+mxAt8d4sV4hD7TLtB9woo0gWPFKCb0r0ltGer2ZQhGfk4n/JHo6ll2XWqwFt9EuPU xjwKM3aLJbPKXhI60U95kY9b4e8oQuk6fMyQ88uJCo+zGpxm47hR6eEic3anNU8Z4fOKST547Jg == X-Received: by 2002:a17:902:6b87:b029:dc:3402:18af with SMTP id p7-20020a1709026b87b02900dc340218afmr9023819plk.29.1610371433867; Mon, 11 Jan 2021 05:23:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7jVycHU5RBztCmwsri0wCBi/0rQAa4YfL0nTnDam861WvPn/ceF/l7C0ynXhmDDXA5unH0A== X-Received: by 2002:a17:902:6b87:b029:dc:3402:18af with SMTP id p7-20020a1709026b87b02900dc340218afmr9023790plk.29.1610371433516; Mon, 11 Jan 2021 05:23:53 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id cu4sm16179355pjb.18.2021.01.11.05.23.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jan 2021 05:23:53 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Gao Xiang Subject: [PATCH v4 4/4] xfs: support shrinking unused space in the last AG Date: Mon, 11 Jan 2021 21:22:43 +0800 Message-Id: <20210111132243.1180013-5-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210111132243.1180013-1-hsiangkao@redhat.com> References: <20210111132243.1180013-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org As the first step of shrinking, this attempts to enable shrinking unused space in the last allocation group by fixing up freespace btree, agi, agf and adjusting super block and introduce a helper xfs_ag_shrink_space() to fixup the last AG. This can be all done in one transaction for now, so I think no additional protection is needed. Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ag.c | 72 ++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_ag.h | 2 ++ fs/xfs/xfs_fsops.c | 70 +++++++++++++++++++++++++++++----------- fs/xfs/xfs_trans.c | 1 - 4 files changed, 125 insertions(+), 20 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c index 9331f3516afa..bec10c85e2a9 100644 --- a/fs/xfs/libxfs/xfs_ag.c +++ b/fs/xfs/libxfs/xfs_ag.c @@ -485,6 +485,78 @@ xfs_ag_init_headers( return error; } +int +xfs_ag_shrink_space( + struct xfs_mount *mp, + struct xfs_trans *tp, + struct aghdr_init_data *id, + xfs_extlen_t len) +{ + struct xfs_buf *agibp, *agfbp; + struct xfs_agi *agi; + struct xfs_agf *agf; + int error, err2; + struct xfs_alloc_arg args = { + .tp = tp, + .mp = mp, + .type = XFS_ALLOCTYPE_THIS_BNO, + .minlen = len, + .maxlen = len, + .oinfo = XFS_RMAP_OINFO_SKIP_UPDATE, + .resv = XFS_AG_RESV_NONE, + .prod = 1 + }; + + ASSERT(id->agno == mp->m_sb.sb_agcount - 1); + error = xfs_ialloc_read_agi(mp, tp, id->agno, &agibp); + if (error) + return error; + + agi = agibp->b_addr; + + error = xfs_alloc_read_agf(mp, tp, id->agno, 0, &agfbp); + if (error) + return error; + + args.fsbno = XFS_AGB_TO_FSB(mp, id->agno, + be32_to_cpu(agi->agi_length) - len); + + /* remove the preallocations before allocation and re-establish then */ + error = xfs_ag_resv_free(agibp->b_pag); + if (error) + return error; + + /* internal log shouldn't also show up in the free space btrees */ + error = xfs_alloc_vextent(&args); + if (error) + goto out; + + if (args.agbno == NULLAGBLOCK) { + error = -ENOSPC; + goto out; + } + + /* Change the agi length */ + be32_add_cpu(&agi->agi_length, -len); + xfs_ialloc_log_agi(tp, agibp, XFS_AGI_LENGTH); + + /* Change agf length */ + agf = agfbp->b_addr; + be32_add_cpu(&agf->agf_length, -len); + ASSERT(agf->agf_length == agi->agi_length); + xfs_alloc_log_agf(tp, agfbp, XFS_AGF_LENGTH); + +out: + err2 = xfs_ag_resv_init(agibp->b_pag, tp); + if (err2 && err2 != -ENOSPC) { + xfs_warn(mp, +"Error %d reserving per-AG metadata reserve pool.", err2); + xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); + return err2; + } + return error; +} + /* * Extent the AG indicated by the @id by the length passed in */ diff --git a/fs/xfs/libxfs/xfs_ag.h b/fs/xfs/libxfs/xfs_ag.h index 5166322807e7..f3b5bbfeadce 100644 --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -24,6 +24,8 @@ struct aghdr_init_data { }; int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id); +int xfs_ag_shrink_space(struct xfs_mount *mp, struct xfs_trans *tp, + struct aghdr_init_data *id, xfs_extlen_t len); int xfs_ag_extend_space(struct xfs_mount *mp, struct xfs_trans *tp, struct aghdr_init_data *id, xfs_extlen_t len); int xfs_ag_get_geometry(struct xfs_mount *mp, xfs_agnumber_t agno, diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 8fde7a2989ce..6ee9ea4d5a67 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -26,7 +26,7 @@ xfs_resizefs_init_new_ags( struct aghdr_init_data *id, xfs_agnumber_t oagcount, xfs_agnumber_t nagcount, - xfs_rfsblock_t *delta) + int64_t *delta) { xfs_rfsblock_t nb = mp->m_sb.sb_dblocks + *delta; int error; @@ -76,22 +76,28 @@ xfs_growfs_data_private( xfs_agnumber_t nagcount; xfs_agnumber_t nagimax = 0; xfs_rfsblock_t nb, nb_div, nb_mod; - xfs_rfsblock_t delta; + int64_t delta; xfs_agnumber_t oagcount; struct xfs_trans *tp; + bool extend; struct aghdr_init_data id = {}; nb = in->newblocks; - if (nb < mp->m_sb.sb_dblocks) - return -EINVAL; - if ((error = xfs_sb_validate_fsb_count(&mp->m_sb, nb))) + if (nb == mp->m_sb.sb_dblocks) + return 0; + + error = xfs_sb_validate_fsb_count(&mp->m_sb, nb); + if (error) return error; - error = xfs_buf_read_uncached(mp->m_ddev_targp, + + if (nb > mp->m_sb.sb_dblocks) { + error = xfs_buf_read_uncached(mp->m_ddev_targp, XFS_FSB_TO_BB(mp, nb) - XFS_FSS_TO_BB(mp, 1), XFS_FSS_TO_BB(mp, 1), 0, &bp, NULL); - if (error) - return error; - xfs_buf_relse(bp); + if (error) + return error; + xfs_buf_relse(bp); + } nb_div = nb; nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks); @@ -99,10 +105,12 @@ xfs_growfs_data_private( if (nb_mod && nb_mod < XFS_MIN_AG_BLOCKS) { nagcount--; nb = (xfs_rfsblock_t)nagcount * mp->m_sb.sb_agblocks; - if (nb < mp->m_sb.sb_dblocks) + if (nagcount < 2) return -EINVAL; } + delta = nb - mp->m_sb.sb_dblocks; + extend = (delta > 0); oagcount = mp->m_sb.sb_agcount; /* allocate the new per-ag structures */ @@ -110,22 +118,34 @@ xfs_growfs_data_private( error = xfs_initialize_perag(mp, nagcount, &nagimax); if (error) return error; + } else if (nagcount != oagcount) { + /* TODO: shrinking the entire AGs hasn't yet completed */ + return -EINVAL; } error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata, - XFS_GROWFS_SPACE_RES(mp), 0, XFS_TRANS_RESERVE, &tp); + (extend ? XFS_GROWFS_SPACE_RES(mp) : -delta), 0, + XFS_TRANS_RESERVE, &tp); if (error) return error; - error = xfs_resizefs_init_new_ags(mp, &id, oagcount, nagcount, &delta); - if (error) - goto out_trans_cancel; - + if (extend) { + error = xfs_resizefs_init_new_ags(mp, &id, oagcount, + nagcount, &delta); + if (error) + goto out_trans_cancel; + } xfs_trans_agblocks_delta(tp, id.nfree); - /* If there are new blocks in the old last AG, extend it. */ + /* If there are some blocks in the last AG, resize it. */ if (delta) { - error = xfs_ag_extend_space(mp, tp, &id, delta); + if (extend) { + error = xfs_ag_extend_space(mp, tp, &id, delta); + } else { + id.agno = nagcount - 1; + error = xfs_ag_shrink_space(mp, tp, &id, -delta); + } + if (error) goto out_trans_cancel; } @@ -137,11 +157,19 @@ xfs_growfs_data_private( */ if (nagcount > oagcount) xfs_trans_mod_sb(tp, XFS_TRANS_SB_AGCOUNT, nagcount - oagcount); - if (nb > mp->m_sb.sb_dblocks) + if (nb != mp->m_sb.sb_dblocks) xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS, nb - mp->m_sb.sb_dblocks); if (id.nfree) xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, id.nfree); + + /* + * update in-core counters (especially sb_fdblocks) now + * so xfs_validate_sb_write() can pass. + */ + if (xfs_sb_version_haslazysbcount(&mp->m_sb)) + xfs_log_sb(tp); + xfs_trans_set_sync(tp); error = xfs_trans_commit(tp); if (error) @@ -157,7 +185,7 @@ xfs_growfs_data_private( * If we expanded the last AG, free the per-AG reservation * so we can reinitialize it with the new size. */ - if (delta) { + if (delta > 0) { struct xfs_perag *pag; pag = xfs_perag_get(mp, id.agno); @@ -178,6 +206,10 @@ xfs_growfs_data_private( return error; out_trans_cancel: + if (!extend && (tp->t_flags & XFS_TRANS_DIRTY)) { + xfs_trans_commit(tp); + return error; + } xfs_trans_cancel(tp); return error; } diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index e72730f85af1..fd2cbf414b80 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -419,7 +419,6 @@ xfs_trans_mod_sb( tp->t_res_frextents_delta += delta; break; case XFS_TRANS_SB_DBLOCKS: - ASSERT(delta > 0); tp->t_dblocks_delta += delta; break; case XFS_TRANS_SB_AGCOUNT: