2 * Copyright (C) 2001 Sistina Software (UK) Limited.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
5 * This file is released under the LGPL.
8 #ifndef _LINUX_DEVICE_MAPPER_H
9 #define _LINUX_DEVICE_MAPPER_H
18 typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
22 unsigned long long ll;
26 * In the constructor the target parameter will already have the
27 * table, type, begin and len fields filled in.
29 typedef int (*dm_ctr_fn) (struct dm_target *target,
30 unsigned int argc, char **argv);
33 * The destructor doesn't need to free the dm_target, just
34 * anything hidden ti->private.
36 typedef void (*dm_dtr_fn) (struct dm_target *ti);
39 * The map function must return:
41 * = 0: The target will handle the io by resubmitting it later
42 * > 0: simple remap complete
44 typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
45 union map_info *map_context);
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).
54 typedef int (*dm_endio_fn) (struct dm_target *ti,
55 struct bio *bio, int error,
56 union map_info *map_context);
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);
63 typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
64 char *result, unsigned int maxlen);
66 typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
68 typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode,
69 struct file *filp, unsigned int cmd,
72 void dm_error(const char *message);
75 * Combine device limits.
77 void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
80 * Constructors should call these functions to ensure destination devices
81 * are opened/closed correctly.
82 * FIXME: too many arguments.
84 int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
85 sector_t len, int mode, struct dm_dev **result);
86 void dm_put_device(struct dm_target *ti, struct dm_dev *d);
89 * Information about a target type
93 struct module *module;
99 dm_presuspend_fn presuspend;
100 dm_postsuspend_fn postsuspend;
101 dm_preresume_fn preresume;
104 dm_message_fn message;
108 struct io_restrictions {
109 unsigned int max_sectors;
110 unsigned short max_phys_segments;
111 unsigned short max_hw_segments;
112 unsigned short hardsect_size;
113 unsigned int max_segment_size;
114 unsigned long seg_boundary_mask;
115 unsigned char no_cluster; /* inverted so that 0 is default */
119 struct dm_table *table;
120 struct target_type *type;
126 /* FIXME: turn this into a mask, and merge with io_restrictions */
127 /* Always a power of 2 */
131 * These are automatically filled in by
132 * dm_table_get_device.
134 struct io_restrictions limits;
136 /* target specific data */
139 /* Used to provide an error string from the ctr */
143 int dm_register_target(struct target_type *t);
144 int dm_unregister_target(struct target_type *t);
147 /*-----------------------------------------------------------------
148 * Functions for creating and manipulating mapped devices.
149 * Drop the reference with dm_put when you finish with the object.
150 *---------------------------------------------------------------*/
153 * DM_ANY_MINOR chooses the next available minor number.
155 #define DM_ANY_MINOR (-1)
156 int dm_create(int minor, struct mapped_device **md);
159 * Reference counting for md.
161 struct mapped_device *dm_get_md(dev_t dev);
162 void dm_get(struct mapped_device *md);
163 void dm_put(struct mapped_device *md);
166 * An arbitrary pointer may be stored alongside a mapped device.
168 void dm_set_mdptr(struct mapped_device *md, void *ptr);
169 void *dm_get_mdptr(struct mapped_device *md);
172 * A device can still be used while suspended, but I/O is deferred.
174 int dm_suspend(struct mapped_device *md, int with_lockfs);
175 int dm_resume(struct mapped_device *md);
180 uint32_t dm_get_event_nr(struct mapped_device *md);
181 int dm_wait_event(struct mapped_device *md, int event_nr);
186 const char *dm_device_name(struct mapped_device *md);
187 struct gendisk *dm_disk(struct mapped_device *md);
188 int dm_suspended(struct mapped_device *md);
191 * Geometry functions.
193 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
194 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
197 /*-----------------------------------------------------------------
198 * Functions for manipulating device-mapper tables.
199 *---------------------------------------------------------------*/
202 * First create an empty table.
204 int dm_table_create(struct dm_table **result, int mode,
205 unsigned num_targets, struct mapped_device *md);
208 * Then call this once for each target.
210 int dm_table_add_target(struct dm_table *t, const char *type,
211 sector_t start, sector_t len, char *params);
214 * Finally call this to make the table ready for use.
216 int dm_table_complete(struct dm_table *t);
219 * Table reference counting.
221 struct dm_table *dm_get_table(struct mapped_device *md);
222 void dm_table_get(struct dm_table *t);
223 void dm_table_put(struct dm_table *t);
228 sector_t dm_table_get_size(struct dm_table *t);
229 unsigned int dm_table_get_num_targets(struct dm_table *t);
230 int dm_table_get_mode(struct dm_table *t);
231 struct mapped_device *dm_table_get_md(struct dm_table *t);
236 void dm_table_event(struct dm_table *t);
239 * The device must be suspended before calling this method.
241 int dm_swap_table(struct mapped_device *md, struct dm_table *t);
244 * Prepare a table for a device that will error all I/O.
245 * To make it active, call dm_suspend(), dm_swap_table() then dm_resume().
247 int dm_create_error_table(struct dm_table **result, struct mapped_device *md);
249 #endif /* __KERNEL__ */
250 #endif /* _LINUX_DEVICE_MAPPER_H */