blob: aee10b2ea4c6855c62d96673371c7eb876e291fa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
11struct dm_target;
12struct dm_table;
13struct dm_dev;
14
15typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
16
17union 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 */
26typedef 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 */
33typedef 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 */
41typedef 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 */
51typedef int (*dm_endio_fn) (struct dm_target *ti,
52 struct bio *bio, int error,
53 union map_info *map_context);
54
55typedef void (*dm_presuspend_fn) (struct dm_target *ti);
56typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
57typedef void (*dm_resume_fn) (struct dm_target *ti);
58
59typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
60 char *result, unsigned int maxlen);
61
62typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
63
64void dm_error(const char *message);
65
66/*
67 * Constructors should call these functions to ensure destination devices
68 * are opened/closed correctly.
69 * FIXME: too many arguments.
70 */
71int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
72 sector_t len, int mode, struct dm_dev **result);
73void dm_put_device(struct dm_target *ti, struct dm_dev *d);
74
75/*
76 * Information about a target type
77 */
78struct target_type {
79 const char *name;
80 struct module *module;
81 unsigned version[3];
82 dm_ctr_fn ctr;
83 dm_dtr_fn dtr;
84 dm_map_fn map;
85 dm_endio_fn end_io;
86 dm_presuspend_fn presuspend;
87 dm_postsuspend_fn postsuspend;
88 dm_resume_fn resume;
89 dm_status_fn status;
90 dm_message_fn message;
91};
92
93struct io_restrictions {
Alasdair G Kergon3ee247e2006-02-01 03:04:55 -080094 unsigned int max_sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 unsigned short max_phys_segments;
96 unsigned short max_hw_segments;
97 unsigned short hardsect_size;
98 unsigned int max_segment_size;
99 unsigned long seg_boundary_mask;
NeilBrown969429b2006-03-27 01:17:49 -0800100 unsigned char no_cluster; /* inverted so that 0 is default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101};
102
103struct dm_target {
104 struct dm_table *table;
105 struct target_type *type;
106
107 /* target limits */
108 sector_t begin;
109 sector_t len;
110
111 /* FIXME: turn this into a mask, and merge with io_restrictions */
112 /* Always a power of 2 */
113 sector_t split_io;
114
115 /*
116 * These are automatically filled in by
117 * dm_table_get_device.
118 */
119 struct io_restrictions limits;
120
121 /* target specific data */
122 void *private;
123
124 /* Used to provide an error string from the ctr */
125 char *error;
126};
127
128int dm_register_target(struct target_type *t);
129int dm_unregister_target(struct target_type *t);
130
131#endif /* _LINUX_DEVICE_MAPPER_H */