Commit bd976f62 authored by Mike Christie's avatar Mike Christie Committed by James Bottomley

[SCSI] iscsi class: add session scanning

This just adds iscsi session scanning which works like fc rport scanning.
The future patches will hook the drivers into Mathew Wilcox's async
scanning infrastructure, so userspace does not have to special case
iscsi and so userspace does not have to make a extra special case for
hardware iscsi root scanning.
Signed-off-by: default avatarMike Christie <michaelc@cs.wisc.edu>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent 7fb1921b
...@@ -128,11 +128,11 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev, ...@@ -128,11 +128,11 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
INIT_LIST_HEAD(&ihost->sessions); INIT_LIST_HEAD(&ihost->sessions);
mutex_init(&ihost->mutex); mutex_init(&ihost->mutex);
snprintf(ihost->unbind_workq_name, KOBJ_NAME_LEN, "iscsi_unbind_%d", snprintf(ihost->scan_workq_name, KOBJ_NAME_LEN, "iscsi_scan_%d",
shost->host_no); shost->host_no);
ihost->unbind_workq = create_singlethread_workqueue( ihost->scan_workq = create_singlethread_workqueue(
ihost->unbind_workq_name); ihost->scan_workq_name);
if (!ihost->unbind_workq) if (!ihost->scan_workq)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
} }
...@@ -143,7 +143,7 @@ static int iscsi_remove_host(struct transport_container *tc, struct device *dev, ...@@ -143,7 +143,7 @@ static int iscsi_remove_host(struct transport_container *tc, struct device *dev,
struct Scsi_Host *shost = dev_to_shost(dev); struct Scsi_Host *shost = dev_to_shost(dev);
struct iscsi_host *ihost = shost->shost_data; struct iscsi_host *ihost = shost->shost_data;
destroy_workqueue(ihost->unbind_workq); destroy_workqueue(ihost->scan_workq);
return 0; return 0;
} }
...@@ -302,6 +302,23 @@ static int iscsi_user_scan(struct Scsi_Host *shost, uint channel, ...@@ -302,6 +302,23 @@ static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
return 0; return 0;
} }
static void iscsi_scan_session(struct work_struct *work)
{
struct iscsi_cls_session *session =
container_of(work, struct iscsi_cls_session, scan_work);
unsigned long flags;
spin_lock_irqsave(&session->lock, flags);
if (session->state != ISCSI_SESSION_LOGGED_IN) {
spin_unlock_irqrestore(&session->lock, flags);
return;
}
spin_unlock_irqrestore(&session->lock, flags);
scsi_scan_target(&session->dev, 0, session->target_id,
SCAN_WILD_CARD, 1);
}
static void session_recovery_timedout(struct work_struct *work) static void session_recovery_timedout(struct work_struct *work)
{ {
struct iscsi_cls_session *session = struct iscsi_cls_session *session =
...@@ -340,6 +357,8 @@ void __iscsi_unblock_session(struct iscsi_cls_session *session) ...@@ -340,6 +357,8 @@ void __iscsi_unblock_session(struct iscsi_cls_session *session)
void iscsi_unblock_session(struct iscsi_cls_session *session) void iscsi_unblock_session(struct iscsi_cls_session *session)
{ {
struct Scsi_Host *shost = iscsi_session_to_shost(session);
struct iscsi_host *ihost = shost->shost_data;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&session->lock, flags); spin_lock_irqsave(&session->lock, flags);
...@@ -347,6 +366,7 @@ void iscsi_unblock_session(struct iscsi_cls_session *session) ...@@ -347,6 +366,7 @@ void iscsi_unblock_session(struct iscsi_cls_session *session)
spin_unlock_irqrestore(&session->lock, flags); spin_unlock_irqrestore(&session->lock, flags);
__iscsi_unblock_session(session); __iscsi_unblock_session(session);
queue_work(ihost->scan_workq, &session->scan_work);
} }
EXPORT_SYMBOL_GPL(iscsi_unblock_session); EXPORT_SYMBOL_GPL(iscsi_unblock_session);
...@@ -390,7 +410,7 @@ static int iscsi_unbind_session(struct iscsi_cls_session *session) ...@@ -390,7 +410,7 @@ static int iscsi_unbind_session(struct iscsi_cls_session *session)
struct Scsi_Host *shost = iscsi_session_to_shost(session); struct Scsi_Host *shost = iscsi_session_to_shost(session);
struct iscsi_host *ihost = shost->shost_data; struct iscsi_host *ihost = shost->shost_data;
return queue_work(ihost->unbind_workq, &session->unbind_work); return queue_work(ihost->scan_workq, &session->unbind_work);
} }
struct iscsi_cls_session * struct iscsi_cls_session *
...@@ -411,6 +431,7 @@ iscsi_alloc_session(struct Scsi_Host *shost, ...@@ -411,6 +431,7 @@ iscsi_alloc_session(struct Scsi_Host *shost,
INIT_LIST_HEAD(&session->host_list); INIT_LIST_HEAD(&session->host_list);
INIT_LIST_HEAD(&session->sess_list); INIT_LIST_HEAD(&session->sess_list);
INIT_WORK(&session->unbind_work, __iscsi_unbind_session); INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
INIT_WORK(&session->scan_work, iscsi_scan_session);
spin_lock_init(&session->lock); spin_lock_init(&session->lock);
/* this is released in the dev's release function */ /* this is released in the dev's release function */
...@@ -530,13 +551,15 @@ void iscsi_remove_session(struct iscsi_cls_session *session) ...@@ -530,13 +551,15 @@ void iscsi_remove_session(struct iscsi_cls_session *session)
spin_unlock_irqrestore(&session->lock, flags); spin_unlock_irqrestore(&session->lock, flags);
__iscsi_unblock_session(session); __iscsi_unblock_session(session);
iscsi_unbind_session(session); iscsi_unbind_session(session);
/* flush running scans */
flush_workqueue(ihost->scan_workq);
/* /*
* If the session dropped while removing devices then we need to make * If the session dropped while removing devices then we need to make
* sure it is not blocked * sure it is not blocked
*/ */
if (!cancel_delayed_work(&session->recovery_work)) if (!cancel_delayed_work(&session->recovery_work))
flush_workqueue(iscsi_eh_timer_workq); flush_workqueue(iscsi_eh_timer_workq);
flush_workqueue(ihost->unbind_workq);
/* hw iscsi may not have removed all connections from session */ /* hw iscsi may not have removed all connections from session */
err = device_for_each_child(&session->dev, NULL, err = device_for_each_child(&session->dev, NULL,
......
...@@ -177,11 +177,12 @@ struct iscsi_cls_session { ...@@ -177,11 +177,12 @@ struct iscsi_cls_session {
struct list_head host_list; struct list_head host_list;
struct iscsi_transport *transport; struct iscsi_transport *transport;
spinlock_t lock; spinlock_t lock;
struct work_struct scan_work;
struct work_struct unbind_work;
/* recovery fields */ /* recovery fields */
int recovery_tmo; int recovery_tmo;
struct delayed_work recovery_work; struct delayed_work recovery_work;
struct work_struct unbind_work;
int target_id; int target_id;
...@@ -203,8 +204,8 @@ struct iscsi_cls_session { ...@@ -203,8 +204,8 @@ struct iscsi_cls_session {
struct iscsi_host { struct iscsi_host {
struct list_head sessions; struct list_head sessions;
struct mutex mutex; struct mutex mutex;
struct workqueue_struct *unbind_workq; struct workqueue_struct *scan_workq;
char unbind_workq_name[KOBJ_NAME_LEN]; char scan_workq_name[KOBJ_NAME_LEN];
}; };
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment