From patchwork Mon Oct 12 13:23:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7375141 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 3DEEFBEEA4 for ; Mon, 12 Oct 2015 13:25:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4BBA7206A4 for ; Mon, 12 Oct 2015 13:25:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C0BC20681 for ; Mon, 12 Oct 2015 13:25:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752347AbbJLNYx (ORCPT ); Mon, 12 Oct 2015 09:24:53 -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 S1752266AbbJLNYw (ORCPT ); Mon, 12 Oct 2015 09:24:52 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="101738558" 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 t9CDOL0f026206 for ; Mon, 12 Oct 2015 21:24:21 +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:47 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH 07/11] btrfs-progs: qgroup: use btrfs_open_dir for btrfs qgroup command Date: Mon, 12 Oct 2015 21:23:00 +0800 Message-ID: <2b77db10ce6818718b4877df8f8ca04ba11760bc.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 qgroup create 1/5 /mnt/tmp1 ERROR: unable to create quota group: Inappropriate ioctl for device # # ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1 ERROR: unable to assign quota group: Inappropriate ioctl for device # # ./btrfs qgroup show /mnt/tmp1 ERROR: can't perform the search - Inappropriate ioctl for device ERROR: can't list qgroups: Inappropriate ioctl for device # # ./btrfs qgroup limit 1G 1/5 /mnt/tmp1 ERROR: unable to limit requested quota group: Inappropriate ioctl for device After patch: # ./btrfs qgroup create 1/5 /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs qgroup show /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs qgroup limit 1G 1/5 /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 Signed-off-by: Zhao Lei --- cmds-qgroup.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 48c1733..0ad99f4 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -79,11 +79,9 @@ static int qgroup_assign(int assign, int argc, char **argv) fprintf(stderr, "ERROR: bad relation requested '%s'\n", path); 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; - } ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args); e = errno; @@ -137,11 +135,9 @@ static int qgroup_create(int create, int argc, char **argv) args.create = create; args.qgroupid = parse_qgroupid(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 = ioctl(fd, BTRFS_IOC_QGROUP_CREATE, &args); e = errno; @@ -351,11 +347,9 @@ static int cmd_qgroup_show(int argc, char **argv) usage(cmd_qgroup_show_usage); path = argv[optind]; - 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; - } if (filter_flag) { qgroupid = btrfs_get_path_rootid(fd); @@ -460,11 +454,9 @@ static int cmd_qgroup_limit(int argc, char **argv) } else usage(cmd_qgroup_limit_usage); - 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 = ioctl(fd, BTRFS_IOC_QGROUP_LIMIT, &args); e = errno;