From patchwork Wed Aug 26 09:04:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7075681 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 85FFB9F305 for ; Wed, 26 Aug 2015 09:06:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9541020914 for ; Wed, 26 Aug 2015 09:06:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A471D20809 for ; Wed, 26 Aug 2015 09:06:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756604AbbHZJGH (ORCPT ); Wed, 26 Aug 2015 05:06:07 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:31219 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756417AbbHZJGF (ORCPT ); Wed, 26 Aug 2015 05:06:05 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100036006" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Aug 2015 17:09: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 t7Q95tTu016064 for ; Wed, 26 Aug 2015 17:05:55 +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 17:06:01 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH v2 2/2] btrfs-progs: use open_btrfs_dir for btrfs device command Date: Wed, 26 Aug 2015 17:04:23 +0800 Message-ID: <88fb97835205d1faa824e695128eeff5927eeda1.1440579753.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=-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; }