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);
51 * < 0 : error (currently ignored)
52 * 0 : ended successfully
53 * 1 : for some reason the io has still not completed (eg,
54 * multipath target might want to requeue a failed io).
55 * 2 : The target wants to push back the io
57 typedef int (*dm_endio_fn) (struct dm_target *ti,
58 struct bio *bio, int error,
59 union map_info *map_context);
61 typedef void (*dm_flush_fn) (struct dm_target *ti);
62 typedef void (*dm_presuspend_fn) (struct dm_target *ti);
63 typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
64 typedef int (*dm_preresume_fn) (struct dm_target *ti);
65 typedef void (*dm_resume_fn) (struct dm_target *ti);
67 typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
68 char *result, unsigned int maxlen);
70 typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
72 typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd,
75 typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
76 struct bio_vec *biovec, int max_size);
78 void dm_error(const char *message);
81 * Combine device limits.
83 void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
86 struct block_device *bdev;
92 * Constructors should call these functions to ensure destination devices
93 * are opened/closed correctly.
94 * FIXME: too many arguments.
96 int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
97 sector_t len, fmode_t mode, struct dm_dev **result);
98 void dm_put_device(struct dm_target *ti, struct dm_dev *d);
101 * Information about a target type
105 struct module *module;
112 dm_presuspend_fn presuspend;
113 dm_postsuspend_fn postsuspend;
114 dm_preresume_fn preresume;
117 dm_message_fn message;
122 struct io_restrictions {
123 unsigned long bounce_pfn;
124 unsigned long seg_boundary_mask;
125 unsigned max_hw_sectors;
126 unsigned max_sectors;
127 unsigned max_segment_size;
128 unsigned short hardsect_size;
129 unsigned short max_hw_segments;
130 unsigned short max_phys_segments;
131 unsigned char no_cluster; /* inverted so that 0 is default */
135 struct dm_table *table;
136 struct target_type *type;
142 /* FIXME: turn this into a mask, and merge with io_restrictions */
143 /* Always a power of 2 */
147 * These are automatically filled in by
148 * dm_table_get_device.
150 struct io_restrictions limits;
152 /* target specific data */
155 /* Used to provide an error string from the ctr */
159 int dm_register_target(struct target_type *t);
160 void dm_unregister_target(struct target_type *t);
162 /*-----------------------------------------------------------------
163 * Functions for creating and manipulating mapped devices.
164 * Drop the reference with dm_put when you finish with the object.
165 *---------------------------------------------------------------*/
168 * DM_ANY_MINOR chooses the next available minor number.
170 #define DM_ANY_MINOR (-1)
171 int dm_create(int minor, struct mapped_device **md);
174 * Reference counting for md.
176 struct mapped_device *dm_get_md(dev_t dev);
177 void dm_get(struct mapped_device *md);
178 void dm_put(struct mapped_device *md);
181 * An arbitrary pointer may be stored alongside a mapped device.
183 void dm_set_mdptr(struct mapped_device *md, void *ptr);
184 void *dm_get_mdptr(struct mapped_device *md);
187 * A device can still be used while suspended, but I/O is deferred.
189 int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
190 int dm_resume(struct mapped_device *md);
195 uint32_t dm_get_event_nr(struct mapped_device *md);
196 int dm_wait_event(struct mapped_device *md, int event_nr);
197 uint32_t dm_next_uevent_seq(struct mapped_device *md);
198 void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
203 const char *dm_device_name(struct mapped_device *md);
204 int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
205 struct gendisk *dm_disk(struct mapped_device *md);
206 int dm_suspended(struct mapped_device *md);
207 int dm_noflush_suspending(struct dm_target *ti);
208 union map_info *dm_get_mapinfo(struct bio *bio);
211 * Geometry functions.
213 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
214 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
217 /*-----------------------------------------------------------------
218 * Functions for manipulating device-mapper tables.
219 *---------------------------------------------------------------*/
222 * First create an empty table.
224 int dm_table_create(struct dm_table **result, fmode_t mode,
225 unsigned num_targets, struct mapped_device *md);
228 * Then call this once for each target.
230 int dm_table_add_target(struct dm_table *t, const char *type,
231 sector_t start, sector_t len, char *params);
234 * Finally call this to make the table ready for use.
236 int dm_table_complete(struct dm_table *t);
239 * Unplug all devices in a table.
241 void dm_table_unplug_all(struct dm_table *t);
244 * Table reference counting.
246 struct dm_table *dm_get_table(struct mapped_device *md);
247 void dm_table_get(struct dm_table *t);
248 void dm_table_put(struct dm_table *t);
253 sector_t dm_table_get_size(struct dm_table *t);
254 unsigned int dm_table_get_num_targets(struct dm_table *t);
255 fmode_t dm_table_get_mode(struct dm_table *t);
256 struct mapped_device *dm_table_get_md(struct dm_table *t);
261 void dm_table_event(struct dm_table *t);
264 * The device must be suspended before calling this method.
266 int dm_swap_table(struct mapped_device *md, struct dm_table *t);
269 * A wrapper around vmalloc.
271 void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
273 /*-----------------------------------------------------------------
275 *---------------------------------------------------------------*/
276 #define DM_NAME "device-mapper"
278 #define DMCRIT(f, arg...) \
279 printk(KERN_CRIT DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
281 #define DMERR(f, arg...) \
282 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
283 #define DMERR_LIMIT(f, arg...) \
285 if (printk_ratelimit()) \
286 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \
290 #define DMWARN(f, arg...) \
291 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
292 #define DMWARN_LIMIT(f, arg...) \
294 if (printk_ratelimit()) \
295 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \
299 #define DMINFO(f, arg...) \
300 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
301 #define DMINFO_LIMIT(f, arg...) \
303 if (printk_ratelimit()) \
304 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \
308 #ifdef CONFIG_DM_DEBUG
309 # define DMDEBUG(f, arg...) \
310 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
311 # define DMDEBUG_LIMIT(f, arg...) \
313 if (printk_ratelimit()) \
314 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \
318 # define DMDEBUG(f, arg...) do {} while (0)
319 # define DMDEBUG_LIMIT(f, arg...) do {} while (0)
322 #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
323 0 : scnprintf(result + sz, maxlen - sz, x))
325 #define SECTOR_SHIFT 9
328 * Definitions of return values from target end_io function.
330 #define DM_ENDIO_INCOMPLETE 1
331 #define DM_ENDIO_REQUEUE 2
334 * Definitions of return values from target map function.
336 #define DM_MAPIO_SUBMITTED 0
337 #define DM_MAPIO_REMAPPED 1
338 #define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE
343 #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
345 #define dm_sector_div_up(n, sz) ( \
347 sector_t _r = ((n) + (sz) - 1); \
348 sector_div(_r, (sz)); \
354 * ceiling(n / size) * size
356 #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
358 #define dm_array_too_big(fixed, obj, num) \
359 ((num) > (UINT_MAX - (fixed)) / (obj))
361 static inline sector_t to_sector(unsigned long n)
363 return (n >> SECTOR_SHIFT);
366 static inline unsigned long to_bytes(sector_t n)
368 return (n << SECTOR_SHIFT);
371 #endif /* _LINUX_DEVICE_MAPPER_H */