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 * = 1: simple remap complete
43 * = 2: The target wants to push back the io
45 typedef int (*dm_map_fn
) (struct dm_target
*ti
, struct bio
*bio
,
46 union map_info
*map_context
);
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).
54 * 2 : The target wants to push back the io
56 typedef int (*dm_endio_fn
) (struct dm_target
*ti
,
57 struct bio
*bio
, int error
,
58 union map_info
*map_context
);
60 typedef void (*dm_flush_fn
) (struct dm_target
*ti
);
61 typedef void (*dm_presuspend_fn
) (struct dm_target
*ti
);
62 typedef void (*dm_postsuspend_fn
) (struct dm_target
*ti
);
63 typedef int (*dm_preresume_fn
) (struct dm_target
*ti
);
64 typedef void (*dm_resume_fn
) (struct dm_target
*ti
);
66 typedef int (*dm_status_fn
) (struct dm_target
*ti
, status_type_t status_type
,
67 char *result
, unsigned int maxlen
);
69 typedef int (*dm_message_fn
) (struct dm_target
*ti
, unsigned argc
, char **argv
);
71 typedef int (*dm_ioctl_fn
) (struct dm_target
*ti
, struct inode
*inode
,
72 struct file
*filp
, unsigned int cmd
,
75 void dm_error(const char *message
);
78 * Combine device limits.
80 void dm_set_device_limits(struct dm_target
*ti
, struct block_device
*bdev
);
83 * Constructors should call these functions to ensure destination devices
84 * are opened/closed correctly.
85 * FIXME: too many arguments.
87 int dm_get_device(struct dm_target
*ti
, const char *path
, sector_t start
,
88 sector_t len
, int mode
, struct dm_dev
**result
);
89 void dm_put_device(struct dm_target
*ti
, struct dm_dev
*d
);
92 * Information about a target type
96 struct module
*module
;
103 dm_presuspend_fn presuspend
;
104 dm_postsuspend_fn postsuspend
;
105 dm_preresume_fn preresume
;
108 dm_message_fn message
;
112 struct io_restrictions
{
113 unsigned int max_sectors
;
114 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
;
119 unsigned long bounce_pfn
;
120 unsigned char no_cluster
; /* inverted so that 0 is default */
124 struct dm_table
*table
;
125 struct target_type
*type
;
131 /* FIXME: turn this into a mask, and merge with io_restrictions */
132 /* Always a power of 2 */
136 * These are automatically filled in by
137 * dm_table_get_device.
139 struct io_restrictions limits
;
141 /* target specific data */
144 /* Used to provide an error string from the ctr */
148 int dm_register_target(struct target_type
*t
);
149 int dm_unregister_target(struct target_type
*t
);
152 /*-----------------------------------------------------------------
153 * Functions for creating and manipulating mapped devices.
154 * Drop the reference with dm_put when you finish with the object.
155 *---------------------------------------------------------------*/
158 * DM_ANY_MINOR chooses the next available minor number.
160 #define DM_ANY_MINOR (-1)
161 int dm_create(int minor
, struct mapped_device
**md
);
164 * Reference counting for md.
166 struct mapped_device
*dm_get_md(dev_t dev
);
167 void dm_get(struct mapped_device
*md
);
168 void dm_put(struct mapped_device
*md
);
171 * An arbitrary pointer may be stored alongside a mapped device.
173 void dm_set_mdptr(struct mapped_device
*md
, void *ptr
);
174 void *dm_get_mdptr(struct mapped_device
*md
);
177 * A device can still be used while suspended, but I/O is deferred.
179 int dm_suspend(struct mapped_device
*md
, unsigned suspend_flags
);
180 int dm_resume(struct mapped_device
*md
);
185 uint32_t dm_get_event_nr(struct mapped_device
*md
);
186 int dm_wait_event(struct mapped_device
*md
, int event_nr
);
187 uint32_t dm_next_uevent_seq(struct mapped_device
*md
);
188 void dm_uevent_add(struct mapped_device
*md
, struct list_head
*elist
);
193 const char *dm_device_name(struct mapped_device
*md
);
194 int dm_copy_name_and_uuid(struct mapped_device
*md
, char *name
, char *uuid
);
195 struct gendisk
*dm_disk(struct mapped_device
*md
);
196 int dm_suspended(struct mapped_device
*md
);
197 int dm_noflush_suspending(struct dm_target
*ti
);
200 * Geometry functions.
202 int dm_get_geometry(struct mapped_device
*md
, struct hd_geometry
*geo
);
203 int dm_set_geometry(struct mapped_device
*md
, struct hd_geometry
*geo
);
206 /*-----------------------------------------------------------------
207 * Functions for manipulating device-mapper tables.
208 *---------------------------------------------------------------*/
211 * First create an empty table.
213 int dm_table_create(struct dm_table
**result
, int mode
,
214 unsigned num_targets
, struct mapped_device
*md
);
217 * Then call this once for each target.
219 int dm_table_add_target(struct dm_table
*t
, const char *type
,
220 sector_t start
, sector_t len
, char *params
);
223 * Finally call this to make the table ready for use.
225 int dm_table_complete(struct dm_table
*t
);
228 * Table reference counting.
230 struct dm_table
*dm_get_table(struct mapped_device
*md
);
231 void dm_table_get(struct dm_table
*t
);
232 void dm_table_put(struct dm_table
*t
);
237 sector_t
dm_table_get_size(struct dm_table
*t
);
238 unsigned int dm_table_get_num_targets(struct dm_table
*t
);
239 int dm_table_get_mode(struct dm_table
*t
);
240 struct mapped_device
*dm_table_get_md(struct dm_table
*t
);
245 void dm_table_event(struct dm_table
*t
);
248 * The device must be suspended before calling this method.
250 int dm_swap_table(struct mapped_device
*md
, struct dm_table
*t
);
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().
256 int dm_create_error_table(struct dm_table
**result
, struct mapped_device
*md
);
258 #endif /* __KERNEL__ */
259 #endif /* _LINUX_DEVICE_MAPPER_H */