From patchwork Fri Feb 7 06:46:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 3599931 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ABD2EBF418 for ; Fri, 7 Feb 2014 07:00:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2AE220145 for ; Fri, 7 Feb 2014 07:00:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AEEE120115 for ; Fri, 7 Feb 2014 07:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751443AbaBGHAN (ORCPT ); Fri, 7 Feb 2014 02:00:13 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:34462 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750745AbaBGHAJ (ORCPT ); Fri, 7 Feb 2014 02:00:09 -0500 X-IronPort-AV: E=Sophos;i="4.95,799,1384272000"; d="scan'208";a="9479985" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 07 Feb 2014 14:56:16 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s176itOf018876 for ; Fri, 7 Feb 2014 14:45:12 +0800 Received: from adam-work.lan ([10.167.226.24]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014020714431465-1632238 ; Fri, 7 Feb 2014 14:43:14 +0800 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs-progs: Add -p/--print-missing options for btrfs fi show Date: Fri, 7 Feb 2014 14:46:00 +0800 Message-Id: <1391755560-4721-2-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.4 In-Reply-To: <1391755560-4721-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1391755560-4721-1-git-send-email-quwenruo@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/07 14:43:14, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/07 14:43:23, Serialize complete at 2014/02/07 14:43:23 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Since a mounted btrfs filesystem contains all the devices info even a device is removed after mount(like btrfs/003 in xfstests), we can use the info to print the known missing device if possible. So -p/--print-missing options are added to print possible missing devices. Signed-off-by: Qu Wenruo --- cmds-filesystem.c | 26 ++++++++++++++++++++------ man/btrfs.8.in | 4 +++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 4c9933d..77b142c 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -360,7 +360,7 @@ static u64 calc_used_bytes(struct btrfs_ioctl_space_args *si) static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, struct btrfs_ioctl_dev_info_args *dev_info, struct btrfs_ioctl_space_args *space_info, - char *label, char *path) + char *label, char *path, int print_missing) { int i; int fd; @@ -392,7 +392,14 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, fd = open((char *)tmp_dev_info->path, O_RDONLY); if (fd < 0) { missing = 1; - continue; + if (print_missing) + printf("\tdevid %4llu size %s used %s path %s (missing)\n", + tmp_dev_info->devid, + pretty_size(tmp_dev_info->total_bytes), + pretty_size(tmp_dev_info->bytes_used), + tmp_dev_info->path); + else + continue; } close(fd); printf("\tdevid %4llu size %s used %s path %s\n", @@ -440,7 +447,7 @@ static int check_arg_type(char *input) return BTRFS_ARG_UNKNOWN; } -static int btrfs_scan_kernel(void *search) +static int btrfs_scan_kernel(void *search, int print_missing) { int ret = 0, fd; FILE *f; @@ -477,7 +484,8 @@ static int btrfs_scan_kernel(void *search) fd = open(mnt->mnt_dir, O_RDONLY); if ((fd != -1) && !get_df(fd, &space_info_arg)) { print_one_fs(&fs_info_arg, dev_info_arg, - space_info_arg, label, mnt->mnt_dir); + space_info_arg, label, mnt->mnt_dir, + print_missing); kfree(space_info_arg); memset(label, 0, sizeof(label)); } @@ -500,6 +508,7 @@ static const char * const cmd_show_usage[] = { "Show the structure of a filesystem", "-d|--all-devices show only disks under /dev containing btrfs filesystem", "-m|--mounted show only mounted btrfs", + "-p|--print-missing show known missing device if possible", "If no argument is given, structure of all present filesystems is shown.", NULL }; @@ -513,6 +522,7 @@ static int cmd_show(int argc, char **argv) int ret; int where = BTRFS_SCAN_LBLKID; int type = 0; + int print_missing = 0; char mp[BTRFS_PATH_NAME_MAX + 1]; char path[PATH_MAX]; @@ -521,9 +531,10 @@ static int cmd_show(int argc, char **argv) static struct option long_options[] = { { "all-devices", no_argument, NULL, 'd'}, { "mounted", no_argument, NULL, 'm'}, + { "print-missing", no_argument, NULL, 'p'}, { NULL, no_argument, NULL, 0 }, }; - int c = getopt_long(argc, argv, "dm", long_options, + int c = getopt_long(argc, argv, "dmp", long_options, &long_index); if (c < 0) break; @@ -534,6 +545,9 @@ static int cmd_show(int argc, char **argv) case 'm': where = BTRFS_SCAN_MOUNTED; break; + case 'p': + print_missing = 1; + break; default: usage(cmd_show_usage); } @@ -571,7 +585,7 @@ static int cmd_show(int argc, char **argv) goto devs_only; /* show mounted btrfs */ - ret = btrfs_scan_kernel(search); + ret = btrfs_scan_kernel(search, print_missing); if (search && !ret) return 0; diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 8fea115..db2e355 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -25,7 +25,7 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem df\fP\fI \fP .PP -\fBbtrfs\fP \fBfilesystem show\fP [\fI--mounted\fP|\fI--all-devices\fP|\fI\fP]\fP +\fBbtrfs\fP \fBfilesystem show\fP [\fI--mounted\fP|\fI--all-devices\fP|\fI--print-missing\fP|\fI\fP]\fP .PP \fBbtrfs\fP \fBfilesystem sync\fP\fI \fP .PP @@ -280,6 +280,8 @@ and unmounted. If \fB--mounted\fP is passed, it would probe btrfs kernel to list mounted btrfs filesystem(s); If \fB--all-devices\fP is passed, all the devices under /dev are scanned; otherwise the devices list is extracted from the /proc/partitions file. +If \fB--print-missing\fP is passed, btrfs will try its best to print the missing device. +This option is only useful if the filesystem is already mounted since mounted filesystem may contain the device list. .TP \fBfilesystem sync\fR\fI \fR