aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r--drivers/scsi/sd.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 5fe7aaed904c..3cea17dd5dba 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -95,7 +95,7 @@ static int sd_resume(struct device *);
95static void sd_rescan(struct device *); 95static void sd_rescan(struct device *);
96static int sd_done(struct scsi_cmnd *); 96static int sd_done(struct scsi_cmnd *);
97static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer); 97static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer);
98static void scsi_disk_release(struct class_device *cdev); 98static void scsi_disk_release(struct device *cdev);
99static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); 99static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
100static void sd_print_result(struct scsi_disk *, int); 100static void sd_print_result(struct scsi_disk *, int);
101 101
@@ -112,11 +112,12 @@ static const char *sd_cache_types[] = {
112 "write back, no read (daft)" 112 "write back, no read (daft)"
113}; 113};
114 114
115static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf, 115static ssize_t
116 size_t count) 116sd_store_cache_type(struct device *dev, struct device_attribute *attr,
117 const char *buf, size_t count)
117{ 118{
118 int i, ct = -1, rcd, wce, sp; 119 int i, ct = -1, rcd, wce, sp;
119 struct scsi_disk *sdkp = to_scsi_disk(cdev); 120 struct scsi_disk *sdkp = to_scsi_disk(dev);
120 struct scsi_device *sdp = sdkp->device; 121 struct scsi_device *sdp = sdkp->device;
121 char buffer[64]; 122 char buffer[64];
122 char *buffer_data; 123 char *buffer_data;
@@ -163,10 +164,11 @@ static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf,
163 return count; 164 return count;
164} 165}
165 166
166static ssize_t sd_store_manage_start_stop(struct class_device *cdev, 167static ssize_t
167 const char *buf, size_t count) 168sd_store_manage_start_stop(struct device *dev, struct device_attribute *attr,
169 const char *buf, size_t count)
168{ 170{
169 struct scsi_disk *sdkp = to_scsi_disk(cdev); 171 struct scsi_disk *sdkp = to_scsi_disk(dev);
170 struct scsi_device *sdp = sdkp->device; 172 struct scsi_device *sdp = sdkp->device;
171 173
172 if (!capable(CAP_SYS_ADMIN)) 174 if (!capable(CAP_SYS_ADMIN))
@@ -177,10 +179,11 @@ static ssize_t sd_store_manage_start_stop(struct class_device *cdev,
177 return count; 179 return count;
178} 180}
179 181
180static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf, 182static ssize_t
181 size_t count) 183sd_store_allow_restart(struct device *dev, struct device_attribute *attr,
184 const char *buf, size_t count)
182{ 185{
183 struct scsi_disk *sdkp = to_scsi_disk(cdev); 186 struct scsi_disk *sdkp = to_scsi_disk(dev);
184 struct scsi_device *sdp = sdkp->device; 187 struct scsi_device *sdp = sdkp->device;
185 188
186 if (!capable(CAP_SYS_ADMIN)) 189 if (!capable(CAP_SYS_ADMIN))
@@ -194,37 +197,44 @@ static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf
194 return count; 197 return count;
195} 198}
196 199
197static ssize_t sd_show_cache_type(struct class_device *cdev, char *buf) 200static ssize_t
201sd_show_cache_type(struct device *dev, struct device_attribute *attr,
202 char *buf)
198{ 203{
199 struct scsi_disk *sdkp = to_scsi_disk(cdev); 204 struct scsi_disk *sdkp = to_scsi_disk(dev);
200 int ct = sdkp->RCD + 2*sdkp->WCE; 205 int ct = sdkp->RCD + 2*sdkp->WCE;
201 206
202 return snprintf(buf, 40, "%s\n", sd_cache_types[ct]); 207 return snprintf(buf, 40, "%s\n", sd_cache_types[ct]);
203} 208}
204 209
205static ssize_t sd_show_fua(struct class_device *cdev, char *buf) 210static ssize_t
211sd_show_fua(struct device *dev, struct device_attribute *attr, char *buf)
206{ 212{
207 struct scsi_disk *sdkp = to_scsi_disk(cdev); 213 struct scsi_disk *sdkp = to_scsi_disk(dev);
208 214
209 return snprintf(buf, 20, "%u\n", sdkp->DPOFUA); 215 return snprintf(buf, 20, "%u\n", sdkp->DPOFUA);
210} 216}
211 217
212static ssize_t sd_show_manage_start_stop(struct class_device *cdev, char *buf) 218static ssize_t
219sd_show_manage_start_stop(struct device *dev, struct device_attribute *attr,
220 char *buf)
213{ 221{
214 struct scsi_disk *sdkp = to_scsi_disk(cdev); 222 struct scsi_disk *sdkp = to_scsi_disk(dev);
215 struct scsi_device *sdp = sdkp->device; 223 struct scsi_device *sdp = sdkp->device;
216 224
217 return snprintf(buf, 20, "%u\n", sdp->manage_start_stop); 225 return snprintf(buf, 20, "%u\n", sdp->manage_start_stop);
218} 226}
219 227
220static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf) 228static ssize_t
229sd_show_allow_restart(struct device *dev, struct device_attribute *attr,
230 char *buf)
221{ 231{
222 struct scsi_disk *sdkp = to_scsi_disk(cdev); 232 struct scsi_disk *sdkp = to_scsi_disk(dev);
223 233
224 return snprintf(buf, 40, "%d\n", sdkp->device->allow_restart); 234 return snprintf(buf, 40, "%d\n", sdkp->device->allow_restart);
225} 235}
226 236
227static struct class_device_attribute sd_disk_attrs[] = { 237static struct device_attribute sd_disk_attrs[] = {
228 __ATTR(cache_type, S_IRUGO|S_IWUSR, sd_show_cache_type, 238 __ATTR(cache_type, S_IRUGO|S_IWUSR, sd_show_cache_type,
229 sd_store_cache_type), 239 sd_store_cache_type),
230 __ATTR(FUA, S_IRUGO, sd_show_fua, NULL), 240 __ATTR(FUA, S_IRUGO, sd_show_fua, NULL),
@@ -238,8 +248,8 @@ static struct class_device_attribute sd_disk_attrs[] = {
238static struct class sd_disk_class = { 248static struct class sd_disk_class = {
239 .name = "scsi_disk", 249 .name = "scsi_disk",
240 .owner = THIS_MODULE, 250 .owner = THIS_MODULE,
241 .release = scsi_disk_release, 251 .dev_release = scsi_disk_release,
242 .class_dev_attrs = sd_disk_attrs, 252 .dev_attrs = sd_disk_attrs,
243}; 253};
244 254
245static struct scsi_driver sd_template = { 255static struct scsi_driver sd_template = {
@@ -297,7 +307,7 @@ static struct scsi_disk *__scsi_disk_get(struct gendisk *disk)
297 if (disk->private_data) { 307 if (disk->private_data) {
298 sdkp = scsi_disk(disk); 308 sdkp = scsi_disk(disk);
299 if (scsi_device_get(sdkp->device) == 0) 309 if (scsi_device_get(sdkp->device) == 0)
300 class_device_get(&sdkp->cdev); 310 get_device(&sdkp->dev);
301 else 311 else
302 sdkp = NULL; 312 sdkp = NULL;
303 } 313 }
@@ -331,7 +341,7 @@ static void scsi_disk_put(struct scsi_disk *sdkp)
331 struct scsi_device *sdev = sdkp->device; 341 struct scsi_device *sdev = sdkp->device;
332 342
333 mutex_lock(&sd_ref_mutex); 343 mutex_lock(&sd_ref_mutex);
334 class_device_put(&sdkp->cdev); 344 put_device(&sdkp->dev);
335 scsi_device_put(sdev); 345 scsi_device_put(sdev);
336 mutex_unlock(&sd_ref_mutex); 346 mutex_unlock(&sd_ref_mutex);
337} 347}
@@ -1663,12 +1673,12 @@ static int sd_probe(struct device *dev)
1663 sdp->timeout = SD_MOD_TIMEOUT; 1673 sdp->timeout = SD_MOD_TIMEOUT;
1664 } 1674 }
1665 1675
1666 class_device_initialize(&sdkp->cdev); 1676 device_initialize(&sdkp->dev);
1667 sdkp->cdev.dev = &sdp->sdev_gendev; 1677 sdkp->dev.parent = &sdp->sdev_gendev;
1668 sdkp->cdev.class = &sd_disk_class; 1678 sdkp->dev.class = &sd_disk_class;
1669 strncpy(sdkp->cdev.class_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE); 1679 strncpy(sdkp->dev.bus_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE);
1670 1680
1671 if (class_device_add(&sdkp->cdev)) 1681 if (device_add(&sdkp->dev))
1672 goto out_put; 1682 goto out_put;
1673 1683
1674 get_device(&sdp->sdev_gendev); 1684 get_device(&sdp->sdev_gendev);
@@ -1734,13 +1744,13 @@ static int sd_remove(struct device *dev)
1734{ 1744{
1735 struct scsi_disk *sdkp = dev_get_drvdata(dev); 1745 struct scsi_disk *sdkp = dev_get_drvdata(dev);
1736 1746
1737 class_device_del(&sdkp->cdev); 1747 device_del(&sdkp->dev);
1738 del_gendisk(sdkp->disk); 1748 del_gendisk(sdkp->disk);
1739 sd_shutdown(dev); 1749 sd_shutdown(dev);
1740 1750
1741 mutex_lock(&sd_ref_mutex); 1751 mutex_lock(&sd_ref_mutex);
1742 dev_set_drvdata(dev, NULL); 1752 dev_set_drvdata(dev, NULL);
1743 class_device_put(&sdkp->cdev); 1753 put_device(&sdkp->dev);
1744 mutex_unlock(&sd_ref_mutex); 1754 mutex_unlock(&sd_ref_mutex);
1745 1755
1746 return 0; 1756 return 0;
@@ -1748,16 +1758,16 @@ static int sd_remove(struct device *dev)
1748 1758
1749/** 1759/**
1750 * scsi_disk_release - Called to free the scsi_disk structure 1760 * scsi_disk_release - Called to free the scsi_disk structure
1751 * @cdev: pointer to embedded class device 1761 * @dev: pointer to embedded class device
1752 * 1762 *
1753 * sd_ref_mutex must be held entering this routine. Because it is 1763 * sd_ref_mutex must be held entering this routine. Because it is
1754 * called on last put, you should always use the scsi_disk_get() 1764 * called on last put, you should always use the scsi_disk_get()
1755 * scsi_disk_put() helpers which manipulate the semaphore directly 1765 * scsi_disk_put() helpers which manipulate the semaphore directly
1756 * and never do a direct class_device_put(). 1766 * and never do a direct put_device.
1757 **/ 1767 **/
1758static void scsi_disk_release(struct class_device *cdev) 1768static void scsi_disk_release(struct device *dev)
1759{ 1769{
1760 struct scsi_disk *sdkp = to_scsi_disk(cdev); 1770 struct scsi_disk *sdkp = to_scsi_disk(dev);
1761 struct gendisk *disk = sdkp->disk; 1771 struct gendisk *disk = sdkp->disk;
1762 1772
1763 spin_lock(&sd_index_lock); 1773 spin_lock(&sd_index_lock);