12 #include <linux/types.h>
17 #include <linux/list.h>
19 #include <linux/module.h>
21 #include <linux/slab.h>
30 #define SUB_JOB_SIZE 128
33 #define RESERVE_PAGES (DIV_ROUND_UP(SUB_JOB_SIZE << SECTOR_SHIFT, PAGE_SIZE))
69 static struct page_list zero_page_list;
79 static struct page_list *alloc_pl(
gfp_t gfp)
96 static void free_pl(
struct page_list *pl)
108 struct page_list *
next;
116 pl->next = kc->
pages;
126 unsigned int nr,
struct page_list **
pages)
128 struct page_list *
pl;
139 kc->
pages = pl->next;
150 kcopyd_put_pages(kc, *pages);
157 static void drop_pages(
struct page_list *pl)
159 struct page_list *
next;
171 static int client_reserve_pages(
struct dm_kcopyd_client *kc,
unsigned nr_pages)
176 for (i = 0; i < nr_pages; i++) {
188 kcopyd_put_pages(kc, pl);
196 drop_pages(kc->
pages);
227 struct dm_io_region
dests[DM_KCOPYD_MAX_REGIONS];
235 dm_kcopyd_notify_fn
fn;
259 zero_page_list.next = &zero_page_list;
283 if (!list_empty(jobs)) {
287 spin_unlock_irqrestore(&kc->
job_lock, flags);
299 spin_unlock_irqrestore(&kc->
job_lock, flags);
309 list_add(&job->
list, jobs);
310 spin_unlock_irqrestore(&kc->
job_lock, flags);
322 static int run_complete_job(
struct kcopyd_job *job)
326 unsigned long write_err = job->
write_err;
327 dm_kcopyd_notify_fn
fn = job->
fn;
330 if (job->
pages && job->
pages != &zero_page_list)
331 kcopyd_put_pages(kc, job->
pages);
338 fn(read_err, write_err, context);
346 static void complete_io(
unsigned long error,
void *context)
382 struct dm_io_request
io_req = {
384 .mem.type = DM_IO_PAGE_LIST,
385 .mem.ptr.pl = job->
pages,
387 .notify.fn = complete_io,
388 .notify.context = job,
389 .client = job->
kc->io_client,
400 static int run_pages_job(
struct kcopyd_job *job)
405 r = kcopyd_get_pages(job->
kc, nr_pages, &job->
pages);
408 push(&job->
kc->io_jobs, job);
429 while ((job =
pop(jobs, kc))) {
448 push_head(jobs, job);
476 process_jobs(&kc->
pages_jobs, kc, run_pages_job);
477 process_jobs(&kc->
io_jobs, kc, run_io_job);
486 static void dispatch_job(
struct kcopyd_job *job)
492 else if (job->
pages == &zero_page_list)
499 static void segment_complete(
int read_err,
unsigned long write_err,
547 sub_job->
fn = segment_complete;
549 dispatch_job(sub_job);
570 static void split_job(
struct kcopyd_job *master_job)
579 segment_complete(0, 0
u, &master_job[i + 1]);
584 unsigned int num_dests,
struct dm_io_region *dests,
585 unsigned int flags, dm_kcopyd_notify_fn fn,
void *context)
604 memcpy(&job->
dests, dests,
sizeof(*dests) * num_dests);
613 job->
pages = &zero_page_list;
635 unsigned flags, dm_kcopyd_notify_fn fn,
void *context)
642 dm_kcopyd_notify_fn fn,
void *context)
716 goto bad_client_pages;
730 client_free_pages(kc);
752 client_free_pages(kc);