vserver 1.9.3
[linux-2.6.git] / drivers / md / dm.h
1 /*
2  * Internal header file for device mapper
3  *
4  * Copyright (C) 2001, 2002 Sistina Software
5  *
6  * This file is released under the LGPL.
7  */
8
9 #ifndef DM_INTERNAL_H
10 #define DM_INTERNAL_H
11
12 #include <linux/fs.h>
13 #include <linux/device-mapper.h>
14 #include <linux/list.h>
15 #include <linux/blkdev.h>
16
17 #define DM_NAME "device-mapper"
18 #define DMWARN(f, x...) printk(KERN_WARNING DM_NAME ": " f "\n" , ## x)
19 #define DMERR(f, x...) printk(KERN_ERR DM_NAME ": " f "\n" , ## x)
20 #define DMINFO(f, x...) printk(KERN_INFO DM_NAME ": " f "\n" , ## x)
21
22 #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
23                           0 : scnprintf(result + sz, maxlen - sz, x))
24
25 /*
26  * FIXME: I think this should be with the definition of sector_t
27  * in types.h.
28  */
29 #ifdef CONFIG_LBD
30 #define SECTOR_FORMAT "%Lu"
31 #else
32 #define SECTOR_FORMAT "%lu"
33 #endif
34
35 #define SECTOR_SHIFT 9
36
37 /*
38  * List of devices that a metadevice uses and should open/close.
39  */
40 struct dm_dev {
41         struct list_head list;
42
43         atomic_t count;
44         int mode;
45         struct block_device *bdev;
46 };
47
48 struct dm_table;
49 struct mapped_device;
50
51 /*-----------------------------------------------------------------
52  * Functions for manipulating a struct mapped_device.
53  * Drop the reference with dm_put when you finish with the object.
54  *---------------------------------------------------------------*/
55 int dm_create(struct mapped_device **md);
56 int dm_create_with_minor(unsigned int minor, struct mapped_device **md);
57
58 /*
59  * Reference counting for md.
60  */
61 void dm_get(struct mapped_device *md);
62 void dm_put(struct mapped_device *md);
63
64 /*
65  * A device can still be used while suspended, but I/O is deferred.
66  */
67 int dm_suspend(struct mapped_device *md);
68 int dm_resume(struct mapped_device *md);
69
70 /*
71  * The device must be suspended before calling this method.
72  */
73 int dm_swap_table(struct mapped_device *md, struct dm_table *t);
74
75 /*
76  * Drop a reference on the table when you've finished with the
77  * result.
78  */
79 struct dm_table *dm_get_table(struct mapped_device *md);
80
81 /*
82  * Event functions.
83  */
84 uint32_t dm_get_event_nr(struct mapped_device *md);
85 int dm_wait_event(struct mapped_device *md, int event_nr);
86
87 /*
88  * Info functions.
89  */
90 struct gendisk *dm_disk(struct mapped_device *md);
91 int dm_suspended(struct mapped_device *md);
92
93 /*-----------------------------------------------------------------
94  * Functions for manipulating a table.  Tables are also reference
95  * counted.
96  *---------------------------------------------------------------*/
97 int dm_table_create(struct dm_table **result, int mode, unsigned num_targets);
98
99 void dm_table_get(struct dm_table *t);
100 void dm_table_put(struct dm_table *t);
101
102 int dm_table_add_target(struct dm_table *t, const char *type,
103                         sector_t start, sector_t len, char *params);
104 int dm_table_complete(struct dm_table *t);
105 void dm_table_event_callback(struct dm_table *t,
106                              void (*fn)(void *), void *context);
107 void dm_table_event(struct dm_table *t);
108 sector_t dm_table_get_size(struct dm_table *t);
109 struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index);
110 struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector);
111 void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q);
112 unsigned int dm_table_get_num_targets(struct dm_table *t);
113 struct list_head *dm_table_get_devices(struct dm_table *t);
114 int dm_table_get_mode(struct dm_table *t);
115 void dm_table_suspend_targets(struct dm_table *t);
116 void dm_table_resume_targets(struct dm_table *t);
117 int dm_table_any_congested(struct dm_table *t, int bdi_bits);
118 void dm_table_unplug_all(struct dm_table *t);
119 int dm_table_flush_all(struct dm_table *t);
120
121 /*-----------------------------------------------------------------
122  * A registry of target types.
123  *---------------------------------------------------------------*/
124 int dm_target_init(void);
125 void dm_target_exit(void);
126 struct target_type *dm_get_target_type(const char *name);
127 void dm_put_target_type(struct target_type *t);
128 int dm_target_iterate(void (*iter_func)(struct target_type *tt,
129                                         void *param), void *param);
130
131
132 /*-----------------------------------------------------------------
133  * Useful inlines.
134  *---------------------------------------------------------------*/
135 static inline int array_too_big(unsigned long fixed, unsigned long obj,
136                                 unsigned long num)
137 {
138         return (num > (ULONG_MAX - fixed) / obj);
139 }
140
141 /*
142  * ceiling(n / size) * size
143  */
144 static inline unsigned long dm_round_up(unsigned long n, unsigned long size)
145 {
146         unsigned long r = n % size;
147         return n + (r ? (size - r) : 0);
148 }
149
150 /*
151  * Ceiling(n / size)
152  */
153 static inline unsigned long dm_div_up(unsigned long n, unsigned long size)
154 {
155         return dm_round_up(n, size) / size;
156 }
157
158 static inline sector_t to_sector(unsigned long n)
159 {
160         return (n >> 9);
161 }
162
163 static inline unsigned long to_bytes(sector_t n)
164 {
165         return (n << 9);
166 }
167
168 /*
169  * The device-mapper can be driven through one of two interfaces;
170  * ioctl or filesystem, depending which patch you have applied.
171  */
172 int dm_interface_init(void);
173 void dm_interface_exit(void);
174
175 /*
176  * Targets for linear and striped mappings
177  */
178 int dm_linear_init(void);
179 void dm_linear_exit(void);
180
181 int dm_stripe_init(void);
182 void dm_stripe_exit(void);
183
184 void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
185
186 #endif