Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1167307rbb; Mon, 26 Feb 2024 00:17:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU9Yut4J1/WvI8YXFuxacLTRbBmf+vdYsbrHoBVyu/Pp7eg9hJ39la71aCBwMpST7y7EqHikcrDq1ya0fdQlL+hePjOLibXoH3MgxvMRQ== X-Google-Smtp-Source: AGHT+IH/IqinUM3RI9U8VtCkDbKOWsPKHR3GgQbzgUTImxeWnmwxrtMdXB5Jj8wlI7+B88qMwp8d X-Received: by 2002:a05:620a:2009:b0:787:7cc6:4424 with SMTP id c9-20020a05620a200900b007877cc64424mr7967404qka.8.1708935474484; Mon, 26 Feb 2024 00:17:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708935474; cv=pass; d=google.com; s=arc-20160816; b=O8yC0pTo3YsUdvA13vjZtrTOi4XKBTUYY1cvUSMq5liAo7SdlvV3YJe4rLtJUj+8bY x9dat2YDjVCor4WCcWK2t6U7YekeSc3eqiYxhmIq2UUr9YD5al0MTAgugQT/1X6oOm9C oKQO6ERmax7VETk9A9oW4e4UWckdYglbKvcLqxB7FXaTtM0N2YBnm6srV9UtXP8F9+En jVW7brDgcM/5E3r+wnePdDj8tbU8XhOPiJlxxTAxlEyK9DaAZhxHRIN3bqrNx/Zs7Cd5 WaQ9X9kkocwnCz/iV6bO2TnA0jGGXQF5MBvrbVTbECr1b5Fty+ZQgvJrovcWlFSpb1qf jzZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=zLVZgGCzWCbfd82W6JOocS3aqIFwLukUnBKGRA2scfU=; fh=+kTitL/2sdzQ5Kjs92GYgPTDhDVaTwS3/OUo2YDpvtU=; b=H8AJ9lqpZLjAzCj9m4T8+b8BnkADYdFMKkMc99pKeJ8Ej0M+7dxn8btH8gtoglnZeU e/8MUaHoaemh2ZQgfTl4NhMYFvqK/orLa2Tk3BPaoBN51NNM+Umr23laXZmjbzVahQM4 4EbmkNM3QRUxeYpXOPbTm1gZKTlCxA+GCEaPiZhAccKicKdmxyDjYP9DTahBSW4OJUaG R2c8KLc9n8Qi+ImSdBUJrdOFAIJBYafhcdOxhYBEKwsB99orWs5mgfXuR714OBADTKJT LkRS1hc65hk9PMbb1f6UJYUtsc9XWbdnm6zzE25xxgnTMf4TeXgAZweH94chvGRl3zOr x1QA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-ext4+bounces-1386-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1386-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f25-20020a05620a15b900b00787abc4f7b0si4542167qkk.19.2024.02.26.00.17.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:17:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1386-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-ext4+bounces-1386-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1386-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 397241C22BBC for ; Mon, 26 Feb 2024 08:17:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A034E1C696; Mon, 26 Feb 2024 08:17:37 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A78971CAA8 for ; Mon, 26 Feb 2024 08:17:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708935457; cv=none; b=YoJEhhU4emLcf7hTREAePEWDBtwtTTf06/GLCI0ijAM5akaUXOa8iDGV48E7fMlEktzQl/ZWv1RGxiWFQXrCtHY1yg7kosGjO+PcWOztSC3/e8e7UOsMLennbit2k+AaXHDIlr3w4gUZ8zqUEXkxE6+5Bp7Zmr5OHIggIaVu4jI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708935457; c=relaxed/simple; bh=vToQbZUIyw2YHyHWR8/F3LXddYsT60XuwSiXZwCRZwU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=kg3nsJojf4wGcgaYZBFnGQaX9Zs68oyTjUVKbKpgR4BTDZnGsjTw/VyUQzW99Pyc/6nppPiiFjUnm3ja7uSoD2s9Dn7Hrud5cHM/vlzLIrEiJYdMuzHBgUHDQ2PJLrBQIJRtXPPyL3ZrHQTib5ms7PP3q/7bYAqKwKt/KEACi0Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Tjthl1HzfzvVys; Mon, 26 Feb 2024 16:15:19 +0800 (CST) Received: from kwepemm600012.china.huawei.com (unknown [7.193.23.74]) by mail.maildlp.com (Postfix) with ESMTPS id D1DEC180068; Mon, 26 Feb 2024 16:17:26 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm600012.china.huawei.com (7.193.23.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 26 Feb 2024 16:17:26 +0800 From: Wenchao Hao To: Theodore Ts'o , Andreas Dilger , CC: , Wenchao Hao Subject: [RESEND PATCH] e2fsprogs: debugfs: Fix infinite loop when dump log Date: Mon, 26 Feb 2024 16:14:51 +0800 Message-ID: <20240226081451.3224276-1-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600012.china.huawei.com (7.193.23.74) There are 2 scenarios which would trigger infinite loop: 1. None log is recorded, then dumplog with "-n", for example: debugfs -R "logdump -O -n 10" /dev/xxx while /dev/xxx has no valid log recorded. 2. The log area is full and cycle write is triggered, then dumplog with debugfs -R "logdump -aOS" /dev/xxx This patch add a new flag "reverse_flag" to mark if logdump has reached to tail of logarea, it is default false, and set in macro WRAP(). If reverse_flag is true, and we comes to first_transaction_blocknr again, just break the logdump loop. Signed-off-by: Wenchao Hao --- debugfs/logdump.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/debugfs/logdump.c b/debugfs/logdump.c index b600228e..05ea839a 100644 --- a/debugfs/logdump.c +++ b/debugfs/logdump.c @@ -52,6 +52,7 @@ static int64_t dump_counts; static blk64_t block_to_dump, bitmap_to_dump, inode_block_to_dump; static unsigned int group_to_dump, inode_offset_to_dump; static ext2_ino_t inode_to_dump; +static bool reverse_flag; struct journal_source { @@ -80,8 +81,10 @@ static void dump_fc_block(FILE *out_file, char *buf, int blocksize, static void do_hexdump (FILE *, char *, int); #define WRAP(jsb, blocknr, maxlen) \ - if (blocknr >= (maxlen)) \ - blocknr -= (maxlen - be32_to_cpu((jsb)->s_first)); + if (blocknr >= (maxlen)) { \ + blocknr -= (maxlen - be32_to_cpu((jsb)->s_first)); \ + reverse_flag = true; \ + } void do_logdump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)), void *infop EXT2FS_ATTR((unused))) @@ -115,6 +118,7 @@ void do_logdump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)), inode_block_to_dump = ANY_BLOCK; inode_to_dump = -1; dump_counts = -1; + reverse_flag = false; reset_getopt(); while ((c = getopt (argc, argv, "ab:ci:f:OsSn:")) != EOF) { @@ -477,8 +481,7 @@ static void dump_journal(char *cmdname, FILE *out_file, if (dump_old && (dump_counts != -1) && (cur_counts >= dump_counts)) break; - if ((blocknr == first_transaction_blocknr) && - (cur_counts != 0) && dump_old && (dump_counts != -1)) { + if ((blocknr == first_transaction_blocknr) && dump_old && reverse_flag) { fprintf(out_file, "Dump all %lld journal records.\n", (long long) cur_counts); break; -- 2.32.0