aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/DAC960.c11
-rw-r--r--drivers/block/Kconfig17
-rw-r--r--drivers/block/Makefile1
-rw-r--r--drivers/block/amiflop.c19
-rw-r--r--drivers/block/aoe/aoeblk.c9
-rw-r--r--drivers/block/aoe/aoechr.c9
-rw-r--r--drivers/block/ataflop.c15
-rw-r--r--drivers/block/brd.c7
-rw-r--r--drivers/block/cciss.c16
-rw-r--r--drivers/block/cpqarray.c15
-rw-r--r--drivers/block/drbd/drbd_main.c11
-rw-r--r--drivers/block/floppy.c16
-rw-r--r--drivers/block/loop.c11
-rw-r--r--drivers/block/nbd.c7
-rw-r--r--drivers/block/paride/pcd.c15
-rw-r--r--drivers/block/paride/pd.c15
-rw-r--r--drivers/block/paride/pf.c17
-rw-r--r--drivers/block/paride/pg.c7
-rw-r--r--drivers/block/paride/pt.c19
-rw-r--r--drivers/block/pktcdvd.c18
-rw-r--r--drivers/block/ps3disk.c2
-rw-r--r--drivers/block/rbd.c1841
-rw-r--r--drivers/block/rbd_types.h73
-rw-r--r--drivers/block/swim.c15
-rw-r--r--drivers/block/swim3.c15
-rw-r--r--drivers/block/ub.c15
-rw-r--r--drivers/block/viodasd.c11
-rw-r--r--drivers/block/virtio_blk.c23
-rw-r--r--drivers/block/xd.c7
-rw-r--r--drivers/block/xen-blkfront.c11
-rw-r--r--drivers/block/xsysace.c11
-rw-r--r--drivers/block/z2ram.c15
32 files changed, 2120 insertions, 174 deletions
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index dfcb33e8d405..1f286ab461d3 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -36,7 +36,7 @@
36#include <linux/ioport.h> 36#include <linux/ioport.h>
37#include <linux/mm.h> 37#include <linux/mm.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/smp_lock.h> 39#include <linux/mutex.h>
40#include <linux/proc_fs.h> 40#include <linux/proc_fs.h>
41#include <linux/seq_file.h> 41#include <linux/seq_file.h>
42#include <linux/reboot.h> 42#include <linux/reboot.h>
@@ -54,6 +54,7 @@
54#define DAC960_GAM_MINOR 252 54#define DAC960_GAM_MINOR 252
55 55
56 56
57static DEFINE_MUTEX(DAC960_mutex);
57static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers]; 58static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];
58static int DAC960_ControllerCount; 59static int DAC960_ControllerCount;
59static struct proc_dir_entry *DAC960_ProcDirectoryEntry; 60static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
@@ -81,7 +82,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
81 int drive_nr = (long)disk->private_data; 82 int drive_nr = (long)disk->private_data;
82 int ret = -ENXIO; 83 int ret = -ENXIO;
83 84
84 lock_kernel(); 85 mutex_lock(&DAC960_mutex);
85 if (p->FirmwareType == DAC960_V1_Controller) { 86 if (p->FirmwareType == DAC960_V1_Controller) {
86 if (p->V1.LogicalDriveInformation[drive_nr]. 87 if (p->V1.LogicalDriveInformation[drive_nr].
87 LogicalDriveState == DAC960_V1_LogicalDrive_Offline) 88 LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
@@ -99,7 +100,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
99 goto out; 100 goto out;
100 ret = 0; 101 ret = 0;
101out: 102out:
102 unlock_kernel(); 103 mutex_unlock(&DAC960_mutex);
103 return ret; 104 return ret;
104} 105}
105 106
@@ -6625,7 +6626,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
6625 long ErrorCode = 0; 6626 long ErrorCode = 0;
6626 if (!capable(CAP_SYS_ADMIN)) return -EACCES; 6627 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
6627 6628
6628 lock_kernel(); 6629 mutex_lock(&DAC960_mutex);
6629 switch (Request) 6630 switch (Request)
6630 { 6631 {
6631 case DAC960_IOCTL_GET_CONTROLLER_COUNT: 6632 case DAC960_IOCTL_GET_CONTROLLER_COUNT:
@@ -7056,7 +7057,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
7056 default: 7057 default:
7057 ErrorCode = -ENOTTY; 7058 ErrorCode = -ENOTTY;
7058 } 7059 }
7059 unlock_kernel(); 7060 mutex_unlock(&DAC960_mutex);
7060 return ErrorCode; 7061 return ErrorCode;
7061} 7062}
7062 7063
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index de277689da61..4b9359a6f6ca 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -488,4 +488,21 @@ config BLK_DEV_HD
488 488
489 If unsure, say N. 489 If unsure, say N.
490 490
491config BLK_DEV_RBD
492 tristate "Rados block device (RBD)"
493 depends on INET && EXPERIMENTAL && BLOCK
494 select CEPH_LIB
495 select LIBCRC32C
496 select CRYPTO_AES
497 select CRYPTO
498 default n
499 help
500 Say Y here if you want include the Rados block device, which stripes
501 a block device over objects stored in the Ceph distributed object
502 store.
503
504 More information at http://ceph.newdream.net/.
505
506 If unsure, say N.
507
491endif # BLK_DEV 508endif # BLK_DEV
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index aff5ac925c34..d7f463d6312d 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -37,5 +37,6 @@ obj-$(CONFIG_BLK_DEV_HD) += hd.o
37 37
38obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o 38obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
39obj-$(CONFIG_BLK_DEV_DRBD) += drbd/ 39obj-$(CONFIG_BLK_DEV_DRBD) += drbd/
40obj-$(CONFIG_BLK_DEV_RBD) += rbd.o
40 41
41swim_mod-objs := swim.o swim_asm.o 42swim_mod-objs := swim.o swim_asm.o
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 76f114f0bba3..4b852c962266 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -60,7 +60,7 @@
60#include <linux/hdreg.h> 60#include <linux/hdreg.h>
61#include <linux/delay.h> 61#include <linux/delay.h>
62#include <linux/init.h> 62#include <linux/init.h>
63#include <linux/smp_lock.h> 63#include <linux/mutex.h>
64#include <linux/amifdreg.h> 64#include <linux/amifdreg.h>
65#include <linux/amifd.h> 65#include <linux/amifd.h>
66#include <linux/buffer_head.h> 66#include <linux/buffer_head.h>
@@ -109,6 +109,7 @@
109#define FD_HD_3 0x55555555 /* high-density 3.5" (1760K) drive */ 109#define FD_HD_3 0x55555555 /* high-density 3.5" (1760K) drive */
110#define FD_DD_5 0xaaaaaaaa /* double-density 5.25" (440K) drive */ 110#define FD_DD_5 0xaaaaaaaa /* double-density 5.25" (440K) drive */
111 111
112static DEFINE_MUTEX(amiflop_mutex);
112static unsigned long int fd_def_df0 = FD_DD_3; /* default for df0 if it doesn't identify */ 113static unsigned long int fd_def_df0 = FD_DD_3; /* default for df0 if it doesn't identify */
113 114
114module_param(fd_def_df0, ulong, 0); 115module_param(fd_def_df0, ulong, 0);
@@ -1506,9 +1507,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1506{ 1507{
1507 int ret; 1508 int ret;
1508 1509
1509 lock_kernel(); 1510 mutex_lock(&amiflop_mutex);
1510 ret = fd_locked_ioctl(bdev, mode, cmd, param); 1511 ret = fd_locked_ioctl(bdev, mode, cmd, param);
1511 unlock_kernel(); 1512 mutex_unlock(&amiflop_mutex);
1512 1513
1513 return ret; 1514 return ret;
1514} 1515}
@@ -1555,11 +1556,11 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1555 int old_dev; 1556 int old_dev;
1556 unsigned long flags; 1557 unsigned long flags;
1557 1558
1558 lock_kernel(); 1559 mutex_lock(&amiflop_mutex);
1559 old_dev = fd_device[drive]; 1560 old_dev = fd_device[drive];
1560 1561
1561 if (fd_ref[drive] && old_dev != system) { 1562 if (fd_ref[drive] && old_dev != system) {
1562 unlock_kernel(); 1563 mutex_unlock(&amiflop_mutex);
1563 return -EBUSY; 1564 return -EBUSY;
1564 } 1565 }
1565 1566
@@ -1575,7 +1576,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1575 rel_fdc(); 1576 rel_fdc();
1576 1577
1577 if (wrprot) { 1578 if (wrprot) {
1578 unlock_kernel(); 1579 mutex_unlock(&amiflop_mutex);
1579 return -EROFS; 1580 return -EROFS;
1580 } 1581 }
1581 } 1582 }
@@ -1594,7 +1595,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1594 printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive, 1595 printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive,
1595 unit[drive].type->name, data_types[system].name); 1596 unit[drive].type->name, data_types[system].name);
1596 1597
1597 unlock_kernel(); 1598 mutex_unlock(&amiflop_mutex);
1598 return 0; 1599 return 0;
1599} 1600}
1600 1601
@@ -1603,7 +1604,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
1603 struct amiga_floppy_struct *p = disk->private_data; 1604 struct amiga_floppy_struct *p = disk->private_data;
1604 int drive = p - unit; 1605 int drive = p - unit;
1605 1606
1606 lock_kernel(); 1607 mutex_lock(&amiflop_mutex);
1607 if (unit[drive].dirty == 1) { 1608 if (unit[drive].dirty == 1) {
1608 del_timer (flush_track_timer + drive); 1609 del_timer (flush_track_timer + drive);
1609 non_int_flush_track (drive); 1610 non_int_flush_track (drive);
@@ -1617,7 +1618,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
1617/* the mod_use counter is handled this way */ 1618/* the mod_use counter is handled this way */
1618 floppy_off (drive | 0x40000000); 1619 floppy_off (drive | 0x40000000);
1619#endif 1620#endif
1620 unlock_kernel(); 1621 mutex_unlock(&amiflop_mutex);
1621 return 0; 1622 return 0;
1622} 1623}
1623 1624
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index a946929735a5..f21c237a9e5e 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -12,9 +12,10 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/genhd.h> 13#include <linux/genhd.h>
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/smp_lock.h> 15#include <linux/mutex.h>
16#include "aoe.h" 16#include "aoe.h"
17 17
18static DEFINE_MUTEX(aoeblk_mutex);
18static struct kmem_cache *buf_pool_cache; 19static struct kmem_cache *buf_pool_cache;
19 20
20static ssize_t aoedisk_show_state(struct device *dev, 21static ssize_t aoedisk_show_state(struct device *dev,
@@ -125,16 +126,16 @@ aoeblk_open(struct block_device *bdev, fmode_t mode)
125 struct aoedev *d = bdev->bd_disk->private_data; 126 struct aoedev *d = bdev->bd_disk->private_data;
126 ulong flags; 127 ulong flags;
127 128
128 lock_kernel(); 129 mutex_lock(&aoeblk_mutex);
129 spin_lock_irqsave(&d->lock, flags); 130 spin_lock_irqsave(&d->lock, flags);
130 if (d->flags & DEVFL_UP) { 131 if (d->flags & DEVFL_UP) {
131 d->nopen++; 132 d->nopen++;
132 spin_unlock_irqrestore(&d->lock, flags); 133 spin_unlock_irqrestore(&d->lock, flags);
133 unlock_kernel(); 134 mutex_unlock(&aoeblk_mutex);
134 return 0; 135 return 0;
135 } 136 }
136 spin_unlock_irqrestore(&d->lock, flags); 137 spin_unlock_irqrestore(&d->lock, flags);
137 unlock_kernel(); 138 mutex_unlock(&aoeblk_mutex);
138 return -ENODEV; 139 return -ENODEV;
139} 140}
140 141
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 32b484ba21bd..146296ca4965 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -9,7 +9,7 @@
9#include <linux/completion.h> 9#include <linux/completion.h>
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/smp_lock.h> 12#include <linux/mutex.h>
13#include <linux/skbuff.h> 13#include <linux/skbuff.h>
14#include "aoe.h" 14#include "aoe.h"
15 15
@@ -37,6 +37,7 @@ struct ErrMsg {
37 char *msg; 37 char *msg;
38}; 38};
39 39
40static DEFINE_MUTEX(aoechr_mutex);
40static struct ErrMsg emsgs[NMSG]; 41static struct ErrMsg emsgs[NMSG];
41static int emsgs_head_idx, emsgs_tail_idx; 42static int emsgs_head_idx, emsgs_tail_idx;
42static struct completion emsgs_comp; 43static struct completion emsgs_comp;
@@ -183,16 +184,16 @@ aoechr_open(struct inode *inode, struct file *filp)
183{ 184{
184 int n, i; 185 int n, i;
185 186
186 lock_kernel(); 187 mutex_lock(&aoechr_mutex);
187 n = iminor(inode); 188 n = iminor(inode);
188 filp->private_data = (void *) (unsigned long) n; 189 filp->private_data = (void *) (unsigned long) n;
189 190
190 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 191 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
191 if (chardevs[i].minor == n) { 192 if (chardevs[i].minor == n) {
192 unlock_kernel(); 193 mutex_unlock(&aoechr_mutex);
193 return 0; 194 return 0;
194 } 195 }
195 unlock_kernel(); 196 mutex_unlock(&aoechr_mutex);
196 return -EINVAL; 197 return -EINVAL;
197} 198}
198 199
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index aceb96476524..8c021bb7a991 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -67,7 +67,7 @@
67#include <linux/delay.h> 67#include <linux/delay.h>
68#include <linux/init.h> 68#include <linux/init.h>
69#include <linux/blkdev.h> 69#include <linux/blkdev.h>
70#include <linux/smp_lock.h> 70#include <linux/mutex.h>
71 71
72#include <asm/atafd.h> 72#include <asm/atafd.h>
73#include <asm/atafdreg.h> 73#include <asm/atafdreg.h>
@@ -79,6 +79,7 @@
79 79
80#undef DEBUG 80#undef DEBUG
81 81
82static DEFINE_MUTEX(ataflop_mutex);
82static struct request_queue *floppy_queue; 83static struct request_queue *floppy_queue;
83static struct request *fd_request; 84static struct request *fd_request;
84 85
@@ -1671,9 +1672,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1671{ 1672{
1672 int ret; 1673 int ret;
1673 1674
1674 lock_kernel(); 1675 mutex_lock(&ataflop_mutex);
1675 ret = fd_locked_ioctl(bdev, mode, cmd, arg); 1676 ret = fd_locked_ioctl(bdev, mode, cmd, arg);
1676 unlock_kernel(); 1677 mutex_unlock(&ataflop_mutex);
1677 1678
1678 return ret; 1679 return ret;
1679} 1680}
@@ -1854,9 +1855,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
1854{ 1855{
1855 int ret; 1856 int ret;
1856 1857
1857 lock_kernel(); 1858 mutex_lock(&ataflop_mutex);
1858 ret = floppy_open(bdev, mode); 1859 ret = floppy_open(bdev, mode);
1859 unlock_kernel(); 1860 mutex_unlock(&ataflop_mutex);
1860 1861
1861 return ret; 1862 return ret;
1862} 1863}
@@ -1864,14 +1865,14 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
1864static int floppy_release(struct gendisk *disk, fmode_t mode) 1865static int floppy_release(struct gendisk *disk, fmode_t mode)
1865{ 1866{
1866 struct atari_floppy_struct *p = disk->private_data; 1867 struct atari_floppy_struct *p = disk->private_data;
1867 lock_kernel(); 1868 mutex_lock(&ataflop_mutex);
1868 if (p->ref < 0) 1869 if (p->ref < 0)
1869 p->ref = 0; 1870 p->ref = 0;
1870 else if (!p->ref--) { 1871 else if (!p->ref--) {
1871 printk(KERN_ERR "floppy_release with fd_ref == 0"); 1872 printk(KERN_ERR "floppy_release with fd_ref == 0");
1872 p->ref = 0; 1873 p->ref = 0;
1873 } 1874 }
1874 unlock_kernel(); 1875 mutex_unlock(&ataflop_mutex);
1875 return 0; 1876 return 0;
1876} 1877}
1877 1878
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 1c7f63792ff8..82bfd5bb4a97 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -15,7 +15,7 @@
15#include <linux/blkdev.h> 15#include <linux/blkdev.h>
16#include <linux/bio.h> 16#include <linux/bio.h>
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/smp_lock.h> 18#include <linux/mutex.h>
19#include <linux/radix-tree.h> 19#include <linux/radix-tree.h>
20#include <linux/buffer_head.h> /* invalidate_bh_lrus() */ 20#include <linux/buffer_head.h> /* invalidate_bh_lrus() */
21#include <linux/slab.h> 21#include <linux/slab.h>
@@ -55,6 +55,7 @@ struct brd_device {
55/* 55/*
56 * Look up and return a brd's page for a given sector. 56 * Look up and return a brd's page for a given sector.
57 */ 57 */
58static DEFINE_MUTEX(brd_mutex);
58static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector) 59static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)
59{ 60{
60 pgoff_t idx; 61 pgoff_t idx;
@@ -402,7 +403,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
402 * ram device BLKFLSBUF has special semantics, we want to actually 403 * ram device BLKFLSBUF has special semantics, we want to actually
403 * release and destroy the ramdisk data. 404 * release and destroy the ramdisk data.
404 */ 405 */
405 lock_kernel(); 406 mutex_lock(&brd_mutex);
406 mutex_lock(&bdev->bd_mutex); 407 mutex_lock(&bdev->bd_mutex);
407 error = -EBUSY; 408 error = -EBUSY;
408 if (bdev->bd_openers <= 1) { 409 if (bdev->bd_openers <= 1) {
@@ -419,7 +420,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
419 error = 0; 420 error = 0;
420 } 421 }
421 mutex_unlock(&bdev->bd_mutex); 422 mutex_unlock(&bdev->bd_mutex);
422 unlock_kernel(); 423 mutex_unlock(&brd_mutex);
423 424
424 return error; 425 return error;
425} 426}
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 6124c2fd2d33..c484c96e22a6 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -26,7 +26,6 @@
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/smp_lock.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <linux/major.h> 30#include <linux/major.h>
32#include <linux/fs.h> 31#include <linux/fs.h>
@@ -66,6 +65,7 @@ MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");
66MODULE_VERSION("3.6.26"); 65MODULE_VERSION("3.6.26");
67MODULE_LICENSE("GPL"); 66MODULE_LICENSE("GPL");
68 67
68static DEFINE_MUTEX(cciss_mutex);
69static int cciss_allow_hpsa; 69static int cciss_allow_hpsa;
70module_param(cciss_allow_hpsa, int, S_IRUGO|S_IWUSR); 70module_param(cciss_allow_hpsa, int, S_IRUGO|S_IWUSR);
71MODULE_PARM_DESC(cciss_allow_hpsa, 71MODULE_PARM_DESC(cciss_allow_hpsa,
@@ -1059,9 +1059,9 @@ static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode)
1059{ 1059{
1060 int ret; 1060 int ret;
1061 1061
1062 lock_kernel(); 1062 mutex_lock(&cciss_mutex);
1063 ret = cciss_open(bdev, mode); 1063 ret = cciss_open(bdev, mode);
1064 unlock_kernel(); 1064 mutex_unlock(&cciss_mutex);
1065 1065
1066 return ret; 1066 return ret;
1067} 1067}
@@ -1074,13 +1074,13 @@ static int cciss_release(struct gendisk *disk, fmode_t mode)
1074 ctlr_info_t *h; 1074 ctlr_info_t *h;
1075 drive_info_struct *drv; 1075 drive_info_struct *drv;
1076 1076
1077 lock_kernel(); 1077 mutex_lock(&cciss_mutex);
1078 h = get_host(disk); 1078 h = get_host(disk);
1079 drv = get_drv(disk); 1079 drv = get_drv(disk);
1080 dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name); 1080 dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name);
1081 drv->usage_count--; 1081 drv->usage_count--;
1082 h->usage_count--; 1082 h->usage_count--;
1083 unlock_kernel(); 1083 mutex_unlock(&cciss_mutex);
1084 return 0; 1084 return 0;
1085} 1085}
1086 1086
@@ -1088,9 +1088,9 @@ static int do_ioctl(struct block_device *bdev, fmode_t mode,
1088 unsigned cmd, unsigned long arg) 1088 unsigned cmd, unsigned long arg)
1089{ 1089{
1090 int ret; 1090 int ret;
1091 lock_kernel(); 1091 mutex_lock(&cciss_mutex);
1092 ret = cciss_ioctl(bdev, mode, cmd, arg); 1092 ret = cciss_ioctl(bdev, mode, cmd, arg);
1093 unlock_kernel(); 1093 mutex_unlock(&cciss_mutex);
1094 return ret; 1094 return ret;
1095} 1095}
1096 1096
@@ -4792,7 +4792,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4792clean4: 4792clean4:
4793 kfree(h->cmd_pool_bits); 4793 kfree(h->cmd_pool_bits);
4794 /* Free up sg elements */ 4794 /* Free up sg elements */
4795 for (k = 0; k < h->nr_cmds; k++) 4795 for (k-- ; k >= 0; k--)
4796 kfree(h->scatter_list[k]); 4796 kfree(h->scatter_list[k]);
4797 kfree(h->scatter_list); 4797 kfree(h->scatter_list);
4798 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds); 4798 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index d53b0291c44b..946dad4caef3 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -35,7 +35,7 @@
35#include <linux/seq_file.h> 35#include <linux/seq_file.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/hdreg.h> 37#include <linux/hdreg.h>
38#include <linux/smp_lock.h> 38#include <linux/mutex.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/blkdev.h> 40#include <linux/blkdev.h>
41#include <linux/genhd.h> 41#include <linux/genhd.h>
@@ -68,6 +68,7 @@ MODULE_LICENSE("GPL");
68 68
69#define CPQARRAY_DMA_MASK 0xFFFFFFFF /* 32 bit DMA */ 69#define CPQARRAY_DMA_MASK 0xFFFFFFFF /* 32 bit DMA */
70 70
71static DEFINE_MUTEX(cpqarray_mutex);
71static int nr_ctlr; 72static int nr_ctlr;
72static ctlr_info_t *hba[MAX_CTLR]; 73static ctlr_info_t *hba[MAX_CTLR];
73 74
@@ -845,9 +846,9 @@ static int ida_unlocked_open(struct block_device *bdev, fmode_t mode)
845{ 846{
846 int ret; 847 int ret;
847 848
848 lock_kernel(); 849 mutex_lock(&cpqarray_mutex);
849 ret = ida_open(bdev, mode); 850 ret = ida_open(bdev, mode);
850 unlock_kernel(); 851 mutex_unlock(&cpqarray_mutex);
851 852
852 return ret; 853 return ret;
853} 854}
@@ -859,10 +860,10 @@ static int ida_release(struct gendisk *disk, fmode_t mode)
859{ 860{
860 ctlr_info_t *host; 861 ctlr_info_t *host;
861 862
862 lock_kernel(); 863 mutex_lock(&cpqarray_mutex);
863 host = get_host(disk); 864 host = get_host(disk);
864 host->usage_count--; 865 host->usage_count--;
865 unlock_kernel(); 866 mutex_unlock(&cpqarray_mutex);
866 867
867 return 0; 868 return 0;
868} 869}
@@ -1217,9 +1218,9 @@ static int ida_ioctl(struct block_device *bdev, fmode_t mode,
1217{ 1218{
1218 int ret; 1219 int ret;
1219 1220
1220 lock_kernel(); 1221 mutex_lock(&cpqarray_mutex);
1221 ret = ida_locked_ioctl(bdev, mode, cmd, param); 1222 ret = ida_locked_ioctl(bdev, mode, cmd, param);
1222 unlock_kernel(); 1223 mutex_unlock(&cpqarray_mutex);
1223 1224
1224 return ret; 1225 return ret;
1225} 1226}
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index fa650dd85b90..e4b56119866e 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -32,7 +32,7 @@
32#include <asm/types.h> 32#include <asm/types.h>
33#include <net/sock.h> 33#include <net/sock.h>
34#include <linux/ctype.h> 34#include <linux/ctype.h>
35#include <linux/smp_lock.h> 35#include <linux/mutex.h>
36#include <linux/fs.h> 36#include <linux/fs.h>
37#include <linux/file.h> 37#include <linux/file.h>
38#include <linux/proc_fs.h> 38#include <linux/proc_fs.h>
@@ -64,6 +64,7 @@ struct after_state_chg_work {
64 struct completion *done; 64 struct completion *done;
65}; 65};
66 66
67static DEFINE_MUTEX(drbd_main_mutex);
67int drbdd_init(struct drbd_thread *); 68int drbdd_init(struct drbd_thread *);
68int drbd_worker(struct drbd_thread *); 69int drbd_worker(struct drbd_thread *);
69int drbd_asender(struct drbd_thread *); 70int drbd_asender(struct drbd_thread *);
@@ -2536,7 +2537,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2536 unsigned long flags; 2537 unsigned long flags;
2537 int rv = 0; 2538 int rv = 0;
2538 2539
2539 lock_kernel(); 2540 mutex_lock(&drbd_main_mutex);
2540 spin_lock_irqsave(&mdev->req_lock, flags); 2541 spin_lock_irqsave(&mdev->req_lock, flags);
2541 /* to have a stable mdev->state.role 2542 /* to have a stable mdev->state.role
2542 * and no race with updating open_cnt */ 2543 * and no race with updating open_cnt */
@@ -2551,7 +2552,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2551 if (!rv) 2552 if (!rv)
2552 mdev->open_cnt++; 2553 mdev->open_cnt++;
2553 spin_unlock_irqrestore(&mdev->req_lock, flags); 2554 spin_unlock_irqrestore(&mdev->req_lock, flags);
2554 unlock_kernel(); 2555 mutex_unlock(&drbd_main_mutex);
2555 2556
2556 return rv; 2557 return rv;
2557} 2558}
@@ -2559,9 +2560,9 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2559static int drbd_release(struct gendisk *gd, fmode_t mode) 2560static int drbd_release(struct gendisk *gd, fmode_t mode)
2560{ 2561{
2561 struct drbd_conf *mdev = gd->private_data; 2562 struct drbd_conf *mdev = gd->private_data;
2562 lock_kernel(); 2563 mutex_lock(&drbd_main_mutex);
2563 mdev->open_cnt--; 2564 mdev->open_cnt--;
2564 unlock_kernel(); 2565 mutex_unlock(&drbd_main_mutex);
2565 return 0; 2566 return 0;
2566} 2567}
2567 2568
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index cf04c1b234ed..3b57459bb745 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -178,7 +178,6 @@ static int print_unex = 1;
178#include <linux/slab.h> 178#include <linux/slab.h>
179#include <linux/mm.h> 179#include <linux/mm.h>
180#include <linux/bio.h> 180#include <linux/bio.h>
181#include <linux/smp_lock.h>
182#include <linux/string.h> 181#include <linux/string.h>
183#include <linux/jiffies.h> 182#include <linux/jiffies.h>
184#include <linux/fcntl.h> 183#include <linux/fcntl.h>
@@ -199,6 +198,7 @@ static int print_unex = 1;
199 * It's been recommended that take about 1/4 of the default speed 198 * It's been recommended that take about 1/4 of the default speed
200 * in some more extreme cases. 199 * in some more extreme cases.
201 */ 200 */
201static DEFINE_MUTEX(floppy_mutex);
202static int slow_floppy; 202static int slow_floppy;
203 203
204#include <asm/dma.h> 204#include <asm/dma.h>
@@ -3553,9 +3553,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
3553{ 3553{
3554 int ret; 3554 int ret;
3555 3555
3556 lock_kernel(); 3556 mutex_lock(&floppy_mutex);
3557 ret = fd_locked_ioctl(bdev, mode, cmd, param); 3557 ret = fd_locked_ioctl(bdev, mode, cmd, param);
3558 unlock_kernel(); 3558 mutex_unlock(&floppy_mutex);
3559 3559
3560 return ret; 3560 return ret;
3561} 3561}
@@ -3616,7 +3616,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
3616{ 3616{
3617 int drive = (long)disk->private_data; 3617 int drive = (long)disk->private_data;
3618 3618
3619 lock_kernel(); 3619 mutex_lock(&floppy_mutex);
3620 mutex_lock(&open_lock); 3620 mutex_lock(&open_lock);
3621 if (UDRS->fd_ref < 0) 3621 if (UDRS->fd_ref < 0)
3622 UDRS->fd_ref = 0; 3622 UDRS->fd_ref = 0;
@@ -3627,7 +3627,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
3627 if (!UDRS->fd_ref) 3627 if (!UDRS->fd_ref)
3628 opened_bdev[drive] = NULL; 3628 opened_bdev[drive] = NULL;
3629 mutex_unlock(&open_lock); 3629 mutex_unlock(&open_lock);
3630 unlock_kernel(); 3630 mutex_unlock(&floppy_mutex);
3631 3631
3632 return 0; 3632 return 0;
3633} 3633}
@@ -3645,7 +3645,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
3645 int res = -EBUSY; 3645 int res = -EBUSY;
3646 char *tmp; 3646 char *tmp;
3647 3647
3648 lock_kernel(); 3648 mutex_lock(&floppy_mutex);
3649 mutex_lock(&open_lock); 3649 mutex_lock(&open_lock);
3650 old_dev = UDRS->fd_device; 3650 old_dev = UDRS->fd_device;
3651 if (opened_bdev[drive] && opened_bdev[drive] != bdev) 3651 if (opened_bdev[drive] && opened_bdev[drive] != bdev)
@@ -3722,7 +3722,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
3722 goto out; 3722 goto out;
3723 } 3723 }
3724 mutex_unlock(&open_lock); 3724 mutex_unlock(&open_lock);
3725 unlock_kernel(); 3725 mutex_unlock(&floppy_mutex);
3726 return 0; 3726 return 0;
3727out: 3727out:
3728 if (UDRS->fd_ref < 0) 3728 if (UDRS->fd_ref < 0)
@@ -3733,7 +3733,7 @@ out:
3733 opened_bdev[drive] = NULL; 3733 opened_bdev[drive] = NULL;
3734out2: 3734out2:
3735 mutex_unlock(&open_lock); 3735 mutex_unlock(&open_lock);
3736 unlock_kernel(); 3736 mutex_unlock(&floppy_mutex);
3737 return res; 3737 return res;
3738} 3738}
3739 3739
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 91797bbbe702..a10c8c9b6b78 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -67,7 +67,7 @@
67#include <linux/compat.h> 67#include <linux/compat.h>
68#include <linux/suspend.h> 68#include <linux/suspend.h>
69#include <linux/freezer.h> 69#include <linux/freezer.h>
70#include <linux/smp_lock.h> 70#include <linux/mutex.h>
71#include <linux/writeback.h> 71#include <linux/writeback.h>
72#include <linux/buffer_head.h> /* for invalidate_bdev() */ 72#include <linux/buffer_head.h> /* for invalidate_bdev() */
73#include <linux/completion.h> 73#include <linux/completion.h>
@@ -77,6 +77,7 @@
77 77
78#include <asm/uaccess.h> 78#include <asm/uaccess.h>
79 79
80static DEFINE_MUTEX(loop_mutex);
80static LIST_HEAD(loop_devices); 81static LIST_HEAD(loop_devices);
81static DEFINE_MUTEX(loop_devices_mutex); 82static DEFINE_MUTEX(loop_devices_mutex);
82 83
@@ -1409,11 +1410,11 @@ static int lo_open(struct block_device *bdev, fmode_t mode)
1409{ 1410{
1410 struct loop_device *lo = bdev->bd_disk->private_data; 1411 struct loop_device *lo = bdev->bd_disk->private_data;
1411 1412
1412 lock_kernel(); 1413 mutex_lock(&loop_mutex);
1413 mutex_lock(&lo->lo_ctl_mutex); 1414 mutex_lock(&lo->lo_ctl_mutex);
1414 lo->lo_refcnt++; 1415 lo->lo_refcnt++;
1415 mutex_unlock(&lo->lo_ctl_mutex); 1416 mutex_unlock(&lo->lo_ctl_mutex);
1416 unlock_kernel(); 1417 mutex_unlock(&loop_mutex);
1417 1418
1418 return 0; 1419 return 0;
1419} 1420}
@@ -1423,7 +1424,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1423 struct loop_device *lo = disk->private_data; 1424 struct loop_device *lo = disk->private_data;
1424 int err; 1425 int err;
1425 1426
1426 lock_kernel(); 1427 mutex_lock(&loop_mutex);
1427 mutex_lock(&lo->lo_ctl_mutex); 1428 mutex_lock(&lo->lo_ctl_mutex);
1428 1429
1429 if (--lo->lo_refcnt) 1430 if (--lo->lo_refcnt)
@@ -1448,7 +1449,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1448out: 1449out:
1449 mutex_unlock(&lo->lo_ctl_mutex); 1450 mutex_unlock(&lo->lo_ctl_mutex);
1450out_unlocked: 1451out_unlocked:
1451 lock_kernel(); 1452 mutex_unlock(&loop_mutex);
1452 return 0; 1453 return 0;
1453} 1454}
1454 1455
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 0daa422aa281..a32fb41246f8 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -24,7 +24,7 @@
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/file.h> 25#include <linux/file.h>
26#include <linux/ioctl.h> 26#include <linux/ioctl.h>
27#include <linux/smp_lock.h> 27#include <linux/mutex.h>
28#include <linux/compiler.h> 28#include <linux/compiler.h>
29#include <linux/err.h> 29#include <linux/err.h>
30#include <linux/kernel.h> 30#include <linux/kernel.h>
@@ -53,6 +53,7 @@
53#define DBG_BLKDEV 0x0100 53#define DBG_BLKDEV 0x0100
54#define DBG_RX 0x0200 54#define DBG_RX 0x0200
55#define DBG_TX 0x0400 55#define DBG_TX 0x0400
56static DEFINE_MUTEX(nbd_mutex);
56static unsigned int debugflags; 57static unsigned int debugflags;
57#endif /* NDEBUG */ 58#endif /* NDEBUG */
58 59
@@ -717,11 +718,11 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
717 dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n", 718 dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n",
718 lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg); 719 lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg);
719 720
720 lock_kernel(); 721 mutex_lock(&nbd_mutex);
721 mutex_lock(&lo->tx_lock); 722 mutex_lock(&lo->tx_lock);
722 error = __nbd_ioctl(bdev, lo, cmd, arg); 723 error = __nbd_ioctl(bdev, lo, cmd, arg);
723 mutex_unlock(&lo->tx_lock); 724 mutex_unlock(&lo->tx_lock);
724 unlock_kernel(); 725 mutex_unlock(&nbd_mutex);
725 726
726 return error; 727 return error;
727} 728}
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index 76f8565e1e8d..62cec6afd7ad 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -138,9 +138,10 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
138#include <linux/cdrom.h> 138#include <linux/cdrom.h>
139#include <linux/spinlock.h> 139#include <linux/spinlock.h>
140#include <linux/blkdev.h> 140#include <linux/blkdev.h>
141#include <linux/smp_lock.h> 141#include <linux/mutex.h>
142#include <asm/uaccess.h> 142#include <asm/uaccess.h>
143 143
144static DEFINE_MUTEX(pcd_mutex);
144static DEFINE_SPINLOCK(pcd_lock); 145static DEFINE_SPINLOCK(pcd_lock);
145 146
146module_param(verbose, bool, 0644); 147module_param(verbose, bool, 0644);
@@ -227,9 +228,9 @@ static int pcd_block_open(struct block_device *bdev, fmode_t mode)
227 struct pcd_unit *cd = bdev->bd_disk->private_data; 228 struct pcd_unit *cd = bdev->bd_disk->private_data;
228 int ret; 229 int ret;
229 230
230 lock_kernel(); 231 mutex_lock(&pcd_mutex);
231 ret = cdrom_open(&cd->info, bdev, mode); 232 ret = cdrom_open(&cd->info, bdev, mode);
232 unlock_kernel(); 233 mutex_unlock(&pcd_mutex);
233 234
234 return ret; 235 return ret;
235} 236}
@@ -237,9 +238,9 @@ static int pcd_block_open(struct block_device *bdev, fmode_t mode)
237static int pcd_block_release(struct gendisk *disk, fmode_t mode) 238static int pcd_block_release(struct gendisk *disk, fmode_t mode)
238{ 239{
239 struct pcd_unit *cd = disk->private_data; 240 struct pcd_unit *cd = disk->private_data;
240 lock_kernel(); 241 mutex_lock(&pcd_mutex);
241 cdrom_release(&cd->info, mode); 242 cdrom_release(&cd->info, mode);
242 unlock_kernel(); 243 mutex_unlock(&pcd_mutex);
243 return 0; 244 return 0;
244} 245}
245 246
@@ -249,9 +250,9 @@ static int pcd_block_ioctl(struct block_device *bdev, fmode_t mode,
249 struct pcd_unit *cd = bdev->bd_disk->private_data; 250 struct pcd_unit *cd = bdev->bd_disk->private_data;
250 int ret; 251 int ret;
251 252
252 lock_kernel(); 253 mutex_lock(&pcd_mutex);
253 ret = cdrom_ioctl(&cd->info, bdev, mode, cmd, arg); 254 ret = cdrom_ioctl(&cd->info, bdev, mode, cmd, arg);
254 unlock_kernel(); 255 mutex_unlock(&pcd_mutex);
255 256
256 return ret; 257 return ret;
257} 258}
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 985f0d4f1d1e..c0ee1558b9bb 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -153,10 +153,11 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_GEO, D_SBY, D_DLY, D_SLV};
153#include <linux/blkdev.h> 153#include <linux/blkdev.h>
154#include <linux/blkpg.h> 154#include <linux/blkpg.h>
155#include <linux/kernel.h> 155#include <linux/kernel.h>
156#include <linux/smp_lock.h> 156#include <linux/mutex.h>
157#include <asm/uaccess.h> 157#include <asm/uaccess.h>
158#include <linux/workqueue.h> 158#include <linux/workqueue.h>
159 159
160static DEFINE_MUTEX(pd_mutex);
160static DEFINE_SPINLOCK(pd_lock); 161static DEFINE_SPINLOCK(pd_lock);
161 162
162module_param(verbose, bool, 0); 163module_param(verbose, bool, 0);
@@ -736,14 +737,14 @@ static int pd_open(struct block_device *bdev, fmode_t mode)
736{ 737{
737 struct pd_unit *disk = bdev->bd_disk->private_data; 738 struct pd_unit *disk = bdev->bd_disk->private_data;
738 739
739 lock_kernel(); 740 mutex_lock(&pd_mutex);
740 disk->access++; 741 disk->access++;
741 742
742 if (disk->removable) { 743 if (disk->removable) {
743 pd_special_command(disk, pd_media_check); 744 pd_special_command(disk, pd_media_check);
744 pd_special_command(disk, pd_door_lock); 745 pd_special_command(disk, pd_door_lock);
745 } 746 }
746 unlock_kernel(); 747 mutex_unlock(&pd_mutex);
747 return 0; 748 return 0;
748} 749}
749 750
@@ -771,10 +772,10 @@ static int pd_ioctl(struct block_device *bdev, fmode_t mode,
771 772
772 switch (cmd) { 773 switch (cmd) {
773 case CDROMEJECT: 774 case CDROMEJECT:
774 lock_kernel(); 775 mutex_lock(&pd_mutex);
775 if (disk->access == 1) 776 if (disk->access == 1)
776 pd_special_command(disk, pd_eject); 777 pd_special_command(disk, pd_eject);
777 unlock_kernel(); 778 mutex_unlock(&pd_mutex);
778 return 0; 779 return 0;
779 default: 780 default:
780 return -EINVAL; 781 return -EINVAL;
@@ -785,10 +786,10 @@ static int pd_release(struct gendisk *p, fmode_t mode)
785{ 786{
786 struct pd_unit *disk = p->private_data; 787 struct pd_unit *disk = p->private_data;
787 788
788 lock_kernel(); 789 mutex_lock(&pd_mutex);
789 if (!--disk->access && disk->removable) 790 if (!--disk->access && disk->removable)
790 pd_special_command(disk, pd_door_unlock); 791 pd_special_command(disk, pd_door_unlock);
791 unlock_kernel(); 792 mutex_unlock(&pd_mutex);
792 793
793 return 0; 794 return 0;
794} 795}
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index 4457b494882a..635f25dd9e10 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -152,9 +152,10 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_LUN, D_DLY};
152#include <linux/spinlock.h> 152#include <linux/spinlock.h>
153#include <linux/blkdev.h> 153#include <linux/blkdev.h>
154#include <linux/blkpg.h> 154#include <linux/blkpg.h>
155#include <linux/smp_lock.h> 155#include <linux/mutex.h>
156#include <asm/uaccess.h> 156#include <asm/uaccess.h>
157 157
158static DEFINE_MUTEX(pf_mutex);
158static DEFINE_SPINLOCK(pf_spin_lock); 159static DEFINE_SPINLOCK(pf_spin_lock);
159 160
160module_param(verbose, bool, 0644); 161module_param(verbose, bool, 0644);
@@ -302,7 +303,7 @@ static int pf_open(struct block_device *bdev, fmode_t mode)
302 struct pf_unit *pf = bdev->bd_disk->private_data; 303 struct pf_unit *pf = bdev->bd_disk->private_data;
303 int ret; 304 int ret;
304 305
305 lock_kernel(); 306 mutex_lock(&pf_mutex);
306 pf_identify(pf); 307 pf_identify(pf);
307 308
308 ret = -ENODEV; 309 ret = -ENODEV;
@@ -318,7 +319,7 @@ static int pf_open(struct block_device *bdev, fmode_t mode)
318 if (pf->removable) 319 if (pf->removable)
319 pf_lock(pf, 1); 320 pf_lock(pf, 1);
320out: 321out:
321 unlock_kernel(); 322 mutex_unlock(&pf_mutex);
322 return ret; 323 return ret;
323} 324}
324 325
@@ -349,9 +350,9 @@ static int pf_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, u
349 350
350 if (pf->access != 1) 351 if (pf->access != 1)
351 return -EBUSY; 352 return -EBUSY;
352 lock_kernel(); 353 mutex_lock(&pf_mutex);
353 pf_eject(pf); 354 pf_eject(pf);
354 unlock_kernel(); 355 mutex_unlock(&pf_mutex);
355 356
356 return 0; 357 return 0;
357} 358}
@@ -360,9 +361,9 @@ static int pf_release(struct gendisk *disk, fmode_t mode)
360{ 361{
361 struct pf_unit *pf = disk->private_data; 362 struct pf_unit *pf = disk->private_data;
362 363
363 lock_kernel(); 364 mutex_lock(&pf_mutex);
364 if (pf->access <= 0) { 365 if (pf->access <= 0) {
365 unlock_kernel(); 366 mutex_unlock(&pf_mutex);
366 return -EINVAL; 367 return -EINVAL;
367 } 368 }
368 369
@@ -371,7 +372,7 @@ static int pf_release(struct gendisk *disk, fmode_t mode)
371 if (!pf->access && pf->removable) 372 if (!pf->access && pf->removable)
372 pf_lock(pf, 0); 373 pf_lock(pf, 0);
373 374
374 unlock_kernel(); 375 mutex_unlock(&pf_mutex);
375 return 0; 376 return 0;
376 377
377} 378}
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index aa27cd84f633..6b9a2000d56a 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -162,7 +162,7 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
162#include <linux/pg.h> 162#include <linux/pg.h>
163#include <linux/device.h> 163#include <linux/device.h>
164#include <linux/sched.h> /* current, TASK_* */ 164#include <linux/sched.h> /* current, TASK_* */
165#include <linux/smp_lock.h> 165#include <linux/mutex.h>
166#include <linux/jiffies.h> 166#include <linux/jiffies.h>
167 167
168#include <asm/uaccess.h> 168#include <asm/uaccess.h>
@@ -193,6 +193,7 @@ module_param_array(drive3, int, NULL, 0);
193 193
194#define ATAPI_IDENTIFY 0x12 194#define ATAPI_IDENTIFY 0x12
195 195
196static DEFINE_MUTEX(pg_mutex);
196static int pg_open(struct inode *inode, struct file *file); 197static int pg_open(struct inode *inode, struct file *file);
197static int pg_release(struct inode *inode, struct file *file); 198static int pg_release(struct inode *inode, struct file *file);
198static ssize_t pg_read(struct file *filp, char __user *buf, 199static ssize_t pg_read(struct file *filp, char __user *buf,
@@ -519,7 +520,7 @@ static int pg_open(struct inode *inode, struct file *file)
519 struct pg *dev = &devices[unit]; 520 struct pg *dev = &devices[unit];
520 int ret = 0; 521 int ret = 0;
521 522
522 lock_kernel(); 523 mutex_lock(&pg_mutex);
523 if ((unit >= PG_UNITS) || (!dev->present)) { 524 if ((unit >= PG_UNITS) || (!dev->present)) {
524 ret = -ENODEV; 525 ret = -ENODEV;
525 goto out; 526 goto out;
@@ -548,7 +549,7 @@ static int pg_open(struct inode *inode, struct file *file)
548 file->private_data = dev; 549 file->private_data = dev;
549 550
550out: 551out:
551 unlock_kernel(); 552 mutex_unlock(&pg_mutex);
552 return ret; 553 return ret;
553} 554}
554 555
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index c372c32e0db3..7179f79d7468 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -146,7 +146,7 @@ static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};
146#include <linux/mtio.h> 146#include <linux/mtio.h>
147#include <linux/device.h> 147#include <linux/device.h>
148#include <linux/sched.h> /* current, TASK_*, schedule_timeout() */ 148#include <linux/sched.h> /* current, TASK_*, schedule_timeout() */
149#include <linux/smp_lock.h> 149#include <linux/mutex.h>
150 150
151#include <asm/uaccess.h> 151#include <asm/uaccess.h>
152 152
@@ -189,6 +189,7 @@ module_param_array(drive3, int, NULL, 0);
189#define ATAPI_MODE_SENSE 0x1a 189#define ATAPI_MODE_SENSE 0x1a
190#define ATAPI_LOG_SENSE 0x4d 190#define ATAPI_LOG_SENSE 0x4d
191 191
192static DEFINE_MUTEX(pt_mutex);
192static int pt_open(struct inode *inode, struct file *file); 193static int pt_open(struct inode *inode, struct file *file);
193static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 194static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
194static int pt_release(struct inode *inode, struct file *file); 195static int pt_release(struct inode *inode, struct file *file);
@@ -651,9 +652,9 @@ static int pt_open(struct inode *inode, struct file *file)
651 struct pt_unit *tape = pt + unit; 652 struct pt_unit *tape = pt + unit;
652 int err; 653 int err;
653 654
654 lock_kernel(); 655 mutex_lock(&pt_mutex);
655 if (unit >= PT_UNITS || (!tape->present)) { 656 if (unit >= PT_UNITS || (!tape->present)) {
656 unlock_kernel(); 657 mutex_unlock(&pt_mutex);
657 return -ENODEV; 658 return -ENODEV;
658 } 659 }
659 660
@@ -682,12 +683,12 @@ static int pt_open(struct inode *inode, struct file *file)
682 } 683 }
683 684
684 file->private_data = tape; 685 file->private_data = tape;
685 unlock_kernel(); 686 mutex_unlock(&pt_mutex);
686 return 0; 687 return 0;
687 688
688out: 689out:
689 atomic_inc(&tape->available); 690 atomic_inc(&tape->available);
690 unlock_kernel(); 691 mutex_unlock(&pt_mutex);
691 return err; 692 return err;
692} 693}
693 694
@@ -705,15 +706,15 @@ static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
705 switch (mtop.mt_op) { 706 switch (mtop.mt_op) {
706 707
707 case MTREW: 708 case MTREW:
708 lock_kernel(); 709 mutex_lock(&pt_mutex);
709 pt_rewind(tape); 710 pt_rewind(tape);
710 unlock_kernel(); 711 mutex_unlock(&pt_mutex);
711 return 0; 712 return 0;
712 713
713 case MTWEOF: 714 case MTWEOF:
714 lock_kernel(); 715 mutex_lock(&pt_mutex);
715 pt_write_fm(tape); 716 pt_write_fm(tape);
716 unlock_kernel(); 717 mutex_unlock(&pt_mutex);
717 return 0; 718 return 0;
718 719
719 default: 720 default:
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 6a4642dd8283..ef58fccadad3 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -57,7 +57,6 @@
57#include <linux/seq_file.h> 57#include <linux/seq_file.h>
58#include <linux/miscdevice.h> 58#include <linux/miscdevice.h>
59#include <linux/freezer.h> 59#include <linux/freezer.h>
60#include <linux/smp_lock.h>
61#include <linux/mutex.h> 60#include <linux/mutex.h>
62#include <linux/slab.h> 61#include <linux/slab.h>
63#include <scsi/scsi_cmnd.h> 62#include <scsi/scsi_cmnd.h>
@@ -86,6 +85,7 @@
86 85
87#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1)) 86#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1))
88 87
88static DEFINE_MUTEX(pktcdvd_mutex);
89static struct pktcdvd_device *pkt_devs[MAX_WRITERS]; 89static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
90static struct proc_dir_entry *pkt_proc; 90static struct proc_dir_entry *pkt_proc;
91static int pktdev_major; 91static int pktdev_major;
@@ -2369,7 +2369,7 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush)
2369 pkt_shrink_pktlist(pd); 2369 pkt_shrink_pktlist(pd);
2370} 2370}
2371 2371
2372static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor) 2372static struct pktcdvd_device *pkt_find_dev_from_minor(unsigned int dev_minor)
2373{ 2373{
2374 if (dev_minor >= MAX_WRITERS) 2374 if (dev_minor >= MAX_WRITERS)
2375 return NULL; 2375 return NULL;
@@ -2383,7 +2383,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode)
2383 2383
2384 VPRINTK(DRIVER_NAME": entering open\n"); 2384 VPRINTK(DRIVER_NAME": entering open\n");
2385 2385
2386 lock_kernel(); 2386 mutex_lock(&pktcdvd_mutex);
2387 mutex_lock(&ctl_mutex); 2387 mutex_lock(&ctl_mutex);
2388 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev)); 2388 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev));
2389 if (!pd) { 2389 if (!pd) {
@@ -2411,7 +2411,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode)
2411 } 2411 }
2412 2412
2413 mutex_unlock(&ctl_mutex); 2413 mutex_unlock(&ctl_mutex);
2414 unlock_kernel(); 2414 mutex_unlock(&pktcdvd_mutex);
2415 return 0; 2415 return 0;
2416 2416
2417out_dec: 2417out_dec:
@@ -2419,7 +2419,7 @@ out_dec:
2419out: 2419out:
2420 VPRINTK(DRIVER_NAME": failed open (%d)\n", ret); 2420 VPRINTK(DRIVER_NAME": failed open (%d)\n", ret);
2421 mutex_unlock(&ctl_mutex); 2421 mutex_unlock(&ctl_mutex);
2422 unlock_kernel(); 2422 mutex_unlock(&pktcdvd_mutex);
2423 return ret; 2423 return ret;
2424} 2424}
2425 2425
@@ -2428,7 +2428,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)
2428 struct pktcdvd_device *pd = disk->private_data; 2428 struct pktcdvd_device *pd = disk->private_data;
2429 int ret = 0; 2429 int ret = 0;
2430 2430
2431 lock_kernel(); 2431 mutex_lock(&pktcdvd_mutex);
2432 mutex_lock(&ctl_mutex); 2432 mutex_lock(&ctl_mutex);
2433 pd->refcnt--; 2433 pd->refcnt--;
2434 BUG_ON(pd->refcnt < 0); 2434 BUG_ON(pd->refcnt < 0);
@@ -2437,7 +2437,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)
2437 pkt_release_dev(pd, flush); 2437 pkt_release_dev(pd, flush);
2438 } 2438 }
2439 mutex_unlock(&ctl_mutex); 2439 mutex_unlock(&ctl_mutex);
2440 unlock_kernel(); 2440 mutex_unlock(&pktcdvd_mutex);
2441 return ret; 2441 return ret;
2442} 2442}
2443 2443
@@ -2773,7 +2773,7 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
2773 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd, 2773 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd,
2774 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); 2774 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
2775 2775
2776 lock_kernel(); 2776 mutex_lock(&pktcdvd_mutex);
2777 switch (cmd) { 2777 switch (cmd) {
2778 case CDROMEJECT: 2778 case CDROMEJECT:
2779 /* 2779 /*
@@ -2798,7 +2798,7 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
2798 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd); 2798 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd);
2799 ret = -ENOTTY; 2799 ret = -ENOTTY;
2800 } 2800 }
2801 unlock_kernel(); 2801 mutex_unlock(&pktcdvd_mutex);
2802 2802
2803 return ret; 2803 return ret;
2804} 2804}
diff --git a/drivers/block/ps3disk.c b/drivers/block/ps3disk.c
index e9da874d0419..03688c2da319 100644
--- a/drivers/block/ps3disk.c
+++ b/drivers/block/ps3disk.c
@@ -113,7 +113,7 @@ static void ps3disk_scatter_gather(struct ps3_storage_device *dev,
113 memcpy(buf, dev->bounce_buf+offset, size); 113 memcpy(buf, dev->bounce_buf+offset, size);
114 offset += size; 114 offset += size;
115 flush_kernel_dcache_page(bvec->bv_page); 115 flush_kernel_dcache_page(bvec->bv_page);
116 bvec_kunmap_irq(bvec, &flags); 116 bvec_kunmap_irq(buf, &flags);
117 i++; 117 i++;
118 } 118 }
119} 119}
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
new file mode 100644
index 000000000000..6ec9d53806c5
--- /dev/null
+++ b/drivers/block/rbd.c
@@ -0,0 +1,1841 @@
1/*
2 rbd.c -- Export ceph rados objects as a Linux block device
3
4
5 based on drivers/block/osdblk.c:
6
7 Copyright 2009 Red Hat, Inc.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22
23
24 Instructions for use
25 --------------------
26
27 1) Map a Linux block device to an existing rbd image.
28
29 Usage: <mon ip addr> <options> <pool name> <rbd image name> [snap name]
30
31 $ echo "192.168.0.1 name=admin rbd foo" > /sys/class/rbd/add
32
33 The snapshot name can be "-" or omitted to map the image read/write.
34
35 2) List all active blkdev<->object mappings.
36
37 In this example, we have performed step #1 twice, creating two blkdevs,
38 mapped to two separate rados objects in the rados rbd pool
39
40 $ cat /sys/class/rbd/list
41 #id major client_name pool name snap KB
42 0 254 client4143 rbd foo - 1024000
43
44 The columns, in order, are:
45 - blkdev unique id
46 - blkdev assigned major
47 - rados client id
48 - rados pool name
49 - rados block device name
50 - mapped snapshot ("-" if none)
51 - device size in KB
52
53
54 3) Create a snapshot.
55
56 Usage: <blkdev id> <snapname>
57
58 $ echo "0 mysnap" > /sys/class/rbd/snap_create
59
60
61 4) Listing a snapshot.
62
63 $ cat /sys/class/rbd/snaps_list
64 #id snap KB
65 0 - 1024000 (*)
66 0 foo 1024000
67
68 The columns, in order, are:
69 - blkdev unique id
70 - snapshot name, '-' means none (active read/write version)
71 - size of device at time of snapshot
72 - the (*) indicates this is the active version
73
74 5) Rollback to snapshot.
75
76 Usage: <blkdev id> <snapname>
77
78 $ echo "0 mysnap" > /sys/class/rbd/snap_rollback
79
80
81 6) Mapping an image using snapshot.
82
83 A snapshot mapping is read-only. This is being done by passing
84 snap=<snapname> to the options when adding a device.
85
86 $ echo "192.168.0.1 name=admin,snap=mysnap rbd foo" > /sys/class/rbd/add
87
88
89 7) Remove an active blkdev<->rbd image mapping.
90
91 In this example, we remove the mapping with blkdev unique id 1.
92
93 $ echo 1 > /sys/class/rbd/remove
94
95
96 NOTE: The actual creation and deletion of rados objects is outside the scope
97 of this driver.
98
99 */
100
101#include <linux/ceph/libceph.h>
102#include <linux/ceph/osd_client.h>
103#include <linux/ceph/mon_client.h>
104#include <linux/ceph/decode.h>
105
106#include <linux/kernel.h>
107#include <linux/device.h>
108#include <linux/module.h>
109#include <linux/fs.h>
110#include <linux/blkdev.h>
111
112#include "rbd_types.h"
113
114#define DRV_NAME "rbd"
115#define DRV_NAME_LONG "rbd (rados block device)"
116
117#define RBD_MINORS_PER_MAJOR 256 /* max minors per blkdev */
118
119#define RBD_MAX_MD_NAME_LEN (96 + sizeof(RBD_SUFFIX))
120#define RBD_MAX_POOL_NAME_LEN 64
121#define RBD_MAX_SNAP_NAME_LEN 32
122#define RBD_MAX_OPT_LEN 1024
123
124#define RBD_SNAP_HEAD_NAME "-"
125
126#define DEV_NAME_LEN 32
127
128/*
129 * block device image metadata (in-memory version)
130 */
131struct rbd_image_header {
132 u64 image_size;
133 char block_name[32];
134 __u8 obj_order;
135 __u8 crypt_type;
136 __u8 comp_type;
137 struct rw_semaphore snap_rwsem;
138 struct ceph_snap_context *snapc;
139 size_t snap_names_len;
140 u64 snap_seq;
141 u32 total_snaps;
142
143 char *snap_names;
144 u64 *snap_sizes;
145};
146
147/*
148 * an instance of the client. multiple devices may share a client.
149 */
150struct rbd_client {
151 struct ceph_client *client;
152 struct kref kref;
153 struct list_head node;
154};
155
156/*
157 * a single io request
158 */
159struct rbd_request {
160 struct request *rq; /* blk layer request */
161 struct bio *bio; /* cloned bio */
162 struct page **pages; /* list of used pages */
163 u64 len;
164};
165
166/*
167 * a single device
168 */
169struct rbd_device {
170 int id; /* blkdev unique id */
171
172 int major; /* blkdev assigned major */
173 struct gendisk *disk; /* blkdev's gendisk and rq */
174 struct request_queue *q;
175
176 struct ceph_client *client;
177 struct rbd_client *rbd_client;
178
179 char name[DEV_NAME_LEN]; /* blkdev name, e.g. rbd3 */
180
181 spinlock_t lock; /* queue lock */
182
183 struct rbd_image_header header;
184 char obj[RBD_MAX_OBJ_NAME_LEN]; /* rbd image name */
185 int obj_len;
186 char obj_md_name[RBD_MAX_MD_NAME_LEN]; /* hdr nm. */
187 char pool_name[RBD_MAX_POOL_NAME_LEN];
188 int poolid;
189
190 char snap_name[RBD_MAX_SNAP_NAME_LEN];
191 u32 cur_snap; /* index+1 of current snapshot within snap context
192 0 - for the head */
193 int read_only;
194
195 struct list_head node;
196};
197
198static spinlock_t node_lock; /* protects client get/put */
199
200static struct class *class_rbd; /* /sys/class/rbd */
201static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */
202static LIST_HEAD(rbd_dev_list); /* devices */
203static LIST_HEAD(rbd_client_list); /* clients */
204
205
206static int rbd_open(struct block_device *bdev, fmode_t mode)
207{
208 struct gendisk *disk = bdev->bd_disk;
209 struct rbd_device *rbd_dev = disk->private_data;
210
211 set_device_ro(bdev, rbd_dev->read_only);
212
213 if ((mode & FMODE_WRITE) && rbd_dev->read_only)
214 return -EROFS;
215
216 return 0;
217}
218
219static const struct block_device_operations rbd_bd_ops = {
220 .owner = THIS_MODULE,
221 .open = rbd_open,
222};
223
224/*
225 * Initialize an rbd client instance.
226 * We own *opt.
227 */
228static struct rbd_client *rbd_client_create(struct ceph_options *opt)
229{
230 struct rbd_client *rbdc;
231 int ret = -ENOMEM;
232
233 dout("rbd_client_create\n");
234 rbdc = kmalloc(sizeof(struct rbd_client), GFP_KERNEL);
235 if (!rbdc)
236 goto out_opt;
237
238 kref_init(&rbdc->kref);
239 INIT_LIST_HEAD(&rbdc->node);
240
241 rbdc->client = ceph_create_client(opt, rbdc);
242 if (IS_ERR(rbdc->client))
243 goto out_rbdc;
244 opt = NULL; /* Now rbdc->client is responsible for opt */
245
246 ret = ceph_open_session(rbdc->client);
247 if (ret < 0)
248 goto out_err;
249
250 spin_lock(&node_lock);
251 list_add_tail(&rbdc->node, &rbd_client_list);
252 spin_unlock(&node_lock);
253
254 dout("rbd_client_create created %p\n", rbdc);
255 return rbdc;
256
257out_err:
258 ceph_destroy_client(rbdc->client);
259out_rbdc:
260 kfree(rbdc);
261out_opt:
262 if (opt)
263 ceph_destroy_options(opt);
264 return ERR_PTR(ret);
265}
266
267/*
268 * Find a ceph client with specific addr and configuration.
269 */
270static struct rbd_client *__rbd_client_find(struct ceph_options *opt)
271{
272 struct rbd_client *client_node;
273
274 if (opt->flags & CEPH_OPT_NOSHARE)
275 return NULL;
276
277 list_for_each_entry(client_node, &rbd_client_list, node)
278 if (ceph_compare_options(opt, client_node->client) == 0)
279 return client_node;
280 return NULL;
281}
282
283/*
284 * Get a ceph client with specific addr and configuration, if one does
285 * not exist create it.
286 */
287static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
288 char *options)
289{
290 struct rbd_client *rbdc;
291 struct ceph_options *opt;
292 int ret;
293
294 ret = ceph_parse_options(&opt, options, mon_addr,
295 mon_addr + strlen(mon_addr), NULL, NULL);
296 if (ret < 0)
297 return ret;
298
299 spin_lock(&node_lock);
300 rbdc = __rbd_client_find(opt);
301 if (rbdc) {
302 ceph_destroy_options(opt);
303
304 /* using an existing client */
305 kref_get(&rbdc->kref);
306 rbd_dev->rbd_client = rbdc;
307 rbd_dev->client = rbdc->client;
308 spin_unlock(&node_lock);
309 return 0;
310 }
311 spin_unlock(&node_lock);
312
313 rbdc = rbd_client_create(opt);
314 if (IS_ERR(rbdc))
315 return PTR_ERR(rbdc);
316
317 rbd_dev->rbd_client = rbdc;
318 rbd_dev->client = rbdc->client;
319 return 0;
320}
321
322/*
323 * Destroy ceph client
324 */
325static void rbd_client_release(struct kref *kref)
326{
327 struct rbd_client *rbdc = container_of(kref, struct rbd_client, kref);
328
329 dout("rbd_release_client %p\n", rbdc);
330 spin_lock(&node_lock);
331 list_del(&rbdc->node);
332 spin_unlock(&node_lock);
333
334 ceph_destroy_client(rbdc->client);
335 kfree(rbdc);
336}
337
338/*
339 * Drop reference to ceph client node. If it's not referenced anymore, release
340 * it.
341 */
342static void rbd_put_client(struct rbd_device *rbd_dev)
343{
344 kref_put(&rbd_dev->rbd_client->kref, rbd_client_release);
345 rbd_dev->rbd_client = NULL;
346 rbd_dev->client = NULL;
347}
348
349
350/*
351 * Create a new header structure, translate header format from the on-disk
352 * header.
353 */
354static int rbd_header_from_disk(struct rbd_image_header *header,
355 struct rbd_image_header_ondisk *ondisk,
356 int allocated_snaps,
357 gfp_t gfp_flags)
358{
359 int i;
360 u32 snap_count = le32_to_cpu(ondisk->snap_count);
361 int ret = -ENOMEM;
362
363 init_rwsem(&header->snap_rwsem);
364
365 header->snap_names_len = le64_to_cpu(ondisk->snap_names_len);
366 header->snapc = kmalloc(sizeof(struct ceph_snap_context) +
367 snap_count *
368 sizeof(struct rbd_image_snap_ondisk),
369 gfp_flags);
370 if (!header->snapc)
371 return -ENOMEM;
372 if (snap_count) {
373 header->snap_names = kmalloc(header->snap_names_len,
374 GFP_KERNEL);
375 if (!header->snap_names)
376 goto err_snapc;
377 header->snap_sizes = kmalloc(snap_count * sizeof(u64),
378 GFP_KERNEL);
379 if (!header->snap_sizes)
380 goto err_names;
381 } else {
382 header->snap_names = NULL;
383 header->snap_sizes = NULL;
384 }
385 memcpy(header->block_name, ondisk->block_name,
386 sizeof(ondisk->block_name));
387
388 header->image_size = le64_to_cpu(ondisk->image_size);
389 header->obj_order = ondisk->options.order;
390 header->crypt_type = ondisk->options.crypt_type;
391 header->comp_type = ondisk->options.comp_type;
392
393 atomic_set(&header->snapc->nref, 1);
394 header->snap_seq = le64_to_cpu(ondisk->snap_seq);
395 header->snapc->num_snaps = snap_count;
396 header->total_snaps = snap_count;
397
398 if (snap_count &&
399 allocated_snaps == snap_count) {
400 for (i = 0; i < snap_count; i++) {
401 header->snapc->snaps[i] =
402 le64_to_cpu(ondisk->snaps[i].id);
403 header->snap_sizes[i] =
404 le64_to_cpu(ondisk->snaps[i].image_size);
405 }
406
407 /* copy snapshot names */
408 memcpy(header->snap_names, &ondisk->snaps[i],
409 header->snap_names_len);
410 }
411
412 return 0;
413
414err_names:
415 kfree(header->snap_names);
416err_snapc:
417 kfree(header->snapc);
418 return ret;
419}
420
421static int snap_index(struct rbd_image_header *header, int snap_num)
422{
423 return header->total_snaps - snap_num;
424}
425
426static u64 cur_snap_id(struct rbd_device *rbd_dev)
427{
428 struct rbd_image_header *header = &rbd_dev->header;
429
430 if (!rbd_dev->cur_snap)
431 return 0;
432
433 return header->snapc->snaps[snap_index(header, rbd_dev->cur_snap)];
434}
435
436static int snap_by_name(struct rbd_image_header *header, const char *snap_name,
437 u64 *seq, u64 *size)
438{
439 int i;
440 char *p = header->snap_names;
441
442 for (i = 0; i < header->total_snaps; i++, p += strlen(p) + 1) {
443 if (strcmp(snap_name, p) == 0)
444 break;
445 }
446 if (i == header->total_snaps)
447 return -ENOENT;
448 if (seq)
449 *seq = header->snapc->snaps[i];
450
451 if (size)
452 *size = header->snap_sizes[i];
453
454 return i;
455}
456
457static int rbd_header_set_snap(struct rbd_device *dev,
458 const char *snap_name,
459 u64 *size)
460{
461 struct rbd_image_header *header = &dev->header;
462 struct ceph_snap_context *snapc = header->snapc;
463 int ret = -ENOENT;
464
465 down_write(&header->snap_rwsem);
466
467 if (!snap_name ||
468 !*snap_name ||
469 strcmp(snap_name, "-") == 0 ||
470 strcmp(snap_name, RBD_SNAP_HEAD_NAME) == 0) {
471 if (header->total_snaps)
472 snapc->seq = header->snap_seq;
473 else
474 snapc->seq = 0;
475 dev->cur_snap = 0;
476 dev->read_only = 0;
477 if (size)
478 *size = header->image_size;
479 } else {
480 ret = snap_by_name(header, snap_name, &snapc->seq, size);
481 if (ret < 0)
482 goto done;
483
484 dev->cur_snap = header->total_snaps - ret;
485 dev->read_only = 1;
486 }
487
488 ret = 0;
489done:
490 up_write(&header->snap_rwsem);
491 return ret;
492}
493
494static void rbd_header_free(struct rbd_image_header *header)
495{
496 kfree(header->snapc);
497 kfree(header->snap_names);
498 kfree(header->snap_sizes);
499}
500
501/*
502 * get the actual striped segment name, offset and length
503 */
504static u64 rbd_get_segment(struct rbd_image_header *header,
505 const char *block_name,
506 u64 ofs, u64 len,
507 char *seg_name, u64 *segofs)
508{
509 u64 seg = ofs >> header->obj_order;
510
511 if (seg_name)
512 snprintf(seg_name, RBD_MAX_SEG_NAME_LEN,
513 "%s.%012llx", block_name, seg);
514
515 ofs = ofs & ((1 << header->obj_order) - 1);
516 len = min_t(u64, len, (1 << header->obj_order) - ofs);
517
518 if (segofs)
519 *segofs = ofs;
520
521 return len;
522}
523
524/*
525 * bio helpers
526 */
527
528static void bio_chain_put(struct bio *chain)
529{
530 struct bio *tmp;
531
532 while (chain) {
533 tmp = chain;
534 chain = chain->bi_next;
535 bio_put(tmp);
536 }
537}
538
539/*
540 * zeros a bio chain, starting at specific offset
541 */
542static void zero_bio_chain(struct bio *chain, int start_ofs)
543{
544 struct bio_vec *bv;
545 unsigned long flags;
546 void *buf;
547 int i;
548 int pos = 0;
549
550 while (chain) {
551 bio_for_each_segment(bv, chain, i) {
552 if (pos + bv->bv_len > start_ofs) {
553 int remainder = max(start_ofs - pos, 0);
554 buf = bvec_kmap_irq(bv, &flags);
555 memset(buf + remainder, 0,
556 bv->bv_len - remainder);
557 bvec_kunmap_irq(buf, &flags);
558 }
559 pos += bv->bv_len;
560 }
561
562 chain = chain->bi_next;
563 }
564}
565
566/*
567 * bio_chain_clone - clone a chain of bios up to a certain length.
568 * might return a bio_pair that will need to be released.
569 */
570static struct bio *bio_chain_clone(struct bio **old, struct bio **next,
571 struct bio_pair **bp,
572 int len, gfp_t gfpmask)
573{
574 struct bio *tmp, *old_chain = *old, *new_chain = NULL, *tail = NULL;
575 int total = 0;
576
577 if (*bp) {
578 bio_pair_release(*bp);
579 *bp = NULL;
580 }
581
582 while (old_chain && (total < len)) {
583 tmp = bio_kmalloc(gfpmask, old_chain->bi_max_vecs);
584 if (!tmp)
585 goto err_out;
586
587 if (total + old_chain->bi_size > len) {
588 struct bio_pair *bp;
589
590 /*
591 * this split can only happen with a single paged bio,
592 * split_bio will BUG_ON if this is not the case
593 */
594 dout("bio_chain_clone split! total=%d remaining=%d"
595 "bi_size=%d\n",
596 (int)total, (int)len-total,
597 (int)old_chain->bi_size);
598
599 /* split the bio. We'll release it either in the next
600 call, or it will have to be released outside */
601 bp = bio_split(old_chain, (len - total) / 512ULL);
602 if (!bp)
603 goto err_out;
604
605 __bio_clone(tmp, &bp->bio1);
606
607 *next = &bp->bio2;
608 } else {
609 __bio_clone(tmp, old_chain);
610 *next = old_chain->bi_next;
611 }
612
613 tmp->bi_bdev = NULL;
614 gfpmask &= ~__GFP_WAIT;
615 tmp->bi_next = NULL;
616
617 if (!new_chain) {
618 new_chain = tail = tmp;
619 } else {
620 tail->bi_next = tmp;
621 tail = tmp;
622 }
623 old_chain = old_chain->bi_next;
624
625 total += tmp->bi_size;
626 }
627
628 BUG_ON(total < len);
629
630 if (tail)
631 tail->bi_next = NULL;
632
633 *old = old_chain;
634
635 return new_chain;
636
637err_out:
638 dout("bio_chain_clone with err\n");
639 bio_chain_put(new_chain);
640 return NULL;
641}
642
643/*
644 * helpers for osd request op vectors.
645 */
646static int rbd_create_rw_ops(struct ceph_osd_req_op **ops,
647 int num_ops,
648 int opcode,
649 u32 payload_len)
650{
651 *ops = kzalloc(sizeof(struct ceph_osd_req_op) * (num_ops + 1),
652 GFP_NOIO);
653 if (!*ops)
654 return -ENOMEM;
655 (*ops)[0].op = opcode;
656 /*
657 * op extent offset and length will be set later on
658 * in calc_raw_layout()
659 */
660 (*ops)[0].payload_len = payload_len;
661 return 0;
662}
663
664static void rbd_destroy_ops(struct ceph_osd_req_op *ops)
665{
666 kfree(ops);
667}
668
669/*
670 * Send ceph osd request
671 */
672static int rbd_do_request(struct request *rq,
673 struct rbd_device *dev,
674 struct ceph_snap_context *snapc,
675 u64 snapid,
676 const char *obj, u64 ofs, u64 len,
677 struct bio *bio,
678 struct page **pages,
679 int num_pages,
680 int flags,
681 struct ceph_osd_req_op *ops,
682 int num_reply,
683 void (*rbd_cb)(struct ceph_osd_request *req,
684 struct ceph_msg *msg))
685{
686 struct ceph_osd_request *req;
687 struct ceph_file_layout *layout;
688 int ret;
689 u64 bno;
690 struct timespec mtime = CURRENT_TIME;
691 struct rbd_request *req_data;
692 struct ceph_osd_request_head *reqhead;
693 struct rbd_image_header *header = &dev->header;
694
695 ret = -ENOMEM;
696 req_data = kzalloc(sizeof(*req_data), GFP_NOIO);
697 if (!req_data)
698 goto done;
699
700 dout("rbd_do_request len=%lld ofs=%lld\n", len, ofs);
701
702 down_read(&header->snap_rwsem);
703
704 req = ceph_osdc_alloc_request(&dev->client->osdc, flags,
705 snapc,
706 ops,
707 false,
708 GFP_NOIO, pages, bio);
709 if (IS_ERR(req)) {
710 up_read(&header->snap_rwsem);
711 ret = PTR_ERR(req);
712 goto done_pages;
713 }
714
715 req->r_callback = rbd_cb;
716
717 req_data->rq = rq;
718 req_data->bio = bio;
719 req_data->pages = pages;
720 req_data->len = len;
721
722 req->r_priv = req_data;
723
724 reqhead = req->r_request->front.iov_base;
725 reqhead->snapid = cpu_to_le64(CEPH_NOSNAP);
726
727 strncpy(req->r_oid, obj, sizeof(req->r_oid));
728 req->r_oid_len = strlen(req->r_oid);
729
730 layout = &req->r_file_layout;
731 memset(layout, 0, sizeof(*layout));
732 layout->fl_stripe_unit = cpu_to_le32(1 << RBD_MAX_OBJ_ORDER);
733 layout->fl_stripe_count = cpu_to_le32(1);
734 layout->fl_object_size = cpu_to_le32(1 << RBD_MAX_OBJ_ORDER);
735 layout->fl_pg_preferred = cpu_to_le32(-1);
736 layout->fl_pg_pool = cpu_to_le32(dev->poolid);
737 ceph_calc_raw_layout(&dev->client->osdc, layout, snapid,
738 ofs, &len, &bno, req, ops);
739
740 ceph_osdc_build_request(req, ofs, &len,
741 ops,
742 snapc,
743 &mtime,
744 req->r_oid, req->r_oid_len);
745 up_read(&header->snap_rwsem);
746
747 ret = ceph_osdc_start_request(&dev->client->osdc, req, false);
748 if (ret < 0)
749 goto done_err;
750
751 if (!rbd_cb) {
752 ret = ceph_osdc_wait_request(&dev->client->osdc, req);
753 ceph_osdc_put_request(req);
754 }
755 return ret;
756
757done_err:
758 bio_chain_put(req_data->bio);
759 ceph_osdc_put_request(req);
760done_pages:
761 kfree(req_data);
762done:
763 if (rq)
764 blk_end_request(rq, ret, len);
765 return ret;
766}
767
768/*
769 * Ceph osd op callback
770 */
771static void rbd_req_cb(struct ceph_osd_request *req, struct ceph_msg *msg)
772{
773 struct rbd_request *req_data = req->r_priv;
774 struct ceph_osd_reply_head *replyhead;
775 struct ceph_osd_op *op;
776 __s32 rc;
777 u64 bytes;
778 int read_op;
779
780 /* parse reply */
781 replyhead = msg->front.iov_base;
782 WARN_ON(le32_to_cpu(replyhead->num_ops) == 0);
783 op = (void *)(replyhead + 1);
784 rc = le32_to_cpu(replyhead->result);
785 bytes = le64_to_cpu(op->extent.length);
786 read_op = (le32_to_cpu(op->op) == CEPH_OSD_OP_READ);
787
788 dout("rbd_req_cb bytes=%lld readop=%d rc=%d\n", bytes, read_op, rc);
789
790 if (rc == -ENOENT && read_op) {
791 zero_bio_chain(req_data->bio, 0);
792 rc = 0;
793 } else if (rc == 0 && read_op && bytes < req_data->len) {
794 zero_bio_chain(req_data->bio, bytes);
795 bytes = req_data->len;
796 }
797
798 blk_end_request(req_data->rq, rc, bytes);
799
800 if (req_data->bio)
801 bio_chain_put(req_data->bio);
802
803 ceph_osdc_put_request(req);
804 kfree(req_data);
805}
806
807/*
808 * Do a synchronous ceph osd operation
809 */
810static int rbd_req_sync_op(struct rbd_device *dev,
811 struct ceph_snap_context *snapc,
812 u64 snapid,
813 int opcode,
814 int flags,
815 struct ceph_osd_req_op *orig_ops,
816 int num_reply,
817 const char *obj,
818 u64 ofs, u64 len,
819 char *buf)
820{
821 int ret;
822 struct page **pages;
823 int num_pages;
824 struct ceph_osd_req_op *ops = orig_ops;
825 u32 payload_len;
826
827 num_pages = calc_pages_for(ofs , len);
828 pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL);
829 if (IS_ERR(pages))
830 return PTR_ERR(pages);
831
832 if (!orig_ops) {
833 payload_len = (flags & CEPH_OSD_FLAG_WRITE ? len : 0);
834 ret = rbd_create_rw_ops(&ops, 1, opcode, payload_len);
835 if (ret < 0)
836 goto done;
837
838 if ((flags & CEPH_OSD_FLAG_WRITE) && buf) {
839 ret = ceph_copy_to_page_vector(pages, buf, ofs, len);
840 if (ret < 0)
841 goto done_ops;
842 }
843 }
844
845 ret = rbd_do_request(NULL, dev, snapc, snapid,
846 obj, ofs, len, NULL,
847 pages, num_pages,
848 flags,
849 ops,
850 2,
851 NULL);
852 if (ret < 0)
853 goto done_ops;
854
855 if ((flags & CEPH_OSD_FLAG_READ) && buf)
856 ret = ceph_copy_from_page_vector(pages, buf, ofs, ret);
857
858done_ops:
859 if (!orig_ops)
860 rbd_destroy_ops(ops);
861done:
862 ceph_release_page_vector(pages, num_pages);
863 return ret;
864}
865
866/*
867 * Do an asynchronous ceph osd operation
868 */
869static int rbd_do_op(struct request *rq,
870 struct rbd_device *rbd_dev ,
871 struct ceph_snap_context *snapc,
872 u64 snapid,
873 int opcode, int flags, int num_reply,
874 u64 ofs, u64 len,
875 struct bio *bio)
876{
877 char *seg_name;
878 u64 seg_ofs;
879 u64 seg_len;
880 int ret;
881 struct ceph_osd_req_op *ops;
882 u32 payload_len;
883
884 seg_name = kmalloc(RBD_MAX_SEG_NAME_LEN + 1, GFP_NOIO);
885 if (!seg_name)
886 return -ENOMEM;
887
888 seg_len = rbd_get_segment(&rbd_dev->header,
889 rbd_dev->header.block_name,
890 ofs, len,
891 seg_name, &seg_ofs);
892
893 payload_len = (flags & CEPH_OSD_FLAG_WRITE ? seg_len : 0);
894
895 ret = rbd_create_rw_ops(&ops, 1, opcode, payload_len);
896 if (ret < 0)
897 goto done;
898
899 /* we've taken care of segment sizes earlier when we
900 cloned the bios. We should never have a segment
901 truncated at this point */
902 BUG_ON(seg_len < len);
903
904 ret = rbd_do_request(rq, rbd_dev, snapc, snapid,
905 seg_name, seg_ofs, seg_len,
906 bio,
907 NULL, 0,
908 flags,
909 ops,
910 num_reply,
911 rbd_req_cb);
912done:
913 kfree(seg_name);
914 return ret;
915}
916
917/*
918 * Request async osd write
919 */
920static int rbd_req_write(struct request *rq,
921 struct rbd_device *rbd_dev,
922 struct ceph_snap_context *snapc,
923 u64 ofs, u64 len,
924 struct bio *bio)
925{
926 return rbd_do_op(rq, rbd_dev, snapc, CEPH_NOSNAP,
927 CEPH_OSD_OP_WRITE,
928 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
929 2,
930 ofs, len, bio);
931}
932
933/*
934 * Request async osd read
935 */
936static int rbd_req_read(struct request *rq,
937 struct rbd_device *rbd_dev,
938 u64 snapid,
939 u64 ofs, u64 len,
940 struct bio *bio)
941{
942 return rbd_do_op(rq, rbd_dev, NULL,
943 (snapid ? snapid : CEPH_NOSNAP),
944 CEPH_OSD_OP_READ,
945 CEPH_OSD_FLAG_READ,
946 2,
947 ofs, len, bio);
948}
949
950/*
951 * Request sync osd read
952 */
953static int rbd_req_sync_read(struct rbd_device *dev,
954 struct ceph_snap_context *snapc,
955 u64 snapid,
956 const char *obj,
957 u64 ofs, u64 len,
958 char *buf)
959{
960 return rbd_req_sync_op(dev, NULL,
961 (snapid ? snapid : CEPH_NOSNAP),
962 CEPH_OSD_OP_READ,
963 CEPH_OSD_FLAG_READ,
964 NULL,
965 1, obj, ofs, len, buf);
966}
967
968/*
969 * Request sync osd read
970 */
971static int rbd_req_sync_rollback_obj(struct rbd_device *dev,
972 u64 snapid,
973 const char *obj)
974{
975 struct ceph_osd_req_op *ops;
976 int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_ROLLBACK, 0);
977 if (ret < 0)
978 return ret;
979
980 ops[0].snap.snapid = snapid;
981
982 ret = rbd_req_sync_op(dev, NULL,
983 CEPH_NOSNAP,
984 0,
985 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
986 ops,
987 1, obj, 0, 0, NULL);
988
989 rbd_destroy_ops(ops);
990
991 if (ret < 0)
992 return ret;
993
994 return ret;
995}
996
997/*
998 * Request sync osd read
999 */
1000static int rbd_req_sync_exec(struct rbd_device *dev,
1001 const char *obj,
1002 const char *cls,
1003 const char *method,
1004 const char *data,
1005 int len)
1006{
1007 struct ceph_osd_req_op *ops;
1008 int cls_len = strlen(cls);
1009 int method_len = strlen(method);
1010 int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_CALL,
1011 cls_len + method_len + len);
1012 if (ret < 0)
1013 return ret;
1014
1015 ops[0].cls.class_name = cls;
1016 ops[0].cls.class_len = (__u8)cls_len;
1017 ops[0].cls.method_name = method;
1018 ops[0].cls.method_len = (__u8)method_len;
1019 ops[0].cls.argc = 0;
1020 ops[0].cls.indata = data;
1021 ops[0].cls.indata_len = len;
1022
1023 ret = rbd_req_sync_op(dev, NULL,
1024 CEPH_NOSNAP,
1025 0,
1026 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
1027 ops,
1028 1, obj, 0, 0, NULL);
1029
1030 rbd_destroy_ops(ops);
1031
1032 dout("cls_exec returned %d\n", ret);
1033 return ret;
1034}
1035
1036/*
1037 * block device queue callback
1038 */
1039static void rbd_rq_fn(struct request_queue *q)
1040{
1041 struct rbd_device *rbd_dev = q->queuedata;
1042 struct request *rq;
1043 struct bio_pair *bp = NULL;
1044
1045 rq = blk_fetch_request(q);
1046
1047 while (1) {
1048 struct bio *bio;
1049 struct bio *rq_bio, *next_bio = NULL;
1050 bool do_write;
1051 int size, op_size = 0;
1052 u64 ofs;
1053
1054 /* peek at request from block layer */
1055 if (!rq)
1056 break;
1057
1058 dout("fetched request\n");
1059
1060 /* filter out block requests we don't understand */
1061 if ((rq->cmd_type != REQ_TYPE_FS)) {
1062 __blk_end_request_all(rq, 0);
1063 goto next;
1064 }
1065
1066 /* deduce our operation (read, write) */
1067 do_write = (rq_data_dir(rq) == WRITE);
1068
1069 size = blk_rq_bytes(rq);
1070 ofs = blk_rq_pos(rq) * 512ULL;
1071 rq_bio = rq->bio;
1072 if (do_write && rbd_dev->read_only) {
1073 __blk_end_request_all(rq, -EROFS);
1074 goto next;
1075 }
1076
1077 spin_unlock_irq(q->queue_lock);
1078
1079 dout("%s 0x%x bytes at 0x%llx\n",
1080 do_write ? "write" : "read",
1081 size, blk_rq_pos(rq) * 512ULL);
1082
1083 do {
1084 /* a bio clone to be passed down to OSD req */
1085 dout("rq->bio->bi_vcnt=%d\n", rq->bio->bi_vcnt);
1086 op_size = rbd_get_segment(&rbd_dev->header,
1087 rbd_dev->header.block_name,
1088 ofs, size,
1089 NULL, NULL);
1090 bio = bio_chain_clone(&rq_bio, &next_bio, &bp,
1091 op_size, GFP_ATOMIC);
1092 if (!bio) {
1093 spin_lock_irq(q->queue_lock);
1094 __blk_end_request_all(rq, -ENOMEM);
1095 goto next;
1096 }
1097
1098 /* init OSD command: write or read */
1099 if (do_write)
1100 rbd_req_write(rq, rbd_dev,
1101 rbd_dev->header.snapc,
1102 ofs,
1103 op_size, bio);
1104 else
1105 rbd_req_read(rq, rbd_dev,
1106 cur_snap_id(rbd_dev),
1107 ofs,
1108 op_size, bio);
1109
1110 size -= op_size;
1111 ofs += op_size;
1112
1113 rq_bio = next_bio;
1114 } while (size > 0);
1115
1116 if (bp)
1117 bio_pair_release(bp);
1118
1119 spin_lock_irq(q->queue_lock);
1120next:
1121 rq = blk_fetch_request(q);
1122 }
1123}
1124
1125/*
1126 * a queue callback. Makes sure that we don't create a bio that spans across
1127 * multiple osd objects. One exception would be with a single page bios,
1128 * which we handle later at bio_chain_clone
1129 */
1130static int rbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bmd,
1131 struct bio_vec *bvec)
1132{
1133 struct rbd_device *rbd_dev = q->queuedata;
1134 unsigned int chunk_sectors = 1 << (rbd_dev->header.obj_order - 9);
1135 sector_t sector = bmd->bi_sector + get_start_sect(bmd->bi_bdev);
1136 unsigned int bio_sectors = bmd->bi_size >> 9;
1137 int max;
1138
1139 max = (chunk_sectors - ((sector & (chunk_sectors - 1))
1140 + bio_sectors)) << 9;
1141 if (max < 0)
1142 max = 0; /* bio_add cannot handle a negative return */
1143 if (max <= bvec->bv_len && bio_sectors == 0)
1144 return bvec->bv_len;
1145 return max;
1146}
1147
1148static void rbd_free_disk(struct rbd_device *rbd_dev)
1149{
1150 struct gendisk *disk = rbd_dev->disk;
1151
1152 if (!disk)
1153 return;
1154
1155 rbd_header_free(&rbd_dev->header);
1156
1157 if (disk->flags & GENHD_FL_UP)
1158 del_gendisk(disk);
1159 if (disk->queue)
1160 blk_cleanup_queue(disk->queue);
1161 put_disk(disk);
1162}
1163
1164/*
1165 * reload the ondisk the header
1166 */
1167static int rbd_read_header(struct rbd_device *rbd_dev,
1168 struct rbd_image_header *header)
1169{
1170 ssize_t rc;
1171 struct rbd_image_header_ondisk *dh;
1172 int snap_count = 0;
1173 u64 snap_names_len = 0;
1174
1175 while (1) {
1176 int len = sizeof(*dh) +
1177 snap_count * sizeof(struct rbd_image_snap_ondisk) +
1178 snap_names_len;
1179
1180 rc = -ENOMEM;
1181 dh = kmalloc(len, GFP_KERNEL);
1182 if (!dh)
1183 return -ENOMEM;
1184
1185 rc = rbd_req_sync_read(rbd_dev,
1186 NULL, CEPH_NOSNAP,
1187 rbd_dev->obj_md_name,
1188 0, len,
1189 (char *)dh);
1190 if (rc < 0)
1191 goto out_dh;
1192
1193 rc = rbd_header_from_disk(header, dh, snap_count, GFP_KERNEL);
1194 if (rc < 0)
1195 goto out_dh;
1196
1197 if (snap_count != header->total_snaps) {
1198 snap_count = header->total_snaps;
1199 snap_names_len = header->snap_names_len;
1200 rbd_header_free(header);
1201 kfree(dh);
1202 continue;
1203 }
1204 break;
1205 }
1206
1207out_dh:
1208 kfree(dh);
1209 return rc;
1210}
1211
1212/*
1213 * create a snapshot
1214 */
1215static int rbd_header_add_snap(struct rbd_device *dev,
1216 const char *snap_name,
1217 gfp_t gfp_flags)
1218{
1219 int name_len = strlen(snap_name);
1220 u64 new_snapid;
1221 int ret;
1222 void *data, *data_start, *data_end;
1223
1224 /* we should create a snapshot only if we're pointing at the head */
1225 if (dev->cur_snap)
1226 return -EINVAL;
1227
1228 ret = ceph_monc_create_snapid(&dev->client->monc, dev->poolid,
1229 &new_snapid);
1230 dout("created snapid=%lld\n", new_snapid);
1231 if (ret < 0)
1232 return ret;
1233
1234 data = kmalloc(name_len + 16, gfp_flags);
1235 if (!data)
1236 return -ENOMEM;
1237
1238 data_start = data;
1239 data_end = data + name_len + 16;
1240
1241 ceph_encode_string_safe(&data, data_end, snap_name, name_len, bad);
1242 ceph_encode_64_safe(&data, data_end, new_snapid, bad);
1243
1244 ret = rbd_req_sync_exec(dev, dev->obj_md_name, "rbd", "snap_add",
1245 data_start, data - data_start);
1246
1247 kfree(data_start);
1248
1249 if (ret < 0)
1250 return ret;
1251
1252 dev->header.snapc->seq = new_snapid;
1253
1254 return 0;
1255bad:
1256 return -ERANGE;
1257}
1258
1259/*
1260 * only read the first part of the ondisk header, without the snaps info
1261 */
1262static int rbd_update_snaps(struct rbd_device *rbd_dev)
1263{
1264 int ret;
1265 struct rbd_image_header h;
1266 u64 snap_seq;
1267
1268 ret = rbd_read_header(rbd_dev, &h);
1269 if (ret < 0)
1270 return ret;
1271
1272 down_write(&rbd_dev->header.snap_rwsem);
1273
1274 snap_seq = rbd_dev->header.snapc->seq;
1275
1276 kfree(rbd_dev->header.snapc);
1277 kfree(rbd_dev->header.snap_names);
1278 kfree(rbd_dev->header.snap_sizes);
1279
1280 rbd_dev->header.total_snaps = h.total_snaps;
1281 rbd_dev->header.snapc = h.snapc;
1282 rbd_dev->header.snap_names = h.snap_names;
1283 rbd_dev->header.snap_sizes = h.snap_sizes;
1284 rbd_dev->header.snapc->seq = snap_seq;
1285
1286 up_write(&rbd_dev->header.snap_rwsem);
1287
1288 return 0;
1289}
1290
1291static int rbd_init_disk(struct rbd_device *rbd_dev)
1292{
1293 struct gendisk *disk;
1294 struct request_queue *q;
1295 int rc;
1296 u64 total_size = 0;
1297
1298 /* contact OSD, request size info about the object being mapped */
1299 rc = rbd_read_header(rbd_dev, &rbd_dev->header);
1300 if (rc)
1301 return rc;
1302
1303 rc = rbd_header_set_snap(rbd_dev, rbd_dev->snap_name, &total_size);
1304 if (rc)
1305 return rc;
1306
1307 /* create gendisk info */
1308 rc = -ENOMEM;
1309 disk = alloc_disk(RBD_MINORS_PER_MAJOR);
1310 if (!disk)
1311 goto out;
1312
1313 sprintf(disk->disk_name, DRV_NAME "%d", rbd_dev->id);
1314 disk->major = rbd_dev->major;
1315 disk->first_minor = 0;
1316 disk->fops = &rbd_bd_ops;
1317 disk->private_data = rbd_dev;
1318
1319 /* init rq */
1320 rc = -ENOMEM;
1321 q = blk_init_queue(rbd_rq_fn, &rbd_dev->lock);
1322 if (!q)
1323 goto out_disk;
1324 blk_queue_merge_bvec(q, rbd_merge_bvec);
1325 disk->queue = q;
1326
1327 q->queuedata = rbd_dev;
1328
1329 rbd_dev->disk = disk;
1330 rbd_dev->q = q;
1331
1332 /* finally, announce the disk to the world */
1333 set_capacity(disk, total_size / 512ULL);
1334 add_disk(disk);
1335
1336 pr_info("%s: added with size 0x%llx\n",
1337 disk->disk_name, (unsigned long long)total_size);
1338 return 0;
1339
1340out_disk:
1341 put_disk(disk);
1342out:
1343 return rc;
1344}
1345
1346/********************************************************************
1347 * /sys/class/rbd/
1348 * add map rados objects to blkdev
1349 * remove unmap rados objects
1350 * list show mappings
1351 *******************************************************************/
1352
1353static void class_rbd_release(struct class *cls)
1354{
1355 kfree(cls);
1356}
1357
1358static ssize_t class_rbd_list(struct class *c,
1359 struct class_attribute *attr,
1360 char *data)
1361{
1362 int n = 0;
1363 struct list_head *tmp;
1364 int max = PAGE_SIZE;
1365
1366 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1367
1368 n += snprintf(data, max,
1369 "#id\tmajor\tclient_name\tpool\tname\tsnap\tKB\n");
1370
1371 list_for_each(tmp, &rbd_dev_list) {
1372 struct rbd_device *rbd_dev;
1373
1374 rbd_dev = list_entry(tmp, struct rbd_device, node);
1375 n += snprintf(data+n, max-n,
1376 "%d\t%d\tclient%lld\t%s\t%s\t%s\t%lld\n",
1377 rbd_dev->id,
1378 rbd_dev->major,
1379 ceph_client_id(rbd_dev->client),
1380 rbd_dev->pool_name,
1381 rbd_dev->obj, rbd_dev->snap_name,
1382 rbd_dev->header.image_size >> 10);
1383 if (n == max)
1384 break;
1385 }
1386
1387 mutex_unlock(&ctl_mutex);
1388 return n;
1389}
1390
1391static ssize_t class_rbd_add(struct class *c,
1392 struct class_attribute *attr,
1393 const char *buf, size_t count)
1394{
1395 struct ceph_osd_client *osdc;
1396 struct rbd_device *rbd_dev;
1397 ssize_t rc = -ENOMEM;
1398 int irc, new_id = 0;
1399 struct list_head *tmp;
1400 char *mon_dev_name;
1401 char *options;
1402
1403 if (!try_module_get(THIS_MODULE))
1404 return -ENODEV;
1405
1406 mon_dev_name = kmalloc(RBD_MAX_OPT_LEN, GFP_KERNEL);
1407 if (!mon_dev_name)
1408 goto err_out_mod;
1409
1410 options = kmalloc(RBD_MAX_OPT_LEN, GFP_KERNEL);
1411 if (!options)
1412 goto err_mon_dev;
1413
1414 /* new rbd_device object */
1415 rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
1416 if (!rbd_dev)
1417 goto err_out_opt;
1418
1419 /* static rbd_device initialization */
1420 spin_lock_init(&rbd_dev->lock);
1421 INIT_LIST_HEAD(&rbd_dev->node);
1422
1423 /* generate unique id: find highest unique id, add one */
1424 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1425
1426 list_for_each(tmp, &rbd_dev_list) {
1427 struct rbd_device *rbd_dev;
1428
1429 rbd_dev = list_entry(tmp, struct rbd_device, node);
1430 if (rbd_dev->id >= new_id)
1431 new_id = rbd_dev->id + 1;
1432 }
1433
1434 rbd_dev->id = new_id;
1435
1436 /* add to global list */
1437 list_add_tail(&rbd_dev->node, &rbd_dev_list);
1438
1439 /* parse add command */
1440 if (sscanf(buf, "%" __stringify(RBD_MAX_OPT_LEN) "s "
1441 "%" __stringify(RBD_MAX_OPT_LEN) "s "
1442 "%" __stringify(RBD_MAX_POOL_NAME_LEN) "s "
1443 "%" __stringify(RBD_MAX_OBJ_NAME_LEN) "s"
1444 "%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
1445 mon_dev_name, options, rbd_dev->pool_name,
1446 rbd_dev->obj, rbd_dev->snap_name) < 4) {
1447 rc = -EINVAL;
1448 goto err_out_slot;
1449 }
1450
1451 if (rbd_dev->snap_name[0] == 0)
1452 rbd_dev->snap_name[0] = '-';
1453
1454 rbd_dev->obj_len = strlen(rbd_dev->obj);
1455 snprintf(rbd_dev->obj_md_name, sizeof(rbd_dev->obj_md_name), "%s%s",
1456 rbd_dev->obj, RBD_SUFFIX);
1457
1458 /* initialize rest of new object */
1459 snprintf(rbd_dev->name, DEV_NAME_LEN, DRV_NAME "%d", rbd_dev->id);
1460 rc = rbd_get_client(rbd_dev, mon_dev_name, options);
1461 if (rc < 0)
1462 goto err_out_slot;
1463
1464 mutex_unlock(&ctl_mutex);
1465
1466 /* pick the pool */
1467 osdc = &rbd_dev->client->osdc;
1468 rc = ceph_pg_poolid_by_name(osdc->osdmap, rbd_dev->pool_name);
1469 if (rc < 0)
1470 goto err_out_client;
1471 rbd_dev->poolid = rc;
1472
1473 /* register our block device */
1474 irc = register_blkdev(0, rbd_dev->name);
1475 if (irc < 0) {
1476 rc = irc;
1477 goto err_out_client;
1478 }
1479 rbd_dev->major = irc;
1480
1481 /* set up and announce blkdev mapping */
1482 rc = rbd_init_disk(rbd_dev);
1483 if (rc)
1484 goto err_out_blkdev;
1485
1486 return count;
1487
1488err_out_blkdev:
1489 unregister_blkdev(rbd_dev->major, rbd_dev->name);
1490err_out_client:
1491 rbd_put_client(rbd_dev);
1492 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1493err_out_slot:
1494 list_del_init(&rbd_dev->node);
1495 mutex_unlock(&ctl_mutex);
1496
1497 kfree(rbd_dev);
1498err_out_opt:
1499 kfree(options);
1500err_mon_dev:
1501 kfree(mon_dev_name);
1502err_out_mod:
1503 dout("Error adding device %s\n", buf);
1504 module_put(THIS_MODULE);
1505 return rc;
1506}
1507
1508static struct rbd_device *__rbd_get_dev(unsigned long id)
1509{
1510 struct list_head *tmp;
1511 struct rbd_device *rbd_dev;
1512
1513 list_for_each(tmp, &rbd_dev_list) {
1514 rbd_dev = list_entry(tmp, struct rbd_device, node);
1515 if (rbd_dev->id == id)
1516 return rbd_dev;
1517 }
1518 return NULL;
1519}
1520
1521static ssize_t class_rbd_remove(struct class *c,
1522 struct class_attribute *attr,
1523 const char *buf,
1524 size_t count)
1525{
1526 struct rbd_device *rbd_dev = NULL;
1527 int target_id, rc;
1528 unsigned long ul;
1529
1530 rc = strict_strtoul(buf, 10, &ul);
1531 if (rc)
1532 return rc;
1533
1534 /* convert to int; abort if we lost anything in the conversion */
1535 target_id = (int) ul;
1536 if (target_id != ul)
1537 return -EINVAL;
1538
1539 /* remove object from list immediately */
1540 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1541
1542 rbd_dev = __rbd_get_dev(target_id);
1543 if (rbd_dev)
1544 list_del_init(&rbd_dev->node);
1545
1546 mutex_unlock(&ctl_mutex);
1547
1548 if (!rbd_dev)
1549 return -ENOENT;
1550
1551 rbd_put_client(rbd_dev);
1552
1553 /* clean up and free blkdev */
1554 rbd_free_disk(rbd_dev);
1555 unregister_blkdev(rbd_dev->major, rbd_dev->name);
1556 kfree(rbd_dev);
1557
1558 /* release module ref */
1559 module_put(THIS_MODULE);
1560
1561 return count;
1562}
1563
1564static ssize_t class_rbd_snaps_list(struct class *c,
1565 struct class_attribute *attr,
1566 char *data)
1567{
1568 struct rbd_device *rbd_dev = NULL;
1569 struct list_head *tmp;
1570 struct rbd_image_header *header;
1571 int i, n = 0, max = PAGE_SIZE;
1572 int ret;
1573
1574 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1575
1576 n += snprintf(data, max, "#id\tsnap\tKB\n");
1577
1578 list_for_each(tmp, &rbd_dev_list) {
1579 char *names, *p;
1580 struct ceph_snap_context *snapc;
1581
1582 rbd_dev = list_entry(tmp, struct rbd_device, node);
1583 header = &rbd_dev->header;
1584
1585 down_read(&header->snap_rwsem);
1586
1587 names = header->snap_names;
1588 snapc = header->snapc;
1589
1590 n += snprintf(data + n, max - n, "%d\t%s\t%lld%s\n",
1591 rbd_dev->id, RBD_SNAP_HEAD_NAME,
1592 header->image_size >> 10,
1593 (!rbd_dev->cur_snap ? " (*)" : ""));
1594 if (n == max)
1595 break;
1596
1597 p = names;
1598 for (i = 0; i < header->total_snaps; i++, p += strlen(p) + 1) {
1599 n += snprintf(data + n, max - n, "%d\t%s\t%lld%s\n",
1600 rbd_dev->id, p, header->snap_sizes[i] >> 10,
1601 (rbd_dev->cur_snap &&
1602 (snap_index(header, i) == rbd_dev->cur_snap) ?
1603 " (*)" : ""));
1604 if (n == max)
1605 break;
1606 }
1607
1608 up_read(&header->snap_rwsem);
1609 }
1610
1611
1612 ret = n;
1613 mutex_unlock(&ctl_mutex);
1614 return ret;
1615}
1616
1617static ssize_t class_rbd_snaps_refresh(struct class *c,
1618 struct class_attribute *attr,
1619 const char *buf,
1620 size_t count)
1621{
1622 struct rbd_device *rbd_dev = NULL;
1623 int target_id, rc;
1624 unsigned long ul;
1625 int ret = count;
1626
1627 rc = strict_strtoul(buf, 10, &ul);
1628 if (rc)
1629 return rc;
1630
1631 /* convert to int; abort if we lost anything in the conversion */
1632 target_id = (int) ul;
1633 if (target_id != ul)
1634 return -EINVAL;
1635
1636 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1637
1638 rbd_dev = __rbd_get_dev(target_id);
1639 if (!rbd_dev) {
1640 ret = -ENOENT;
1641 goto done;
1642 }
1643
1644 rc = rbd_update_snaps(rbd_dev);
1645 if (rc < 0)
1646 ret = rc;
1647
1648done:
1649 mutex_unlock(&ctl_mutex);
1650 return ret;
1651}
1652
1653static ssize_t class_rbd_snap_create(struct class *c,
1654 struct class_attribute *attr,
1655 const char *buf,
1656 size_t count)
1657{
1658 struct rbd_device *rbd_dev = NULL;
1659 int target_id, ret;
1660 char *name;
1661
1662 name = kmalloc(RBD_MAX_SNAP_NAME_LEN + 1, GFP_KERNEL);
1663 if (!name)
1664 return -ENOMEM;
1665
1666 /* parse snaps add command */
1667 if (sscanf(buf, "%d "
1668 "%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
1669 &target_id,
1670 name) != 2) {
1671 ret = -EINVAL;
1672 goto done;
1673 }
1674
1675 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1676
1677 rbd_dev = __rbd_get_dev(target_id);
1678 if (!rbd_dev) {
1679 ret = -ENOENT;
1680 goto done_unlock;
1681 }
1682
1683 ret = rbd_header_add_snap(rbd_dev,
1684 name, GFP_KERNEL);
1685 if (ret < 0)
1686 goto done_unlock;
1687
1688 ret = rbd_update_snaps(rbd_dev);
1689 if (ret < 0)
1690 goto done_unlock;
1691
1692 ret = count;
1693done_unlock:
1694 mutex_unlock(&ctl_mutex);
1695done:
1696 kfree(name);
1697 return ret;
1698}
1699
1700static ssize_t class_rbd_rollback(struct class *c,
1701 struct class_attribute *attr,
1702 const char *buf,
1703 size_t count)
1704{
1705 struct rbd_device *rbd_dev = NULL;
1706 int target_id, ret;
1707 u64 snapid;
1708 char snap_name[RBD_MAX_SNAP_NAME_LEN];
1709 u64 cur_ofs;
1710 char *seg_name;
1711
1712 /* parse snaps add command */
1713 if (sscanf(buf, "%d "
1714 "%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
1715 &target_id,
1716 snap_name) != 2) {
1717 return -EINVAL;
1718 }
1719
1720 ret = -ENOMEM;
1721 seg_name = kmalloc(RBD_MAX_SEG_NAME_LEN + 1, GFP_NOIO);
1722 if (!seg_name)
1723 return ret;
1724
1725 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1726
1727 rbd_dev = __rbd_get_dev(target_id);
1728 if (!rbd_dev) {
1729 ret = -ENOENT;
1730 goto done_unlock;
1731 }
1732
1733 ret = snap_by_name(&rbd_dev->header, snap_name, &snapid, NULL);
1734 if (ret < 0)
1735 goto done_unlock;
1736
1737 dout("snapid=%lld\n", snapid);
1738
1739 cur_ofs = 0;
1740 while (cur_ofs < rbd_dev->header.image_size) {
1741 cur_ofs += rbd_get_segment(&rbd_dev->header,
1742 rbd_dev->obj,
1743 cur_ofs, (u64)-1,
1744 seg_name, NULL);
1745 dout("seg_name=%s\n", seg_name);
1746
1747 ret = rbd_req_sync_rollback_obj(rbd_dev, snapid, seg_name);
1748 if (ret < 0)
1749 pr_warning("could not roll back obj %s err=%d\n",
1750 seg_name, ret);
1751 }
1752
1753 ret = rbd_update_snaps(rbd_dev);
1754 if (ret < 0)
1755 goto done_unlock;
1756
1757 ret = count;
1758
1759done_unlock:
1760 mutex_unlock(&ctl_mutex);
1761 kfree(seg_name);
1762
1763 return ret;
1764}
1765
1766static struct class_attribute class_rbd_attrs[] = {
1767 __ATTR(add, 0200, NULL, class_rbd_add),
1768 __ATTR(remove, 0200, NULL, class_rbd_remove),
1769 __ATTR(list, 0444, class_rbd_list, NULL),
1770 __ATTR(snaps_refresh, 0200, NULL, class_rbd_snaps_refresh),
1771 __ATTR(snap_create, 0200, NULL, class_rbd_snap_create),
1772 __ATTR(snaps_list, 0444, class_rbd_snaps_list, NULL),
1773 __ATTR(snap_rollback, 0200, NULL, class_rbd_rollback),
1774 __ATTR_NULL
1775};
1776
1777/*
1778 * create control files in sysfs
1779 * /sys/class/rbd/...
1780 */
1781static int rbd_sysfs_init(void)
1782{
1783 int ret = -ENOMEM;
1784
1785 class_rbd = kzalloc(sizeof(*class_rbd), GFP_KERNEL);
1786 if (!class_rbd)
1787 goto out;
1788
1789 class_rbd->name = DRV_NAME;
1790 class_rbd->owner = THIS_MODULE;
1791 class_rbd->class_release = class_rbd_release;
1792 class_rbd->class_attrs = class_rbd_attrs;
1793
1794 ret = class_register(class_rbd);
1795 if (ret)
1796 goto out_class;
1797 return 0;
1798
1799out_class:
1800 kfree(class_rbd);
1801 class_rbd = NULL;
1802 pr_err(DRV_NAME ": failed to create class rbd\n");
1803out:
1804 return ret;
1805}
1806
1807static void rbd_sysfs_cleanup(void)
1808{
1809 if (class_rbd)
1810 class_destroy(class_rbd);
1811 class_rbd = NULL;
1812}
1813
1814int __init rbd_init(void)
1815{
1816 int rc;
1817
1818 rc = rbd_sysfs_init();
1819 if (rc)
1820 return rc;
1821 spin_lock_init(&node_lock);
1822 pr_info("loaded " DRV_NAME_LONG "\n");
1823 return 0;
1824}
1825
1826void __exit rbd_exit(void)
1827{
1828 rbd_sysfs_cleanup();
1829}
1830
1831module_init(rbd_init);
1832module_exit(rbd_exit);
1833
1834MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1835MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1836MODULE_DESCRIPTION("rados block device");
1837
1838/* following authorship retained from original osdblk.c */
1839MODULE_AUTHOR("Jeff Garzik <jeff@garzik.org>");
1840
1841MODULE_LICENSE("GPL");
diff --git a/drivers/block/rbd_types.h b/drivers/block/rbd_types.h
new file mode 100644
index 000000000000..fc6c678aa2cb
--- /dev/null
+++ b/drivers/block/rbd_types.h
@@ -0,0 +1,73 @@
1/*
2 * Ceph - scalable distributed file system
3 *
4 * Copyright (C) 2004-2010 Sage Weil <sage@newdream.net>
5 *
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software
9 * Foundation. See file COPYING.
10 *
11 */
12
13#ifndef CEPH_RBD_TYPES_H
14#define CEPH_RBD_TYPES_H
15
16#include <linux/types.h>
17
18/*
19 * rbd image 'foo' consists of objects
20 * foo.rbd - image metadata
21 * foo.00000000
22 * foo.00000001
23 * ... - data
24 */
25
26#define RBD_SUFFIX ".rbd"
27#define RBD_DIRECTORY "rbd_directory"
28#define RBD_INFO "rbd_info"
29
30#define RBD_DEFAULT_OBJ_ORDER 22 /* 4MB */
31#define RBD_MIN_OBJ_ORDER 16
32#define RBD_MAX_OBJ_ORDER 30
33
34#define RBD_MAX_OBJ_NAME_LEN 96
35#define RBD_MAX_SEG_NAME_LEN 128
36
37#define RBD_COMP_NONE 0
38#define RBD_CRYPT_NONE 0
39
40#define RBD_HEADER_TEXT "<<< Rados Block Device Image >>>\n"
41#define RBD_HEADER_SIGNATURE "RBD"
42#define RBD_HEADER_VERSION "001.005"
43
44struct rbd_info {
45 __le64 max_id;
46} __attribute__ ((packed));
47
48struct rbd_image_snap_ondisk {
49 __le64 id;
50 __le64 image_size;
51} __attribute__((packed));
52
53struct rbd_image_header_ondisk {
54 char text[40];
55 char block_name[24];
56 char signature[4];
57 char version[8];
58 struct {
59 __u8 order;
60 __u8 crypt_type;
61 __u8 comp_type;
62 __u8 unused;
63 } __attribute__((packed)) options;
64 __le64 image_size;
65 __le64 snap_seq;
66 __le32 snap_count;
67 __le32 reserved;
68 __le64 snap_names_len;
69 struct rbd_image_snap_ondisk snaps[0];
70} __attribute__((packed));
71
72
73#endif
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 2e46815876df..75333d0a3327 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -20,7 +20,7 @@
20#include <linux/fd.h> 20#include <linux/fd.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/blkdev.h> 22#include <linux/blkdev.h>
23#include <linux/smp_lock.h> 23#include <linux/mutex.h>
24#include <linux/hdreg.h> 24#include <linux/hdreg.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
@@ -222,6 +222,7 @@ extern int swim_read_sector_header(struct swim __iomem *base,
222extern int swim_read_sector_data(struct swim __iomem *base, 222extern int swim_read_sector_data(struct swim __iomem *base,
223 unsigned char *data); 223 unsigned char *data);
224 224
225static DEFINE_MUTEX(swim_mutex);
225static inline void set_swim_mode(struct swim __iomem *base, int enable) 226static inline void set_swim_mode(struct swim __iomem *base, int enable)
226{ 227{
227 struct iwm __iomem *iwm_base; 228 struct iwm __iomem *iwm_base;
@@ -666,9 +667,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
666{ 667{
667 int ret; 668 int ret;
668 669
669 lock_kernel(); 670 mutex_lock(&swim_mutex);
670 ret = floppy_open(bdev, mode); 671 ret = floppy_open(bdev, mode);
671 unlock_kernel(); 672 mutex_unlock(&swim_mutex);
672 673
673 return ret; 674 return ret;
674} 675}
@@ -678,7 +679,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
678 struct floppy_state *fs = disk->private_data; 679 struct floppy_state *fs = disk->private_data;
679 struct swim __iomem *base = fs->swd->base; 680 struct swim __iomem *base = fs->swd->base;
680 681
681 lock_kernel(); 682 mutex_lock(&swim_mutex);
682 if (fs->ref_count < 0) 683 if (fs->ref_count < 0)
683 fs->ref_count = 0; 684 fs->ref_count = 0;
684 else if (fs->ref_count > 0) 685 else if (fs->ref_count > 0)
@@ -686,7 +687,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
686 687
687 if (fs->ref_count == 0) 688 if (fs->ref_count == 0)
688 swim_motor(base, OFF); 689 swim_motor(base, OFF);
689 unlock_kernel(); 690 mutex_unlock(&swim_mutex);
690 691
691 return 0; 692 return 0;
692} 693}
@@ -704,9 +705,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
704 case FDEJECT: 705 case FDEJECT:
705 if (fs->ref_count != 1) 706 if (fs->ref_count != 1)
706 return -EBUSY; 707 return -EBUSY;
707 lock_kernel(); 708 mutex_lock(&swim_mutex);
708 err = floppy_eject(fs); 709 err = floppy_eject(fs);
709 unlock_kernel(); 710 mutex_unlock(&swim_mutex);
710 return err; 711 return err;
711 712
712 case FDGETPRM: 713 case FDGETPRM:
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index cc6a3864822c..bf3a5b859299 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -25,7 +25,7 @@
25#include <linux/ioctl.h> 25#include <linux/ioctl.h>
26#include <linux/blkdev.h> 26#include <linux/blkdev.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/smp_lock.h> 28#include <linux/mutex.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/spinlock.h> 30#include <linux/spinlock.h>
31#include <asm/io.h> 31#include <asm/io.h>
@@ -36,6 +36,7 @@
36#include <asm/machdep.h> 36#include <asm/machdep.h>
37#include <asm/pmac_feature.h> 37#include <asm/pmac_feature.h>
38 38
39static DEFINE_MUTEX(swim3_mutex);
39static struct request_queue *swim3_queue; 40static struct request_queue *swim3_queue;
40static struct gendisk *disks[2]; 41static struct gendisk *disks[2];
41static struct request *fd_req; 42static struct request *fd_req;
@@ -873,9 +874,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
873{ 874{
874 int ret; 875 int ret;
875 876
876 lock_kernel(); 877 mutex_lock(&swim3_mutex);
877 ret = floppy_locked_ioctl(bdev, mode, cmd, param); 878 ret = floppy_locked_ioctl(bdev, mode, cmd, param);
878 unlock_kernel(); 879 mutex_unlock(&swim3_mutex);
879 880
880 return ret; 881 return ret;
881} 882}
@@ -953,9 +954,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
953{ 954{
954 int ret; 955 int ret;
955 956
956 lock_kernel(); 957 mutex_lock(&swim3_mutex);
957 ret = floppy_open(bdev, mode); 958 ret = floppy_open(bdev, mode);
958 unlock_kernel(); 959 mutex_unlock(&swim3_mutex);
959 960
960 return ret; 961 return ret;
961} 962}
@@ -964,13 +965,13 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
964{ 965{
965 struct floppy_state *fs = disk->private_data; 966 struct floppy_state *fs = disk->private_data;
966 struct swim3 __iomem *sw = fs->swim3; 967 struct swim3 __iomem *sw = fs->swim3;
967 lock_kernel(); 968 mutex_lock(&swim3_mutex);
968 if (fs->ref_count > 0 && --fs->ref_count == 0) { 969 if (fs->ref_count > 0 && --fs->ref_count == 0) {
969 swim3_action(fs, MOTOR_OFF); 970 swim3_action(fs, MOTOR_OFF);
970 out_8(&sw->control_bic, 0xff); 971 out_8(&sw->control_bic, 0xff);
971 swim3_select(fs, RELAX); 972 swim3_select(fs, RELAX);
972 } 973 }
973 unlock_kernel(); 974 mutex_unlock(&swim3_mutex);
974 return 0; 975 return 0;
975} 976}
976 977
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index c48e14878582..b5690a045a01 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -28,7 +28,7 @@
28#include <linux/timer.h> 28#include <linux/timer.h>
29#include <linux/scatterlist.h> 29#include <linux/scatterlist.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/smp_lock.h> 31#include <linux/mutex.h>
32#include <scsi/scsi.h> 32#include <scsi/scsi.h>
33 33
34#define DRV_NAME "ub" 34#define DRV_NAME "ub"
@@ -248,6 +248,7 @@ struct ub_completion {
248 spinlock_t lock; 248 spinlock_t lock;
249}; 249};
250 250
251static DEFINE_MUTEX(ub_mutex);
251static inline void ub_init_completion(struct ub_completion *x) 252static inline void ub_init_completion(struct ub_completion *x)
252{ 253{
253 x->done = 0; 254 x->done = 0;
@@ -1715,9 +1716,9 @@ static int ub_bd_unlocked_open(struct block_device *bdev, fmode_t mode)
1715{ 1716{
1716 int ret; 1717 int ret;
1717 1718
1718 lock_kernel(); 1719 mutex_lock(&ub_mutex);
1719 ret = ub_bd_open(bdev, mode); 1720 ret = ub_bd_open(bdev, mode);
1720 unlock_kernel(); 1721 mutex_unlock(&ub_mutex);
1721 1722
1722 return ret; 1723 return ret;
1723} 1724}
@@ -1730,9 +1731,9 @@ static int ub_bd_release(struct gendisk *disk, fmode_t mode)
1730 struct ub_lun *lun = disk->private_data; 1731 struct ub_lun *lun = disk->private_data;
1731 struct ub_dev *sc = lun->udev; 1732 struct ub_dev *sc = lun->udev;
1732 1733
1733 lock_kernel(); 1734 mutex_lock(&ub_mutex);
1734 ub_put(sc); 1735 ub_put(sc);
1735 unlock_kernel(); 1736 mutex_unlock(&ub_mutex);
1736 1737
1737 return 0; 1738 return 0;
1738} 1739}
@@ -1747,9 +1748,9 @@ static int ub_bd_ioctl(struct block_device *bdev, fmode_t mode,
1747 void __user *usermem = (void __user *) arg; 1748 void __user *usermem = (void __user *) arg;
1748 int ret; 1749 int ret;
1749 1750
1750 lock_kernel(); 1751 mutex_lock(&ub_mutex);
1751 ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem); 1752 ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem);
1752 unlock_kernel(); 1753 mutex_unlock(&ub_mutex);
1753 1754
1754 return ret; 1755 return ret;
1755} 1756}
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index f651e51a3319..e2ff697697c2 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -41,7 +41,7 @@
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/string.h> 43#include <linux/string.h>
44#include <linux/smp_lock.h> 44#include <linux/mutex.h>
45#include <linux/dma-mapping.h> 45#include <linux/dma-mapping.h>
46#include <linux/completion.h> 46#include <linux/completion.h>
47#include <linux/device.h> 47#include <linux/device.h>
@@ -73,6 +73,7 @@ enum {
73 MAX_DISK_NAME = FIELD_SIZEOF(struct gendisk, disk_name) 73 MAX_DISK_NAME = FIELD_SIZEOF(struct gendisk, disk_name)
74}; 74};
75 75
76static DEFINE_MUTEX(viodasd_mutex);
76static DEFINE_SPINLOCK(viodasd_spinlock); 77static DEFINE_SPINLOCK(viodasd_spinlock);
77 78
78#define VIOMAXREQ 16 79#define VIOMAXREQ 16
@@ -180,9 +181,9 @@ static int viodasd_unlocked_open(struct block_device *bdev, fmode_t mode)
180{ 181{
181 int ret; 182 int ret;
182 183
183 lock_kernel(); 184 mutex_lock(&viodasd_mutex);
184 ret = viodasd_open(bdev, mode); 185 ret = viodasd_open(bdev, mode);
185 unlock_kernel(); 186 mutex_unlock(&viodasd_mutex);
186 187
187 return ret; 188 return ret;
188} 189}
@@ -196,7 +197,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)
196 struct viodasd_device *d = disk->private_data; 197 struct viodasd_device *d = disk->private_data;
197 HvLpEvent_Rc hvrc; 198 HvLpEvent_Rc hvrc;
198 199
199 lock_kernel(); 200 mutex_lock(&viodasd_mutex);
200 /* Send the event to OS/400. We DON'T expect a response */ 201 /* Send the event to OS/400. We DON'T expect a response */
201 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, 202 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
202 HvLpEvent_Type_VirtualIo, 203 HvLpEvent_Type_VirtualIo,
@@ -210,7 +211,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)
210 if (hvrc != 0) 211 if (hvrc != 0)
211 pr_warning("HV close call failed %d\n", (int)hvrc); 212 pr_warning("HV close call failed %d\n", (int)hvrc);
212 213
213 unlock_kernel(); 214 mutex_unlock(&viodasd_mutex);
214 215
215 return 0; 216 return 0;
216} 217}
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 2aafafca2b13..8320490226b7 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -2,7 +2,6 @@
2#include <linux/spinlock.h> 2#include <linux/spinlock.h>
3#include <linux/slab.h> 3#include <linux/slab.h>
4#include <linux/blkdev.h> 4#include <linux/blkdev.h>
5#include <linux/smp_lock.h>
6#include <linux/hdreg.h> 5#include <linux/hdreg.h>
7#include <linux/virtio.h> 6#include <linux/virtio.h>
8#include <linux/virtio_blk.h> 7#include <linux/virtio_blk.h>
@@ -202,6 +201,7 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str)
202 struct virtio_blk *vblk = disk->private_data; 201 struct virtio_blk *vblk = disk->private_data;
203 struct request *req; 202 struct request *req;
204 struct bio *bio; 203 struct bio *bio;
204 int err;
205 205
206 bio = bio_map_kern(vblk->disk->queue, id_str, VIRTIO_BLK_ID_BYTES, 206 bio = bio_map_kern(vblk->disk->queue, id_str, VIRTIO_BLK_ID_BYTES,
207 GFP_KERNEL); 207 GFP_KERNEL);
@@ -215,11 +215,14 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str)
215 } 215 }
216 216
217 req->cmd_type = REQ_TYPE_SPECIAL; 217 req->cmd_type = REQ_TYPE_SPECIAL;
218 return blk_execute_rq(vblk->disk->queue, vblk->disk, req, false); 218 err = blk_execute_rq(vblk->disk->queue, vblk->disk, req, false);
219 blk_put_request(req);
220
221 return err;
219} 222}
220 223
221static int virtblk_locked_ioctl(struct block_device *bdev, fmode_t mode, 224static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
222 unsigned cmd, unsigned long data) 225 unsigned int cmd, unsigned long data)
223{ 226{
224 struct gendisk *disk = bdev->bd_disk; 227 struct gendisk *disk = bdev->bd_disk;
225 struct virtio_blk *vblk = disk->private_data; 228 struct virtio_blk *vblk = disk->private_data;
@@ -234,18 +237,6 @@ static int virtblk_locked_ioctl(struct block_device *bdev, fmode_t mode,
234 (void __user *)data); 237 (void __user *)data);
235} 238}
236 239
237static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
238 unsigned int cmd, unsigned long param)
239{
240 int ret;
241
242 lock_kernel();
243 ret = virtblk_locked_ioctl(bdev, mode, cmd, param);
244 unlock_kernel();
245
246 return ret;
247}
248
249/* We provide getgeo only to please some old bootloader/partitioning tools */ 240/* We provide getgeo only to please some old bootloader/partitioning tools */
250static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) 241static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
251{ 242{
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index d5a3cd750561..4abd2bcd20fb 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -46,7 +46,7 @@
46#include <linux/init.h> 46#include <linux/init.h>
47#include <linux/wait.h> 47#include <linux/wait.h>
48#include <linux/blkdev.h> 48#include <linux/blkdev.h>
49#include <linux/smp_lock.h> 49#include <linux/mutex.h>
50#include <linux/blkpg.h> 50#include <linux/blkpg.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/io.h> 52#include <linux/io.h>
@@ -58,6 +58,7 @@
58 58
59#include "xd.h" 59#include "xd.h"
60 60
61static DEFINE_MUTEX(xd_mutex);
61static void __init do_xd_setup (int *integers); 62static void __init do_xd_setup (int *integers);
62#ifdef MODULE 63#ifdef MODULE
63static int xd[5] = { -1,-1,-1,-1, }; 64static int xd[5] = { -1,-1,-1,-1, };
@@ -381,9 +382,9 @@ static int xd_ioctl(struct block_device *bdev, fmode_t mode,
381{ 382{
382 int ret; 383 int ret;
383 384
384 lock_kernel(); 385 mutex_lock(&xd_mutex);
385 ret = xd_locked_ioctl(bdev, mode, cmd, param); 386 ret = xd_locked_ioctl(bdev, mode, cmd, param);
386 unlock_kernel(); 387 mutex_unlock(&xd_mutex);
387 388
388 return ret; 389 return ret;
389} 390}
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index ab735a605cf3..3ff06f475eef 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -41,7 +41,7 @@
41#include <linux/cdrom.h> 41#include <linux/cdrom.h>
42#include <linux/module.h> 42#include <linux/module.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/smp_lock.h> 44#include <linux/mutex.h>
45#include <linux/scatterlist.h> 45#include <linux/scatterlist.h>
46 46
47#include <xen/xen.h> 47#include <xen/xen.h>
@@ -69,6 +69,7 @@ struct blk_shadow {
69 unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 69 unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST];
70}; 70};
71 71
72static DEFINE_MUTEX(blkfront_mutex);
72static const struct block_device_operations xlvbd_block_fops; 73static const struct block_device_operations xlvbd_block_fops;
73 74
74#define BLK_RING_SIZE __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE) 75#define BLK_RING_SIZE __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE)
@@ -1201,7 +1202,7 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)
1201 struct blkfront_info *info; 1202 struct blkfront_info *info;
1202 int err = 0; 1203 int err = 0;
1203 1204
1204 lock_kernel(); 1205 mutex_lock(&blkfront_mutex);
1205 1206
1206 info = disk->private_data; 1207 info = disk->private_data;
1207 if (!info) { 1208 if (!info) {
@@ -1219,7 +1220,7 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)
1219 mutex_unlock(&info->mutex); 1220 mutex_unlock(&info->mutex);
1220 1221
1221out: 1222out:
1222 unlock_kernel(); 1223 mutex_unlock(&blkfront_mutex);
1223 return err; 1224 return err;
1224} 1225}
1225 1226
@@ -1229,7 +1230,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
1229 struct block_device *bdev; 1230 struct block_device *bdev;
1230 struct xenbus_device *xbdev; 1231 struct xenbus_device *xbdev;
1231 1232
1232 lock_kernel(); 1233 mutex_lock(&blkfront_mutex);
1233 1234
1234 bdev = bdget_disk(disk, 0); 1235 bdev = bdget_disk(disk, 0);
1235 bdput(bdev); 1236 bdput(bdev);
@@ -1263,7 +1264,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
1263 } 1264 }
1264 1265
1265out: 1266out:
1266 unlock_kernel(); 1267 mutex_unlock(&blkfront_mutex);
1267 return 0; 1268 return 0;
1268} 1269}
1269 1270
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index 057413bb16e2..6e968cd4893c 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -89,7 +89,7 @@
89#include <linux/delay.h> 89#include <linux/delay.h>
90#include <linux/slab.h> 90#include <linux/slab.h>
91#include <linux/blkdev.h> 91#include <linux/blkdev.h>
92#include <linux/smp_lock.h> 92#include <linux/mutex.h>
93#include <linux/ata.h> 93#include <linux/ata.h>
94#include <linux/hdreg.h> 94#include <linux/hdreg.h>
95#include <linux/platform_device.h> 95#include <linux/platform_device.h>
@@ -214,6 +214,7 @@ struct ace_device {
214 u16 cf_id[ATA_ID_WORDS]; 214 u16 cf_id[ATA_ID_WORDS];
215}; 215};
216 216
217static DEFINE_MUTEX(xsysace_mutex);
217static int ace_major; 218static int ace_major;
218 219
219/* --------------------------------------------------------------------- 220/* ---------------------------------------------------------------------
@@ -903,13 +904,13 @@ static int ace_open(struct block_device *bdev, fmode_t mode)
903 904
904 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1); 905 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1);
905 906
906 lock_kernel(); 907 mutex_lock(&xsysace_mutex);
907 spin_lock_irqsave(&ace->lock, flags); 908 spin_lock_irqsave(&ace->lock, flags);
908 ace->users++; 909 ace->users++;
909 spin_unlock_irqrestore(&ace->lock, flags); 910 spin_unlock_irqrestore(&ace->lock, flags);
910 911
911 check_disk_change(bdev); 912 check_disk_change(bdev);
912 unlock_kernel(); 913 mutex_unlock(&xsysace_mutex);
913 914
914 return 0; 915 return 0;
915} 916}
@@ -922,7 +923,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)
922 923
923 dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1); 924 dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1);
924 925
925 lock_kernel(); 926 mutex_lock(&xsysace_mutex);
926 spin_lock_irqsave(&ace->lock, flags); 927 spin_lock_irqsave(&ace->lock, flags);
927 ace->users--; 928 ace->users--;
928 if (ace->users == 0) { 929 if (ace->users == 0) {
@@ -930,7 +931,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)
930 ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ); 931 ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ);
931 } 932 }
932 spin_unlock_irqrestore(&ace->lock, flags); 933 spin_unlock_irqrestore(&ace->lock, flags);
933 unlock_kernel(); 934 mutex_unlock(&xsysace_mutex);
934 return 0; 935 return 0;
935} 936}
936 937
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index d75b2bb601ad..dcd4cfcf4126 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -33,7 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/blkdev.h> 34#include <linux/blkdev.h>
35#include <linux/bitops.h> 35#include <linux/bitops.h>
36#include <linux/smp_lock.h> 36#include <linux/mutex.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38 38
39#include <asm/setup.h> 39#include <asm/setup.h>
@@ -57,6 +57,7 @@ extern struct mem_info m68k_memory[NUM_MEMINFO];
57 57
58#define Z2RAM_CHUNK1024 ( Z2RAM_CHUNKSIZE >> 10 ) 58#define Z2RAM_CHUNK1024 ( Z2RAM_CHUNKSIZE >> 10 )
59 59
60static DEFINE_MUTEX(z2ram_mutex);
60static u_long *z2ram_map = NULL; 61static u_long *z2ram_map = NULL;
61static u_long z2ram_size = 0; 62static u_long z2ram_size = 0;
62static int z2_count = 0; 63static int z2_count = 0;
@@ -154,7 +155,7 @@ static int z2_open(struct block_device *bdev, fmode_t mode)
154 155
155 device = MINOR(bdev->bd_dev); 156 device = MINOR(bdev->bd_dev);
156 157
157 lock_kernel(); 158 mutex_lock(&z2ram_mutex);
158 if ( current_device != -1 && current_device != device ) 159 if ( current_device != -1 && current_device != device )
159 { 160 {
160 rc = -EBUSY; 161 rc = -EBUSY;
@@ -296,25 +297,25 @@ static int z2_open(struct block_device *bdev, fmode_t mode)
296 set_capacity(z2ram_gendisk, z2ram_size >> 9); 297 set_capacity(z2ram_gendisk, z2ram_size >> 9);
297 } 298 }
298 299
299 unlock_kernel(); 300 mutex_unlock(&z2ram_mutex);
300 return 0; 301 return 0;
301 302
302err_out_kfree: 303err_out_kfree:
303 kfree(z2ram_map); 304 kfree(z2ram_map);
304err_out: 305err_out:
305 unlock_kernel(); 306 mutex_unlock(&z2ram_mutex);
306 return rc; 307 return rc;
307} 308}
308 309
309static int 310static int
310z2_release(struct gendisk *disk, fmode_t mode) 311z2_release(struct gendisk *disk, fmode_t mode)
311{ 312{
312 lock_kernel(); 313 mutex_lock(&z2ram_mutex);
313 if ( current_device == -1 ) { 314 if ( current_device == -1 ) {
314 unlock_kernel(); 315 mutex_unlock(&z2ram_mutex);
315 return 0; 316 return 0;
316 } 317 }
317 unlock_kernel(); 318 mutex_unlock(&z2ram_mutex);
318 /* 319 /*
319 * FIXME: unmap memory 320 * FIXME: unmap memory
320 */ 321 */