From patchwork Wed Sep 2 12:22:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7111611 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F038EBEEC1 for ; Wed, 2 Sep 2015 12:24:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DB27620656 for ; Wed, 2 Sep 2015 12:24:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E925C2065A for ; Wed, 2 Sep 2015 12:24:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754320AbbIBMYS (ORCPT ); Wed, 2 Sep 2015 08:24:18 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:46125 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754044AbbIBMYQ (ORCPT ); Wed, 2 Sep 2015 08:24:16 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100283463" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 Sep 2015 20:27:14 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t82CO10J030326 for ; Wed, 2 Sep 2015 20:24:01 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Wed, 2 Sep 2015 20:24:10 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH v3 3/4] btrfs-progs: stat info for btrfs rescue chunk-recover Date: Wed, 2 Sep 2015 20:22:31 +0800 Message-ID: <3711e85cec33955bbd437d733b25aa02b87f0fa2.1441196519.git.zhaolei@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP chunk-recover need to use many many time in scan_devices(), and no output in screen: # btrfs rescue chunk-recover /dev/sda6 (no output here, but need long time) To notice user that "the command is not hang", this patch add dynamic updated stat information in above period: # btrfs rescue chunk-recover /dev/sda6 Scanning: DONE in dev[0], 19998441472 in dev[1], DONE in dev[2] (until) Scanning: DONE in dev0, DONE in dev1, DONE in dev2 Check chunks successfully with no orphans Recover the chunk tree successfully. Signed-off-by: Zhao Lei --- chunk-recover.c | 72 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/chunk-recover.c b/chunk-recover.c index 3cb22ae..562817b 100644 --- a/chunk-recover.c +++ b/chunk-recover.c @@ -76,6 +76,7 @@ struct device_scan { struct recover_control *rc; struct btrfs_device *dev; int fd; + u64 bytenr; }; static struct extent_record *btrfs_new_extent_record(struct extent_buffer *eb) @@ -766,6 +767,8 @@ static int scan_one_device(void *dev_scan_struct) bytenr = 0; while (1) { + dev_scan->bytenr = bytenr; + if (is_super_block_address(bytenr)) bytenr += rc->sectorsize; @@ -832,9 +835,8 @@ static int scan_devices(struct recover_control *rc) long *t_rets; int devnr = 0; int devidx = 0; - int cancel_from = 0; - int cancel_to = 0; int i; + int all_done; list_for_each_entry(dev, &rc->fs_devices->devices, dev_list) devnr++; @@ -860,30 +862,64 @@ static int scan_devices(struct recover_control *rc) dev_scans[devidx].rc = rc; dev_scans[devidx].dev = dev; dev_scans[devidx].fd = fd; - ret = pthread_create(&t_scans[devidx], NULL, - (void *)scan_one_device, - (void *)&dev_scans[devidx]); - if (ret) { - cancel_from = 0; - cancel_to = devidx - 1; - goto out1; - } + dev_scans[devidx].bytenr = -1; devidx++; } for (i = 0; i < devidx; i++) { - ret = pthread_join(t_scans[i], (void **)&t_rets[i]); - if (ret || t_rets[i]) { - ret = 1; - cancel_from = i + 1; - cancel_to = devnr - 1; + ret = pthread_create(&t_scans[i], NULL, + (void *)scan_one_device, + (void *)&dev_scans[i]); + if (ret) goto out1; + + dev_scans[i].bytenr = 0; + } + + while (1) { + all_done = 1; + for (i = 0; i < devidx; i++) { + if (dev_scans[i].bytenr == -1) + continue; + ret = pthread_tryjoin_np(t_scans[i], + (void **)&t_rets[i]); + if (ret == EBUSY) { + all_done = 0; + continue; + } + if (ret || t_rets[i]) { + ret = 1; + goto out1; + } + dev_scans[i].bytenr = -1; + } + + printf("\rScanning: "); + for (i = 0; i < devidx; i++) { + if (dev_scans[i].bytenr == -1) + printf("%sDONE in dev%d", + i ? ", " : "", i); + else + printf("%s%llu in dev%d", + i ? ", " : "", dev_scans[i].bytenr, i); } + /* clear chars if exist in tail */ + printf(" "); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); + + if (all_done) { + printf("\n"); + break; + } + + sleep(1); } out1: - while (ret && (cancel_from <= cancel_to)) { - pthread_cancel(t_scans[cancel_from]); - cancel_from++; + for (i = 0; i < devidx; i++) { + if (dev_scans[i].bytenr == -1) + continue; + pthread_cancel(t_scans[i]); } out2: free(dev_scans);