From patchwork Thu Jul 12 08:35:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10521279 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 BD980601C2 for ; Thu, 12 Jul 2018 08:36:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A9D929356 for ; Thu, 12 Jul 2018 08:36:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E6AB29512; Thu, 12 Jul 2018 08:36:36 +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 218E829356 for ; Thu, 12 Jul 2018 08:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726529AbeGLIpI (ORCPT ); Thu, 12 Jul 2018 04:45:08 -0400 Received: from mout.gmx.net ([212.227.17.20]:48745 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725845AbeGLIpI (ORCPT ); Thu, 12 Jul 2018 04:45:08 -0400 Received: from x201.localdomain ([117.136.31.239]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LjLwB-1gD9YA28pb-00dTKx; Thu, 12 Jul 2018 10:36:30 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.co, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 1/2] ceph: introudce a variable to avoid calling refcount_read() twice Date: Thu, 12 Jul 2018 16:35:32 +0800 Message-Id: <20180712083533.23854-1-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 X-Provags-ID: V03:K1:/iTCix+daRh2ywXAdPgLOgJIWUgBE7VpAf7h5+2BckfdKre8K95 m/7CW8vENPq5B9uyMkj320TqSh+wuqXW+rHbeotXvm05ioH3JFU4eVvSg35FkHAjSFtXCBn hcF9fvS3A4EFT+DG5+t8nDevsJ67d6Z++pb127D9E/epvCRXmmvignOu1yAJdajjYmMaUtI REWMG2rbqG+dQbGQnqffg== X-UI-Out-Filterresults: notjunk:1; V01:K0:+wvqEacLAg4=:KFXn1X1d38Pvg7qiSt3jb4 GbPShrgmCVtbXgsUFCt85Ur9Ixlqoh/snAMF7BBZJFV9X5hNJwzA2oiUy1jmfWPuG2R3aaW+l rNtvRATtyu9pB7QQkh4FrAN3EKDRNtAFNLLPhYQ0SbSaGTAsLCfT41dIqoEe6JN5QnV+nCc0p rebtlYhwfliLUqOiAc1RfQtlloI38AkXjU2NatTN5T/YxzUr2n1gj7C0nhnOqMfcv2tx8QEbv JFqgFPUMxiKe5FbhtGOecg64YJMqMD6xWC5e3jum6v8/WZ0gTqTLW5jEsjVR7XDwO5z+CxJVu 2HNvdCdTmu7rDdpES1oWLzT7K3gS7goPKMEPLYQq85BQdR568I5XlmxHwTiY4nJ7RHAzdwpC1 oY+D2yyxIsvG8BOkSpmNQbq/ifaii3J6mmIVi1Ur5MlHowNN0FHjiXk2p3vmjEvuKe3oNcWKK BdhA07EtfPiRRJdS6mXHFqGyVdbQs9v5EQq2S+Z9zK1LdV1r5ErFJQkuvaxTmGoYE0ca3SqIq c+T54G6YvertHpY82NXYhmoO1zXXLhiB7UbO5lYD6axs4T8iL9vCWNVSs/JQiA0m54fSFflQy 4WHhP+NryFc2V5LWowBwuKlJQbMomvEmfn/J5D6YtIHy4ACOy/1unWCuLhXIVIFoeG2ZetWwt o513mm8XV0WMHMHdXp0t+ERbIp4Qw5TGXtTxVJmp5dkjuc7QMBGfAtcLvWs5IirzCmK+fCWLi Cf/bnHrov5b7xlhOYFbsggOelextu90tVEN5YJZYuFxbptxmjBQUzbtwCOg= 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 Calling refcount_read() twice may return different value each time, so introduce a variable to avoid it. Signed-off-by: Chengguang Xu --- fs/ceph/mds_client.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index df0a3bb0f6a5..2a8d4cc69eb6 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -399,9 +399,10 @@ const char *ceph_session_state_name(int s) static struct ceph_mds_session *get_session(struct ceph_mds_session *s) { + unsigned int refcnt = refcount_read(&s->s_ref); + if (refcount_inc_not_zero(&s->s_ref)) { - dout("mdsc get_session %p %d -> %d\n", s, - refcount_read(&s->s_ref)-1, refcount_read(&s->s_ref)); + dout("mdsc get_session %p %d -> %d\n", s, refcnt - 1, refcnt); return s; } else { dout("mdsc get_session %p 0 -- FAIL\n", s); @@ -411,8 +412,9 @@ static struct ceph_mds_session *get_session(struct ceph_mds_session *s) void ceph_put_mds_session(struct ceph_mds_session *s) { - dout("mdsc put_session %p %d -> %d\n", s, - refcount_read(&s->s_ref), refcount_read(&s->s_ref)-1); + unsigned int refcnt = refcount_read(&s->s_ref); + + dout("mdsc put_session %p %d -> %d\n", s, refcnt, refcnt - 1); if (refcount_dec_and_test(&s->s_ref)) { if (s->s_auth.authorizer) ceph_auth_destroy_authorizer(s->s_auth.authorizer);