diff mbox

[1/2] ceph: introudce a variable to avoid calling refcount_read() twice

Message ID 20180712083533.23854-1-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chengguang Xu July 12, 2018, 8:35 a.m. UTC
Calling refcount_read() twice may return different value each time,
so introduce a variable to avoid it.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 fs/ceph/mds_client.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox

Patch

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);