sys/dev/disk/dm: Don't implement "status" as a subset of "table" [1/2]
[dragonfly.git] / sys / dev / disk / dm / dm.h
CommitLineData
ff56536e
AH
1/* $NetBSD: dm.h,v 1.17 2009/12/29 23:37:48 haad Exp $ */
2
3/*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Hamsik.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _DM_DEV_H_
33#define _DM_DEV_H_
34
35
36#ifdef _KERNEL
37
38#include <sys/errno.h>
5b279a20
AH
39#include <sys/systm.h>
40#include <sys/kernel.h>
ff56536e 41
5b279a20
AH
42#include <cpu/inttypes.h>
43#include <cpu/atomic.h>
ff56536e 44#include <sys/condvar.h>
5b279a20 45#include <sys/lock.h>
ff56536e
AH
46#include <sys/queue.h>
47
26f449c0 48#include <sys/buf.h>
ff56536e 49#include <sys/device.h>
3b48c3c1 50#include <sys/devicestat.h>
79b7159f 51#include <sys/diskslice.h>
ff56536e
AH
52#include <sys/disklabel.h>
53
5b279a20 54#include <libprop/proplib.h>
ff56536e
AH
55
56#define DM_MAX_TYPE_NAME 16
57#define DM_NAME_LEN 128
58#define DM_UUID_LEN 129
59
60#define DM_VERSION_MAJOR 4
61#define DM_VERSION_MINOR 16
62
63#define DM_VERSION_PATCHLEVEL 0
64
65/*** Internal device-mapper structures ***/
66
ff56536e
AH
67/*
68 * A device mapper table is a list of physical ranges plus the mapping target
69 * applied to them.
70 */
ff56536e
AH
71typedef struct dm_table_entry {
72 struct dm_dev *dm_dev; /* backlink */
73 uint64_t start;
74 uint64_t length;
75
76 struct dm_target *target; /* Link to table target. */
77 void *target_config; /* Target specific data. */
78 SLIST_ENTRY(dm_table_entry) next;
79} dm_table_entry_t;
80
81SLIST_HEAD(dm_table, dm_table_entry);
82
83typedef struct dm_table dm_table_t;
84
85typedef struct dm_table_head {
86 /* Current active table is selected with this. */
87 int cur_active_table;
88 struct dm_table tables[2];
89
5b279a20 90 struct lock table_mtx;
ff56536e 91
1efa8440 92 int io_cnt;
ff56536e
AH
93} dm_table_head_t;
94
95#define MAX_DEV_NAME 32
96
97/*
98 * This structure is used to store opened vnodes for disk with name.
99 * I need this because devices can be opened only once, but I can
100 * have more then one device on one partition.
101 */
102
103typedef struct dm_pdev {
104 char name[MAX_DEV_NAME];
79b7159f 105 struct partinfo pdev_pinfo; /* partinfo of the underlying device */
ff56536e
AH
106
107 struct vnode *pdev_vnode;
108 int ref_cnt; /* reference counter for users ofthis pdev */
109
110 SLIST_ENTRY(dm_pdev) next_pdev;
111} dm_pdev_t;
112
113/*
114 * This structure is called for every device-mapper device.
115 * It points to SLIST of device tables and mirrored, snapshoted etc. devices.
116 */
5b279a20 117TAILQ_HEAD(dm_dev_head, dm_dev);
3b48c3c1 118
ff56536e
AH
119typedef struct dm_dev {
120 char name[DM_NAME_LEN];
121 char uuid[DM_UUID_LEN];
122
5b279a20 123 cdev_t devt; /* pointer to autoconf device_t structure */
ff56536e
AH
124 uint64_t minor;
125 uint32_t flags; /* store communication protocol flags */
126
5b279a20
AH
127 struct lock dev_mtx; /* mutex for generall device lock */
128 struct cv dev_cv; /* cv for between ioctl synchronisation */
3b48c3c1 129
ff56536e
AH
130 uint32_t event_nr;
131 uint32_t ref_cnt;
132
133 uint32_t dev_type;
956c8d71 134 uint32_t is_open;
ff56536e
AH
135
136 dm_table_head_t table_head;
137
138 struct dm_dev_head upcalls;
3b48c3c1 139
ff56536e 140 struct disk *diskp;
3b48c3c1
AH
141
142 struct devstat stats;
143
ff56536e
AH
144 TAILQ_ENTRY(dm_dev) next_upcall; /* LIST of mirrored, snapshoted devices. */
145
146 TAILQ_ENTRY(dm_dev) next_devlist; /* Major device list. */
147} dm_dev_t;
148
149/* Device types used for upcalls */
150#define DM_ZERO_DEV (1 << 0)
01588625 151#define DM_ERROR_DEV (1 << 1)
ff56536e
AH
152#define DM_LINEAR_DEV (1 << 2)
153#define DM_MIRROR_DEV (1 << 3)
154#define DM_STRIPE_DEV (1 << 4)
155#define DM_SNAPSHOT_DEV (1 << 5)
156#define DM_SNAPSHOT_ORIG_DEV (1 << 6)
bae9e161
TK
157#define DM_RESERVED1_DEV (1 << 7)
158#define DM_RESERVED2_DEV (1 << 8)
01588625
TK
159#define DM_CRYPTO_DEV (1 << 9)
160#define DM_RAID1_DEV (1 << 10)
59146421 161#define DM_DELAY_DEV (1 << 11)
ff56536e
AH
162
163/* for zero, error : dm_target->target_config == NULL */
01588625 164
ff56536e
AH
165/*
166 * Target config is initiated with target_init function.
167 */
01588625 168
ff56536e
AH
169/* constant dm_target structures for error, zero, linear, stripes etc. */
170typedef struct dm_target {
171 char name[DM_MAX_TYPE_NAME];
172 /* Initialize target_config area */
173 int (*init)(dm_dev_t *, void **, char *);
174
51292ec6
AH
175 /* Message interface */
176 int (*message)(dm_table_entry_t *, char *);
177
ff56536e
AH
178 /* Destroy target_config area */
179 int (*destroy)(dm_table_entry_t *);
01588625 180
ff56536e
AH
181 int (*deps) (dm_table_entry_t *, prop_array_t);
182 /*
f134a703 183 * Info and status are called to get params string, which is target
ff56536e
AH
184 * specific. When dm_table_status_ioctl is called with flag
185 * DM_STATUS_TABLE_FLAG I have to sent params string back.
186 */
f134a703 187 char *(*info)(void *);
bdf2de7b 188 char *(*status)(void *);
ff56536e
AH
189 int (*strategy)(dm_table_entry_t *, struct buf *);
190 int (*upcall)(dm_table_entry_t *, struct buf *);
79b7159f
AH
191 int (*dump)(dm_table_entry_t *, void *data, size_t length, off_t offset);
192
ff56536e
AH
193 uint32_t version[3];
194 int ref_cnt;
01588625 195
ff56536e
AH
196 TAILQ_ENTRY(dm_target) dm_target_next;
197} dm_target_t;
198
199/* Interface structures */
200
201/*
202 * This structure is used to translate command sent to kernel driver in
203 * <key>command</key>
204 * <value></value>
205 * to function which I can call.
206 */
207struct cmd_function {
208 const char *cmd;
209 int (*fn)(prop_dictionary_t);
210};
211
212/* device-mapper */
5b279a20 213void dmsetdiskinfo(struct disk *, dm_table_head_t *);
ff56536e
AH
214
215/* dm_ioctl.c */
216int dm_dev_create_ioctl(prop_dictionary_t);
217int dm_dev_list_ioctl(prop_dictionary_t);
218int dm_dev_remove_ioctl(prop_dictionary_t);
9fada28a 219int dm_dev_remove_all_ioctl(prop_dictionary_t);
ff56536e
AH
220int dm_dev_rename_ioctl(prop_dictionary_t);
221int dm_dev_resume_ioctl(prop_dictionary_t);
222int dm_dev_status_ioctl(prop_dictionary_t);
223int dm_dev_suspend_ioctl(prop_dictionary_t);
224
225int dm_check_version(prop_dictionary_t);
ff56536e
AH
226int dm_list_versions_ioctl(prop_dictionary_t);
227
228int dm_table_clear_ioctl(prop_dictionary_t);
229int dm_table_deps_ioctl(prop_dictionary_t);
230int dm_table_load_ioctl(prop_dictionary_t);
231int dm_table_status_ioctl(prop_dictionary_t);
51292ec6 232int dm_message_ioctl(prop_dictionary_t);
ff56536e
AH
233
234/* dm_target.c */
9fada28a
AH
235int dm_target_init(void);
236int dm_target_uninit(void);
ff56536e 237dm_target_t* dm_target_alloc(const char *);
7115a22b 238dm_target_t* dm_target_autoload(const char *);
ff56536e
AH
239int dm_target_insert(dm_target_t *);
240prop_array_t dm_target_prop_list(void);
241dm_target_t* dm_target_lookup(const char *);
242int dm_target_rem(char *);
243void dm_target_unbusy(dm_target_t *);
244void dm_target_busy(dm_target_t *);
245
ff56536e
AH
246#define DM_MAX_PARAMS_SIZE 1024
247
ff56536e 248/* Generic function used to convert char to string */
1446934e 249uint64_t atoi64(const char *);
ff56536e 250
ff56536e
AH
251/* dm_table.c */
252#define DM_TABLE_ACTIVE 0
253#define DM_TABLE_INACTIVE 1
254
255int dm_table_destroy(dm_table_head_t *, uint8_t);
256uint64_t dm_table_size(dm_table_head_t *);
cc760215 257uint64_t dm_inactive_table_size(dm_table_head_t *);
bdf2de7b 258dm_table_t *dm_table_get_entry(dm_table_head_t *, uint8_t);
ff56536e
AH
259int dm_table_get_target_count(dm_table_head_t *, uint8_t);
260void dm_table_release(dm_table_head_t *, uint8_t s);
261void dm_table_switch_tables(dm_table_head_t *);
262void dm_table_head_init(dm_table_head_t *);
263void dm_table_head_destroy(dm_table_head_t *);
264
265/* dm_dev.c */
9fada28a
AH
266int dm_dev_init(void);
267int dm_dev_uninit(void);
ff56536e
AH
268dm_dev_t* dm_dev_alloc(void);
269void dm_dev_busy(dm_dev_t *);
9fada28a
AH
270int dm_dev_create(dm_dev_t **, const char *, const char *, int);
271int dm_dev_remove(dm_dev_t *);
272int dm_dev_remove_all(int);
273int dm_dev_destroy(dm_dev_t *);
ff56536e 274int dm_dev_free(dm_dev_t *);
ff56536e
AH
275int dm_dev_insert(dm_dev_t *);
276dm_dev_t* dm_dev_lookup(const char *, const char *, int);
277prop_array_t dm_dev_prop_list(void);
4c28af7b
TK
278dm_dev_t* dm_dev_rem_dev(dm_dev_t *);
279dm_dev_t* dm_dev_rem(const char *, const char *, int);
ff56536e
AH
280void dm_dev_unbusy(dm_dev_t *);
281
282/* dm_pdev.c */
ff56536e 283int dm_pdev_init(void);
9fada28a
AH
284int dm_pdev_uninit(void);
285int dm_pdev_decr(dm_pdev_t *);
ff56536e 286dm_pdev_t* dm_pdev_insert(const char *);
79b7159f 287off_t dm_pdev_correct_dump_offset(dm_pdev_t *, off_t);
ff56536e 288
7115a22b
AH
289/* dm builtin magic */
290void dm_builtin_init(void *);
291void dm_builtin_uninit(void *);
292
aadb5a11 293extern int dm_debug_level;
1446934e 294MALLOC_DECLARE(M_DM);
aadb5a11
AH
295
296#define aprint_debug(format, ...) \
297 do { if (dm_debug_level) kprintf(format, ## __VA_ARGS__); } while(0)
5b279a20
AH
298#define aprint_normal kprintf
299
ba65ac12
AH
300#define DM_TARGET_MODULE(name, evh) \
301 static moduledata_t name##_mod = { \
302 #name, \
303 evh, \
304 NULL \
305 }; \
7115a22b
AH
306 DECLARE_MODULE(name, name##_mod, SI_SUB_DM_TARGETS, \
307 SI_ORDER_ANY); \
308 MODULE_DEPEND(name, dm, 1, 1, 1)
309
310#define DM_TARGET_BUILTIN(name, evh) \
311 SYSINIT(name##module, SI_SUB_DM_TARGETS, SI_ORDER_ANY, \
312 dm_builtin_init, evh); \
313 SYSUNINIT(name##module, SI_SUB_DM_TARGETS, SI_ORDER_ANY, \
314 dm_builtin_uninit, evh)
ba65ac12 315
ff56536e
AH
316#endif /*_KERNEL*/
317
318#endif /*_DM_DEV_H_*/