aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm.c10
-rw-r--r--drivers/md/md.c13
2 files changed, 12 insertions, 11 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index ac384b2a6a33..7967eca5a2d5 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -15,7 +15,6 @@
15#include <linux/blkpg.h> 15#include <linux/blkpg.h>
16#include <linux/bio.h> 16#include <linux/bio.h>
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/smp_lock.h>
19#include <linux/mempool.h> 18#include <linux/mempool.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21#include <linux/idr.h> 20#include <linux/idr.h>
@@ -33,6 +32,7 @@
33#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE" 32#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE"
34#define DM_COOKIE_LENGTH 24 33#define DM_COOKIE_LENGTH 24
35 34
35static DEFINE_MUTEX(dm_mutex);
36static const char *_name = DM_NAME; 36static const char *_name = DM_NAME;
37 37
38static unsigned int major = 0; 38static unsigned int major = 0;
@@ -344,7 +344,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode)
344{ 344{
345 struct mapped_device *md; 345 struct mapped_device *md;
346 346
347 lock_kernel(); 347 mutex_lock(&dm_mutex);
348 spin_lock(&_minor_lock); 348 spin_lock(&_minor_lock);
349 349
350 md = bdev->bd_disk->private_data; 350 md = bdev->bd_disk->private_data;
@@ -362,7 +362,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode)
362 362
363out: 363out:
364 spin_unlock(&_minor_lock); 364 spin_unlock(&_minor_lock);
365 unlock_kernel(); 365 mutex_unlock(&dm_mutex);
366 366
367 return md ? 0 : -ENXIO; 367 return md ? 0 : -ENXIO;
368} 368}
@@ -371,10 +371,10 @@ static int dm_blk_close(struct gendisk *disk, fmode_t mode)
371{ 371{
372 struct mapped_device *md = disk->private_data; 372 struct mapped_device *md = disk->private_data;
373 373
374 lock_kernel(); 374 mutex_lock(&dm_mutex);
375 atomic_dec(&md->open_count); 375 atomic_dec(&md->open_count);
376 dm_put(md); 376 dm_put(md);
377 unlock_kernel(); 377 mutex_unlock(&dm_mutex);
378 378
379 return 0; 379 return 0;
380} 380}
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 43cf9cc9c1df..f38f939e94c3 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -36,7 +36,7 @@
36#include <linux/blkdev.h> 36#include <linux/blkdev.h>
37#include <linux/sysctl.h> 37#include <linux/sysctl.h>
38#include <linux/seq_file.h> 38#include <linux/seq_file.h>
39#include <linux/smp_lock.h> 39#include <linux/mutex.h>
40#include <linux/buffer_head.h> /* for invalidate_bdev */ 40#include <linux/buffer_head.h> /* for invalidate_bdev */
41#include <linux/poll.h> 41#include <linux/poll.h>
42#include <linux/ctype.h> 42#include <linux/ctype.h>
@@ -57,6 +57,7 @@
57#define DEBUG 0 57#define DEBUG 0
58#define dprintk(x...) ((void)(DEBUG && printk(x))) 58#define dprintk(x...) ((void)(DEBUG && printk(x)))
59 59
60static DEFINE_MUTEX(md_mutex);
60 61
61#ifndef MODULE 62#ifndef MODULE
62static void autostart_arrays(int part); 63static void autostart_arrays(int part);
@@ -5949,7 +5950,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5949 mddev_t *mddev = mddev_find(bdev->bd_dev); 5950 mddev_t *mddev = mddev_find(bdev->bd_dev);
5950 int err; 5951 int err;
5951 5952
5952 lock_kernel(); 5953 mutex_lock(&md_mutex);
5953 if (mddev->gendisk != bdev->bd_disk) { 5954 if (mddev->gendisk != bdev->bd_disk) {
5954 /* we are racing with mddev_put which is discarding this 5955 /* we are racing with mddev_put which is discarding this
5955 * bd_disk. 5956 * bd_disk.
@@ -5958,7 +5959,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5958 /* Wait until bdev->bd_disk is definitely gone */ 5959 /* Wait until bdev->bd_disk is definitely gone */
5959 flush_scheduled_work(); 5960 flush_scheduled_work();
5960 /* Then retry the open from the top */ 5961 /* Then retry the open from the top */
5961 unlock_kernel(); 5962 mutex_unlock(&md_mutex);
5962 return -ERESTARTSYS; 5963 return -ERESTARTSYS;
5963 } 5964 }
5964 BUG_ON(mddev != bdev->bd_disk->private_data); 5965 BUG_ON(mddev != bdev->bd_disk->private_data);
@@ -5972,7 +5973,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5972 5973
5973 check_disk_size_change(mddev->gendisk, bdev); 5974 check_disk_size_change(mddev->gendisk, bdev);
5974 out: 5975 out:
5975 unlock_kernel(); 5976 mutex_unlock(&md_mutex);
5976 return err; 5977 return err;
5977} 5978}
5978 5979
@@ -5981,10 +5982,10 @@ static int md_release(struct gendisk *disk, fmode_t mode)
5981 mddev_t *mddev = disk->private_data; 5982 mddev_t *mddev = disk->private_data;
5982 5983
5983 BUG_ON(!mddev); 5984 BUG_ON(!mddev);
5984 lock_kernel(); 5985 mutex_lock(&md_mutex);
5985 atomic_dec(&mddev->openers); 5986 atomic_dec(&mddev->openers);
5986 mddev_put(mddev); 5987 mddev_put(mddev);
5987 unlock_kernel(); 5988 mutex_unlock(&md_mutex);
5988 5989
5989 return 0; 5990 return 0;
5990} 5991}