2 * Copyright (C) 2001 Sistina Software (UK) Limited.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
5 * This file is released under the LGPL.
8 #ifndef _LINUX_DEVICE_MAPPER_H
9 #define _LINUX_DEVICE_MAPPER_H
11 #include <linux/bio.h>
12 #include <linux/blkdev.h>
19 typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
23 unsigned long long ll;
27 * In the constructor the target parameter will already have the
28 * table, type, begin and len fields filled in.
30 typedef int (*dm_ctr_fn) (struct dm_target *target,
31 unsigned int argc, char **argv);
34 * The destructor doesn't need to free the dm_target, just
35 * anything hidden ti->private.
37 typedef void (*dm_dtr_fn) (struct dm_target *ti);
40 * The map function must return:
42 * = 0: The target will handle the io by resubmitting it later
43 * = 1: simple remap complete
44 * = 2: The target wants to push back the io
46 typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
47 union map_info *map_context);
48 typedef int (*dm_map_request_fn) (struct dm_target *ti, struct request *clone,
49 union map_info *map_context);
53 * < 0 : error (currently ignored)
54 * 0 : ended successfully
55 * 1 : for some reason the io has still not completed (eg,
56 * multipath target might want to requeue a failed io).
57 * 2 : The target wants to push back the io
59 typedef int (*dm_endio_fn) (struct dm_target *ti,
60 struct bio *bio, int error,
61 union map_info *map_context);
62 typedef int (*dm_request_endio_fn) (struct dm_target *ti,
63 struct request *clone, int error,
64 union map_info *map_context);
66 typedef void (*dm_flush_fn) (struct dm_target *ti);
67 typedef void (*dm_presuspend_fn) (struct dm_target *ti);
68 typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
69 typedef int (*dm_preresume_fn) (struct dm_target *ti);
70 typedef void (*dm_resume_fn) (struct dm_target *ti);
72 typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
73 char *result, unsigned int maxlen);
75 typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
77 typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd,
80 typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
81 struct bio_vec *biovec, int max_size);
85 * 0: The target can handle the next I/O immediately.
86 * 1: The target can't handle the next I/O immediately.
88 typedef int (*dm_busy_fn) (struct dm_target *ti);
90 void dm_error(const char *message);
93 * Combine device limits.
95 void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
98 struct block_device *bdev;
104 * Constructors should call these functions to ensure destination devices
105 * are opened/closed correctly.
106 * FIXME: too many arguments.
108 int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
109 sector_t len, fmode_t mode, struct dm_dev **result);
110 void dm_put_device(struct dm_target *ti, struct dm_dev *d);
113 * Information about a target type
119 #define DM_TARGET_SUPPORTS_BARRIERS 0x00000001
124 struct module *module;
129 dm_map_request_fn map_rq;
131 dm_request_endio_fn rq_end_io;
133 dm_presuspend_fn presuspend;
134 dm_postsuspend_fn postsuspend;
135 dm_preresume_fn preresume;
138 dm_message_fn message;
143 /* For internal device-mapper use. */
144 struct list_head list;
147 struct io_restrictions {
148 unsigned long bounce_pfn;
149 unsigned long seg_boundary_mask;
150 unsigned max_hw_sectors;
151 unsigned max_sectors;
152 unsigned max_segment_size;
153 unsigned short hardsect_size;
154 unsigned short max_hw_segments;
155 unsigned short max_phys_segments;
156 unsigned char no_cluster; /* inverted so that 0 is default */
160 struct dm_table *table;
161 struct target_type *type;
167 /* FIXME: turn this into a mask, and merge with io_restrictions */
168 /* Always a power of 2 */
172 * These are automatically filled in by
173 * dm_table_get_device.
175 struct io_restrictions limits;
177 /* target specific data */
180 /* Used to provide an error string from the ctr */
184 int dm_register_target(struct target_type *t);
185 void dm_unregister_target(struct target_type *t);
187 /*-----------------------------------------------------------------
188 * Functions for creating and manipulating mapped devices.
189 * Drop the reference with dm_put when you finish with the object.
190 *---------------------------------------------------------------*/
193 * DM_ANY_MINOR chooses the next available minor number.
195 #define DM_ANY_MINOR (-1)
196 int dm_create(int minor, struct mapped_device **md);
199 * Reference counting for md.
201 struct mapped_device *dm_get_md(dev_t dev);
202 void dm_get(struct mapped_device *md);
203 void dm_put(struct mapped_device *md);
206 * An arbitrary pointer may be stored alongside a mapped device.
208 void dm_set_mdptr(struct mapped_device *md, void *ptr);
209 void *dm_get_mdptr(struct mapped_device *md);
212 * A device can still be used while suspended, but I/O is deferred.
214 int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
215 int dm_resume(struct mapped_device *md);
220 uint32_t dm_get_event_nr(struct mapped_device *md);
221 int dm_wait_event(struct mapped_device *md, int event_nr);
222 uint32_t dm_next_uevent_seq(struct mapped_device *md);
223 void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
228 const char *dm_device_name(struct mapped_device *md);
229 int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
230 struct gendisk *dm_disk(struct mapped_device *md);
231 int dm_suspended(struct mapped_device *md);
232 int dm_noflush_suspending(struct dm_target *ti);
233 union map_info *dm_get_mapinfo(struct bio *bio);
236 * Geometry functions.
238 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
239 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
242 /*-----------------------------------------------------------------
243 * Functions for manipulating device-mapper tables.
244 *---------------------------------------------------------------*/
247 * First create an empty table.
249 int dm_table_create(struct dm_table **result, fmode_t mode,
250 unsigned num_targets, struct mapped_device *md);
253 * Then call this once for each target.
255 int dm_table_add_target(struct dm_table *t, const char *type,
256 sector_t start, sector_t len, char *params);
259 * Finally call this to make the table ready for use.
261 int dm_table_complete(struct dm_table *t);
264 * Unplug all devices in a table.
266 void dm_table_unplug_all(struct dm_table *t);
269 * Table reference counting.
271 struct dm_table *dm_get_table(struct mapped_device *md);
272 void dm_table_get(struct dm_table *t);
273 void dm_table_put(struct dm_table *t);
278 sector_t dm_table_get_size(struct dm_table *t);
279 unsigned int dm_table_get_num_targets(struct dm_table *t);
280 fmode_t dm_table_get_mode(struct dm_table *t);
281 struct mapped_device *dm_table_get_md(struct dm_table *t);
286 void dm_table_event(struct dm_table *t);
289 * The device must be suspended before calling this method.
291 int dm_swap_table(struct mapped_device *md, struct dm_table *t);
294 * A wrapper around vmalloc.
296 void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
298 /*-----------------------------------------------------------------
300 *---------------------------------------------------------------*/
301 #define DM_NAME "device-mapper"
303 #define DMCRIT(f, arg...) \
304 printk(KERN_CRIT DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
306 #define DMERR(f, arg...) \
307 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
308 #define DMERR_LIMIT(f, arg...) \
310 if (printk_ratelimit()) \
311 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \
315 #define DMWARN(f, arg...) \
316 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
317 #define DMWARN_LIMIT(f, arg...) \
319 if (printk_ratelimit()) \
320 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \
324 #define DMINFO(f, arg...) \
325 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
326 #define DMINFO_LIMIT(f, arg...) \
328 if (printk_ratelimit()) \
329 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \
333 #ifdef CONFIG_DM_DEBUG
334 # define DMDEBUG(f, arg...) \
335 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
336 # define DMDEBUG_LIMIT(f, arg...) \
338 if (printk_ratelimit()) \
339 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \
343 # define DMDEBUG(f, arg...) do {} while (0)
344 # define DMDEBUG_LIMIT(f, arg...) do {} while (0)
347 #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
348 0 : scnprintf(result + sz, maxlen - sz, x))
350 #define SECTOR_SHIFT 9
353 * Definitions of return values from target end_io function.
355 #define DM_ENDIO_INCOMPLETE 1
356 #define DM_ENDIO_REQUEUE 2
359 * Definitions of return values from target map function.
361 #define DM_MAPIO_SUBMITTED 0
362 #define DM_MAPIO_REMAPPED 1
363 #define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE
368 #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
370 #define dm_sector_div_up(n, sz) ( \
372 sector_t _r = ((n) + (sz) - 1); \
373 sector_div(_r, (sz)); \
379 * ceiling(n / size) * size
381 #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
383 #define dm_array_too_big(fixed, obj, num) \
384 ((num) > (UINT_MAX - (fixed)) / (obj))
386 static inline sector_t to_sector(unsigned long n)
388 return (n >> SECTOR_SHIFT);
391 static inline unsigned long to_bytes(sector_t n)
393 return (n << SECTOR_SHIFT);
396 #endif /* _LINUX_DEVICE_MAPPER_H */