aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/drbd/drbd_nl.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block/drbd/drbd_nl.c')
-rw-r--r--drivers/block/drbd/drbd_nl.c103
1 files changed, 36 insertions, 67 deletions
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);