Whamcloud - gitweb
LU-4199 libcfs: remove assertion of spin_is_locked() 44/8144/20
authorLi Xi <lixi@ddn.com>
Thu, 10 Apr 2014 13:30:54 +0000 (09:30 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 18 Apr 2014 23:50:17 +0000 (23:50 +0000)
spin_is_locked() is always false when the platform is
uniprocessor and CONFIG_DEBUG_SPINLOCK is not enabled.
This patch replaces its assertion by assert_spin_locked().

Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: James Simmons <uja.ornl@gmail.com>
Change-Id: Id8a7207b6fb08f10ccd4447263fec805df31ed67
Reviewed-on: http://review.whamcloud.com/8144
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Alexey Lyashkov <alexey_lyashkov@xyratex.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
22 files changed:
libcfs/include/libcfs/linux/linux-lock.h
libcfs/include/libcfs/user-lock.h
libcfs/include/libcfs/winnt/winnt-lock.h
lustre/include/lustre_dlm.h
lustre/include/lustre_net.h
lustre/lov/lov_merge.c
lustre/obdclass/cl_lock.c
lustre/obdclass/cl_object.c
lustre/ofd/ofd_fmd.c
lustre/ofd/ofd_grant.c
lustre/osc/osc_cache.c
lustre/osc/osc_cl_internal.h
lustre/ptlrpc/client.c
lustre/ptlrpc/gss/gss_pipefs.c
lustre/ptlrpc/import.c
lustre/ptlrpc/lproc_ptlrpc.c
lustre/ptlrpc/nrs_crr.c
lustre/ptlrpc/nrs_orr.c
lustre/ptlrpc/nrs_tbf.c
lustre/ptlrpc/pinger.c
lustre/ptlrpc/sec_bulk.c
lustre/ptlrpc/service.c

index 7d9b9e7..6f0b84d 100644 (file)
@@ -69,7 +69,7 @@
  * - spin_unlock(x)
  * - spin_unlock_bh(x)
  * - spin_trylock(x)
- * - spin_is_locked(x)
+ * - assert_spin_locked(x)
  *
  * - spin_lock_irq(x)
  * - spin_lock_irqsave(x, f)
index d0ff4ff..20f2006 100644 (file)
@@ -78,7 +78,7 @@
  * - spin_lock_bh(x)
  * - spin_unlock_bh(x)
  *
- * - spin_is_locked(x)
+ * - assert_spin_locked(x)
  * - spin_lock_irqsave(x, f)
  * - spin_unlock_irqrestore(x, f)
  *
@@ -99,10 +99,11 @@ void spin_lock_bh_init(spinlock_t *lock);
 void spin_lock_bh(spinlock_t *lock);
 void spin_unlock_bh(spinlock_t *lock);
 
-static inline int spin_is_locked(spinlock_t *l) { return 1; }
 static inline void spin_lock_irqsave(spinlock_t *l, unsigned long f) {}
 static inline void spin_unlock_irqrestore(spinlock_t *l, unsigned long f) {}
 
+#define assert_spin_locked(lock)       do { (void)(lock); } while (0)
+
 /*
  * Semaphore
  *
index 2251c5d..23f93c3 100644 (file)
@@ -298,7 +298,7 @@ static int spin_trylock(spinlock_t *lock)
        return rc;
 }
 
-static int spin_is_locked(spinlock_t *lock)
+static int assert_spin_locked(spinlock_t *lock)
 {
 #if _WIN32_WINNT >= 0x502
        /* KeTestSpinLock only avalilable on 2k3 server or later */
index bd3e589..0c669cc 100644 (file)
@@ -1502,7 +1502,7 @@ static inline void unlock_res(struct ldlm_resource *res)
 /** Check if resource is already locked, assert if not. */
 static inline void check_res_locked(struct ldlm_resource *res)
 {
-       LASSERT(spin_is_locked(&res->lr_lock));
+       assert_spin_locked(&res->lr_lock);
 }
 
 struct ldlm_resource * lock_res_and_lock(struct ldlm_lock *lock);
index 83c40cb..8a55b6e 100644 (file)
@@ -963,7 +963,7 @@ struct ptlrpc_nrs_pol_ops {
         *                       \a nrq
         * \param[in,out] nrq    The request
         *
-        * \pre spin_is_locked(&svcpt->scp_req_lock)
+        * \pre assert_spin_locked(&svcpt->scp_req_lock)
         *
         * \see ptlrpc_nrs_req_stop_nolock()
         */
index 77da860..fd74179 100644 (file)
@@ -62,7 +62,7 @@ int lov_merge_lvb_kms(struct lov_stripe_md *lsm,
        int i;
        int rc = 0;
 
-       LASSERT(spin_is_locked(&lsm->lsm_lock));
+       assert_spin_locked(&lsm->lsm_lock);
 #ifdef __KERNEL__
        LASSERT(lsm->lsm_lock_owner == current_pid());
 #endif
index 44d4445..bdd82c9 100644 (file)
@@ -500,7 +500,7 @@ static struct cl_lock *cl_lock_lookup(const struct lu_env *env,
         ENTRY;
 
        head = cl_object_header(obj);
-       LINVRNT(spin_is_locked(&head->coh_lock_guard));
+       assert_spin_locked(&head->coh_lock_guard);
        CS_LOCK_INC(obj, lookup);
        cfs_list_for_each_entry(lock, &head->coh_locks, cll_linkage) {
                int matched;
index ccc7345..ac46d07 100644 (file)
@@ -214,7 +214,7 @@ int cl_object_attr_get(const struct lu_env *env, struct cl_object *obj,
        struct lu_object_header *top;
        int result;
 
-       LASSERT(spin_is_locked(cl_object_attr_guard(obj)));
+       assert_spin_locked(cl_object_attr_guard(obj));
        ENTRY;
 
         top = obj->co_lu.lo_header;
@@ -246,7 +246,7 @@ int cl_object_attr_set(const struct lu_env *env, struct cl_object *obj,
        struct lu_object_header *top;
        int result;
 
-       LASSERT(spin_is_locked(cl_object_attr_guard(obj)));
+       assert_spin_locked(cl_object_attr_guard(obj));
        ENTRY;
 
         top = obj->co_lu.lo_header;
index b546732..63433e8 100644 (file)
@@ -48,7 +48,7 @@ static inline void ofd_fmd_put_nolock(struct obd_export *exp,
 {
        struct filter_export_data *fed = &exp->exp_filter_data;
 
-       LASSERT(spin_is_locked(&fed->fed_lock));
+       assert_spin_locked(&fed->fed_lock);
        if (--fmd->fmd_refcount == 0) {
                /* XXX when we have persistent reservations and the handle
                 * is stored herein we need to drop it here. */
@@ -115,7 +115,7 @@ static struct ofd_mod_data *ofd_fmd_find_nolock(struct obd_export *exp,
 
        cfs_time_t now = cfs_time_current();
 
-       LASSERT(spin_is_locked(&fed->fed_lock));
+       assert_spin_locked(&fed->fed_lock);
 
        cfs_list_for_each_entry_reverse(fmd, &fed->fed_mod_list, fmd_list) {
                if (lu_fid_eq(&fmd->fmd_fid, fid)) {
index 7fa1e4a..d662ec2 100644 (file)
@@ -234,7 +234,7 @@ static obd_size ofd_grant_space_left(struct obd_export *exp)
        obd_size                 unstable;
 
        ENTRY;
-       LASSERT(spin_is_locked(&ofd->ofd_grant_lock));
+       assert_spin_locked(&ofd->ofd_grant_lock);
 
        spin_lock(&ofd->ofd_osfs_lock);
        /* get available space from cached statfs data */
@@ -299,7 +299,7 @@ static void ofd_grant_incoming(const struct lu_env *env, struct obd_export *exp,
        long                             dirty, dropped, grant_chunk;
        ENTRY;
 
-       LASSERT(spin_is_locked(&ofd->ofd_grant_lock));
+       assert_spin_locked(&ofd->ofd_grant_lock);
 
        if ((oa->o_valid & (OBD_MD_FLBLOCKS|OBD_MD_FLGRANT)) !=
                                        (OBD_MD_FLBLOCKS|OBD_MD_FLGRANT)) {
@@ -377,7 +377,7 @@ static void ofd_grant_shrink(struct obd_export *exp,
        struct obd_device               *obd = exp->exp_obd;
        long                             grant_shrink;
 
-       LASSERT(spin_is_locked(&ofd->ofd_grant_lock));
+       assert_spin_locked(&ofd->ofd_grant_lock);
        LASSERT(exp);
        if (left_space >= ofd->ofd_tot_granted_clients *
                          OFD_GRANT_SHRINK_LIMIT(exp))
@@ -458,7 +458,7 @@ static void ofd_grant_check(const struct lu_env *env, struct obd_export *exp,
 
        ENTRY;
 
-       LASSERT(spin_is_locked(&ofd->ofd_grant_lock));
+       assert_spin_locked(&ofd->ofd_grant_lock);
 
        if ((oa->o_valid & OBD_MD_FLFLAGS) &&
            (oa->o_flags & OBD_FL_RECOV_RESEND)) {
index 5885c59..75f58fe 100644 (file)
@@ -1337,7 +1337,7 @@ static int osc_completion(const struct lu_env *env, struct osc_async_page *oap,
 static void osc_consume_write_grant(struct client_obd *cli,
                                    struct brw_page *pga)
 {
-       LASSERT(spin_is_locked(&cli->cl_loi_list_lock.lock));
+       assert_spin_locked(&cli->cl_loi_list_lock.lock);
        LASSERT(!(pga->flag & OBD_BRW_FROM_GRANT));
        atomic_inc(&obd_dirty_pages);
        cli->cl_dirty += PAGE_CACHE_SIZE;
@@ -1354,7 +1354,7 @@ static void osc_release_write_grant(struct client_obd *cli,
 {
        ENTRY;
 
-       LASSERT(spin_is_locked(&cli->cl_loi_list_lock.lock));
+       assert_spin_locked(&cli->cl_loi_list_lock.lock);
        if (!(pga->flag & OBD_BRW_FROM_GRANT)) {
                EXIT;
                return;
index d1a3dbf..4a62b3c 100644 (file)
@@ -201,7 +201,16 @@ static inline void osc_object_unlock(struct osc_object *obj)
 
 static inline int osc_object_is_locked(struct osc_object *obj)
 {
+#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
        return spin_is_locked(&obj->oo_lock);
+#else
+       /*
+        * It is not perfect to return true all the time.
+        * But since this function is only used for assertion
+        * and checking, it seems OK.
+        */
+       return 1;
+#endif
 }
 
 /*
index 9f6d54a..7936a0d 100644 (file)
@@ -2297,7 +2297,7 @@ static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked);
  */
 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request)
 {
-       LASSERT(spin_is_locked(&request->rq_import->imp_lock));
+       assert_spin_locked(&request->rq_import->imp_lock);
        (void)__ptlrpc_req_finished(request, 1);
 }
 EXPORT_SYMBOL(ptlrpc_req_finished_with_imp_lock);
@@ -2480,8 +2480,7 @@ void ptlrpc_free_committed(struct obd_import *imp)
        ENTRY;
 
        LASSERT(imp != NULL);
-       LASSERT(spin_is_locked(&imp->imp_lock));
-
+       assert_spin_locked(&imp->imp_lock);
 
         if (imp->imp_peer_committed_transno == imp->imp_last_transno_checked &&
             imp->imp_generation == imp->imp_last_generation_checked) {
@@ -2618,7 +2617,7 @@ void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
 {
        cfs_list_t *tmp;
 
-       LASSERT(spin_is_locked(&imp->imp_lock));
+       assert_spin_locked(&imp->imp_lock);
 
         if (req->rq_transno == 0) {
                 DEBUG_REQ(D_EMERG, req, "saving request with zero transno");
index aa61d6e..dc4bb54 100644 (file)
@@ -141,7 +141,7 @@ void ctx_enhash_pf(struct ptlrpc_cli_ctx *ctx, cfs_hlist_head_t *hash)
 static
 void ctx_unhash_pf(struct ptlrpc_cli_ctx *ctx, cfs_hlist_head_t *freelist)
 {
-       LASSERT(spin_is_locked(&ctx->cc_sec->ps_lock));
+       assert_spin_locked(&ctx->cc_sec->ps_lock);
        LASSERT(atomic_read(&ctx->cc_refcount) > 0);
        LASSERT(test_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags));
        LASSERT(!cfs_hlist_unhashed(&ctx->cc_cache));
@@ -734,7 +734,7 @@ void gss_unhash_msg_nolock(struct gss_upcall_msg *gmsg)
        __u32 idx = gmsg->gum_mechidx;
 
        LASSERT(idx < MECH_MAX);
-       LASSERT(spin_is_locked(&upcall_locks[idx]));
+       assert_spin_locked(&upcall_locks[idx]);
 
        if (cfs_list_empty(&gmsg->gum_list))
                return;
index 21306f2..40753de 100644 (file)
@@ -198,7 +198,7 @@ int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt)
 static void ptlrpc_deactivate_and_unlock_import(struct obd_import *imp)
 {
        ENTRY;
-       LASSERT(spin_is_locked(&imp->imp_lock));
+       assert_spin_locked(&imp->imp_lock);
 
        CDEBUG(D_HA, "setting import %s INVALID\n", obd2cli_tgt(imp->imp_obd));
        imp->imp_invalid = 1;
index 2a5b643..84b0460 100644 (file)
@@ -459,7 +459,7 @@ void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy,
 {
        LASSERT(policy != NULL);
        LASSERT(info != NULL);
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_lock);
 
        memcpy(info->pi_name, policy->pol_desc->pd_name, NRS_POL_NAME_MAX);
 
index 2214176..53a3fbc 100644 (file)
@@ -267,8 +267,8 @@ static void nrs_crrn_stop(struct ptlrpc_nrs_policy *policy)
  * \param[in]    opc    the opcode
  * \param[in,out] arg   used for passing parameters and information
  *
- * \pre spin_is_locked(&policy->pol_nrs->->nrs_lock)
- * \post spin_is_locked(&policy->pol_nrs->->nrs_lock)
+ * \pre assert_spin_locked(&policy->pol_nrs->->nrs_lock)
+ * \post assert_spin_locked(&policy->pol_nrs->->nrs_lock)
  *
  * \retval 0   operation carried out successfully
  * \retval -ve error
@@ -276,7 +276,7 @@ static void nrs_crrn_stop(struct ptlrpc_nrs_policy *policy)
 int nrs_crrn_ctl(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc,
                 void *arg)
 {
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_lock);
 
        switch((enum nrs_ctl_crr)opc) {
        default:
index 9f36825..6d54e6d 100644 (file)
@@ -735,8 +735,8 @@ static void nrs_orr_stop(struct ptlrpc_nrs_policy *policy)
  * \param[in]    opc    the opcode
  * \param[in,out] arg   used for passing parameters and information
  *
- * \pre spin_is_locked(&policy->pol_nrs->->nrs_lock)
- * \post spin_is_locked(&policy->pol_nrs->->nrs_lock)
+ * \pre assert_spin_locked(&policy->pol_nrs->->nrs_lock)
+ * \post assert_spin_locked(&policy->pol_nrs->->nrs_lock)
  *
  * \retval 0   operation carried successfully
  * \retval -ve error
@@ -744,7 +744,7 @@ static void nrs_orr_stop(struct ptlrpc_nrs_policy *policy)
 int nrs_orr_ctl(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc,
                void *arg)
 {
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_lock);
 
        switch((enum nrs_ctl_orr)opc) {
        default:
index 96eac30..80fa9ff 100644 (file)
@@ -327,7 +327,7 @@ nrs_tbf_rule_change(struct ptlrpc_nrs_policy *policy,
 {
        struct nrs_tbf_rule *rule;
 
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_lock);
 
        rule = nrs_tbf_rule_find(head, change->tc_name);
        if (rule == NULL)
@@ -348,7 +348,7 @@ nrs_tbf_rule_stop(struct ptlrpc_nrs_policy *policy,
 {
        struct nrs_tbf_rule *rule;
 
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_lock);
 
        if (strcmp(stop->tc_name, NRS_TBF_DEFAULT_RULE) == 0)
                return -EPERM;
@@ -372,7 +372,7 @@ nrs_tbf_command(struct ptlrpc_nrs_policy *policy,
 {
        int rc;
 
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_lock);
 
        switch (cmd->tc_cmd) {
        case NRS_CTL_TBF_START_RULE:
@@ -1197,8 +1197,8 @@ static void nrs_tbf_stop(struct ptlrpc_nrs_policy *policy)
  * \param[in]    opc    the opcode
  * \param[in,out] arg   used for passing parameters and information
  *
- * \pre spin_is_locked(&policy->pol_nrs->->nrs_lock)
- * \post spin_is_locked(&policy->pol_nrs->->nrs_lock)
+ * \pre assert_spin_locked(&policy->pol_nrs->->nrs_lock)
+ * \post assert_spin_locked(&policy->pol_nrs->->nrs_lock)
  *
  * \retval 0   operation carried out successfully
  * \retval -ve error
@@ -1209,7 +1209,7 @@ int nrs_tbf_ctl(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc,
        int rc = 0;
        ENTRY;
 
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_lock);
 
        switch ((enum nrs_ctl_tbf)opc) {
        default:
@@ -1382,7 +1382,7 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
        struct nrs_tbf_client     *cli;
        cfs_binheap_node_t        *node;
 
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
 
        if (!peek && policy->pol_nrs->nrs_throttling)
                return NULL;
@@ -1469,7 +1469,7 @@ static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy,
        struct nrs_tbf_client *cli;
        int                    rc = 0;
 
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
 
        cli = container_of(nrs_request_resource(nrq),
                           struct nrs_tbf_client, tc_res);
@@ -1519,7 +1519,7 @@ static void nrs_tbf_req_del(struct ptlrpc_nrs_policy *policy,
        struct nrs_tbf_head   *head;
        struct nrs_tbf_client *cli;
 
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
 
        cli = container_of(nrs_request_resource(nrq),
                           struct nrs_tbf_client, tc_res);
@@ -1554,7 +1554,7 @@ static void nrs_tbf_req_stop(struct ptlrpc_nrs_policy *policy,
        struct ptlrpc_request *req = container_of(nrq, struct ptlrpc_request,
                                                  rq_nrq);
 
-       LASSERT(spin_is_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock));
+       assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
 
        CDEBUG(D_RPCTRACE, "NRS stop %s request from %s, seq: "LPU64"\n",
               policy->pol_desc->pd_name, libcfs_id2str(req->rq_peer),
index 1c32555..7606e69 100644 (file)
@@ -386,7 +386,7 @@ EXPORT_SYMBOL(ptlrpc_pinger_sending_on_import);
 void ptlrpc_pinger_commit_expected(struct obd_import *imp)
 {
        ptlrpc_update_next_ping(imp, 1);
-       LASSERT(spin_is_locked(&imp->imp_lock));
+       assert_spin_locked(&imp->imp_lock);
        /*
         * Avoid reading stale imp_connect_data.  When not sure if pings are
         * expected or not on next connection, we assume they are not and force
index 0601486..bb1e782 100644 (file)
@@ -448,7 +448,7 @@ out:
 
 static inline void enc_pools_wakeup(void)
 {
-       LASSERT(spin_is_locked(&page_pools.epp_lock));
+       assert_spin_locked(&page_pools.epp_lock);
 
        if (unlikely(page_pools.epp_waitqlen)) {
                LASSERT(waitqueue_active(&page_pools.epp_waitq));
index e54f59c..b312f8b 100644 (file)
@@ -404,8 +404,8 @@ ptlrpc_schedule_difficult_reply(struct ptlrpc_reply_state *rs)
 {
        ENTRY;
 
-       LASSERT(spin_is_locked(&rs->rs_svcpt->scp_rep_lock));
-       LASSERT(spin_is_locked(&rs->rs_lock));
+       assert_spin_locked(&rs->rs_svcpt->scp_rep_lock);
+       assert_spin_locked(&rs->rs_lock);
        LASSERT (rs->rs_difficult);
        rs->rs_scheduled_ever = 1;  /* flag any notification attempt */