]> err.no Git - linux-2.6/blob - include/linux/device-mapper.h
[PATCH] dm table: add target preresume
[linux-2.6] / include / linux / device-mapper.h
1 /*
2  * Copyright (C) 2001 Sistina Software (UK) Limited.
3  * Copyright (C) 2004 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 #ifdef __KERNEL__
12
13 struct dm_target;
14 struct dm_table;
15 struct dm_dev;
16 struct mapped_device;
17
18 typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
19
20 union map_info {
21         void *ptr;
22         unsigned long long ll;
23 };
24
25 /*
26  * In the constructor the target parameter will already have the
27  * table, type, begin and len fields filled in.
28  */
29 typedef int (*dm_ctr_fn) (struct dm_target *target,
30                           unsigned int argc, char **argv);
31
32 /*
33  * The destructor doesn't need to free the dm_target, just
34  * anything hidden ti->private.
35  */
36 typedef void (*dm_dtr_fn) (struct dm_target *ti);
37
38 /*
39  * The map function must return:
40  * < 0: error
41  * = 0: The target will handle the io by resubmitting it later
42  * > 0: simple remap complete
43  */
44 typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
45                           union map_info *map_context);
46
47 /*
48  * Returns:
49  * < 0 : error (currently ignored)
50  * 0   : ended successfully
51  * 1   : for some reason the io has still not completed (eg,
52  *       multipath target might want to requeue a failed io).
53  */
54 typedef int (*dm_endio_fn) (struct dm_target *ti,
55                             struct bio *bio, int error,
56                             union map_info *map_context);
57
58 typedef void (*dm_presuspend_fn) (struct dm_target *ti);
59 typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
60 typedef int (*dm_preresume_fn) (struct dm_target *ti);
61 typedef void (*dm_resume_fn) (struct dm_target *ti);
62
63 typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
64                              char *result, unsigned int maxlen);
65
66 typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
67
68 typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode,
69                             struct file *filp, unsigned int cmd,
70                             unsigned long arg);
71
72 void dm_error(const char *message);
73
74 /*
75  * Constructors should call these functions to ensure destination devices
76  * are opened/closed correctly.
77  * FIXME: too many arguments.
78  */
79 int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
80                   sector_t len, int mode, struct dm_dev **result);
81 void dm_put_device(struct dm_target *ti, struct dm_dev *d);
82
83 /*
84  * Information about a target type
85  */
86 struct target_type {
87         const char *name;
88         struct module *module;
89         unsigned version[3];
90         dm_ctr_fn ctr;
91         dm_dtr_fn dtr;
92         dm_map_fn map;
93         dm_endio_fn end_io;
94         dm_presuspend_fn presuspend;
95         dm_postsuspend_fn postsuspend;
96         dm_preresume_fn preresume;
97         dm_resume_fn resume;
98         dm_status_fn status;
99         dm_message_fn message;
100         dm_ioctl_fn ioctl;
101 };
102
103 struct io_restrictions {
104         unsigned int            max_sectors;
105         unsigned short          max_phys_segments;
106         unsigned short          max_hw_segments;
107         unsigned short          hardsect_size;
108         unsigned int            max_segment_size;
109         unsigned long           seg_boundary_mask;
110         unsigned char           no_cluster; /* inverted so that 0 is default */
111 };
112
113 struct dm_target {
114         struct dm_table *table;
115         struct target_type *type;
116
117         /* target limits */
118         sector_t begin;
119         sector_t len;
120
121         /* FIXME: turn this into a mask, and merge with io_restrictions */
122         /* Always a power of 2 */
123         sector_t split_io;
124
125         /*
126          * These are automatically filled in by
127          * dm_table_get_device.
128          */
129         struct io_restrictions limits;
130
131         /* target specific data */
132         void *private;
133
134         /* Used to provide an error string from the ctr */
135         char *error;
136 };
137
138 int dm_register_target(struct target_type *t);
139 int dm_unregister_target(struct target_type *t);
140
141
142 /*-----------------------------------------------------------------
143  * Functions for creating and manipulating mapped devices.
144  * Drop the reference with dm_put when you finish with the object.
145  *---------------------------------------------------------------*/
146
147 /*
148  * DM_ANY_MINOR chooses the next available minor number.
149  */
150 #define DM_ANY_MINOR (-1)
151 int dm_create(int minor, struct mapped_device **md);
152
153 /*
154  * Reference counting for md.
155  */
156 struct mapped_device *dm_get_md(dev_t dev);
157 void dm_get(struct mapped_device *md);
158 void dm_put(struct mapped_device *md);
159
160 /*
161  * An arbitrary pointer may be stored alongside a mapped device.
162  */
163 void dm_set_mdptr(struct mapped_device *md, void *ptr);
164 void *dm_get_mdptr(struct mapped_device *md);
165
166 /*
167  * A device can still be used while suspended, but I/O is deferred.
168  */
169 int dm_suspend(struct mapped_device *md, int with_lockfs);
170 int dm_resume(struct mapped_device *md);
171
172 /*
173  * Event functions.
174  */
175 uint32_t dm_get_event_nr(struct mapped_device *md);
176 int dm_wait_event(struct mapped_device *md, int event_nr);
177
178 /*
179  * Info functions.
180  */
181 const char *dm_device_name(struct mapped_device *md);
182 struct gendisk *dm_disk(struct mapped_device *md);
183 int dm_suspended(struct mapped_device *md);
184
185 /*
186  * Geometry functions.
187  */
188 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
189 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
190
191
192 /*-----------------------------------------------------------------
193  * Functions for manipulating device-mapper tables.
194  *---------------------------------------------------------------*/
195
196 /*
197  * First create an empty table.
198  */
199 int dm_table_create(struct dm_table **result, int mode,
200                     unsigned num_targets, struct mapped_device *md);
201
202 /*
203  * Then call this once for each target.
204  */
205 int dm_table_add_target(struct dm_table *t, const char *type,
206                         sector_t start, sector_t len, char *params);
207
208 /*
209  * Finally call this to make the table ready for use.
210  */
211 int dm_table_complete(struct dm_table *t);
212
213 /*
214  * Table reference counting.
215  */
216 struct dm_table *dm_get_table(struct mapped_device *md);
217 void dm_table_get(struct dm_table *t);
218 void dm_table_put(struct dm_table *t);
219
220 /*
221  * Queries
222  */
223 sector_t dm_table_get_size(struct dm_table *t);
224 unsigned int dm_table_get_num_targets(struct dm_table *t);
225 int dm_table_get_mode(struct dm_table *t);
226 struct mapped_device *dm_table_get_md(struct dm_table *t);
227
228 /*
229  * Trigger an event.
230  */
231 void dm_table_event(struct dm_table *t);
232
233 /*
234  * The device must be suspended before calling this method.
235  */
236 int dm_swap_table(struct mapped_device *md, struct dm_table *t);
237
238 /*
239  * Prepare a table for a device that will error all I/O.
240  * To make it active, call dm_suspend(), dm_swap_table() then dm_resume().
241  */
242 int dm_create_error_table(struct dm_table **result, struct mapped_device *md);
243
244 #endif  /* __KERNEL__ */
245 #endif  /* _LINUX_DEVICE_MAPPER_H */