]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/device-mapper.h
dm: export name and uuid
[mirror_ubuntu-bionic-kernel.git] / include / linux / device-mapper.h
CommitLineData
1da177e4
LT
1/*
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
17b2f66f
AK
11#ifdef __KERNEL__
12
1da177e4
LT
13struct dm_target;
14struct dm_table;
15struct dm_dev;
17b2f66f 16struct mapped_device;
1da177e4
LT
17
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
45cbcd79 42 * = 1: simple remap complete
2e93ccc1 43 * = 2: The target wants to push back the io
1da177e4
LT
44 */
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).
2e93ccc1 54 * 2 : The target wants to push back the io
1da177e4
LT
55 */
56typedef int (*dm_endio_fn) (struct dm_target *ti,
57 struct bio *bio, int error,
58 union map_info *map_context);
59
999d8168 60typedef void (*dm_flush_fn) (struct dm_target *ti);
1da177e4
LT
61typedef void (*dm_presuspend_fn) (struct dm_target *ti);
62typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
8757b776 63typedef int (*dm_preresume_fn) (struct dm_target *ti);
1da177e4
LT
64typedef 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
aa129a22
MB
71typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode,
72 struct file *filp, unsigned int cmd,
73 unsigned long arg);
74
1da177e4
LT
75void dm_error(const char *message);
76
3cb40214
BR
77/*
78 * Combine device limits.
79 */
80void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
81
1da177e4
LT
82/*
83 * 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;
17b2f66f 97 unsigned version[3];
1da177e4
LT
98 dm_ctr_fn ctr;
99 dm_dtr_fn dtr;
100 dm_map_fn map;
101 dm_endio_fn end_io;
999d8168 102 dm_flush_fn flush;
1da177e4
LT
103 dm_presuspend_fn presuspend;
104 dm_postsuspend_fn postsuspend;
8757b776 105 dm_preresume_fn preresume;
1da177e4
LT
106 dm_resume_fn resume;
107 dm_status_fn status;
108 dm_message_fn message;
aa129a22 109 dm_ioctl_fn ioctl;
1da177e4
LT
110};
111
112struct io_restrictions {
3ee247eb 113 unsigned int max_sectors;
1da177e4
LT
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;
969429b5 119 unsigned char no_cluster; /* inverted so that 0 is default */
1da177e4
LT
120};
121
122struct dm_target {
123 struct dm_table *table;
124 struct target_type *type;
125
126 /* target limits */
127 sector_t begin;
128 sector_t len;
129
130 /* FIXME: turn this into a mask, and merge with io_restrictions */
131 /* Always a power of 2 */
132 sector_t split_io;
133
134 /*
135 * These are automatically filled in by
136 * dm_table_get_device.
137 */
138 struct io_restrictions limits;
139
140 /* target specific data */
141 void *private;
142
143 /* Used to provide an error string from the ctr */
144 char *error;
145};
146
147int dm_register_target(struct target_type *t);
148int dm_unregister_target(struct target_type *t);
149
17b2f66f
AK
150
151/*-----------------------------------------------------------------
152 * Functions for creating and manipulating mapped devices.
153 * Drop the reference with dm_put when you finish with the object.
154 *---------------------------------------------------------------*/
155
156/*
157 * DM_ANY_MINOR chooses the next available minor number.
158 */
159#define DM_ANY_MINOR (-1)
160int dm_create(int minor, struct mapped_device **md);
161
162/*
163 * Reference counting for md.
164 */
165struct mapped_device *dm_get_md(dev_t dev);
166void dm_get(struct mapped_device *md);
167void dm_put(struct mapped_device *md);
168
169/*
170 * An arbitrary pointer may be stored alongside a mapped device.
171 */
172void dm_set_mdptr(struct mapped_device *md, void *ptr);
173void *dm_get_mdptr(struct mapped_device *md);
174
175/*
176 * A device can still be used while suspended, but I/O is deferred.
177 */
a3d77d35 178int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
17b2f66f
AK
179int dm_resume(struct mapped_device *md);
180
181/*
182 * Event functions.
183 */
184uint32_t dm_get_event_nr(struct mapped_device *md);
185int dm_wait_event(struct mapped_device *md, int event_nr);
186
187/*
188 * Info functions.
189 */
72d94861 190const char *dm_device_name(struct mapped_device *md);
96a1f7db 191int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
17b2f66f
AK
192struct gendisk *dm_disk(struct mapped_device *md);
193int dm_suspended(struct mapped_device *md);
2e93ccc1 194int dm_noflush_suspending(struct dm_target *ti);
17b2f66f
AK
195
196/*
197 * Geometry functions.
198 */
199int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
200int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
201
202
203/*-----------------------------------------------------------------
204 * Functions for manipulating device-mapper tables.
205 *---------------------------------------------------------------*/
206
207/*
208 * First create an empty table.
209 */
210int dm_table_create(struct dm_table **result, int mode,
211 unsigned num_targets, struct mapped_device *md);
212
213/*
214 * Then call this once for each target.
215 */
216int dm_table_add_target(struct dm_table *t, const char *type,
217 sector_t start, sector_t len, char *params);
218
219/*
220 * Finally call this to make the table ready for use.
221 */
222int dm_table_complete(struct dm_table *t);
223
224/*
225 * Table reference counting.
226 */
227struct dm_table *dm_get_table(struct mapped_device *md);
228void dm_table_get(struct dm_table *t);
229void dm_table_put(struct dm_table *t);
230
231/*
232 * Queries
233 */
234sector_t dm_table_get_size(struct dm_table *t);
235unsigned int dm_table_get_num_targets(struct dm_table *t);
236int dm_table_get_mode(struct dm_table *t);
237struct mapped_device *dm_table_get_md(struct dm_table *t);
238
239/*
240 * Trigger an event.
241 */
242void dm_table_event(struct dm_table *t);
243
244/*
245 * The device must be suspended before calling this method.
246 */
247int dm_swap_table(struct mapped_device *md, struct dm_table *t);
248
c2ade42d
DT
249/*
250 * Prepare a table for a device that will error all I/O.
251 * To make it active, call dm_suspend(), dm_swap_table() then dm_resume().
252 */
253int dm_create_error_table(struct dm_table **result, struct mapped_device *md);
254
17b2f66f
AK
255#endif /* __KERNEL__ */
256#endif /* _LINUX_DEVICE_MAPPER_H */