coredump: move mm->core_waiters into struct core_state
[linux-2.6/mini2440.git] / include / linux / device-mapper.h
bloba90222e3297d807e554ca270b50f097a3a5dfbc7
1 /*
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.
6 */
8 #ifndef _LINUX_DEVICE_MAPPER_H
9 #define _LINUX_DEVICE_MAPPER_H
11 #include <linux/bio.h>
12 #include <linux/blkdev.h>
14 struct dm_target;
15 struct dm_table;
16 struct dm_dev;
17 struct mapped_device;
18 struct bio_vec;
20 typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
22 union map_info {
23 void *ptr;
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:
42 * < 0: error
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);
51 * Returns:
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,
75 unsigned long arg);
77 typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
78 struct bio_vec *biovec, int max_size);
80 void dm_error(const char *message);
83 * Combine device limits.
85 void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
88 * Constructors should call these functions to ensure destination devices
89 * are opened/closed correctly.
90 * FIXME: too many arguments.
92 int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
93 sector_t len, int mode, struct dm_dev **result);
94 void dm_put_device(struct dm_target *ti, struct dm_dev *d);
97 * Information about a target type
99 struct target_type {
100 const char *name;
101 struct module *module;
102 unsigned version[3];
103 dm_ctr_fn ctr;
104 dm_dtr_fn dtr;
105 dm_map_fn map;
106 dm_endio_fn end_io;
107 dm_flush_fn flush;
108 dm_presuspend_fn presuspend;
109 dm_postsuspend_fn postsuspend;
110 dm_preresume_fn preresume;
111 dm_resume_fn resume;
112 dm_status_fn status;
113 dm_message_fn message;
114 dm_ioctl_fn ioctl;
115 dm_merge_fn merge;
118 struct io_restrictions {
119 unsigned long bounce_pfn;
120 unsigned long seg_boundary_mask;
121 unsigned max_hw_sectors;
122 unsigned max_sectors;
123 unsigned max_segment_size;
124 unsigned short hardsect_size;
125 unsigned short max_hw_segments;
126 unsigned short max_phys_segments;
127 unsigned char no_cluster; /* inverted so that 0 is default */
130 struct dm_target {
131 struct dm_table *table;
132 struct target_type *type;
134 /* target limits */
135 sector_t begin;
136 sector_t len;
138 /* FIXME: turn this into a mask, and merge with io_restrictions */
139 /* Always a power of 2 */
140 sector_t split_io;
143 * These are automatically filled in by
144 * dm_table_get_device.
146 struct io_restrictions limits;
148 /* target specific data */
149 void *private;
151 /* Used to provide an error string from the ctr */
152 char *error;
155 int dm_register_target(struct target_type *t);
156 int dm_unregister_target(struct target_type *t);
159 /*-----------------------------------------------------------------
160 * Functions for creating and manipulating mapped devices.
161 * Drop the reference with dm_put when you finish with the object.
162 *---------------------------------------------------------------*/
165 * DM_ANY_MINOR chooses the next available minor number.
167 #define DM_ANY_MINOR (-1)
168 int dm_create(int minor, struct mapped_device **md);
171 * Reference counting for md.
173 struct mapped_device *dm_get_md(dev_t dev);
174 void dm_get(struct mapped_device *md);
175 void dm_put(struct mapped_device *md);
178 * An arbitrary pointer may be stored alongside a mapped device.
180 void dm_set_mdptr(struct mapped_device *md, void *ptr);
181 void *dm_get_mdptr(struct mapped_device *md);
184 * A device can still be used while suspended, but I/O is deferred.
186 int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
187 int dm_resume(struct mapped_device *md);
190 * Event functions.
192 uint32_t dm_get_event_nr(struct mapped_device *md);
193 int dm_wait_event(struct mapped_device *md, int event_nr);
194 uint32_t dm_next_uevent_seq(struct mapped_device *md);
195 void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
198 * Info functions.
200 const char *dm_device_name(struct mapped_device *md);
201 int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
202 struct gendisk *dm_disk(struct mapped_device *md);
203 int dm_suspended(struct mapped_device *md);
204 int dm_noflush_suspending(struct dm_target *ti);
207 * Geometry functions.
209 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
210 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
213 /*-----------------------------------------------------------------
214 * Functions for manipulating device-mapper tables.
215 *---------------------------------------------------------------*/
218 * First create an empty table.
220 int dm_table_create(struct dm_table **result, int mode,
221 unsigned num_targets, struct mapped_device *md);
224 * Then call this once for each target.
226 int dm_table_add_target(struct dm_table *t, const char *type,
227 sector_t start, sector_t len, char *params);
230 * Finally call this to make the table ready for use.
232 int dm_table_complete(struct dm_table *t);
235 * Table reference counting.
237 struct dm_table *dm_get_table(struct mapped_device *md);
238 void dm_table_get(struct dm_table *t);
239 void dm_table_put(struct dm_table *t);
242 * Queries
244 sector_t dm_table_get_size(struct dm_table *t);
245 unsigned int dm_table_get_num_targets(struct dm_table *t);
246 int dm_table_get_mode(struct dm_table *t);
247 struct mapped_device *dm_table_get_md(struct dm_table *t);
250 * Trigger an event.
252 void dm_table_event(struct dm_table *t);
255 * The device must be suspended before calling this method.
257 int dm_swap_table(struct mapped_device *md, struct dm_table *t);
259 /*-----------------------------------------------------------------
260 * Macros.
261 *---------------------------------------------------------------*/
262 #define DM_NAME "device-mapper"
264 #define DMERR(f, arg...) \
265 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
266 #define DMERR_LIMIT(f, arg...) \
267 do { \
268 if (printk_ratelimit()) \
269 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \
270 f "\n", ## arg); \
271 } while (0)
273 #define DMWARN(f, arg...) \
274 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
275 #define DMWARN_LIMIT(f, arg...) \
276 do { \
277 if (printk_ratelimit()) \
278 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \
279 f "\n", ## arg); \
280 } while (0)
282 #define DMINFO(f, arg...) \
283 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
284 #define DMINFO_LIMIT(f, arg...) \
285 do { \
286 if (printk_ratelimit()) \
287 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \
288 "\n", ## arg); \
289 } while (0)
291 #ifdef CONFIG_DM_DEBUG
292 # define DMDEBUG(f, arg...) \
293 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
294 # define DMDEBUG_LIMIT(f, arg...) \
295 do { \
296 if (printk_ratelimit()) \
297 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \
298 "\n", ## arg); \
299 } while (0)
300 #else
301 # define DMDEBUG(f, arg...) do {} while (0)
302 # define DMDEBUG_LIMIT(f, arg...) do {} while (0)
303 #endif
305 #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
306 0 : scnprintf(result + sz, maxlen - sz, x))
308 #define SECTOR_SHIFT 9
311 * Definitions of return values from target end_io function.
313 #define DM_ENDIO_INCOMPLETE 1
314 #define DM_ENDIO_REQUEUE 2
317 * Definitions of return values from target map function.
319 #define DM_MAPIO_SUBMITTED 0
320 #define DM_MAPIO_REMAPPED 1
321 #define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE
324 * Ceiling(n / sz)
326 #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
328 #define dm_sector_div_up(n, sz) ( \
330 sector_t _r = ((n) + (sz) - 1); \
331 sector_div(_r, (sz)); \
332 _r; \
337 * ceiling(n / size) * size
339 #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
341 static inline sector_t to_sector(unsigned long n)
343 return (n >> SECTOR_SHIFT);
346 static inline unsigned long to_bytes(sector_t n)
348 return (n << SECTOR_SHIFT);
351 #endif /* _LINUX_DEVICE_MAPPER_H */