Skip to content

Commit a95be38

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: target/core: Simplify transport_clear_lun_ref()
Since transport_clear_lun_ref() already waits until the percpu-refcount .release() method is called, it is not necessary to wait first until percpu_ref_kill_and_confirm() has finished transitioning the refcount into atomic mode. Remove the code that waits for percpu_ref_kill_and_confirm() to complete and also the completion object that is used by that code. This patch does not change the behavior of the SCSI target code. Cc: Nicholas Bellinger <nab@linux-iscsi.org> Cc: Mike Christie <mchristi@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: David Disseldorp <ddiss@suse.de> Cc: Hannes Reinecke <hare@suse.de> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 5d6cd9f commit a95be38

File tree

4 files changed

+5
-33
lines changed

4 files changed

+5
-33
lines changed

drivers/target/target_core_device.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,6 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
823823

824824
xcopy_lun = &dev->xcopy_lun;
825825
rcu_assign_pointer(xcopy_lun->lun_se_dev, dev);
826-
init_completion(&xcopy_lun->lun_ref_comp);
827826
init_completion(&xcopy_lun->lun_shutdown_comp);
828827
INIT_LIST_HEAD(&xcopy_lun->lun_deve_list);
829828
INIT_LIST_HEAD(&xcopy_lun->lun_dev_link);

drivers/target/target_core_tpg.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ struct se_lun *core_tpg_alloc_lun(
577577
}
578578
lun->unpacked_lun = unpacked_lun;
579579
atomic_set(&lun->lun_acl_count, 0);
580-
init_completion(&lun->lun_ref_comp);
581580
init_completion(&lun->lun_shutdown_comp);
582581
INIT_LIST_HEAD(&lun->lun_deve_list);
583582
INIT_LIST_HEAD(&lun->lun_dev_link);

drivers/target/target_core_transport.c

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,38 +2911,13 @@ void target_wait_for_sess_cmds(struct se_session *se_sess)
29112911
}
29122912
EXPORT_SYMBOL(target_wait_for_sess_cmds);
29132913

2914-
static void target_lun_confirm(struct percpu_ref *ref)
2915-
{
2916-
struct se_lun *lun = container_of(ref, struct se_lun, lun_ref);
2917-
2918-
complete(&lun->lun_ref_comp);
2919-
}
2920-
2914+
/*
2915+
* Prevent that new percpu_ref_tryget_live() calls succeed and wait until
2916+
* all references to the LUN have been released. Called during LUN shutdown.
2917+
*/
29212918
void transport_clear_lun_ref(struct se_lun *lun)
29222919
{
2923-
/*
2924-
* Mark the percpu-ref as DEAD, switch to atomic_t mode, drop
2925-
* the initial reference and schedule confirm kill to be
2926-
* executed after one full RCU grace period has completed.
2927-
*/
2928-
percpu_ref_kill_and_confirm(&lun->lun_ref, target_lun_confirm);
2929-
/*
2930-
* The first completion waits for percpu_ref_switch_to_atomic_rcu()
2931-
* to call target_lun_confirm after lun->lun_ref has been marked
2932-
* as __PERCPU_REF_DEAD on all CPUs, and switches to atomic_t
2933-
* mode so that percpu_ref_tryget_live() lookup of lun->lun_ref
2934-
* fails for all new incoming I/O.
2935-
*/
2936-
wait_for_completion(&lun->lun_ref_comp);
2937-
/*
2938-
* The second completion waits for percpu_ref_put_many() to
2939-
* invoke ->release() after lun->lun_ref has switched to
2940-
* atomic_t mode, and lun->lun_ref.count has reached zero.
2941-
*
2942-
* At this point all target-core lun->lun_ref references have
2943-
* been dropped via transport_lun_remove_cmd(), and it's safe
2944-
* to proceed with the remaining LUN shutdown.
2945-
*/
2920+
percpu_ref_kill(&lun->lun_ref);
29462921
wait_for_completion(&lun->lun_shutdown_comp);
29472922
}
29482923

include/target/target_core_base.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,6 @@ struct se_lun {
733733
struct scsi_port_stats lun_stats;
734734
struct config_group lun_group;
735735
struct se_port_stat_grps port_stat_grps;
736-
struct completion lun_ref_comp;
737736
struct completion lun_shutdown_comp;
738737
struct percpu_ref lun_ref;
739738
struct list_head lun_dev_link;

0 commit comments

Comments
 (0)