Skip to content

Commit 3195019

Browse files
mwilckmartinkpetersen
authored andcommitted
scsi: core: Replace scsi_target_block() with scsi_block_targets()
All callers (fc_remote_port_delete(), __iscsi_block_session(), __srp_start_tl_fail_timers(), srp_reconnect_rport(), snic_tgt_del()) pass parent devices of scsi_target devices to scsi_target_block(). Rename the function to scsi_block_targets(), and simplify it by assuming that it is always passed a parent device. Also, have callers pass the Scsi_Host pointer to scsi_block_targets(), as every caller has this pointer readily available. Suggested-by: Christoph Hellwig <[email protected]> Suggested-by: Bart Van Assche <[email protected]> Signed-off-by: Martin Wilck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: Karan Tilak Kumar <[email protected]> Cc: Sesidhar Baddela <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent e20fff8 commit 3195019

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,20 +2890,26 @@ target_block(struct device *dev, void *data)
28902890
return 0;
28912891
}
28922892

2893+
/**
2894+
* scsi_block_targets - transition all SCSI child devices to SDEV_BLOCK state
2895+
* @dev: a parent device of one or more scsi_target devices
2896+
* @shost: the Scsi_Host to which this device belongs
2897+
*
2898+
* Iterate over all children of @dev, which should be scsi_target devices,
2899+
* and switch all subordinate scsi devices to SDEV_BLOCK state. Wait for
2900+
* ongoing scsi_queue_rq() calls to finish. May sleep.
2901+
*
2902+
* Note:
2903+
* @dev must not itself be a scsi_target device.
2904+
*/
28932905
void
2894-
scsi_target_block(struct device *dev)
2906+
scsi_block_targets(struct Scsi_Host *shost, struct device *dev)
28952907
{
2896-
struct Scsi_Host *shost = dev_to_shost(dev);
2897-
2898-
if (scsi_is_target_device(dev))
2899-
starget_for_each_device(to_scsi_target(dev), NULL,
2900-
scsi_device_block);
2901-
else
2902-
device_for_each_child(dev, NULL, target_block);
2903-
2908+
WARN_ON_ONCE(scsi_is_target_device(dev));
2909+
device_for_each_child(dev, NULL, target_block);
29042910
blk_mq_wait_quiesce_done(&shost->tag_set);
29052911
}
2906-
EXPORT_SYMBOL_GPL(scsi_target_block);
2912+
EXPORT_SYMBOL_GPL(scsi_block_targets);
29072913

29082914
static void
29092915
device_unblock(struct scsi_device *sdev, void *data)

drivers/scsi/scsi_transport_fc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3451,7 +3451,7 @@ fc_remote_port_delete(struct fc_rport *rport)
34513451

34523452
spin_unlock_irqrestore(shost->host_lock, flags);
34533453

3454-
scsi_target_block(&rport->dev);
3454+
scsi_block_targets(shost, &rport->dev);
34553455

34563456
/* see if we need to kill io faster than waiting for device loss */
34573457
if ((rport->fast_io_fail_tmo != -1) &&

drivers/scsi/scsi_transport_iscsi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,13 +1943,14 @@ static void __iscsi_block_session(struct work_struct *work)
19431943
struct iscsi_cls_session *session =
19441944
container_of(work, struct iscsi_cls_session,
19451945
block_work);
1946+
struct Scsi_Host *shost = iscsi_session_to_shost(session);
19461947
unsigned long flags;
19471948

19481949
ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n");
19491950
spin_lock_irqsave(&session->lock, flags);
19501951
session->state = ISCSI_SESSION_FAILED;
19511952
spin_unlock_irqrestore(&session->lock, flags);
1952-
scsi_target_block(&session->dev);
1953+
scsi_block_targets(shost, &session->dev);
19531954
ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n");
19541955
if (session->recovery_tmo >= 0)
19551956
queue_delayed_work(session->workq,

drivers/scsi/scsi_transport_srp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static void srp_reconnect_work(struct work_struct *work)
396396
}
397397

398398
/*
399-
* scsi_target_block() must have been called before this function is
399+
* scsi_block_targets() must have been called before this function is
400400
* called to guarantee that no .queuecommand() calls are in progress.
401401
*/
402402
static void __rport_fail_io_fast(struct srp_rport *rport)
@@ -480,7 +480,7 @@ static void __srp_start_tl_fail_timers(struct srp_rport *rport)
480480
srp_rport_set_state(rport, SRP_RPORT_BLOCKED) == 0) {
481481
pr_debug("%s new state: %d\n", dev_name(&shost->shost_gendev),
482482
rport->state);
483-
scsi_target_block(&shost->shost_gendev);
483+
scsi_block_targets(shost, &shost->shost_gendev);
484484
if (fast_io_fail_tmo >= 0)
485485
queue_delayed_work(system_long_wq,
486486
&rport->fast_io_fail_work,
@@ -548,7 +548,7 @@ int srp_reconnect_rport(struct srp_rport *rport)
548548
* later is ok though, scsi_internal_device_unblock_nowait()
549549
* treats SDEV_TRANSPORT_OFFLINE like SDEV_BLOCK.
550550
*/
551-
scsi_target_block(&shost->shost_gendev);
551+
scsi_block_targets(shost, &shost->shost_gendev);
552552
res = rport->state != SRP_RPORT_LOST ? i->f->reconnect(rport) : -ENODEV;
553553
pr_debug("%s (state %d): transport.reconnect() returned %d\n",
554554
dev_name(&shost->shost_gendev), rport->state, res);

drivers/scsi/snic/snic_disc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ snic_tgt_del(struct work_struct *work)
214214
scsi_flush_work(shost);
215215

216216
/* Block IOs on child devices, stops new IOs */
217-
scsi_target_block(&tgt->dev);
217+
scsi_block_targets(shost, &tgt->dev);
218218

219219
/* Cleanup IOs */
220220
snic_tgt_scsi_abort_io(tgt);

include/scsi/scsi_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ extern void scsi_scan_target(struct device *parent, unsigned int channel,
450450
unsigned int id, u64 lun,
451451
enum scsi_scan_mode rescan);
452452
extern void scsi_target_reap(struct scsi_target *);
453-
extern void scsi_target_block(struct device *);
453+
void scsi_block_targets(struct Scsi_Host *shost, struct device *dev);
454454
extern void scsi_target_unblock(struct device *, enum scsi_device_state);
455455
extern void scsi_remove_target(struct device *);
456456
extern const char *scsi_device_state_name(enum scsi_device_state);

0 commit comments

Comments
 (0)