Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Alasdair G Kergon | 17b2f66 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 11 | #ifdef __KERNEL__ |
| 12 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 13 | #include <linux/bio.h> |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | struct dm_target; |
| 16 | struct dm_table; |
| 17 | struct dm_dev; |
Alasdair G Kergon | 17b2f66 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 18 | struct mapped_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t; |
| 21 | |
| 22 | union map_info { |
| 23 | void *ptr; |
| 24 | unsigned long long ll; |
| 25 | }; |
| 26 | |
| 27 | /* |
| 28 | * In the constructor the target parameter will already have the |
| 29 | * table, type, begin and len fields filled in. |
| 30 | */ |
| 31 | typedef int (*dm_ctr_fn) (struct dm_target *target, |
| 32 | unsigned int argc, char **argv); |
| 33 | |
| 34 | /* |
| 35 | * The destructor doesn't need to free the dm_target, just |
| 36 | * anything hidden ti->private. |
| 37 | */ |
| 38 | typedef void (*dm_dtr_fn) (struct dm_target *ti); |
| 39 | |
| 40 | /* |
| 41 | * The map function must return: |
| 42 | * < 0: error |
| 43 | * = 0: The target will handle the io by resubmitting it later |
Kiyoshi Ueda | 45cbcd7 | 2006-12-08 02:41:05 -0800 | [diff] [blame] | 44 | * = 1: simple remap complete |
Kiyoshi Ueda | 2e93ccc | 2006-12-08 02:41:09 -0800 | [diff] [blame] | 45 | * = 2: The target wants to push back the io |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | */ |
| 47 | typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio, |
| 48 | union map_info *map_context); |
| 49 | |
| 50 | /* |
| 51 | * Returns: |
| 52 | * < 0 : error (currently ignored) |
| 53 | * 0 : ended successfully |
| 54 | * 1 : for some reason the io has still not completed (eg, |
| 55 | * multipath target might want to requeue a failed io). |
Kiyoshi Ueda | 2e93ccc | 2006-12-08 02:41:09 -0800 | [diff] [blame] | 56 | * 2 : The target wants to push back the io |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | */ |
| 58 | typedef int (*dm_endio_fn) (struct dm_target *ti, |
| 59 | struct bio *bio, int error, |
| 60 | union map_info *map_context); |
| 61 | |
Bryn Reeves | 999d816 | 2006-10-03 01:15:43 -0700 | [diff] [blame] | 62 | typedef void (*dm_flush_fn) (struct dm_target *ti); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | typedef void (*dm_presuspend_fn) (struct dm_target *ti); |
| 64 | typedef void (*dm_postsuspend_fn) (struct dm_target *ti); |
Milan Broz | 8757b77 | 2006-10-03 01:15:36 -0700 | [diff] [blame] | 65 | typedef int (*dm_preresume_fn) (struct dm_target *ti); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | typedef void (*dm_resume_fn) (struct dm_target *ti); |
| 67 | |
| 68 | typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type, |
| 69 | char *result, unsigned int maxlen); |
| 70 | |
| 71 | typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv); |
| 72 | |
Milan Broz | aa129a2 | 2006-10-03 01:15:15 -0700 | [diff] [blame] | 73 | typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode, |
| 74 | struct file *filp, unsigned int cmd, |
| 75 | unsigned long arg); |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | void dm_error(const char *message); |
| 78 | |
| 79 | /* |
Bryn Reeves | 3cb4021 | 2006-10-03 01:15:42 -0700 | [diff] [blame] | 80 | * Combine device limits. |
| 81 | */ |
| 82 | void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev); |
| 83 | |
| 84 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | * Constructors should call these functions to ensure destination devices |
| 86 | * are opened/closed correctly. |
| 87 | * FIXME: too many arguments. |
| 88 | */ |
| 89 | int dm_get_device(struct dm_target *ti, const char *path, sector_t start, |
| 90 | sector_t len, int mode, struct dm_dev **result); |
| 91 | void dm_put_device(struct dm_target *ti, struct dm_dev *d); |
| 92 | |
| 93 | /* |
| 94 | * Information about a target type |
| 95 | */ |
| 96 | struct target_type { |
| 97 | const char *name; |
| 98 | struct module *module; |
Alasdair G Kergon | 17b2f66 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 99 | unsigned version[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | dm_ctr_fn ctr; |
| 101 | dm_dtr_fn dtr; |
| 102 | dm_map_fn map; |
| 103 | dm_endio_fn end_io; |
Bryn Reeves | 999d816 | 2006-10-03 01:15:43 -0700 | [diff] [blame] | 104 | dm_flush_fn flush; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | dm_presuspend_fn presuspend; |
| 106 | dm_postsuspend_fn postsuspend; |
Milan Broz | 8757b77 | 2006-10-03 01:15:36 -0700 | [diff] [blame] | 107 | dm_preresume_fn preresume; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | dm_resume_fn resume; |
| 109 | dm_status_fn status; |
| 110 | dm_message_fn message; |
Milan Broz | aa129a2 | 2006-10-03 01:15:15 -0700 | [diff] [blame] | 111 | dm_ioctl_fn ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | struct io_restrictions { |
Vasily Averin | 4f41b09 | 2008-02-08 02:10:01 +0000 | [diff] [blame] | 115 | unsigned long bounce_pfn; |
| 116 | unsigned long seg_boundary_mask; |
| 117 | unsigned max_hw_sectors; |
| 118 | unsigned max_sectors; |
| 119 | unsigned max_segment_size; |
| 120 | unsigned short hardsect_size; |
| 121 | unsigned short max_hw_segments; |
| 122 | unsigned short max_phys_segments; |
| 123 | unsigned char no_cluster; /* inverted so that 0 is default */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | struct dm_target { |
| 127 | struct dm_table *table; |
| 128 | struct target_type *type; |
| 129 | |
| 130 | /* target limits */ |
| 131 | sector_t begin; |
| 132 | sector_t len; |
| 133 | |
| 134 | /* FIXME: turn this into a mask, and merge with io_restrictions */ |
| 135 | /* Always a power of 2 */ |
| 136 | sector_t split_io; |
| 137 | |
| 138 | /* |
| 139 | * These are automatically filled in by |
| 140 | * dm_table_get_device. |
| 141 | */ |
| 142 | struct io_restrictions limits; |
| 143 | |
| 144 | /* target specific data */ |
| 145 | void *private; |
| 146 | |
| 147 | /* Used to provide an error string from the ctr */ |
| 148 | char *error; |
| 149 | }; |
| 150 | |
| 151 | int dm_register_target(struct target_type *t); |
| 152 | int dm_unregister_target(struct target_type *t); |
| 153 | |
Alasdair G Kergon | 17b2f66 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 154 | |
| 155 | /*----------------------------------------------------------------- |
| 156 | * Functions for creating and manipulating mapped devices. |
| 157 | * Drop the reference with dm_put when you finish with the object. |
| 158 | *---------------------------------------------------------------*/ |
| 159 | |
| 160 | /* |
| 161 | * DM_ANY_MINOR chooses the next available minor number. |
| 162 | */ |
| 163 | #define DM_ANY_MINOR (-1) |
| 164 | int dm_create(int minor, struct mapped_device **md); |
| 165 | |
| 166 | /* |
| 167 | * Reference counting for md. |
| 168 | */ |
| 169 | struct mapped_device *dm_get_md(dev_t dev); |
| 170 | void dm_get(struct mapped_device *md); |
| 171 | void dm_put(struct mapped_device *md); |
| 172 | |
| 173 | /* |
| 174 | * An arbitrary pointer may be stored alongside a mapped device. |
| 175 | */ |
| 176 | void dm_set_mdptr(struct mapped_device *md, void *ptr); |
| 177 | void *dm_get_mdptr(struct mapped_device *md); |
| 178 | |
| 179 | /* |
| 180 | * A device can still be used while suspended, but I/O is deferred. |
| 181 | */ |
Kiyoshi Ueda | a3d77d3 | 2006-12-08 02:41:04 -0800 | [diff] [blame] | 182 | int dm_suspend(struct mapped_device *md, unsigned suspend_flags); |
Alasdair G Kergon | 17b2f66 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 183 | int dm_resume(struct mapped_device *md); |
| 184 | |
| 185 | /* |
| 186 | * Event functions. |
| 187 | */ |
| 188 | uint32_t dm_get_event_nr(struct mapped_device *md); |
| 189 | int dm_wait_event(struct mapped_device *md, int event_nr); |
Mike Anderson | 7a8c3d3 | 2007-10-19 22:48:01 +0100 | [diff] [blame] | 190 | uint32_t dm_next_uevent_seq(struct mapped_device *md); |
| 191 | void dm_uevent_add(struct mapped_device *md, struct list_head *elist); |
Alasdair G Kergon | 17b2f66 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * Info functions. |
| 195 | */ |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 196 | const char *dm_device_name(struct mapped_device *md); |
Mike Anderson | 96a1f7d | 2007-10-19 22:47:59 +0100 | [diff] [blame] | 197 | int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid); |
Alasdair G Kergon | 17b2f66 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 198 | struct gendisk *dm_disk(struct mapped_device *md); |
| 199 | int dm_suspended(struct mapped_device *md); |
Kiyoshi Ueda | 2e93ccc | 2006-12-08 02:41:09 -0800 | [diff] [blame] | 200 | int dm_noflush_suspending(struct dm_target *ti); |
Alasdair G Kergon | 17b2f66 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 201 | |
| 202 | /* |
| 203 | * Geometry functions. |
| 204 | */ |
| 205 | int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo); |
| 206 | int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo); |
| 207 | |
| 208 | |
| 209 | /*----------------------------------------------------------------- |
| 210 | * Functions for manipulating device-mapper tables. |
| 211 | *---------------------------------------------------------------*/ |
| 212 | |
| 213 | /* |
| 214 | * First create an empty table. |
| 215 | */ |
| 216 | int dm_table_create(struct dm_table **result, int mode, |
| 217 | unsigned num_targets, struct mapped_device *md); |
| 218 | |
| 219 | /* |
| 220 | * Then call this once for each target. |
| 221 | */ |
| 222 | int dm_table_add_target(struct dm_table *t, const char *type, |
| 223 | sector_t start, sector_t len, char *params); |
| 224 | |
| 225 | /* |
| 226 | * Finally call this to make the table ready for use. |
| 227 | */ |
| 228 | int dm_table_complete(struct dm_table *t); |
| 229 | |
| 230 | /* |
| 231 | * Table reference counting. |
| 232 | */ |
| 233 | struct dm_table *dm_get_table(struct mapped_device *md); |
| 234 | void dm_table_get(struct dm_table *t); |
| 235 | void dm_table_put(struct dm_table *t); |
| 236 | |
| 237 | /* |
| 238 | * Queries |
| 239 | */ |
| 240 | sector_t dm_table_get_size(struct dm_table *t); |
| 241 | unsigned int dm_table_get_num_targets(struct dm_table *t); |
| 242 | int dm_table_get_mode(struct dm_table *t); |
| 243 | struct mapped_device *dm_table_get_md(struct dm_table *t); |
| 244 | |
| 245 | /* |
| 246 | * Trigger an event. |
| 247 | */ |
| 248 | void dm_table_event(struct dm_table *t); |
| 249 | |
| 250 | /* |
| 251 | * The device must be suspended before calling this method. |
| 252 | */ |
| 253 | int dm_swap_table(struct mapped_device *md, struct dm_table *t); |
| 254 | |
David Teigland | c2ade42 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 255 | /* |
| 256 | * Prepare a table for a device that will error all I/O. |
| 257 | * To make it active, call dm_suspend(), dm_swap_table() then dm_resume(). |
| 258 | */ |
| 259 | int dm_create_error_table(struct dm_table **result, struct mapped_device *md); |
| 260 | |
Alasdair G Kergon | 17b2f66 | 2006-06-26 00:27:33 -0700 | [diff] [blame] | 261 | #endif /* __KERNEL__ */ |
| 262 | #endif /* _LINUX_DEVICE_MAPPER_H */ |