]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/linux/device-mapper.h
dm: export struct dm_dev
[linux-2.6-omap-h63xx.git] / include / linux / device-mapper.h
1 /*
2  * Copyright (C) 2001 Sistina Software (UK) Limited.
3  * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
4  *
5  * This file is released under the LGPL.
6  */
7
8 #ifndef _LINUX_DEVICE_MAPPER_H
9 #define _LINUX_DEVICE_MAPPER_H
10
11 #include <linux/bio.h>
12 #include <linux/blkdev.h>
13
14 struct dm_target;
15 struct dm_table;
16 struct mapped_device;
17 struct bio_vec;
18
19 typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
20
21 union map_info {
22         void *ptr;
23         unsigned long long ll;
24 };
25
26 /*
27  * In the constructor the target parameter will already have the
28  * table, type, begin and len fields filled in.
29  */
30 typedef int (*dm_ctr_fn) (struct dm_target *target,
31                           unsigned int argc, char **argv);
32
33 /*
34  * The destructor doesn't need to free the dm_target, just
35  * anything hidden ti->private.
36  */
37 typedef void (*dm_dtr_fn) (struct dm_target *ti);
38
39 /*
40  * The map function must return:
41  * < 0: error
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
45  */
46 typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
47                           union map_info *map_context);
48
49 /*
50  * Returns:
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
56  */
57 typedef int (*dm_endio_fn) (struct dm_target *ti,
58                             struct bio *bio, int error,
59                             union map_info *map_context);
60
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);
66
67 typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
68                              char *result, unsigned int maxlen);
69
70 typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
71
72 typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode,
73                             struct file *filp, unsigned int cmd,
74                             unsigned long arg);
75
76 typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
77                             struct bio_vec *biovec, int max_size);
78
79 void dm_error(const char *message);
80
81 /*
82  * Combine device limits.
83  */
84 void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
85
86 struct dm_dev {
87         struct block_device *bdev;
88         int mode;
89         char name[16];
90 };
91
92 /*
93  * Constructors should call these functions to ensure destination devices
94  * are opened/closed correctly.
95  * FIXME: too many arguments.
96  */
97 int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
98                   sector_t len, int mode, struct dm_dev **result);
99 void dm_put_device(struct dm_target *ti, struct dm_dev *d);
100
101 /*
102  * Information about a target type
103  */
104 struct target_type {
105         const char *name;
106         struct module *module;
107         unsigned version[3];
108         dm_ctr_fn ctr;
109         dm_dtr_fn dtr;
110         dm_map_fn map;
111         dm_endio_fn end_io;
112         dm_flush_fn flush;
113         dm_presuspend_fn presuspend;
114         dm_postsuspend_fn postsuspend;
115         dm_preresume_fn preresume;
116         dm_resume_fn resume;
117         dm_status_fn status;
118         dm_message_fn message;
119         dm_ioctl_fn ioctl;
120         dm_merge_fn merge;
121 };
122
123 struct io_restrictions {
124         unsigned long bounce_pfn;
125         unsigned long seg_boundary_mask;
126         unsigned max_hw_sectors;
127         unsigned max_sectors;
128         unsigned max_segment_size;
129         unsigned short hardsect_size;
130         unsigned short max_hw_segments;
131         unsigned short max_phys_segments;
132         unsigned char no_cluster; /* inverted so that 0 is default */
133 };
134
135 struct dm_target {
136         struct dm_table *table;
137         struct target_type *type;
138
139         /* target limits */
140         sector_t begin;
141         sector_t len;
142
143         /* FIXME: turn this into a mask, and merge with io_restrictions */
144         /* Always a power of 2 */
145         sector_t split_io;
146
147         /*
148          * These are automatically filled in by
149          * dm_table_get_device.
150          */
151         struct io_restrictions limits;
152
153         /* target specific data */
154         void *private;
155
156         /* Used to provide an error string from the ctr */
157         char *error;
158 };
159
160 int dm_register_target(struct target_type *t);
161 int dm_unregister_target(struct target_type *t);
162
163
164 /*-----------------------------------------------------------------
165  * Functions for creating and manipulating mapped devices.
166  * Drop the reference with dm_put when you finish with the object.
167  *---------------------------------------------------------------*/
168
169 /*
170  * DM_ANY_MINOR chooses the next available minor number.
171  */
172 #define DM_ANY_MINOR (-1)
173 int dm_create(int minor, struct mapped_device **md);
174
175 /*
176  * Reference counting for md.
177  */
178 struct mapped_device *dm_get_md(dev_t dev);
179 void dm_get(struct mapped_device *md);
180 void dm_put(struct mapped_device *md);
181
182 /*
183  * An arbitrary pointer may be stored alongside a mapped device.
184  */
185 void dm_set_mdptr(struct mapped_device *md, void *ptr);
186 void *dm_get_mdptr(struct mapped_device *md);
187
188 /*
189  * A device can still be used while suspended, but I/O is deferred.
190  */
191 int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
192 int dm_resume(struct mapped_device *md);
193
194 /*
195  * Event functions.
196  */
197 uint32_t dm_get_event_nr(struct mapped_device *md);
198 int dm_wait_event(struct mapped_device *md, int event_nr);
199 uint32_t dm_next_uevent_seq(struct mapped_device *md);
200 void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
201
202 /*
203  * Info functions.
204  */
205 const char *dm_device_name(struct mapped_device *md);
206 int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
207 struct gendisk *dm_disk(struct mapped_device *md);
208 int dm_suspended(struct mapped_device *md);
209 int dm_noflush_suspending(struct dm_target *ti);
210
211 /*
212  * Geometry functions.
213  */
214 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
215 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
216
217
218 /*-----------------------------------------------------------------
219  * Functions for manipulating device-mapper tables.
220  *---------------------------------------------------------------*/
221
222 /*
223  * First create an empty table.
224  */
225 int dm_table_create(struct dm_table **result, int mode,
226                     unsigned num_targets, struct mapped_device *md);
227
228 /*
229  * Then call this once for each target.
230  */
231 int dm_table_add_target(struct dm_table *t, const char *type,
232                         sector_t start, sector_t len, char *params);
233
234 /*
235  * Finally call this to make the table ready for use.
236  */
237 int dm_table_complete(struct dm_table *t);
238
239 /*
240  * Table reference counting.
241  */
242 struct dm_table *dm_get_table(struct mapped_device *md);
243 void dm_table_get(struct dm_table *t);
244 void dm_table_put(struct dm_table *t);
245
246 /*
247  * Queries
248  */
249 sector_t dm_table_get_size(struct dm_table *t);
250 unsigned int dm_table_get_num_targets(struct dm_table *t);
251 int dm_table_get_mode(struct dm_table *t);
252 struct mapped_device *dm_table_get_md(struct dm_table *t);
253
254 /*
255  * Trigger an event.
256  */
257 void dm_table_event(struct dm_table *t);
258
259 /*
260  * The device must be suspended before calling this method.
261  */
262 int dm_swap_table(struct mapped_device *md, struct dm_table *t);
263
264 /*-----------------------------------------------------------------
265  * Macros.
266  *---------------------------------------------------------------*/
267 #define DM_NAME "device-mapper"
268
269 #define DMERR(f, arg...) \
270         printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
271 #define DMERR_LIMIT(f, arg...) \
272         do { \
273                 if (printk_ratelimit()) \
274                         printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \
275                                f "\n", ## arg); \
276         } while (0)
277
278 #define DMWARN(f, arg...) \
279         printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
280 #define DMWARN_LIMIT(f, arg...) \
281         do { \
282                 if (printk_ratelimit()) \
283                         printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \
284                                f "\n", ## arg); \
285         } while (0)
286
287 #define DMINFO(f, arg...) \
288         printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
289 #define DMINFO_LIMIT(f, arg...) \
290         do { \
291                 if (printk_ratelimit()) \
292                         printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \
293                                "\n", ## arg); \
294         } while (0)
295
296 #ifdef CONFIG_DM_DEBUG
297 #  define DMDEBUG(f, arg...) \
298         printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
299 #  define DMDEBUG_LIMIT(f, arg...) \
300         do { \
301                 if (printk_ratelimit()) \
302                         printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \
303                                "\n", ## arg); \
304         } while (0)
305 #else
306 #  define DMDEBUG(f, arg...) do {} while (0)
307 #  define DMDEBUG_LIMIT(f, arg...) do {} while (0)
308 #endif
309
310 #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
311                           0 : scnprintf(result + sz, maxlen - sz, x))
312
313 #define SECTOR_SHIFT 9
314
315 /*
316  * Definitions of return values from target end_io function.
317  */
318 #define DM_ENDIO_INCOMPLETE     1
319 #define DM_ENDIO_REQUEUE        2
320
321 /*
322  * Definitions of return values from target map function.
323  */
324 #define DM_MAPIO_SUBMITTED      0
325 #define DM_MAPIO_REMAPPED       1
326 #define DM_MAPIO_REQUEUE        DM_ENDIO_REQUEUE
327
328 /*
329  * Ceiling(n / sz)
330  */
331 #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
332
333 #define dm_sector_div_up(n, sz) ( \
334 { \
335         sector_t _r = ((n) + (sz) - 1); \
336         sector_div(_r, (sz)); \
337         _r; \
338 } \
339 )
340
341 /*
342  * ceiling(n / size) * size
343  */
344 #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
345
346 static inline sector_t to_sector(unsigned long n)
347 {
348         return (n >> SECTOR_SHIFT);
349 }
350
351 static inline unsigned long to_bytes(sector_t n)
352 {
353         return (n << SECTOR_SHIFT);
354 }
355
356 #endif  /* _LINUX_DEVICE_MAPPER_H */