1 // SPDX-License-Identifier: GPL-2.0
2 /* Maximum size of each resync request */
3 #define RESYNC_BLOCK_SIZE (64*1024)
4 #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
6 /* for managing resync I/O pages */
9 struct page
*pages
[RESYNC_PAGES
];
12 static inline int resync_alloc_pages(struct resync_pages
*rp
,
17 for (i
= 0; i
< RESYNC_PAGES
; i
++) {
18 rp
->pages
[i
] = alloc_page(gfp_flags
);
27 put_page(rp
->pages
[i
]);
31 static inline void resync_free_pages(struct resync_pages
*rp
)
35 for (i
= 0; i
< RESYNC_PAGES
; i
++)
36 put_page(rp
->pages
[i
]);
39 static inline void resync_get_all_pages(struct resync_pages
*rp
)
43 for (i
= 0; i
< RESYNC_PAGES
; i
++)
44 get_page(rp
->pages
[i
]);
47 static inline struct page
*resync_fetch_page(struct resync_pages
*rp
,
50 if (WARN_ON_ONCE(idx
>= RESYNC_PAGES
))
52 return rp
->pages
[idx
];
56 * 'strct resync_pages' stores actual pages used for doing the resync
57 * IO, and it is per-bio, so make .bi_private points to it.
59 static inline struct resync_pages
*get_resync_pages(struct bio
*bio
)
61 return bio
->bi_private
;
64 /* generally called after bio_reset() for reseting bvec */
65 static void md_bio_reset_resync_pages(struct bio
*bio
, struct resync_pages
*rp
,
70 /* initialize bvec table again */
72 struct page
*page
= resync_fetch_page(rp
, idx
);
73 int len
= min_t(int, size
, PAGE_SIZE
);
76 * won't fail because the vec table is big
77 * enough to hold all these pages
79 bio_add_page(bio
, page
, len
, 0);
81 } while (idx
++ < RESYNC_PAGES
&& size
> 0);