Whamcloud - gitweb
b=23289 cleanup assertion on atomic
authorJian Yu <jian.yu@oracle.com>
Mon, 29 Nov 2010 13:37:56 +0000 (21:37 +0800)
committerVitaly Fertman <vitaly.fertman@oracle.com>
Wed, 1 Dec 2010 01:45:33 +0000 (04:45 +0300)
Remove assertion on atomic from addref functions, which is less helpful,
also, add macros to reduce atomic_read() in assertion.

o=Liang Zhen
i=andreas.dilger
i=mikhail.pershin
i=vitaly.fertman

libcfs/include/libcfs/libcfs_private.h
lnet/klnds/o2iblnd/o2iblnd.h
lustre/include/lustre_log.h
lustre/include/obd_class.h
lustre/ldlm/ldlm_lib.c
lustre/ldlm/ldlm_resource.c
lustre/obdclass/genops.c
lustre/ptlrpc/sec.c
lustre/ptlrpc/sec_null.c

index d7dfac6..92f9854 100644 (file)
@@ -288,6 +288,98 @@ int libcfs_debug_cleanup(void);
 /* !__KERNEL__ */
 #endif
 
 /* !__KERNEL__ */
 #endif
 
+#define LASSERT_ATOMIC_ENABLED          (1)
+
+#if LASSERT_ATOMIC_ENABLED
+
+/** assert value of @a is equal to @v */
+#define LASSERT_ATOMIC_EQ(a, v)                                 \
+do {                                                            \
+        LASSERTF(cfs_atomic_read(a) == v,                       \
+                 "value: %d\n", cfs_atomic_read((a)));          \
+} while (0)
+
+/** assert value of @a is unequal to @v */
+#define LASSERT_ATOMIC_NE(a, v)                                 \
+do {                                                            \
+        LASSERTF(cfs_atomic_read(a) != v,                       \
+                 "value: %d\n", cfs_atomic_read((a)));          \
+} while (0)
+
+/** assert value of @a is little than @v */
+#define LASSERT_ATOMIC_LT(a, v)                                 \
+do {                                                            \
+        LASSERTF(cfs_atomic_read(a) < v,                        \
+                 "value: %d\n", cfs_atomic_read((a)));          \
+} while (0)
+
+/** assert value of @a is little/equal to @v */
+#define LASSERT_ATOMIC_LE(a, v)                                 \
+do {                                                            \
+        LASSERTF(cfs_atomic_read(a) <= v,                       \
+                 "value: %d\n", cfs_atomic_read((a)));          \
+} while (0)
+
+/** assert value of @a is great than @v */
+#define LASSERT_ATOMIC_GT(a, v)                                 \
+do {                                                            \
+        LASSERTF(cfs_atomic_read(a) > v,                        \
+                 "value: %d\n", cfs_atomic_read((a)));          \
+} while (0)
+
+/** assert value of @a is great/equal to @v */
+#define LASSERT_ATOMIC_GE(a, v)                                 \
+do {                                                            \
+        LASSERTF(cfs_atomic_read(a) >= v,                       \
+                 "value: %d\n", cfs_atomic_read((a)));          \
+} while (0)
+
+/** assert value of @a is great than @v1 and little than @v2 */
+#define LASSERT_ATOMIC_GT_LT(a, v1, v2)                         \
+do {                                                            \
+        int __v = cfs_atomic_read(a);                           \
+        LASSERTF(__v > v1 && __v < v2, "value: %d\n", __v);     \
+} while (0)
+
+/** assert value of @a is great than @v1 and little/equal to @v2 */
+#define LASSERT_ATOMIC_GT_LE(a, v1, v2)                         \
+do {                                                            \
+        int __v = cfs_atomic_read(a);                           \
+        LASSERTF(__v > v1 && __v <= v2, "value: %d\n", __v);    \
+} while (0)
+
+/** assert value of @a is great/equal to @v1 and little than @v2 */
+#define LASSERT_ATOMIC_GE_LT(a, v1, v2)                         \
+do {                                                            \
+        int __v = cfs_atomic_read(a);                           \
+        LASSERTF(__v >= v1 && __v < v2, "value: %d\n", __v);    \
+} while (0)
+
+/** assert value of @a is great/equal to @v1 and little/equal to @v2 */
+#define LASSERT_ATOMIC_GE_LE(a, v1, v2)                         \
+do {                                                            \
+        int __v = cfs_atomic_read(a);                           \
+        LASSERTF(__v >= v1 && __v <= v2, "value: %d\n", __v);   \
+} while (0)
+
+#else /* !LASSERT_ATOMIC_ENABLED */
+
+#define LASSERT_ATOMIC_EQ(a, v)                 do {} while (0)
+#define LASSERT_ATOMIC_NE(a, v)                 do {} while (0)
+#define LASSERT_ATOMIC_LT(a, v)                 do {} while (0)
+#define LASSERT_ATOMIC_LE(a, v)                 do {} while (0)
+#define LASSERT_ATOMIC_GT(a, v)                 do {} while (0)
+#define LASSERT_ATOMIC_GE(a, v)                 do {} while (0)
+#define LASSERT_ATOMIC_GT_LT(a, v1, v2)         do {} while (0)
+#define LASSERT_ATOMIC_GT_LE(a, v1, v2)         do {} while (0)
+#define LASSERT_ATOMIC_GE_LT(a, v1, v2)         do {} while (0)
+#define LASSERT_ATOMIC_GE_LE(a, v1, v2)         do {} while (0)
+
+#endif /* LASSERT_ATOMIC_ENABLED */
+
+#define LASSERT_ATOMIC_ZERO(a)                  LASSERT_ATOMIC_EQ(a, 0)
+#define LASSERT_ATOMIC_POS(a)                   LASSERT_ATOMIC_GT(a, 0)
+
 #define CFS_ALLOC_PTR(ptr)      LIBCFS_ALLOC(ptr, sizeof (*(ptr)));
 #define CFS_FREE_PTR(ptr)       LIBCFS_FREE(ptr, sizeof (*(ptr)));
 
 #define CFS_ALLOC_PTR(ptr)      LIBCFS_ALLOC(ptr, sizeof (*(ptr)));
 #define CFS_FREE_PTR(ptr)       LIBCFS_FREE(ptr, sizeof (*(ptr)));
 
index 8f7db5a..491cd70 100644 (file)
@@ -647,7 +647,6 @@ kiblnd_dev_can_failover(kib_dev_t *dev)
 do {                                                            \
         CDEBUG(D_NET, "conn[%p] (%d)++\n",                      \
                (conn), cfs_atomic_read(&(conn)->ibc_refcount)); \
 do {                                                            \
         CDEBUG(D_NET, "conn[%p] (%d)++\n",                      \
                (conn), cfs_atomic_read(&(conn)->ibc_refcount)); \
-        LASSERT(cfs_atomic_read(&(conn)->ibc_refcount) > 0);    \
         cfs_atomic_inc(&(conn)->ibc_refcount);                  \
 } while (0)
 
         cfs_atomic_inc(&(conn)->ibc_refcount);                  \
 } while (0)
 
@@ -657,7 +656,7 @@ do {                                                                           \
                                                                                \
         CDEBUG(D_NET, "conn[%p] (%d)--\n",                                     \
                (conn), cfs_atomic_read(&(conn)->ibc_refcount));                \
                                                                                \
         CDEBUG(D_NET, "conn[%p] (%d)--\n",                                     \
                (conn), cfs_atomic_read(&(conn)->ibc_refcount));                \
-        LASSERT(cfs_atomic_read(&(conn)->ibc_refcount) > 0);                   \
+        LASSERT_ATOMIC_POS(&(conn)->ibc_refcount);                             \
         if (cfs_atomic_dec_and_test(&(conn)->ibc_refcount)) {                  \
                 cfs_spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);     \
                 cfs_list_add_tail(&(conn)->ibc_list,                           \
         if (cfs_atomic_dec_and_test(&(conn)->ibc_refcount)) {                  \
                 cfs_spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);     \
                 cfs_list_add_tail(&(conn)->ibc_list,                           \
@@ -672,7 +671,6 @@ do {                                                            \
         CDEBUG(D_NET, "peer[%p] -> %s (%d)++\n",                \
                (peer), libcfs_nid2str((peer)->ibp_nid),         \
                cfs_atomic_read (&(peer)->ibp_refcount));        \
         CDEBUG(D_NET, "peer[%p] -> %s (%d)++\n",                \
                (peer), libcfs_nid2str((peer)->ibp_nid),         \
                cfs_atomic_read (&(peer)->ibp_refcount));        \
-        LASSERT(cfs_atomic_read(&(peer)->ibp_refcount) > 0);    \
         cfs_atomic_inc(&(peer)->ibp_refcount);                  \
 } while (0)
 
         cfs_atomic_inc(&(peer)->ibp_refcount);                  \
 } while (0)
 
@@ -681,7 +679,7 @@ do {                                                            \
         CDEBUG(D_NET, "peer[%p] -> %s (%d)--\n",                \
                (peer), libcfs_nid2str((peer)->ibp_nid),         \
                cfs_atomic_read (&(peer)->ibp_refcount));        \
         CDEBUG(D_NET, "peer[%p] -> %s (%d)--\n",                \
                (peer), libcfs_nid2str((peer)->ibp_nid),         \
                cfs_atomic_read (&(peer)->ibp_refcount));        \
-        LASSERT(cfs_atomic_read(&(peer)->ibp_refcount) > 0);    \
+        LASSERT_ATOMIC_POS(&(peer)->ibp_refcount);              \
         if (cfs_atomic_dec_and_test(&(peer)->ibp_refcount))     \
                 kiblnd_destroy_peer(peer);                      \
 } while (0)
         if (cfs_atomic_dec_and_test(&(peer)->ibp_refcount))     \
                 kiblnd_destroy_peer(peer);                      \
 } while (0)
index 634a19b..54f3f04 100644 (file)
@@ -329,7 +329,6 @@ struct llog_commit_master {
 static inline struct llog_commit_master
 *lcm_get(struct llog_commit_master *lcm)
 {
 static inline struct llog_commit_master
 *lcm_get(struct llog_commit_master *lcm)
 {
-        LASSERT(cfs_atomic_read(&lcm->lcm_refcount) > 0);
         cfs_atomic_inc(&lcm->lcm_refcount);
         return lcm;
 }
         cfs_atomic_inc(&lcm->lcm_refcount);
         return lcm;
 }
@@ -337,10 +336,9 @@ static inline struct llog_commit_master
 static inline void
 lcm_put(struct llog_commit_master *lcm)
 {
 static inline void
 lcm_put(struct llog_commit_master *lcm)
 {
-        if (!cfs_atomic_dec_and_test(&lcm->lcm_refcount)) {
-                return ;
-        }
-        OBD_FREE_PTR(lcm);
+        LASSERT_ATOMIC_POS(&lcm->lcm_refcount);
+        if (cfs_atomic_dec_and_test(&lcm->lcm_refcount))
+                OBD_FREE_PTR(lcm);
 }
 
 struct llog_canceld_ctxt {
 }
 
 struct llog_canceld_ctxt {
@@ -437,7 +435,6 @@ static inline int llog_data_len(int len)
 
 static inline struct llog_ctxt *llog_ctxt_get(struct llog_ctxt *ctxt)
 {
 
 static inline struct llog_ctxt *llog_ctxt_get(struct llog_ctxt *ctxt)
 {
-        LASSERT(cfs_atomic_read(&ctxt->loc_refcount) > 0);
         cfs_atomic_inc(&ctxt->loc_refcount);
         CDEBUG(D_INFO, "GETting ctxt %p : new refcount %d\n", ctxt,
                cfs_atomic_read(&ctxt->loc_refcount));
         cfs_atomic_inc(&ctxt->loc_refcount);
         CDEBUG(D_INFO, "GETting ctxt %p : new refcount %d\n", ctxt,
                cfs_atomic_read(&ctxt->loc_refcount));
@@ -448,8 +445,7 @@ static inline void llog_ctxt_put(struct llog_ctxt *ctxt)
 {
         if (ctxt == NULL)
                 return;
 {
         if (ctxt == NULL)
                 return;
-        LASSERT(cfs_atomic_read(&ctxt->loc_refcount) > 0);
-        LASSERT(cfs_atomic_read(&ctxt->loc_refcount) < 0x5a5a5a);
+        LASSERT_ATOMIC_GT_LT(&ctxt->loc_refcount, 0, 0x5a5a5a);
         CDEBUG(D_INFO, "PUTting ctxt %p : new refcount %d\n", ctxt,
                cfs_atomic_read(&ctxt->loc_refcount) - 1);
         __llog_ctxt_put(ctxt);
         CDEBUG(D_INFO, "PUTting ctxt %p : new refcount %d\n", ctxt,
                cfs_atomic_read(&ctxt->loc_refcount) - 1);
         __llog_ctxt_put(ctxt);
index 5adae76..fb6f702 100644 (file)
@@ -203,7 +203,7 @@ extern void (*class_export_dump_hook)(struct obd_export *);
 
 #define class_export_rpc_put(exp)                                       \
 ({                                                                      \
 
 #define class_export_rpc_put(exp)                                       \
 ({                                                                      \
-        LASSERT(cfs_atomic_read(&exp->exp_rpc_count) > 0);              \
+        LASSERT_ATOMIC_POS(&exp->exp_rpc_count);                        \
         cfs_atomic_dec(&(exp)->exp_rpc_count);                          \
         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
                (exp), cfs_atomic_read(&(exp)->exp_rpc_count));          \
         cfs_atomic_dec(&(exp)->exp_rpc_count);                          \
         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
                (exp), cfs_atomic_read(&(exp)->exp_rpc_count));          \
@@ -221,7 +221,7 @@ extern void (*class_export_dump_hook)(struct obd_export *);
 
 #define class_export_lock_put(exp, lock)                                \
 ({                                                                      \
 
 #define class_export_lock_put(exp, lock)                                \
 ({                                                                      \
-        LASSERT(cfs_atomic_read(&exp->exp_locks_count) > 0);            \
+        LASSERT_ATOMIC_POS(&exp->exp_locks_count);                      \
         cfs_atomic_dec(&(exp)->exp_locks_count);                        \
         __class_export_del_lock_ref(exp, lock);                         \
         CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
         cfs_atomic_dec(&(exp)->exp_locks_count);                        \
         __class_export_del_lock_ref(exp, lock);                         \
         CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
@@ -239,7 +239,7 @@ extern void (*class_export_dump_hook)(struct obd_export *);
 
 #define class_export_cb_put(exp)                                        \
 ({                                                                      \
 
 #define class_export_cb_put(exp)                                        \
 ({                                                                      \
-        LASSERT(cfs_atomic_read(&exp->exp_cb_count) > 0);               \
+        LASSERT_ATOMIC_POS(&exp->exp_cb_count);                         \
         cfs_atomic_dec(&(exp)->exp_cb_count);                           \
         CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
                (exp), cfs_atomic_read(&(exp)->exp_cb_count));           \
         cfs_atomic_dec(&(exp)->exp_cb_count);                           \
         CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
                (exp), cfs_atomic_read(&(exp)->exp_cb_count));           \
index b49c28a..775a297 100644 (file)
@@ -1104,10 +1104,10 @@ void target_destroy_export(struct obd_export *exp)
         if (exp->exp_imp_reverse != NULL)
                 client_destroy_import(exp->exp_imp_reverse);
 
         if (exp->exp_imp_reverse != NULL)
                 client_destroy_import(exp->exp_imp_reverse);
 
-        LASSERT(cfs_atomic_read(&exp->exp_locks_count) == 0);
-        LASSERT(cfs_atomic_read(&exp->exp_rpc_count) == 0);
-        LASSERT(cfs_atomic_read(&exp->exp_cb_count) == 0);
-        LASSERT(cfs_atomic_read(&exp->exp_replay_count) == 0);
+        LASSERT_ATOMIC_ZERO(&exp->exp_locks_count);
+        LASSERT_ATOMIC_ZERO(&exp->exp_rpc_count);
+        LASSERT_ATOMIC_ZERO(&exp->exp_cb_count);
+        LASSERT_ATOMIC_ZERO(&exp->exp_replay_count);
 }
 
 /*
 }
 
 /*
@@ -1118,8 +1118,8 @@ static void target_request_copy_get(struct ptlrpc_request *req)
         class_export_rpc_get(req->rq_export);
         LASSERT(cfs_list_empty(&req->rq_list));
         CFS_INIT_LIST_HEAD(&req->rq_replay_list);
         class_export_rpc_get(req->rq_export);
         LASSERT(cfs_list_empty(&req->rq_list));
         CFS_INIT_LIST_HEAD(&req->rq_replay_list);
+
         /* increase refcount to keep request in queue */
         /* increase refcount to keep request in queue */
-        LASSERT(cfs_atomic_read(&req->rq_refcount));
         cfs_atomic_inc(&req->rq_refcount);
         /** let export know it has replays to be handled */
         cfs_atomic_inc(&req->rq_export->exp_replay_count);
         cfs_atomic_inc(&req->rq_refcount);
         /** let export know it has replays to be handled */
         cfs_atomic_inc(&req->rq_export->exp_replay_count);
@@ -1132,7 +1132,8 @@ static void target_request_copy_get(struct ptlrpc_request *req)
 static void target_request_copy_put(struct ptlrpc_request *req)
 {
         LASSERT(cfs_list_empty(&req->rq_replay_list));
 static void target_request_copy_put(struct ptlrpc_request *req)
 {
         LASSERT(cfs_list_empty(&req->rq_replay_list));
-        LASSERT(cfs_atomic_read(&req->rq_export->exp_replay_count) > 0);
+        LASSERT_ATOMIC_POS(&req->rq_export->exp_replay_count);
+
         cfs_atomic_dec(&req->rq_export->exp_replay_count);
         class_export_rpc_put(req->rq_export);
         /* ptlrpc_server_drop_request() assumes the request is active */
         cfs_atomic_dec(&req->rq_export->exp_replay_count);
         class_export_rpc_put(req->rq_export);
         /* ptlrpc_server_drop_request() assumes the request is active */
@@ -1924,7 +1925,8 @@ static int target_process_req_flags(struct obd_device *obd,
                 if (exp->exp_req_replay_needed) {
                         exp->exp_req_replay_needed = 0;
                         cfs_spin_unlock(&exp->exp_lock);
                 if (exp->exp_req_replay_needed) {
                         exp->exp_req_replay_needed = 0;
                         cfs_spin_unlock(&exp->exp_lock);
-                        LASSERT(cfs_atomic_read(&obd->obd_req_replay_clients));
+
+                        LASSERT_ATOMIC_POS(&obd->obd_req_replay_clients);
                         cfs_atomic_dec(&obd->obd_req_replay_clients);
                 } else {
                         cfs_spin_unlock(&exp->exp_lock);
                         cfs_atomic_dec(&obd->obd_req_replay_clients);
                 } else {
                         cfs_spin_unlock(&exp->exp_lock);
@@ -1937,7 +1939,8 @@ static int target_process_req_flags(struct obd_device *obd,
                 if (exp->exp_lock_replay_needed) {
                         exp->exp_lock_replay_needed = 0;
                         cfs_spin_unlock(&exp->exp_lock);
                 if (exp->exp_lock_replay_needed) {
                         exp->exp_lock_replay_needed = 0;
                         cfs_spin_unlock(&exp->exp_lock);
-                        LASSERT(cfs_atomic_read(&obd->obd_lock_replay_clients));
+
+                        LASSERT_ATOMIC_POS(&obd->obd_lock_replay_clients);
                         cfs_atomic_dec(&obd->obd_lock_replay_clients);
                 } else {
                         cfs_spin_unlock(&exp->exp_lock);
                         cfs_atomic_dec(&obd->obd_lock_replay_clients);
                 } else {
                         cfs_spin_unlock(&exp->exp_lock);
index 0d34e40..e8d90c2 100644 (file)
@@ -1128,11 +1128,12 @@ static void __ldlm_resource_putref_final(cfs_hash_bd_t *bd,
 int ldlm_resource_putref(struct ldlm_resource *res)
 {
         struct ldlm_namespace *ns = ldlm_res_to_ns(res);
 int ldlm_resource_putref(struct ldlm_resource *res)
 {
         struct ldlm_namespace *ns = ldlm_res_to_ns(res);
-        int ref = cfs_atomic_read(&res->lr_refcount);
         cfs_hash_bd_t   bd;
 
         cfs_hash_bd_t   bd;
 
-        CDEBUG(D_INFO, "putref res: %p count: %d\n", res, ref - 1);
-        LASSERTF(ref > 0 && ref < LI_POISON, "%d", ref);
+        LASSERT_ATOMIC_GT_LT(&res->lr_refcount, 0, LI_POISON);
+        CDEBUG(D_INFO, "putref res: %p count: %d\n",
+               res, cfs_atomic_read(&res->lr_refcount) - 1);
+
         cfs_hash_bd_get(ns->ns_rs_hash, &res->lr_name, &bd);
         if (cfs_hash_bd_dec_and_lock(ns->ns_rs_hash, &bd, &res->lr_refcount)) {
                 __ldlm_resource_putref_final(&bd, res);
         cfs_hash_bd_get(ns->ns_rs_hash, &res->lr_name, &bd);
         if (cfs_hash_bd_dec_and_lock(ns->ns_rs_hash, &bd, &res->lr_refcount)) {
                 __ldlm_resource_putref_final(&bd, res);
@@ -1149,10 +1150,11 @@ int ldlm_resource_putref(struct ldlm_resource *res)
 int ldlm_resource_putref_locked(struct ldlm_resource *res)
 {
         struct ldlm_namespace *ns = ldlm_res_to_ns(res);
 int ldlm_resource_putref_locked(struct ldlm_resource *res)
 {
         struct ldlm_namespace *ns = ldlm_res_to_ns(res);
-        int ref = cfs_atomic_read(&res->lr_refcount);
 
 
-        CDEBUG(D_INFO, "putref res: %p count: %d\n", res, ref - 1);
-        LASSERTF(ref > 0 && ref < LI_POISON, "%d", ref);
+        LASSERT_ATOMIC_GT_LT(&res->lr_refcount, 0, LI_POISON);
+        CDEBUG(D_INFO, "putref res: %p count: %d\n",
+               res, cfs_atomic_read(&res->lr_refcount) - 1);
+
         if (cfs_atomic_dec_and_test(&res->lr_refcount)) {
                 cfs_hash_bd_t bd;
 
         if (cfs_atomic_dec_and_test(&res->lr_refcount)) {
                 cfs_hash_bd_t bd;
 
index 7dd25ad..51cd9b9 100644 (file)
@@ -712,7 +712,7 @@ static void class_export_destroy(struct obd_export *exp)
         struct obd_device *obd = exp->exp_obd;
         ENTRY;
 
         struct obd_device *obd = exp->exp_obd;
         ENTRY;
 
-        LASSERT (cfs_atomic_read(&exp->exp_refcount) == 0);
+        LASSERT_ATOMIC_ZERO(&exp->exp_refcount);
 
         CDEBUG(D_IOCTL, "destroying export %p/%s for %s\n", exp,
                exp->exp_client_uuid.uuid, obd->obd_name);
 
         CDEBUG(D_IOCTL, "destroying export %p/%s for %s\n", exp,
                exp->exp_client_uuid.uuid, obd->obd_name);
@@ -751,10 +751,9 @@ EXPORT_SYMBOL(class_export_get);
 void class_export_put(struct obd_export *exp)
 {
         LASSERT(exp != NULL);
 void class_export_put(struct obd_export *exp)
 {
         LASSERT(exp != NULL);
+        LASSERT_ATOMIC_GT_LT(&exp->exp_refcount, 0, 0x5a5a5a);
         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", exp,
                cfs_atomic_read(&exp->exp_refcount) - 1);
         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", exp,
                cfs_atomic_read(&exp->exp_refcount) - 1);
-        LASSERT(cfs_atomic_read(&exp->exp_refcount) > 0);
-        LASSERT(cfs_atomic_read(&exp->exp_refcount) < 0x5a5a5a);
 
         if (cfs_atomic_dec_and_test(&exp->exp_refcount)) {
                 LASSERT(!cfs_list_empty(&exp->exp_obd_chain));
 
         if (cfs_atomic_dec_and_test(&exp->exp_refcount)) {
                 LASSERT(!cfs_list_empty(&exp->exp_obd_chain));
@@ -888,7 +887,7 @@ void class_import_destroy(struct obd_import *imp)
         CDEBUG(D_IOCTL, "destroying import %p for %s\n", imp,
                 imp->imp_obd->obd_name);
 
         CDEBUG(D_IOCTL, "destroying import %p for %s\n", imp,
                 imp->imp_obd->obd_name);
 
-        LASSERT(cfs_atomic_read(&imp->imp_refcount) == 0);
+        LASSERT_ATOMIC_ZERO(&imp->imp_refcount);
 
         ptlrpc_put_connection_superhack(imp->imp_connection);
 
 
         ptlrpc_put_connection_superhack(imp->imp_connection);
 
@@ -915,8 +914,6 @@ static void import_handle_addref(void *import)
 
 struct obd_import *class_import_get(struct obd_import *import)
 {
 
 struct obd_import *class_import_get(struct obd_import *import)
 {
-        LASSERT(cfs_atomic_read(&import->imp_refcount) >= 0);
-        LASSERT(cfs_atomic_read(&import->imp_refcount) < 0x5a5a5a);
         cfs_atomic_inc(&import->imp_refcount);
         CDEBUG(D_INFO, "import %p refcount=%d obd=%s\n", import,
                cfs_atomic_read(&import->imp_refcount),
         cfs_atomic_inc(&import->imp_refcount);
         CDEBUG(D_INFO, "import %p refcount=%d obd=%s\n", import,
                cfs_atomic_read(&import->imp_refcount),
@@ -929,9 +926,8 @@ void class_import_put(struct obd_import *imp)
 {
         ENTRY;
 
 {
         ENTRY;
 
-        LASSERT(cfs_atomic_read(&imp->imp_refcount) > 0);
-        LASSERT(cfs_atomic_read(&imp->imp_refcount) < 0x5a5a5a);
         LASSERT(cfs_list_empty(&imp->imp_zombie_chain));
         LASSERT(cfs_list_empty(&imp->imp_zombie_chain));
+        LASSERT_ATOMIC_GE_LT(&imp->imp_refcount, 0, 0x5a5a5a);
 
         CDEBUG(D_INFO, "import %p refcount=%d obd=%s\n", imp,
                cfs_atomic_read(&imp->imp_refcount) - 1,
 
         CDEBUG(D_INFO, "import %p refcount=%d obd=%s\n", imp,
                cfs_atomic_read(&imp->imp_refcount) - 1,
index 1494e0d..1a0cd25 100644 (file)
@@ -287,7 +287,6 @@ struct ptlrpc_cli_ctx *get_my_ctx(struct ptlrpc_sec *sec)
 
 struct ptlrpc_cli_ctx *sptlrpc_cli_ctx_get(struct ptlrpc_cli_ctx *ctx)
 {
 
 struct ptlrpc_cli_ctx *sptlrpc_cli_ctx_get(struct ptlrpc_cli_ctx *ctx)
 {
-        LASSERT(cfs_atomic_read(&ctx->cc_refcount) > 0);
         cfs_atomic_inc(&ctx->cc_refcount);
         return ctx;
 }
         cfs_atomic_inc(&ctx->cc_refcount);
         return ctx;
 }
@@ -298,7 +297,7 @@ void sptlrpc_cli_ctx_put(struct ptlrpc_cli_ctx *ctx, int sync)
         struct ptlrpc_sec *sec = ctx->cc_sec;
 
         LASSERT(sec);
         struct ptlrpc_sec *sec = ctx->cc_sec;
 
         LASSERT(sec);
-        LASSERT(cfs_atomic_read(&ctx->cc_refcount));
+        LASSERT_ATOMIC_POS(&ctx->cc_refcount);
 
         if (!cfs_atomic_dec_and_test(&ctx->cc_refcount))
                 return;
 
         if (!cfs_atomic_dec_and_test(&ctx->cc_refcount))
                 return;
@@ -1230,8 +1229,8 @@ static void sec_cop_destroy_sec(struct ptlrpc_sec *sec)
 {
         struct ptlrpc_sec_policy *policy = sec->ps_policy;
 
 {
         struct ptlrpc_sec_policy *policy = sec->ps_policy;
 
-        LASSERT(cfs_atomic_read(&sec->ps_refcount) == 0);
-        LASSERT(cfs_atomic_read(&sec->ps_nctx) == 0);
+        LASSERT_ATOMIC_ZERO(&sec->ps_refcount);
+        LASSERT_ATOMIC_ZERO(&sec->ps_nctx);
         LASSERT(policy->sp_cops->destroy_sec);
 
         CDEBUG(D_SEC, "%s@%p: being destroied\n", sec->ps_policy->sp_name, sec);
         LASSERT(policy->sp_cops->destroy_sec);
 
         CDEBUG(D_SEC, "%s@%p: being destroied\n", sec->ps_policy->sp_name, sec);
@@ -1248,7 +1247,7 @@ EXPORT_SYMBOL(sptlrpc_sec_destroy);
 
 static void sptlrpc_sec_kill(struct ptlrpc_sec *sec)
 {
 
 static void sptlrpc_sec_kill(struct ptlrpc_sec *sec)
 {
-        LASSERT(cfs_atomic_read(&sec->ps_refcount) > 0);
+        LASSERT_ATOMIC_POS(&sec->ps_refcount);
 
         if (sec->ps_policy->sp_cops->kill_sec) {
                 sec->ps_policy->sp_cops->kill_sec(sec);
 
         if (sec->ps_policy->sp_cops->kill_sec) {
                 sec->ps_policy->sp_cops->kill_sec(sec);
@@ -1259,10 +1258,8 @@ static void sptlrpc_sec_kill(struct ptlrpc_sec *sec)
 
 struct ptlrpc_sec *sptlrpc_sec_get(struct ptlrpc_sec *sec)
 {
 
 struct ptlrpc_sec *sptlrpc_sec_get(struct ptlrpc_sec *sec)
 {
-        if (sec) {
-                LASSERT(cfs_atomic_read(&sec->ps_refcount) > 0);
+        if (sec)
                 cfs_atomic_inc(&sec->ps_refcount);
                 cfs_atomic_inc(&sec->ps_refcount);
-        }
 
         return sec;
 }
 
         return sec;
 }
@@ -1271,11 +1268,9 @@ EXPORT_SYMBOL(sptlrpc_sec_get);
 void sptlrpc_sec_put(struct ptlrpc_sec *sec)
 {
         if (sec) {
 void sptlrpc_sec_put(struct ptlrpc_sec *sec)
 {
         if (sec) {
-                LASSERT(cfs_atomic_read(&sec->ps_refcount) > 0);
+                LASSERT_ATOMIC_POS(&sec->ps_refcount);
 
                 if (cfs_atomic_dec_and_test(&sec->ps_refcount)) {
 
                 if (cfs_atomic_dec_and_test(&sec->ps_refcount)) {
-                        LASSERT(cfs_atomic_read(&sec->ps_nctx) == 0);
-
                         sptlrpc_gc_del_sec(sec);
                         sec_cop_destroy_sec(sec);
                 }
                         sptlrpc_gc_del_sec(sec);
                         sec_cop_destroy_sec(sec);
                 }
@@ -1354,7 +1349,7 @@ static void sptlrpc_import_sec_install(struct obd_import *imp,
 {
         struct ptlrpc_sec *old_sec;
 
 {
         struct ptlrpc_sec *old_sec;
 
-        LASSERT(cfs_atomic_read(&sec->ps_refcount) > 0);
+        LASSERT_ATOMIC_POS(&sec->ps_refcount);
 
         cfs_spin_lock(&imp->imp_lock);
         old_sec = imp->imp_sec;
 
         cfs_spin_lock(&imp->imp_lock);
         old_sec = imp->imp_sec;
@@ -1553,10 +1548,10 @@ int sptlrpc_cli_alloc_reqbuf(struct ptlrpc_request *req, int msgsize)
         int rc;
 
         LASSERT(ctx);
         int rc;
 
         LASSERT(ctx);
-        LASSERT(cfs_atomic_read(&ctx->cc_refcount));
         LASSERT(ctx->cc_sec);
         LASSERT(ctx->cc_sec->ps_policy);
         LASSERT(req->rq_reqmsg == NULL);
         LASSERT(ctx->cc_sec);
         LASSERT(ctx->cc_sec->ps_policy);
         LASSERT(req->rq_reqmsg == NULL);
+        LASSERT_ATOMIC_POS(&ctx->cc_refcount);
 
         policy = ctx->cc_sec->ps_policy;
         rc = policy->sp_cops->alloc_reqbuf(ctx->cc_sec, req, msgsize);
 
         policy = ctx->cc_sec->ps_policy;
         rc = policy->sp_cops->alloc_reqbuf(ctx->cc_sec, req, msgsize);
@@ -1582,9 +1577,9 @@ void sptlrpc_cli_free_reqbuf(struct ptlrpc_request *req)
         struct ptlrpc_sec_policy *policy;
 
         LASSERT(ctx);
         struct ptlrpc_sec_policy *policy;
 
         LASSERT(ctx);
-        LASSERT(cfs_atomic_read(&ctx->cc_refcount));
         LASSERT(ctx->cc_sec);
         LASSERT(ctx->cc_sec->ps_policy);
         LASSERT(ctx->cc_sec);
         LASSERT(ctx->cc_sec->ps_policy);
+        LASSERT_ATOMIC_POS(&ctx->cc_refcount);
 
         if (req->rq_reqbuf == NULL && req->rq_clrbuf == NULL)
                 return;
 
         if (req->rq_reqbuf == NULL && req->rq_clrbuf == NULL)
                 return;
@@ -1680,7 +1675,6 @@ int sptlrpc_cli_alloc_repbuf(struct ptlrpc_request *req, int msgsize)
         ENTRY;
 
         LASSERT(ctx);
         ENTRY;
 
         LASSERT(ctx);
-        LASSERT(cfs_atomic_read(&ctx->cc_refcount));
         LASSERT(ctx->cc_sec);
         LASSERT(ctx->cc_sec->ps_policy);
 
         LASSERT(ctx->cc_sec);
         LASSERT(ctx->cc_sec->ps_policy);
 
@@ -1702,9 +1696,9 @@ void sptlrpc_cli_free_repbuf(struct ptlrpc_request *req)
         ENTRY;
 
         LASSERT(ctx);
         ENTRY;
 
         LASSERT(ctx);
-        LASSERT(cfs_atomic_read(&ctx->cc_refcount));
         LASSERT(ctx->cc_sec);
         LASSERT(ctx->cc_sec->ps_policy);
         LASSERT(ctx->cc_sec);
         LASSERT(ctx->cc_sec->ps_policy);
+        LASSERT_ATOMIC_POS(&ctx->cc_refcount);
 
         if (req->rq_repbuf == NULL)
                 return;
 
         if (req->rq_repbuf == NULL)
                 return;
@@ -2182,11 +2176,8 @@ void sptlrpc_svc_ctx_addref(struct ptlrpc_request *req)
 {
         struct ptlrpc_svc_ctx *ctx = req->rq_svc_ctx;
 
 {
         struct ptlrpc_svc_ctx *ctx = req->rq_svc_ctx;
 
-        if (ctx == NULL)
-                return;
-
-        LASSERT(cfs_atomic_read(&ctx->sc_refcount) > 0);
-        cfs_atomic_inc(&ctx->sc_refcount);
+        if (ctx != NULL)
+                cfs_atomic_inc(&ctx->sc_refcount);
 }
 
 void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req)
 }
 
 void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req)
@@ -2196,7 +2187,7 @@ void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req)
         if (ctx == NULL)
                 return;
 
         if (ctx == NULL)
                 return;
 
-        LASSERT(cfs_atomic_read(&ctx->sc_refcount) > 0);
+        LASSERT_ATOMIC_POS(&ctx->sc_refcount);
         if (cfs_atomic_dec_and_test(&ctx->sc_refcount)) {
                 if (ctx->sc_policy->sp_sops->free_ctx)
                         ctx->sc_policy->sp_sops->free_ctx(ctx);
         if (cfs_atomic_dec_and_test(&ctx->sc_refcount)) {
                 if (ctx->sc_policy->sp_sops->free_ctx)
                         ctx->sc_policy->sp_sops->free_ctx(ctx);
@@ -2211,7 +2202,7 @@ void sptlrpc_svc_ctx_invalidate(struct ptlrpc_request *req)
         if (ctx == NULL)
                 return;
 
         if (ctx == NULL)
                 return;
 
-        LASSERT(cfs_atomic_read(&ctx->sc_refcount) > 0);
+        LASSERT_ATOMIC_POS(&ctx->sc_refcount);
         if (ctx->sc_policy->sp_sops->invalidate_ctx)
                 ctx->sc_policy->sp_sops->invalidate_ctx(ctx);
 }
         if (ctx->sc_policy->sp_sops->invalidate_ctx)
                 ctx->sc_policy->sp_sops->invalidate_ctx(ctx);
 }
index dd4332b..4fc2242 100644 (file)
@@ -340,7 +340,7 @@ int null_alloc_rs(struct ptlrpc_request *req, int msgsize)
 static
 void null_free_rs(struct ptlrpc_reply_state *rs)
 {
 static
 void null_free_rs(struct ptlrpc_reply_state *rs)
 {
-        LASSERT(cfs_atomic_read(&rs->rs_svc_ctx->sc_refcount) > 1);
+        LASSERT_ATOMIC_GT(&rs->rs_svc_ctx->sc_refcount, 1);
         cfs_atomic_dec(&rs->rs_svc_ctx->sc_refcount);
 
         if (!rs->rs_prealloc)
         cfs_atomic_dec(&rs->rs_svc_ctx->sc_refcount);
 
         if (!rs->rs_prealloc)