diff mbox series

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

Message ID 20180802133222.3692-1-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] ceph: introudce a variable to avoid calling atomic_read() twice | expand

Commit Message

Chengguang Xu Aug. 2, 2018, 1:32 p.m. UTC
Calling atomic_read() twice in a debug message may return different
value each time, so introduce a variable to avoid it.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
v1->v2:
- Keep atomic_t type as it is and only fix the problem of calling
atomic_read() twice in a debug message.

 fs/ceph/snap.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index 01b0144c0b73..4f8228e58d73 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -63,8 +63,8 @@ 
 void ceph_get_snap_realm(struct ceph_mds_client *mdsc,
 			 struct ceph_snap_realm *realm)
 {
-	dout("get_realm %p %d -> %d\n", realm,
-	     atomic_read(&realm->nref), atomic_read(&realm->nref)+1);
+	int nref = atomic_read(&realm->nref);
+	dout("get_realm %p %d -> %d\n", realm, nref, nref + 1);
 	/*
 	 * since we _only_ increment realm refs or empty the empty
 	 * list with snap_rwsem held, adjusting the empty list here is
@@ -193,8 +193,9 @@  static void __destroy_snap_realm(struct ceph_mds_client *mdsc,
 static void __put_snap_realm(struct ceph_mds_client *mdsc,
 			     struct ceph_snap_realm *realm)
 {
+	int nref = atomic_read(&realm->nref);
 	dout("__put_snap_realm %llx %p %d -> %d\n", realm->ino, realm,
-	     atomic_read(&realm->nref), atomic_read(&realm->nref)-1);
+		nref, nref - 1);
 	if (atomic_dec_and_test(&realm->nref))
 		__destroy_snap_realm(mdsc, realm);
 }
@@ -205,8 +206,9 @@  static void __put_snap_realm(struct ceph_mds_client *mdsc,
 void ceph_put_snap_realm(struct ceph_mds_client *mdsc,
 			 struct ceph_snap_realm *realm)
 {
+	int nref = atomic_read(&realm->nref);
 	dout("put_snap_realm %llx %p %d -> %d\n", realm->ino, realm,
-	     atomic_read(&realm->nref), atomic_read(&realm->nref)-1);
+		nref, nref - 1);
 	if (!atomic_dec_and_test(&realm->nref))
 		return;