Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
17b2f66f AK |
11 | #ifdef __KERNEL__ |
12 | ||
1da177e4 LT |
13 | struct dm_target; |
14 | struct dm_table; | |
15 | struct dm_dev; | |
17b2f66f | 16 | struct mapped_device; |
1da177e4 LT |
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 void (*dm_resume_fn) (struct dm_target *ti); | |
61 | ||
62 | typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type, | |
63 | char *result, unsigned int maxlen); | |
64 | ||
65 | typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv); | |
66 | ||
67 | void dm_error(const char *message); | |
68 | ||
69 | /* | |
70 | * Constructors should call these functions to ensure destination devices | |
71 | * are opened/closed correctly. | |
72 | * FIXME: too many arguments. | |
73 | */ | |
74 | int dm_get_device(struct dm_target *ti, const char *path, sector_t start, | |
75 | sector_t len, int mode, struct dm_dev **result); | |
76 | void dm_put_device(struct dm_target *ti, struct dm_dev *d); | |
77 | ||
78 | /* | |
79 | * Information about a target type | |
80 | */ | |
81 | struct target_type { | |
82 | const char *name; | |
83 | struct module *module; | |
17b2f66f | 84 | unsigned version[3]; |
1da177e4 LT |
85 | dm_ctr_fn ctr; |
86 | dm_dtr_fn dtr; | |
87 | dm_map_fn map; | |
88 | dm_endio_fn end_io; | |
89 | dm_presuspend_fn presuspend; | |
90 | dm_postsuspend_fn postsuspend; | |
91 | dm_resume_fn resume; | |
92 | dm_status_fn status; | |
93 | dm_message_fn message; | |
94 | }; | |
95 | ||
96 | struct io_restrictions { | |
3ee247eb | 97 | unsigned int max_sectors; |
1da177e4 LT |
98 | unsigned short max_phys_segments; |
99 | unsigned short max_hw_segments; | |
100 | unsigned short hardsect_size; | |
101 | unsigned int max_segment_size; | |
102 | unsigned long seg_boundary_mask; | |
969429b5 | 103 | unsigned char no_cluster; /* inverted so that 0 is default */ |
1da177e4 LT |
104 | }; |
105 | ||
106 | struct dm_target { | |
107 | struct dm_table *table; | |
108 | struct target_type *type; | |
109 | ||
110 | /* target limits */ | |
111 | sector_t begin; | |
112 | sector_t len; | |
113 | ||
114 | /* FIXME: turn this into a mask, and merge with io_restrictions */ | |
115 | /* Always a power of 2 */ | |
116 | sector_t split_io; | |
117 | ||
118 | /* | |
119 | * These are automatically filled in by | |
120 | * dm_table_get_device. | |
121 | */ | |
122 | struct io_restrictions limits; | |
123 | ||
124 | /* target specific data */ | |
125 | void *private; | |
126 | ||
127 | /* Used to provide an error string from the ctr */ | |
128 | char *error; | |
129 | }; | |
130 | ||
131 | int dm_register_target(struct target_type *t); | |
132 | int dm_unregister_target(struct target_type *t); | |
133 | ||
17b2f66f AK |
134 | |
135 | /*----------------------------------------------------------------- | |
136 | * Functions for creating and manipulating mapped devices. | |
137 | * Drop the reference with dm_put when you finish with the object. | |
138 | *---------------------------------------------------------------*/ | |
139 | ||
140 | /* | |
141 | * DM_ANY_MINOR chooses the next available minor number. | |
142 | */ | |
143 | #define DM_ANY_MINOR (-1) | |
144 | int dm_create(int minor, struct mapped_device **md); | |
145 | ||
146 | /* | |
147 | * Reference counting for md. | |
148 | */ | |
149 | struct mapped_device *dm_get_md(dev_t dev); | |
150 | void dm_get(struct mapped_device *md); | |
151 | void dm_put(struct mapped_device *md); | |
152 | ||
153 | /* | |
154 | * An arbitrary pointer may be stored alongside a mapped device. | |
155 | */ | |
156 | void dm_set_mdptr(struct mapped_device *md, void *ptr); | |
157 | void *dm_get_mdptr(struct mapped_device *md); | |
158 | ||
159 | /* | |
160 | * A device can still be used while suspended, but I/O is deferred. | |
161 | */ | |
162 | int dm_suspend(struct mapped_device *md, int with_lockfs); | |
163 | int dm_resume(struct mapped_device *md); | |
164 | ||
165 | /* | |
166 | * Event functions. | |
167 | */ | |
168 | uint32_t dm_get_event_nr(struct mapped_device *md); | |
169 | int dm_wait_event(struct mapped_device *md, int event_nr); | |
170 | ||
171 | /* | |
172 | * Info functions. | |
173 | */ | |
174 | struct gendisk *dm_disk(struct mapped_device *md); | |
175 | int dm_suspended(struct mapped_device *md); | |
176 | ||
177 | /* | |
178 | * Geometry functions. | |
179 | */ | |
180 | int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo); | |
181 | int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo); | |
182 | ||
183 | ||
184 | /*----------------------------------------------------------------- | |
185 | * Functions for manipulating device-mapper tables. | |
186 | *---------------------------------------------------------------*/ | |
187 | ||
188 | /* | |
189 | * First create an empty table. | |
190 | */ | |
191 | int dm_table_create(struct dm_table **result, int mode, | |
192 | unsigned num_targets, struct mapped_device *md); | |
193 | ||
194 | /* | |
195 | * Then call this once for each target. | |
196 | */ | |
197 | int dm_table_add_target(struct dm_table *t, const char *type, | |
198 | sector_t start, sector_t len, char *params); | |
199 | ||
200 | /* | |
201 | * Finally call this to make the table ready for use. | |
202 | */ | |
203 | int dm_table_complete(struct dm_table *t); | |
204 | ||
205 | /* | |
206 | * Table reference counting. | |
207 | */ | |
208 | struct dm_table *dm_get_table(struct mapped_device *md); | |
209 | void dm_table_get(struct dm_table *t); | |
210 | void dm_table_put(struct dm_table *t); | |
211 | ||
212 | /* | |
213 | * Queries | |
214 | */ | |
215 | sector_t dm_table_get_size(struct dm_table *t); | |
216 | unsigned int dm_table_get_num_targets(struct dm_table *t); | |
217 | int dm_table_get_mode(struct dm_table *t); | |
218 | struct mapped_device *dm_table_get_md(struct dm_table *t); | |
219 | ||
220 | /* | |
221 | * Trigger an event. | |
222 | */ | |
223 | void dm_table_event(struct dm_table *t); | |
224 | ||
225 | /* | |
226 | * The device must be suspended before calling this method. | |
227 | */ | |
228 | int dm_swap_table(struct mapped_device *md, struct dm_table *t); | |
229 | ||
c2ade42d DT |
230 | /* |
231 | * Prepare a table for a device that will error all I/O. | |
232 | * To make it active, call dm_suspend(), dm_swap_table() then dm_resume(). | |
233 | */ | |
234 | int dm_create_error_table(struct dm_table **result, struct mapped_device *md); | |
235 | ||
17b2f66f AK |
236 | #endif /* __KERNEL__ */ |
237 | #endif /* _LINUX_DEVICE_MAPPER_H */ |