xref: /openbmc/linux/include/linux/device-mapper.h (revision 498f0103ea13123e007660def9072a0b7dd1c599)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Copyright (C) 2001 Sistina Software (UK) Limited.
30da336e5SAlasdair G Kergon  * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * This file is released under the LGPL.
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #ifndef _LINUX_DEVICE_MAPPER_H
91da177e4SLinus Torvalds #define _LINUX_DEVICE_MAPPER_H
101da177e4SLinus Torvalds 
11416cd17bSHeinz Mauelshagen #include <linux/bio.h>
12f6fccb12SMilan Broz #include <linux/blkdev.h>
13416cd17bSHeinz Mauelshagen 
14af4874e0SMike Snitzer struct dm_dev;
151da177e4SLinus Torvalds struct dm_target;
161da177e4SLinus Torvalds struct dm_table;
1717b2f66fSAlasdair G Kergon struct mapped_device;
18f6fccb12SMilan Broz struct bio_vec;
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds union map_info {
231da177e4SLinus Torvalds 	void *ptr;
241da177e4SLinus Torvalds 	unsigned long long ll;
2557cba5d3SMike Snitzer 	unsigned target_request_nr;
261da177e4SLinus Torvalds };
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds /*
291da177e4SLinus Torvalds  * In the constructor the target parameter will already have the
301da177e4SLinus Torvalds  * table, type, begin and len fields filled in.
311da177e4SLinus Torvalds  */
321da177e4SLinus Torvalds typedef int (*dm_ctr_fn) (struct dm_target *target,
331da177e4SLinus Torvalds 			  unsigned int argc, char **argv);
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds /*
361da177e4SLinus Torvalds  * The destructor doesn't need to free the dm_target, just
371da177e4SLinus Torvalds  * anything hidden ti->private.
381da177e4SLinus Torvalds  */
391da177e4SLinus Torvalds typedef void (*dm_dtr_fn) (struct dm_target *ti);
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds /*
421da177e4SLinus Torvalds  * The map function must return:
431da177e4SLinus Torvalds  * < 0: error
441da177e4SLinus Torvalds  * = 0: The target will handle the io by resubmitting it later
4545cbcd79SKiyoshi Ueda  * = 1: simple remap complete
462e93ccc1SKiyoshi Ueda  * = 2: The target wants to push back the io
471da177e4SLinus Torvalds  */
481da177e4SLinus Torvalds typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
491da177e4SLinus Torvalds 			  union map_info *map_context);
507d76345dSKiyoshi Ueda typedef int (*dm_map_request_fn) (struct dm_target *ti, struct request *clone,
517d76345dSKiyoshi Ueda 				  union map_info *map_context);
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds /*
541da177e4SLinus Torvalds  * Returns:
551da177e4SLinus Torvalds  * < 0 : error (currently ignored)
561da177e4SLinus Torvalds  * 0   : ended successfully
571da177e4SLinus Torvalds  * 1   : for some reason the io has still not completed (eg,
581da177e4SLinus Torvalds  *       multipath target might want to requeue a failed io).
592e93ccc1SKiyoshi Ueda  * 2   : The target wants to push back the io
601da177e4SLinus Torvalds  */
611da177e4SLinus Torvalds typedef int (*dm_endio_fn) (struct dm_target *ti,
621da177e4SLinus Torvalds 			    struct bio *bio, int error,
631da177e4SLinus Torvalds 			    union map_info *map_context);
647d76345dSKiyoshi Ueda typedef int (*dm_request_endio_fn) (struct dm_target *ti,
657d76345dSKiyoshi Ueda 				    struct request *clone, int error,
667d76345dSKiyoshi Ueda 				    union map_info *map_context);
671da177e4SLinus Torvalds 
68999d8168SBryn Reeves typedef void (*dm_flush_fn) (struct dm_target *ti);
691da177e4SLinus Torvalds typedef void (*dm_presuspend_fn) (struct dm_target *ti);
701da177e4SLinus Torvalds typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
718757b776SMilan Broz typedef int (*dm_preresume_fn) (struct dm_target *ti);
721da177e4SLinus Torvalds typedef void (*dm_resume_fn) (struct dm_target *ti);
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
751da177e4SLinus Torvalds 			     char *result, unsigned int maxlen);
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
781da177e4SLinus Torvalds 
79647b3d00SAl Viro typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd,
80aa129a22SMilan Broz 			    unsigned long arg);
81aa129a22SMilan Broz 
82f6fccb12SMilan Broz typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
83f6fccb12SMilan Broz 			    struct bio_vec *biovec, int max_size);
84f6fccb12SMilan Broz 
85af4874e0SMike Snitzer typedef int (*iterate_devices_callout_fn) (struct dm_target *ti,
86af4874e0SMike Snitzer 					   struct dm_dev *dev,
875dea271bSMike Snitzer 					   sector_t start, sector_t len,
88af4874e0SMike Snitzer 					   void *data);
89af4874e0SMike Snitzer 
90af4874e0SMike Snitzer typedef int (*dm_iterate_devices_fn) (struct dm_target *ti,
91af4874e0SMike Snitzer 				      iterate_devices_callout_fn fn,
92af4874e0SMike Snitzer 				      void *data);
93af4874e0SMike Snitzer 
9440bea431SMike Snitzer typedef void (*dm_io_hints_fn) (struct dm_target *ti,
9540bea431SMike Snitzer 				struct queue_limits *limits);
9640bea431SMike Snitzer 
977d76345dSKiyoshi Ueda /*
987d76345dSKiyoshi Ueda  * Returns:
997d76345dSKiyoshi Ueda  *    0: The target can handle the next I/O immediately.
1007d76345dSKiyoshi Ueda  *    1: The target can't handle the next I/O immediately.
1017d76345dSKiyoshi Ueda  */
1027d76345dSKiyoshi Ueda typedef int (*dm_busy_fn) (struct dm_target *ti);
1037d76345dSKiyoshi Ueda 
1041da177e4SLinus Torvalds void dm_error(const char *message);
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds /*
1073cb40214SBryn Reeves  * Combine device limits.
1083cb40214SBryn Reeves  */
109754c5fc7SMike Snitzer int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
1105dea271bSMike Snitzer 			 sector_t start, sector_t len, void *data);
1113cb40214SBryn Reeves 
11282b1519bSMikulas Patocka struct dm_dev {
11382b1519bSMikulas Patocka 	struct block_device *bdev;
114aeb5d727SAl Viro 	fmode_t mode;
11582b1519bSMikulas Patocka 	char name[16];
11682b1519bSMikulas Patocka };
11782b1519bSMikulas Patocka 
1183cb40214SBryn Reeves /*
1191da177e4SLinus Torvalds  * Constructors should call these functions to ensure destination devices
1201da177e4SLinus Torvalds  * are opened/closed correctly.
1211da177e4SLinus Torvalds  */
1228215d6ecSNikanth Karthikesan int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
1238215d6ecSNikanth Karthikesan 						 struct dm_dev **result);
1241da177e4SLinus Torvalds void dm_put_device(struct dm_target *ti, struct dm_dev *d);
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds /*
1271da177e4SLinus Torvalds  * Information about a target type
1281da177e4SLinus Torvalds  */
129ab4c1424SAndi Kleen 
130ab4c1424SAndi Kleen /*
131ab4c1424SAndi Kleen  * Target features
132ab4c1424SAndi Kleen  */
133ab4c1424SAndi Kleen 
1341da177e4SLinus Torvalds struct target_type {
135ab4c1424SAndi Kleen 	uint64_t features;
1361da177e4SLinus Torvalds 	const char *name;
1371da177e4SLinus Torvalds 	struct module *module;
1381da177e4SLinus Torvalds 	unsigned version[3];
1391da177e4SLinus Torvalds 	dm_ctr_fn ctr;
1401da177e4SLinus Torvalds 	dm_dtr_fn dtr;
1411da177e4SLinus Torvalds 	dm_map_fn map;
1427d76345dSKiyoshi Ueda 	dm_map_request_fn map_rq;
1431da177e4SLinus Torvalds 	dm_endio_fn end_io;
1447d76345dSKiyoshi Ueda 	dm_request_endio_fn rq_end_io;
145999d8168SBryn Reeves 	dm_flush_fn flush;
1461da177e4SLinus Torvalds 	dm_presuspend_fn presuspend;
1471da177e4SLinus Torvalds 	dm_postsuspend_fn postsuspend;
1488757b776SMilan Broz 	dm_preresume_fn preresume;
1491da177e4SLinus Torvalds 	dm_resume_fn resume;
1501da177e4SLinus Torvalds 	dm_status_fn status;
1511da177e4SLinus Torvalds 	dm_message_fn message;
152aa129a22SMilan Broz 	dm_ioctl_fn ioctl;
153f6fccb12SMilan Broz 	dm_merge_fn merge;
1547d76345dSKiyoshi Ueda 	dm_busy_fn busy;
155af4874e0SMike Snitzer 	dm_iterate_devices_fn iterate_devices;
15640bea431SMike Snitzer 	dm_io_hints_fn io_hints;
15745194e4fSCheng Renquan 
15845194e4fSCheng Renquan 	/* For internal device-mapper use. */
15945194e4fSCheng Renquan 	struct list_head list;
1601da177e4SLinus Torvalds };
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds struct dm_target {
1631da177e4SLinus Torvalds 	struct dm_table *table;
1641da177e4SLinus Torvalds 	struct target_type *type;
1651da177e4SLinus Torvalds 
1661da177e4SLinus Torvalds 	/* target limits */
1671da177e4SLinus Torvalds 	sector_t begin;
1681da177e4SLinus Torvalds 	sector_t len;
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds 	/* Always a power of 2 */
1711da177e4SLinus Torvalds 	sector_t split_io;
1721da177e4SLinus Torvalds 
1731da177e4SLinus Torvalds 	/*
174f9ab94ceSMikulas Patocka 	 * A number of zero-length barrier requests that will be submitted
175f9ab94ceSMikulas Patocka 	 * to the target for the purpose of flushing cache.
176f9ab94ceSMikulas Patocka 	 *
17757cba5d3SMike Snitzer 	 * The request number will be placed in union map_info->target_request_nr.
178f9ab94ceSMikulas Patocka 	 * It is a responsibility of the target driver to remap these requests
179f9ab94ceSMikulas Patocka 	 * to the real underlying devices.
180f9ab94ceSMikulas Patocka 	 */
181f9ab94ceSMikulas Patocka 	unsigned num_flush_requests;
182f9ab94ceSMikulas Patocka 
1835ae89a87SMike Snitzer 	/*
1845ae89a87SMike Snitzer 	 * The number of discard requests that will be submitted to the
1855ae89a87SMike Snitzer 	 * target.  map_info->request_nr is used just like num_flush_requests.
1865ae89a87SMike Snitzer 	 */
1875ae89a87SMike Snitzer 	unsigned num_discard_requests;
1885ae89a87SMike Snitzer 
1891da177e4SLinus Torvalds 	/* target specific data */
1901da177e4SLinus Torvalds 	void *private;
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds 	/* Used to provide an error string from the ctr */
1931da177e4SLinus Torvalds 	char *error;
1944c259327SMike Snitzer 
1954c259327SMike Snitzer 	/*
1964c259327SMike Snitzer 	 * Set if this target needs to receive discards regardless of
1974c259327SMike Snitzer 	 * whether or not its underlying devices have support.
1984c259327SMike Snitzer 	 */
1994c259327SMike Snitzer 	unsigned discards_supported:1;
2001da177e4SLinus Torvalds };
2011da177e4SLinus Torvalds 
2029d357b07SNeilBrown /* Each target can link one of these into the table */
2039d357b07SNeilBrown struct dm_target_callbacks {
2049d357b07SNeilBrown 	struct list_head list;
2059d357b07SNeilBrown 	int (*congested_fn) (struct dm_target_callbacks *, int);
2069d357b07SNeilBrown };
2079d357b07SNeilBrown 
2081da177e4SLinus Torvalds int dm_register_target(struct target_type *t);
20910d3bd09SMikulas Patocka void dm_unregister_target(struct target_type *t);
21017b2f66fSAlasdair G Kergon 
211*498f0103SMike Snitzer /*
212*498f0103SMike Snitzer  * Target argument parsing.
213*498f0103SMike Snitzer  */
214*498f0103SMike Snitzer struct dm_arg_set {
215*498f0103SMike Snitzer 	unsigned argc;
216*498f0103SMike Snitzer 	char **argv;
217*498f0103SMike Snitzer };
218*498f0103SMike Snitzer 
219*498f0103SMike Snitzer /*
220*498f0103SMike Snitzer  * The minimum and maximum value of a numeric argument, together with
221*498f0103SMike Snitzer  * the error message to use if the number is found to be outside that range.
222*498f0103SMike Snitzer  */
223*498f0103SMike Snitzer struct dm_arg {
224*498f0103SMike Snitzer 	unsigned min;
225*498f0103SMike Snitzer 	unsigned max;
226*498f0103SMike Snitzer 	char *error;
227*498f0103SMike Snitzer };
228*498f0103SMike Snitzer 
229*498f0103SMike Snitzer /*
230*498f0103SMike Snitzer  * Validate the next argument, either returning it as *value or, if invalid,
231*498f0103SMike Snitzer  * returning -EINVAL and setting *error.
232*498f0103SMike Snitzer  */
233*498f0103SMike Snitzer int dm_read_arg(struct dm_arg *arg, struct dm_arg_set *arg_set,
234*498f0103SMike Snitzer 		unsigned *value, char **error);
235*498f0103SMike Snitzer 
236*498f0103SMike Snitzer /*
237*498f0103SMike Snitzer  * Process the next argument as the start of a group containing between
238*498f0103SMike Snitzer  * arg->min and arg->max further arguments. Either return the size as
239*498f0103SMike Snitzer  * *num_args or, if invalid, return -EINVAL and set *error.
240*498f0103SMike Snitzer  */
241*498f0103SMike Snitzer int dm_read_arg_group(struct dm_arg *arg, struct dm_arg_set *arg_set,
242*498f0103SMike Snitzer 		      unsigned *num_args, char **error);
243*498f0103SMike Snitzer 
244*498f0103SMike Snitzer /*
245*498f0103SMike Snitzer  * Return the current argument and shift to the next.
246*498f0103SMike Snitzer  */
247*498f0103SMike Snitzer const char *dm_shift_arg(struct dm_arg_set *as);
248*498f0103SMike Snitzer 
249*498f0103SMike Snitzer /*
250*498f0103SMike Snitzer  * Move through num_args arguments.
251*498f0103SMike Snitzer  */
252*498f0103SMike Snitzer void dm_consume_args(struct dm_arg_set *as, unsigned num_args);
253*498f0103SMike Snitzer 
25417b2f66fSAlasdair G Kergon /*-----------------------------------------------------------------
25517b2f66fSAlasdair G Kergon  * Functions for creating and manipulating mapped devices.
25617b2f66fSAlasdair G Kergon  * Drop the reference with dm_put when you finish with the object.
25717b2f66fSAlasdair G Kergon  *---------------------------------------------------------------*/
25817b2f66fSAlasdair G Kergon 
25917b2f66fSAlasdair G Kergon /*
26017b2f66fSAlasdair G Kergon  * DM_ANY_MINOR chooses the next available minor number.
26117b2f66fSAlasdair G Kergon  */
26217b2f66fSAlasdair G Kergon #define DM_ANY_MINOR (-1)
26317b2f66fSAlasdair G Kergon int dm_create(int minor, struct mapped_device **md);
26417b2f66fSAlasdair G Kergon 
26517b2f66fSAlasdair G Kergon /*
26617b2f66fSAlasdair G Kergon  * Reference counting for md.
26717b2f66fSAlasdair G Kergon  */
26817b2f66fSAlasdair G Kergon struct mapped_device *dm_get_md(dev_t dev);
26917b2f66fSAlasdair G Kergon void dm_get(struct mapped_device *md);
27017b2f66fSAlasdair G Kergon void dm_put(struct mapped_device *md);
27117b2f66fSAlasdair G Kergon 
27217b2f66fSAlasdair G Kergon /*
27317b2f66fSAlasdair G Kergon  * An arbitrary pointer may be stored alongside a mapped device.
27417b2f66fSAlasdair G Kergon  */
27517b2f66fSAlasdair G Kergon void dm_set_mdptr(struct mapped_device *md, void *ptr);
27617b2f66fSAlasdair G Kergon void *dm_get_mdptr(struct mapped_device *md);
27717b2f66fSAlasdair G Kergon 
27817b2f66fSAlasdair G Kergon /*
27917b2f66fSAlasdair G Kergon  * A device can still be used while suspended, but I/O is deferred.
28017b2f66fSAlasdair G Kergon  */
281a3d77d35SKiyoshi Ueda int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
28217b2f66fSAlasdair G Kergon int dm_resume(struct mapped_device *md);
28317b2f66fSAlasdair G Kergon 
28417b2f66fSAlasdair G Kergon /*
28517b2f66fSAlasdair G Kergon  * Event functions.
28617b2f66fSAlasdair G Kergon  */
28717b2f66fSAlasdair G Kergon uint32_t dm_get_event_nr(struct mapped_device *md);
28817b2f66fSAlasdair G Kergon int dm_wait_event(struct mapped_device *md, int event_nr);
2897a8c3d3bSMike Anderson uint32_t dm_next_uevent_seq(struct mapped_device *md);
2907a8c3d3bSMike Anderson void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
29117b2f66fSAlasdair G Kergon 
29217b2f66fSAlasdair G Kergon /*
29317b2f66fSAlasdair G Kergon  * Info functions.
29417b2f66fSAlasdair G Kergon  */
29572d94861SAlasdair G Kergon const char *dm_device_name(struct mapped_device *md);
29696a1f7dbSMike Anderson int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
29717b2f66fSAlasdair G Kergon struct gendisk *dm_disk(struct mapped_device *md);
29864dbce58SKiyoshi Ueda int dm_suspended(struct dm_target *ti);
2992e93ccc1SKiyoshi Ueda int dm_noflush_suspending(struct dm_target *ti);
30089343da0SMikulas Patocka union map_info *dm_get_mapinfo(struct bio *bio);
301cec47e3dSKiyoshi Ueda union map_info *dm_get_rq_mapinfo(struct request *rq);
30217b2f66fSAlasdair G Kergon 
30317b2f66fSAlasdair G Kergon /*
30417b2f66fSAlasdair G Kergon  * Geometry functions.
30517b2f66fSAlasdair G Kergon  */
30617b2f66fSAlasdair G Kergon int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
30717b2f66fSAlasdair G Kergon int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
30817b2f66fSAlasdair G Kergon 
30917b2f66fSAlasdair G Kergon 
31017b2f66fSAlasdair G Kergon /*-----------------------------------------------------------------
31117b2f66fSAlasdair G Kergon  * Functions for manipulating device-mapper tables.
31217b2f66fSAlasdair G Kergon  *---------------------------------------------------------------*/
31317b2f66fSAlasdair G Kergon 
31417b2f66fSAlasdair G Kergon /*
31517b2f66fSAlasdair G Kergon  * First create an empty table.
31617b2f66fSAlasdair G Kergon  */
317aeb5d727SAl Viro int dm_table_create(struct dm_table **result, fmode_t mode,
31817b2f66fSAlasdair G Kergon 		    unsigned num_targets, struct mapped_device *md);
31917b2f66fSAlasdair G Kergon 
32017b2f66fSAlasdair G Kergon /*
32117b2f66fSAlasdair G Kergon  * Then call this once for each target.
32217b2f66fSAlasdair G Kergon  */
32317b2f66fSAlasdair G Kergon int dm_table_add_target(struct dm_table *t, const char *type,
32417b2f66fSAlasdair G Kergon 			sector_t start, sector_t len, char *params);
32517b2f66fSAlasdair G Kergon 
32617b2f66fSAlasdair G Kergon /*
3279d357b07SNeilBrown  * Target_ctr should call this if it needs to add any callbacks.
3289d357b07SNeilBrown  */
3299d357b07SNeilBrown void dm_table_add_target_callbacks(struct dm_table *t, struct dm_target_callbacks *cb);
3309d357b07SNeilBrown 
3319d357b07SNeilBrown /*
33217b2f66fSAlasdair G Kergon  * Finally call this to make the table ready for use.
33317b2f66fSAlasdair G Kergon  */
33417b2f66fSAlasdair G Kergon int dm_table_complete(struct dm_table *t);
33517b2f66fSAlasdair G Kergon 
33617b2f66fSAlasdair G Kergon /*
33717b2f66fSAlasdair G Kergon  * Table reference counting.
33817b2f66fSAlasdair G Kergon  */
3397c666411SAlasdair G Kergon struct dm_table *dm_get_live_table(struct mapped_device *md);
34017b2f66fSAlasdair G Kergon void dm_table_get(struct dm_table *t);
34117b2f66fSAlasdair G Kergon void dm_table_put(struct dm_table *t);
34217b2f66fSAlasdair G Kergon 
34317b2f66fSAlasdair G Kergon /*
34417b2f66fSAlasdair G Kergon  * Queries
34517b2f66fSAlasdair G Kergon  */
34617b2f66fSAlasdair G Kergon sector_t dm_table_get_size(struct dm_table *t);
34717b2f66fSAlasdair G Kergon unsigned int dm_table_get_num_targets(struct dm_table *t);
348aeb5d727SAl Viro fmode_t dm_table_get_mode(struct dm_table *t);
34917b2f66fSAlasdair G Kergon struct mapped_device *dm_table_get_md(struct dm_table *t);
35017b2f66fSAlasdair G Kergon 
35117b2f66fSAlasdair G Kergon /*
35217b2f66fSAlasdair G Kergon  * Trigger an event.
35317b2f66fSAlasdair G Kergon  */
35417b2f66fSAlasdair G Kergon void dm_table_event(struct dm_table *t);
35517b2f66fSAlasdair G Kergon 
35617b2f66fSAlasdair G Kergon /*
35717b2f66fSAlasdair G Kergon  * The device must be suspended before calling this method.
358042d2a9bSAlasdair G Kergon  * Returns the previous table, which the caller must destroy.
35917b2f66fSAlasdair G Kergon  */
360042d2a9bSAlasdair G Kergon struct dm_table *dm_swap_table(struct mapped_device *md,
361042d2a9bSAlasdair G Kergon 			       struct dm_table *t);
36217b2f66fSAlasdair G Kergon 
36354160904SMikulas Patocka /*
36454160904SMikulas Patocka  * A wrapper around vmalloc.
36554160904SMikulas Patocka  */
36654160904SMikulas Patocka void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
36754160904SMikulas Patocka 
3680da336e5SAlasdair G Kergon /*-----------------------------------------------------------------
3690da336e5SAlasdair G Kergon  * Macros.
3700da336e5SAlasdair G Kergon  *---------------------------------------------------------------*/
3710da336e5SAlasdair G Kergon #define DM_NAME "device-mapper"
3720da336e5SAlasdair G Kergon 
37310d3bd09SMikulas Patocka #define DMCRIT(f, arg...) \
37410d3bd09SMikulas Patocka 	printk(KERN_CRIT DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
37510d3bd09SMikulas Patocka 
3760da336e5SAlasdair G Kergon #define DMERR(f, arg...) \
3770da336e5SAlasdair G Kergon 	printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
3780da336e5SAlasdair G Kergon #define DMERR_LIMIT(f, arg...) \
3790da336e5SAlasdair G Kergon 	do { \
3800da336e5SAlasdair G Kergon 		if (printk_ratelimit())	\
3810da336e5SAlasdair G Kergon 			printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \
3820da336e5SAlasdair G Kergon 			       f "\n", ## arg); \
3830da336e5SAlasdair G Kergon 	} while (0)
3840da336e5SAlasdair G Kergon 
3850da336e5SAlasdair G Kergon #define DMWARN(f, arg...) \
3860da336e5SAlasdair G Kergon 	printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
3870da336e5SAlasdair G Kergon #define DMWARN_LIMIT(f, arg...) \
3880da336e5SAlasdair G Kergon 	do { \
3890da336e5SAlasdair G Kergon 		if (printk_ratelimit())	\
3900da336e5SAlasdair G Kergon 			printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \
3910da336e5SAlasdair G Kergon 			       f "\n", ## arg); \
3920da336e5SAlasdair G Kergon 	} while (0)
3930da336e5SAlasdair G Kergon 
3940da336e5SAlasdair G Kergon #define DMINFO(f, arg...) \
3950da336e5SAlasdair G Kergon 	printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
3960da336e5SAlasdair G Kergon #define DMINFO_LIMIT(f, arg...) \
3970da336e5SAlasdair G Kergon 	do { \
3980da336e5SAlasdair G Kergon 		if (printk_ratelimit())	\
3990da336e5SAlasdair G Kergon 			printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \
4000da336e5SAlasdair G Kergon 			       "\n", ## arg); \
4010da336e5SAlasdair G Kergon 	} while (0)
4020da336e5SAlasdair G Kergon 
4030da336e5SAlasdair G Kergon #ifdef CONFIG_DM_DEBUG
4040da336e5SAlasdair G Kergon #  define DMDEBUG(f, arg...) \
4050da336e5SAlasdair G Kergon 	printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
4060da336e5SAlasdair G Kergon #  define DMDEBUG_LIMIT(f, arg...) \
4070da336e5SAlasdair G Kergon 	do { \
4080da336e5SAlasdair G Kergon 		if (printk_ratelimit())	\
4090da336e5SAlasdair G Kergon 			printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \
4100da336e5SAlasdair G Kergon 			       "\n", ## arg); \
4110da336e5SAlasdair G Kergon 	} while (0)
4120da336e5SAlasdair G Kergon #else
4130da336e5SAlasdair G Kergon #  define DMDEBUG(f, arg...) do {} while (0)
4140da336e5SAlasdair G Kergon #  define DMDEBUG_LIMIT(f, arg...) do {} while (0)
4150da336e5SAlasdair G Kergon #endif
4160da336e5SAlasdair G Kergon 
4170da336e5SAlasdair G Kergon #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
4180da336e5SAlasdair G Kergon 			  0 : scnprintf(result + sz, maxlen - sz, x))
4190da336e5SAlasdair G Kergon 
4200da336e5SAlasdair G Kergon #define SECTOR_SHIFT 9
4210da336e5SAlasdair G Kergon 
4220da336e5SAlasdair G Kergon /*
4230da336e5SAlasdair G Kergon  * Definitions of return values from target end_io function.
4240da336e5SAlasdair G Kergon  */
4250da336e5SAlasdair G Kergon #define DM_ENDIO_INCOMPLETE	1
4260da336e5SAlasdair G Kergon #define DM_ENDIO_REQUEUE	2
4270da336e5SAlasdair G Kergon 
4280da336e5SAlasdair G Kergon /*
4290da336e5SAlasdair G Kergon  * Definitions of return values from target map function.
4300da336e5SAlasdair G Kergon  */
4310da336e5SAlasdair G Kergon #define DM_MAPIO_SUBMITTED	0
4320da336e5SAlasdair G Kergon #define DM_MAPIO_REMAPPED	1
4330da336e5SAlasdair G Kergon #define DM_MAPIO_REQUEUE	DM_ENDIO_REQUEUE
4340da336e5SAlasdair G Kergon 
4350da336e5SAlasdair G Kergon /*
4360da336e5SAlasdair G Kergon  * Ceiling(n / sz)
4370da336e5SAlasdair G Kergon  */
4380da336e5SAlasdair G Kergon #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
4390da336e5SAlasdair G Kergon 
4400da336e5SAlasdair G Kergon #define dm_sector_div_up(n, sz) ( \
4410da336e5SAlasdair G Kergon { \
4420da336e5SAlasdair G Kergon 	sector_t _r = ((n) + (sz) - 1); \
4430da336e5SAlasdair G Kergon 	sector_div(_r, (sz)); \
4440da336e5SAlasdair G Kergon 	_r; \
4450da336e5SAlasdair G Kergon } \
4460da336e5SAlasdair G Kergon )
4470da336e5SAlasdair G Kergon 
4480da336e5SAlasdair G Kergon /*
4490da336e5SAlasdair G Kergon  * ceiling(n / size) * size
4500da336e5SAlasdair G Kergon  */
4510da336e5SAlasdair G Kergon #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
4520da336e5SAlasdair G Kergon 
453d63a5ce3SMikulas Patocka #define dm_array_too_big(fixed, obj, num) \
454d63a5ce3SMikulas Patocka 	((num) > (UINT_MAX - (fixed)) / (obj))
455d63a5ce3SMikulas Patocka 
45656a67df7SMike Snitzer /*
45756a67df7SMike Snitzer  * Sector offset taken relative to the start of the target instead of
45856a67df7SMike Snitzer  * relative to the start of the device.
45956a67df7SMike Snitzer  */
46056a67df7SMike Snitzer #define dm_target_offset(ti, sector) ((sector) - (ti)->begin)
46156a67df7SMike Snitzer 
4620da336e5SAlasdair G Kergon static inline sector_t to_sector(unsigned long n)
4630da336e5SAlasdair G Kergon {
4640da336e5SAlasdair G Kergon 	return (n >> SECTOR_SHIFT);
4650da336e5SAlasdair G Kergon }
4660da336e5SAlasdair G Kergon 
4670da336e5SAlasdair G Kergon static inline unsigned long to_bytes(sector_t n)
4680da336e5SAlasdair G Kergon {
4690da336e5SAlasdair G Kergon 	return (n << SECTOR_SHIFT);
4700da336e5SAlasdair G Kergon }
4710da336e5SAlasdair G Kergon 
472cec47e3dSKiyoshi Ueda /*-----------------------------------------------------------------
473cec47e3dSKiyoshi Ueda  * Helper for block layer and dm core operations
474cec47e3dSKiyoshi Ueda  *---------------------------------------------------------------*/
475cec47e3dSKiyoshi Ueda void dm_dispatch_request(struct request *rq);
476cec47e3dSKiyoshi Ueda void dm_requeue_unmapped_request(struct request *rq);
477cec47e3dSKiyoshi Ueda void dm_kill_unmapped_request(struct request *rq, int error);
478cec47e3dSKiyoshi Ueda int dm_underlying_device_busy(struct request_queue *q);
479cec47e3dSKiyoshi Ueda 
4801da177e4SLinus Torvalds #endif	/* _LINUX_DEVICE_MAPPER_H */
481