From patchwork Mon Dec 7 00:15:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11954663 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=-18.8 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, 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 319E3C433FE for ; Mon, 7 Dec 2020 00:18:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 002F723108 for ; Mon, 7 Dec 2020 00:18:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727393AbgLGAR5 (ORCPT ); Sun, 6 Dec 2020 19:17:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23153 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbgLGAR5 (ORCPT ); Sun, 6 Dec 2020 19:17:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607300190; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=NENDvw0JxA1rt741Or+cB19d9O6Fy2czmjuXVdfK9OM=; b=CmFj7k6ddo2NY8gSKR9tvo5y6R8hiqKJWeoqIgMLKj+t6xBBg/tyOLkvvuzjms9I3jOfR+ 76MkefgVCfk7lNeZulS5njT+4/PCOskFrG5bP7gPgsfTUsbETGt945ubOrF9Fgjy3Nil6/ G/YR5ZxBDQnh11PwY9Z+BAgTL8aHWcY= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-382-pc7cbHIKO5OcY1kGPAVsRQ-1; Sun, 06 Dec 2020 19:16:29 -0500 X-MC-Unique: pc7cbHIKO5OcY1kGPAVsRQ-1 Received: by mail-pf1-f197.google.com with SMTP id t8so7874736pfl.17 for ; Sun, 06 Dec 2020 16:16:29 -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; bh=NENDvw0JxA1rt741Or+cB19d9O6Fy2czmjuXVdfK9OM=; b=S2quD0UbZciNSQL+1+pV/qDPvf2UFAR53lzK+odhHMp0LyKDtQDlW7xOCzjhptsGps 14+bP07cIlMfYHqxcebsnH9Sx4QZtIZxQW3MIcvz0ZGihgfmgxRqXDcXNCzdoWEw/+oc ssFKBSE3kak5GD0B+BC3g6RbP3dP4aFBQlV8qEeFxLDUjkwVPFXyjJXMJFxdT/WFyP3F MxbtV5EF8nISi7tUBpv15MeL7zXzMTkBfW6rhmZnI6z6rJlzr6nS+6QZEFz3R8r+1QqW J9zIth8+Yo7gChpNPmSkuoJCC6ZMj6NrA7cKpf2uhVKN/5UItUj9KUO+7saUz/ouRznY qboQ== X-Gm-Message-State: AOAM5339qbBIKPgc8dBbgwywgEEKlCEGNoDFNFQR1m0ZR77el1RChurs j2iB58dTLppH8INJj5dAyxURdlHwndRlS6apEz9TeZIXyJRHlJV+mzDN7BMd3PAHk06vNeA4+hU 6iBbqBnilu0mUQTxeuc6zY8ce0ZWfnsg/MFhtJkzpN+GfMXUd9+cBkIWn0NIzGmtYMy1zJNNc4Q == X-Received: by 2002:a63:1622:: with SMTP id w34mr681132pgl.1.1607300188192; Sun, 06 Dec 2020 16:16:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5dWBoL6+4xfOvvrrg+tqMuNBJkdode+Q+5qrItb1/LBKFUVJqJ1gxGAk5R1IpRkEUQn9s2Q== X-Received: by 2002:a63:1622:: with SMTP id w34mr681115pgl.1.1607300187936; Sun, 06 Dec 2020 16:16:27 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o9sm8218056pjl.11.2020.12.06.16.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2020 16:16:27 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Dave Chinner , Christoph Hellwig , Eric Sandeen , Gao Xiang Subject: [PATCH v3 1/6] xfs: convert noroom, okalloc in xfs_dialloc() to bool Date: Mon, 7 Dec 2020 08:15:28 +0800 Message-Id: <20201207001533.2702719-2-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201207001533.2702719-1-hsiangkao@redhat.com> References: <20201207001533.2702719-1-hsiangkao@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Boolean is preferred for such use. Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ialloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 974e71bc4a3a..45cf7e55f5ee 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -1716,11 +1716,11 @@ xfs_dialloc( xfs_agnumber_t agno; int error; int ialloced; - int noroom = 0; + bool noroom = false; xfs_agnumber_t start_agno; struct xfs_perag *pag; struct xfs_ino_geometry *igeo = M_IGEO(mp); - int okalloc = 1; + bool okalloc = true; if (*IO_agbp) { /* @@ -1753,8 +1753,8 @@ xfs_dialloc( if (igeo->maxicount && percpu_counter_read_positive(&mp->m_icount) + igeo->ialloc_inos > igeo->maxicount) { - noroom = 1; - okalloc = 0; + noroom = true; + okalloc = false; } /* From patchwork Mon Dec 7 00:15:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11954667 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=-18.8 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 4A932C4167B for ; Mon, 7 Dec 2020 00:18:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 19EEF23123 for ; Mon, 7 Dec 2020 00:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728171AbgLGASF (ORCPT ); Sun, 6 Dec 2020 19:18:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54097 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbgLGASF (ORCPT ); Sun, 6 Dec 2020 19:18:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607300198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=8shifgnJyENzsnf537IZfK2Yi2aGEnRhZljtyUd0Dts=; b=VFU/xGZ5sCtoA02x+yXimWA7L5/KsOpPuYTnTkAhLleyUHWKTrQi2ofyyHII0OVRTloILY 3um0Anbz1x+/OZ2WZ9rA/w7iwp4mn6W7R0hFbKZj/PaQ9WPCbq+wY+MfHIeob8KMf5PsWd 67DvYK5JjXNXJ4iUEOWpM9GGLVn+25k= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-451--lFlZn_hN42AH4ZZgxnsiA-1; Sun, 06 Dec 2020 19:16:34 -0500 X-MC-Unique: -lFlZn_hN42AH4ZZgxnsiA-1 Received: by mail-pf1-f197.google.com with SMTP id u3so7858502pfm.22 for ; Sun, 06 Dec 2020 16:16:34 -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; bh=8shifgnJyENzsnf537IZfK2Yi2aGEnRhZljtyUd0Dts=; b=nt3qyyhlsSXdpP+RTxcrmItmHTA4bQJ870V9XsZiXg/uEsraQIq48fkQ92KJXDoYar D/qep6oji5U4h5GfXJ/3IYVsgPC+qb3Z7HMNvbXfLEKNMiH2gsKLvzMwLYMh/xRxIB6P OBIsArYRY6T9MViionjgGgSQTlmGyfTvqHwsRc8NS7SlNkHEz4j3j6yJiDhx/++3kWBf sxWYZrOYudkTHB5uZWzeSmaWG9bWkiScvA5Li8WRvKW3CeqjH9vydmG0vBee65TmUP4c 3/p1wCJaniJfeHTTo3MS53TbbHm23AEb+LrK9D22CTiQ60ggGvFQKTiRcRVP4SYjGZwk nFXQ== X-Gm-Message-State: AOAM530BvPAxhsMH/LPE3l5AyCAlcg5Z5gNENK19RgO3XuzFUed38c6w 5+JzC9MBcXSa0g7zAtK7cdeNGvtmsf2VTWgfTtIQJRukurHif+xHaLn80huKAVwjYVoW6DcA7fP WDMBZEl8SGmVW9s4EbtssEDGhIP1RRw4KymQtEgUZs0oYpr+SdGrrgIIkVJOB6QH87NnAm4zybw == X-Received: by 2002:a17:902:b707:b029:da:a304:1952 with SMTP id d7-20020a170902b707b02900daa3041952mr13440780pls.6.1607300193149; Sun, 06 Dec 2020 16:16:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMUUXVbOx5tnXXkY9Mlm5gHPZ7PIjJHMOquT7B/NWQyFsrvcqIg9YSpjmlFDOh9KmwFE5lNg== X-Received: by 2002:a17:902:b707:b029:da:a304:1952 with SMTP id d7-20020a170902b707b02900daa3041952mr13440758pls.6.1607300192827; Sun, 06 Dec 2020 16:16:32 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o9sm8218056pjl.11.2020.12.06.16.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2020 16:16:32 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Dave Chinner , Christoph Hellwig , Eric Sandeen , Dave Chinner , Gao Xiang Subject: [PATCH v3 2/6] xfs: introduce xfs_dialloc_roll() Date: Mon, 7 Dec 2020 08:15:29 +0800 Message-Id: <20201207001533.2702719-3-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201207001533.2702719-1-hsiangkao@redhat.com> References: <20201207001533.2702719-1-hsiangkao@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Dave Chinner Introduce a helper to make the on-disk inode allocation rolling logic clearer in preparation of the following cleanup. Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_ialloc.c | 45 ++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_ialloc.h | 6 +++++ fs/xfs/xfs_inode.c | 39 +-------------------------------- 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 45cf7e55f5ee..3d2862e3ff41 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -1682,6 +1682,51 @@ xfs_dialloc_ag( return error; } +int +xfs_dialloc_roll( + struct xfs_trans **tpp, + struct xfs_buf *agibp) +{ + struct xfs_trans *tp = *tpp; + struct xfs_dquot_acct *dqinfo = NULL; + unsigned int tflags = 0; + int error; + + /* + * Hold to on to the agibp across the commit so no other allocation can + * come in and take the free inodes we just allocated for our caller. + */ + xfs_trans_bhold(tp, agibp); + + /* + * We want the quota changes to be associated with the next transaction, + * NOT this one. So, detach the dqinfo from this and attach it to the + * next transaction. + */ + if (tp->t_dqinfo) { + dqinfo = tp->t_dqinfo; + tp->t_dqinfo = NULL; + tflags = tp->t_flags & XFS_TRANS_DQ_DIRTY; + tp->t_flags &= ~(XFS_TRANS_DQ_DIRTY); + } + + error = xfs_trans_roll(&tp); + + /* Re-attach the quota info that we detached from prev trx. */ + if (dqinfo) { + tp->t_dqinfo = dqinfo; + tp->t_flags |= tflags; + } + + *tpp = tp; + if (error) { + xfs_buf_relse(agibp); + return error; + } + xfs_trans_bjoin(tp, agibp); + return 0; +} + /* * Allocate an inode on disk. * diff --git a/fs/xfs/libxfs/xfs_ialloc.h b/fs/xfs/libxfs/xfs_ialloc.h index 72b3468b97b1..a145e2a72530 100644 --- a/fs/xfs/libxfs/xfs_ialloc.h +++ b/fs/xfs/libxfs/xfs_ialloc.h @@ -32,6 +32,12 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog); } +/* XXX: will be removed in the following patch */ +int +xfs_dialloc_roll( + struct xfs_trans **tpp, + struct xfs_buf *agibp); + /* * Allocate an inode on disk. * Mode is used to tell whether the new inode will need space, and whether diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 2bfbcf28b1bd..6672cdffcda5 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -958,8 +958,6 @@ xfs_dir_ialloc( xfs_inode_t *ip; xfs_buf_t *ialloc_context = NULL; int code; - void *dqinfo; - uint tflags; tp = *tpp; ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); @@ -1003,46 +1001,12 @@ xfs_dir_ialloc( * to succeed the second time. */ if (ialloc_context) { - /* - * Normally, xfs_trans_commit releases all the locks. - * We call bhold to hang on to the ialloc_context across - * the commit. Holding this buffer prevents any other - * processes from doing any allocations in this - * allocation group. - */ - xfs_trans_bhold(tp, ialloc_context); - - /* - * We want the quota changes to be associated with the next - * transaction, NOT this one. So, detach the dqinfo from this - * and attach it to the next transaction. - */ - dqinfo = NULL; - tflags = 0; - if (tp->t_dqinfo) { - dqinfo = (void *)tp->t_dqinfo; - tp->t_dqinfo = NULL; - tflags = tp->t_flags & XFS_TRANS_DQ_DIRTY; - tp->t_flags &= ~(XFS_TRANS_DQ_DIRTY); - } - - code = xfs_trans_roll(&tp); - - /* - * Re-attach the quota info that we detached from prev trx. - */ - if (dqinfo) { - tp->t_dqinfo = dqinfo; - tp->t_flags |= tflags; - } - + code = xfs_dialloc_roll(&tp, ialloc_context); if (code) { - xfs_buf_relse(ialloc_context); *tpp = tp; *ipp = NULL; return code; } - xfs_trans_bjoin(tp, ialloc_context); /* * Call ialloc again. Since we've locked out all @@ -1062,7 +1026,6 @@ xfs_dir_ialloc( return code; } ASSERT(!ialloc_context && ip); - } *ipp = ip; From patchwork Mon Dec 7 00:15:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11954669 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=-18.8 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 7AD90C433FE for ; Mon, 7 Dec 2020 00:18:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52E3122E03 for ; Mon, 7 Dec 2020 00:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728209AbgLGASJ (ORCPT ); Sun, 6 Dec 2020 19:18:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41721 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbgLGASI (ORCPT ); Sun, 6 Dec 2020 19:18:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607300200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=5tlUKSSQUsZTbvO71wj/cVAdrW23gTJMB2a6uPVVt+c=; b=Bbyw8MFl4yRX+LaBXl9ofyN40PhYSfCjBFedn3Z8bwO81I6J04sNi3AqGp1Z8L2JaOAZis eoVaf6Iya+SMhyOL/paEOFvoJPVgEgz2qKDYp+Yr264EcqLsgOM9IgEQP2dtTrJz5TJFYN /cbvd8u6fuQYHW9BHLxFIHeNgz3sIs8= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373-_g1YUUxIOGOvwcs5Ses5mg-1; Sun, 06 Dec 2020 19:16:39 -0500 X-MC-Unique: _g1YUUxIOGOvwcs5Ses5mg-1 Received: by mail-pf1-f199.google.com with SMTP id x20so7881480pfm.6 for ; Sun, 06 Dec 2020 16:16:39 -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; bh=5tlUKSSQUsZTbvO71wj/cVAdrW23gTJMB2a6uPVVt+c=; b=PQMyNT7hb6bIVJC6+1wgvqKwwdpBzgjdA1/0uiV87VqaQpR0TaP+dxPQk7AXVJAUPb 1vXa2kVAew3t5vhN0j9unUaZCvaKjjypqBBC/Y6LZoUk5+RmvkQCqAxTHn1rquD8mlTI WSCgtrwWKTPJcueXRJP4coIG2xMUjFP0IrNViruyNuER/ipiqkXCV5dXDUbaEyXb5Oz9 YHb1K8R7sOPNdBCzzMbX2IT9bVX4xmlr5MUVTkvCbOAMiD8xvrC3H3U10fY1fuP+1bCa lq/Xqq7tPIMbrVYeckUwCpKovlmNTfO0CALAqqINICpNyRB8e5a42xp9db9ndTdgErxh zlew== X-Gm-Message-State: AOAM532sIh92mZifb190mU768eJ8Z2RbZtAH8H/lXT5baWDcQq4oKb58 1gET7V/wqImb4oihyYFULKT4JdjSsGFxOEe2PqUMbvTTUliTrXA1nsjt7xqDWdt/hE0+YK8niVV hwrKN2F16BMtEneEqbDcVByjK/NQ7iAN8K9PnXXwKQCApYhjtYMgvQd8lyP7eRsO+tgrqyhWFfA == X-Received: by 2002:a17:90b:33d1:: with SMTP id lk17mr14397240pjb.174.1607300197758; Sun, 06 Dec 2020 16:16:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoxitVsPYiNWslMMp0z8atrIjbeAHe3kmTG5QQpW3eFJdkdaHDWbNziodm8y729Nm7MsKtTw== X-Received: by 2002:a17:90b:33d1:: with SMTP id lk17mr14397212pjb.174.1607300197390; Sun, 06 Dec 2020 16:16:37 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o9sm8218056pjl.11.2020.12.06.16.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2020 16:16:36 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Dave Chinner , Christoph Hellwig , Eric Sandeen , Dave Chinner , Gao Xiang Subject: [PATCH v3 3/6] xfs: move on-disk inode allocation out of xfs_ialloc() Date: Mon, 7 Dec 2020 08:15:30 +0800 Message-Id: <20201207001533.2702719-4-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201207001533.2702719-1-hsiangkao@redhat.com> References: <20201207001533.2702719-1-hsiangkao@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Dave Chinner So xfs_ialloc() will only address in-core inode allocation then, Also, rename xfs_ialloc() to xfs_dir_ialloc_init() in order to keep everything in xfs_inode.c under the same namespace. Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang --- fs/xfs/xfs_inode.c | 202 +++++++++++++++------------------------------ 1 file changed, 66 insertions(+), 136 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 6672cdffcda5..22843e81bccf 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -761,68 +761,25 @@ xfs_inode_inherit_flags2( } /* - * Allocate an inode on disk and return a copy of its in-core version. - * The in-core inode is locked exclusively. Set mode, nlink, and rdev - * appropriately within the inode. The uid and gid for the inode are - * set according to the contents of the given cred structure. - * - * Use xfs_dialloc() to allocate the on-disk inode. If xfs_dialloc() - * has a free inode available, call xfs_iget() to obtain the in-core - * version of the allocated inode. Finally, fill in the inode and - * log its initial contents. In this case, ialloc_context would be - * set to NULL. - * - * If xfs_dialloc() does not have an available inode, it will replenish - * its supply by doing an allocation. Since we can only do one - * allocation within a transaction without deadlocks, we must commit - * the current transaction before returning the inode itself. - * In this case, therefore, we will set ialloc_context and return. - * The caller should then commit the current transaction, start a new - * transaction, and call xfs_ialloc() again to actually get the inode. - * - * To ensure that some other process does not grab the inode that - * was allocated during the first call to xfs_ialloc(), this routine - * also returns the [locked] bp pointing to the head of the freelist - * as ialloc_context. The caller should hold this buffer across - * the commit and pass it back into this routine on the second call. - * - * If we are allocating quota inodes, we do not have a parent inode - * to attach to or associate with (i.e. pip == NULL) because they - * are not linked into the directory structure - they are attached - * directly to the superblock - and so have no parent. + * Initialise a newly allocated inode and return the in-core inode to the + * caller locked exclusively. */ -static int -xfs_ialloc( - xfs_trans_t *tp, - xfs_inode_t *pip, - umode_t mode, - xfs_nlink_t nlink, - dev_t rdev, - prid_t prid, - xfs_buf_t **ialloc_context, - xfs_inode_t **ipp) +static struct xfs_inode * +xfs_dir_ialloc_init( + struct xfs_trans *tp, + struct xfs_inode *pip, + xfs_ino_t ino, + umode_t mode, + xfs_nlink_t nlink, + dev_t rdev, + prid_t prid) { - struct xfs_mount *mp = tp->t_mountp; - xfs_ino_t ino; - xfs_inode_t *ip; - uint flags; - int error; - struct timespec64 tv; - struct inode *inode; - - /* - * Call the space management code to pick - * the on-disk inode to be allocated. - */ - error = xfs_dialloc(tp, pip ? pip->i_ino : 0, mode, - ialloc_context, &ino); - if (error) - return error; - if (*ialloc_context || ino == NULLFSINO) { - *ipp = NULL; - return 0; - } - ASSERT(*ialloc_context == NULL); + struct xfs_mount *mp = tp->t_mountp; + struct xfs_inode *ip; + unsigned int flags; + int error; + struct timespec64 tv; + struct inode *inode; /* * Protect against obviously corrupt allocation btree records. Later @@ -833,18 +790,16 @@ xfs_ialloc( */ if ((pip && ino == pip->i_ino) || !xfs_verify_dir_ino(mp, ino)) { xfs_alert(mp, "Allocated a known in-use inode 0x%llx!", ino); - return -EFSCORRUPTED; + return ERR_PTR(-EFSCORRUPTED); } /* - * Get the in-core inode with the lock held exclusively. - * This is because we're setting fields here we need - * to prevent others from looking at until we're done. + * Get the in-core inode with the lock held exclusively to prevent + * others from looking at until we're done. */ - error = xfs_iget(mp, tp, ino, XFS_IGET_CREATE, - XFS_ILOCK_EXCL, &ip); + error = xfs_iget(mp, tp, ino, XFS_IGET_CREATE, XFS_ILOCK_EXCL, &ip); if (error) - return error; + return ERR_PTR(error); ASSERT(ip != NULL); inode = VFS_I(ip); inode->i_mode = mode; @@ -926,20 +881,19 @@ xfs_ialloc( /* now that we have an i_mode we can setup the inode structure */ xfs_setup_inode(ip); - - *ipp = ip; - return 0; + return ip; } /* - * Allocates a new inode from disk and return a pointer to the - * incore copy. This routine will internally commit the current - * transaction and allocate a new one if the Space Manager needed - * to do an allocation to replenish the inode free-list. - * - * This routine is designed to be called from xfs_create and - * xfs_create_dir. + * Allocates a new inode from disk and return a pointer to the incore copy. This + * routine will internally commit the current transaction and allocate a new one + * if we needed to allocate more on-disk free inodes to perform the requested + * operation. * + * If we are allocating quota inodes, we do not have a parent inode to attach to + * or associate with (i.e. dp == NULL) because they are not linked into the + * directory structure - they are attached directly to the superblock - and so + * have no parent. */ int xfs_dir_ialloc( @@ -954,83 +908,59 @@ xfs_dir_ialloc( xfs_inode_t **ipp) /* pointer to inode; it will be locked. */ { - xfs_trans_t *tp; xfs_inode_t *ip; xfs_buf_t *ialloc_context = NULL; - int code; - - tp = *tpp; - ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); + xfs_ino_t pino = dp ? dp->i_ino : 0; + xfs_ino_t ino; + int error; - /* - * xfs_ialloc will return a pointer to an incore inode if - * the Space Manager has an available inode on the free - * list. Otherwise, it will do an allocation and replenish - * the freelist. Since we can only do one allocation per - * transaction without deadlocks, we will need to commit the - * current transaction and start a new one. We will then - * need to call xfs_ialloc again to get the inode. - * - * If xfs_ialloc did an allocation to replenish the freelist, - * it returns the bp containing the head of the freelist as - * ialloc_context. We will hold a lock on it across the - * transaction commit so that no other process can steal - * the inode(s) that we've just allocated. - */ - code = xfs_ialloc(tp, dp, mode, nlink, rdev, prid, &ialloc_context, - &ip); + ASSERT((*tpp)->t_flags & XFS_TRANS_PERM_LOG_RES); + *ipp = NULL; /* - * Return an error if we were unable to allocate a new inode. - * This should only happen if we run out of space on disk or - * encounter a disk error. + * Call the space management code to pick the on-disk inode to be + * allocated and replenish the freelist. Since we can only do one + * allocation per transaction without deadlocks, we will need to + * commit the current transaction and start a new one. + * If xfs_dialloc did an allocation to replenish the freelist, it + * returns the bp containing the head of the freelist as + * ialloc_context. We will hold a lock on it across the transaction + * commit so that no other process can steal the inode(s) that we've + * just allocated. */ - if (code) { - *ipp = NULL; - return code; - } - if (!ialloc_context && !ip) { - *ipp = NULL; - return -ENOSPC; - } + error = xfs_dialloc(*tpp, pino, mode, &ialloc_context, &ino); + if (error) + return error; /* * If the AGI buffer is non-NULL, then we were unable to get an * inode in one operation. We need to commit the current - * transaction and call xfs_ialloc() again. It is guaranteed + * transaction and call xfs_dialloc() again. It is guaranteed * to succeed the second time. */ if (ialloc_context) { - code = xfs_dialloc_roll(&tp, ialloc_context); - if (code) { - *tpp = tp; - *ipp = NULL; - return code; - } - - /* - * Call ialloc again. Since we've locked out all - * other allocations in this allocation group, - * this call should always succeed. - */ - code = xfs_ialloc(tp, dp, mode, nlink, rdev, prid, - &ialloc_context, &ip); - + error = xfs_dialloc_roll(tpp, ialloc_context); + if (error) + return error; /* - * If we get an error at this point, return to the caller - * so that the current transaction can be aborted. + * Call dialloc again. Since we've locked out all other + * allocations in this allocation group, this call should + * always succeed. */ - if (code) { - *tpp = tp; - *ipp = NULL; - return code; - } - ASSERT(!ialloc_context && ip); + error = xfs_dialloc(*tpp, pino, mode, &ialloc_context, &ino); + if (error) + return error; + ASSERT(!ialloc_context); } - *ipp = ip; - *tpp = tp; + if (ino == NULLFSINO) + return -ENOSPC; + /* Initialise the newly allocated inode. */ + ip = xfs_dir_ialloc_init(*tpp, dp, ino, mode, nlink, rdev, prid); + if (IS_ERR(ip)) + return PTR_ERR(ip); + *ipp = ip; return 0; } From patchwork Mon Dec 7 00:15:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11954671 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=-18.8 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 61989C4361B for ; Mon, 7 Dec 2020 00:18:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32C4A22E03 for ; Mon, 7 Dec 2020 00:18:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728281AbgLGASN (ORCPT ); Sun, 6 Dec 2020 19:18:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52118 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbgLGASN (ORCPT ); Sun, 6 Dec 2020 19:18:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607300205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=oGfGnlBjeYZzgbduFWtuNRuiaCBisZCNj5yZrfUntKY=; b=HM3ERxq/bjRPeQCQlSM6v39K6d2ZdN624qqfTIW97KpyvmzyKw2RDUf2UFr6rjqo812d5I C0brSkW9EhyMzFk0LXDapBdKNjgCwZ+hLn0c4r70ImtR1eWiuSfvjzzPnpcfIMzVK7WHDa pbhtwuK1CR+fb6N+JF5pwgywSMsIin4= Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-47-b6LO_XlON72FUFILYfleXw-1; Sun, 06 Dec 2020 19:16:44 -0500 X-MC-Unique: b6LO_XlON72FUFILYfleXw-1 Received: by mail-pj1-f71.google.com with SMTP id o13so6561334pjp.1 for ; Sun, 06 Dec 2020 16:16:44 -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; bh=oGfGnlBjeYZzgbduFWtuNRuiaCBisZCNj5yZrfUntKY=; b=rS8VaaPrkzGEcDgjpguvXX4yRiFQyUHzIwdC5W8ZiWb6BRXHwTs/YdhZPEeqSGBFdY TGsSExLDbcCMgD0uSHogNvxpjy+rsx2lGZ8BmkrFsLIOUGBL3pKP7KXXuw0EoKWc50Kk FD9RnqpXolSvCirJbwBzHNMsMsLwf7W+c5yDOMCBVQhzGe3y39Q0rID0s63OZeelZhNC jEyMyecGwmdlZ+yto3zDxKDz3S3OdecveiMd/EZ6FdIptEis7Ea/sFhFuRx09ATNTLcU TEHtU7jP7SB2LMxiI267KQJUYfnHEZi5wTaNr/HezmwPe0pDaW0ktD8kbCGxnyemwyFq WmjQ== X-Gm-Message-State: AOAM530E9qsP3VZtLfKAm5yBWQGvytMoecmotP5m2UMHJNQMMROcBPgU G+wGgK53KnNSgFlnFY+af53UtcPphdIx2q/XDPDd0qGf1HqVj1/D8/qgCy14TTx+o1ulsPr8VEP ydE5/3yobePXYW8LbEi1PBpBGLMwUL8xgay0dswjmnoRpqSh96TWdNyK2Qvkc1OO0cGJnaI7ImA == X-Received: by 2002:a62:a509:0:b029:19e:1ac3:34bc with SMTP id v9-20020a62a5090000b029019e1ac334bcmr1335289pfm.7.1607300202506; Sun, 06 Dec 2020 16:16:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+INPmDrPefWd19jdRMFFYRvr5DwtUuHefwoPmwY4t1WeIWPYEvYCk1Na56LWKZVlHTTr/4g== X-Received: by 2002:a62:a509:0:b029:19e:1ac3:34bc with SMTP id v9-20020a62a5090000b029019e1ac334bcmr1335248pfm.7.1607300201983; Sun, 06 Dec 2020 16:16:41 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o9sm8218056pjl.11.2020.12.06.16.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2020 16:16:41 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Dave Chinner , Christoph Hellwig , Eric Sandeen , Dave Chinner , Gao Xiang Subject: [PATCH v3 4/6] xfs: move xfs_dialloc_roll() into xfs_dialloc() Date: Mon, 7 Dec 2020 08:15:31 +0800 Message-Id: <20201207001533.2702719-5-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201207001533.2702719-1-hsiangkao@redhat.com> References: <20201207001533.2702719-1-hsiangkao@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Dave Chinner Get rid of the confusing ialloc_context and failure handling around xfs_dialloc() by moving xfs_dialloc_roll() into xfs_dialloc(). Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_ialloc.c | 57 ++++++++++++-------------------------- fs/xfs/libxfs/xfs_ialloc.h | 22 +-------------- fs/xfs/xfs_inode.c | 35 ++--------------------- 3 files changed, 22 insertions(+), 92 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 3d2862e3ff41..b00bbd680177 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -1682,7 +1682,7 @@ xfs_dialloc_ag( return error; } -int +static int xfs_dialloc_roll( struct xfs_trans **tpp, struct xfs_buf *agibp) @@ -1733,30 +1733,18 @@ xfs_dialloc_roll( * Mode is used to tell whether the new inode will need space, and whether it * is a directory. * - * This function is designed to be called twice if it has to do an allocation - * to make more free inodes. On the first call, *IO_agbp should be set to NULL. - * If an inode is available without having to performn an allocation, an inode - * number is returned. In this case, *IO_agbp is set to NULL. If an allocation - * needs to be done, xfs_dialloc returns the current AGI buffer in *IO_agbp. - * The caller should then commit the current transaction, allocate a - * new transaction, and call xfs_dialloc() again, passing in the previous value - * of *IO_agbp. IO_agbp should be held across the transactions. Since the AGI - * buffer is locked across the two calls, the second call is guaranteed to have - * a free inode available. - * * Once we successfully pick an inode its number is returned and the on-disk * data structures are updated. The inode itself is not read in, since doing so * would break ordering constraints with xfs_reclaim. */ int xfs_dialloc( - struct xfs_trans *tp, + struct xfs_trans **tpp, xfs_ino_t parent, umode_t mode, - struct xfs_buf **IO_agbp, xfs_ino_t *inop) { - struct xfs_mount *mp = tp->t_mountp; + struct xfs_mount *mp = (*tpp)->t_mountp; struct xfs_buf *agbp; xfs_agnumber_t agno; int error; @@ -1767,21 +1755,11 @@ xfs_dialloc( struct xfs_ino_geometry *igeo = M_IGEO(mp); bool okalloc = true; - if (*IO_agbp) { - /* - * If the caller passes in a pointer to the AGI buffer, - * continue where we left off before. In this case, we - * know that the allocation group has free inodes. - */ - agbp = *IO_agbp; - goto out_alloc; - } - /* * We do not have an agbp, so select an initial allocation * group for inode allocation. */ - start_agno = xfs_ialloc_ag_select(tp, parent, mode); + start_agno = xfs_ialloc_ag_select(*tpp, parent, mode); if (start_agno == NULLAGNUMBER) { *inop = NULLFSINO; return 0; @@ -1816,7 +1794,7 @@ xfs_dialloc( } if (!pag->pagi_init) { - error = xfs_ialloc_pagi_init(mp, tp, agno); + error = xfs_ialloc_pagi_init(mp, *tpp, agno); if (error) goto out_error; } @@ -1831,7 +1809,7 @@ xfs_dialloc( * Then read in the AGI buffer and recheck with the AGI buffer * lock held. */ - error = xfs_ialloc_read_agi(mp, tp, agno, &agbp); + error = xfs_ialloc_read_agi(mp, *tpp, agno, &agbp); if (error) goto out_error; @@ -1844,9 +1822,9 @@ xfs_dialloc( goto nextag_relse_buffer; - error = xfs_ialloc_ag_alloc(tp, agbp, &ialloced); + error = xfs_ialloc_ag_alloc(*tpp, agbp, &ialloced); if (error) { - xfs_trans_brelse(tp, agbp); + xfs_trans_brelse(*tpp, agbp); if (error != -ENOSPC) goto out_error; @@ -1858,21 +1836,23 @@ xfs_dialloc( if (ialloced) { /* - * We successfully allocated some inodes, return - * the current context to the caller so that it - * can commit the current transaction and call - * us again where we left off. + * We successfully allocated some inodes, roll the + * transaction so they can allocate one of the free + * inodes we just prepared for them. */ ASSERT(pag->pagi_freecount > 0); xfs_perag_put(pag); - *IO_agbp = agbp; + error = xfs_dialloc_roll(tpp, agbp); + if (error) + return error; + *inop = NULLFSINO; - return 0; + goto out_alloc; } nextag_relse_buffer: - xfs_trans_brelse(tp, agbp); + xfs_trans_brelse(*tpp, agbp); nextag: xfs_perag_put(pag); if (++agno == mp->m_sb.sb_agcount) @@ -1884,8 +1864,7 @@ xfs_dialloc( } out_alloc: - *IO_agbp = NULL; - return xfs_dialloc_ag(tp, agbp, parent, inop); + return xfs_dialloc_ag(*tpp, agbp, parent, inop); out_error: xfs_perag_put(pag); return error; diff --git a/fs/xfs/libxfs/xfs_ialloc.h b/fs/xfs/libxfs/xfs_ialloc.h index a145e2a72530..13810ffe4af9 100644 --- a/fs/xfs/libxfs/xfs_ialloc.h +++ b/fs/xfs/libxfs/xfs_ialloc.h @@ -32,40 +32,20 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog); } -/* XXX: will be removed in the following patch */ -int -xfs_dialloc_roll( - struct xfs_trans **tpp, - struct xfs_buf *agibp); - /* * Allocate an inode on disk. * Mode is used to tell whether the new inode will need space, and whether * it is a directory. * - * To work within the constraint of one allocation per transaction, - * xfs_dialloc() is designed to be called twice if it has to do an - * allocation to make more free inodes. If an inode is - * available without an allocation, agbp would be set to the current - * agbp and alloc_done set to false. - * If an allocation needed to be done, agbp would be set to the - * inode header of the allocation group and alloc_done set to true. - * The caller should then commit the current transaction and allocate a new - * transaction. xfs_dialloc() should then be called again with - * the agbp value returned from the previous call. - * * Once we successfully pick an inode its number is returned and the * on-disk data structures are updated. The inode itself is not read * in, since doing so would break ordering constraints with xfs_reclaim. - * - * *agbp should be set to NULL on the first call, *alloc_done set to FALSE. */ int /* error */ xfs_dialloc( - struct xfs_trans *tp, /* transaction pointer */ + struct xfs_trans **tpp, /* double pointer of transaction */ xfs_ino_t parent, /* parent inode (directory) */ umode_t mode, /* mode bits for new inode */ - struct xfs_buf **agbp, /* buf for a.g. inode header */ xfs_ino_t *inop); /* inode number allocated */ /* diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 22843e81bccf..78ecfdf77320 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -909,7 +909,6 @@ xfs_dir_ialloc( locked. */ { xfs_inode_t *ip; - xfs_buf_t *ialloc_context = NULL; xfs_ino_t pino = dp ? dp->i_ino : 0; xfs_ino_t ino; int error; @@ -919,40 +918,12 @@ xfs_dir_ialloc( /* * Call the space management code to pick the on-disk inode to be - * allocated and replenish the freelist. Since we can only do one - * allocation per transaction without deadlocks, we will need to - * commit the current transaction and start a new one. - * If xfs_dialloc did an allocation to replenish the freelist, it - * returns the bp containing the head of the freelist as - * ialloc_context. We will hold a lock on it across the transaction - * commit so that no other process can steal the inode(s) that we've - * just allocated. - */ - error = xfs_dialloc(*tpp, pino, mode, &ialloc_context, &ino); + * allocated. + */ + error = xfs_dialloc(tpp, pino, mode, &ino); if (error) return error; - /* - * If the AGI buffer is non-NULL, then we were unable to get an - * inode in one operation. We need to commit the current - * transaction and call xfs_dialloc() again. It is guaranteed - * to succeed the second time. - */ - if (ialloc_context) { - error = xfs_dialloc_roll(tpp, ialloc_context); - if (error) - return error; - /* - * Call dialloc again. Since we've locked out all other - * allocations in this allocation group, this call should - * always succeed. - */ - error = xfs_dialloc(*tpp, pino, mode, &ialloc_context, &ino); - if (error) - return error; - ASSERT(!ialloc_context); - } - if (ino == NULLFSINO) return -ENOSPC; From patchwork Mon Dec 7 00:15:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11954673 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=-18.8 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 33575C4361B for ; Mon, 7 Dec 2020 00:18:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F300622E03 for ; Mon, 7 Dec 2020 00:18:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728321AbgLGASR (ORCPT ); Sun, 6 Dec 2020 19:18:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31582 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbgLGASR (ORCPT ); Sun, 6 Dec 2020 19:18:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607300209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=6z9vIoekncYlBCuZ/VLdBFG/yEXreA5yd+jeTFL6/Wg=; b=hQFgRFSElQK5KRpwPidsAPyydYMq/zUfTI+idPkrjeB271JdMF4JNWbfC6I8yhAc3ydF4P UGyrghJm8BFmvjJhIAsEIlosEDmuA13b9hDMQC8CGBKnV2XeMGg19HyoCX2CvwrONx3zcu 44holJhOm5elBwrC8Xlnvel2c276kfk= Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-159-HSmOgYIaMY6MjHOADeDPIw-1; Sun, 06 Dec 2020 19:16:48 -0500 X-MC-Unique: HSmOgYIaMY6MjHOADeDPIw-1 Received: by mail-pg1-f198.google.com with SMTP id z2so7293029pgb.23 for ; Sun, 06 Dec 2020 16:16:48 -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; bh=6z9vIoekncYlBCuZ/VLdBFG/yEXreA5yd+jeTFL6/Wg=; b=OHxEmXkjaPXgTX6t4+cScDNlZFa+gFSVEKg1E4jZ4efDr8WRWtbzGYZX2+XtRbGalx U1Gx8Qt4XyWEpuakNzQoiu9O1QU7oZYNEPZLD8eFvKnJmyVbWbtSTCdB73Da6iKE7GRZ kh/aor537qSnCIbc4aDp3mTrt/HO1B20L0nWyAJ00jSHYQB8grhfnbmoMFAzWjX1LKVv PZ8UoRvvVZmjpEYtZHqAgTyhtQYikSFaQ0SG/TuJrdqT6GF0DBwuOZhXeOXuJDL1C+5c ziqdRyFPmAPJnwEXG58824fqGfi+qS8x3Nm6n1i609Tj0Mu6SlJNn+O5E5rLjfegBCm2 85zQ== X-Gm-Message-State: AOAM530gv2imzgWx5xgwcSYJ03SCOm5iZV7vXqyjIS+7PK/mtUBA57OU 4iiFqjCUHdHzj32vVD21hhdI+HwP+GXCbAHZY9yr9qRNEMqw/duFZDTxjfanWMwRf5zWX3bOCr7 RCK21WtELbHFiKDe/EImISGJVvZBbciSCyyeNOuuRAl1FRna9gnOgRXSV+jg/YVlbVGL6C3a4GQ == X-Received: by 2002:a65:6a4e:: with SMTP id o14mr16299048pgu.65.1607300206914; Sun, 06 Dec 2020 16:16:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQef+6TMtnj68TtvaGsbWSQ6iTNLvmygxas6QifGbu+8dwEcStA382CldSHpMCXgobt4Y/3Q== X-Received: by 2002:a65:6a4e:: with SMTP id o14mr16299014pgu.65.1607300206390; Sun, 06 Dec 2020 16:16:46 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o9sm8218056pjl.11.2020.12.06.16.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2020 16:16:46 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Dave Chinner , Christoph Hellwig , Eric Sandeen , Dave Chinner , Gao Xiang Subject: [PATCH v3 5/6] xfs: spilt xfs_dialloc() into 2 functions Date: Mon, 7 Dec 2020 08:15:32 +0800 Message-Id: <20201207001533.2702719-6-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201207001533.2702719-1-hsiangkao@redhat.com> References: <20201207001533.2702719-1-hsiangkao@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Dave Chinner This patch explicitly separates free inode chunk allocation and inode allocation into two individual high level operations. Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_ialloc.c | 59 +++++++++++++++++--------------------- fs/xfs/libxfs/xfs_ialloc.h | 20 +++++++++---- fs/xfs/xfs_inode.c | 19 ++++++++---- 3 files changed, 55 insertions(+), 43 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index b00bbd680177..527f17f09bd3 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -1570,7 +1570,7 @@ xfs_dialloc_ag_update_inobt( * The caller selected an AG for us, and made sure that free inodes are * available. */ -STATIC int +int xfs_dialloc_ag( struct xfs_trans *tp, struct xfs_buf *agbp, @@ -1728,21 +1728,22 @@ xfs_dialloc_roll( } /* - * Allocate an inode on disk. + * Select and prepare an AG for inode allocation. * - * Mode is used to tell whether the new inode will need space, and whether it - * is a directory. + * Mode is used to tell whether the new inode is a directory and hence where to + * locate it. * - * Once we successfully pick an inode its number is returned and the on-disk - * data structures are updated. The inode itself is not read in, since doing so - * would break ordering constraints with xfs_reclaim. + * This function will ensure that the selected AG has free inodes available to + * allocate from. The selected AGI will be returned locked to the caller, and it + * will allocate more free inodes if required. If no free inodes are found or + * can be allocated, no AGI will be returned. */ int -xfs_dialloc( +xfs_dialloc_select_ag( struct xfs_trans **tpp, xfs_ino_t parent, umode_t mode, - xfs_ino_t *inop) + struct xfs_buf **IO_agbp) { struct xfs_mount *mp = (*tpp)->t_mountp; struct xfs_buf *agbp; @@ -1755,15 +1756,15 @@ xfs_dialloc( struct xfs_ino_geometry *igeo = M_IGEO(mp); bool okalloc = true; + *IO_agbp = NULL; + /* * We do not have an agbp, so select an initial allocation * group for inode allocation. */ start_agno = xfs_ialloc_ag_select(*tpp, parent, mode); - if (start_agno == NULLAGNUMBER) { - *inop = NULLFSINO; + if (start_agno == NULLAGNUMBER) return 0; - } /* * If we have already hit the ceiling of inode blocks then clear @@ -1796,7 +1797,7 @@ xfs_dialloc( if (!pag->pagi_init) { error = xfs_ialloc_pagi_init(mp, *tpp, agno); if (error) - goto out_error; + break; } /* @@ -1811,11 +1812,12 @@ xfs_dialloc( */ error = xfs_ialloc_read_agi(mp, *tpp, agno, &agbp); if (error) - goto out_error; + break; if (pag->pagi_freecount) { xfs_perag_put(pag); - goto out_alloc; + *IO_agbp = agbp; + return 0; } if (!okalloc) @@ -1826,19 +1828,17 @@ xfs_dialloc( if (error) { xfs_trans_brelse(*tpp, agbp); - if (error != -ENOSPC) - goto out_error; - - xfs_perag_put(pag); - *inop = NULLFSINO; - return 0; + if (error == -ENOSPC) + error = 0; + break; } if (ialloced) { /* - * We successfully allocated some inodes, roll the - * transaction so they can allocate one of the free - * inodes we just prepared for them. + * We successfully allocated some inodes, so roll the + * transaction and return the locked AGI buffer to the + * caller so they can allocate one of the free inodes we + * just prepared for them. */ ASSERT(pag->pagi_freecount > 0); xfs_perag_put(pag); @@ -1847,8 +1847,8 @@ xfs_dialloc( if (error) return error; - *inop = NULLFSINO; - goto out_alloc; + *IO_agbp = agbp; + return 0; } nextag_relse_buffer: @@ -1857,15 +1857,10 @@ xfs_dialloc( xfs_perag_put(pag); if (++agno == mp->m_sb.sb_agcount) agno = 0; - if (agno == start_agno) { - *inop = NULLFSINO; + if (agno == start_agno) return noroom ? -ENOSPC : 0; - } } -out_alloc: - return xfs_dialloc_ag(*tpp, agbp, parent, inop); -out_error: xfs_perag_put(pag); return error; } diff --git a/fs/xfs/libxfs/xfs_ialloc.h b/fs/xfs/libxfs/xfs_ialloc.h index 13810ffe4af9..3511086a7ae1 100644 --- a/fs/xfs/libxfs/xfs_ialloc.h +++ b/fs/xfs/libxfs/xfs_ialloc.h @@ -37,16 +37,26 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) * Mode is used to tell whether the new inode will need space, and whether * it is a directory. * - * Once we successfully pick an inode its number is returned and the - * on-disk data structures are updated. The inode itself is not read - * in, since doing so would break ordering constraints with xfs_reclaim. + * There are two phases to inode allocation: selecting an AG and ensuring + * that it contains free inodes, followed by allocating one of the free + * inodes. xfs_dialloc_select_ag() does the former and returns a locked AGI + * to the caller, ensuring that followup call to xfs_dialloc_ag() will + * have free inodes to allocate from. xfs_dialloc_ag() will return the inode + * number of the free inode we allocated. */ int /* error */ -xfs_dialloc( +xfs_dialloc_select_ag( struct xfs_trans **tpp, /* double pointer of transaction */ xfs_ino_t parent, /* parent inode (directory) */ umode_t mode, /* mode bits for new inode */ - xfs_ino_t *inop); /* inode number allocated */ + struct xfs_buf **IO_agbp); + +int +xfs_dialloc_ag( + struct xfs_trans *tp, + struct xfs_buf *agbp, + xfs_ino_t parent, + xfs_ino_t *inop); /* * Free disk inode. Carefully avoids touching the incore inode, all diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 78ecfdf77320..90dadf862b3a 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -908,10 +908,11 @@ xfs_dir_ialloc( xfs_inode_t **ipp) /* pointer to inode; it will be locked. */ { - xfs_inode_t *ip; - xfs_ino_t pino = dp ? dp->i_ino : 0; - xfs_ino_t ino; - int error; + struct xfs_buf *agibp; + struct xfs_inode *ip; + xfs_ino_t pino = dp ? dp->i_ino : 0; + xfs_ino_t ino; + int error; ASSERT((*tpp)->t_flags & XFS_TRANS_PERM_LOG_RES); *ipp = NULL; @@ -920,13 +921,19 @@ xfs_dir_ialloc( * Call the space management code to pick the on-disk inode to be * allocated. */ - error = xfs_dialloc(tpp, pino, mode, &ino); + error = xfs_dialloc_select_ag(tpp, pino, mode, &agibp); if (error) return error; - if (ino == NULLFSINO) + if (!agibp) return -ENOSPC; + /* Allocate an inode from the selected AG */ + error = xfs_dialloc_ag(*tpp, agibp, pino, &ino); + if (error) + return error; + ASSERT(ino != NULLFSINO); + /* Initialise the newly allocated inode. */ ip = xfs_dir_ialloc_init(*tpp, dp, ino, mode, nlink, rdev, prid); if (IS_ERR(ip)) From patchwork Mon Dec 7 00:15:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11954675 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=-18.8 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, 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 EECCEC433FE for ; Mon, 7 Dec 2020 00:18:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C31B322E03 for ; Mon, 7 Dec 2020 00:18:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728338AbgLGASU (ORCPT ); Sun, 6 Dec 2020 19:18:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54409 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbgLGASU (ORCPT ); Sun, 6 Dec 2020 19:18:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607300213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=V/FQM7+BNIZb8xy/yAEOGBR4rK3IjDnj432W9+MGeq4=; b=VnMgp8z+JQ0Pbo3ykv77Q5/ZJY73/BR9Jlya0+1aYZFCiGl3t2yGLm9SY81LU37jjHufJY 0XBxjDVDhK5BjRiSpOvWVs90nVv2cVKbsNWNGYL4cpmFTPB5Q7kjVo+LuKr/h26KnkfnDt AOxWCUcOmLvytm5bPAGsQLQfTz5kCEc= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-4ctzrekqPquDb4p2qJBmkw-1; Sun, 06 Dec 2020 19:16:51 -0500 X-MC-Unique: 4ctzrekqPquDb4p2qJBmkw-1 Received: by mail-pj1-f69.google.com with SMTP id gv14so8054581pjb.1 for ; Sun, 06 Dec 2020 16:16:51 -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; bh=V/FQM7+BNIZb8xy/yAEOGBR4rK3IjDnj432W9+MGeq4=; b=DURmmNMI7Dm0O0xEEHnDHIyDhctzDwvgHh443d2lWvjH2kP1eoKQEjL3pB46RD5an3 rArfsJA3FJSx5T1dvVvpejuxPAhCuJXWKPBHQ084DfClvSwsyHC2OgdxEG4kmddHowFd CAjECfkRatBWefaeQl8LXDz9Z6uTr90t7aKppM3J+7iErhwqln4PQcboaNulZ5RabVg8 1RWlzBl2pdkXw6E2zQMFY7hBOZB+T9IsFE513Kp+3PeSBrvgthmOn14Hj5loaupBeRBi /P6G6FmngIIjhRueVyowgHpW9KXb2oaqW88nMUQGp+5JP4fHsr3xfhDEvASixYQ6zZbd 2gLw== X-Gm-Message-State: AOAM530ifwGNSd5Krt6H8y6GOGu6l9G93dLwpmw9K0WKFf29Knz3vGrb qA0pwcw032c0GmxY28c8A8S7nwBmtQRyjGgF9HWmslShvL19MIR6luGEw66REgPR7hTvqH8hmmy mgSDeI9jH+4wU2uy3lmG+h5A7vPkEnDQP6Ms/ddcXqyKCauTlSS4kUQJuclJ6rfyNBbzRUfJBOQ == X-Received: by 2002:a17:90a:fa0c:: with SMTP id cm12mr14239261pjb.87.1607300210698; Sun, 06 Dec 2020 16:16:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBfzhn/az6pMcNfySeI4XEUwIOiRduKJKkuvYOjGIWHjTYScAXBZhFcmso7RVultU5x21PiQ== X-Received: by 2002:a17:90a:fa0c:: with SMTP id cm12mr14239246pjb.87.1607300210382; Sun, 06 Dec 2020 16:16:50 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o9sm8218056pjl.11.2020.12.06.16.16.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2020 16:16:50 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Dave Chinner , Christoph Hellwig , Eric Sandeen , Gao Xiang Subject: [PATCH v3 6/6] xfs: kill ialloced in xfs_dialloc() Date: Mon, 7 Dec 2020 08:15:33 +0800 Message-Id: <20201207001533.2702719-7-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201207001533.2702719-1-hsiangkao@redhat.com> References: <20201207001533.2702719-1-hsiangkao@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org It's enough to just use return code, and get rid of an argument. Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ialloc.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 527f17f09bd3..a0e6e333eea2 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -607,13 +607,13 @@ xfs_inobt_insert_sprec( /* * Allocate new inodes in the allocation group specified by agbp. - * Return 0 for success, else error code. + * Returns 0 if inodes were allocated in this AG; 1 if there was no space + * in this AG; or the usual negative error code. */ STATIC int xfs_ialloc_ag_alloc( struct xfs_trans *tp, - struct xfs_buf *agbp, - int *alloc) + struct xfs_buf *agbp) { struct xfs_agi *agi; struct xfs_alloc_arg args; @@ -795,10 +795,9 @@ xfs_ialloc_ag_alloc( allocmask = (1 << (newlen / XFS_INODES_PER_HOLEMASK_BIT)) - 1; } - if (args.fsbno == NULLFSBLOCK) { - *alloc = 0; - return 0; - } + if (args.fsbno == NULLFSBLOCK) + return 1; + ASSERT(args.len == args.minlen); /* @@ -903,7 +902,6 @@ xfs_ialloc_ag_alloc( */ xfs_trans_mod_sb(tp, XFS_TRANS_SB_ICOUNT, (long)newlen); xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, (long)newlen); - *alloc = 1; return 0; } @@ -1749,7 +1747,6 @@ xfs_dialloc_select_ag( struct xfs_buf *agbp; xfs_agnumber_t agno; int error; - int ialloced; bool noroom = false; xfs_agnumber_t start_agno; struct xfs_perag *pag; @@ -1823,17 +1820,14 @@ xfs_dialloc_select_ag( if (!okalloc) goto nextag_relse_buffer; - - error = xfs_ialloc_ag_alloc(*tpp, agbp, &ialloced); - if (error) { + error = xfs_ialloc_ag_alloc(*tpp, agbp); + if (error < 0) { xfs_trans_brelse(*tpp, agbp); if (error == -ENOSPC) error = 0; break; - } - - if (ialloced) { + } else if (error == 0) { /* * We successfully allocated some inodes, so roll the * transaction and return the locked AGI buffer to the