From patchwork Mon Oct 12 13:22:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7375101 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F174F9F4DC for ; Mon, 12 Oct 2015 13:25:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0793920681 for ; Mon, 12 Oct 2015 13:25:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F224F20794 for ; Mon, 12 Oct 2015 13:24:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752359AbbJLNYx (ORCPT ); Mon, 12 Oct 2015 09:24:53 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:31025 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752111AbbJLNYv (ORCPT ); Mon, 12 Oct 2015 09:24:51 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="101738557" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Oct 2015 21:27:15 +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 t9CDOKOC026203 for ; Mon, 12 Oct 2015 21:24:20 +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; Mon, 12 Oct 2015 21:24:46 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH 06/11] btrfs-progs: inspect: use btrfs_open_dir for btrfs inspect command Date: Mon, 12 Oct 2015 21:22:59 +0800 Message-ID: <163c84b92016fc8905d80e820414db2dc62ab8d8.1444655800.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 We can use btrfs_open_dir() to check whether target dir is in btrfs's mount point before open, instead of checking it in kernel space of ioctl, and return fuzzy error message. Before patch: # ./btrfs inspect-internal rootid /mnt/tmp1 ERROR: Failed to lookup root id - Inappropriate ioctl for device btrfs inspect-internal rootid: rootid failed with ret=-1 # ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1 ioctl ret=-1, error: Inappropriate ioctl for device # ./btrfs inspect-internal min-dev-size /mnt/tmp1 Error invoking tree search ioctl: Inappropriate ioctl for device After patch: # ./btrfs inspect-internal rootid /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs inspect-internal min-dev-size /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 Signed-off-by: Zhao Lei --- cmds-inspect.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/cmds-inspect.c b/cmds-inspect.c index a13a170..40ab49b 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -116,11 +116,9 @@ static int cmd_inspect_inode_resolve(int argc, char **argv) if (check_argc_exact(argc - optind, 2)) usage(cmd_inspect_inode_resolve_usage); - fd = open_file_or_dir(argv[optind+1], &dirstream); - if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", argv[optind+1]); + fd = btrfs_open_dir(argv[optind + 1], &dirstream, 1); + if (fd < 0) return 1; - } ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd, verbose, argv[optind+1]); @@ -189,9 +187,8 @@ static int cmd_inspect_logical_resolve(int argc, char **argv) loi.size = size; loi.inodes = ptr_to_u64(inodes); - fd = open_file_or_dir(argv[optind+1], &dirstream); + fd = btrfs_open_dir(argv[optind + 1], &dirstream, 1); if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", argv[optind+1]); ret = 12; goto out; } @@ -239,10 +236,8 @@ static int cmd_inspect_logical_resolve(int argc, char **argv) name); BUG_ON(ret >= bytes_left); free(name); - path_fd = open_file_or_dir(full_path, &dirs); + path_fd = btrfs_open_dir(full_path, &dirs, 1); if (path_fd < 0) { - fprintf(stderr, "ERROR: can't access " - "'%s'\n", full_path); ret = -ENOENT; goto out; } @@ -279,9 +274,8 @@ static int cmd_inspect_subvolid_resolve(int argc, char **argv) if (check_argc_exact(argc, 3)) usage(cmd_inspect_subvolid_resolve_usage); - fd = open_file_or_dir(argv[2], &dirstream); + fd = btrfs_open_dir(argv[2], &dirstream, 1); if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", argv[2]); ret = -ENOENT; goto out; } @@ -320,9 +314,8 @@ static int cmd_inspect_rootid(int argc, char **argv) if (check_argc_exact(argc, 2)) usage(cmd_inspect_rootid_usage); - fd = open_file_or_dir(argv[1], &dirstream); + fd = btrfs_open_dir(argv[1], &dirstream, 1); if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", argv[1]); ret = -ENOENT; goto out; } @@ -619,9 +612,8 @@ static int cmd_inspect_min_dev_size(int argc, char **argv) if (check_argc_exact(argc - optind, 1)) usage(cmd_inspect_min_dev_size_usage); - fd = open_file_or_dir(argv[optind], &dirstream); + fd = btrfs_open_dir(argv[optind], &dirstream, 1); if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", argv[optind]); ret = -ENOENT; goto out; }