From patchwork Mon Oct 12 13:22:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7375081 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 00831BF90C for ; Mon, 12 Oct 2015 13:24:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 04850206A4 for ; Mon, 12 Oct 2015 13:24:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0FB3620681 for ; Mon, 12 Oct 2015 13:24:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752248AbbJLNYu (ORCPT ); Mon, 12 Oct 2015 09:24:50 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:38274 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752111AbbJLNYt (ORCPT ); Mon, 12 Oct 2015 09:24:49 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="101738553" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Oct 2015 21:27:11 +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 t9CDOH1Q026190 for ; Mon, 12 Oct 2015 21:24:17 +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:43 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH 02/11] btrfs-progs: filesystem: use btrfs_open_dir for btrfs filesystem command Date: Mon, 12 Oct 2015 21:22:55 +0800 Message-ID: <7c63fe4764710e398157c5ba112e2fc6c52a622b.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: # (/mnt/tmp is not btrfs mountpoint) # # btrfs filesystem df /mnt/tmp ERROR: couldn't get space info - Inappropriate ioctl for device ERROR: get_df failed Inappropriate ioctl for device # After patch: # ./btrfs filesystem df /mnt/tmp ERROR: not btrfs filesystem: /mnt/tmp # Signed-off-by: Zhao Lei --- cmds-fi-usage.c | 4 +--- cmds-filesystem.c | 19 +++++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c index 50d6333..5fefed4 100644 --- a/cmds-fi-usage.c +++ b/cmds-fi-usage.c @@ -901,10 +901,8 @@ int cmd_filesystem_usage(int argc, char **argv) int chunkcount = 0; int devcount = 0; - fd = open_file_or_dir(argv[i], &dirstream); + fd = btrfs_open_dir(argv[i], &dirstream, 1); if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", - argv[i]); ret = 1; goto out; } diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 3663734..91bf1fa 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -205,11 +205,10 @@ static int cmd_filesystem_df(int argc, char **argv) path = argv[1]; - fd = open_file_or_dir(path, &dirstream); - if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", path); + fd = btrfs_open_dir(path, &dirstream, 1); + if (fd < 0) return 1; - } + ret = get_df(fd, &sargs); if (ret == 0) { @@ -939,11 +938,9 @@ static int cmd_filesystem_sync(int argc, char **argv) path = argv[1]; - fd = open_file_or_dir(path, &dirstream); - if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", path); + fd = btrfs_open_dir(path, &dirstream, 1); + if (fd < 0) return 1; - } printf("FSSync '%s'\n", path); res = ioctl(fd, BTRFS_IOC_SYNC); @@ -1229,11 +1226,9 @@ static int cmd_filesystem_resize(int argc, char **argv) return 1; } - fd = open_file_or_dir(path, &dirstream); - if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", path); + fd = btrfs_open_dir(path, &dirstream, 1); + if (fd < 0) return 1; - } printf("Resize '%s' of '%s'\n", path, amount); memset(&args, 0, sizeof(args));