Commit eb69aca5 authored by Heinz Mauelshagen's avatar Heinz Mauelshagen Committed by Alasdair G Kergon

dm kcopyd: clean interface

Clean up the kcopyd interface to prepare for publishing it in include/linux.
Signed-off-by: default avatarHeinz Mauelshagen <hjm@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 22a1ceb1
...@@ -133,7 +133,7 @@ struct mirror_set { ...@@ -133,7 +133,7 @@ struct mirror_set {
struct dm_target *ti; struct dm_target *ti;
struct list_head list; struct list_head list;
struct region_hash rh; struct region_hash rh;
struct kcopyd_client *kcopyd_client; struct dm_kcopyd_client *kcopyd_client;
uint64_t features; uint64_t features;
spinlock_t lock; /* protects the lists */ spinlock_t lock; /* protects the lists */
...@@ -788,7 +788,7 @@ static int recover(struct mirror_set *ms, struct region *reg) ...@@ -788,7 +788,7 @@ static int recover(struct mirror_set *ms, struct region *reg)
{ {
int r; int r;
unsigned int i; unsigned int i;
struct dm_io_region from, to[KCOPYD_MAX_REGIONS], *dest; struct dm_io_region from, to[DM_KCOPYD_MAX_REGIONS], *dest;
struct mirror *m; struct mirror *m;
unsigned long flags = 0; unsigned long flags = 0;
...@@ -820,9 +820,9 @@ static int recover(struct mirror_set *ms, struct region *reg) ...@@ -820,9 +820,9 @@ static int recover(struct mirror_set *ms, struct region *reg)
} }
/* hand to kcopyd */ /* hand to kcopyd */
set_bit(KCOPYD_IGNORE_ERROR, &flags); set_bit(DM_KCOPYD_IGNORE_ERROR, &flags);
r = kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to, flags, r = dm_kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to,
recovery_complete, reg); flags, recovery_complete, reg);
return r; return r;
} }
...@@ -1504,7 +1504,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -1504,7 +1504,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
argc -= args_used; argc -= args_used;
if (!argc || sscanf(argv[0], "%u", &nr_mirrors) != 1 || if (!argc || sscanf(argv[0], "%u", &nr_mirrors) != 1 ||
nr_mirrors < 2 || nr_mirrors > KCOPYD_MAX_REGIONS + 1) { nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) {
ti->error = "Invalid number of mirrors"; ti->error = "Invalid number of mirrors";
dm_destroy_dirty_log(dl); dm_destroy_dirty_log(dl);
return -EINVAL; return -EINVAL;
...@@ -1569,7 +1569,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -1569,7 +1569,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
goto err_destroy_wq; goto err_destroy_wq;
} }
r = kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client); r = dm_kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client);
if (r) if (r)
goto err_destroy_wq; goto err_destroy_wq;
...@@ -1588,7 +1588,7 @@ static void mirror_dtr(struct dm_target *ti) ...@@ -1588,7 +1588,7 @@ static void mirror_dtr(struct dm_target *ti)
struct mirror_set *ms = (struct mirror_set *) ti->private; struct mirror_set *ms = (struct mirror_set *) ti->private;
flush_workqueue(ms->kmirrord_wq); flush_workqueue(ms->kmirrord_wq);
kcopyd_client_destroy(ms->kcopyd_client); dm_kcopyd_client_destroy(ms->kcopyd_client);
destroy_workqueue(ms->kmirrord_wq); destroy_workqueue(ms->kmirrord_wq);
free_context(ms, ti, ms->nr_mirrors); free_context(ms, ti, ms->nr_mirrors);
} }
......
...@@ -558,7 +558,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -558,7 +558,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
goto bad4; goto bad4;
} }
r = kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client); r = dm_kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client);
if (r) { if (r) {
ti->error = "Could not create kcopyd client"; ti->error = "Could not create kcopyd client";
goto bad5; goto bad5;
...@@ -591,7 +591,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -591,7 +591,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
return 0; return 0;
bad6: bad6:
kcopyd_client_destroy(s->kcopyd_client); dm_kcopyd_client_destroy(s->kcopyd_client);
bad5: bad5:
s->store.destroy(&s->store); s->store.destroy(&s->store);
...@@ -613,7 +613,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -613,7 +613,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
static void __free_exceptions(struct dm_snapshot *s) static void __free_exceptions(struct dm_snapshot *s)
{ {
kcopyd_client_destroy(s->kcopyd_client); dm_kcopyd_client_destroy(s->kcopyd_client);
s->kcopyd_client = NULL; s->kcopyd_client = NULL;
exit_exception_table(&s->pending, pending_cache); exit_exception_table(&s->pending, pending_cache);
...@@ -839,7 +839,7 @@ static void start_copy(struct dm_snap_pending_exception *pe) ...@@ -839,7 +839,7 @@ static void start_copy(struct dm_snap_pending_exception *pe)
dest.count = src.count; dest.count = src.count;
/* Hand over to kcopyd */ /* Hand over to kcopyd */
kcopyd_copy(s->kcopyd_client, dm_kcopyd_copy(s->kcopyd_client,
&src, 1, &dest, 0, copy_callback, pe); &src, 1, &dest, 0, copy_callback, pe);
} }
......
...@@ -169,7 +169,7 @@ struct dm_snapshot { ...@@ -169,7 +169,7 @@ struct dm_snapshot {
/* The on disk metadata handler */ /* The on disk metadata handler */
struct exception_store store; struct exception_store store;
struct kcopyd_client *kcopyd_client; struct dm_kcopyd_client *kcopyd_client;
/* Queue of snapshot writes for ksnapd to flush */ /* Queue of snapshot writes for ksnapd to flush */
struct bio_list queued_bios; struct bio_list queued_bios;
......
...@@ -9,9 +9,8 @@ ...@@ -9,9 +9,8 @@
* completion notification. * completion notification.
*/ */
#include <asm/types.h> #include <linux/types.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -39,7 +38,7 @@ static void wake(void) ...@@ -39,7 +38,7 @@ static void wake(void)
* Each kcopyd client has its own little pool of preallocated * Each kcopyd client has its own little pool of preallocated
* pages for kcopyd io. * pages for kcopyd io.
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
struct kcopyd_client { struct dm_kcopyd_client {
struct list_head list; struct list_head list;
spinlock_t lock; spinlock_t lock;
...@@ -76,7 +75,7 @@ static void free_pl(struct page_list *pl) ...@@ -76,7 +75,7 @@ static void free_pl(struct page_list *pl)
kfree(pl); kfree(pl);
} }
static int kcopyd_get_pages(struct kcopyd_client *kc, static int kcopyd_get_pages(struct dm_kcopyd_client *kc,
unsigned int nr, struct page_list **pages) unsigned int nr, struct page_list **pages)
{ {
struct page_list *pl; struct page_list *pl;
...@@ -99,7 +98,7 @@ static int kcopyd_get_pages(struct kcopyd_client *kc, ...@@ -99,7 +98,7 @@ static int kcopyd_get_pages(struct kcopyd_client *kc,
return 0; return 0;
} }
static void kcopyd_put_pages(struct kcopyd_client *kc, struct page_list *pl) static void kcopyd_put_pages(struct dm_kcopyd_client *kc, struct page_list *pl)
{ {
struct page_list *cursor; struct page_list *cursor;
...@@ -127,7 +126,7 @@ static void drop_pages(struct page_list *pl) ...@@ -127,7 +126,7 @@ static void drop_pages(struct page_list *pl)
} }
} }
static int client_alloc_pages(struct kcopyd_client *kc, unsigned int nr) static int client_alloc_pages(struct dm_kcopyd_client *kc, unsigned int nr)
{ {
unsigned int i; unsigned int i;
struct page_list *pl = NULL, *next; struct page_list *pl = NULL, *next;
...@@ -148,7 +147,7 @@ static int client_alloc_pages(struct kcopyd_client *kc, unsigned int nr) ...@@ -148,7 +147,7 @@ static int client_alloc_pages(struct kcopyd_client *kc, unsigned int nr)
return 0; return 0;
} }
static void client_free_pages(struct kcopyd_client *kc) static void client_free_pages(struct dm_kcopyd_client *kc)
{ {
BUG_ON(kc->nr_free_pages != kc->nr_pages); BUG_ON(kc->nr_free_pages != kc->nr_pages);
drop_pages(kc->pages); drop_pages(kc->pages);
...@@ -162,7 +161,7 @@ static void client_free_pages(struct kcopyd_client *kc) ...@@ -162,7 +161,7 @@ static void client_free_pages(struct kcopyd_client *kc)
* ever having to do io (which could cause a deadlock). * ever having to do io (which could cause a deadlock).
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
struct kcopyd_job { struct kcopyd_job {
struct kcopyd_client *kc; struct dm_kcopyd_client *kc;
struct list_head list; struct list_head list;
unsigned long flags; unsigned long flags;
...@@ -182,7 +181,7 @@ struct kcopyd_job { ...@@ -182,7 +181,7 @@ struct kcopyd_job {
* The destinations for the transfer. * The destinations for the transfer.
*/ */
unsigned int num_dests; unsigned int num_dests;
struct dm_io_region dests[KCOPYD_MAX_REGIONS]; struct dm_io_region dests[DM_KCOPYD_MAX_REGIONS];
sector_t offset; sector_t offset;
unsigned int nr_pages; unsigned int nr_pages;
...@@ -192,7 +191,7 @@ struct kcopyd_job { ...@@ -192,7 +191,7 @@ struct kcopyd_job {
* Set this to ensure you are notified when the job has * Set this to ensure you are notified when the job has
* completed. 'context' is for callback to use. * completed. 'context' is for callback to use.
*/ */
kcopyd_notify_fn fn; dm_kcopyd_notify_fn fn;
void *context; void *context;
/* /*
...@@ -295,8 +294,8 @@ static int run_complete_job(struct kcopyd_job *job) ...@@ -295,8 +294,8 @@ static int run_complete_job(struct kcopyd_job *job)
void *context = job->context; void *context = job->context;
int read_err = job->read_err; int read_err = job->read_err;
unsigned long write_err = job->write_err; unsigned long write_err = job->write_err;
kcopyd_notify_fn fn = job->fn; dm_kcopyd_notify_fn fn = job->fn;
struct kcopyd_client *kc = job->kc; struct dm_kcopyd_client *kc = job->kc;
kcopyd_put_pages(kc, job->pages); kcopyd_put_pages(kc, job->pages);
mempool_free(job, _job_pool); mempool_free(job, _job_pool);
...@@ -318,7 +317,7 @@ static void complete_io(unsigned long error, void *context) ...@@ -318,7 +317,7 @@ static void complete_io(unsigned long error, void *context)
else else
job->read_err = 1; job->read_err = 1;
if (!test_bit(KCOPYD_IGNORE_ERROR, &job->flags)) { if (!test_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags)) {
push(&_complete_jobs, job); push(&_complete_jobs, job);
wake(); wake();
return; return;
...@@ -470,7 +469,7 @@ static void segment_complete(int read_err, unsigned long write_err, ...@@ -470,7 +469,7 @@ static void segment_complete(int read_err, unsigned long write_err,
* Only dispatch more work if there hasn't been an error. * Only dispatch more work if there hasn't been an error.
*/ */
if ((!job->read_err && !job->write_err) || if ((!job->read_err && !job->write_err) ||
test_bit(KCOPYD_IGNORE_ERROR, &job->flags)) { test_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags)) {
/* get the next chunk of work */ /* get the next chunk of work */
progress = job->progress; progress = job->progress;
count = job->source.count - progress; count = job->source.count - progress;
...@@ -527,9 +526,9 @@ static void split_job(struct kcopyd_job *job) ...@@ -527,9 +526,9 @@ static void split_job(struct kcopyd_job *job)
segment_complete(0, 0u, job); segment_complete(0, 0u, job);
} }
int kcopyd_copy(struct kcopyd_client *kc, struct dm_io_region *from, int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
unsigned int num_dests, struct dm_io_region *dests, unsigned int num_dests, struct dm_io_region *dests,
unsigned int flags, kcopyd_notify_fn fn, void *context) unsigned int flags, dm_kcopyd_notify_fn fn, void *context)
{ {
struct kcopyd_job *job; struct kcopyd_job *job;
...@@ -570,6 +569,7 @@ int kcopyd_copy(struct kcopyd_client *kc, struct dm_io_region *from, ...@@ -570,6 +569,7 @@ int kcopyd_copy(struct kcopyd_client *kc, struct dm_io_region *from,
return 0; return 0;
} }
EXPORT_SYMBOL(dm_kcopyd_copy);
/* /*
* Cancels a kcopyd job, eg. someone might be deactivating a * Cancels a kcopyd job, eg. someone might be deactivating a
...@@ -589,14 +589,14 @@ int kcopyd_cancel(struct kcopyd_job *job, int block) ...@@ -589,14 +589,14 @@ int kcopyd_cancel(struct kcopyd_job *job, int block)
static DEFINE_MUTEX(_client_lock); static DEFINE_MUTEX(_client_lock);
static LIST_HEAD(_clients); static LIST_HEAD(_clients);
static void client_add(struct kcopyd_client *kc) static void client_add(struct dm_kcopyd_client *kc)
{ {
mutex_lock(&_client_lock); mutex_lock(&_client_lock);
list_add(&kc->list, &_clients); list_add(&kc->list, &_clients);
mutex_unlock(&_client_lock); mutex_unlock(&_client_lock);
} }
static void client_del(struct kcopyd_client *kc) static void client_del(struct dm_kcopyd_client *kc)
{ {
mutex_lock(&_client_lock); mutex_lock(&_client_lock);
list_del(&kc->list); list_del(&kc->list);
...@@ -650,10 +650,11 @@ static void kcopyd_exit(void) ...@@ -650,10 +650,11 @@ static void kcopyd_exit(void)
mutex_unlock(&kcopyd_init_lock); mutex_unlock(&kcopyd_init_lock);
} }
int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result) int dm_kcopyd_client_create(unsigned int nr_pages,
struct dm_kcopyd_client **result)
{ {
int r = 0; int r = 0;
struct kcopyd_client *kc; struct dm_kcopyd_client *kc;
r = kcopyd_init(); r = kcopyd_init();
if (r) if (r)
...@@ -691,8 +692,9 @@ int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result) ...@@ -691,8 +692,9 @@ int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result)
*result = kc; *result = kc;
return 0; return 0;
} }
EXPORT_SYMBOL(dm_kcopyd_client_create);
void kcopyd_client_destroy(struct kcopyd_client *kc) void dm_kcopyd_client_destroy(struct dm_kcopyd_client *kc)
{ {
/* Wait for completion of all jobs submitted by this client. */ /* Wait for completion of all jobs submitted by this client. */
wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs)); wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs));
...@@ -703,7 +705,4 @@ void kcopyd_client_destroy(struct kcopyd_client *kc) ...@@ -703,7 +705,4 @@ void kcopyd_client_destroy(struct kcopyd_client *kc)
kfree(kc); kfree(kc);
kcopyd_exit(); kcopyd_exit();
} }
EXPORT_SYMBOL(dm_kcopyd_client_destroy);
EXPORT_SYMBOL(kcopyd_client_create);
EXPORT_SYMBOL(kcopyd_client_destroy);
EXPORT_SYMBOL(kcopyd_copy);
/* /*
* Copyright (C) 2001 Sistina Software * Copyright (C) 2001 - 2003 Sistina Software
* Copyright (C) 2004 - 2008 Red Hat, Inc. All rights reserved.
* *
* This file is released under the GPL. * kcopyd provides a simple interface for copying an area of one
* block-device to one or more other block-devices, either synchronous
* or with an asynchronous completion notification.
* *
* Kcopyd provides a simple interface for copying an area of one * This file is released under the GPL.
* block-device to one or more other block-devices, with an asynchronous
* completion notification.
*/ */
#ifndef DM_KCOPYD_H #ifndef _LINUX_DM_KCOPYD_H
#define DM_KCOPYD_H #define _LINUX_DM_KCOPYD_H
#ifdef __KERNEL__
#include "dm-io.h" #include "dm-io.h"
/* FIXME: make this configurable */ /* FIXME: make this configurable */
#define KCOPYD_MAX_REGIONS 8 #define DM_KCOPYD_MAX_REGIONS 8
#define KCOPYD_IGNORE_ERROR 1 #define DM_KCOPYD_IGNORE_ERROR 1
/* /*
* To use kcopyd you must first create a kcopyd client object. * To use kcopyd you must first create a dm_kcopyd_client object.
*/ */
struct kcopyd_client; struct dm_kcopyd_client;
int kcopyd_client_create(unsigned int num_pages, struct kcopyd_client **result); int dm_kcopyd_client_create(unsigned num_pages,
void kcopyd_client_destroy(struct kcopyd_client *kc); struct dm_kcopyd_client **result);
void dm_kcopyd_client_destroy(struct dm_kcopyd_client *kc);
/* /*
* Submit a copy job to kcopyd. This is built on top of the * 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,11 +36,12 @@ void kcopyd_client_destroy(struct kcopyd_client *kc);
* read_err is a boolean, * read_err is a boolean,
* write_err is a bitset, with 1 bit for each destination region * write_err is a bitset, with 1 bit for each destination region
*/ */
typedef void (*kcopyd_notify_fn)(int read_err, unsigned long write_err, typedef void (*dm_kcopyd_notify_fn)(int read_err, unsigned long write_err,
void *context); void *context);
int kcopyd_copy(struct kcopyd_client *kc, struct dm_io_region *from, int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
unsigned num_dests, struct dm_io_region *dests, unsigned num_dests, struct dm_io_region *dests,
unsigned int flags, kcopyd_notify_fn fn, void *context); unsigned flags, dm_kcopyd_notify_fn fn, void *context);
#endif #endif /* __KERNEL__ */
#endif /* _LINUX_DM_KCOPYD_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment