From patchwork Wed Aug 26 06:15:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7074571 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 76FFAC05AC for ; Wed, 26 Aug 2015 06:17:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A1079208DA for ; Wed, 26 Aug 2015 06:17:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE8D320823 for ; Wed, 26 Aug 2015 06:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756418AbbHZGRL (ORCPT ); Wed, 26 Aug 2015 02:17:11 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:21034 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756407AbbHZGRJ (ORCPT ); Wed, 26 Aug 2015 02:17:09 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100029297" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Aug 2015 14:20:16 +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 t7Q6Gx5k004420 for ; Wed, 26 Aug 2015 14:16:59 +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, 26 Aug 2015 14:17:05 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH 2/2] btrfs-progs: use open_btrfs_dir for btrfs device command Date: Wed, 26 Aug 2015 14:15:28 +0800 Message-ID: X-Mailer: git-send-email 1.8.5.1 In-Reply-To: <5378c4862f34d6459665448b437d79d5847ce2b5.1440569707.git.zhaolei@cn.fujitsu.com> References: <5378c4862f34d6459665448b437d79d5847ce2b5.1440569707.git.zhaolei@cn.fujitsu.com> 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=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 open_btrfs_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 device add -f /dev/sda13 /mnt/tmp ERROR: error adding the device '/dev/sda13' - Inappropriate ioctl for device # After patch: # btrfs device add -f /dev/sda13 /mnt/tmp ERROR: not btrfs filesystem: /mnt/tmp # Similar fix for device remove and device usage. Signed-off-by: Zhao Lei --- cmds-device.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index 00e362a..2dba050 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -84,11 +84,9 @@ static int cmd_device_add(int argc, char **argv) mntpnt = argv[optind + argc - 1]; - fdmnt = open_file_or_dir(mntpnt, &dirstream); - if (fdmnt < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", mntpnt); + fdmnt = open_btrfs_dir(mntpnt, &dirstream, 1); + if (fdmnt < 0) return 1; - } for (i = optind; i < optind + argc - 1; i++){ struct btrfs_ioctl_vol_args ioctl_args; @@ -157,11 +155,9 @@ static int _cmd_device_remove(int argc, char **argv, mntpnt = argv[argc - 1]; - fdmnt = open_file_or_dir(mntpnt, &dirstream); - if (fdmnt < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", mntpnt); + fdmnt = open_btrfs_dir(mntpnt, &dirstream, 1); + if (fdmnt < 0) return 1; - } for(i=1 ; i < argc - 1; i++ ){ struct btrfs_ioctl_vol_args arg; @@ -586,10 +582,8 @@ int cmd_device_usage(int argc, char **argv) if (more_than_one) printf("\n"); - fd = open_file_or_dir(argv[i], &dirstream); + fd = open_btrfs_dir(argv[i], &dirstream, 1); if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", - argv[1]); ret = 1; goto out; }