24 #include <linux/slab.h>
25 #include <linux/module.h>
27 #include "../scsi_priv.h"
55 device_handler_match_function(
struct scsi_device *sdev)
85 found_dh = device_handler_match_function(sdev);
87 if (scsi_dh && found_dh != scsi_dh)
98 static int scsi_dh_handler_attach(
struct scsi_device *sdev,
108 }
else if (scsi_dh->
attach) {
109 err = scsi_dh->
attach(sdev);
118 static void __detach_handler (
struct kref *
kref)
132 static void scsi_dh_handler_detach(
struct scsi_device *sdev,
144 if (scsi_dh && scsi_dh->
detach)
167 if (!(scsi_dh = get_device_handler(buf)))
169 err = scsi_dh_handler_attach(sdev, scsi_dh);
172 if (!
strncmp(buf,
"detach", 6)) {
176 scsi_dh_handler_detach(sdev, scsi_dh);
178 }
else if (!
strncmp(buf,
"activate", 8)) {
189 return err<0?err:
count;
198 return snprintf(buf, 20,
"detached\n");
210 static int scsi_dh_sysfs_attr_add(
struct device *dev,
void *
data)
221 &scsi_dh_state_attr);
229 static int scsi_dh_sysfs_attr_remove(
struct device *dev,
void *data)
239 &scsi_dh_state_attr);
248 unsigned long action,
void *data)
263 devinfo = device_handler_match(
NULL, sdev);
265 err = scsi_dh_handler_attach(sdev, devinfo);
268 scsi_dh_handler_detach(sdev,
NULL);
276 static int scsi_dh_notifier_add(
struct device *dev,
void *data)
289 if (device_handler_match(scsi_dh, sdev))
290 scsi_dh_handler_attach(sdev, scsi_dh);
300 static int scsi_dh_notifier_remove(
struct device *dev,
void *data)
313 scsi_dh_handler_detach(sdev, scsi_dh);
330 if (get_device_handler(scsi_dh->
name))
334 list_add(&scsi_dh->
list, &scsi_dh_list);
354 if (!get_device_handler(scsi_dh->
name))
358 scsi_dh_notifier_remove);
393 spin_unlock_irqrestore(q->queue_lock, flags);
403 if (!scsi_dh || !dev ||
409 spin_unlock_irqrestore(q->queue_lock, flags);
418 err = scsi_dh->
activate(sdev, fn, data);
448 spin_unlock_irqrestore(q->queue_lock, flags);
465 return (get_device_handler(name) !=
NULL);
482 scsi_dh = get_device_handler(name);
490 spin_unlock_irqrestore(q->queue_lock, flags);
493 err = scsi_dh_handler_attach(sdev, scsi_dh);
519 spin_unlock_irqrestore(q->queue_lock, flags);
526 scsi_dh_handler_detach(sdev, scsi_dh);
545 const char *handler_name =
NULL;
551 spin_unlock_irqrestore(q->queue_lock, flags);
565 .notifier_call = scsi_dh_notifier
568 static int __init scsi_dh_init(
void)
576 scsi_dh_sysfs_attr_add);
581 static void __exit scsi_dh_exit(
void)
584 scsi_dh_sysfs_attr_remove);