aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHannes Reinecke <hare@suse.de>2015-12-01 04:16:41 -0500
committerMartin K. Petersen <martin.petersen@oracle.com>2015-12-02 16:29:19 -0500
commit41f95dd2efd80a611c8566888fcdcb5d399ea474 (patch)
treee5c706b5eef78f4a7b6be962e7245fbd5d45a72b
parent7789cd39274c51bf475411fe22a8ee7255082809 (diff)
scsi_dh: move 'dh_state' sysfs attribute to generic code
As scsi_dh.c is now always compiled in we should be moving the 'dh_state' attribute to the generic code. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.com> Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r--drivers/scsi/scsi_dh.c72
-rw-r--r--drivers/scsi/scsi_priv.h3
-rw-r--r--drivers/scsi/scsi_sysfs.c58
3 files changed, 60 insertions, 73 deletions
diff --git a/drivers/scsi/scsi_dh.c b/drivers/scsi/scsi_dh.c
index e7649ed3f667..54d446c9f56e 100644
--- a/drivers/scsi/scsi_dh.c
+++ b/drivers/scsi/scsi_dh.c
@@ -153,76 +153,11 @@ static void scsi_dh_handler_detach(struct scsi_device *sdev)
153 module_put(sdev->handler->module); 153 module_put(sdev->handler->module);
154} 154}
155 155
156/*
157 * Functions for sysfs attribute 'dh_state'
158 */
159static ssize_t
160store_dh_state(struct device *dev, struct device_attribute *attr,
161 const char *buf, size_t count)
162{
163 struct scsi_device *sdev = to_scsi_device(dev);
164 struct scsi_device_handler *scsi_dh;
165 int err = -EINVAL;
166
167 if (sdev->sdev_state == SDEV_CANCEL ||
168 sdev->sdev_state == SDEV_DEL)
169 return -ENODEV;
170
171 if (!sdev->handler) {
172 /*
173 * Attach to a device handler
174 */
175 scsi_dh = scsi_dh_lookup(buf);
176 if (!scsi_dh)
177 return err;
178 err = scsi_dh_handler_attach(sdev, scsi_dh);
179 } else {
180 if (!strncmp(buf, "detach", 6)) {
181 /*
182 * Detach from a device handler
183 */
184 sdev_printk(KERN_WARNING, sdev,
185 "can't detach handler %s.\n",
186 sdev->handler->name);
187 err = -EINVAL;
188 } else if (!strncmp(buf, "activate", 8)) {
189 /*
190 * Activate a device handler
191 */
192 if (sdev->handler->activate)
193 err = sdev->handler->activate(sdev, NULL, NULL);
194 else
195 err = 0;
196 }
197 }
198
199 return err<0?err:count;
200}
201
202static ssize_t
203show_dh_state(struct device *dev, struct device_attribute *attr, char *buf)
204{
205 struct scsi_device *sdev = to_scsi_device(dev);
206
207 if (!sdev->handler)
208 return snprintf(buf, 20, "detached\n");
209
210 return snprintf(buf, 20, "%s\n", sdev->handler->name);
211}
212
213static struct device_attribute scsi_dh_state_attr =
214 __ATTR(dh_state, S_IRUGO | S_IWUSR, show_dh_state,
215 store_dh_state);
216
217int scsi_dh_add_device(struct scsi_device *sdev) 156int scsi_dh_add_device(struct scsi_device *sdev)
218{ 157{
219 struct scsi_device_handler *devinfo = NULL; 158 struct scsi_device_handler *devinfo = NULL;
220 const char *drv; 159 const char *drv;
221 int err; 160 int err = 0;
222
223 err = device_create_file(&sdev->sdev_gendev, &scsi_dh_state_attr);
224 if (err)
225 return err;
226 161
227 drv = scsi_dh_find_driver(sdev); 162 drv = scsi_dh_find_driver(sdev);
228 if (drv) 163 if (drv)
@@ -238,11 +173,6 @@ void scsi_dh_release_device(struct scsi_device *sdev)
238 scsi_dh_handler_detach(sdev); 173 scsi_dh_handler_detach(sdev);
239} 174}
240 175
241void scsi_dh_remove_device(struct scsi_device *sdev)
242{
243 device_remove_file(&sdev->sdev_gendev, &scsi_dh_state_attr);
244}
245
246/* 176/*
247 * scsi_register_device_handler - register a device handler personality 177 * scsi_register_device_handler - register a device handler personality
248 * module. 178 * module.
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 4d01cdb1b348..27b4d0a6a01d 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -174,12 +174,11 @@ extern struct async_domain scsi_sd_probe_domain;
174#ifdef CONFIG_SCSI_DH 174#ifdef CONFIG_SCSI_DH
175int scsi_dh_add_device(struct scsi_device *sdev); 175int scsi_dh_add_device(struct scsi_device *sdev);
176void scsi_dh_release_device(struct scsi_device *sdev); 176void scsi_dh_release_device(struct scsi_device *sdev);
177void scsi_dh_remove_device(struct scsi_device *sdev);
178#else 177#else
179static inline int scsi_dh_add_device(struct scsi_device *sdev) { return 0; } 178static inline int scsi_dh_add_device(struct scsi_device *sdev) { return 0; }
180static inline void scsi_dh_release_device(struct scsi_device *sdev) { } 179static inline void scsi_dh_release_device(struct scsi_device *sdev) { }
181static inline void scsi_dh_remove_device(struct scsi_device *sdev) { }
182#endif 180#endif
181static inline void scsi_dh_remove_device(struct scsi_device *sdev) { }
183 182
184/* 183/*
185 * internal scsi timeout functions: for use by mid-layer and transport 184 * internal scsi timeout functions: for use by mid-layer and transport
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 158f1b553acf..fc3cd2656059 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -17,6 +17,7 @@
17#include <scsi/scsi_device.h> 17#include <scsi/scsi_device.h>
18#include <scsi/scsi_host.h> 18#include <scsi/scsi_host.h>
19#include <scsi/scsi_tcq.h> 19#include <scsi/scsi_tcq.h>
20#include <scsi/scsi_dh.h>
20#include <scsi/scsi_transport.h> 21#include <scsi/scsi_transport.h>
21#include <scsi/scsi_driver.h> 22#include <scsi/scsi_driver.h>
22 23
@@ -904,6 +905,60 @@ sdev_show_function(queue_depth, "%d\n");
904static DEVICE_ATTR(queue_depth, S_IRUGO | S_IWUSR, sdev_show_queue_depth, 905static DEVICE_ATTR(queue_depth, S_IRUGO | S_IWUSR, sdev_show_queue_depth,
905 sdev_store_queue_depth); 906 sdev_store_queue_depth);
906 907
908#ifdef CONFIG_SCSI_DH
909static ssize_t
910sdev_show_dh_state(struct device *dev, struct device_attribute *attr,
911 char *buf)
912{
913 struct scsi_device *sdev = to_scsi_device(dev);
914
915 if (!sdev->handler)
916 return snprintf(buf, 20, "detached\n");
917
918 return snprintf(buf, 20, "%s\n", sdev->handler->name);
919}
920
921static ssize_t
922sdev_store_dh_state(struct device *dev, struct device_attribute *attr,
923 const char *buf, size_t count)
924{
925 struct scsi_device *sdev = to_scsi_device(dev);
926 int err = -EINVAL;
927
928 if (sdev->sdev_state == SDEV_CANCEL ||
929 sdev->sdev_state == SDEV_DEL)
930 return -ENODEV;
931
932 if (!sdev->handler) {
933 /*
934 * Attach to a device handler
935 */
936 err = scsi_dh_attach(sdev->request_queue, buf);
937 } else if (!strncmp(buf, "activate", 8)) {
938 /*
939 * Activate a device handler
940 */
941 if (sdev->handler->activate)
942 err = sdev->handler->activate(sdev, NULL, NULL);
943 else
944 err = 0;
945 } else if (!strncmp(buf, "detach", 6)) {
946 /*
947 * Detach from a device handler
948 */
949 sdev_printk(KERN_WARNING, sdev,
950 "can't detach handler %s.\n",
951 sdev->handler->name);
952 err = -EINVAL;
953 }
954
955 return err < 0 ? err : count;
956}
957
958static DEVICE_ATTR(dh_state, S_IRUGO | S_IWUSR, sdev_show_dh_state,
959 sdev_store_dh_state);
960#endif
961
907static ssize_t 962static ssize_t
908sdev_show_queue_ramp_up_period(struct device *dev, 963sdev_show_queue_ramp_up_period(struct device *dev,
909 struct device_attribute *attr, 964 struct device_attribute *attr,
@@ -973,6 +1028,9 @@ static struct attribute *scsi_sdev_attrs[] = {
973 &dev_attr_modalias.attr, 1028 &dev_attr_modalias.attr,
974 &dev_attr_queue_depth.attr, 1029 &dev_attr_queue_depth.attr,
975 &dev_attr_queue_type.attr, 1030 &dev_attr_queue_type.attr,
1031#ifdef CONFIG_SCSI_DH
1032 &dev_attr_dh_state.attr,
1033#endif
976 &dev_attr_queue_ramp_up_period.attr, 1034 &dev_attr_queue_ramp_up_period.attr,
977 REF_EVT(media_change), 1035 REF_EVT(media_change),
978 REF_EVT(inquiry_change_reported), 1036 REF_EVT(inquiry_change_reported),