diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-28 15:24:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-28 15:24:21 -0400 |
commit | 9583f1c99fe5a11b3f294ac8093e93f008bea29e (patch) | |
tree | 21a9b44d5e3b4e210559dd94c5e8b55c4d97c105 /drivers/md/raid1-10.c | |
parent | 1731a47444e7bf66d5cf9415bbd6ac5e3903d719 (diff) | |
parent | ed9b66d21866ae3bf16557406258ebe6c00a9a84 (diff) |
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/shli/md
Pull MD fixes from Shaohua Li:
"This fixes several bugs, three of them are marked for stable:
- an initialization issue fixed by Ming
- a bio clone race issue fixed by me
- an async tx flush issue fixed by Ofer
- other cleanups"
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/shli/md:
MD: fix warnning for UP case
md/raid5: add thread_group worker async_tx_issue_pending_all
md: simplify code with bio_io_error
md/raid1: fix writebehind bio clone
md: raid1-10: move raid1/raid10 common code into raid1-10.c
md: raid1/raid10: initialize bvec table via bio_add_page()
md: remove 'idx' from 'struct resync_pages'
Diffstat (limited to 'drivers/md/raid1-10.c')
-rw-r--r-- | drivers/md/raid1-10.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c new file mode 100644 index 000000000000..9f2670b45f31 --- /dev/null +++ b/drivers/md/raid1-10.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* Maximum size of each resync request */ | ||
2 | #define RESYNC_BLOCK_SIZE (64*1024) | ||
3 | #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE) | ||
4 | |||
5 | /* for managing resync I/O pages */ | ||
6 | struct resync_pages { | ||
7 | void *raid_bio; | ||
8 | struct page *pages[RESYNC_PAGES]; | ||
9 | }; | ||
10 | |||
11 | static inline int resync_alloc_pages(struct resync_pages *rp, | ||
12 | gfp_t gfp_flags) | ||
13 | { | ||
14 | int i; | ||
15 | |||
16 | for (i = 0; i < RESYNC_PAGES; i++) { | ||
17 | rp->pages[i] = alloc_page(gfp_flags); | ||
18 | if (!rp->pages[i]) | ||
19 | goto out_free; | ||
20 | } | ||
21 | |||
22 | return 0; | ||
23 | |||
24 | out_free: | ||
25 | while (--i >= 0) | ||
26 | put_page(rp->pages[i]); | ||
27 | return -ENOMEM; | ||
28 | } | ||
29 | |||
30 | static inline void resync_free_pages(struct resync_pages *rp) | ||
31 | { | ||
32 | int i; | ||
33 | |||
34 | for (i = 0; i < RESYNC_PAGES; i++) | ||
35 | put_page(rp->pages[i]); | ||
36 | } | ||
37 | |||
38 | static inline void resync_get_all_pages(struct resync_pages *rp) | ||
39 | { | ||
40 | int i; | ||
41 | |||
42 | for (i = 0; i < RESYNC_PAGES; i++) | ||
43 | get_page(rp->pages[i]); | ||
44 | } | ||
45 | |||
46 | static inline struct page *resync_fetch_page(struct resync_pages *rp, | ||
47 | unsigned idx) | ||
48 | { | ||
49 | if (WARN_ON_ONCE(idx >= RESYNC_PAGES)) | ||
50 | return NULL; | ||
51 | return rp->pages[idx]; | ||
52 | } | ||
53 | |||
54 | /* | ||
55 | * 'strct resync_pages' stores actual pages used for doing the resync | ||
56 | * IO, and it is per-bio, so make .bi_private points to it. | ||
57 | */ | ||
58 | static inline struct resync_pages *get_resync_pages(struct bio *bio) | ||
59 | { | ||
60 | return bio->bi_private; | ||
61 | } | ||
62 | |||
63 | /* generally called after bio_reset() for reseting bvec */ | ||
64 | static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp, | ||
65 | int size) | ||
66 | { | ||
67 | int idx = 0; | ||
68 | |||
69 | /* initialize bvec table again */ | ||
70 | do { | ||
71 | struct page *page = resync_fetch_page(rp, idx); | ||
72 | int len = min_t(int, size, PAGE_SIZE); | ||
73 | |||
74 | /* | ||
75 | * won't fail because the vec table is big | ||
76 | * enough to hold all these pages | ||
77 | */ | ||
78 | bio_add_page(bio, page, len, 0); | ||
79 | size -= len; | ||
80 | } while (idx++ < RESYNC_PAGES && size > 0); | ||
81 | } | ||