1/*	$NetBSD$	*/
2
3/*
4 * Copyright (C) 2001 - 2003 Sistina Software (UK) Limited.
5 * Copyright (C) 2004 - 2009 Red Hat, Inc. All rights reserved.
6 *
7 * This file is released under the LGPL.
8 */
9
10#ifndef _LINUX_DM_IOCTL_V4_H
11#define _LINUX_DM_IOCTL_V4_H
12
13#ifdef linux
14#  include <linux/types.h>
15#endif
16
17#define DM_DIR "mapper"		/* Slashes not supported */
18#define DM_MAX_TYPE_NAME 16
19#define DM_NAME_LEN 128
20#define DM_UUID_LEN 129
21
22/*
23 * A traditional ioctl interface for the device mapper.
24 *
25 * Each device can have two tables associated with it, an
26 * 'active' table which is the one currently used by io passing
27 * through the device, and an 'inactive' one which is a table
28 * that is being prepared as a replacement for the 'active' one.
29 *
30 * DM_VERSION:
31 * Just get the version information for the ioctl interface.
32 *
33 * DM_REMOVE_ALL:
34 * Remove all dm devices, destroy all tables.  Only really used
35 * for debug.
36 *
37 * DM_LIST_DEVICES:
38 * Get a list of all the dm device names.
39 *
40 * DM_DEV_CREATE:
41 * Create a new device, neither the 'active' or 'inactive' table
42 * slots will be filled.  The device will be in suspended state
43 * after creation, however any io to the device will get errored
44 * since it will be out-of-bounds.
45 *
46 * DM_DEV_REMOVE:
47 * Remove a device, destroy any tables.
48 *
49 * DM_DEV_RENAME:
50 * Rename a device.
51 *
52 * DM_SUSPEND:
53 * This performs both suspend and resume, depending which flag is
54 * passed in.
55 * Suspend: This command will not return until all pending io to
56 * the device has completed.  Further io will be deferred until
57 * the device is resumed.
58 * Resume: It is no longer an error to issue this command on an
59 * unsuspended device.  If a table is present in the 'inactive'
60 * slot, it will be moved to the active slot, then the old table
61 * from the active slot will be _destroyed_.  Finally the device
62 * is resumed.
63 *
64 * DM_DEV_STATUS:
65 * Retrieves the status for the table in the 'active' slot.
66 *
67 * DM_DEV_WAIT:
68 * Wait for a significant event to occur to the device.  This
69 * could either be caused by an event triggered by one of the
70 * targets of the table in the 'active' slot, or a table change.
71 *
72 * DM_TABLE_LOAD:
73 * Load a table into the 'inactive' slot for the device.  The
74 * device does _not_ need to be suspended prior to this command.
75 *
76 * DM_TABLE_CLEAR:
77 * Destroy any table in the 'inactive' slot (ie. abort).
78 *
79 * DM_TABLE_DEPS:
80 * Return a set of device dependencies for the 'active' table.
81 *
82 * DM_TABLE_STATUS:
83 * Return the targets status for the 'active' table.
84 *
85 * DM_TARGET_MSG:
86 * Pass a message string to the target at a specific offset of a device.
87 *
88 * DM_DEV_SET_GEOMETRY:
89 * Set the geometry of a device by passing in a string in this format:
90 *
91 * "cylinders heads sectors_per_track start_sector"
92 *
93 * Beware that CHS geometry is nearly obsolete and only provided
94 * for compatibility with dm devices that can be booted by a PC
95 * BIOS.  See struct hd_geometry for range limits.  Also note that
96 * the geometry is erased if the device size changes.
97 */
98
99/*
100 * All ioctl arguments consist of a single chunk of memory, with
101 * this structure at the start.  If a uuid is specified any
102 * lookup (eg. for a DM_INFO) will be done on that, *not* the
103 * name.
104 */
105struct dm_ioctl {
106	/*
107	 * The version number is made up of three parts:
108	 * major - no backward or forward compatibility,
109	 * minor - only backwards compatible,
110	 * patch - both backwards and forwards compatible.
111	 *
112	 * All clients of the ioctl interface should fill in the
113	 * version number of the interface that they were
114	 * compiled with.
115	 *
116	 * All recognised ioctl commands (ie. those that don't
117	 * return -ENOTTY) fill out this field, even if the
118	 * command failed.
119	 */
120	uint32_t version[3];	/* in/out */
121	uint32_t data_size;	/* total size of data passed in
122				 * including this struct */
123
124	uint32_t data_start;	/* offset to start of data
125				 * relative to start of this struct */
126
127	uint32_t target_count;	/* in/out */
128	int32_t open_count;	/* out */
129	uint32_t flags;		/* in/out */
130
131	/*
132	 * event_nr holds either the event number (input and output) or the
133	 * udev cookie value (input only).
134	 * The DM_DEV_WAIT ioctl takes an event number as input.
135	 * The DM_SUSPEND, DM_DEV_REMOVE and DM_DEV_RENAME ioctls
136	 * use the field as a cookie to return in the DM_COOKIE
137	 * variable with the uevents they issue.
138	 * For output, the ioctls return the event number, not the cookie.
139	 */
140	uint32_t event_nr;      	/* in/out */
141	uint32_t padding;
142
143	uint64_t dev;		/* in/out */
144
145	char name[DM_NAME_LEN];	/* device name */
146	char uuid[DM_UUID_LEN];	/* unique identifier for
147				 * the block device */
148	char data[7];		/* padding or data */
149};
150
151/*
152 * Used to specify tables.  These structures appear after the
153 * dm_ioctl.
154 */
155struct dm_target_spec {
156	uint64_t sector_start;
157	uint64_t length;
158	int32_t status;		/* used when reading from kernel only */
159
160	/*
161	 * Location of the next dm_target_spec.
162	 * - When specifying targets on a DM_TABLE_LOAD command, this value is
163	 *   the number of bytes from the start of the "current" dm_target_spec
164	 *   to the start of the "next" dm_target_spec.
165	 * - When retrieving targets on a DM_TABLE_STATUS command, this value
166	 *   is the number of bytes from the start of the first dm_target_spec
167	 *   (that follows the dm_ioctl struct) to the start of the "next"
168	 *   dm_target_spec.
169	 */
170	uint32_t next;
171
172	char target_type[DM_MAX_TYPE_NAME];
173
174	/*
175	 * Parameter string starts immediately after this object.
176	 * Be careful to add padding after string to ensure correct
177	 * alignment of subsequent dm_target_spec.
178	 */
179};
180
181/*
182 * Used to retrieve the target dependencies.
183 */
184struct dm_target_deps {
185	uint32_t count;	/* Array size */
186	uint32_t padding;	/* unused */
187	uint64_t dev[0];	/* out */
188};
189
190/*
191 * Used to get a list of all dm devices.
192 */
193struct dm_name_list {
194	uint64_t dev;
195	uint32_t next;		/* offset to the next record from
196				   the _start_ of this */
197	char name[0];
198};
199
200/*
201 * Used to retrieve the target versions
202 */
203struct dm_target_versions {
204        uint32_t next;
205        uint32_t version[3];
206
207        char name[0];
208};
209
210/*
211 * Used to pass message to a target
212 */
213struct dm_target_msg {
214	uint64_t sector;	/* Device sector */
215
216	char message[0];
217};
218
219/*
220 * If you change this make sure you make the corresponding change
221 * to dm-ioctl.c:lookup_ioctl()
222 */
223enum {
224	/* Top level cmds */
225	DM_VERSION_CMD = 0,
226	DM_REMOVE_ALL_CMD,
227	DM_LIST_DEVICES_CMD,
228
229	/* device level cmds */
230	DM_DEV_CREATE_CMD,
231	DM_DEV_REMOVE_CMD,
232	DM_DEV_RENAME_CMD,
233	DM_DEV_SUSPEND_CMD,
234	DM_DEV_STATUS_CMD,
235	DM_DEV_WAIT_CMD,
236
237	/* Table level cmds */
238	DM_TABLE_LOAD_CMD,
239	DM_TABLE_CLEAR_CMD,
240	DM_TABLE_DEPS_CMD,
241	DM_TABLE_STATUS_CMD,
242
243	/* Added later */
244	DM_LIST_VERSIONS_CMD,
245	DM_TARGET_MSG_CMD,
246	DM_DEV_SET_GEOMETRY_CMD
247};
248
249#define DM_IOCTL 0xfd
250
251#define DM_VERSION       _IOWR(DM_IOCTL, DM_VERSION_CMD, struct dm_ioctl)
252#define DM_REMOVE_ALL    _IOWR(DM_IOCTL, DM_REMOVE_ALL_CMD, struct dm_ioctl)
253#define DM_LIST_DEVICES  _IOWR(DM_IOCTL, DM_LIST_DEVICES_CMD, struct dm_ioctl)
254
255#define DM_DEV_CREATE    _IOWR(DM_IOCTL, DM_DEV_CREATE_CMD, struct dm_ioctl)
256#define DM_DEV_REMOVE    _IOWR(DM_IOCTL, DM_DEV_REMOVE_CMD, struct dm_ioctl)
257#define DM_DEV_RENAME    _IOWR(DM_IOCTL, DM_DEV_RENAME_CMD, struct dm_ioctl)
258#define DM_DEV_SUSPEND   _IOWR(DM_IOCTL, DM_DEV_SUSPEND_CMD, struct dm_ioctl)
259#define DM_DEV_STATUS    _IOWR(DM_IOCTL, DM_DEV_STATUS_CMD, struct dm_ioctl)
260#define DM_DEV_WAIT      _IOWR(DM_IOCTL, DM_DEV_WAIT_CMD, struct dm_ioctl)
261
262#define DM_TABLE_LOAD    _IOWR(DM_IOCTL, DM_TABLE_LOAD_CMD, struct dm_ioctl)
263#define DM_TABLE_CLEAR   _IOWR(DM_IOCTL, DM_TABLE_CLEAR_CMD, struct dm_ioctl)
264#define DM_TABLE_DEPS    _IOWR(DM_IOCTL, DM_TABLE_DEPS_CMD, struct dm_ioctl)
265#define DM_TABLE_STATUS  _IOWR(DM_IOCTL, DM_TABLE_STATUS_CMD, struct dm_ioctl)
266
267#define DM_LIST_VERSIONS _IOWR(DM_IOCTL, DM_LIST_VERSIONS_CMD, struct dm_ioctl)
268
269#define DM_TARGET_MSG	 _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, struct dm_ioctl)
270#define DM_DEV_SET_GEOMETRY	_IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
271
272#define DM_VERSION_MAJOR	4
273#define DM_VERSION_MINOR	16
274#define DM_VERSION_PATCHLEVEL	0
275#define DM_VERSION_EXTRA	"-ioctl (2009-11-05)"
276
277/* Status bits */
278#define DM_READONLY_FLAG	(1 << 0) /* In/Out */
279#define DM_SUSPEND_FLAG		(1 << 1) /* In/Out */
280#define DM_PERSISTENT_DEV_FLAG	(1 << 3) /* In */
281
282/*
283 * Flag passed into ioctl STATUS command to get table information
284 * rather than current status.
285 */
286#define DM_STATUS_TABLE_FLAG	(1 << 4) /* In */
287
288/*
289 * Flags that indicate whether a table is present in either of
290 * the two table slots that a device has.
291 */
292#define DM_ACTIVE_PRESENT_FLAG   (1 << 5) /* Out */
293#define DM_INACTIVE_PRESENT_FLAG (1 << 6) /* Out */
294
295/*
296 * Indicates that the buffer passed in wasn't big enough for the
297 * results.
298 */
299#define DM_BUFFER_FULL_FLAG	(1 << 8) /* Out */
300
301/*
302 * This flag is now ignored.
303 */
304#define DM_SKIP_BDGET_FLAG	(1 << 9) /* In */
305
306/*
307 * Set this to avoid attempting to freeze any filesystem when suspending.
308 */
309#define DM_SKIP_LOCKFS_FLAG	(1 << 10) /* In */
310
311/*
312 * Set this to suspend without flushing queued ios.
313 */
314#define DM_NOFLUSH_FLAG		(1 << 11) /* In */
315
316/*
317 * If set, any table information returned will relate to the inactive
318 * table instead of the live one.  Always check DM_INACTIVE_PRESENT_FLAG
319 * is set before using the data returned.
320 */
321#define DM_QUERY_INACTIVE_TABLE_FLAG	(1 << 12) /* In */
322
323#endif				/* _LINUX_DM_IOCTL_H */
324