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