aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlasdair G Kergon <agk@redhat.com>2006-06-26 03:27:33 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-26 12:58:36 -0400
commit17b2f66f2a39a4e4d1ed456f35ee3bb598e41d35 (patch)
tree64801e095918f685fa83bface7f8289e33bb9bcd
parent2b06cfff12f0f87c4bc4d4c4dd76997e72c360ba (diff)
[PATCH] dm: add exports
Move definitions of core device-mapper functions for manipulating mapped devices and their tables to <linux/device-mapper.h> advertising their availability for use elsewhere in the kernel. Protect the contents of device-mapper.h with ifdef __KERNEL__. And throw in a few formatting clean-ups and extra comments. Signed-off-by: Alasdair G Kergon <agk@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/md/dm.c12
-rw-r--r--drivers/md/dm.h75
-rw-r--r--include/linux/device-mapper.h104
3 files changed, 109 insertions, 82 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 59bf797de9a5..952c49c3b9aa 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -50,9 +50,9 @@ struct target_io {
50 50
51union map_info *dm_get_mapinfo(struct bio *bio) 51union map_info *dm_get_mapinfo(struct bio *bio)
52{ 52{
53 if (bio && bio->bi_private) 53 if (bio && bio->bi_private)
54 return &((struct target_io *)bio->bi_private)->info; 54 return &((struct target_io *)bio->bi_private)->info;
55 return NULL; 55 return NULL;
56} 56}
57 57
58#define MINOR_ALLOCED ((void *)-1) 58#define MINOR_ALLOCED ((void *)-1)
@@ -474,8 +474,8 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
474 if (r > 0) { 474 if (r > 0) {
475 /* the bio has been remapped so dispatch it */ 475 /* the bio has been remapped so dispatch it */
476 476
477 blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone, 477 blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone,
478 tio->io->bio->bi_bdev->bd_dev, sector, 478 tio->io->bio->bi_bdev->bd_dev, sector,
479 clone->bi_sector); 479 clone->bi_sector);
480 480
481 generic_make_request(clone); 481 generic_make_request(clone);
@@ -1042,7 +1042,7 @@ static struct mapped_device *dm_find_md(dev_t dev)
1042 md = idr_find(&_minor_idr, minor); 1042 md = idr_find(&_minor_idr, minor);
1043 if (md && (md == MINOR_ALLOCED || 1043 if (md && (md == MINOR_ALLOCED ||
1044 (dm_disk(md)->first_minor != minor) || 1044 (dm_disk(md)->first_minor != minor) ||
1045 test_bit(DMF_FREEING, &md->flags))) { 1045 test_bit(DMF_FREEING, &md->flags))) {
1046 md = NULL; 1046 md = NULL;
1047 goto out; 1047 goto out;
1048 } 1048 }
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 2901ab943191..71ddd1e23007 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -39,88 +39,16 @@ struct dm_dev {
39}; 39};
40 40
41struct dm_table; 41struct dm_table;
42struct mapped_device;
43 42
44/*----------------------------------------------------------------- 43/*-----------------------------------------------------------------
45 * Functions for manipulating a struct mapped_device. 44 * Internal table functions.
46 * Drop the reference with dm_put when you finish with the object.
47 *---------------------------------------------------------------*/ 45 *---------------------------------------------------------------*/
48
49/*
50 * DM_ANY_MINOR allocates any available minor number.
51 */
52#define DM_ANY_MINOR (-1)
53int dm_create(int minor, struct mapped_device **md);
54
55void dm_set_mdptr(struct mapped_device *md, void *ptr);
56void *dm_get_mdptr(struct mapped_device *md);
57
58/*
59 * Reference counting for md.
60 */
61void dm_get(struct mapped_device *md);
62struct mapped_device *dm_get_md(dev_t dev);
63void dm_put(struct mapped_device *md);
64
65/*
66 * A device can still be used while suspended, but I/O is deferred.
67 */
68int dm_suspend(struct mapped_device *md, int with_lockfs);
69int dm_resume(struct mapped_device *md);
70
71/*
72 * The device must be suspended before calling this method.
73 */
74int dm_swap_table(struct mapped_device *md, struct dm_table *t);
75
76/*
77 * Drop a reference on the table when you've finished with the
78 * result.
79 */
80struct dm_table *dm_get_table(struct mapped_device *md);
81
82/*
83 * Event functions.
84 */
85uint32_t dm_get_event_nr(struct mapped_device *md);
86int dm_wait_event(struct mapped_device *md, int event_nr);
87
88/*
89 * Info functions.
90 */
91struct gendisk *dm_disk(struct mapped_device *md);
92int dm_suspended(struct mapped_device *md);
93
94/*
95 * Geometry functions.
96 */
97int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
98int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
99
100/*-----------------------------------------------------------------
101 * Functions for manipulating a table. Tables are also reference
102 * counted.
103 *---------------------------------------------------------------*/
104int dm_table_create(struct dm_table **result, int mode,
105 unsigned num_targets, struct mapped_device *md);
106
107void dm_table_get(struct dm_table *t);
108void dm_table_put(struct dm_table *t);
109
110int dm_table_add_target(struct dm_table *t, const char *type,
111 sector_t start, sector_t len, char *params);
112int dm_table_complete(struct dm_table *t);
113void dm_table_event_callback(struct dm_table *t, 46void dm_table_event_callback(struct dm_table *t,
114 void (*fn)(void *), void *context); 47 void (*fn)(void *), void *context);
115void dm_table_event(struct dm_table *t);
116sector_t dm_table_get_size(struct dm_table *t);
117struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index); 48struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index);
118struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector); 49struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector);
119void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q); 50void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q);
120unsigned int dm_table_get_num_targets(struct dm_table *t);
121struct list_head *dm_table_get_devices(struct dm_table *t); 51struct list_head *dm_table_get_devices(struct dm_table *t);
122int dm_table_get_mode(struct dm_table *t);
123struct mapped_device *dm_table_get_md(struct dm_table *t);
124void dm_table_presuspend_targets(struct dm_table *t); 52void dm_table_presuspend_targets(struct dm_table *t);
125void dm_table_postsuspend_targets(struct dm_table *t); 53void dm_table_postsuspend_targets(struct dm_table *t);
126void dm_table_resume_targets(struct dm_table *t); 54void dm_table_resume_targets(struct dm_table *t);
@@ -138,7 +66,6 @@ void dm_put_target_type(struct target_type *t);
138int dm_target_iterate(void (*iter_func)(struct target_type *tt, 66int dm_target_iterate(void (*iter_func)(struct target_type *tt,
139 void *param), void *param); 67 void *param), void *param);
140 68
141
142/*----------------------------------------------------------------- 69/*-----------------------------------------------------------------
143 * Useful inlines. 70 * Useful inlines.
144 *---------------------------------------------------------------*/ 71 *---------------------------------------------------------------*/
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index aee10b2ea4c6..010c8c5eeb37 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -8,9 +8,12 @@
8#ifndef _LINUX_DEVICE_MAPPER_H 8#ifndef _LINUX_DEVICE_MAPPER_H
9#define _LINUX_DEVICE_MAPPER_H 9#define _LINUX_DEVICE_MAPPER_H
10 10
11#ifdef __KERNEL__
12
11struct dm_target; 13struct dm_target;
12struct dm_table; 14struct dm_table;
13struct dm_dev; 15struct dm_dev;
16struct mapped_device;
14 17
15typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t; 18typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
16 19
@@ -78,7 +81,7 @@ void dm_put_device(struct dm_target *ti, struct dm_dev *d);
78struct target_type { 81struct target_type {
79 const char *name; 82 const char *name;
80 struct module *module; 83 struct module *module;
81 unsigned version[3]; 84 unsigned version[3];
82 dm_ctr_fn ctr; 85 dm_ctr_fn ctr;
83 dm_dtr_fn dtr; 86 dm_dtr_fn dtr;
84 dm_map_fn map; 87 dm_map_fn map;
@@ -128,4 +131,101 @@ struct dm_target {
128int dm_register_target(struct target_type *t); 131int dm_register_target(struct target_type *t);
129int dm_unregister_target(struct target_type *t); 132int dm_unregister_target(struct target_type *t);
130 133
131#endif /* _LINUX_DEVICE_MAPPER_H */ 134
135/*-----------------------------------------------------------------
136 * Functions for creating and manipulating mapped devices.
137 * Drop the reference with dm_put when you finish with the object.
138 *---------------------------------------------------------------*/
139
140/*
141 * DM_ANY_MINOR chooses the next available minor number.
142 */
143#define DM_ANY_MINOR (-1)
144int dm_create(int minor, struct mapped_device **md);
145
146/*
147 * Reference counting for md.
148 */
149struct mapped_device *dm_get_md(dev_t dev);
150void dm_get(struct mapped_device *md);
151void dm_put(struct mapped_device *md);
152
153/*
154 * An arbitrary pointer may be stored alongside a mapped device.
155 */
156void dm_set_mdptr(struct mapped_device *md, void *ptr);
157void *dm_get_mdptr(struct mapped_device *md);
158
159/*
160 * A device can still be used while suspended, but I/O is deferred.
161 */
162int dm_suspend(struct mapped_device *md, int with_lockfs);
163int dm_resume(struct mapped_device *md);
164
165/*
166 * Event functions.
167 */
168uint32_t dm_get_event_nr(struct mapped_device *md);
169int dm_wait_event(struct mapped_device *md, int event_nr);
170
171/*
172 * Info functions.
173 */
174struct gendisk *dm_disk(struct mapped_device *md);
175int dm_suspended(struct mapped_device *md);
176
177/*
178 * Geometry functions.
179 */
180int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
181int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
182
183
184/*-----------------------------------------------------------------
185 * Functions for manipulating device-mapper tables.
186 *---------------------------------------------------------------*/
187
188/*
189 * First create an empty table.
190 */
191int dm_table_create(struct dm_table **result, int mode,
192 unsigned num_targets, struct mapped_device *md);
193
194/*
195 * Then call this once for each target.
196 */
197int dm_table_add_target(struct dm_table *t, const char *type,
198 sector_t start, sector_t len, char *params);
199
200/*
201 * Finally call this to make the table ready for use.
202 */
203int dm_table_complete(struct dm_table *t);
204
205/*
206 * Table reference counting.
207 */
208struct dm_table *dm_get_table(struct mapped_device *md);
209void dm_table_get(struct dm_table *t);
210void dm_table_put(struct dm_table *t);
211
212/*
213 * Queries
214 */
215sector_t dm_table_get_size(struct dm_table *t);
216unsigned int dm_table_get_num_targets(struct dm_table *t);
217int dm_table_get_mode(struct dm_table *t);
218struct mapped_device *dm_table_get_md(struct dm_table *t);
219
220/*
221 * Trigger an event.
222 */
223void dm_table_event(struct dm_table *t);
224
225/*
226 * The device must be suspended before calling this method.
227 */
228int dm_swap_table(struct mapped_device *md, struct dm_table *t);
229
230#endif /* __KERNEL__ */
231#endif /* _LINUX_DEVICE_MAPPER_H */