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