From patchwork Sat Jul 28 15:15:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10547999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A99BB112E for ; Sat, 28 Jul 2018 15:16:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A4B62B20D for ; Sat, 28 Jul 2018 15:16:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8ED892B555; Sat, 28 Jul 2018 15:16:49 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,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 36CE82B20D for ; Sat, 28 Jul 2018 15:16:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729049AbeG1Qni (ORCPT ); Sat, 28 Jul 2018 12:43:38 -0400 Received: from mout.gmx.net ([212.227.15.15]:48023 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728951AbeG1Qni (ORCPT ); Sat, 28 Jul 2018 12:43:38 -0400 Received: from localhost.localdomain ([113.87.89.132]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MIdTM-1fhE2632L2-002EPM; Sat, 28 Jul 2018 17:16:43 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 3/6] ceph: refactor error handling code in ceph_reserve_caps() Date: Sat, 28 Jul 2018 23:15:37 +0800 Message-Id: <20180728151540.11253-4-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180728151540.11253-1-cgxu519@gmx.com> References: <20180728151540.11253-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:vRt3F8Tz9uNCrLjpxzgR6YR6ZQRWwNEJ/46lGp50cJbYDDcdDRg y9AzTSwSnmo08tFZXjkJderqFqZpN1Sba8+XMDqmCst8y6ooM95EIBZmLZF6doa2lXOHVFy LBEbtN41UzWLbDkmB61E5wM4i9/cQcaSZAxr5D905XmJMUyn7i3USTGvBo6Z3Zs1CVagBlm kvZll234ViGEKPY8fJ+NA== X-UI-Out-Filterresults: notjunk:1;V01:K0:zxDO/AxETwU=:7eBQJciG98kP/jIO4IEwMT D4QkSsNao6uG1RGi52inYXxYp3oJ5umbQxNg8tuZL6lL/pZ53QRcvHw7MYahoy2cGW0PYXMwM OanthsC2/fXglJAyEB3FxfBND5xA2yi1uZCQoQmyIEHJv9PAe5Z063lnfTfUjqxl9yTBnWFgN TO1GlyXCUrHTXOysTyM7V6GRETmOSivuljb/cgS1O5u/DZsLJ39o79voW+x2qRRU3DGuBmGFy 3kZNuo0Pcs4Or2MLs1u+sEv0Ipjx0KdtpWH3CPvS5cJK0r0DMthZ8X98FD4H+Xg/OqWm8xnUp PB3LkXk39+PrZR29zdzcTzhbwd10Dh2Ly402lHxFA5IPI2c9FSeUt5OGne6w/XRNdQSi3joIK XUsIYvmcjjj26IPyZrEc8fyxRVGkS6VOI9Kxb1iseE8misCgTYelk7BaD2aJ6xweO3SNPqQWj RxxC8Pcu71c+TSL91ENoAjhBjzPiVE2vG8HD/J9bwwykkU21P10efxxnV/sBCnlSwBRxIXAsK +DF7FuRLglRjvhQxMbMIUazGqCkKqIPDW8iotbs5FM4MjIGFIxcQSiyQpRUIWPFZtydbPWC5U S56qfPV7pgppuMcsoCK1BofkCXvNZRBlcJC/c3uH+pPybauEkW+GslM0HLulatshO65E7xztk ZXX1bZ1R+9ZifSr+w+prxDz9VtMdN7RsZY830C3/W67oYBuflS2nGGdSdKKKeS6GvhwyJMatD BPVMId2VRHGJSz1CzXmhI4LnEkbkmCgHTV/JxtQBwFGX1B/NKuwW3FTT9C8= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Call new helper __ceph_unreserve_caps() to reduce duplicated code. Signed-off-by: Chengguang Xu --- fs/ceph/caps.c | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 8129f6b39147..22eb70742c0b 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -198,6 +198,7 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, int have; int alloc = 0; int max_caps; + int err = 0; bool trimmed = false; struct ceph_mds_session *s; LIST_HEAD(newcaps); @@ -264,10 +265,12 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, pr_warn("reserve caps ctx=%p ENOMEM need=%d got=%d\n", ctx, need, have + alloc); + err = -ENOMEM; goto out_nomem; } BUG_ON(have + alloc != need); +out_nomem: spin_lock(&mdsc->caps_list_lock); mdsc->caps_total_count += alloc; mdsc->caps_reserve_count += alloc; @@ -276,42 +279,17 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + mdsc->caps_reserve_count + mdsc->caps_avail_count); + + if (err) + __ceph_unreserve_caps(mdsc, have + alloc); + else + ctx->count = need; spin_unlock(&mdsc->caps_list_lock); - ctx->count = need; dout("reserve caps ctx=%p %d = %d used + %d resv + %d avail\n", ctx, mdsc->caps_total_count, mdsc->caps_use_count, mdsc->caps_reserve_count, mdsc->caps_avail_count); - return 0; - -out_nomem: - - spin_lock(&mdsc->caps_list_lock); - mdsc->caps_avail_count += have; - mdsc->caps_reserve_count -= have; - - while (!list_empty(&newcaps)) { - cap = list_first_entry(&newcaps, - struct ceph_cap, caps_item); - list_del(&cap->caps_item); - - /* Keep some preallocated caps around (ceph_min_count), to - * avoid lots of free/alloc churn. */ - if (mdsc->caps_avail_count >= - mdsc->caps_reserve_count + mdsc->caps_min_count) { - kmem_cache_free(ceph_cap_cachep, cap); - } else { - mdsc->caps_avail_count++; - mdsc->caps_total_count++; - list_add(&cap->caps_item, &mdsc->caps_list); - } - } - - BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + - mdsc->caps_reserve_count + - mdsc->caps_avail_count); - spin_unlock(&mdsc->caps_list_lock); - return -ENOMEM; + return err; } int ceph_unreserve_caps(struct ceph_mds_client *mdsc,