All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH v2 2/4] btrfs-progs: qgroup: cleanup __qgroup_search
Date: Mon, 4 Dec 2017 18:20:42 +0800	[thread overview]
Message-ID: <20171204102044.25702-3-lufq.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20171204102044.25702-1-lufq.fnst@cn.fujitsu.com>

Replace the if statement with the switch statement, and return the
appropriate value for the future use rather than directly exit.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---

Changelog:
v2:
1. revoke incorrect goto pattern
2. split the error handler movement to another patch

 qgroup.c | 48 ++++++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 22 deletions(-)

diff --git a/qgroup.c b/qgroup.c
index 23463d8a..b5b893f4 100644
--- a/qgroup.c
+++ b/qgroup.c
@@ -1046,8 +1046,10 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
 	struct btrfs_ioctl_search_header *sh;
 	unsigned long off = 0;
 	unsigned int i;
+	struct btrfs_qgroup_status_item *si;
 	struct btrfs_qgroup_info_item *info;
 	struct btrfs_qgroup_limit_item *limit;
+	u64 flags;
 	u64 qgroupid;
 	u64 qgroupid1;
 
@@ -1092,44 +1094,47 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
 								  off);
 			off += sizeof(*sh);
 
-			if (btrfs_search_header_type(sh)
-			    == BTRFS_QGROUP_STATUS_KEY) {
-				struct btrfs_qgroup_status_item *si;
-				u64 flags;
-
+			switch (btrfs_search_header_type(sh)) {
+			case BTRFS_QGROUP_STATUS_KEY:
 				si = (struct btrfs_qgroup_status_item *)
 				     (args.buf + off);
 				flags = btrfs_stack_qgroup_status_flags(si);
+
 				print_status_flag_warning(flags);
-			} else if (btrfs_search_header_type(sh)
-				   == BTRFS_QGROUP_INFO_KEY) {
+				break;
+			case BTRFS_QGROUP_INFO_KEY:
 				qgroupid = btrfs_search_header_offset(sh);
 				info = (struct btrfs_qgroup_info_item *)
 				       (args.buf + off);
 
-				update_qgroup_info(qgroup_lookup, qgroupid,
-						   info);
-			} else if (btrfs_search_header_type(sh)
-				   == BTRFS_QGROUP_LIMIT_KEY) {
+				ret = update_qgroup_info(qgroup_lookup,
+							 qgroupid, info);
+				break;
+			case BTRFS_QGROUP_LIMIT_KEY:
 				qgroupid = btrfs_search_header_offset(sh);
 				limit = (struct btrfs_qgroup_limit_item *)
 					(args.buf + off);
 
-				update_qgroup_limit(qgroup_lookup, qgroupid,
-						    limit);
-			} else if (btrfs_search_header_type(sh)
-				   == BTRFS_QGROUP_RELATION_KEY) {
+				ret = update_qgroup_limit(qgroup_lookup,
+							  qgroupid, limit);
+				break;
+			case BTRFS_QGROUP_RELATION_KEY:
 				qgroupid = btrfs_search_header_offset(sh);
 				qgroupid1 = btrfs_search_header_objectid(sh);
 
 				if (qgroupid < qgroupid1)
-					goto skip;
+					break;
+
+				ret = update_qgroup_relation(qgroup_lookup,
+							qgroupid, qgroupid1);
+				break;
+			default:
+				return ret;
+			}
+
+			if (ret)
+				return ret;
 
-				update_qgroup_relation(qgroup_lookup, qgroupid,
-						       qgroupid1);
-			} else
-				goto done;
-skip:
 			off += btrfs_search_header_len(sh);
 
 			/*
@@ -1151,7 +1156,6 @@ skip:
 			break;
 	}
 
-done:
 	return ret;
 }
 
-- 
2.14.3




  parent reply	other threads:[~2017-12-04 10:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-04 10:20 [PATCH 0/4] qgroup cleanup and add show path feature Lu Fengqi
2017-12-04 10:20 ` [PATCH 1/4] btrfs-progs: qgroup: move btrfs_show_qgroups's error handler to __qgroup_search Lu Fengqi
2017-12-04 10:20 ` Lu Fengqi [this message]
2017-12-04 10:20 ` [PATCH v2 3/4] btrfs-progs: qgroup: show subvol path when qgroup show Lu Fengqi
2017-12-04 10:20 ` [PATCH v2 4/4] btrfs-progs: qgroup: allow show qgroup in order of subvol path Lu Fengqi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171204102044.25702-3-lufq.fnst@cn.fujitsu.com \
    --to=lufq.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.