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
13 #include <linux/bio.h>
20 typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
24 unsigned long long ll;
28 * In the constructor the target parameter will already have the
29 * table, type, begin and len fields filled in.
31 typedef int (*dm_ctr_fn) (struct dm_target *target,
32 unsigned int argc, char **argv);
35 * The destructor doesn't need to free the dm_target, just
36 * anything hidden ti->private.
38 typedef void (*dm_dtr_fn) (struct dm_target *ti);
41 * The map function must return:
43 * = 0: The target will handle the io by resubmitting it later
44 * = 1: simple remap complete
45 * = 2: The target wants to push back the io
47 typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
48 union map_info *map_context);
52 * < 0 : error (currently ignored)
53 * 0 : ended successfully
54 * 1 : for some reason the io has still not completed (eg,
55 * multipath target might want to requeue a failed io).
56 * 2 : The target wants to push back the io
58 typedef int (*dm_endio_fn) (struct dm_target *ti,
59 struct bio *bio, int error,
60 union map_info *map_context);
62 typedef void (*dm_flush_fn) (struct dm_target *ti);
63 typedef void (*dm_presuspend_fn) (struct dm_target *ti);
64 typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
65 typedef int (*dm_preresume_fn) (struct dm_target *ti);
66 typedef void (*dm_resume_fn) (struct dm_target *ti);
68 typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
69 char *result, unsigned int maxlen);
71 typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
73 typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode,
74 struct file *filp, unsigned int cmd,
77 void dm_error(const char *message);
80 * Combine device limits.
82 void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
85 * Constructors should call these functions to ensure destination devices
86 * are opened/closed correctly.
87 * FIXME: too many arguments.
89 int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
90 sector_t len, int mode, struct dm_dev **result);
91 void dm_put_device(struct dm_target *ti, struct dm_dev *d);
94 * Information about a target type
98 struct module *module;
105 dm_presuspend_fn presuspend;
106 dm_postsuspend_fn postsuspend;
107 dm_preresume_fn preresume;
110 dm_message_fn message;
114 struct io_restrictions {
115 unsigned long bounce_pfn;
116 unsigned long seg_boundary_mask;
117 unsigned max_hw_sectors;
118 unsigned max_sectors;
119 unsigned max_segment_size;
120 unsigned short hardsect_size;
121 unsigned short max_hw_segments;
122 unsigned short max_phys_segments;
123 unsigned char no_cluster; /* inverted so that 0 is default */
127 struct dm_table *table;
128 struct target_type *type;
134 /* FIXME: turn this into a mask, and merge with io_restrictions */
135 /* Always a power of 2 */
139 * These are automatically filled in by
140 * dm_table_get_device.
142 struct io_restrictions limits;
144 /* target specific data */
147 /* Used to provide an error string from the ctr */
151 int dm_register_target(struct target_type *t);
152 int dm_unregister_target(struct target_type *t);
155 /*-----------------------------------------------------------------
156 * Functions for creating and manipulating mapped devices.
157 * Drop the reference with dm_put when you finish with the object.
158 *---------------------------------------------------------------*/
161 * DM_ANY_MINOR chooses the next available minor number.
163 #define DM_ANY_MINOR (-1)
164 int dm_create(int minor, struct mapped_device **md);
167 * Reference counting for md.
169 struct mapped_device *dm_get_md(dev_t dev);
170 void dm_get(struct mapped_device *md);
171 void dm_put(struct mapped_device *md);
174 * An arbitrary pointer may be stored alongside a mapped device.
176 void dm_set_mdptr(struct mapped_device *md, void *ptr);
177 void *dm_get_mdptr(struct mapped_device *md);
180 * A device can still be used while suspended, but I/O is deferred.
182 int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
183 int dm_resume(struct mapped_device *md);
188 uint32_t dm_get_event_nr(struct mapped_device *md);
189 int dm_wait_event(struct mapped_device *md, int event_nr);
190 uint32_t dm_next_uevent_seq(struct mapped_device *md);
191 void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
196 const char *dm_device_name(struct mapped_device *md);
197 int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
198 struct gendisk *dm_disk(struct mapped_device *md);
199 int dm_suspended(struct mapped_device *md);
200 int dm_noflush_suspending(struct dm_target *ti);
203 * Geometry functions.
205 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
206 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
209 /*-----------------------------------------------------------------
210 * Functions for manipulating device-mapper tables.
211 *---------------------------------------------------------------*/
214 * First create an empty table.
216 int dm_table_create(struct dm_table **result, int mode,
217 unsigned num_targets, struct mapped_device *md);
220 * Then call this once for each target.
222 int dm_table_add_target(struct dm_table *t, const char *type,
223 sector_t start, sector_t len, char *params);
226 * Finally call this to make the table ready for use.
228 int dm_table_complete(struct dm_table *t);
231 * Table reference counting.
233 struct dm_table *dm_get_table(struct mapped_device *md);
234 void dm_table_get(struct dm_table *t);
235 void dm_table_put(struct dm_table *t);
240 sector_t dm_table_get_size(struct dm_table *t);
241 unsigned int dm_table_get_num_targets(struct dm_table *t);
242 int dm_table_get_mode(struct dm_table *t);
243 struct mapped_device *dm_table_get_md(struct dm_table *t);
248 void dm_table_event(struct dm_table *t);
251 * The device must be suspended before calling this method.
253 int dm_swap_table(struct mapped_device *md, struct dm_table *t);
255 /*-----------------------------------------------------------------
257 *---------------------------------------------------------------*/
258 #define DM_NAME "device-mapper"
260 #define DMERR(f, arg...) \
261 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
262 #define DMERR_LIMIT(f, arg...) \
264 if (printk_ratelimit()) \
265 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \
269 #define DMWARN(f, arg...) \
270 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
271 #define DMWARN_LIMIT(f, arg...) \
273 if (printk_ratelimit()) \
274 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \
278 #define DMINFO(f, arg...) \
279 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
280 #define DMINFO_LIMIT(f, arg...) \
282 if (printk_ratelimit()) \
283 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \
287 #ifdef CONFIG_DM_DEBUG
288 # define DMDEBUG(f, arg...) \
289 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
290 # define DMDEBUG_LIMIT(f, arg...) \
292 if (printk_ratelimit()) \
293 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \
297 # define DMDEBUG(f, arg...) do {} while (0)
298 # define DMDEBUG_LIMIT(f, arg...) do {} while (0)
301 #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
302 0 : scnprintf(result + sz, maxlen - sz, x))
304 #define SECTOR_SHIFT 9
307 * Definitions of return values from target end_io function.
309 #define DM_ENDIO_INCOMPLETE 1
310 #define DM_ENDIO_REQUEUE 2
313 * Definitions of return values from target map function.
315 #define DM_MAPIO_SUBMITTED 0
316 #define DM_MAPIO_REMAPPED 1
317 #define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE
322 #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
324 #define dm_sector_div_up(n, sz) ( \
326 sector_t _r = ((n) + (sz) - 1); \
327 sector_div(_r, (sz)); \
333 * ceiling(n / size) * size
335 #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
337 static inline sector_t to_sector(unsigned long n)
339 return (n >> SECTOR_SHIFT);
342 static inline unsigned long to_bytes(sector_t n)
344 return (n << SECTOR_SHIFT);
347 #endif /* __KERNEL__ */
348 #endif /* _LINUX_DEVICE_MAPPER_H */