diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/drbd/drbd_int.h | 2 | ||||
-rw-r--r-- | drivers/block/drbd/drbd_main.c | 7 | ||||
-rw-r--r-- | drivers/block/drbd/drbd_nl.c | 103 | ||||
-rw-r--r-- | drivers/block/pktcdvd.c | 22 | ||||
-rw-r--r-- | drivers/char/raw.c | 14 | ||||
-rw-r--r-- | drivers/md/dm-table.c | 20 | ||||
-rw-r--r-- | drivers/md/md.c | 16 | ||||
-rw-r--r-- | drivers/mtd/devices/block2mtd.c | 10 | ||||
-rw-r--r-- | drivers/s390/block/dasd_genhd.c | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/storage_common.c | 7 |
10 files changed, 73 insertions, 130 deletions
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h index 1ea1a34e78b2..3803a0348937 100644 --- a/drivers/block/drbd/drbd_int.h +++ b/drivers/block/drbd/drbd_int.h | |||
@@ -911,8 +911,6 @@ struct drbd_md { | |||
911 | struct drbd_backing_dev { | 911 | struct drbd_backing_dev { |
912 | struct block_device *backing_bdev; | 912 | struct block_device *backing_bdev; |
913 | struct block_device *md_bdev; | 913 | struct block_device *md_bdev; |
914 | struct file *lo_file; | ||
915 | struct file *md_file; | ||
916 | struct drbd_md md; | 914 | struct drbd_md md; |
917 | struct disk_conf dc; /* The user provided config... */ | 915 | struct disk_conf dc; /* The user provided config... */ |
918 | sector_t known_size; /* last known size of that backing device */ | 916 | sector_t known_size; /* last known size of that backing device */ |
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index 6be5401d0e88..29cd0dc9fe4f 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c | |||
@@ -3372,11 +3372,8 @@ void drbd_free_bc(struct drbd_backing_dev *ldev) | |||
3372 | if (ldev == NULL) | 3372 | if (ldev == NULL) |
3373 | return; | 3373 | return; |
3374 | 3374 | ||
3375 | bd_release(ldev->backing_bdev); | 3375 | blkdev_put(ldev->backing_bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); |
3376 | bd_release(ldev->md_bdev); | 3376 | blkdev_put(ldev->md_bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); |
3377 | |||
3378 | fput(ldev->lo_file); | ||
3379 | fput(ldev->md_file); | ||
3380 | 3377 | ||
3381 | kfree(ldev); | 3378 | kfree(ldev); |
3382 | } | 3379 | } |
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c index 29e5c70e4e26..8cbfaa687d72 100644 --- a/drivers/block/drbd/drbd_nl.c +++ b/drivers/block/drbd/drbd_nl.c | |||
@@ -855,7 +855,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp | |||
855 | sector_t max_possible_sectors; | 855 | sector_t max_possible_sectors; |
856 | sector_t min_md_device_sectors; | 856 | sector_t min_md_device_sectors; |
857 | struct drbd_backing_dev *nbc = NULL; /* new_backing_conf */ | 857 | struct drbd_backing_dev *nbc = NULL; /* new_backing_conf */ |
858 | struct inode *inode, *inode2; | 858 | struct block_device *bdev; |
859 | struct lru_cache *resync_lru = NULL; | 859 | struct lru_cache *resync_lru = NULL; |
860 | union drbd_state ns, os; | 860 | union drbd_state ns, os; |
861 | unsigned int max_seg_s; | 861 | unsigned int max_seg_s; |
@@ -907,46 +907,40 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp | |||
907 | } | 907 | } |
908 | } | 908 | } |
909 | 909 | ||
910 | nbc->lo_file = filp_open(nbc->dc.backing_dev, O_RDWR, 0); | 910 | bdev = blkdev_get_by_path(nbc->dc.backing_dev, |
911 | if (IS_ERR(nbc->lo_file)) { | 911 | FMODE_READ | FMODE_WRITE | FMODE_EXCL, mdev); |
912 | if (IS_ERR(bdev)) { | ||
912 | dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.backing_dev, | 913 | dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.backing_dev, |
913 | PTR_ERR(nbc->lo_file)); | 914 | PTR_ERR(bdev)); |
914 | nbc->lo_file = NULL; | ||
915 | retcode = ERR_OPEN_DISK; | 915 | retcode = ERR_OPEN_DISK; |
916 | goto fail; | 916 | goto fail; |
917 | } | 917 | } |
918 | nbc->backing_bdev = bdev; | ||
918 | 919 | ||
919 | inode = nbc->lo_file->f_dentry->d_inode; | 920 | /* |
920 | 921 | * meta_dev_idx >= 0: external fixed size, possibly multiple | |
921 | if (!S_ISBLK(inode->i_mode)) { | 922 | * drbd sharing one meta device. TODO in that case, paranoia |
922 | retcode = ERR_DISK_NOT_BDEV; | 923 | * check that [md_bdev, meta_dev_idx] is not yet used by some |
923 | goto fail; | 924 | * other drbd minor! (if you use drbd.conf + drbdadm, that |
924 | } | 925 | * should check it for you already; but if you don't, or |
925 | 926 | * someone fooled it, we need to double check here) | |
926 | nbc->md_file = filp_open(nbc->dc.meta_dev, O_RDWR, 0); | 927 | */ |
927 | if (IS_ERR(nbc->md_file)) { | 928 | bdev = blkdev_get_by_path(nbc->dc.meta_dev, |
929 | FMODE_READ | FMODE_WRITE | FMODE_EXCL, | ||
930 | (nbc->dc.meta_dev_idx < 0) ? | ||
931 | (void *)mdev : (void *)drbd_m_holder); | ||
932 | if (IS_ERR(bdev)) { | ||
928 | dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.meta_dev, | 933 | dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.meta_dev, |
929 | PTR_ERR(nbc->md_file)); | 934 | PTR_ERR(bdev)); |
930 | nbc->md_file = NULL; | ||
931 | retcode = ERR_OPEN_MD_DISK; | 935 | retcode = ERR_OPEN_MD_DISK; |
932 | goto fail; | 936 | goto fail; |
933 | } | 937 | } |
938 | nbc->md_bdev = bdev; | ||
934 | 939 | ||
935 | inode2 = nbc->md_file->f_dentry->d_inode; | 940 | if ((nbc->backing_bdev == nbc->md_bdev) != |
936 | 941 | (nbc->dc.meta_dev_idx == DRBD_MD_INDEX_INTERNAL || | |
937 | if (!S_ISBLK(inode2->i_mode)) { | 942 | nbc->dc.meta_dev_idx == DRBD_MD_INDEX_FLEX_INT)) { |
938 | retcode = ERR_MD_NOT_BDEV; | 943 | retcode = ERR_MD_IDX_INVALID; |
939 | goto fail; | ||
940 | } | ||
941 | |||
942 | nbc->backing_bdev = inode->i_bdev; | ||
943 | if (bd_claim(nbc->backing_bdev, mdev)) { | ||
944 | printk(KERN_ERR "drbd: bd_claim(%p,%p); failed [%p;%p;%u]\n", | ||
945 | nbc->backing_bdev, mdev, | ||
946 | nbc->backing_bdev->bd_holder, | ||
947 | nbc->backing_bdev->bd_contains->bd_holder, | ||
948 | nbc->backing_bdev->bd_holders); | ||
949 | retcode = ERR_BDCLAIM_DISK; | ||
950 | goto fail; | 944 | goto fail; |
951 | } | 945 | } |
952 | 946 | ||
@@ -955,28 +949,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp | |||
955 | offsetof(struct bm_extent, lce)); | 949 | offsetof(struct bm_extent, lce)); |
956 | if (!resync_lru) { | 950 | if (!resync_lru) { |
957 | retcode = ERR_NOMEM; | 951 | retcode = ERR_NOMEM; |
958 | goto release_bdev_fail; | 952 | goto fail; |
959 | } | ||
960 | |||
961 | /* meta_dev_idx >= 0: external fixed size, | ||
962 | * possibly multiple drbd sharing one meta device. | ||
963 | * TODO in that case, paranoia check that [md_bdev, meta_dev_idx] is | ||
964 | * not yet used by some other drbd minor! | ||
965 | * (if you use drbd.conf + drbdadm, | ||
966 | * that should check it for you already; but if you don't, or someone | ||
967 | * fooled it, we need to double check here) */ | ||
968 | nbc->md_bdev = inode2->i_bdev; | ||
969 | if (bd_claim(nbc->md_bdev, (nbc->dc.meta_dev_idx < 0) ? (void *)mdev | ||
970 | : (void *) drbd_m_holder)) { | ||
971 | retcode = ERR_BDCLAIM_MD_DISK; | ||
972 | goto release_bdev_fail; | ||
973 | } | ||
974 | |||
975 | if ((nbc->backing_bdev == nbc->md_bdev) != | ||
976 | (nbc->dc.meta_dev_idx == DRBD_MD_INDEX_INTERNAL || | ||
977 | nbc->dc.meta_dev_idx == DRBD_MD_INDEX_FLEX_INT)) { | ||
978 | retcode = ERR_MD_IDX_INVALID; | ||
979 | goto release_bdev2_fail; | ||
980 | } | 953 | } |
981 | 954 | ||
982 | /* RT - for drbd_get_max_capacity() DRBD_MD_INDEX_FLEX_INT */ | 955 | /* RT - for drbd_get_max_capacity() DRBD_MD_INDEX_FLEX_INT */ |
@@ -987,7 +960,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp | |||
987 | (unsigned long long) drbd_get_max_capacity(nbc), | 960 | (unsigned long long) drbd_get_max_capacity(nbc), |
988 | (unsigned long long) nbc->dc.disk_size); | 961 | (unsigned long long) nbc->dc.disk_size); |
989 | retcode = ERR_DISK_TO_SMALL; | 962 | retcode = ERR_DISK_TO_SMALL; |
990 | goto release_bdev2_fail; | 963 | goto fail; |
991 | } | 964 | } |
992 | 965 | ||
993 | if (nbc->dc.meta_dev_idx < 0) { | 966 | if (nbc->dc.meta_dev_idx < 0) { |
@@ -1004,7 +977,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp | |||
1004 | dev_warn(DEV, "refusing attach: md-device too small, " | 977 | dev_warn(DEV, "refusing attach: md-device too small, " |
1005 | "at least %llu sectors needed for this meta-disk type\n", | 978 | "at least %llu sectors needed for this meta-disk type\n", |
1006 | (unsigned long long) min_md_device_sectors); | 979 | (unsigned long long) min_md_device_sectors); |
1007 | goto release_bdev2_fail; | 980 | goto fail; |
1008 | } | 981 | } |
1009 | 982 | ||
1010 | /* Make sure the new disk is big enough | 983 | /* Make sure the new disk is big enough |
@@ -1012,7 +985,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp | |||
1012 | if (drbd_get_max_capacity(nbc) < | 985 | if (drbd_get_max_capacity(nbc) < |
1013 | drbd_get_capacity(mdev->this_bdev)) { | 986 | drbd_get_capacity(mdev->this_bdev)) { |
1014 | retcode = ERR_DISK_TO_SMALL; | 987 | retcode = ERR_DISK_TO_SMALL; |
1015 | goto release_bdev2_fail; | 988 | goto fail; |
1016 | } | 989 | } |
1017 | 990 | ||
1018 | nbc->known_size = drbd_get_capacity(nbc->backing_bdev); | 991 | nbc->known_size = drbd_get_capacity(nbc->backing_bdev); |
@@ -1035,7 +1008,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp | |||
1035 | retcode = _drbd_request_state(mdev, NS(disk, D_ATTACHING), CS_VERBOSE); | 1008 | retcode = _drbd_request_state(mdev, NS(disk, D_ATTACHING), CS_VERBOSE); |
1036 | drbd_resume_io(mdev); | 1009 | drbd_resume_io(mdev); |
1037 | if (retcode < SS_SUCCESS) | 1010 | if (retcode < SS_SUCCESS) |
1038 | goto release_bdev2_fail; | 1011 | goto fail; |
1039 | 1012 | ||
1040 | if (!get_ldev_if_state(mdev, D_ATTACHING)) | 1013 | if (!get_ldev_if_state(mdev, D_ATTACHING)) |
1041 | goto force_diskless; | 1014 | goto force_diskless; |
@@ -1269,18 +1242,14 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp | |||
1269 | force_diskless: | 1242 | force_diskless: |
1270 | drbd_force_state(mdev, NS(disk, D_FAILED)); | 1243 | drbd_force_state(mdev, NS(disk, D_FAILED)); |
1271 | drbd_md_sync(mdev); | 1244 | drbd_md_sync(mdev); |
1272 | release_bdev2_fail: | ||
1273 | if (nbc) | ||
1274 | bd_release(nbc->md_bdev); | ||
1275 | release_bdev_fail: | ||
1276 | if (nbc) | ||
1277 | bd_release(nbc->backing_bdev); | ||
1278 | fail: | 1245 | fail: |
1279 | if (nbc) { | 1246 | if (nbc) { |
1280 | if (nbc->lo_file) | 1247 | if (nbc->backing_bdev) |
1281 | fput(nbc->lo_file); | 1248 | blkdev_put(nbc->backing_bdev, |
1282 | if (nbc->md_file) | 1249 | FMODE_READ | FMODE_WRITE | FMODE_EXCL); |
1283 | fput(nbc->md_file); | 1250 | if (nbc->md_bdev) |
1251 | blkdev_put(nbc->md_bdev, | ||
1252 | FMODE_READ | FMODE_WRITE | FMODE_EXCL); | ||
1284 | kfree(nbc); | 1253 | kfree(nbc); |
1285 | } | 1254 | } |
1286 | lc_destroy(resync_lru); | 1255 | lc_destroy(resync_lru); |
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 19b3568e9326..77d70eebb6b2 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c | |||
@@ -2296,15 +2296,12 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write) | |||
2296 | * so bdget() can't fail. | 2296 | * so bdget() can't fail. |
2297 | */ | 2297 | */ |
2298 | bdget(pd->bdev->bd_dev); | 2298 | bdget(pd->bdev->bd_dev); |
2299 | if ((ret = blkdev_get(pd->bdev, FMODE_READ))) | 2299 | if ((ret = blkdev_get(pd->bdev, FMODE_READ | FMODE_EXCL, pd))) |
2300 | goto out; | 2300 | goto out; |
2301 | 2301 | ||
2302 | if ((ret = bd_claim(pd->bdev, pd))) | ||
2303 | goto out_putdev; | ||
2304 | |||
2305 | if ((ret = pkt_get_last_written(pd, &lba))) { | 2302 | if ((ret = pkt_get_last_written(pd, &lba))) { |
2306 | printk(DRIVER_NAME": pkt_get_last_written failed\n"); | 2303 | printk(DRIVER_NAME": pkt_get_last_written failed\n"); |
2307 | goto out_unclaim; | 2304 | goto out_putdev; |
2308 | } | 2305 | } |
2309 | 2306 | ||
2310 | set_capacity(pd->disk, lba << 2); | 2307 | set_capacity(pd->disk, lba << 2); |
@@ -2314,7 +2311,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write) | |||
2314 | q = bdev_get_queue(pd->bdev); | 2311 | q = bdev_get_queue(pd->bdev); |
2315 | if (write) { | 2312 | if (write) { |
2316 | if ((ret = pkt_open_write(pd))) | 2313 | if ((ret = pkt_open_write(pd))) |
2317 | goto out_unclaim; | 2314 | goto out_putdev; |
2318 | /* | 2315 | /* |
2319 | * Some CDRW drives can not handle writes larger than one packet, | 2316 | * Some CDRW drives can not handle writes larger than one packet, |
2320 | * even if the size is a multiple of the packet size. | 2317 | * even if the size is a multiple of the packet size. |
@@ -2329,23 +2326,21 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write) | |||
2329 | } | 2326 | } |
2330 | 2327 | ||
2331 | if ((ret = pkt_set_segment_merging(pd, q))) | 2328 | if ((ret = pkt_set_segment_merging(pd, q))) |
2332 | goto out_unclaim; | 2329 | goto out_putdev; |
2333 | 2330 | ||
2334 | if (write) { | 2331 | if (write) { |
2335 | if (!pkt_grow_pktlist(pd, CONFIG_CDROM_PKTCDVD_BUFFERS)) { | 2332 | if (!pkt_grow_pktlist(pd, CONFIG_CDROM_PKTCDVD_BUFFERS)) { |
2336 | printk(DRIVER_NAME": not enough memory for buffers\n"); | 2333 | printk(DRIVER_NAME": not enough memory for buffers\n"); |
2337 | ret = -ENOMEM; | 2334 | ret = -ENOMEM; |
2338 | goto out_unclaim; | 2335 | goto out_putdev; |
2339 | } | 2336 | } |
2340 | printk(DRIVER_NAME": %lukB available on disc\n", lba << 1); | 2337 | printk(DRIVER_NAME": %lukB available on disc\n", lba << 1); |
2341 | } | 2338 | } |
2342 | 2339 | ||
2343 | return 0; | 2340 | return 0; |
2344 | 2341 | ||
2345 | out_unclaim: | ||
2346 | bd_release(pd->bdev); | ||
2347 | out_putdev: | 2342 | out_putdev: |
2348 | blkdev_put(pd->bdev, FMODE_READ); | 2343 | blkdev_put(pd->bdev, FMODE_READ | FMODE_EXCL); |
2349 | out: | 2344 | out: |
2350 | return ret; | 2345 | return ret; |
2351 | } | 2346 | } |
@@ -2362,8 +2357,7 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush) | |||
2362 | pkt_lock_door(pd, 0); | 2357 | pkt_lock_door(pd, 0); |
2363 | 2358 | ||
2364 | pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); | 2359 | pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); |
2365 | bd_release(pd->bdev); | 2360 | blkdev_put(pd->bdev, FMODE_READ | FMODE_EXCL); |
2366 | blkdev_put(pd->bdev, FMODE_READ); | ||
2367 | 2361 | ||
2368 | pkt_shrink_pktlist(pd); | 2362 | pkt_shrink_pktlist(pd); |
2369 | } | 2363 | } |
@@ -2733,7 +2727,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) | |||
2733 | bdev = bdget(dev); | 2727 | bdev = bdget(dev); |
2734 | if (!bdev) | 2728 | if (!bdev) |
2735 | return -ENOMEM; | 2729 | return -ENOMEM; |
2736 | ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY); | 2730 | ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY, NULL); |
2737 | if (ret) | 2731 | if (ret) |
2738 | return ret; | 2732 | return ret; |
2739 | 2733 | ||
diff --git a/drivers/char/raw.c b/drivers/char/raw.c index bfe25ea9766b..b4b9d5a47885 100644 --- a/drivers/char/raw.c +++ b/drivers/char/raw.c | |||
@@ -65,15 +65,12 @@ static int raw_open(struct inode *inode, struct file *filp) | |||
65 | if (!bdev) | 65 | if (!bdev) |
66 | goto out; | 66 | goto out; |
67 | igrab(bdev->bd_inode); | 67 | igrab(bdev->bd_inode); |
68 | err = blkdev_get(bdev, filp->f_mode); | 68 | err = blkdev_get(bdev, filp->f_mode | FMODE_EXCL, raw_open); |
69 | if (err) | 69 | if (err) |
70 | goto out; | 70 | goto out; |
71 | err = bd_claim(bdev, raw_open); | ||
72 | if (err) | ||
73 | goto out1; | ||
74 | err = set_blocksize(bdev, bdev_logical_block_size(bdev)); | 71 | err = set_blocksize(bdev, bdev_logical_block_size(bdev)); |
75 | if (err) | 72 | if (err) |
76 | goto out2; | 73 | goto out1; |
77 | filp->f_flags |= O_DIRECT; | 74 | filp->f_flags |= O_DIRECT; |
78 | filp->f_mapping = bdev->bd_inode->i_mapping; | 75 | filp->f_mapping = bdev->bd_inode->i_mapping; |
79 | if (++raw_devices[minor].inuse == 1) | 76 | if (++raw_devices[minor].inuse == 1) |
@@ -83,10 +80,8 @@ static int raw_open(struct inode *inode, struct file *filp) | |||
83 | mutex_unlock(&raw_mutex); | 80 | mutex_unlock(&raw_mutex); |
84 | return 0; | 81 | return 0; |
85 | 82 | ||
86 | out2: | ||
87 | bd_release(bdev); | ||
88 | out1: | 83 | out1: |
89 | blkdev_put(bdev, filp->f_mode); | 84 | blkdev_put(bdev, filp->f_mode | FMODE_EXCL); |
90 | out: | 85 | out: |
91 | mutex_unlock(&raw_mutex); | 86 | mutex_unlock(&raw_mutex); |
92 | return err; | 87 | return err; |
@@ -110,8 +105,7 @@ static int raw_release(struct inode *inode, struct file *filp) | |||
110 | } | 105 | } |
111 | mutex_unlock(&raw_mutex); | 106 | mutex_unlock(&raw_mutex); |
112 | 107 | ||
113 | bd_release(bdev); | 108 | blkdev_put(bdev, filp->f_mode | FMODE_EXCL); |
114 | blkdev_put(bdev, filp->f_mode); | ||
115 | return 0; | 109 | return 0; |
116 | } | 110 | } |
117 | 111 | ||
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 90267f8d64ee..67150c32986c 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c | |||
@@ -325,15 +325,18 @@ static int open_dev(struct dm_dev_internal *d, dev_t dev, | |||
325 | 325 | ||
326 | BUG_ON(d->dm_dev.bdev); | 326 | BUG_ON(d->dm_dev.bdev); |
327 | 327 | ||
328 | bdev = open_by_devnum(dev, d->dm_dev.mode); | 328 | bdev = blkdev_get_by_dev(dev, d->dm_dev.mode | FMODE_EXCL, _claim_ptr); |
329 | if (IS_ERR(bdev)) | 329 | if (IS_ERR(bdev)) |
330 | return PTR_ERR(bdev); | 330 | return PTR_ERR(bdev); |
331 | r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md)); | 331 | |
332 | if (r) | 332 | r = bd_link_disk_holder(bdev, dm_disk(md)); |
333 | blkdev_put(bdev, d->dm_dev.mode); | 333 | if (r) { |
334 | else | 334 | blkdev_put(bdev, d->dm_dev.mode | FMODE_EXCL); |
335 | d->dm_dev.bdev = bdev; | 335 | return r; |
336 | return r; | 336 | } |
337 | |||
338 | d->dm_dev.bdev = bdev; | ||
339 | return 0; | ||
337 | } | 340 | } |
338 | 341 | ||
339 | /* | 342 | /* |
@@ -344,8 +347,7 @@ static void close_dev(struct dm_dev_internal *d, struct mapped_device *md) | |||
344 | if (!d->dm_dev.bdev) | 347 | if (!d->dm_dev.bdev) |
345 | return; | 348 | return; |
346 | 349 | ||
347 | bd_release_from_disk(d->dm_dev.bdev, dm_disk(md)); | 350 | blkdev_put(d->dm_dev.bdev, d->dm_dev.mode | FMODE_EXCL); |
348 | blkdev_put(d->dm_dev.bdev, d->dm_dev.mode); | ||
349 | d->dm_dev.bdev = NULL; | 351 | d->dm_dev.bdev = NULL; |
350 | } | 352 | } |
351 | 353 | ||
diff --git a/drivers/md/md.c b/drivers/md/md.c index 324a3663fcda..3bacccab1b8c 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
@@ -1880,7 +1880,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) | |||
1880 | rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state"); | 1880 | rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state"); |
1881 | 1881 | ||
1882 | list_add_rcu(&rdev->same_set, &mddev->disks); | 1882 | list_add_rcu(&rdev->same_set, &mddev->disks); |
1883 | bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); | 1883 | bd_link_disk_holder(rdev->bdev, mddev->gendisk); |
1884 | 1884 | ||
1885 | /* May as well allow recovery to be retried once */ | 1885 | /* May as well allow recovery to be retried once */ |
1886 | mddev->recovery_disabled = 0; | 1886 | mddev->recovery_disabled = 0; |
@@ -1907,7 +1907,6 @@ static void unbind_rdev_from_array(mdk_rdev_t * rdev) | |||
1907 | MD_BUG(); | 1907 | MD_BUG(); |
1908 | return; | 1908 | return; |
1909 | } | 1909 | } |
1910 | bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk); | ||
1911 | list_del_rcu(&rdev->same_set); | 1910 | list_del_rcu(&rdev->same_set); |
1912 | printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); | 1911 | printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); |
1913 | rdev->mddev = NULL; | 1912 | rdev->mddev = NULL; |
@@ -1935,19 +1934,13 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev, int shared) | |||
1935 | struct block_device *bdev; | 1934 | struct block_device *bdev; |
1936 | char b[BDEVNAME_SIZE]; | 1935 | char b[BDEVNAME_SIZE]; |
1937 | 1936 | ||
1938 | bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); | 1937 | bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, |
1938 | shared ? (mdk_rdev_t *)lock_rdev : rdev); | ||
1939 | if (IS_ERR(bdev)) { | 1939 | if (IS_ERR(bdev)) { |
1940 | printk(KERN_ERR "md: could not open %s.\n", | 1940 | printk(KERN_ERR "md: could not open %s.\n", |
1941 | __bdevname(dev, b)); | 1941 | __bdevname(dev, b)); |
1942 | return PTR_ERR(bdev); | 1942 | return PTR_ERR(bdev); |
1943 | } | 1943 | } |
1944 | err = bd_claim(bdev, shared ? (mdk_rdev_t *)lock_rdev : rdev); | ||
1945 | if (err) { | ||
1946 | printk(KERN_ERR "md: could not bd_claim %s.\n", | ||
1947 | bdevname(bdev, b)); | ||
1948 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); | ||
1949 | return err; | ||
1950 | } | ||
1951 | if (!shared) | 1944 | if (!shared) |
1952 | set_bit(AllReserved, &rdev->flags); | 1945 | set_bit(AllReserved, &rdev->flags); |
1953 | rdev->bdev = bdev; | 1946 | rdev->bdev = bdev; |
@@ -1960,8 +1953,7 @@ static void unlock_rdev(mdk_rdev_t *rdev) | |||
1960 | rdev->bdev = NULL; | 1953 | rdev->bdev = NULL; |
1961 | if (!bdev) | 1954 | if (!bdev) |
1962 | MD_BUG(); | 1955 | MD_BUG(); |
1963 | bd_release(bdev); | 1956 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); |
1964 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); | ||
1965 | } | 1957 | } |
1966 | 1958 | ||
1967 | void md_autodetect_dev(dev_t dev); | 1959 | void md_autodetect_dev(dev_t dev); |
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index 2cf0cc6a4189..f29a6f9df6e7 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c | |||
@@ -224,7 +224,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) | |||
224 | if (dev->blkdev) { | 224 | if (dev->blkdev) { |
225 | invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping, | 225 | invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping, |
226 | 0, -1); | 226 | 0, -1); |
227 | close_bdev_exclusive(dev->blkdev, FMODE_READ|FMODE_WRITE); | 227 | blkdev_put(dev->blkdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); |
228 | } | 228 | } |
229 | 229 | ||
230 | kfree(dev); | 230 | kfree(dev); |
@@ -234,6 +234,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) | |||
234 | /* FIXME: ensure that mtd->size % erase_size == 0 */ | 234 | /* FIXME: ensure that mtd->size % erase_size == 0 */ |
235 | static struct block2mtd_dev *add_device(char *devname, int erase_size) | 235 | static struct block2mtd_dev *add_device(char *devname, int erase_size) |
236 | { | 236 | { |
237 | const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; | ||
237 | struct block_device *bdev; | 238 | struct block_device *bdev; |
238 | struct block2mtd_dev *dev; | 239 | struct block2mtd_dev *dev; |
239 | char *name; | 240 | char *name; |
@@ -246,7 +247,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size) | |||
246 | return NULL; | 247 | return NULL; |
247 | 248 | ||
248 | /* Get a handle on the device */ | 249 | /* Get a handle on the device */ |
249 | bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, NULL); | 250 | bdev = blkdev_get_by_path(devname, mode, dev); |
250 | #ifndef MODULE | 251 | #ifndef MODULE |
251 | if (IS_ERR(bdev)) { | 252 | if (IS_ERR(bdev)) { |
252 | 253 | ||
@@ -254,9 +255,8 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size) | |||
254 | to resolve the device name by other means. */ | 255 | to resolve the device name by other means. */ |
255 | 256 | ||
256 | dev_t devt = name_to_dev_t(devname); | 257 | dev_t devt = name_to_dev_t(devname); |
257 | if (devt) { | 258 | if (devt) |
258 | bdev = open_by_devnum(devt, FMODE_WRITE | FMODE_READ); | 259 | bdev = blkdev_get_by_dev(devt, mode, dev); |
259 | } | ||
260 | } | 260 | } |
261 | #endif | 261 | #endif |
262 | 262 | ||
diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c index 30a1ca3d08b7..5505bc07e1e7 100644 --- a/drivers/s390/block/dasd_genhd.c +++ b/drivers/s390/block/dasd_genhd.c | |||
@@ -103,7 +103,7 @@ int dasd_scan_partitions(struct dasd_block *block) | |||
103 | struct block_device *bdev; | 103 | struct block_device *bdev; |
104 | 104 | ||
105 | bdev = bdget_disk(block->gdp, 0); | 105 | bdev = bdget_disk(block->gdp, 0); |
106 | if (!bdev || blkdev_get(bdev, FMODE_READ) < 0) | 106 | if (!bdev || blkdev_get(bdev, FMODE_READ, NULL) < 0) |
107 | return -ENODEV; | 107 | return -ENODEV; |
108 | /* | 108 | /* |
109 | * See fs/partition/check.c:register_disk,rescan_partitions | 109 | * See fs/partition/check.c:register_disk,rescan_partitions |
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 3b513bafaf2a..b015561fd602 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
@@ -543,7 +543,7 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | |||
543 | ro = curlun->initially_ro; | 543 | ro = curlun->initially_ro; |
544 | if (!ro) { | 544 | if (!ro) { |
545 | filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0); | 545 | filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0); |
546 | if (-EROFS == PTR_ERR(filp)) | 546 | if (PTR_ERR(filp) == -EROFS || PTR_ERR(filp) == -EACCES) |
547 | ro = 1; | 547 | ro = 1; |
548 | } | 548 | } |
549 | if (ro) | 549 | if (ro) |
@@ -558,10 +558,7 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | |||
558 | 558 | ||
559 | if (filp->f_path.dentry) | 559 | if (filp->f_path.dentry) |
560 | inode = filp->f_path.dentry->d_inode; | 560 | inode = filp->f_path.dentry->d_inode; |
561 | if (inode && S_ISBLK(inode->i_mode)) { | 561 | if (!inode || (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) { |
562 | if (bdev_read_only(inode->i_bdev)) | ||
563 | ro = 1; | ||
564 | } else if (!inode || !S_ISREG(inode->i_mode)) { | ||
565 | LINFO(curlun, "invalid file type: %s\n", filename); | 562 | LINFO(curlun, "invalid file type: %s\n", filename); |
566 | goto out; | 563 | goto out; |
567 | } | 564 | } |