ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / linux / device-mapper.h
1 /*
2  * Copyright (C) 2001 Sistina Software (UK) Limited.
3  *
4  * This file is released under the LGPL.
5  */
6
7 #ifndef _LINUX_DEVICE_MAPPER_H
8 #define _LINUX_DEVICE_MAPPER_H
9
10 struct dm_target;
11 struct dm_table;
12 struct dm_dev;
13
14 typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
15
16 union map_info {
17         void *ptr;
18         unsigned long long ll;
19 };
20
21 /*
22  * In the constructor the target parameter will already have the
23  * table, type, begin and len fields filled in.
24  */
25 typedef int (*dm_ctr_fn) (struct dm_target *target,
26                           unsigned int argc, char **argv);
27
28 /*
29  * The destructor doesn't need to free the dm_target, just
30  * anything hidden ti->private.
31  */
32 typedef void (*dm_dtr_fn) (struct dm_target *ti);
33
34 /*
35  * The map function must return:
36  * < 0: error
37  * = 0: The target will handle the io by resubmitting it later
38  * > 0: simple remap complete
39  */
40 typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
41                           union map_info *map_context);
42
43 /*
44  * Returns:
45  * < 0 : error (currently ignored)
46  * 0   : ended successfully
47  * 1   : for some reason the io has still not completed (eg,
48  *       multipath target might want to requeue a failed io).
49  */
50 typedef int (*dm_endio_fn) (struct dm_target *ti,
51                             struct bio *bio, int error,
52                             union map_info *map_context);
53
54 typedef void (*dm_suspend_fn) (struct dm_target *ti);
55 typedef void (*dm_resume_fn) (struct dm_target *ti);
56
57 typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
58                              char *result, unsigned int maxlen);
59
60 void dm_error(const char *message);
61
62 /*
63  * Constructors should call these functions to ensure destination devices
64  * are opened/closed correctly.
65  * FIXME: too many arguments.
66  */
67 int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
68                   sector_t len, int mode, struct dm_dev **result);
69 void dm_put_device(struct dm_target *ti, struct dm_dev *d);
70
71 /*
72  * Information about a target type
73  */
74 struct target_type {
75         const char *name;
76         struct module *module;
77         unsigned version[3];
78         dm_ctr_fn ctr;
79         dm_dtr_fn dtr;
80         dm_map_fn map;
81         dm_endio_fn end_io;
82         dm_suspend_fn suspend;
83         dm_resume_fn resume;
84         dm_status_fn status;
85 };
86
87 struct io_restrictions {
88         unsigned short          max_sectors;
89         unsigned short          max_phys_segments;
90         unsigned short          max_hw_segments;
91         unsigned short          hardsect_size;
92         unsigned int            max_segment_size;
93         unsigned long           seg_boundary_mask;
94 };
95
96 struct dm_target {
97         struct dm_table *table;
98         struct target_type *type;
99
100         /* target limits */
101         sector_t begin;
102         sector_t len;
103
104         /* FIXME: turn this into a mask, and merge with io_restrictions */
105         sector_t split_io;
106
107         /*
108          * These are automatically filled in by
109          * dm_table_get_device.
110          */
111         struct io_restrictions limits;
112
113         /* target specific data */
114         void *private;
115
116         /* Used to provide an error string from the ctr */
117         char *error;
118 };
119
120 int dm_register_target(struct target_type *t);
121 int dm_unregister_target(struct target_type *t);
122
123 #endif                          /* _LINUX_DEVICE_MAPPER_H */