From patchwork Wed Dec 9 11:28:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11961155 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 2DE7CC2BB40 for ; Wed, 9 Dec 2020 11:30:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 194CD23B81 for ; Wed, 9 Dec 2020 11:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730763AbgLILau (ORCPT ); Wed, 9 Dec 2020 06:30:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20149 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729260AbgLILau (ORCPT ); Wed, 9 Dec 2020 06:30:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607513364; 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=DgvAFx7DbGS/+nMB2fwpoXH399kfy9Qoolk1LKShHv8=; b=S3peN4cWwhtF6GwdWFwaPGb1RppCRfdsyE2HZN9i0qwGW1/wfee3IT7X7bxR/4LkC0eRke wlP3dzSbWMIEv0WwaVIF6h1rvtCUIILZFDdxfheaVwD2l8jxJLkB+2T9Dxrx0Zoo2+9i5G GacQMBF/m1ElY64hLC3uUJRjD+XrxpI= 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-29-Asq7Jft7N5C-397yHb8AfQ-1; Wed, 09 Dec 2020 06:29:23 -0500 X-MC-Unique: Asq7Jft7N5C-397yHb8AfQ-1 Received: by mail-pg1-f198.google.com with SMTP id j4so880628pgi.21 for ; Wed, 09 Dec 2020 03:29:22 -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=DgvAFx7DbGS/+nMB2fwpoXH399kfy9Qoolk1LKShHv8=; b=ifJDtxE/Sat4aIKVCDUF4gBj8bBjsgycrcB2oBpYayn139MhAPfHso1BqC4NPJzUNB lxx4/cfAFNqXwozZxoNc9nAqtOeShxcM4jy1mzlbeNcank1Fvjkqrxg8Aq/H/BAtdaNe qk4wuklWsyoXBPtXwpHuRVR2zOHua/g56y66sr6cQqyS27TBzIcAWa6TyWrM4Yw+0iqt uvGBUjn6AjG4YZOurnVcC//a7TwU2rzv+1kL2ciHVYdIw5cqcw5R2FwVBbMWyqAuoHoK fCLYPEsUhTjhktNrv+dh+0w+LvZ6uimrtD538W6Jlw/qv8enc20YZhm7CTTElnvHsDQC ommA== X-Gm-Message-State: AOAM531gjFDMO0g29ms/ep36aRziq8s2thk+qgrUmNkPFphFFS2DSb0O lIby96TTMGLaaPWAE2epOedGw/wUFQTuqXCNKbWF0O2QQEi0dlBDTCp5L9PIz1Ay5t81JWoSrta 39IgSyB3zaXmbtRZGkxtREtEMux55FfNI6cMqi1ttW0KwWJytitA3CVJgl56m3jL0Dh9fA0DI7g == X-Received: by 2002:a17:90a:5509:: with SMTP id b9mr1843510pji.53.1607513361865; Wed, 09 Dec 2020 03:29:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvoXIi+qQWRB3/txN1Ld9e1AFanec+ne3mccuZ5NmV789OZWzXBJSEd9CD/QTuqIzhGfGNRw== X-Received: by 2002:a17:90a:5509:: with SMTP id b9mr1843490pji.53.1607513361618; Wed, 09 Dec 2020 03:29:21 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y5sm2231280pfp.45.2020.12.09.03.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:29:21 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Dave Chinner , Christoph Hellwig , Eric Sandeen , Gao Xiang , Dave Chinner Subject: [PATCH v5 1/6] xfs: convert noroom, okalloc in xfs_dialloc() to bool Date: Wed, 9 Dec 2020 19:28:15 +0800 Message-Id: <20201209112820.114863-2-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201209112820.114863-1-hsiangkao@redhat.com> References: <20201209112820.114863-1-hsiangkao@redhat.com> MIME-Version: 1.0 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 Wed Dec 9 11:28:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11961157 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 E1E45C1B0D8 for ; Wed, 9 Dec 2020 11:30:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE6CD23B77 for ; Wed, 9 Dec 2020 11:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730765AbgLILa4 (ORCPT ); Wed, 9 Dec 2020 06:30:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32401 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729260AbgLILa4 (ORCPT ); Wed, 9 Dec 2020 06:30:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607513369; 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=CcBzLVl1B0hB409MFh3hNt3GjsIOtwUEc3hmbVI40Fg=; b=haCfijjOQ0PHhYC0f7jVcHeMc8nlp+iihCaZ8BR2J/7/UA4f8/n6U17raFeBqeE3ziM959 eJqUdL2ZE9UXKoFfPw77m93HoXs3fDny3FOA2lSuaU05y02GRkR/sXVZD0wnPACvOSwPSU fi1cObn4taLhzTFrYj64QXM7Rbi3cbM= 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-187-PHQRoZTqP-G9zATO3tiSpw-1; Wed, 09 Dec 2020 06:29:27 -0500 X-MC-Unique: PHQRoZTqP-G9zATO3tiSpw-1 Received: by mail-pl1-f198.google.com with SMTP id x17so642711pll.8 for ; Wed, 09 Dec 2020 03:29:27 -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=CcBzLVl1B0hB409MFh3hNt3GjsIOtwUEc3hmbVI40Fg=; b=NehG4HpY7HV1M5OBZjTfhHNBbtB3SfZR0QBneZHw3AfMK3Tgi/fKfoZk2OFUCNj1Ni 07dvsTdYX+E7P93AMTP6Hp1BPdgksAbVCum8h9f51P1fnAtuLo+hmh9FwYSA9W4TJHyg iAfPwjBnQY5CP6tVOzbdYZnpRToIgPebNuxqwl9Txxn2pH1DI1jfwTpVeyPWYKClgZMn Hipb0/5/UA5dONcAKWlmu9QrNTPpM7x8yOzkEc1Ba2FLxsPOaYr9yd3pKUxcA8z7AAfJ q1wCC+Pp4hiXV+XZlShUZ77UlCO19B47m2aEwqaxtfTQSjL/WK1gU4ai1GakNN+Xxmui YYsw== X-Gm-Message-State: AOAM533hLQn/5N5silPNT6+1KoUQVAjcFica69n+STiEcCbsDCkzIW57 T3XxIFOW7tgCOMuEaPoKhPl0bgoItrxytLh+NTDuCDm/Zqy8TEBpYr7dEBD3/AVZDpR/GmyYd0V HdVxOtLe9sJcIwgqnX0aNrmIuHPXPR6N9CBh3+gnT6rtvUSCXrwgQqQZqYYwqqh//INUAVNAIJg == X-Received: by 2002:a62:764a:0:b029:19d:9fa8:5bc6 with SMTP id r71-20020a62764a0000b029019d9fa85bc6mr1920636pfc.76.1607513366709; Wed, 09 Dec 2020 03:29:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+4fyeTAwxQeW2bffBIEVA8nhNOfKxzA1Dxgqjvh4sb8Fcf1riO5hDSi5t5iDDj03Qg5ywFA== X-Received: by 2002:a62:764a:0:b029:19d:9fa8:5bc6 with SMTP id r71-20020a62764a0000b029019d9fa85bc6mr1920603pfc.76.1607513366369; Wed, 09 Dec 2020 03:29:26 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y5sm2231280pfp.45.2020.12.09.03.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:29:25 -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 v5 2/6] xfs: introduce xfs_dialloc_roll() Date: Wed, 9 Dec 2020 19:28:16 +0800 Message-Id: <20201209112820.114863-3-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201209112820.114863-1-hsiangkao@redhat.com> References: <20201209112820.114863-1-hsiangkao@redhat.com> MIME-Version: 1.0 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. Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ialloc.c | 43 ++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_ialloc.h | 5 +++++ fs/xfs/xfs_inode.c | 37 +------------------------------- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 45cf7e55f5ee..23e94d43acb2 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -1682,6 +1682,49 @@ 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) + 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..bd6e0db9e23c 100644 --- a/fs/xfs/libxfs/xfs_ialloc.h +++ b/fs/xfs/libxfs/xfs_ialloc.h @@ -32,6 +32,11 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog); } +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..76282da7a05c 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,13 @@ 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 From patchwork Wed Dec 9 11:28:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11961159 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 1720CC433FE for ; Wed, 9 Dec 2020 11:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA04323B23 for ; Wed, 9 Dec 2020 11:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730766AbgLILbD (ORCPT ); Wed, 9 Dec 2020 06:31:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20060 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729260AbgLILbD (ORCPT ); Wed, 9 Dec 2020 06:31:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607513374; 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=+RsZ/MAJLT+7nYLqFrps7ZzthxWr7P9CynxskgXopO8=; b=b9vGtN4RaXlGfo2aYPLAdepHM0FAkIBU8uLnjQjb87KX1yK5OcHjWIZFZzZiBnEnCHRLS1 uX6jVUSCKc1TSt3OLdhuB2Z+6dSqoa2Rn9qhQE9bEkEiRmpJLRNFN0/nSr+hsQBk+DJtX3 Z+OOL/7R2XyPwLmd11IfsmkEqP4H0qE= 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-13-Ny4xyFgLMOm1RnCxfnlp4A-1; Wed, 09 Dec 2020 06:29:33 -0500 X-MC-Unique: Ny4xyFgLMOm1RnCxfnlp4A-1 Received: by mail-pf1-f197.google.com with SMTP id r15so902894pfg.5 for ; Wed, 09 Dec 2020 03:29:33 -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=+RsZ/MAJLT+7nYLqFrps7ZzthxWr7P9CynxskgXopO8=; b=SlErhq7uYq/tFe6GlSg6EJeyRQXp3aISrC3eo+tf5hrGriiXJfLX27SEmNltGXwGcC YrMPpMN82YVQ+QixY68LA1K3/oC/XTC1SJp9Ogj9j2Luh0uwM5kqHdpJIzsycpCPlVAi W0gTFZTGEUWqfhibdpaL30cNWlB+ntDnAur89h0NLRBAHZxOJuK/rQnGXD442G3nuGhn /264qFacTZ1k0PUqwklL1e3hcALIYGl13OHYhb+o2LELQ0FWRztKFeouuwwPZTHron1F /P3UyJqOJfM/bjG49Sx4I0+oXt6MeJgTOp92NfcMgZ8JEEWj0JDWdseFDjfLcHoh0tpr QU3Q== X-Gm-Message-State: AOAM531p03JmtkU5wnn5VMfK7ppZtccwmAckHMa7cDB9PU23C6oQelPS ggczEzicOvKTwMYgMPIOTFPSazVLdFyZp1cxhrfANuCMkeAJ0mxz9La8+J1GS5T2zOGYt/cQURO QOHY/Xsn1+cCmWyxwzCdLvq+MWLT6bx3HcfY+Zs8bL8dJdu1GCQ58oGNkjsY0qrNd4D7joQQ2JQ == X-Received: by 2002:a62:cec1:0:b029:19e:5605:36a0 with SMTP id y184-20020a62cec10000b029019e560536a0mr1847538pfg.27.1607513371661; Wed, 09 Dec 2020 03:29:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQKqfHsji4c1bV1WMQXGMc/j+EdhnbtZ2XOYWLOdbRyY4JyO2LyJnCZ5JhzO1mGwaTCbmLjA== X-Received: by 2002:a62:cec1:0:b029:19e:5605:36a0 with SMTP id y184-20020a62cec10000b029019e560536a0mr1847492pfg.27.1607513371057; Wed, 09 Dec 2020 03:29:31 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y5sm2231280pfp.45.2020.12.09.03.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:29:30 -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 v5 3/6] xfs: move on-disk inode allocation out of xfs_ialloc() Date: Wed, 9 Dec 2020 19:28:17 +0800 Message-Id: <20201209112820.114863-4-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201209112820.114863-1-hsiangkao@redhat.com> References: <20201209112820.114863-1-hsiangkao@redhat.com> MIME-Version: 1.0 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 Reviewed-by: Christoph Hellwig Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang --- fs/xfs/xfs_inode.c | 219 +++++++++++++++---------------------------- fs/xfs/xfs_inode.h | 6 +- fs/xfs/xfs_qm.c | 27 +++--- fs/xfs/xfs_symlink.c | 8 +- 4 files changed, 97 insertions(+), 163 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 76282da7a05c..07d692020da3 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_init_new_inode( + 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,22 +881,21 @@ 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 +struct xfs_inode * xfs_dir_ialloc( xfs_trans_t **tpp, /* input: current transaction; output: may be a new transaction. */ @@ -950,90 +904,59 @@ xfs_dir_ialloc( umode_t mode, xfs_nlink_t nlink, dev_t rdev, - prid_t prid, /* project id */ - xfs_inode_t **ipp) /* pointer to inode; it will be - locked. */ + prid_t prid) /* project id */ { - 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 parent_ino = 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); /* - * 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, parent_ino, mode, &ialloc_context, &ino); + if (error) + return ERR_PTR(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) { + error = xfs_dialloc_roll(tpp, ialloc_context); + if (error) { xfs_buf_relse(ialloc_context); - *tpp = tp; - *ipp = NULL; - return code; + return ERR_PTR(error); } - /* - * Call ialloc again. Since we've locked out all - * other allocations in this allocation group, - * this call should always succeed. + * Call dialloc 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); - - /* - * If we get an error at this point, return to the caller - * so that the current transaction can be aborted. - */ - if (code) { - *tpp = tp; - *ipp = NULL; - return code; - } - ASSERT(!ialloc_context && ip); - + error = xfs_dialloc(*tpp, parent_ino, mode, + &ialloc_context, &ino); + if (error) + return ERR_PTR(error); + ASSERT(!ialloc_context); } - *ipp = ip; - *tpp = tp; + if (ino == NULLFSINO) + return ERR_PTR(-ENOSPC); - return 0; + return xfs_init_new_inode(*tpp, dp, ino, mode, nlink, rdev, prid); } /* @@ -1147,9 +1070,12 @@ xfs_create( * entry pointing to them, but a directory also the "." entry * pointing to itself. */ - error = xfs_dir_ialloc(&tp, dp, mode, is_dir ? 2 : 1, rdev, prid, &ip); - if (error) + ip = xfs_dir_ialloc(&tp, dp, mode, is_dir ? 2 : 1, rdev, prid); + if (IS_ERR(ip)) { + error = PTR_ERR(ip); + ip = NULL; goto out_trans_cancel; + } /* * Now we join the directory inode to the transaction. We do not do it @@ -1269,9 +1195,12 @@ xfs_create_tmpfile( if (error) goto out_trans_cancel; - error = xfs_dir_ialloc(&tp, dp, mode, 0, 0, prid, &ip); - if (error) + ip = xfs_dir_ialloc(&tp, dp, mode, 0, 0, prid); + if (IS_ERR(ip)) { + error = PTR_ERR(ip); + ip = NULL; goto out_trans_cancel; + } if (mp->m_flags & XFS_MOUNT_WSYNC) xfs_trans_set_sync(tp); diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 751a3d1d7d84..95b4ae35e6df 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -407,9 +407,9 @@ void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode, xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip); xfs_extlen_t xfs_get_cowextsz_hint(struct xfs_inode *ip); -int xfs_dir_ialloc(struct xfs_trans **, struct xfs_inode *, umode_t, - xfs_nlink_t, dev_t, prid_t, - struct xfs_inode **); +struct xfs_inode * +xfs_dir_ialloc(struct xfs_trans **, struct xfs_inode *, umode_t, xfs_nlink_t, + dev_t, prid_t); static inline int xfs_itruncate_extents( diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index b2a9abee8b2b..bfdf71d87777 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -737,15 +737,15 @@ xfs_qm_destroy_quotainfo( */ STATIC int xfs_qm_qino_alloc( - xfs_mount_t *mp, - xfs_inode_t **ip, - uint flags) + struct xfs_mount *mp, + struct xfs_inode **ipp, + unsigned int flags) { xfs_trans_t *tp; int error; bool need_alloc = true; - *ip = NULL; + *ipp = NULL; /* * With superblock that doesn't have separate pquotino, we * share an inode between gquota and pquota. If the on-disk @@ -771,7 +771,7 @@ xfs_qm_qino_alloc( return -EFSCORRUPTED; } if (ino != NULLFSINO) { - error = xfs_iget(mp, NULL, ino, 0, 0, ip); + error = xfs_iget(mp, NULL, ino, 0, 0, ipp); if (error) return error; mp->m_sb.sb_gquotino = NULLFSINO; @@ -787,11 +787,14 @@ xfs_qm_qino_alloc( return error; if (need_alloc) { - error = xfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0, 0, ip); - if (error) { + struct xfs_inode *ip; + + ip = xfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0, 0); + if (IS_ERR(ip)) { xfs_trans_cancel(tp); - return error; + return PTR_ERR(ip); } + *ipp = ip; } /* @@ -812,11 +815,11 @@ xfs_qm_qino_alloc( mp->m_sb.sb_qflags = mp->m_qflags & XFS_ALL_QUOTA_ACCT; } if (flags & XFS_QMOPT_UQUOTA) - mp->m_sb.sb_uquotino = (*ip)->i_ino; + mp->m_sb.sb_uquotino = (*ipp)->i_ino; else if (flags & XFS_QMOPT_GQUOTA) - mp->m_sb.sb_gquotino = (*ip)->i_ino; + mp->m_sb.sb_gquotino = (*ipp)->i_ino; else - mp->m_sb.sb_pquotino = (*ip)->i_ino; + mp->m_sb.sb_pquotino = (*ipp)->i_ino; spin_unlock(&mp->m_sb_lock); xfs_log_sb(tp); @@ -826,7 +829,7 @@ xfs_qm_qino_alloc( xfs_alert(mp, "%s failed (error %d)!", __func__, error); } if (need_alloc) - xfs_finish_inode_setup(*ip); + xfs_finish_inode_setup(*ipp); return error; } diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 8e88a7ca387e..988fc771f089 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -223,10 +223,12 @@ xfs_symlink( /* * Allocate an inode for the symlink. */ - error = xfs_dir_ialloc(&tp, dp, S_IFLNK | (mode & ~S_IFMT), 1, 0, - prid, &ip); - if (error) + ip = xfs_dir_ialloc(&tp, dp, S_IFLNK | (mode & ~S_IFMT), 1, 0, prid); + if (IS_ERR(ip)) { + error = PTR_ERR(ip); + ip = NULL; goto out_trans_cancel; + } /* * Now we join the directory inode to the transaction. We do not do it From patchwork Wed Dec 9 11:28:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11961161 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 C2D1FC4361B for ; Wed, 9 Dec 2020 11:31:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9819123B23 for ; Wed, 9 Dec 2020 11:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730549AbgLILbG (ORCPT ); Wed, 9 Dec 2020 06:31:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38007 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729260AbgLILbF (ORCPT ); Wed, 9 Dec 2020 06:31:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607513378; 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=TRdMHyIHJCNXWPPhu6We2FinOTnf1YC7crLImE4NSQw=; b=NNRsaL+z/B2YMn/05wfXSIXDbfqmdlDchHbYU/1AdhqEh6gFrD1qABqBZBbQDali+SbIEK 9GJGtTa5XBNvb+JpIXfK/70pCBDreYCQu6vEsJNpXXnSfy9o76r8dhWY3rP03NfE91vfnA vpqkh5+YVneOLRcgO0eSQgeOqLZQqkc= 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-98-cO9wsHfjOVSHsCQASvL4VQ-1; Wed, 09 Dec 2020 06:29:37 -0500 X-MC-Unique: cO9wsHfjOVSHsCQASvL4VQ-1 Received: by mail-pf1-f197.google.com with SMTP id q22so872174pfj.20 for ; Wed, 09 Dec 2020 03:29:37 -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=TRdMHyIHJCNXWPPhu6We2FinOTnf1YC7crLImE4NSQw=; b=Xe66cAxXAzK2vKxVcXi4A1UtQOE+nPQJKMdoIovp8XyXVaum/xCluwkDFElxO7+H6T F51wcsgAA3blGSPndwKjMs3jiYssZceFqEmHPOByZ5IU2np9OMJXMRh0/9BMNR7TO2Qp MI3h1ZhXIy06fRaIcyyctGhyAPo/3BbyEo/PCgMnjUt69jZE1SkHpTKkJS5GVT86NDhp z0dmAVtfvQ0EOp99Oaa0KHKWbX88M8djP3kS/RGBM+jPmcXg15kEm6TO6XqC3dNkI6lU M9OaXJPAEAAejgBTr8URgJ/TkUbcODcKEeQYfm8IHafuLGyq5ithjPaGVG7vY+VXXnQt l0AA== X-Gm-Message-State: AOAM533j/ONAzGE2EDG23wXzq784vVHcC7tTq9rnwzDdVdetcbt9+L6F RFLgNwKQ+9ZPqPWKlV9Eu7DxJH5hFofw/4f4KUXu9w+sTyI1NWwrvk5TKKAGwhHt9rAflrReimo jXe6MzaZGmgPa9gruh74aGmef4Q1qjjSLd6CAHY6bkoCN9emW53vjUv+zjwlRvWmcl5xBjIsC/Q == X-Received: by 2002:a62:6844:0:b029:198:4f13:e9b2 with SMTP id d65-20020a6268440000b02901984f13e9b2mr1958733pfc.29.1607513376247; Wed, 09 Dec 2020 03:29:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzL5VS0iACBAypiRVmR2EdgEaDhoU872BeVzeYI7/AXtfw4Yz18wJgssmUbkP6ij4mqc7vLwg== X-Received: by 2002:a62:6844:0:b029:198:4f13:e9b2 with SMTP id d65-20020a6268440000b02901984f13e9b2mr1958691pfc.29.1607513375764; Wed, 09 Dec 2020 03:29:35 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y5sm2231280pfp.45.2020.12.09.03.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:29:35 -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 v5 4/6] xfs: move xfs_dialloc_roll() into xfs_dialloc() Date: Wed, 9 Dec 2020 19:28:18 +0800 Message-Id: <20201209112820.114863-5-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201209112820.114863-1-hsiangkao@redhat.com> References: <20201209112820.114863-1-hsiangkao@redhat.com> MIME-Version: 1.0 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 Reviewed-by: Christoph Hellwig Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ialloc.c | 59 +++++++++++++------------------------- fs/xfs/libxfs/xfs_ialloc.h | 21 +------------- fs/xfs/xfs_inode.c | 38 ++---------------------- 3 files changed, 24 insertions(+), 94 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 23e94d43acb2..074c2d83de77 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) @@ -1731,30 +1731,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; @@ -1765,21 +1753,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; @@ -1814,7 +1792,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; } @@ -1829,7 +1807,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; @@ -1842,9 +1820,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; @@ -1856,21 +1834,25 @@ 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 space for an inode cluster + * in this AG. Roll the transaction so that we can + * allocate one of the new inodes. */ ASSERT(pag->pagi_freecount > 0); xfs_perag_put(pag); - *IO_agbp = agbp; + error = xfs_dialloc_roll(tpp, agbp); + if (error) { + xfs_buf_relse(agbp); + 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) @@ -1882,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 bd6e0db9e23c..13810ffe4af9 100644 --- a/fs/xfs/libxfs/xfs_ialloc.h +++ b/fs/xfs/libxfs/xfs_ialloc.h @@ -32,39 +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); } -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 07d692020da3..860979fe18c3 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -907,7 +907,6 @@ xfs_dir_ialloc( prid_t prid) /* project id */ { xfs_inode_t *ip; - xfs_buf_t *ialloc_context = NULL; xfs_ino_t parent_ino = dp ? dp->i_ino : 0; xfs_ino_t ino; int error; @@ -916,43 +915,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, parent_ino, mode, &ialloc_context, &ino); + * allocated. + */ + error = xfs_dialloc(tpp, parent_ino, mode, &ino); if (error) return ERR_PTR(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) { - xfs_buf_relse(ialloc_context); - return ERR_PTR(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, parent_ino, mode, - &ialloc_context, &ino); - if (error) - return ERR_PTR(error); - ASSERT(!ialloc_context); - } - if (ino == NULLFSINO) return ERR_PTR(-ENOSPC); From patchwork Wed Dec 9 11:28:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11961163 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 B3320C4361B for ; Wed, 9 Dec 2020 11:31:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6350B23B23 for ; Wed, 9 Dec 2020 11:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730767AbgLILbL (ORCPT ); Wed, 9 Dec 2020 06:31:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47948 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729260AbgLILbK (ORCPT ); Wed, 9 Dec 2020 06:31:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607513383; 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=4+/QD8kERVG//FSnEJ/K6dy8ckMecXmSB7TwKOHOb04=; b=XPOm+/An0v02UIySLvxGW9HFR/oxgN4AAXJoiuBIsGu9kgdg68/XuvZFipvvr6R1vXRkUd SWea7M9je20U/auxdlLc4qtHaJO23kVMM6jcbfoM/3Ridl1rPPSbaICCg+eHs/xmirIZ7m FA1aKnaKCpEBtrVX9xHFq/dTctL6rKE= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-363-sHvb_8mqM9qPyd63YJ4aGw-1; Wed, 09 Dec 2020 06:29:42 -0500 X-MC-Unique: sHvb_8mqM9qPyd63YJ4aGw-1 Received: by mail-pj1-f72.google.com with SMTP id ob4so796698pjb.9 for ; Wed, 09 Dec 2020 03:29: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=4+/QD8kERVG//FSnEJ/K6dy8ckMecXmSB7TwKOHOb04=; b=LRrVprOmJ4kIQ3eqESd5lrvp0lt8uqzsL3W0MdKBTpZnbYLW+g589Sc/0ZWDz20Bp2 wQ3Faj7+zqxHPAs7W7KocXRyyUOv8J9Cmyd0gziMVEOYHPJPClTPeQGp+ex6G/2om/aX lH+edu7fz6m1GiLbVF/2rB5yq/OQ9fEdDMmw+vIuHyRNtjDHxVNUUPgsh9OqFGyfHNoB SQsbOXHSt4Uue4S0p81N9iECt9v+Mjbyd256ESn27ckDyjela7cqCHIyEFVF6WOhdqtG MZRMYJ1NvwpFrGfM/jCgQHRxAeLjs3vmCW3Ab2f17bwzy2pp5aEOyqeOUak/7Z8Dh7ZH Q9Cg== X-Gm-Message-State: AOAM531/OVYUPevhCyOiBVH6cbCl9Bq1YUBGP11kX2YJIYRQai2VRENW ERz5gMYefbxIix3ZmNHeoLbeyRqIsCben8VJTzCx885mHeRhRkE5VzGcAytUQ+6CVUOlv6Ds0M6 NWaHVqVrqxGlRJwO3tDXUPTfIlzBzpQJ2anGitcsy28hvzPA0ltcAELT/YjaAFcIGHyuIslnjoA == X-Received: by 2002:a63:4207:: with SMTP id p7mr1569626pga.287.1607513380742; Wed, 09 Dec 2020 03:29:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGCa9WFMESxAXduFW1esDOjEKb7fDMtgQvFjOlyLS6ztmugRPBCBExJMDyUM7sI6bLx+HUcw== X-Received: by 2002:a63:4207:: with SMTP id p7mr1569603pga.287.1607513380353; Wed, 09 Dec 2020 03:29:40 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y5sm2231280pfp.45.2020.12.09.03.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:29:40 -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 v5 5/6] xfs: spilt xfs_dialloc() into 2 functions Date: Wed, 9 Dec 2020 19:28:19 +0800 Message-Id: <20201209112820.114863-6-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201209112820.114863-1-hsiangkao@redhat.com> References: <20201209112820.114863-1-hsiangkao@redhat.com> MIME-Version: 1.0 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 Reviewed-by: Christoph Hellwig Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ialloc.c | 54 +++++++++++++++++--------------------- fs/xfs/libxfs/xfs_ialloc.h | 20 ++++++++++---- fs/xfs/xfs_inode.c | 18 ++++++++----- 3 files changed, 51 insertions(+), 41 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 074c2d83de77..dcb076d5c390 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, @@ -1726,21 +1726,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; @@ -1753,15 +1754,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 @@ -1794,7 +1795,7 @@ xfs_dialloc( if (!pag->pagi_init) { error = xfs_ialloc_pagi_init(mp, *tpp, agno); if (error) - goto out_error; + break; } /* @@ -1809,11 +1810,11 @@ 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; + goto found_ag; } if (!okalloc) @@ -1824,12 +1825,9 @@ 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) { @@ -1846,9 +1844,7 @@ xfs_dialloc( xfs_buf_relse(agbp); return error; } - - *inop = NULLFSINO; - goto out_alloc; + goto found_ag; } nextag_relse_buffer: @@ -1857,17 +1853,15 @@ 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; +found_ag: + *IO_agbp = agbp; + return 0; } /* 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 860979fe18c3..3bbd3f5a57b1 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -906,10 +906,10 @@ xfs_dir_ialloc( dev_t rdev, prid_t prid) /* project id */ { - xfs_inode_t *ip; - xfs_ino_t parent_ino = dp ? dp->i_ino : 0; - xfs_ino_t ino; - int error; + struct xfs_buf *agibp; + xfs_ino_t parent_ino = dp ? dp->i_ino : 0; + xfs_ino_t ino; + int error; ASSERT((*tpp)->t_flags & XFS_TRANS_PERM_LOG_RES); @@ -917,13 +917,19 @@ xfs_dir_ialloc( * Call the space management code to pick the on-disk inode to be * allocated. */ - error = xfs_dialloc(tpp, parent_ino, mode, &ino); + error = xfs_dialloc_select_ag(tpp, parent_ino, mode, &agibp); if (error) return ERR_PTR(error); - if (ino == NULLFSINO) + if (!agibp) return ERR_PTR(-ENOSPC); + /* Allocate an inode from the selected AG */ + error = xfs_dialloc_ag(*tpp, agibp, parent_ino, &ino); + if (error) + return ERR_PTR(error); + ASSERT(ino != NULLFSINO); + return xfs_init_new_inode(*tpp, dp, ino, mode, nlink, rdev, prid); } From patchwork Wed Dec 9 11:28:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11961165 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 E7C9EC433FE for ; Wed, 9 Dec 2020 11:34:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E6E723B23 for ; Wed, 9 Dec 2020 11:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729130AbgLILe3 (ORCPT ); Wed, 9 Dec 2020 06:34:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52621 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbgLILe2 (ORCPT ); Wed, 9 Dec 2020 06:34:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607513582; 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=1zyT/hm2nAM99UvYak/INvxUxfGjQvEiSb6l+IMi4YI=; b=ZSMaKhFm5r/ig1AeaOXoZ8soNI+6bqEsXF3G3k27FWHzB69czoyYHRZskny7M47OdVBGUV tsUbXtRzfGLKzmQUv5WhZT2d9/lc3D325pqLl9V5as4A29xgmYRxpCljnaYubIquWrZ0L3 OHcPivDm3ykt8kyLk8bdtalCv2IfwhI= 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-4-hbx-PrsENbuISDOXa21qAA-1; Wed, 09 Dec 2020 06:29:46 -0500 X-MC-Unique: hbx-PrsENbuISDOXa21qAA-1 Received: by mail-pg1-f198.google.com with SMTP id m15so914048pgs.7 for ; Wed, 09 Dec 2020 03:29: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=1zyT/hm2nAM99UvYak/INvxUxfGjQvEiSb6l+IMi4YI=; b=ZvXKmhA4ZLwvpbAjzhcGMeZdClDkoPs9ExzbFb+dUtQblxig0JfU0MpZKKojfTqS/H MWOoQzq35Y2YzV6Tl1LVWMkrQuc8dBss6QYDQVa5uXhfqyOp/vrclWLoMysvaB3N1kCo P0adWp27m3zcv+qLvoPS0X2/lwLjsPHVvxKpCWj0TafzDgBPEUpVc8vMyHTRlv+CWgOy GsDhUyVRbohRYFE8LarwRtFTtb3q3+ffUKTkAtrVb/w9VNyIfFsZ1F8trCa/ffpwmdss 6biHdaGYhh6z4vo3A9qMjuHcqlfItsFYA7qjsJPlIgz+6YaqwJU1cr1egLVuXrv896Ls 16UA== X-Gm-Message-State: AOAM5334p1m8pEr9vOaV5AkG0Zhlx1lOvLv3QiCJq/lDt+6G1I0gSPKx A+rl6BORUEWuMqJPffaHuj375V9sReQhV6e17JUeEfa5p5Ys+ln3auORKd9KUAi8I2Qu1OXbA8H DqjQJRVC77xD7/PlukQLGWC5Qb/EV8mZ05spTtNU6YTRStl1ZZ8bSM1HUn3E+KpgqWjg2KujVcQ == X-Received: by 2002:a63:1a5b:: with SMTP id a27mr1546946pgm.169.1607513384941; Wed, 09 Dec 2020 03:29:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxLGL0c1Q+jvu25liIWm4YVISCN2B7dyjCd8206US+99gVQ2mGCz7U49tyHQ1GQAqjDfp0Lxg== X-Received: by 2002:a63:1a5b:: with SMTP id a27mr1546925pgm.169.1607513384663; Wed, 09 Dec 2020 03:29:44 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y5sm2231280pfp.45.2020.12.09.03.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:29:44 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Dave Chinner , Christoph Hellwig , Eric Sandeen , Gao Xiang , Dave Chinner Subject: [PATCH v5 6/6] xfs: kill ialloced in xfs_dialloc() Date: Wed, 9 Dec 2020 19:28:20 +0800 Message-Id: <20201209112820.114863-7-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201209112820.114863-1-hsiangkao@redhat.com> References: <20201209112820.114863-1-hsiangkao@redhat.com> MIME-Version: 1.0 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 | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index dcb076d5c390..063a1a543890 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; } @@ -1747,7 +1745,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; @@ -1820,9 +1817,8 @@ 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) @@ -1830,7 +1826,7 @@ xfs_dialloc_select_ag( break; } - if (ialloced) { + if (error == 0) { /* * We successfully allocated space for an inode cluster * in this AG. Roll the transaction so that we can