blob: b8b7c51389fe0ecff2608f63b928140601347a3f [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
Kiyoshi Ueda45cbcd72006-12-08 02:41:05 -080042 * = 1: simple remap complete
Kiyoshi Ueda2e93ccc2006-12-08 02:41:09 -080043 * = 2: The target wants to push back the io
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 */
45typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
46 union map_info *map_context);
47
48/*
49 * Returns:
50 * < 0 : error (currently ignored)
51 * 0 : ended successfully
52 * 1 : for some reason the io has still not completed (eg,
53 * multipath target might want to requeue a failed io).
Kiyoshi Ueda2e93ccc2006-12-08 02:41:09 -080054 * 2 : The target wants to push back the io
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 */
56typedef int (*dm_endio_fn) (struct dm_target *ti,
57 struct bio *bio, int error,
58 union map_info *map_context);
59
Bryn Reeves999d8162006-10-03 01:15:43 -070060typedef void (*dm_flush_fn) (struct dm_target *ti);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061typedef void (*dm_presuspend_fn) (struct dm_target *ti);
62typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
Milan Broz8757b772006-10-03 01:15:36 -070063typedef int (*dm_preresume_fn) (struct dm_target *ti);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064typedef void (*dm_resume_fn) (struct dm_target *ti);
65
66typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
67 char *result, unsigned int maxlen);
68
69typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
70
Milan Brozaa129a22006-10-03 01:15:15 -070071typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode,
72 struct file *filp, unsigned int cmd,
73 unsigned long arg);
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075void dm_error(const char *message);
76
77/*
Bryn Reeves3cb40212006-10-03 01:15:42 -070078 * Combine device limits.
79 */
80void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
81
82/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 * Constructors should call these functions to ensure destination devices
84 * are opened/closed correctly.
85 * FIXME: too many arguments.
86 */
87int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
88 sector_t len, int mode, struct dm_dev **result);
89void dm_put_device(struct dm_target *ti, struct dm_dev *d);
90
91/*
92 * Information about a target type
93 */
94struct target_type {
95 const char *name;
96 struct module *module;
Alasdair G Kergon17b2f662006-06-26 00:27:33 -070097 unsigned version[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 dm_ctr_fn ctr;
99 dm_dtr_fn dtr;
100 dm_map_fn map;
101 dm_endio_fn end_io;
Bryn Reeves999d8162006-10-03 01:15:43 -0700102 dm_flush_fn flush;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 dm_presuspend_fn presuspend;
104 dm_postsuspend_fn postsuspend;
Milan Broz8757b772006-10-03 01:15:36 -0700105 dm_preresume_fn preresume;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 dm_resume_fn resume;
107 dm_status_fn status;
108 dm_message_fn message;
Milan Brozaa129a22006-10-03 01:15:15 -0700109 dm_ioctl_fn ioctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110};
111
112struct io_restrictions {
Alasdair G Kergon3ee247e2006-02-01 03:04:55 -0800113 unsigned int max_sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 unsigned short max_phys_segments;
115 unsigned short max_hw_segments;
116 unsigned short hardsect_size;
117 unsigned int max_segment_size;
118 unsigned long seg_boundary_mask;
Vasily Averin5ec140e2007-10-31 08:33:24 +0100119 unsigned long bounce_pfn;
NeilBrown969429b2006-03-27 01:17:49 -0800120 unsigned char no_cluster; /* inverted so that 0 is default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121};
122
123struct dm_target {
124 struct dm_table *table;
125 struct target_type *type;
126
127 /* target limits */
128 sector_t begin;
129 sector_t len;
130
131 /* FIXME: turn this into a mask, and merge with io_restrictions */
132 /* Always a power of 2 */
133 sector_t split_io;
134
135 /*
136 * These are automatically filled in by
137 * dm_table_get_device.
138 */
139 struct io_restrictions limits;
140
141 /* target specific data */
142 void *private;
143
144 /* Used to provide an error string from the ctr */
145 char *error;
146};
147
148int dm_register_target(struct target_type *t);
149int dm_unregister_target(struct target_type *t);
150
Alasdair G Kergon17b2f662006-06-26 00:27:33 -0700151
152/*-----------------------------------------------------------------
153 * Functions for creating and manipulating mapped devices.
154 * Drop the reference with dm_put when you finish with the object.
155 *---------------------------------------------------------------*/
156
157/*
158 * DM_ANY_MINOR chooses the next available minor number.
159 */
160#define DM_ANY_MINOR (-1)
161int dm_create(int minor, struct mapped_device **md);
162
163/*
164 * Reference counting for md.
165 */
166struct mapped_device *dm_get_md(dev_t dev);
167void dm_get(struct mapped_device *md);
168void dm_put(struct mapped_device *md);
169
170/*
171 * An arbitrary pointer may be stored alongside a mapped device.
172 */
173void dm_set_mdptr(struct mapped_device *md, void *ptr);
174void *dm_get_mdptr(struct mapped_device *md);
175
176/*
177 * A device can still be used while suspended, but I/O is deferred.
178 */
Kiyoshi Uedaa3d77d32006-12-08 02:41:04 -0800179int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
Alasdair G Kergon17b2f662006-06-26 00:27:33 -0700180int dm_resume(struct mapped_device *md);
181
182/*
183 * Event functions.
184 */
185uint32_t dm_get_event_nr(struct mapped_device *md);
186int dm_wait_event(struct mapped_device *md, int event_nr);
Mike Anderson7a8c3d32007-10-19 22:48:01 +0100187uint32_t dm_next_uevent_seq(struct mapped_device *md);
188void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
Alasdair G Kergon17b2f662006-06-26 00:27:33 -0700189
190/*
191 * Info functions.
192 */
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700193const char *dm_device_name(struct mapped_device *md);
Mike Anderson96a1f7d2007-10-19 22:47:59 +0100194int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
Alasdair G Kergon17b2f662006-06-26 00:27:33 -0700195struct gendisk *dm_disk(struct mapped_device *md);
196int dm_suspended(struct mapped_device *md);
Kiyoshi Ueda2e93ccc2006-12-08 02:41:09 -0800197int dm_noflush_suspending(struct dm_target *ti);
Alasdair G Kergon17b2f662006-06-26 00:27:33 -0700198
199/*
200 * Geometry functions.
201 */
202int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
203int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
204
205
206/*-----------------------------------------------------------------
207 * Functions for manipulating device-mapper tables.
208 *---------------------------------------------------------------*/
209
210/*
211 * First create an empty table.
212 */
213int dm_table_create(struct dm_table **result, int mode,
214 unsigned num_targets, struct mapped_device *md);
215
216/*
217 * Then call this once for each target.
218 */
219int dm_table_add_target(struct dm_table *t, const char *type,
220 sector_t start, sector_t len, char *params);
221
222/*
223 * Finally call this to make the table ready for use.
224 */
225int dm_table_complete(struct dm_table *t);
226
227/*
228 * Table reference counting.
229 */
230struct dm_table *dm_get_table(struct mapped_device *md);
231void dm_table_get(struct dm_table *t);
232void dm_table_put(struct dm_table *t);
233
234/*
235 * Queries
236 */
237sector_t dm_table_get_size(struct dm_table *t);
238unsigned int dm_table_get_num_targets(struct dm_table *t);
239int dm_table_get_mode(struct dm_table *t);
240struct mapped_device *dm_table_get_md(struct dm_table *t);
241
242/*
243 * Trigger an event.
244 */
245void dm_table_event(struct dm_table *t);
246
247/*
248 * The device must be suspended before calling this method.
249 */
250int dm_swap_table(struct mapped_device *md, struct dm_table *t);
251
David Teiglandc2ade422006-06-26 00:27:33 -0700252/*
253 * Prepare a table for a device that will error all I/O.
254 * To make it active, call dm_suspend(), dm_swap_table() then dm_resume().
255 */
256int dm_create_error_table(struct dm_table **result, struct mapped_device *md);
257
Alasdair G Kergon17b2f662006-06-26 00:27:33 -0700258#endif /* __KERNEL__ */
259#endif /* _LINUX_DEVICE_MAPPER_H */