Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3187138rwd; Sat, 3 Jun 2023 00:03:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5h6cmz4AwifWNNCyyQnswL56MKmcz5cu4lb7frUq01sMV/1Y6euJkhXuWJ47goRaHt1qGv X-Received: by 2002:a9d:6f89:0:b0:6b0:66f5:2058 with SMTP id h9-20020a9d6f89000000b006b066f52058mr5230183otq.10.1685775819478; Sat, 03 Jun 2023 00:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685775819; cv=none; d=google.com; s=arc-20160816; b=qfXDyTOE1AzeGl90amOvmYS7xfilbfAtx5unI/922ov+/7EeTAN3LnaPTD3VMbg1yH 2G0kPPv8cZPoc9aDpKPUeDreKUdigS//RZw8KMbm+8tx8cZIa9gcALDqkpXJQ14VSpWr DyvJmQe5FK/uiFffVppTsmyEjvXLIKBdITWtTUSH2+IRQgB6kQPXO2onRETjd3adduCr Lpiu7GIcYzNGNr8MZCsgVJfE8R08wbRlZGGO9egDztK2NCtYfwFk7s/MCflIl0qMZcHq soZVcdCL51kSbAv/SwZdQRniooH2dQriV8Y+s0V6sgGawCbpnE64dtIytNc0l2xCCUnB vhug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wIrJRbn7uOpxu7G6zFAhEtvF6XT3YpSpRP6zO7TSccg=; b=MYillv1vSAKFUlO1YERd3Skg9W5bmvI7aoJWrCJHhfibHu5ESAtmoswCqqfpEi/72H qZbRJYMKLTgUjssdx3J0vwDwKOybBx0hukMVwUn1xJGeJydcQszLzu9xse8P7p3P9Abv Sjl4Ho+SSMQ7mv28OwClGMJFLchBep+oSCvaUkElx8UHC3ZIJKrQzYTfEfuGe9C6mVDy iaWViqpIWT5eKpRlieJa8VMM91ngEccLa8F96RYlKe3P4DaRSW6+My5wEbs596sY2wBl EEcPwVWeTNMaAouYhV+ZI7dQTNuu+BgkExnYHxkyUiGAGzqMPCZUx4gbHDv1bnYQagQT /IWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 132-20020a62198a000000b006434a04f2fcsi1937511pfz.297.2023.06.03.00.03.27; Sat, 03 Jun 2023 00:03:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232397AbjFCHCM (ORCPT + 99 others); Sat, 3 Jun 2023 03:02:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232282AbjFCHCK (ORCPT ); Sat, 3 Jun 2023 03:02:10 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB3D1E5A; Sat, 3 Jun 2023 00:02:06 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QY9ls1WYWz4f3lKr; Sat, 3 Jun 2023 15:02:01 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgCHOKxk5Xpk+MxPKw--.30174S9; Sat, 03 Jun 2023 15:02:02 +0800 (CST) From: Kemeng Shi To: tytso@mit.edu, adilger.kernel@dilger.ca, ojaswin@linux.ibm.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, shikemeng@huaweicloud.com Subject: [PATCH v4 07/19] ext4: try all groups in ext4_mb_new_blocks_simple Date: Sat, 3 Jun 2023 23:03:15 +0800 Message-Id: <20230603150327.3596033-8-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230603150327.3596033-1-shikemeng@huaweicloud.com> References: <20230603150327.3596033-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgCHOKxk5Xpk+MxPKw--.30174S9 X-Coremail-Antispam: 1UD129KBjvJXoW7ur13Kry7uF1DAFyDZw15XFb_yoW8AF4Dpw sxCF18Gr1fWrnFgFZFg34SqF1xJw1xuFyUWryfC34rGrZrJryfJFsrKF1Fv3WYyFZ3X3ZI vr4YvryrA3WjgaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6x IIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xv wVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFc xC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_ Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2 IErcIFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRvJPtU UUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org ext4_mb_new_blocks_simple ignores the group before goal, so it will fail if free blocks reside in group before goal. Try all groups to avoid unexpected failure. Search finishes either if any free block is found or if no available blocks are found. Simpliy check "i >= max" to distinguish the above cases. Signed-off-by: Kemeng Shi Suggested-by: Theodore Ts'o Reviewed-by: Ojaswin Mujoo --- fs/ext4/mballoc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 839db9c46aea..bcc9622daa4a 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -6047,7 +6047,7 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle, struct buffer_head *bitmap_bh; struct super_block *sb = ar->inode->i_sb; struct ext4_sb_info *sbi = EXT4_SB(sb); - ext4_group_t group; + ext4_group_t group, nr; ext4_grpblk_t blkoff; ext4_grpblk_t max = EXT4_CLUSTERS_PER_GROUP(sb); ext4_grpblk_t i = 0; @@ -6061,7 +6061,7 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle, ar->len = 0; ext4_get_group_no_and_offset(sb, goal, &group, &blkoff); - for (; group < ext4_get_groups_count(sb); group++) { + for (nr = ext4_get_groups_count(sb); nr > 0; nr--) { bitmap_bh = ext4_read_block_bitmap(sb, group); if (IS_ERR(bitmap_bh)) { *errp = PTR_ERR(bitmap_bh); @@ -6085,10 +6085,13 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle, if (i < max) break; + if (++group >= ext4_get_groups_count(sb)) + group = 0; + blkoff = 0; } - if (group >= ext4_get_groups_count(sb) || i >= max) { + if (i >= max) { *errp = -ENOSPC; return 0; } -- 2.30.0