From patchwork Wed Oct 30 08:41:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11219241 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F63D14DB for ; Wed, 30 Oct 2019 08:41:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6400A20874 for ; Wed, 30 Oct 2019 08:41:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="MRo2hyBC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726513AbfJ3Ilw (ORCPT ); Wed, 30 Oct 2019 04:41:52 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:60880 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726063AbfJ3Ilw (ORCPT ); Wed, 30 Oct 2019 04:41:52 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9U8cenV054064; Wed, 30 Oct 2019 08:41:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=bEA2tfZodVsZHkxpz8gpMfwD3FUidjG7mEELSFzUQu4=; b=MRo2hyBCqLQr2PQQWwCkOnTYQNWX3ZQYibpU8KeDEW8Yz1R6/6z+24833OHwpb2kNYZc hD1ofTXh/ZKXyo8f53L2RgbR4fD96KrcJo5I++Hpi5x3jZRTmXFNcmVGGkVtsGKCECSr pFdobhMt8VimsHK03qHystRQHo4rXdxWlOpiYgcJNJEz5f1cGdDu3GSlnndgGgKGwK4B WAL24qhoo3nxeyWkJf1MquxIeWfNHiHHFOpWUzUfg4tBFs5uAcotByBXJACzQ3AixafH qnoOgPczzuQubPwhtKtzULB5kG3PVMnJllCm6VhHcAg2FK1ZbHjZoeC5vgg+OCAME3W8 uQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2vxwhfje3y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2019 08:41:50 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9U8cY7v073791; Wed, 30 Oct 2019 08:41:50 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2vxwj63nj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2019 08:41:50 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x9U8fnqP001302; Wed, 30 Oct 2019 08:41:49 GMT Received: from mb.wifi.oracle.com (/192.188.170.109) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 30 Oct 2019 01:41:49 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com Subject: [PATCH v1 13/18] btrfs-progs: restore: use global verbose option Date: Wed, 30 Oct 2019 16:41:17 +0800 Message-Id: <20191030084122.29745-14-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191030084122.29745-1-anand.jain@oracle.com> References: <20191030084122.29745-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9425 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910300086 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9425 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910300086 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Transpire global --verbose option down to the btrfs restore sub-command. Suggested-by: David Sterba Signed-off-by: Anand Jain --- cmds/restore.c | 55 ++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/cmds/restore.c b/cmds/restore.c index c104b01aef69..37b8e770bbe6 100644 --- a/cmds/restore.c +++ b/cmds/restore.c @@ -51,7 +51,6 @@ static char fs_name[PATH_MAX]; static char path_name[PATH_MAX]; static char symlink_target[PATH_MAX]; static int get_snaps = 0; -static int verbose = 0; static int restore_metadata = 0; static int restore_symlinks = 0; static int ignore_errors = 0; @@ -375,8 +374,7 @@ static int copy_one_extent(struct btrfs_root *root, int fd, if (compress == BTRFS_COMPRESS_NONE) bytenr += offset; - if (verbose && offset) - printf("offset is %Lu\n", offset); + pr_verbose(offset ? 1 : 0, "offset is %Lu\n", offset); /* we found a hole */ if (disk_size == 0) return 0; @@ -832,11 +830,13 @@ static int overwrite_ok(const char * path) if (overwrite) return 2; - if (verbose || !warn) - printf("Skipping existing file" - " %s\n", path); - if (!warn) + if (!warn) { + printf("Skipping existing file %s\n", path); printf("If you wish to overwrite use -o\n"); + } else { + pr_verbose(1, "Skipping existing file %s\n", path); + } + warn = 1; return 0; } @@ -987,9 +987,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key, leaf = path.nodes[0]; while (!leaf) { - if (verbose > 1) - printf("No leaf after search, looking for the next " - "leaf\n"); + pr_verbose(2, + "No leaf after search, looking for the next leaf\n"); ret = next_leaf(root, &path); if (ret < 0) { fprintf(stderr, "Error getting next leaf %d\n", @@ -997,9 +996,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key, goto out; } else if (ret > 0) { /* No more leaves to search */ - if (verbose) - printf("Reached the end of the tree looking " - "for the directory\n"); + pr_verbose(1, + "Reached the end of the tree looking for the directory\n"); ret = 0; goto out; } @@ -1023,10 +1021,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key, goto out; } else if (ret > 0) { /* No more leaves to search */ - if (verbose) - printf("Reached the end of " - "the tree searching the" - " directory\n"); + pr_verbose(1, + "Reached the end of the tree searching the directory\n"); ret = 0; goto out; } @@ -1036,14 +1032,12 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key, } btrfs_item_key_to_cpu(leaf, &found_key, path.slots[0]); if (found_key.objectid != key->objectid) { - if (verbose > 1) - printf("Found objectid=%Lu, key=%Lu\n", - found_key.objectid, key->objectid); + pr_verbose(2, "Found objectid=%Lu, key=%Lu\n", + found_key.objectid, key->objectid); break; } if (found_key.type != key->type) { - if (verbose > 1) - printf("Found type=%u, want=%u\n", + pr_verbose(2, "Found type=%u, want=%u\n", found_key.type, key->type); break; } @@ -1072,8 +1066,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key, if (!overwrite_ok(path_name)) goto next; - if (verbose) - printf("Restoring %s\n", path_name); + pr_verbose(1, "Restoring %s\n", path_name); if (dry_run) goto next; fd = open(path_name, O_CREAT|O_WRONLY, 0644); @@ -1145,8 +1138,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key, location.objectid = BTRFS_FIRST_FREE_OBJECTID; } - if (verbose) - printf("Restoring %s\n", path_name); + pr_verbose(1, "Restoring %s\n", path_name); errno = 0; if (dry_run) @@ -1209,8 +1201,7 @@ next: } } - if (verbose) - printf("Done searching %s\n", in_dir); + pr_verbose(1, "Done searching %s\n", in_dir); out: btrfs_release_path(&path); return ret; @@ -1420,6 +1411,8 @@ static const char * const cmd_restore_usage[] = { " you have to use following syntax (possibly quoted):", " ^/(|home(|/username(|/Desktop(|/.*))))$", "-c ignore case (--path-regex only)", + HELPINFO_GLOBAL_OPTIONS_HEADER, + HELPINFO_INSERT_VERBOSE, NULL }; @@ -1441,6 +1434,10 @@ static int cmd_restore(const struct cmd_struct *cmd, int argc, char **argv) regex_t match_reg, *mreg = NULL; char reg_err[256]; + /* Init global verbose if unset */ + if (bconf.verbose < 0) + bconf.verbose = 0; + optind = 0; while (1) { int opt; @@ -1472,7 +1469,7 @@ static int cmd_restore(const struct cmd_struct *cmd, int argc, char **argv) get_snaps = 1; break; case 'v': - verbose++; + bconf.verbose++; break; case 'i': ignore_errors = 1;