Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] dm: create error table

Add a library function dm_create_error_table() to create a table that rejects
any I/O sent to a device with EIO.

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>

authored by

David Teigland and committed by
Linus Torvalds
c2ade42d 17b2f66f

+44
+38
drivers/md/dm-table.c
··· 237 237 return 0; 238 238 } 239 239 240 + int dm_create_error_table(struct dm_table **result, struct mapped_device *md) 241 + { 242 + struct dm_table *t; 243 + sector_t dev_size = 1; 244 + int r; 245 + 246 + /* 247 + * Find current size of device. 248 + * Default to 1 sector if inactive. 249 + */ 250 + t = dm_get_table(md); 251 + if (t) { 252 + dev_size = dm_table_get_size(t); 253 + dm_table_put(t); 254 + } 255 + 256 + r = dm_table_create(&t, FMODE_READ, 1, md); 257 + if (r) 258 + return r; 259 + 260 + r = dm_table_add_target(t, "error", 0, dev_size, NULL); 261 + if (r) 262 + goto out; 263 + 264 + r = dm_table_complete(t); 265 + if (r) 266 + goto out; 267 + 268 + *result = t; 269 + 270 + out: 271 + if (r) 272 + dm_table_put(t); 273 + 274 + return r; 275 + } 276 + EXPORT_SYMBOL_GPL(dm_create_error_table); 277 + 240 278 static void free_devices(struct list_head *devices) 241 279 { 242 280 struct list_head *tmp, *next;
+6
include/linux/device-mapper.h
··· 227 227 */ 228 228 int dm_swap_table(struct mapped_device *md, struct dm_table *t); 229 229 230 + /* 231 + * Prepare a table for a device that will error all I/O. 232 + * To make it active, call dm_suspend(), dm_swap_table() then dm_resume(). 233 + */ 234 + int dm_create_error_table(struct dm_table **result, struct mapped_device *md); 235 + 230 236 #endif /* __KERNEL__ */ 231 237 #endif /* _LINUX_DEVICE_MAPPER_H */