[1/2] btrfs-progs: qgroup: move btrfs_show_qgroups's error handler to __qgroup_search
diff mbox

Message ID 20171113053316.14573-1-lufq.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Lu Fengqi Nov. 13, 2017, 5:33 a.m. UTC
We have to process the return value of BTRFS_IOC_TREE_SEARCH ioctl in
advance, so that we can distinguish between the two case where quota
is not enabled (ioctl return -ENOENT) and either parent qgroup or child
qgroup does not exist (update_qgroup_relation return -ENOENT). Besides
this, any error in this routine has been reported, so we don't need to
report again in cmd_qgroup_show.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---
 cmds-qgroup.c |  4 ----
 qgroup.c      | 14 ++++++++++++--
 2 files changed, 12 insertions(+), 6 deletions(-)

Comments

David Sterba Jan. 8, 2018, 6:23 p.m. UTC | #1
On Mon, Nov 13, 2017 at 01:33:15PM +0800, Lu Fengqi wrote:
> We have to process the return value of BTRFS_IOC_TREE_SEARCH ioctl in
> advance, so that we can distinguish between the two case where quota
> is not enabled (ioctl return -ENOENT) and either parent qgroup or child
> qgroup does not exist (update_qgroup_relation return -ENOENT). Besides
> this, any error in this routine has been reported, so we don't need to
> report again in cmd_qgroup_show.
> 
> Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>

1 and 2 applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 38382ea9..d07bb0c0 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -399,10 +399,6 @@  static int cmd_qgroup_show(int argc, char **argv)
 					qgroupid);
 	}
 	ret = btrfs_show_qgroups(fd, filter_set, comparer_set);
-	if (ret == -ENOENT)
-		error("can't list qgroups: quotas not enabled");
-	else if (ret < 0)
-		error("can't list qgroups: %s", strerror(-ret));
 	close_file_or_dir(fd, dirstream);
 
 out:
diff --git a/qgroup.c b/qgroup.c
index 156825fd..23463d8a 100644
--- a/qgroup.c
+++ b/qgroup.c
@@ -1065,8 +1065,18 @@  static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
 
 	while (1) {
 		ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
-		if (ret < 0)
-			return -errno;
+		if (ret < 0) {
+			if (errno == ENOENT) {
+				error("can't list qgroups: quotas not enabled");
+				ret = -ENOTTY;
+			} else {
+				error("can't list qgroups: %s",
+				       strerror(errno));
+				ret = -errno;
+			}
+
+			break;
+		}
 
 		/* the ioctl returns the number of item it found in nr_items */
 		if (sk->nr_items == 0)