aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHeinz Mauelshagen <hjm@redhat.com>2008-04-24 16:43:19 -0400
committerAlasdair G Kergon <agk@redhat.com>2008-04-25 08:26:44 -0400
commiteb69aca5d3370b81450d68edeebc2bb9a3eb9689 (patch)
treeddb4c6d52e963b0898a892aaaee3228680e36449 /drivers
parent22a1ceb1e6a7fbce95a1531ff10bb4fb036d4a37 (diff)
dm kcopyd: clean interface
Clean up the kcopyd interface to prepare for publishing it in include/linux. Signed-off-by: Heinz Mauelshagen <hjm@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/md/dm-raid1.c16
-rw-r--r--drivers/md/dm-snap.c8
-rw-r--r--drivers/md/dm-snap.h2
-rw-r--r--drivers/md/kcopyd.c51
-rw-r--r--drivers/md/kcopyd.h43
5 files changed, 62 insertions, 58 deletions
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index 0d4e7e9653ff..32c7c6d10939 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -133,7 +133,7 @@ struct mirror_set {
133 struct dm_target *ti; 133 struct dm_target *ti;
134 struct list_head list; 134 struct list_head list;
135 struct region_hash rh; 135 struct region_hash rh;
136 struct kcopyd_client *kcopyd_client; 136 struct dm_kcopyd_client *kcopyd_client;
137 uint64_t features; 137 uint64_t features;
138 138
139 spinlock_t lock; /* protects the lists */ 139 spinlock_t lock; /* protects the lists */
@@ -788,7 +788,7 @@ static int recover(struct mirror_set *ms, struct region *reg)
788{ 788{
789 int r; 789 int r;
790 unsigned int i; 790 unsigned int i;
791 struct dm_io_region from, to[KCOPYD_MAX_REGIONS], *dest; 791 struct dm_io_region from, to[DM_KCOPYD_MAX_REGIONS], *dest;
792 struct mirror *m; 792 struct mirror *m;
793 unsigned long flags = 0; 793 unsigned long flags = 0;
794 794
@@ -820,9 +820,9 @@ static int recover(struct mirror_set *ms, struct region *reg)
820 } 820 }
821 821
822 /* hand to kcopyd */ 822 /* hand to kcopyd */
823 set_bit(KCOPYD_IGNORE_ERROR, &flags); 823 set_bit(DM_KCOPYD_IGNORE_ERROR, &flags);
824 r = kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to, flags, 824 r = dm_kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to,
825 recovery_complete, reg); 825 flags, recovery_complete, reg);
826 826
827 return r; 827 return r;
828} 828}
@@ -1504,7 +1504,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1504 argc -= args_used; 1504 argc -= args_used;
1505 1505
1506 if (!argc || sscanf(argv[0], "%u", &nr_mirrors) != 1 || 1506 if (!argc || sscanf(argv[0], "%u", &nr_mirrors) != 1 ||
1507 nr_mirrors < 2 || nr_mirrors > KCOPYD_MAX_REGIONS + 1) { 1507 nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) {
1508 ti->error = "Invalid number of mirrors"; 1508 ti->error = "Invalid number of mirrors";
1509 dm_destroy_dirty_log(dl); 1509 dm_destroy_dirty_log(dl);
1510 return -EINVAL; 1510 return -EINVAL;
@@ -1569,7 +1569,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1569 goto err_destroy_wq; 1569 goto err_destroy_wq;
1570 } 1570 }
1571 1571
1572 r = kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client); 1572 r = dm_kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client);
1573 if (r) 1573 if (r)
1574 goto err_destroy_wq; 1574 goto err_destroy_wq;
1575 1575
@@ -1588,7 +1588,7 @@ static void mirror_dtr(struct dm_target *ti)
1588 struct mirror_set *ms = (struct mirror_set *) ti->private; 1588 struct mirror_set *ms = (struct mirror_set *) ti->private;
1589 1589
1590 flush_workqueue(ms->kmirrord_wq); 1590 flush_workqueue(ms->kmirrord_wq);
1591 kcopyd_client_destroy(ms->kcopyd_client); 1591 dm_kcopyd_client_destroy(ms->kcopyd_client);
1592 destroy_workqueue(ms->kmirrord_wq); 1592 destroy_workqueue(ms->kmirrord_wq);
1593 free_context(ms, ti, ms->nr_mirrors); 1593 free_context(ms, ti, ms->nr_mirrors);
1594} 1594}
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index bab159b77742..e1dcca99392e 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -558,7 +558,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
558 goto bad4; 558 goto bad4;
559 } 559 }
560 560
561 r = kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client); 561 r = dm_kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client);
562 if (r) { 562 if (r) {
563 ti->error = "Could not create kcopyd client"; 563 ti->error = "Could not create kcopyd client";
564 goto bad5; 564 goto bad5;
@@ -591,7 +591,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
591 return 0; 591 return 0;
592 592
593 bad6: 593 bad6:
594 kcopyd_client_destroy(s->kcopyd_client); 594 dm_kcopyd_client_destroy(s->kcopyd_client);
595 595
596 bad5: 596 bad5:
597 s->store.destroy(&s->store); 597 s->store.destroy(&s->store);
@@ -613,7 +613,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
613 613
614static void __free_exceptions(struct dm_snapshot *s) 614static void __free_exceptions(struct dm_snapshot *s)
615{ 615{
616 kcopyd_client_destroy(s->kcopyd_client); 616 dm_kcopyd_client_destroy(s->kcopyd_client);
617 s->kcopyd_client = NULL; 617 s->kcopyd_client = NULL;
618 618
619 exit_exception_table(&s->pending, pending_cache); 619 exit_exception_table(&s->pending, pending_cache);
@@ -839,7 +839,7 @@ static void start_copy(struct dm_snap_pending_exception *pe)
839 dest.count = src.count; 839 dest.count = src.count;
840 840
841 /* Hand over to kcopyd */ 841 /* Hand over to kcopyd */
842 kcopyd_copy(s->kcopyd_client, 842 dm_kcopyd_copy(s->kcopyd_client,
843 &src, 1, &dest, 0, copy_callback, pe); 843 &src, 1, &dest, 0, copy_callback, pe);
844} 844}
845 845
diff --git a/drivers/md/dm-snap.h b/drivers/md/dm-snap.h
index 434d1dbe6bce..24f9fb73b982 100644
--- a/drivers/md/dm-snap.h
+++ b/drivers/md/dm-snap.h
@@ -169,7 +169,7 @@ struct dm_snapshot {
169 /* The on disk metadata handler */ 169 /* The on disk metadata handler */
170 struct exception_store store; 170 struct exception_store store;
171 171
172 struct kcopyd_client *kcopyd_client; 172 struct dm_kcopyd_client *kcopyd_client;
173 173
174 /* Queue of snapshot writes for ksnapd to flush */ 174 /* Queue of snapshot writes for ksnapd to flush */
175 struct bio_list queued_bios; 175 struct bio_list queued_bios;
diff --git a/drivers/md/kcopyd.c b/drivers/md/kcopyd.c
index 21fea42c68c4..4f2c61acf7c6 100644
--- a/drivers/md/kcopyd.c
+++ b/drivers/md/kcopyd.c
@@ -9,9 +9,8 @@
9 * completion notification. 9 * completion notification.
10 */ 10 */
11 11
12#include <asm/types.h> 12#include <linux/types.h>
13#include <asm/atomic.h> 13#include <asm/atomic.h>
14
15#include <linux/blkdev.h> 14#include <linux/blkdev.h>
16#include <linux/fs.h> 15#include <linux/fs.h>
17#include <linux/init.h> 16#include <linux/init.h>
@@ -39,7 +38,7 @@ static void wake(void)
39 * Each kcopyd client has its own little pool of preallocated 38 * Each kcopyd client has its own little pool of preallocated
40 * pages for kcopyd io. 39 * pages for kcopyd io.
41 *---------------------------------------------------------------*/ 40 *---------------------------------------------------------------*/
42struct kcopyd_client { 41struct dm_kcopyd_client {
43 struct list_head list; 42 struct list_head list;
44 43
45 spinlock_t lock; 44 spinlock_t lock;
@@ -76,7 +75,7 @@ static void free_pl(struct page_list *pl)
76 kfree(pl); 75 kfree(pl);
77} 76}
78 77
79static int kcopyd_get_pages(struct kcopyd_client *kc, 78static int kcopyd_get_pages(struct dm_kcopyd_client *kc,
80 unsigned int nr, struct page_list **pages) 79 unsigned int nr, struct page_list **pages)
81{ 80{
82 struct page_list *pl; 81 struct page_list *pl;
@@ -99,7 +98,7 @@ static int kcopyd_get_pages(struct kcopyd_client *kc,
99 return 0; 98 return 0;
100} 99}
101 100
102static void kcopyd_put_pages(struct kcopyd_client *kc, struct page_list *pl) 101static void kcopyd_put_pages(struct dm_kcopyd_client *kc, struct page_list *pl)
103{ 102{
104 struct page_list *cursor; 103 struct page_list *cursor;
105 104
@@ -127,7 +126,7 @@ static void drop_pages(struct page_list *pl)
127 } 126 }
128} 127}
129 128
130static int client_alloc_pages(struct kcopyd_client *kc, unsigned int nr) 129static int client_alloc_pages(struct dm_kcopyd_client *kc, unsigned int nr)
131{ 130{
132 unsigned int i; 131 unsigned int i;
133 struct page_list *pl = NULL, *next; 132 struct page_list *pl = NULL, *next;
@@ -148,7 +147,7 @@ static int client_alloc_pages(struct kcopyd_client *kc, unsigned int nr)
148 return 0; 147 return 0;
149} 148}
150 149
151static void client_free_pages(struct kcopyd_client *kc) 150static void client_free_pages(struct dm_kcopyd_client *kc)
152{ 151{
153 BUG_ON(kc->nr_free_pages != kc->nr_pages); 152 BUG_ON(kc->nr_free_pages != kc->nr_pages);
154 drop_pages(kc->pages); 153 drop_pages(kc->pages);
@@ -162,7 +161,7 @@ static void client_free_pages(struct kcopyd_client *kc)
162 * ever having to do io (which could cause a deadlock). 161 * ever having to do io (which could cause a deadlock).
163 *---------------------------------------------------------------*/ 162 *---------------------------------------------------------------*/
164struct kcopyd_job { 163struct kcopyd_job {
165 struct kcopyd_client *kc; 164 struct dm_kcopyd_client *kc;
166 struct list_head list; 165 struct list_head list;
167 unsigned long flags; 166 unsigned long flags;
168 167
@@ -182,7 +181,7 @@ struct kcopyd_job {
182 * The destinations for the transfer. 181 * The destinations for the transfer.
183 */ 182 */
184 unsigned int num_dests; 183 unsigned int num_dests;
185 struct dm_io_region dests[KCOPYD_MAX_REGIONS]; 184 struct dm_io_region dests[DM_KCOPYD_MAX_REGIONS];
186 185
187 sector_t offset; 186 sector_t offset;
188 unsigned int nr_pages; 187 unsigned int nr_pages;
@@ -192,7 +191,7 @@ struct kcopyd_job {
192 * Set this to ensure you are notified when the job has 191 * Set this to ensure you are notified when the job has
193 * completed. 'context' is for callback to use. 192 * completed. 'context' is for callback to use.
194 */ 193 */
195 kcopyd_notify_fn fn; 194 dm_kcopyd_notify_fn fn;
196 void *context; 195 void *context;
197 196
198 /* 197 /*
@@ -295,8 +294,8 @@ static int run_complete_job(struct kcopyd_job *job)
295 void *context = job->context; 294 void *context = job->context;
296 int read_err = job->read_err; 295 int read_err = job->read_err;
297 unsigned long write_err = job->write_err; 296 unsigned long write_err = job->write_err;
298 kcopyd_notify_fn fn = job->fn; 297 dm_kcopyd_notify_fn fn = job->fn;
299 struct kcopyd_client *kc = job->kc; 298 struct dm_kcopyd_client *kc = job->kc;
300 299
301 kcopyd_put_pages(kc, job->pages); 300 kcopyd_put_pages(kc, job->pages);
302 mempool_free(job, _job_pool); 301 mempool_free(job, _job_pool);
@@ -318,7 +317,7 @@ static void complete_io(unsigned long error, void *context)
318 else 317 else
319 job->read_err = 1; 318 job->read_err = 1;
320 319
321 if (!test_bit(KCOPYD_IGNORE_ERROR, &job->flags)) { 320 if (!test_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags)) {
322 push(&_complete_jobs, job); 321 push(&_complete_jobs, job);
323 wake(); 322 wake();
324 return; 323 return;
@@ -470,7 +469,7 @@ static void segment_complete(int read_err, unsigned long write_err,
470 * Only dispatch more work if there hasn't been an error. 469 * Only dispatch more work if there hasn't been an error.
471 */ 470 */
472 if ((!job->read_err && !job->write_err) || 471 if ((!job->read_err && !job->write_err) ||
473 test_bit(KCOPYD_IGNORE_ERROR, &job->flags)) { 472 test_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags)) {
474 /* get the next chunk of work */ 473 /* get the next chunk of work */
475 progress = job->progress; 474 progress = job->progress;
476 count = job->source.count - progress; 475 count = job->source.count - progress;
@@ -527,9 +526,9 @@ static void split_job(struct kcopyd_job *job)
527 segment_complete(0, 0u, job); 526 segment_complete(0, 0u, job);
528} 527}
529 528
530int kcopyd_copy(struct kcopyd_client *kc, struct dm_io_region *from, 529int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
531 unsigned int num_dests, struct dm_io_region *dests, 530 unsigned int num_dests, struct dm_io_region *dests,
532 unsigned int flags, kcopyd_notify_fn fn, void *context) 531 unsigned int flags, dm_kcopyd_notify_fn fn, void *context)
533{ 532{
534 struct kcopyd_job *job; 533 struct kcopyd_job *job;
535 534
@@ -570,6 +569,7 @@ int kcopyd_copy(struct kcopyd_client *kc, struct dm_io_region *from,
570 569
571 return 0; 570 return 0;
572} 571}
572EXPORT_SYMBOL(dm_kcopyd_copy);
573 573
574/* 574/*
575 * Cancels a kcopyd job, eg. someone might be deactivating a 575 * Cancels a kcopyd job, eg. someone might be deactivating a
@@ -589,14 +589,14 @@ int kcopyd_cancel(struct kcopyd_job *job, int block)
589static DEFINE_MUTEX(_client_lock); 589static DEFINE_MUTEX(_client_lock);
590static LIST_HEAD(_clients); 590static LIST_HEAD(_clients);
591 591
592static void client_add(struct kcopyd_client *kc) 592static void client_add(struct dm_kcopyd_client *kc)
593{ 593{
594 mutex_lock(&_client_lock); 594 mutex_lock(&_client_lock);
595 list_add(&kc->list, &_clients); 595 list_add(&kc->list, &_clients);
596 mutex_unlock(&_client_lock); 596 mutex_unlock(&_client_lock);
597} 597}
598 598
599static void client_del(struct kcopyd_client *kc) 599static void client_del(struct dm_kcopyd_client *kc)
600{ 600{
601 mutex_lock(&_client_lock); 601 mutex_lock(&_client_lock);
602 list_del(&kc->list); 602 list_del(&kc->list);
@@ -650,10 +650,11 @@ static void kcopyd_exit(void)
650 mutex_unlock(&kcopyd_init_lock); 650 mutex_unlock(&kcopyd_init_lock);
651} 651}
652 652
653int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result) 653int dm_kcopyd_client_create(unsigned int nr_pages,
654 struct dm_kcopyd_client **result)
654{ 655{
655 int r = 0; 656 int r = 0;
656 struct kcopyd_client *kc; 657 struct dm_kcopyd_client *kc;
657 658
658 r = kcopyd_init(); 659 r = kcopyd_init();
659 if (r) 660 if (r)
@@ -691,8 +692,9 @@ int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result)
691 *result = kc; 692 *result = kc;
692 return 0; 693 return 0;
693} 694}
695EXPORT_SYMBOL(dm_kcopyd_client_create);
694 696
695void kcopyd_client_destroy(struct kcopyd_client *kc) 697void dm_kcopyd_client_destroy(struct dm_kcopyd_client *kc)
696{ 698{
697 /* Wait for completion of all jobs submitted by this client. */ 699 /* Wait for completion of all jobs submitted by this client. */
698 wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs)); 700 wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs));
@@ -703,7 +705,4 @@ void kcopyd_client_destroy(struct kcopyd_client *kc)
703 kfree(kc); 705 kfree(kc);
704 kcopyd_exit(); 706 kcopyd_exit();
705} 707}
706 708EXPORT_SYMBOL(dm_kcopyd_client_destroy);
707EXPORT_SYMBOL(kcopyd_client_create);
708EXPORT_SYMBOL(kcopyd_client_destroy);
709EXPORT_SYMBOL(kcopyd_copy);
diff --git a/drivers/md/kcopyd.h b/drivers/md/kcopyd.h
index 588f05dffbe1..d3057846b0b0 100644
--- a/drivers/md/kcopyd.h
+++ b/drivers/md/kcopyd.h
@@ -1,29 +1,33 @@
1/* 1/*
2 * Copyright (C) 2001 Sistina Software 2 * Copyright (C) 2001 - 2003 Sistina Software
3 * Copyright (C) 2004 - 2008 Red Hat, Inc. All rights reserved.
3 * 4 *
4 * This file is released under the GPL. 5 * kcopyd provides a simple interface for copying an area of one
6 * block-device to one or more other block-devices, either synchronous
7 * or with an asynchronous completion notification.
5 * 8 *
6 * Kcopyd provides a simple interface for copying an area of one 9 * This file is released under the GPL.
7 * block-device to one or more other block-devices, with an asynchronous
8 * completion notification.
9 */ 10 */
10 11
11#ifndef DM_KCOPYD_H 12#ifndef _LINUX_DM_KCOPYD_H
12#define DM_KCOPYD_H 13#define _LINUX_DM_KCOPYD_H
14
15#ifdef __KERNEL__
13 16
14#include "dm-io.h" 17#include "dm-io.h"
15 18
16/* FIXME: make this configurable */ 19/* FIXME: make this configurable */
17#define KCOPYD_MAX_REGIONS 8 20#define DM_KCOPYD_MAX_REGIONS 8
18 21
19#define KCOPYD_IGNORE_ERROR 1 22#define DM_KCOPYD_IGNORE_ERROR 1
20 23
21/* 24/*
22 * To use kcopyd you must first create a kcopyd client object. 25 * To use kcopyd you must first create a dm_kcopyd_client object.
23 */ 26 */
24struct kcopyd_client; 27struct dm_kcopyd_client;
25int kcopyd_client_create(unsigned int num_pages, struct kcopyd_client **result); 28int dm_kcopyd_client_create(unsigned num_pages,
26void kcopyd_client_destroy(struct kcopyd_client *kc); 29 struct dm_kcopyd_client **result);
30void dm_kcopyd_client_destroy(struct dm_kcopyd_client *kc);
27 31
28/* 32/*
29 * Submit a copy job to kcopyd. This is built on top of the 33 * Submit a copy job to kcopyd. This is built on top of the
@@ -32,11 +36,12 @@ void kcopyd_client_destroy(struct kcopyd_client *kc);
32 * read_err is a boolean, 36 * read_err is a boolean,
33 * write_err is a bitset, with 1 bit for each destination region 37 * write_err is a bitset, with 1 bit for each destination region
34 */ 38 */
35typedef void (*kcopyd_notify_fn)(int read_err, unsigned long write_err, 39typedef void (*dm_kcopyd_notify_fn)(int read_err, unsigned long write_err,
36 void *context); 40 void *context);
37 41
38int kcopyd_copy(struct kcopyd_client *kc, struct dm_io_region *from, 42int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
39 unsigned num_dests, struct dm_io_region *dests, 43 unsigned num_dests, struct dm_io_region *dests,
40 unsigned int flags, kcopyd_notify_fn fn, void *context); 44 unsigned flags, dm_kcopyd_notify_fn fn, void *context);
41 45
42#endif 46#endif /* __KERNEL__ */
47#endif /* _LINUX_DM_KCOPYD_H */