diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-10 13:52:45 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-10 13:52:45 -0400 |
commit | e26feff647ef34423b048b940540a0059001ddb0 (patch) | |
tree | acafe68602ee2f6f1a438c113073ffcc0040e949 /drivers/scsi/sd.c | |
parent | d403a6484f0341bf0624d17ece46f24f741b6a92 (diff) | |
parent | b911e473d24633c19414b54b82b9ff0b1a2419d7 (diff) |
Merge branch 'for-2.6.28' of git://git.kernel.dk/linux-2.6-block
* 'for-2.6.28' of git://git.kernel.dk/linux-2.6-block: (132 commits)
doc/cdrom: Trvial documentation error, file not present
block_dev: fix kernel-doc in new functions
block: add some comments around the bio read-write flags
block: mark bio_split_pool static
block: Find bio sector offset given idx and offset
block: gendisk integrity wrapper
block: Switch blk_integrity_compare from bdev to gendisk
block: Fix double put in blk_integrity_unregister
block: Introduce integrity data ownership flag
block: revert part of d7533ad0e132f92e75c1b2eb7c26387b25a583c1
bio.h: Remove unused conditional code
block: remove end_{queued|dequeued}_request()
block: change elevator to use __blk_end_request()
gdrom: change to use __blk_end_request()
memstick: change to use __blk_end_request()
virtio_blk: change to use __blk_end_request()
blktrace: use BLKTRACE_BDEV_SIZE as the name size for setup structure
block: add lld busy state exporting interface
block: Fix blk_start_queueing() to not kick a stopped queue
include blktrace_api.h in headers_install
...
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r-- | drivers/scsi/sd.c | 95 |
1 files changed, 67 insertions, 28 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index e5e7d7856454..c0cf4acda7de 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -86,6 +86,12 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_DISK); | |||
86 | MODULE_ALIAS_SCSI_DEVICE(TYPE_MOD); | 86 | MODULE_ALIAS_SCSI_DEVICE(TYPE_MOD); |
87 | MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC); | 87 | MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC); |
88 | 88 | ||
89 | #if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT) | ||
90 | #define SD_MINORS 16 | ||
91 | #else | ||
92 | #define SD_MINORS 0 | ||
93 | #endif | ||
94 | |||
89 | static int sd_revalidate_disk(struct gendisk *); | 95 | static int sd_revalidate_disk(struct gendisk *); |
90 | static int sd_probe(struct device *); | 96 | static int sd_probe(struct device *); |
91 | static int sd_remove(struct device *); | 97 | static int sd_remove(struct device *); |
@@ -159,7 +165,7 @@ sd_store_cache_type(struct device *dev, struct device_attribute *attr, | |||
159 | sd_print_sense_hdr(sdkp, &sshdr); | 165 | sd_print_sense_hdr(sdkp, &sshdr); |
160 | return -EINVAL; | 166 | return -EINVAL; |
161 | } | 167 | } |
162 | sd_revalidate_disk(sdkp->disk); | 168 | revalidate_disk(sdkp->disk); |
163 | return count; | 169 | return count; |
164 | } | 170 | } |
165 | 171 | ||
@@ -377,7 +383,6 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq) | |||
377 | sector_t block = rq->sector; | 383 | sector_t block = rq->sector; |
378 | sector_t threshold; | 384 | sector_t threshold; |
379 | unsigned int this_count = rq->nr_sectors; | 385 | unsigned int this_count = rq->nr_sectors; |
380 | unsigned int timeout = sdp->timeout; | ||
381 | int ret; | 386 | int ret; |
382 | 387 | ||
383 | if (rq->cmd_type == REQ_TYPE_BLOCK_PC) { | 388 | if (rq->cmd_type == REQ_TYPE_BLOCK_PC) { |
@@ -578,7 +583,6 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq) | |||
578 | SCpnt->transfersize = sdp->sector_size; | 583 | SCpnt->transfersize = sdp->sector_size; |
579 | SCpnt->underflow = this_count << 9; | 584 | SCpnt->underflow = this_count << 9; |
580 | SCpnt->allowed = SD_MAX_RETRIES; | 585 | SCpnt->allowed = SD_MAX_RETRIES; |
581 | SCpnt->timeout_per_command = timeout; | ||
582 | 586 | ||
583 | /* | 587 | /* |
584 | * This indicates that the command is ready from our end to be | 588 | * This indicates that the command is ready from our end to be |
@@ -910,7 +914,7 @@ static void sd_rescan(struct device *dev) | |||
910 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); | 914 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); |
911 | 915 | ||
912 | if (sdkp) { | 916 | if (sdkp) { |
913 | sd_revalidate_disk(sdkp->disk); | 917 | revalidate_disk(sdkp->disk); |
914 | scsi_disk_put(sdkp); | 918 | scsi_disk_put(sdkp); |
915 | } | 919 | } |
916 | } | 920 | } |
@@ -1764,6 +1768,52 @@ static int sd_revalidate_disk(struct gendisk *disk) | |||
1764 | } | 1768 | } |
1765 | 1769 | ||
1766 | /** | 1770 | /** |
1771 | * sd_format_disk_name - format disk name | ||
1772 | * @prefix: name prefix - ie. "sd" for SCSI disks | ||
1773 | * @index: index of the disk to format name for | ||
1774 | * @buf: output buffer | ||
1775 | * @buflen: length of the output buffer | ||
1776 | * | ||
1777 | * SCSI disk names starts at sda. The 26th device is sdz and the | ||
1778 | * 27th is sdaa. The last one for two lettered suffix is sdzz | ||
1779 | * which is followed by sdaaa. | ||
1780 | * | ||
1781 | * This is basically 26 base counting with one extra 'nil' entry | ||
1782 | * at the beggining from the second digit on and can be | ||
1783 | * determined using similar method as 26 base conversion with the | ||
1784 | * index shifted -1 after each digit is computed. | ||
1785 | * | ||
1786 | * CONTEXT: | ||
1787 | * Don't care. | ||
1788 | * | ||
1789 | * RETURNS: | ||
1790 | * 0 on success, -errno on failure. | ||
1791 | */ | ||
1792 | static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen) | ||
1793 | { | ||
1794 | const int base = 'z' - 'a' + 1; | ||
1795 | char *begin = buf + strlen(prefix); | ||
1796 | char *end = buf + buflen; | ||
1797 | char *p; | ||
1798 | int unit; | ||
1799 | |||
1800 | p = end - 1; | ||
1801 | *p = '\0'; | ||
1802 | unit = base; | ||
1803 | do { | ||
1804 | if (p == begin) | ||
1805 | return -EINVAL; | ||
1806 | *--p = 'a' + (index % unit); | ||
1807 | index = (index / unit) - 1; | ||
1808 | } while (index >= 0); | ||
1809 | |||
1810 | memmove(begin, p, end - p); | ||
1811 | memcpy(buf, prefix, strlen(prefix)); | ||
1812 | |||
1813 | return 0; | ||
1814 | } | ||
1815 | |||
1816 | /** | ||
1767 | * sd_probe - called during driver initialization and whenever a | 1817 | * sd_probe - called during driver initialization and whenever a |
1768 | * new scsi device is attached to the system. It is called once | 1818 | * new scsi device is attached to the system. It is called once |
1769 | * for each scsi device (not just disks) present. | 1819 | * for each scsi device (not just disks) present. |
@@ -1801,7 +1851,7 @@ static int sd_probe(struct device *dev) | |||
1801 | if (!sdkp) | 1851 | if (!sdkp) |
1802 | goto out; | 1852 | goto out; |
1803 | 1853 | ||
1804 | gd = alloc_disk(16); | 1854 | gd = alloc_disk(SD_MINORS); |
1805 | if (!gd) | 1855 | if (!gd) |
1806 | goto out_free; | 1856 | goto out_free; |
1807 | 1857 | ||
@@ -1815,8 +1865,8 @@ static int sd_probe(struct device *dev) | |||
1815 | if (error) | 1865 | if (error) |
1816 | goto out_put; | 1866 | goto out_put; |
1817 | 1867 | ||
1818 | error = -EBUSY; | 1868 | error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN); |
1819 | if (index >= SD_MAX_DISKS) | 1869 | if (error) |
1820 | goto out_free_index; | 1870 | goto out_free_index; |
1821 | 1871 | ||
1822 | sdkp->device = sdp; | 1872 | sdkp->device = sdp; |
@@ -1826,11 +1876,12 @@ static int sd_probe(struct device *dev) | |||
1826 | sdkp->openers = 0; | 1876 | sdkp->openers = 0; |
1827 | sdkp->previous_state = 1; | 1877 | sdkp->previous_state = 1; |
1828 | 1878 | ||
1829 | if (!sdp->timeout) { | 1879 | if (!sdp->request_queue->rq_timeout) { |
1830 | if (sdp->type != TYPE_MOD) | 1880 | if (sdp->type != TYPE_MOD) |
1831 | sdp->timeout = SD_TIMEOUT; | 1881 | blk_queue_rq_timeout(sdp->request_queue, SD_TIMEOUT); |
1832 | else | 1882 | else |
1833 | sdp->timeout = SD_MOD_TIMEOUT; | 1883 | blk_queue_rq_timeout(sdp->request_queue, |
1884 | SD_MOD_TIMEOUT); | ||
1834 | } | 1885 | } |
1835 | 1886 | ||
1836 | device_initialize(&sdkp->dev); | 1887 | device_initialize(&sdkp->dev); |
@@ -1843,24 +1894,12 @@ static int sd_probe(struct device *dev) | |||
1843 | 1894 | ||
1844 | get_device(&sdp->sdev_gendev); | 1895 | get_device(&sdp->sdev_gendev); |
1845 | 1896 | ||
1846 | gd->major = sd_major((index & 0xf0) >> 4); | 1897 | if (index < SD_MAX_DISKS) { |
1847 | gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); | 1898 | gd->major = sd_major((index & 0xf0) >> 4); |
1848 | gd->minors = 16; | 1899 | gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); |
1849 | gd->fops = &sd_fops; | 1900 | gd->minors = SD_MINORS; |
1850 | |||
1851 | if (index < 26) { | ||
1852 | sprintf(gd->disk_name, "sd%c", 'a' + index % 26); | ||
1853 | } else if (index < (26 + 1) * 26) { | ||
1854 | sprintf(gd->disk_name, "sd%c%c", | ||
1855 | 'a' + index / 26 - 1,'a' + index % 26); | ||
1856 | } else { | ||
1857 | const unsigned int m1 = (index / 26 - 1) / 26 - 1; | ||
1858 | const unsigned int m2 = (index / 26 - 1) % 26; | ||
1859 | const unsigned int m3 = index % 26; | ||
1860 | sprintf(gd->disk_name, "sd%c%c%c", | ||
1861 | 'a' + m1, 'a' + m2, 'a' + m3); | ||
1862 | } | 1901 | } |
1863 | 1902 | gd->fops = &sd_fops; | |
1864 | gd->private_data = &sdkp->driver; | 1903 | gd->private_data = &sdkp->driver; |
1865 | gd->queue = sdkp->device->request_queue; | 1904 | gd->queue = sdkp->device->request_queue; |
1866 | 1905 | ||
@@ -1869,7 +1908,7 @@ static int sd_probe(struct device *dev) | |||
1869 | blk_queue_prep_rq(sdp->request_queue, sd_prep_fn); | 1908 | blk_queue_prep_rq(sdp->request_queue, sd_prep_fn); |
1870 | 1909 | ||
1871 | gd->driverfs_dev = &sdp->sdev_gendev; | 1910 | gd->driverfs_dev = &sdp->sdev_gendev; |
1872 | gd->flags = GENHD_FL_DRIVERFS; | 1911 | gd->flags = GENHD_FL_EXT_DEVT | GENHD_FL_DRIVERFS; |
1873 | if (sdp->removable) | 1912 | if (sdp->removable) |
1874 | gd->flags |= GENHD_FL_REMOVABLE; | 1913 | gd->flags |= GENHD_FL_REMOVABLE; |
1875 | 1914 | ||