aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/raid1.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/raid1.c')
-rw-r--r--drivers/md/raid1.c133
1 files changed, 43 insertions, 90 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 851023e2ba5d..55951182af73 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -92,7 +92,6 @@ static void r1bio_pool_free(void *r1_bio, void *data)
92static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data) 92static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
93{ 93{
94 struct pool_info *pi = data; 94 struct pool_info *pi = data;
95 struct page *page;
96 struct r1bio *r1_bio; 95 struct r1bio *r1_bio;
97 struct bio *bio; 96 struct bio *bio;
98 int i, j; 97 int i, j;
@@ -122,14 +121,10 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
122 j = 1; 121 j = 1;
123 while(j--) { 122 while(j--) {
124 bio = r1_bio->bios[j]; 123 bio = r1_bio->bios[j];
125 for (i = 0; i < RESYNC_PAGES; i++) { 124 bio->bi_vcnt = RESYNC_PAGES;
126 page = alloc_page(gfp_flags);
127 if (unlikely(!page))
128 goto out_free_pages;
129 125
130 bio->bi_io_vec[i].bv_page = page; 126 if (bio_alloc_pages(bio, gfp_flags))
131 bio->bi_vcnt = i+1; 127 goto out_free_bio;
132 }
133 } 128 }
134 /* If not user-requests, copy the page pointers to all bios */ 129 /* If not user-requests, copy the page pointers to all bios */
135 if (!test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery)) { 130 if (!test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery)) {
@@ -143,11 +138,6 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
143 138
144 return r1_bio; 139 return r1_bio;
145 140
146out_free_pages:
147 for (j=0 ; j < pi->raid_disks; j++)
148 for (i=0; i < r1_bio->bios[j]->bi_vcnt ; i++)
149 put_page(r1_bio->bios[j]->bi_io_vec[i].bv_page);
150 j = -1;
151out_free_bio: 141out_free_bio:
152 while (++j < pi->raid_disks) 142 while (++j < pi->raid_disks)
153 bio_put(r1_bio->bios[j]); 143 bio_put(r1_bio->bios[j]);
@@ -267,7 +257,7 @@ static void raid_end_bio_io(struct r1bio *r1_bio)
267 (bio_data_dir(bio) == WRITE) ? "write" : "read", 257 (bio_data_dir(bio) == WRITE) ? "write" : "read",
268 (unsigned long long) bio->bi_sector, 258 (unsigned long long) bio->bi_sector,
269 (unsigned long long) bio->bi_sector + 259 (unsigned long long) bio->bi_sector +
270 (bio->bi_size >> 9) - 1); 260 bio_sectors(bio) - 1);
271 261
272 call_bio_endio(r1_bio); 262 call_bio_endio(r1_bio);
273 } 263 }
@@ -458,7 +448,7 @@ static void raid1_end_write_request(struct bio *bio, int error)
458 " %llu-%llu\n", 448 " %llu-%llu\n",
459 (unsigned long long) mbio->bi_sector, 449 (unsigned long long) mbio->bi_sector,
460 (unsigned long long) mbio->bi_sector + 450 (unsigned long long) mbio->bi_sector +
461 (mbio->bi_size >> 9) - 1); 451 bio_sectors(mbio) - 1);
462 call_bio_endio(r1_bio); 452 call_bio_endio(r1_bio);
463 } 453 }
464 } 454 }
@@ -925,7 +915,7 @@ static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio)
925 if (unlikely(!bvecs)) 915 if (unlikely(!bvecs))
926 return; 916 return;
927 917
928 bio_for_each_segment(bvec, bio, i) { 918 bio_for_each_segment_all(bvec, bio, i) {
929 bvecs[i] = *bvec; 919 bvecs[i] = *bvec;
930 bvecs[i].bv_page = alloc_page(GFP_NOIO); 920 bvecs[i].bv_page = alloc_page(GFP_NOIO);
931 if (unlikely(!bvecs[i].bv_page)) 921 if (unlikely(!bvecs[i].bv_page))
@@ -1023,7 +1013,7 @@ static void make_request(struct mddev *mddev, struct bio * bio)
1023 md_write_start(mddev, bio); /* wait on superblock update early */ 1013 md_write_start(mddev, bio); /* wait on superblock update early */
1024 1014
1025 if (bio_data_dir(bio) == WRITE && 1015 if (bio_data_dir(bio) == WRITE &&
1026 bio->bi_sector + bio->bi_size/512 > mddev->suspend_lo && 1016 bio_end_sector(bio) > mddev->suspend_lo &&
1027 bio->bi_sector < mddev->suspend_hi) { 1017 bio->bi_sector < mddev->suspend_hi) {
1028 /* As the suspend_* range is controlled by 1018 /* As the suspend_* range is controlled by
1029 * userspace, we want an interruptible 1019 * userspace, we want an interruptible
@@ -1034,7 +1024,7 @@ static void make_request(struct mddev *mddev, struct bio * bio)
1034 flush_signals(current); 1024 flush_signals(current);
1035 prepare_to_wait(&conf->wait_barrier, 1025 prepare_to_wait(&conf->wait_barrier,
1036 &w, TASK_INTERRUPTIBLE); 1026 &w, TASK_INTERRUPTIBLE);
1037 if (bio->bi_sector + bio->bi_size/512 <= mddev->suspend_lo || 1027 if (bio_end_sector(bio) <= mddev->suspend_lo ||
1038 bio->bi_sector >= mddev->suspend_hi) 1028 bio->bi_sector >= mddev->suspend_hi)
1039 break; 1029 break;
1040 schedule(); 1030 schedule();
@@ -1054,7 +1044,7 @@ static void make_request(struct mddev *mddev, struct bio * bio)
1054 r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO); 1044 r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO);
1055 1045
1056 r1_bio->master_bio = bio; 1046 r1_bio->master_bio = bio;
1057 r1_bio->sectors = bio->bi_size >> 9; 1047 r1_bio->sectors = bio_sectors(bio);
1058 r1_bio->state = 0; 1048 r1_bio->state = 0;
1059 r1_bio->mddev = mddev; 1049 r1_bio->mddev = mddev;
1060 r1_bio->sector = bio->bi_sector; 1050 r1_bio->sector = bio->bi_sector;
@@ -1132,7 +1122,7 @@ read_again:
1132 r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO); 1122 r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO);
1133 1123
1134 r1_bio->master_bio = bio; 1124 r1_bio->master_bio = bio;
1135 r1_bio->sectors = (bio->bi_size >> 9) - sectors_handled; 1125 r1_bio->sectors = bio_sectors(bio) - sectors_handled;
1136 r1_bio->state = 0; 1126 r1_bio->state = 0;
1137 r1_bio->mddev = mddev; 1127 r1_bio->mddev = mddev;
1138 r1_bio->sector = bio->bi_sector + sectors_handled; 1128 r1_bio->sector = bio->bi_sector + sectors_handled;
@@ -1289,14 +1279,10 @@ read_again:
1289 struct bio_vec *bvec; 1279 struct bio_vec *bvec;
1290 int j; 1280 int j;
1291 1281
1292 /* Yes, I really want the '__' version so that 1282 /*
1293 * we clear any unused pointer in the io_vec, rather 1283 * We trimmed the bio, so _all is legit
1294 * than leave them unchanged. This is important
1295 * because when we come to free the pages, we won't
1296 * know the original bi_idx, so we just free
1297 * them all
1298 */ 1284 */
1299 __bio_for_each_segment(bvec, mbio, j, 0) 1285 bio_for_each_segment_all(bvec, mbio, j)
1300 bvec->bv_page = r1_bio->behind_bvecs[j].bv_page; 1286 bvec->bv_page = r1_bio->behind_bvecs[j].bv_page;
1301 if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags)) 1287 if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags))
1302 atomic_inc(&r1_bio->behind_remaining); 1288 atomic_inc(&r1_bio->behind_remaining);
@@ -1334,14 +1320,14 @@ read_again:
1334 /* Mustn't call r1_bio_write_done before this next test, 1320 /* Mustn't call r1_bio_write_done before this next test,
1335 * as it could result in the bio being freed. 1321 * as it could result in the bio being freed.
1336 */ 1322 */
1337 if (sectors_handled < (bio->bi_size >> 9)) { 1323 if (sectors_handled < bio_sectors(bio)) {
1338 r1_bio_write_done(r1_bio); 1324 r1_bio_write_done(r1_bio);
1339 /* We need another r1_bio. It has already been counted 1325 /* We need another r1_bio. It has already been counted
1340 * in bio->bi_phys_segments 1326 * in bio->bi_phys_segments
1341 */ 1327 */
1342 r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO); 1328 r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO);
1343 r1_bio->master_bio = bio; 1329 r1_bio->master_bio = bio;
1344 r1_bio->sectors = (bio->bi_size >> 9) - sectors_handled; 1330 r1_bio->sectors = bio_sectors(bio) - sectors_handled;
1345 r1_bio->state = 0; 1331 r1_bio->state = 0;
1346 r1_bio->mddev = mddev; 1332 r1_bio->mddev = mddev;
1347 r1_bio->sector = bio->bi_sector + sectors_handled; 1333 r1_bio->sector = bio->bi_sector + sectors_handled;
@@ -1867,7 +1853,7 @@ static int process_checks(struct r1bio *r1_bio)
1867 struct bio *sbio = r1_bio->bios[i]; 1853 struct bio *sbio = r1_bio->bios[i];
1868 int size; 1854 int size;
1869 1855
1870 if (r1_bio->bios[i]->bi_end_io != end_sync_read) 1856 if (sbio->bi_end_io != end_sync_read)
1871 continue; 1857 continue;
1872 1858
1873 if (test_bit(BIO_UPTODATE, &sbio->bi_flags)) { 1859 if (test_bit(BIO_UPTODATE, &sbio->bi_flags)) {
@@ -1892,16 +1878,15 @@ static int process_checks(struct r1bio *r1_bio)
1892 continue; 1878 continue;
1893 } 1879 }
1894 /* fixup the bio for reuse */ 1880 /* fixup the bio for reuse */
1881 bio_reset(sbio);
1895 sbio->bi_vcnt = vcnt; 1882 sbio->bi_vcnt = vcnt;
1896 sbio->bi_size = r1_bio->sectors << 9; 1883 sbio->bi_size = r1_bio->sectors << 9;
1897 sbio->bi_idx = 0;
1898 sbio->bi_phys_segments = 0;
1899 sbio->bi_flags &= ~(BIO_POOL_MASK - 1);
1900 sbio->bi_flags |= 1 << BIO_UPTODATE;
1901 sbio->bi_next = NULL;
1902 sbio->bi_sector = r1_bio->sector + 1884 sbio->bi_sector = r1_bio->sector +
1903 conf->mirrors[i].rdev->data_offset; 1885 conf->mirrors[i].rdev->data_offset;
1904 sbio->bi_bdev = conf->mirrors[i].rdev->bdev; 1886 sbio->bi_bdev = conf->mirrors[i].rdev->bdev;
1887 sbio->bi_end_io = end_sync_read;
1888 sbio->bi_private = r1_bio;
1889
1905 size = sbio->bi_size; 1890 size = sbio->bi_size;
1906 for (j = 0; j < vcnt ; j++) { 1891 for (j = 0; j < vcnt ; j++) {
1907 struct bio_vec *bi; 1892 struct bio_vec *bi;
@@ -1912,10 +1897,9 @@ static int process_checks(struct r1bio *r1_bio)
1912 else 1897 else
1913 bi->bv_len = size; 1898 bi->bv_len = size;
1914 size -= PAGE_SIZE; 1899 size -= PAGE_SIZE;
1915 memcpy(page_address(bi->bv_page),
1916 page_address(pbio->bi_io_vec[j].bv_page),
1917 PAGE_SIZE);
1918 } 1900 }
1901
1902 bio_copy_data(sbio, pbio);
1919 } 1903 }
1920 return 0; 1904 return 0;
1921} 1905}
@@ -1952,7 +1936,7 @@ static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
1952 wbio->bi_rw = WRITE; 1936 wbio->bi_rw = WRITE;
1953 wbio->bi_end_io = end_sync_write; 1937 wbio->bi_end_io = end_sync_write;
1954 atomic_inc(&r1_bio->remaining); 1938 atomic_inc(&r1_bio->remaining);
1955 md_sync_acct(conf->mirrors[i].rdev->bdev, wbio->bi_size >> 9); 1939 md_sync_acct(conf->mirrors[i].rdev->bdev, bio_sectors(wbio));
1956 1940
1957 generic_make_request(wbio); 1941 generic_make_request(wbio);
1958 } 1942 }
@@ -2064,32 +2048,11 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
2064 } 2048 }
2065} 2049}
2066 2050
2067static void bi_complete(struct bio *bio, int error)
2068{
2069 complete((struct completion *)bio->bi_private);
2070}
2071
2072static int submit_bio_wait(int rw, struct bio *bio)
2073{
2074 struct completion event;
2075 rw |= REQ_SYNC;
2076
2077 init_completion(&event);
2078 bio->bi_private = &event;
2079 bio->bi_end_io = bi_complete;
2080 submit_bio(rw, bio);
2081 wait_for_completion(&event);
2082
2083 return test_bit(BIO_UPTODATE, &bio->bi_flags);
2084}
2085
2086static int narrow_write_error(struct r1bio *r1_bio, int i) 2051static int narrow_write_error(struct r1bio *r1_bio, int i)
2087{ 2052{
2088 struct mddev *mddev = r1_bio->mddev; 2053 struct mddev *mddev = r1_bio->mddev;
2089 struct r1conf *conf = mddev->private; 2054 struct r1conf *conf = mddev->private;
2090 struct md_rdev *rdev = conf->mirrors[i].rdev; 2055 struct md_rdev *rdev = conf->mirrors[i].rdev;
2091 int vcnt, idx;
2092 struct bio_vec *vec;
2093 2056
2094 /* bio has the data to be written to device 'i' where 2057 /* bio has the data to be written to device 'i' where
2095 * we just recently had a write error. 2058 * we just recently had a write error.
@@ -2117,30 +2080,32 @@ static int narrow_write_error(struct r1bio *r1_bio, int i)
2117 & ~(sector_t)(block_sectors - 1)) 2080 & ~(sector_t)(block_sectors - 1))
2118 - sector; 2081 - sector;
2119 2082
2120 if (test_bit(R1BIO_BehindIO, &r1_bio->state)) {
2121 vcnt = r1_bio->behind_page_count;
2122 vec = r1_bio->behind_bvecs;
2123 idx = 0;
2124 while (vec[idx].bv_page == NULL)
2125 idx++;
2126 } else {
2127 vcnt = r1_bio->master_bio->bi_vcnt;
2128 vec = r1_bio->master_bio->bi_io_vec;
2129 idx = r1_bio->master_bio->bi_idx;
2130 }
2131 while (sect_to_write) { 2083 while (sect_to_write) {
2132 struct bio *wbio; 2084 struct bio *wbio;
2133 if (sectors > sect_to_write) 2085 if (sectors > sect_to_write)
2134 sectors = sect_to_write; 2086 sectors = sect_to_write;
2135 /* Write at 'sector' for 'sectors'*/ 2087 /* Write at 'sector' for 'sectors'*/
2136 2088
2137 wbio = bio_alloc_mddev(GFP_NOIO, vcnt, mddev); 2089 if (test_bit(R1BIO_BehindIO, &r1_bio->state)) {
2138 memcpy(wbio->bi_io_vec, vec, vcnt * sizeof(struct bio_vec)); 2090 unsigned vcnt = r1_bio->behind_page_count;
2139 wbio->bi_sector = r1_bio->sector; 2091 struct bio_vec *vec = r1_bio->behind_bvecs;
2092
2093 while (!vec->bv_page) {
2094 vec++;
2095 vcnt--;
2096 }
2097
2098 wbio = bio_alloc_mddev(GFP_NOIO, vcnt, mddev);
2099 memcpy(wbio->bi_io_vec, vec, vcnt * sizeof(struct bio_vec));
2100
2101 wbio->bi_vcnt = vcnt;
2102 } else {
2103 wbio = bio_clone_mddev(r1_bio->master_bio, GFP_NOIO, mddev);
2104 }
2105
2140 wbio->bi_rw = WRITE; 2106 wbio->bi_rw = WRITE;
2141 wbio->bi_vcnt = vcnt; 2107 wbio->bi_sector = r1_bio->sector;
2142 wbio->bi_size = r1_bio->sectors << 9; 2108 wbio->bi_size = r1_bio->sectors << 9;
2143 wbio->bi_idx = idx;
2144 2109
2145 md_trim_bio(wbio, sector - r1_bio->sector, sectors); 2110 md_trim_bio(wbio, sector - r1_bio->sector, sectors);
2146 wbio->bi_sector += rdev->data_offset; 2111 wbio->bi_sector += rdev->data_offset;
@@ -2289,8 +2254,7 @@ read_more:
2289 r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO); 2254 r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO);
2290 2255
2291 r1_bio->master_bio = mbio; 2256 r1_bio->master_bio = mbio;
2292 r1_bio->sectors = (mbio->bi_size >> 9) 2257 r1_bio->sectors = bio_sectors(mbio) - sectors_handled;
2293 - sectors_handled;
2294 r1_bio->state = 0; 2258 r1_bio->state = 0;
2295 set_bit(R1BIO_ReadError, &r1_bio->state); 2259 set_bit(R1BIO_ReadError, &r1_bio->state);
2296 r1_bio->mddev = mddev; 2260 r1_bio->mddev = mddev;
@@ -2464,18 +2428,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp
2464 for (i = 0; i < conf->raid_disks * 2; i++) { 2428 for (i = 0; i < conf->raid_disks * 2; i++) {
2465 struct md_rdev *rdev; 2429 struct md_rdev *rdev;
2466 bio = r1_bio->bios[i]; 2430 bio = r1_bio->bios[i];
2467 2431 bio_reset(bio);
2468 /* take from bio_init */
2469 bio->bi_next = NULL;
2470 bio->bi_flags &= ~(BIO_POOL_MASK-1);
2471 bio->bi_flags |= 1 << BIO_UPTODATE;
2472 bio->bi_rw = READ;
2473 bio->bi_vcnt = 0;
2474 bio->bi_idx = 0;
2475 bio->bi_phys_segments = 0;
2476 bio->bi_size = 0;
2477 bio->bi_end_io = NULL;
2478 bio->bi_private = NULL;
2479 2432
2480 rdev = rcu_dereference(conf->mirrors[i].rdev); 2433 rdev = rcu_dereference(conf->mirrors[i].rdev);
2481 if (rdev == NULL || 2434 if (rdev == NULL ||