From patchwork Mon Dec 4 10:20:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Fengqi X-Patchwork-Id: 10089915 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 309E060329 for ; Mon, 4 Dec 2017 10:22:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2341726E47 for ; Mon, 4 Dec 2017 10:22:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17F152887A; Mon, 4 Dec 2017 10:22:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B343126E47 for ; Mon, 4 Dec 2017 10:22:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753516AbdLDKWB (ORCPT ); Mon, 4 Dec 2017 05:22:01 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:20500 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753494AbdLDKWA (ORCPT ); Mon, 4 Dec 2017 05:22:00 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="30693130" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Dec 2017 18:21:59 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id C9F59482D017 for ; Mon, 4 Dec 2017 18:21:54 +0800 (CST) Received: from localhost.localdomain (10.167.226.155) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 4 Dec 2017 18:21:55 +0800 From: Lu Fengqi To: Subject: [PATCH v2 2/4] btrfs-progs: qgroup: cleanup __qgroup_search Date: Mon, 4 Dec 2017 18:20:42 +0800 Message-ID: <20171204102044.25702-3-lufq.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171204102044.25702-1-lufq.fnst@cn.fujitsu.com> References: <20171204102044.25702-1-lufq.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.155] X-yoursite-MailScanner-ID: C9F59482D017.ABAE5 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lufq.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; }