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