From 585c5d2fe0301c96635a67a1dd1027e84f7856e4 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 24 Feb 2017 02:07:29 +0000 Subject: [PATCH 1/2] scst_copy_mgr: Convert comments about locking into runtime checks git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7095 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_copy_mgr.c | 43 ++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/scst/src/scst_copy_mgr.c b/scst/src/scst_copy_mgr.c index e5b939bf9..f5935fdf8 100644 --- a/scst/src/scst_copy_mgr.c +++ b/scst/src/scst_copy_mgr.c @@ -2498,7 +2498,6 @@ out_free: goto out; } -/* scst_mutex supposed to be held and activities suspended */ static bool scst_cm_is_lun_free(unsigned int lun) { bool res = true; @@ -2507,6 +2506,9 @@ static bool scst_cm_is_lun_free(unsigned int lun) TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + list_for_each_entry(tgt_dev, head, sess_tgt_dev_list_entry) { if (tgt_dev->lun == lun) { res = false; @@ -2518,7 +2520,6 @@ static bool scst_cm_is_lun_free(unsigned int lun) return res; } -/* scst_mutex supposed to be held and activities suspended */ static unsigned int scst_cm_get_lun(const struct scst_device *dev) { unsigned int res = -1; @@ -2527,6 +2528,9 @@ static unsigned int scst_cm_get_lun(const struct scst_device *dev) TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + for (i = 0; i < SESS_TGT_DEV_LIST_HASH_SIZE; i++) { struct list_head *head = &scst_cm_sess->sess_tgt_dev_list[i]; struct scst_tgt_dev *tgt_dev; @@ -2549,7 +2553,6 @@ out: return res; } -/* scst_mutex supposed to be held and activities suspended */ static int scst_cm_dev_register(struct scst_device *dev, uint64_t lun) { int res, i; @@ -2558,6 +2561,9 @@ static int scst_cm_dev_register(struct scst_device *dev, uint64_t lun) TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + TRACE_DBG("dev %s, LUN %ld", dev->virt_name, (unsigned long)lun); for (i = 0; i < SESS_TGT_DEV_LIST_HASH_SIZE; i++) { @@ -2622,7 +2628,6 @@ out_err: goto out; } -/* scst_mutex supposed to be held and activities suspended */ static void scst_cm_dev_unregister(struct scst_device *dev, bool del_lun) { int i; @@ -2630,6 +2635,9 @@ static void scst_cm_dev_unregister(struct scst_device *dev, bool del_lun) TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + TRACE_DBG("dev %s, del_lun %d", dev->virt_name, del_lun); list_for_each_entry_safe(des, t, &scst_cm_desig_list, cm_desig_list_entry) { @@ -2696,13 +2704,15 @@ out_unblock: goto out_resume; } -/* scst_mutex supposed to be held and activities suspended */ int scst_cm_on_dev_register(struct scst_device *dev) { int res = 0; TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + if (!dev->handler->auto_cm_assignment_possible) goto out; @@ -2713,24 +2723,28 @@ out: return res; } -/* scst_mutex supposed to be held and activities suspended */ void scst_cm_on_dev_unregister(struct scst_device *dev) { TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + scst_cm_dev_unregister(dev, true); TRACE_EXIT(); return; } -/* scst_mutex supposed to be held and activities suspended */ int scst_cm_on_add_acg(struct scst_acg *acg) { int res = 0; TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + if (scst_cm_tgt == NULL) goto out; @@ -2748,13 +2762,13 @@ out: return res; } -/* scst_mutex supposed to be held and activities suspended */ void scst_cm_on_del_acg(struct scst_acg *acg) { + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); /* Nothing to do */ } -/* scst_mutex supposed to be held and activities suspended */ int scst_cm_on_add_lun(struct scst_acg_dev *acg_dev, uint64_t lun, unsigned int *flags) { @@ -2762,6 +2776,9 @@ int scst_cm_on_add_lun(struct scst_acg_dev *acg_dev, uint64_t lun, TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + if (acg_dev->acg != scst_cm_tgt->default_acg) goto out; @@ -2780,13 +2797,15 @@ out: return res; } -/* scst_mutex supposed to be held and activities suspended */ bool scst_cm_on_del_lun(struct scst_acg_dev *acg_dev, bool gen_report_luns_changed) { bool res = gen_report_luns_changed; TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + if (acg_dev->acg != scst_cm_tgt->default_acg) goto out; @@ -2799,7 +2818,6 @@ out: return res; } -/* scst_mutex supposed to be locked */ static bool scst_cm_check_access_acg(const char *initiator_name, const struct scst_device *dev, const struct scst_acg *acg, bool default_acg) @@ -2809,6 +2827,9 @@ static bool scst_cm_check_access_acg(const char *initiator_name, TRACE_ENTRY(); + scst_assert_activity_suspended(); + lockdep_assert_held(&scst_mutex); + list_for_each_entry(acg_dev, &acg->acg_dev_list, acg_dev_list_entry) { if (acg_dev->dev == dev) { struct scst_acn *acn; From ab0e7cc0bec29bcc843dafcd82db21b6513f712d Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 24 Feb 2017 02:08:17 +0000 Subject: [PATCH 2/2] scst_copy_mgr: Avoid that LUN removal triggers a BUG() Reported-by: Jinpu Wang git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7096 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_copy_mgr.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scst/src/scst_copy_mgr.c b/scst/src/scst_copy_mgr.c index f5935fdf8..5c9ce1345 100644 --- a/scst/src/scst_copy_mgr.c +++ b/scst/src/scst_copy_mgr.c @@ -2522,9 +2522,8 @@ static bool scst_cm_is_lun_free(unsigned int lun) static unsigned int scst_cm_get_lun(const struct scst_device *dev) { - unsigned int res = -1; + unsigned int res = SCST_MAX_LUN; int i; - bool found = false; TRACE_ENTRY(); @@ -2538,7 +2537,6 @@ static unsigned int scst_cm_get_lun(const struct scst_device *dev) list_for_each_entry(tgt_dev, head, sess_tgt_dev_list_entry) { if (tgt_dev->dev == dev) { res = tgt_dev->lun; - found = true; TRACE_DBG("LUN %d found (full LUN %lld)", res, tgt_dev->lun); goto out; @@ -2546,8 +2544,6 @@ static unsigned int scst_cm_get_lun(const struct scst_device *dev) } } - sBUG_ON(!found); - out: TRACE_EXIT_RES(res); return res;