1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Copyright (C) 2001 - 2003 Sistina Software 3*4882a593Smuzhiyun * Copyright (C) 2004 - 2008 Red Hat, Inc. All rights reserved. 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * kcopyd provides a simple interface for copying an area of one 6*4882a593Smuzhiyun * block-device to one or more other block-devices, either synchronous 7*4882a593Smuzhiyun * or with an asynchronous completion notification. 8*4882a593Smuzhiyun * 9*4882a593Smuzhiyun * This file is released under the GPL. 10*4882a593Smuzhiyun */ 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun #ifndef _LINUX_DM_KCOPYD_H 13*4882a593Smuzhiyun #define _LINUX_DM_KCOPYD_H 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun #ifdef __KERNEL__ 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun #include <linux/dm-io.h> 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun /* FIXME: make this configurable */ 20*4882a593Smuzhiyun #define DM_KCOPYD_MAX_REGIONS 8 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun #define DM_KCOPYD_IGNORE_ERROR 1 23*4882a593Smuzhiyun #define DM_KCOPYD_WRITE_SEQ 2 24*4882a593Smuzhiyun #define DM_KCOPYD_SNAP_MERGE 3 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun struct dm_kcopyd_throttle { 27*4882a593Smuzhiyun unsigned throttle; 28*4882a593Smuzhiyun unsigned num_io_jobs; 29*4882a593Smuzhiyun unsigned io_period; 30*4882a593Smuzhiyun unsigned total_period; 31*4882a593Smuzhiyun unsigned last_jiffies; 32*4882a593Smuzhiyun }; 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun /* 35*4882a593Smuzhiyun * kcopyd clients that want to support throttling must pass an initialised 36*4882a593Smuzhiyun * dm_kcopyd_throttle struct into dm_kcopyd_client_create(). 37*4882a593Smuzhiyun * Two or more clients may share the same instance of this struct between 38*4882a593Smuzhiyun * them if they wish to be throttled as a group. 39*4882a593Smuzhiyun * 40*4882a593Smuzhiyun * This macro also creates a corresponding module parameter to configure 41*4882a593Smuzhiyun * the amount of throttling. 42*4882a593Smuzhiyun */ 43*4882a593Smuzhiyun #define DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(name, description) \ 44*4882a593Smuzhiyun static struct dm_kcopyd_throttle dm_kcopyd_throttle = { 100, 0, 0, 0, 0 }; \ 45*4882a593Smuzhiyun module_param_named(name, dm_kcopyd_throttle.throttle, uint, 0644); \ 46*4882a593Smuzhiyun MODULE_PARM_DESC(name, description) 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun /* 49*4882a593Smuzhiyun * To use kcopyd you must first create a dm_kcopyd_client object. 50*4882a593Smuzhiyun * throttle can be NULL if you don't want any throttling. 51*4882a593Smuzhiyun */ 52*4882a593Smuzhiyun struct dm_kcopyd_client; 53*4882a593Smuzhiyun struct dm_kcopyd_client *dm_kcopyd_client_create(struct dm_kcopyd_throttle *throttle); 54*4882a593Smuzhiyun void dm_kcopyd_client_destroy(struct dm_kcopyd_client *kc); 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun /* 57*4882a593Smuzhiyun * Submit a copy job to kcopyd. This is built on top of the 58*4882a593Smuzhiyun * previous three fns. 59*4882a593Smuzhiyun * 60*4882a593Smuzhiyun * read_err is a boolean, 61*4882a593Smuzhiyun * write_err is a bitset, with 1 bit for each destination region 62*4882a593Smuzhiyun */ 63*4882a593Smuzhiyun typedef void (*dm_kcopyd_notify_fn)(int read_err, unsigned long write_err, 64*4882a593Smuzhiyun void *context); 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun void dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from, 67*4882a593Smuzhiyun unsigned num_dests, struct dm_io_region *dests, 68*4882a593Smuzhiyun unsigned flags, dm_kcopyd_notify_fn fn, void *context); 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun /* 71*4882a593Smuzhiyun * Prepare a callback and submit it via the kcopyd thread. 72*4882a593Smuzhiyun * 73*4882a593Smuzhiyun * dm_kcopyd_prepare_callback allocates a callback structure and returns it. 74*4882a593Smuzhiyun * It must not be called from interrupt context. 75*4882a593Smuzhiyun * The returned value should be passed into dm_kcopyd_do_callback. 76*4882a593Smuzhiyun * 77*4882a593Smuzhiyun * dm_kcopyd_do_callback submits the callback. 78*4882a593Smuzhiyun * It may be called from interrupt context. 79*4882a593Smuzhiyun * The callback is issued from the kcopyd thread. 80*4882a593Smuzhiyun */ 81*4882a593Smuzhiyun void *dm_kcopyd_prepare_callback(struct dm_kcopyd_client *kc, 82*4882a593Smuzhiyun dm_kcopyd_notify_fn fn, void *context); 83*4882a593Smuzhiyun void dm_kcopyd_do_callback(void *job, int read_err, unsigned long write_err); 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun void dm_kcopyd_zero(struct dm_kcopyd_client *kc, 86*4882a593Smuzhiyun unsigned num_dests, struct dm_io_region *dests, 87*4882a593Smuzhiyun unsigned flags, dm_kcopyd_notify_fn fn, void *context); 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun #endif /* __KERNEL__ */ 90*4882a593Smuzhiyun #endif /* _LINUX_DM_KCOPYD_H */ 91