From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bob Liu Subject: [PATCH 12/14] tmem: cleanup: refactor function tmemc_shared_pool_auth() Date: Wed, 18 Dec 2013 14:52:39 +0800 Message-ID: <1387349561-27923-13-git-send-email-bob.liu@oracle.com> References: <1387349561-27923-1-git-send-email-bob.liu@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VtB3t-0007LR-Rq for xen-devel@lists.xenproject.org; Wed, 18 Dec 2013 06:56:54 +0000 Received: by mail-pb0-f41.google.com with SMTP id jt11so8094742pbb.0 for ; Tue, 17 Dec 2013 22:56:50 -0800 (PST) In-Reply-To: <1387349561-27923-1-git-send-email-bob.liu@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: james.harper@bendigoit.com.au, keir@xen.org, ian.campbell@citrix.com, andrew.cooper3@citrix.com, JBeulich@suse.com List-Id: xen-devel@lists.xenproject.org Make function tmemc_shared_pool_auth() more readable. Signed-off-by: Bob Liu --- xen/common/tmem.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/xen/common/tmem.c b/xen/common/tmem.c index eea3cbb..37f4e8f 100644 --- a/xen/common/tmem.c +++ b/xen/common/tmem.c @@ -2252,27 +2252,39 @@ static int tmemc_shared_pool_auth(domid_t cli_id, uint64_t uuid_lo, client = tmem_client_from_cli_id(cli_id); if ( client == NULL ) return -EINVAL; + for ( i = 0; i < MAX_GLOBAL_SHARED_POOLS; i++) { - if ( (client->shared_auth_uuid[i][0] == uuid_lo) && - (client->shared_auth_uuid[i][1] == uuid_hi) ) + if ( auth == 0 ) { - if ( auth == 0 ) - client->shared_auth_uuid[i][0] = - client->shared_auth_uuid[i][1] = -1L; - return 1; + if ( (client->shared_auth_uuid[i][0] == uuid_lo) && + (client->shared_auth_uuid[i][1] == uuid_hi) ) + { + client->shared_auth_uuid[i][0] = -1L; + client->shared_auth_uuid[i][1] = -1L; + return 1; + } } - if ( (auth == 1) && (client->shared_auth_uuid[i][0] == -1L) && - (client->shared_auth_uuid[i][1] == -1L) && (free == -1) ) - free = i; + else + { + if ( (client->shared_auth_uuid[i][0] == -1L) && + (client->shared_auth_uuid[i][1] == -1L) ) + { + free = i; + break; + } + } } if ( auth == 0 ) return 0; - if ( auth == 1 && free == -1 ) + else if ( free == -1) return -ENOMEM; - client->shared_auth_uuid[free][0] = uuid_lo; - client->shared_auth_uuid[free][1] = uuid_hi; - return 1; + else + { + client->shared_auth_uuid[free][0] = uuid_lo; + client->shared_auth_uuid[free][1] = uuid_hi; + return 1; + } } static int tmemc_save_subop(int cli_id, uint32_t pool_id, -- 1.7.10.4