From patchwork Tue Dec 8 12:19:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11958347 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 4CBB5C433FE for ; Tue, 8 Dec 2020 12:23:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06FB623A84 for ; Tue, 8 Dec 2020 12:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729467AbgLHMXE (ORCPT ); Tue, 8 Dec 2020 07:23:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31117 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729424AbgLHMXE (ORCPT ); Tue, 8 Dec 2020 07:23:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607430098; 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=Y2fsuwVKaviiglTZPHyiPG03XdhrKqgduCWdOP+ueQgyqDkteC6mM/liDWUbZ2cz/JvF7z 7JFsg1QkNSg+OLhuWyng3bT+Z9kNZ0+J6/ZIu8+SSvMok/mvH6J5calettXr4+BRBBbfsG QQ307WJaJvCiWo5mOjj13dYPqF6j/qQ= 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-393-RALpWb4oP_mzLOVm8XrxRw-1; Tue, 08 Dec 2020 07:21:36 -0500 X-MC-Unique: RALpWb4oP_mzLOVm8XrxRw-1 Received: by mail-pf1-f197.google.com with SMTP id q13so9307171pfn.18 for ; Tue, 08 Dec 2020 04:21:36 -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=VT705w2eNjr8uQYpzIUyIUU1ByLQyrt6E3xgQgom2oMbQZyiMhufdGtPXkPjfbDGVV GdJMug0y+oVm9HJZoAZyDIJLuLu345jp2HT/iCY6s1Uy9ifCtL0l6mEgtbvHZ7SeXWu6 YSJsbFPlSjStehFYfKemGMNfLzzOK4pKBCK236IfElWhNVYlc69krkSDbBoHy8tUIITx LvU75MiGCS9rQpJNqzO9zDRT52lBHo7WKNpDlNZBXFvRihhFWnVuzZ09k4iSjOnmGFyC Rx4K4Duff0qnoCheLhLcv/oakiqC7gr2zo0i7PWegUS+Lq4q6LJVcOpBz8BYaZVmj7u5 8QPQ== X-Gm-Message-State: AOAM533Hxd7OQEgDIOBDAd+Y8NxGAzTOKYhgOYdqI6EwYpBFtm/Sx8Jk y1xdoPiiUOkJ2roM+qIiYlAtl8PCR0wAr+vwdUyvhGVov5RVxxAug1D2Kq3CxMB57JbjPjT0rLD SdJ4lrj32HZVUUuVUbPjRvmsQKsXvW6o/5p81I3JBuQNZ7NLk/A1K7+Hs3PBbHMN8DFpWTK6jRA == X-Received: by 2002:a63:e14c:: with SMTP id h12mr18302737pgk.181.1607430095500; Tue, 08 Dec 2020 04:21:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4geCuru7DrmegHZ+a152Y6gUQ8oK+u8nszROS5mVm1i0msC+cD+4OwBzp7aNc5e/nhYGiKQ== X-Received: by 2002:a63:e14c:: with SMTP id h12mr18302713pgk.181.1607430095159; Tue, 08 Dec 2020 04:21:35 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id a29sm1156926pfr.73.2020.12.08.04.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 04:21:34 -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 v4 1/6] xfs: convert noroom, okalloc in xfs_dialloc() to bool Date: Tue, 8 Dec 2020 20:19:58 +0800 Message-Id: <20201208122003.3158922-2-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201208122003.3158922-1-hsiangkao@redhat.com> References: <20201208122003.3158922-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 Tue Dec 8 12:19:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11958349 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 B9A07C4361B for ; Tue, 8 Dec 2020 12:23:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A6FE23A9B for ; Tue, 8 Dec 2020 12:23:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729468AbgLHMXJ (ORCPT ); Tue, 8 Dec 2020 07:23:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26768 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729424AbgLHMXJ (ORCPT ); Tue, 8 Dec 2020 07:23:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607430103; 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=J59CpIHABVhPzEGvzEppdhYhc7QmrrNmU0hchNcI7Fo=; b=Dl/E1Vz07lOv9mTJ9zOLLyadjix8d1+NAzeCnmIjt2LXXYZ542rPy/LPCT7nLUJkPSuiOI 2/qoG7bezdl95OXhFEBBUlsoOnwdtT6brp3Rg9TlL5v4f/pCz2fk9+/AocK4+bLcxnt2QW SDa2w7MHPvkgaIEBTFIf4yl5AeE1m6Q= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-xTGR-sb9OeOp5JWJ9L3nAA-1; Tue, 08 Dec 2020 07:21:41 -0500 X-MC-Unique: xTGR-sb9OeOp5JWJ9L3nAA-1 Received: by mail-pg1-f200.google.com with SMTP id f6so894419pgh.3 for ; Tue, 08 Dec 2020 04:21: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; bh=J59CpIHABVhPzEGvzEppdhYhc7QmrrNmU0hchNcI7Fo=; b=a+LUkiCPCNBwfhwX7eSXQisHA6iSrbde6MP6xHOrfqGF075iJVm5fyckYbiyKOCfK5 Jze6Nni5Lr+dRgm6V3kvv/jKyx+t5tgUMtnFaefCt8911Mx3cD88ha1cfKPXZogZeigh KhKL/qLjN/roLZ4ysp4HZesZQOR9PqxIEvrZw1xkUP6fTTgp6vN+m6SYYev6wkfnG98u mukAmmsB91TDjmCG3iUXNzHlli34ycec9+AKU4d+njeghydayaxGV7qcqT58N/sqxhTw JUM/AWuRIODM5Qs9ykwld9D7RutdjOkyAP6jNGxZKBkcaQ9tkwxaLj9bDGNx7qQyG30p /ClA== X-Gm-Message-State: AOAM533azCpiR3e0VEhcgQomq790BykHz7fj3PHYgG0oUtuhd1L03xDO JRA+3ePv8dJfRqAkICVF1u39RuTiu6EX56YtId0NEkn905XU60/bdRYtOThrIIu7ZjDQUbZt7MK nlDBbFG5ejN3GyUuIsGjUPLcUXfCZ42Ecg0HCVO+sbwfBmphB9xCZ+6FaGU+aDT5pqKH6SP/MXQ == X-Received: by 2002:a17:902:bf4a:b029:da:d0b8:6489 with SMTP id u10-20020a170902bf4ab02900dad0b86489mr20861312pls.58.1607430100579; Tue, 08 Dec 2020 04:21:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhODr52e93r4x/a/ewxKi9nNtcu6lftj52UwAN/JqRq6uFgMXJvmndLw6o+HWt8NiEPsXEzQ== X-Received: by 2002:a17:902:bf4a:b029:da:d0b8:6489 with SMTP id u10-20020a170902bf4ab02900dad0b86489mr20861290pls.58.1607430100231; Tue, 08 Dec 2020 04:21:40 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id a29sm1156926pfr.73.2020.12.08.04.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 04:21:39 -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 v4 2/6] xfs: introduce xfs_dialloc_roll() Date: Tue, 8 Dec 2020 20:19:59 +0800 Message-Id: <20201208122003.3158922-3-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201208122003.3158922-1-hsiangkao@redhat.com> References: <20201208122003.3158922-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. Reviewed-by: Christoph Hellwig Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang Reviewed-by: Darrick J. Wong --- 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 Tue Dec 8 12:20:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11958351 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 7030AC4361B for ; Tue, 8 Dec 2020 12:23:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A8F023AC9 for ; Tue, 8 Dec 2020 12:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729482AbgLHMXT (ORCPT ); Tue, 8 Dec 2020 07:23:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24581 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729469AbgLHMXS (ORCPT ); Tue, 8 Dec 2020 07:23:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607430110; 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=+rERYrc0vi2lseq8lrY0U4s4tpyi5hlTKss9H9yLv9k=; b=buNbnOmp1J8oLrptSi4c77k6xa+VRpOG53N/tb97zM5w57eshR6HoMkjobuLCigyRAnv4T w4FQpdxFEI24tgDN871szv79tdXlTeGucZzrluWSmhGD9Oz92VhaFa84CrsSDAtU6217oG rGemnisoNCnoUsSBuLUR7SKDB2RSPxo= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-72-PJvdHa87OJm5q3MLkKOh6g-1; Tue, 08 Dec 2020 07:21:47 -0500 X-MC-Unique: PJvdHa87OJm5q3MLkKOh6g-1 Received: by mail-pl1-f200.google.com with SMTP id d6so2177950plr.17 for ; Tue, 08 Dec 2020 04:21:47 -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=+rERYrc0vi2lseq8lrY0U4s4tpyi5hlTKss9H9yLv9k=; b=rubUy1b/BbtNtRCduUR/X2j0/RlJJ6H+1B+3I9X2VA7ikawNEOKPwI4W7ITVNLU6hV cnGJE1nxdmX2aS1w6Dw95tFK9RYc84gJHxWDDnAMFQi77KIzNGrZ+QXz3MO6XF0TT0TI CiwgaI/HQhYnCbuFgMlRpxcIjueY/khm4bCzdZWIQtny6xqsivrZXeSCqAJPSZXKDRHq /oYJeNoL+23jZR2r9yNhNxGsqRC3vQSWHuAYLC3WnZh8wEnAVKvStIDG8+SenJbUjgDp /4NS5yWgt/zdVsG0nT6JoKXTFV8fD2LLCodVdRq29C2xtK7T9NEh7b8QESm37RrJCbL7 4PRQ== X-Gm-Message-State: AOAM531jd+RzGAxJ3vgVUJC/OuOcJFXP6WkdnjD7CS0X6gI/PTWvCNhq 2gA73UORA+OIdkGBaPCH6omds6i0aDFOrZAi97kGgsyALDWMl0dEW+DvnShgLnuH4Lpw0LeyvfV 9oS/eHOGGl+7ijALyD1hPY4/md6iJczke9UTIobBNgYLGwz4TquNRgmNjDnGmSz4pPopGamP6lg == X-Received: by 2002:a63:b908:: with SMTP id z8mr22983786pge.396.1607430105794; Tue, 08 Dec 2020 04:21:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEv3nawxQquNNckPLun7/nxAnMJRXr+uSmZDgHVYIg9MSp8iJw4N7Alw0zRS4dz3zRJdXV9w== X-Received: by 2002:a63:b908:: with SMTP id z8mr22983754pge.396.1607430105277; Tue, 08 Dec 2020 04:21:45 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id a29sm1156926pfr.73.2020.12.08.04.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 04:21:44 -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 v4 3/6] xfs: move on-disk inode allocation out of xfs_ialloc() Date: Tue, 8 Dec 2020 20:20:00 +0800 Message-Id: <20201208122003.3158922-4-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201208122003.3158922-1-hsiangkao@redhat.com> References: <20201208122003.3158922-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. Signed-off-by: Dave Chinner Signed-off-by: Gao Xiang Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_inode.c | 220 +++++++++++++++---------------------------- fs/xfs/xfs_inode.h | 6 +- fs/xfs/xfs_qm.c | 27 +++--- fs/xfs/xfs_symlink.c | 8 +- 4 files changed, 98 insertions(+), 163 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 76282da7a05c..ae6c83d46aaa 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,60 @@ 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; + /* Initialise the newly allocated inode. */ + return xfs_init_new_inode(*tpp, dp, ino, mode, nlink, rdev, prid); } /* @@ -1147,9 +1071,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 +1196,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 Tue Dec 8 12:20:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11958357 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 A01DAC1B0D9 for ; Tue, 8 Dec 2020 12:23:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 58A4F23B03 for ; Tue, 8 Dec 2020 12:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729469AbgLHMXV (ORCPT ); Tue, 8 Dec 2020 07:23:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39162 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729480AbgLHMXV (ORCPT ); Tue, 8 Dec 2020 07:23:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607430113; 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=a7tYCY35wjnBwcju5TqPMLpYHfMUAf+l8kIJOwE8v7w=; b=Pw3jGnywBJ1xKztEt2uhSV6KokUKAOgqS1TWgcGIUtYXZp1nvPYYPSIha6P4B/FAElAyDA gOghSjMS3lEPhataJkA9ebrpNAaI2u04rLyGct1k2NQnJ9ZPTjSaY409S25U21X2vsa1YR mJCE2k9Bm/jaOfmxDkKrGo2jRQ7wRmE= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-161-WUmDNVC9NIyFDvqpEQLInA-1; Tue, 08 Dec 2020 07:21:52 -0500 X-MC-Unique: WUmDNVC9NIyFDvqpEQLInA-1 Received: by mail-pg1-f200.google.com with SMTP id u26so11660701pgl.15 for ; Tue, 08 Dec 2020 04:21:52 -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=a7tYCY35wjnBwcju5TqPMLpYHfMUAf+l8kIJOwE8v7w=; b=kpFgQ7dFVx8e2FDlktDET0n8ppX49U9w41GVvUYhUW+wf3tSIEwimC4x83ICVwbVVc VdFQoTkByDbcHsare4Mkm6yAJ0imQnDPHobvBWVkxocyF6JTjZ8zsqFkBQcJW5dA3L4D E3fLM2lggp/G70qei9VTPsNjZ2f61+pqSxuM3njzZEyMWePjPxsoOOCw874u9vUSJm7I puCtreSz0OruLn9/xE0b7eTuzStrV6mG/iEybzS1tnfMHCKia+opgnesF5HbAbsZ+owr srPZJIeqXvhrGtoOExd8Wn8wjghDxa1GcR2O/8eQKWWRffsl1C01HmBkh1RV3qnrUFo3 RHZw== X-Gm-Message-State: AOAM533htkmXWxvUtlfw4jxgxmBWgl4XJzIjikHOQOtDD9k1zIpNk6HK F5bWw6KJlYgaZ3yrrVUPJ6ue4QbIGRe35IFkgXkk5IaJi394z5nTNh5jNCdZfU9uEo9K1EwrLDl aK5pjyWC0EOIQSWVx3OnrOvT0nxAOot9mFngixXWcmlHgj0P+nT3Q9WY8CbhvIS5GWP/bH/Tr4Q == X-Received: by 2002:a17:90a:ad82:: with SMTP id s2mr4024224pjq.167.1607430110844; Tue, 08 Dec 2020 04:21:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMzELG5NnOL2TLOUEUnAcNfQhnU8oOmUmCClxIHHSRpVLaYjkavyDtVbvLqrsrneyr6xWhAQ== X-Received: by 2002:a17:90a:ad82:: with SMTP id s2mr4024203pjq.167.1607430110465; Tue, 08 Dec 2020 04:21:50 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id a29sm1156926pfr.73.2020.12.08.04.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 04:21:50 -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 v4 4/6] xfs: move xfs_dialloc_roll() into xfs_dialloc() Date: Tue, 8 Dec 2020 20:20:01 +0800 Message-Id: <20201208122003.3158922-5-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201208122003.3158922-1-hsiangkao@redhat.com> References: <20201208122003.3158922-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 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 ae6c83d46aaa..ec8433ea6985 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 Tue Dec 8 12:20:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11958355 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 9A7B9C4167B for ; Tue, 8 Dec 2020 12:23:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76F0623AC8 for ; Tue, 8 Dec 2020 12:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729483AbgLHMX0 (ORCPT ); Tue, 8 Dec 2020 07:23:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31823 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729480AbgLHMXZ (ORCPT ); Tue, 8 Dec 2020 07:23:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607430118; 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=4wap+Uy7r4snX0QOhvjD1HhGIzMLLvg2kThPx2dr5uc=; b=K2vXQferlY0vHNGZ9LiUeRpU+myIakfemnL12mt0fTynyBb+GOetSCLcMnI+5io/JTIHIs 13dKlM105QMkWZ+bpeoQsejUdtYGB9FQp0gw5TUCLyoozMNQ98/ijyGXq+byuhIQEiIhXd aDkGFKaVxDaYR/rfRJTKftZo8oJlhdc= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-30-xhhHA0_lN_OhHwhIdoibjQ-1; Tue, 08 Dec 2020 07:21:57 -0500 X-MC-Unique: xhhHA0_lN_OhHwhIdoibjQ-1 Received: by mail-pl1-f200.google.com with SMTP id m9so3502181plt.5 for ; Tue, 08 Dec 2020 04:21:56 -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=4wap+Uy7r4snX0QOhvjD1HhGIzMLLvg2kThPx2dr5uc=; b=JJD5RkqFVL5YSlMZswobcyKe/Hfr5s1QNUi4yFPmK+qqwTCLNq3P8geUmcbYrzGkz1 FXDXZhUaoKaUKHqN4eYhaKPSev7UWqWfB+/eiaLD5zewQepboj3BbwaVMIHpuhZHLpTj xqv15zPpfTR6W+Z0cIGvfWCh3fDtabnare9ovsV9GpzuKLjI0zQvU6ISRHfhI5NZw7hA wVW0zIm1vUnu4eLl9SAl3oqIaHpI/c1PtY+NK1dCXp1wkS748kA+lIrbg7buMKk5eWzo ifYUMAC3TW58JAGPwmSP9aSkN8e8bIqeGBQHRIaNPgQfdLRJYCGI1PaIcDymjLK5JO7K cZAQ== X-Gm-Message-State: AOAM5338o/ozGPuYq4s59HGcwOQJf/JVaf+Jz4TJHo+Ur/7cooZ6Ce2M vdtm4smBXRIvMF9wmis/cF/WJLoVBA3mLhYlGLaaQEtcWYKd5AY2fPRLLoY4Rvpx63sQxOIC9S4 lqUkPhbh6icVFzlIlqFgkohW801PTgSGQD7Y+hc5L7h22CGOq08vzdym5zuLOd62onJ+G9SE9Hg == X-Received: by 2002:a63:f94f:: with SMTP id q15mr21080704pgk.402.1607430115630; Tue, 08 Dec 2020 04:21:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyd9wTNq2nPLiVLyI8Wf6g1wqp3+3Qj19tn8Js6J4zuzBmlX4oAftCy1gnT7ui1hF2d2DSNJA== X-Received: by 2002:a63:f94f:: with SMTP id q15mr21080670pgk.402.1607430115159; Tue, 08 Dec 2020 04:21:55 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id a29sm1156926pfr.73.2020.12.08.04.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 04:21:54 -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 v4 5/6] xfs: spilt xfs_dialloc() into 2 functions Date: Tue, 8 Dec 2020 20:20:02 +0800 Message-Id: <20201208122003.3158922-6-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201208122003.3158922-1-hsiangkao@redhat.com> References: <20201208122003.3158922-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 | 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 ec8433ea6985..09e934b8332d 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); + /* Initialise the newly allocated inode. */ return xfs_init_new_inode(*tpp, dp, ino, mode, nlink, rdev, prid); } From patchwork Tue Dec 8 12:20:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11958353 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 AF53CC19437 for ; Tue, 8 Dec 2020 12:23:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C41823AA8 for ; Tue, 8 Dec 2020 12:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729480AbgLHMXa (ORCPT ); Tue, 8 Dec 2020 07:23:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41664 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729485AbgLHMX3 (ORCPT ); Tue, 8 Dec 2020 07:23:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607430122; 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=G5zHoFl4vQEdOQtxHPJtiOs+Z6vqtbTnbc4CAVi7q6A=; b=WKgpbSjw+m4f9nnCnLCiB9rFzVYf4a+kHOWk7BnqqsFbhK2zF7CCbJCaRA9firvrfQXeYi S32vLeKATbAyVi2vKcRG+S64YbbMFmx4OmdyPujcr3nZTFsDfUW/DMhO9kWSuGa+Oa5DJb 5tgPwDRk42ausv/BdE0myCQ2jx9JrDM= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-172-xX1UXkLSOMqQ1gHJDMV_4A-1; Tue, 08 Dec 2020 07:22:01 -0500 X-MC-Unique: xX1UXkLSOMqQ1gHJDMV_4A-1 Received: by mail-pg1-f197.google.com with SMTP id a27so11751649pga.6 for ; Tue, 08 Dec 2020 04:22:00 -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=G5zHoFl4vQEdOQtxHPJtiOs+Z6vqtbTnbc4CAVi7q6A=; b=FEe35UCn2j8RbsDEB0cGmdCPf5fydgg9TB9QrIQF6w9QAZm5Y2osvi5hk+FgAS/X6U c4ZzMDYhRPzHCj4zOiDk7TRaoQT0fac2G32xDgQzx/tf7fllEIcHkfRtaRYA0WQ5WSf2 2UQQHB2MWhlHArkhCxtmNyRppkQ5pe9HaS2m2BjW/E2yPGH+UvBcCnUzL469YZCnS5mq ye1SWUuLNOEokEmnJ25MOgmBeKUHaeNSLzmSKfsOop7xBJkQ8MpV6evOPtmkax6O5x10 Wl5mp4rrpoQDX/o2lHDlkQFmPCtJmUz6ZDL5iSpYxIvvsm+zqIdlue5wFg30PJU6nW0H U5Tg== X-Gm-Message-State: AOAM530SYQe7e2sCWWCkKLWBXw/+6lYnG31gX9tW9JbHOo0tnCBThIql +wfw4lY2DDbUlWECVLInNBooE48ET+NSdZXF4sqtZjSZGmp3iT+hZu0GpXw1h6X+VcoC3piMT1J 8WN6dlsT3M8rlh5h8MFtURZswR6A4x0Yf6xBjGeov+sIWj7AUGwqZPhy1GEU5P0V/Dx6N9nhbiQ == X-Received: by 2002:a17:902:b192:b029:d7:ca4a:4ec1 with SMTP id s18-20020a170902b192b02900d7ca4a4ec1mr20952202plr.76.1607430119824; Tue, 08 Dec 2020 04:21:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcfa5QXZEbzzdXuLVGSTt+BxQXkEOOiP4M5OfpF8u2Q04N+i/9D9OErXQn2wOvsRDzIwwtzg== X-Received: by 2002:a17:902:b192:b029:d7:ca4a:4ec1 with SMTP id s18-20020a170902b192b02900d7ca4a4ec1mr20952179plr.76.1607430119533; Tue, 08 Dec 2020 04:21:59 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id a29sm1156926pfr.73.2020.12.08.04.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 04:21:59 -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 v4 6/6] xfs: kill ialloced in xfs_dialloc() Date: Tue, 8 Dec 2020 20:20:03 +0800 Message-Id: <20201208122003.3158922-7-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201208122003.3158922-1-hsiangkao@redhat.com> References: <20201208122003.3158922-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 | 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