Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2001 - 2003 Sistina Software
0003  * Copyright (C) 2004 - 2008 Red Hat, Inc. All rights reserved.
0004  *
0005  * kcopyd provides a simple interface for copying an area of one
0006  * block-device to one or more other block-devices, either synchronous
0007  * or with an asynchronous completion notification.
0008  *
0009  * This file is released under the GPL.
0010  */
0011 
0012 #ifndef _LINUX_DM_KCOPYD_H
0013 #define _LINUX_DM_KCOPYD_H
0014 
0015 #ifdef __KERNEL__
0016 
0017 #include <linux/dm-io.h>
0018 
0019 /* FIXME: make this configurable */
0020 #define DM_KCOPYD_MAX_REGIONS 8
0021 
0022 #define DM_KCOPYD_IGNORE_ERROR 1
0023 #define DM_KCOPYD_WRITE_SEQ    2
0024 
0025 struct dm_kcopyd_throttle {
0026     unsigned throttle;
0027     unsigned num_io_jobs;
0028     unsigned io_period;
0029     unsigned total_period;
0030     unsigned last_jiffies;
0031 };
0032 
0033 /*
0034  * kcopyd clients that want to support throttling must pass an initialised
0035  * dm_kcopyd_throttle struct into dm_kcopyd_client_create().
0036  * Two or more clients may share the same instance of this struct between
0037  * them if they wish to be throttled as a group.
0038  *
0039  * This macro also creates a corresponding module parameter to configure
0040  * the amount of throttling.
0041  */
0042 #define DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(name, description)  \
0043 static struct dm_kcopyd_throttle dm_kcopyd_throttle = { 100, 0, 0, 0, 0 }; \
0044 module_param_named(name, dm_kcopyd_throttle.throttle, uint, 0644); \
0045 MODULE_PARM_DESC(name, description)
0046 
0047 /*
0048  * To use kcopyd you must first create a dm_kcopyd_client object.
0049  * throttle can be NULL if you don't want any throttling.
0050  */
0051 struct dm_kcopyd_client;
0052 struct dm_kcopyd_client *dm_kcopyd_client_create(struct dm_kcopyd_throttle *throttle);
0053 void dm_kcopyd_client_destroy(struct dm_kcopyd_client *kc);
0054 void dm_kcopyd_client_flush(struct dm_kcopyd_client *kc);
0055 
0056 /*
0057  * Submit a copy job to kcopyd.  This is built on top of the
0058  * previous three fns.
0059  *
0060  * read_err is a boolean,
0061  * write_err is a bitset, with 1 bit for each destination region
0062  */
0063 typedef void (*dm_kcopyd_notify_fn)(int read_err, unsigned long write_err,
0064                     void *context);
0065 
0066 void dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
0067             unsigned num_dests, struct dm_io_region *dests,
0068             unsigned flags, dm_kcopyd_notify_fn fn, void *context);
0069 
0070 /*
0071  * Prepare a callback and submit it via the kcopyd thread.
0072  *
0073  * dm_kcopyd_prepare_callback allocates a callback structure and returns it.
0074  * It must not be called from interrupt context.
0075  * The returned value should be passed into dm_kcopyd_do_callback.
0076  *
0077  * dm_kcopyd_do_callback submits the callback.
0078  * It may be called from interrupt context.
0079  * The callback is issued from the kcopyd thread.
0080  */
0081 void *dm_kcopyd_prepare_callback(struct dm_kcopyd_client *kc,
0082                  dm_kcopyd_notify_fn fn, void *context);
0083 void dm_kcopyd_do_callback(void *job, int read_err, unsigned long write_err);
0084 
0085 void dm_kcopyd_zero(struct dm_kcopyd_client *kc,
0086             unsigned num_dests, struct dm_io_region *dests,
0087             unsigned flags, dm_kcopyd_notify_fn fn, void *context);
0088 
0089 #endif  /* __KERNEL__ */
0090 #endif  /* _LINUX_DM_KCOPYD_H */