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