blob: 03ef41c1eaac346b441a00a54048818b7f35c60f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Alasdair G Kergon17b2f662006-06-26 00:27:33 -070011#ifdef __KERNEL__
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013struct dm_target;
14struct dm_table;
15struct dm_dev;
Alasdair G Kergon17b2f662006-06-26 00:27:33 -070016struct mapped_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
19
20union 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 */
29typedef 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 */
36typedef 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 */
44typedef 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 */
54typedef int (*dm_endio_fn) (struct dm_target *ti,
55 struct bio *bio, int error,
56 union map_info *map_context);
57
Bryn Reeves999d8162006-10-03 01:15:43 -070058typedef void (*dm_flush_fn) (struct dm_target *ti);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059typedef void (*dm_presuspend_fn) (struct dm_target *ti);
60typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
Milan Broz8757b772006-10-03 01:15:36 -070061typedef int (*dm_preresume_fn) (struct dm_target *ti);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062typedef void (*dm_resume_fn) (struct dm_target *ti);
63
64typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
65 char *result, unsigned int maxlen);
66
67typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
68
Milan Brozaa129a22006-10-03 01:15:15 -070069typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode,
70 struct file *filp, unsigned int cmd,
71 unsigned long arg);
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073void dm_error(const char *message);
74
75/*
Bryn Reeves3cb40212006-10-03 01:15:42 -070076 * Combine device limits.
77 */
78void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
79
80/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 * Constructors should call these functions to ensure destination devices
82 * are opened/closed correctly.
83 * FIXME: too many arguments.
84 */
85int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
86 sector_t len, int mode, struct dm_dev **result);
87void dm_put_device(struct dm_target *ti, struct dm_dev *d);
88
89/*
90 * Information about a target type
91 */
92struct target_type {
93 const char *name;
94 struct module *module;
Alasdair G Kergon17b2f662006-06-26 00:27:33 -070095 unsigned version[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 dm_ctr_fn ctr;
97 dm_dtr_fn dtr;
98 dm_map_fn map;
99 dm_endio_fn end_io;
Bryn Reeves999d8162006-10-03 01:15:43 -0700100 dm_flush_fn flush;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 dm_presuspend_fn presuspend;
102 dm_postsuspend_fn postsuspend;
Milan Broz8757b772006-10-03 01:15:36 -0700103 dm_preresume_fn preresume;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 dm_resume_fn resume;
105 dm_status_fn status;
106 dm_message_fn message;
Milan Brozaa129a22006-10-03 01:15:15 -0700107 dm_ioctl_fn ioctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108};
109
110struct io_restrictions {
Alasdair G Kergon3ee247e2006-02-01 03:04:55 -0800111 unsigned int max_sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 unsigned short max_phys_segments;
113 unsigned short max_hw_segments;
114 unsigned short hardsect_size;
115 unsigned int max_segment_size;
116 unsigned long seg_boundary_mask;
NeilBrown969429b2006-03-27 01:17:49 -0800117 unsigned char no_cluster; /* inverted so that 0 is default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
120struct dm_target {
121 struct dm_table *table;
122 struct target_type *type;
123
124 /* target limits */
125 sector_t begin;
126 sector_t len;
127
128 /* FIXME: turn this into a mask, and merge with io_restrictions */
129 /* Always a power of 2 */
130 sector_t split_io;
131
132 /*
133 * These are automatically filled in by
134 * dm_table_get_device.
135 */
136 struct io_restrictions limits;
137
138 /* target specific data */
139 void *private;
140
141 /* Used to provide an error string from the ctr */
142 char *error;
143};
144
145int dm_register_target(struct target_type *t);
146int dm_unregister_target(struct target_type *t);
147
Alasdair G Kergon17b2f662006-06-26 00:27:33 -0700148
149/*-----------------------------------------------------------------
150 * Functions for creating and manipulating mapped devices.
151 * Drop the reference with dm_put when you finish with the object.
152 *---------------------------------------------------------------*/
153
154/*
155 * DM_ANY_MINOR chooses the next available minor number.
156 */
157#define DM_ANY_MINOR (-1)
158int dm_create(int minor, struct mapped_device **md);
159
160/*
161 * Reference counting for md.
162 */
163struct mapped_device *dm_get_md(dev_t dev);
164void dm_get(struct mapped_device *md);
165void dm_put(struct mapped_device *md);
166
167/*
168 * An arbitrary pointer may be stored alongside a mapped device.
169 */
170void dm_set_mdptr(struct mapped_device *md, void *ptr);
171void *dm_get_mdptr(struct mapped_device *md);
172
173/*
174 * A device can still be used while suspended, but I/O is deferred.
175 */
176int dm_suspend(struct mapped_device *md, int with_lockfs);
177int dm_resume(struct mapped_device *md);
178
179/*
180 * Event functions.
181 */
182uint32_t dm_get_event_nr(struct mapped_device *md);
183int dm_wait_event(struct mapped_device *md, int event_nr);
184
185/*
186 * Info functions.
187 */
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700188const char *dm_device_name(struct mapped_device *md);
Alasdair G Kergon17b2f662006-06-26 00:27:33 -0700189struct gendisk *dm_disk(struct mapped_device *md);
190int dm_suspended(struct mapped_device *md);
191
192/*
193 * Geometry functions.
194 */
195int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
196int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
197
198
199/*-----------------------------------------------------------------
200 * Functions for manipulating device-mapper tables.
201 *---------------------------------------------------------------*/
202
203/*
204 * First create an empty table.
205 */
206int dm_table_create(struct dm_table **result, int mode,
207 unsigned num_targets, struct mapped_device *md);
208
209/*
210 * Then call this once for each target.
211 */
212int dm_table_add_target(struct dm_table *t, const char *type,
213 sector_t start, sector_t len, char *params);
214
215/*
216 * Finally call this to make the table ready for use.
217 */
218int dm_table_complete(struct dm_table *t);
219
220/*
221 * Table reference counting.
222 */
223struct dm_table *dm_get_table(struct mapped_device *md);
224void dm_table_get(struct dm_table *t);
225void dm_table_put(struct dm_table *t);
226
227/*
228 * Queries
229 */
230sector_t dm_table_get_size(struct dm_table *t);
231unsigned int dm_table_get_num_targets(struct dm_table *t);
232int dm_table_get_mode(struct dm_table *t);
233struct mapped_device *dm_table_get_md(struct dm_table *t);
234
235/*
236 * Trigger an event.
237 */
238void dm_table_event(struct dm_table *t);
239
240/*
241 * The device must be suspended before calling this method.
242 */
243int dm_swap_table(struct mapped_device *md, struct dm_table *t);
244
David Teiglandc2ade422006-06-26 00:27:33 -0700245/*
246 * Prepare a table for a device that will error all I/O.
247 * To make it active, call dm_suspend(), dm_swap_table() then dm_resume().
248 */
249int dm_create_error_table(struct dm_table **result, struct mapped_device *md);
250
Alasdair G Kergon17b2f662006-06-26 00:27:33 -0700251#endif /* __KERNEL__ */
252#endif /* _LINUX_DEVICE_MAPPER_H */