From: frank zago Date: Sun, 13 Jul 2014 17:06:02 +0000 (-0500) Subject: LU-5396: add sparse locking annotations X-Git-Tag: 2.6.52~16 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=8553494bca7381262843f900d14c58f5c242f3ea LU-5396: add sparse locking annotations Adds __acquires / __releases / __must_hold sparse locking annotations to several functions. Fixes sparse warnings such as: libcfs/libcfs/hash.c:127:1: warning: context imbalance in 'cfs_hash_spin_lock' - wrong count at exit libcfs/libcfs/hash.c:133:1: warning: context imbalance in 'cfs_hash_spin_unlock' - unexpected unlock libcfs/libcfs/hash.c:141:9: warning: context imbalance in 'cfs_hash_rw_lock' - wrong count at exit include/linux/rwlock_api_smp.h:221:9: warning: context imbalance in 'cfs_hash_rw_unlock' - unexpected unlock Change-Id: I91834ea62a2bc21ee853a80b0b266e3d0e960bc3 Signed-off-by: frank zago Reviewed-on: http://review.whamcloud.com/11295 Reviewed-by: John L. Hammond Tested-by: Jenkins Reviewed-by: Patrick Farrell Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/libcfs/libcfs/hash.c b/libcfs/libcfs/hash.c index dda925c..b637760 100644 --- a/libcfs/libcfs/hash.c +++ b/libcfs/libcfs/hash.c @@ -125,18 +125,21 @@ cfs_hash_nl_unlock(cfs_hash_lock_t *lock, int exclusive) {} static inline void cfs_hash_spin_lock(cfs_hash_lock_t *lock, int exclusive) +__acquires(&lock->spin) { spin_lock(&lock->spin); } static inline void cfs_hash_spin_unlock(cfs_hash_lock_t *lock, int exclusive) +__releases(&lock->spin) { spin_unlock(&lock->spin); } static inline void cfs_hash_rw_lock(cfs_hash_lock_t *lock, int exclusive) +__acquires(&lock->rw) { if (!exclusive) read_lock(&lock->rw); @@ -146,6 +149,7 @@ cfs_hash_rw_lock(cfs_hash_lock_t *lock, int exclusive) static inline void cfs_hash_rw_unlock(cfs_hash_lock_t *lock, int exclusive) +__releases(&lock->rw) { if (!exclusive) read_unlock(&lock->rw); diff --git a/libcfs/libcfs/libcfs_lock.c b/libcfs/libcfs/libcfs_lock.c index fa8c652..f979f6f 100644 --- a/libcfs/libcfs/libcfs_lock.c +++ b/libcfs/libcfs/libcfs_lock.c @@ -92,6 +92,7 @@ EXPORT_SYMBOL(cfs_percpt_lock_alloc); */ void cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index) +__acquires(pcl->pcl_locks) { int ncpt = cfs_cpt_number(pcl->pcl_cptab); int i; @@ -126,6 +127,7 @@ EXPORT_SYMBOL(cfs_percpt_lock); /** unlock a CPU partition */ void cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index) +__releases(pcl->pcl_locks) { int ncpt = cfs_cpt_number(pcl->pcl_cptab); int i; diff --git a/libcfs/libcfs/linux/linux-tracefile.c b/libcfs/libcfs/linux/linux-tracefile.c index c67103b..294a34e 100644 --- a/libcfs/libcfs/linux/linux-tracefile.c +++ b/libcfs/libcfs/linux/linux-tracefile.c @@ -153,6 +153,7 @@ cfs_trace_buf_type_t cfs_trace_buf_idx_get() * for details. */ int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking) +__acquires(&tcd->tcd_lock) { __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX); if (tcd->tcd_type == CFS_TCD_TYPE_IRQ) @@ -167,6 +168,7 @@ int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking) } void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking) +__releases(&tcd->tcd_lock) { __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX); if (tcd->tcd_type == CFS_TCD_TYPE_IRQ) diff --git a/lnet/klnds/o2iblnd/o2iblnd_cb.c b/lnet/klnds/o2iblnd/o2iblnd_cb.c index c52ff41..de402e7 100644 --- a/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -800,6 +800,7 @@ kiblnd_setup_rd_kiov (lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd, static int kiblnd_post_tx_locked (kib_conn_t *conn, kib_tx_t *tx, int credit) +__must_hold(&conn->ibc_lock) { kib_msg_t *msg = tx->tx_msg; kib_peer_t *peer = conn->ibc_peer; diff --git a/lnet/klnds/socklnd/socklnd_cb.c b/lnet/klnds/socklnd/socklnd_cb.c index 96d4eec..71ba3e4 100644 --- a/lnet/klnds/socklnd/socklnd_cb.c +++ b/lnet/klnds/socklnd/socklnd_cb.c @@ -2357,6 +2357,7 @@ ksocknal_flush_stale_txs(ksock_peer_t *peer) int ksocknal_send_keepalive_locked(ksock_peer_t *peer) +__must_hold(&ksocknal_data.ksnd_global_lock) { ksock_sched_t *sched; ksock_conn_t *conn; diff --git a/lnet/lnet/lib-eq.c b/lnet/lnet/lib-eq.c index 8810409..1e6b9af 100644 --- a/lnet/lnet/lib-eq.c +++ b/lnet/lnet/lib-eq.c @@ -336,6 +336,7 @@ EXPORT_SYMBOL(LNetEQWait); static int lnet_eq_wait_locked(int *timeout_ms) +__must_hold(&the_lnet.ln_eq_wait_lock) { int tms = *timeout_ms; int wait; diff --git a/lnet/selftest/framework.c b/lnet/selftest/framework.c index eae145c..c67192d 100644 --- a/lnet/selftest/framework.c +++ b/lnet/selftest/framework.c @@ -210,6 +210,7 @@ sfw_del_session_timer (void) /* called with sfw_data.fw_lock held */ static void sfw_deactivate_session (void) +__must_hold(&sfw_data.fw_lock) { sfw_session_t *sn = sfw_data.fw_session; int nactive = 0; diff --git a/lnet/selftest/rpc.c b/lnet/selftest/rpc.c index 9337435..f86155e 100644 --- a/lnet/selftest/rpc.c +++ b/lnet/selftest/rpc.c @@ -503,6 +503,7 @@ srpc_post_passive_rqtbuf(int service, int local, void *buf, int len, int srpc_service_post_buffer(struct srpc_service_cd *scd, struct srpc_buffer *buf) +__must_hold(&scd->scd_lock) { struct srpc_service *sv = scd->scd_svc; struct srpc_msg *msg = &buf->buf_msg; @@ -734,6 +735,7 @@ srpc_finish_service(struct srpc_service *sv) /* called with sv->sv_lock held */ void srpc_service_recycle_buffer(struct srpc_service_cd *scd, srpc_buffer_t *buf) +__must_hold(&scd->scd_lock) { if (!scd->scd_svc->sv_shuttingdown && scd->scd_buf_adjust >= 0) { if (srpc_service_post_buffer(scd, buf) != 0) { diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index 9fafedd..bdf0cc5 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -2265,6 +2265,7 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp, } void lov_stripe_lock(struct lov_stripe_md *md) +__acquires(&md->lsm_lock) { LASSERT(md->lsm_lock_owner != current_pid()); spin_lock(&md->lsm_lock); @@ -2273,6 +2274,7 @@ void lov_stripe_lock(struct lov_stripe_md *md) } void lov_stripe_unlock(struct lov_stripe_md *md) +__releases(&md->lsm_lock) { LASSERT(md->lsm_lock_owner == current_pid()); md->lsm_lock_owner = 0; diff --git a/lustre/obdclass/cl_object.c b/lustre/obdclass/cl_object.c index 357e73f..d94ef6d8 100644 --- a/lustre/obdclass/cl_object.c +++ b/lustre/obdclass/cl_object.c @@ -187,6 +187,7 @@ static spinlock_t *cl_object_attr_guard(struct cl_object *o) * cl_object_attr_get(), cl_object_attr_set(). */ void cl_object_attr_lock(struct cl_object *o) +__acquires(cl_object_attr_guard(o)) { spin_lock(cl_object_attr_guard(o)); } @@ -196,6 +197,7 @@ EXPORT_SYMBOL(cl_object_attr_lock); * Releases data-attributes lock, acquired by cl_object_attr_lock(). */ void cl_object_attr_unlock(struct cl_object *o) +__releases(cl_object_attr_guard(o)) { spin_unlock(cl_object_attr_guard(o)); } diff --git a/lustre/osc/osc_cache.c b/lustre/osc/osc_cache.c index 95f68cf..4a8e9ce 100644 --- a/lustre/osc/osc_cache.c +++ b/lustre/osc/osc_cache.c @@ -1937,6 +1937,7 @@ static int get_write_extents(struct osc_object *obj, struct list_head *rpclist) static int osc_send_write_rpc(const struct lu_env *env, struct client_obd *cli, struct osc_object *osc, pdl_policy_t pol) +__must_hold(osc) { struct list_head rpclist = LIST_HEAD_INIT(rpclist); struct osc_extent *ext; @@ -2010,6 +2011,7 @@ osc_send_write_rpc(const struct lu_env *env, struct client_obd *cli, static int osc_send_read_rpc(const struct lu_env *env, struct client_obd *cli, struct osc_object *osc, pdl_policy_t pol) +__must_hold(osc) { struct osc_extent *ext; struct osc_extent *next; @@ -2089,6 +2091,7 @@ static struct osc_object *osc_next_obj(struct client_obd *cli) /* called with the loi list lock held */ static void osc_check_rpcs(const struct lu_env *env, struct client_obd *cli, pdl_policy_t pol) +__must_hold(&cli->cl_loi_list_lock) { struct osc_object *osc; int rc = 0; diff --git a/lustre/ptlrpc/client.c b/lustre/ptlrpc/client.c index 8342eae..1621367 100644 --- a/lustre/ptlrpc/client.c +++ b/lustre/ptlrpc/client.c @@ -338,6 +338,7 @@ static int unpack_reply(struct ptlrpc_request *req) * If anything goes wrong just ignore it - same as if it never happened */ static int ptlrpc_at_recv_early_reply(struct ptlrpc_request *req) +__must_hold(&req->rq_lock) { struct ptlrpc_request *early_req; time_t olddl;