11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (C) 2001 Sistina Software (UK) Limited. 30da336e5SAlasdair G Kergon * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * This file is released under the LGPL. 61da177e4SLinus Torvalds */ 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds #ifndef _LINUX_DEVICE_MAPPER_H 91da177e4SLinus Torvalds #define _LINUX_DEVICE_MAPPER_H 101da177e4SLinus Torvalds 11416cd17bSHeinz Mauelshagen #include <linux/bio.h> 12f6fccb12SMilan Broz #include <linux/blkdev.h> 13416cd17bSHeinz Mauelshagen 14af4874e0SMike Snitzer struct dm_dev; 151da177e4SLinus Torvalds struct dm_target; 161da177e4SLinus Torvalds struct dm_table; 1717b2f66fSAlasdair G Kergon struct mapped_device; 18f6fccb12SMilan Broz struct bio_vec; 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t; 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds union map_info { 231da177e4SLinus Torvalds void *ptr; 241da177e4SLinus Torvalds unsigned long long ll; 25f9ab94ceSMikulas Patocka unsigned flush_request; 261da177e4SLinus Torvalds }; 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds /* 291da177e4SLinus Torvalds * In the constructor the target parameter will already have the 301da177e4SLinus Torvalds * table, type, begin and len fields filled in. 311da177e4SLinus Torvalds */ 321da177e4SLinus Torvalds typedef int (*dm_ctr_fn) (struct dm_target *target, 331da177e4SLinus Torvalds unsigned int argc, char **argv); 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds /* 361da177e4SLinus Torvalds * The destructor doesn't need to free the dm_target, just 371da177e4SLinus Torvalds * anything hidden ti->private. 381da177e4SLinus Torvalds */ 391da177e4SLinus Torvalds typedef void (*dm_dtr_fn) (struct dm_target *ti); 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds /* 421da177e4SLinus Torvalds * The map function must return: 431da177e4SLinus Torvalds * < 0: error 441da177e4SLinus Torvalds * = 0: The target will handle the io by resubmitting it later 4545cbcd79SKiyoshi Ueda * = 1: simple remap complete 462e93ccc1SKiyoshi Ueda * = 2: The target wants to push back the io 471da177e4SLinus Torvalds */ 481da177e4SLinus Torvalds typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio, 491da177e4SLinus Torvalds union map_info *map_context); 507d76345dSKiyoshi Ueda typedef int (*dm_map_request_fn) (struct dm_target *ti, struct request *clone, 517d76345dSKiyoshi Ueda union map_info *map_context); 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds /* 541da177e4SLinus Torvalds * Returns: 551da177e4SLinus Torvalds * < 0 : error (currently ignored) 561da177e4SLinus Torvalds * 0 : ended successfully 571da177e4SLinus Torvalds * 1 : for some reason the io has still not completed (eg, 581da177e4SLinus Torvalds * multipath target might want to requeue a failed io). 592e93ccc1SKiyoshi Ueda * 2 : The target wants to push back the io 601da177e4SLinus Torvalds */ 611da177e4SLinus Torvalds typedef int (*dm_endio_fn) (struct dm_target *ti, 621da177e4SLinus Torvalds struct bio *bio, int error, 631da177e4SLinus Torvalds union map_info *map_context); 647d76345dSKiyoshi Ueda typedef int (*dm_request_endio_fn) (struct dm_target *ti, 657d76345dSKiyoshi Ueda struct request *clone, int error, 667d76345dSKiyoshi Ueda union map_info *map_context); 671da177e4SLinus Torvalds 68999d8168SBryn Reeves typedef void (*dm_flush_fn) (struct dm_target *ti); 691da177e4SLinus Torvalds typedef void (*dm_presuspend_fn) (struct dm_target *ti); 701da177e4SLinus Torvalds typedef void (*dm_postsuspend_fn) (struct dm_target *ti); 718757b776SMilan Broz typedef int (*dm_preresume_fn) (struct dm_target *ti); 721da177e4SLinus Torvalds typedef void (*dm_resume_fn) (struct dm_target *ti); 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type, 751da177e4SLinus Torvalds char *result, unsigned int maxlen); 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv); 781da177e4SLinus Torvalds 79647b3d00SAl Viro typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd, 80aa129a22SMilan Broz unsigned long arg); 81aa129a22SMilan Broz 82f6fccb12SMilan Broz typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm, 83f6fccb12SMilan Broz struct bio_vec *biovec, int max_size); 84f6fccb12SMilan Broz 85af4874e0SMike Snitzer typedef int (*iterate_devices_callout_fn) (struct dm_target *ti, 86af4874e0SMike Snitzer struct dm_dev *dev, 87af4874e0SMike Snitzer sector_t physical_start, 88af4874e0SMike Snitzer void *data); 89af4874e0SMike Snitzer 90af4874e0SMike Snitzer typedef int (*dm_iterate_devices_fn) (struct dm_target *ti, 91af4874e0SMike Snitzer iterate_devices_callout_fn fn, 92af4874e0SMike Snitzer void *data); 93af4874e0SMike Snitzer 947d76345dSKiyoshi Ueda /* 957d76345dSKiyoshi Ueda * Returns: 967d76345dSKiyoshi Ueda * 0: The target can handle the next I/O immediately. 977d76345dSKiyoshi Ueda * 1: The target can't handle the next I/O immediately. 987d76345dSKiyoshi Ueda */ 997d76345dSKiyoshi Ueda typedef int (*dm_busy_fn) (struct dm_target *ti); 1007d76345dSKiyoshi Ueda 1011da177e4SLinus Torvalds void dm_error(const char *message); 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds /* 1043cb40214SBryn Reeves * Combine device limits. 1053cb40214SBryn Reeves */ 106754c5fc7SMike Snitzer int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev, 107754c5fc7SMike Snitzer sector_t start, void *data); 1083cb40214SBryn Reeves 10982b1519bSMikulas Patocka struct dm_dev { 11082b1519bSMikulas Patocka struct block_device *bdev; 111aeb5d727SAl Viro fmode_t mode; 11282b1519bSMikulas Patocka char name[16]; 11382b1519bSMikulas Patocka }; 11482b1519bSMikulas Patocka 1153cb40214SBryn Reeves /* 1161da177e4SLinus Torvalds * Constructors should call these functions to ensure destination devices 1171da177e4SLinus Torvalds * are opened/closed correctly. 1181da177e4SLinus Torvalds * FIXME: too many arguments. 1191da177e4SLinus Torvalds */ 1201da177e4SLinus Torvalds int dm_get_device(struct dm_target *ti, const char *path, sector_t start, 121aeb5d727SAl Viro sector_t len, fmode_t mode, struct dm_dev **result); 1221da177e4SLinus Torvalds void dm_put_device(struct dm_target *ti, struct dm_dev *d); 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds /* 1251da177e4SLinus Torvalds * Information about a target type 1261da177e4SLinus Torvalds */ 127ab4c1424SAndi Kleen 128ab4c1424SAndi Kleen /* 129ab4c1424SAndi Kleen * Target features 130ab4c1424SAndi Kleen */ 131ab4c1424SAndi Kleen 1321da177e4SLinus Torvalds struct target_type { 133ab4c1424SAndi Kleen uint64_t features; 1341da177e4SLinus Torvalds const char *name; 1351da177e4SLinus Torvalds struct module *module; 1361da177e4SLinus Torvalds unsigned version[3]; 1371da177e4SLinus Torvalds dm_ctr_fn ctr; 1381da177e4SLinus Torvalds dm_dtr_fn dtr; 1391da177e4SLinus Torvalds dm_map_fn map; 1407d76345dSKiyoshi Ueda dm_map_request_fn map_rq; 1411da177e4SLinus Torvalds dm_endio_fn end_io; 1427d76345dSKiyoshi Ueda dm_request_endio_fn rq_end_io; 143999d8168SBryn Reeves dm_flush_fn flush; 1441da177e4SLinus Torvalds dm_presuspend_fn presuspend; 1451da177e4SLinus Torvalds dm_postsuspend_fn postsuspend; 1468757b776SMilan Broz dm_preresume_fn preresume; 1471da177e4SLinus Torvalds dm_resume_fn resume; 1481da177e4SLinus Torvalds dm_status_fn status; 1491da177e4SLinus Torvalds dm_message_fn message; 150aa129a22SMilan Broz dm_ioctl_fn ioctl; 151f6fccb12SMilan Broz dm_merge_fn merge; 1527d76345dSKiyoshi Ueda dm_busy_fn busy; 153af4874e0SMike Snitzer dm_iterate_devices_fn iterate_devices; 15445194e4fSCheng Renquan 15545194e4fSCheng Renquan /* For internal device-mapper use. */ 15645194e4fSCheng Renquan struct list_head list; 1571da177e4SLinus Torvalds }; 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds struct dm_target { 1601da177e4SLinus Torvalds struct dm_table *table; 1611da177e4SLinus Torvalds struct target_type *type; 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds /* target limits */ 1641da177e4SLinus Torvalds sector_t begin; 1651da177e4SLinus Torvalds sector_t len; 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds /* Always a power of 2 */ 1681da177e4SLinus Torvalds sector_t split_io; 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds /* 171f9ab94ceSMikulas Patocka * A number of zero-length barrier requests that will be submitted 172f9ab94ceSMikulas Patocka * to the target for the purpose of flushing cache. 173f9ab94ceSMikulas Patocka * 174f9ab94ceSMikulas Patocka * The request number will be placed in union map_info->flush_request. 175f9ab94ceSMikulas Patocka * It is a responsibility of the target driver to remap these requests 176f9ab94ceSMikulas Patocka * to the real underlying devices. 177f9ab94ceSMikulas Patocka */ 178f9ab94ceSMikulas Patocka unsigned num_flush_requests; 179f9ab94ceSMikulas Patocka 1801da177e4SLinus Torvalds /* target specific data */ 1811da177e4SLinus Torvalds void *private; 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds /* Used to provide an error string from the ctr */ 1841da177e4SLinus Torvalds char *error; 1851da177e4SLinus Torvalds }; 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds int dm_register_target(struct target_type *t); 18810d3bd09SMikulas Patocka void dm_unregister_target(struct target_type *t); 18917b2f66fSAlasdair G Kergon 19017b2f66fSAlasdair G Kergon /*----------------------------------------------------------------- 19117b2f66fSAlasdair G Kergon * Functions for creating and manipulating mapped devices. 19217b2f66fSAlasdair G Kergon * Drop the reference with dm_put when you finish with the object. 19317b2f66fSAlasdair G Kergon *---------------------------------------------------------------*/ 19417b2f66fSAlasdair G Kergon 19517b2f66fSAlasdair G Kergon /* 19617b2f66fSAlasdair G Kergon * DM_ANY_MINOR chooses the next available minor number. 19717b2f66fSAlasdair G Kergon */ 19817b2f66fSAlasdair G Kergon #define DM_ANY_MINOR (-1) 19917b2f66fSAlasdair G Kergon int dm_create(int minor, struct mapped_device **md); 20017b2f66fSAlasdair G Kergon 20117b2f66fSAlasdair G Kergon /* 20217b2f66fSAlasdair G Kergon * Reference counting for md. 20317b2f66fSAlasdair G Kergon */ 20417b2f66fSAlasdair G Kergon struct mapped_device *dm_get_md(dev_t dev); 20517b2f66fSAlasdair G Kergon void dm_get(struct mapped_device *md); 20617b2f66fSAlasdair G Kergon void dm_put(struct mapped_device *md); 20717b2f66fSAlasdair G Kergon 20817b2f66fSAlasdair G Kergon /* 20917b2f66fSAlasdair G Kergon * An arbitrary pointer may be stored alongside a mapped device. 21017b2f66fSAlasdair G Kergon */ 21117b2f66fSAlasdair G Kergon void dm_set_mdptr(struct mapped_device *md, void *ptr); 21217b2f66fSAlasdair G Kergon void *dm_get_mdptr(struct mapped_device *md); 21317b2f66fSAlasdair G Kergon 21417b2f66fSAlasdair G Kergon /* 21517b2f66fSAlasdair G Kergon * A device can still be used while suspended, but I/O is deferred. 21617b2f66fSAlasdair G Kergon */ 217a3d77d35SKiyoshi Ueda int dm_suspend(struct mapped_device *md, unsigned suspend_flags); 21817b2f66fSAlasdair G Kergon int dm_resume(struct mapped_device *md); 21917b2f66fSAlasdair G Kergon 22017b2f66fSAlasdair G Kergon /* 22117b2f66fSAlasdair G Kergon * Event functions. 22217b2f66fSAlasdair G Kergon */ 22317b2f66fSAlasdair G Kergon uint32_t dm_get_event_nr(struct mapped_device *md); 22417b2f66fSAlasdair G Kergon int dm_wait_event(struct mapped_device *md, int event_nr); 2257a8c3d3bSMike Anderson uint32_t dm_next_uevent_seq(struct mapped_device *md); 2267a8c3d3bSMike Anderson void dm_uevent_add(struct mapped_device *md, struct list_head *elist); 22717b2f66fSAlasdair G Kergon 22817b2f66fSAlasdair G Kergon /* 22917b2f66fSAlasdair G Kergon * Info functions. 23017b2f66fSAlasdair G Kergon */ 23172d94861SAlasdair G Kergon const char *dm_device_name(struct mapped_device *md); 23296a1f7dbSMike Anderson int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid); 23317b2f66fSAlasdair G Kergon struct gendisk *dm_disk(struct mapped_device *md); 23417b2f66fSAlasdair G Kergon int dm_suspended(struct mapped_device *md); 2352e93ccc1SKiyoshi Ueda int dm_noflush_suspending(struct dm_target *ti); 23689343da0SMikulas Patocka union map_info *dm_get_mapinfo(struct bio *bio); 237*cec47e3dSKiyoshi Ueda union map_info *dm_get_rq_mapinfo(struct request *rq); 23817b2f66fSAlasdair G Kergon 23917b2f66fSAlasdair G Kergon /* 24017b2f66fSAlasdair G Kergon * Geometry functions. 24117b2f66fSAlasdair G Kergon */ 24217b2f66fSAlasdair G Kergon int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo); 24317b2f66fSAlasdair G Kergon int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo); 24417b2f66fSAlasdair G Kergon 24517b2f66fSAlasdair G Kergon 24617b2f66fSAlasdair G Kergon /*----------------------------------------------------------------- 24717b2f66fSAlasdair G Kergon * Functions for manipulating device-mapper tables. 24817b2f66fSAlasdair G Kergon *---------------------------------------------------------------*/ 24917b2f66fSAlasdair G Kergon 25017b2f66fSAlasdair G Kergon /* 25117b2f66fSAlasdair G Kergon * First create an empty table. 25217b2f66fSAlasdair G Kergon */ 253aeb5d727SAl Viro int dm_table_create(struct dm_table **result, fmode_t mode, 25417b2f66fSAlasdair G Kergon unsigned num_targets, struct mapped_device *md); 25517b2f66fSAlasdair G Kergon 25617b2f66fSAlasdair G Kergon /* 25717b2f66fSAlasdair G Kergon * Then call this once for each target. 25817b2f66fSAlasdair G Kergon */ 25917b2f66fSAlasdair G Kergon int dm_table_add_target(struct dm_table *t, const char *type, 26017b2f66fSAlasdair G Kergon sector_t start, sector_t len, char *params); 26117b2f66fSAlasdair G Kergon 26217b2f66fSAlasdair G Kergon /* 26317b2f66fSAlasdair G Kergon * Finally call this to make the table ready for use. 26417b2f66fSAlasdair G Kergon */ 26517b2f66fSAlasdair G Kergon int dm_table_complete(struct dm_table *t); 26617b2f66fSAlasdair G Kergon 26717b2f66fSAlasdair G Kergon /* 268ea0ec640SMikulas Patocka * Unplug all devices in a table. 269ea0ec640SMikulas Patocka */ 270ea0ec640SMikulas Patocka void dm_table_unplug_all(struct dm_table *t); 271ea0ec640SMikulas Patocka 272ea0ec640SMikulas Patocka /* 27317b2f66fSAlasdair G Kergon * Table reference counting. 27417b2f66fSAlasdair G Kergon */ 27517b2f66fSAlasdair G Kergon struct dm_table *dm_get_table(struct mapped_device *md); 27617b2f66fSAlasdair G Kergon void dm_table_get(struct dm_table *t); 27717b2f66fSAlasdair G Kergon void dm_table_put(struct dm_table *t); 27817b2f66fSAlasdair G Kergon 27917b2f66fSAlasdair G Kergon /* 28017b2f66fSAlasdair G Kergon * Queries 28117b2f66fSAlasdair G Kergon */ 28217b2f66fSAlasdair G Kergon sector_t dm_table_get_size(struct dm_table *t); 28317b2f66fSAlasdair G Kergon unsigned int dm_table_get_num_targets(struct dm_table *t); 284aeb5d727SAl Viro fmode_t dm_table_get_mode(struct dm_table *t); 28517b2f66fSAlasdair G Kergon struct mapped_device *dm_table_get_md(struct dm_table *t); 28617b2f66fSAlasdair G Kergon 28717b2f66fSAlasdair G Kergon /* 28817b2f66fSAlasdair G Kergon * Trigger an event. 28917b2f66fSAlasdair G Kergon */ 29017b2f66fSAlasdair G Kergon void dm_table_event(struct dm_table *t); 29117b2f66fSAlasdair G Kergon 29217b2f66fSAlasdair G Kergon /* 29317b2f66fSAlasdair G Kergon * The device must be suspended before calling this method. 29417b2f66fSAlasdair G Kergon */ 29517b2f66fSAlasdair G Kergon int dm_swap_table(struct mapped_device *md, struct dm_table *t); 29617b2f66fSAlasdair G Kergon 29754160904SMikulas Patocka /* 29854160904SMikulas Patocka * A wrapper around vmalloc. 29954160904SMikulas Patocka */ 30054160904SMikulas Patocka void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size); 30154160904SMikulas Patocka 3020da336e5SAlasdair G Kergon /*----------------------------------------------------------------- 3030da336e5SAlasdair G Kergon * Macros. 3040da336e5SAlasdair G Kergon *---------------------------------------------------------------*/ 3050da336e5SAlasdair G Kergon #define DM_NAME "device-mapper" 3060da336e5SAlasdair G Kergon 30710d3bd09SMikulas Patocka #define DMCRIT(f, arg...) \ 30810d3bd09SMikulas Patocka printk(KERN_CRIT DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 30910d3bd09SMikulas Patocka 3100da336e5SAlasdair G Kergon #define DMERR(f, arg...) \ 3110da336e5SAlasdair G Kergon printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 3120da336e5SAlasdair G Kergon #define DMERR_LIMIT(f, arg...) \ 3130da336e5SAlasdair G Kergon do { \ 3140da336e5SAlasdair G Kergon if (printk_ratelimit()) \ 3150da336e5SAlasdair G Kergon printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \ 3160da336e5SAlasdair G Kergon f "\n", ## arg); \ 3170da336e5SAlasdair G Kergon } while (0) 3180da336e5SAlasdair G Kergon 3190da336e5SAlasdair G Kergon #define DMWARN(f, arg...) \ 3200da336e5SAlasdair G Kergon printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 3210da336e5SAlasdair G Kergon #define DMWARN_LIMIT(f, arg...) \ 3220da336e5SAlasdair G Kergon do { \ 3230da336e5SAlasdair G Kergon if (printk_ratelimit()) \ 3240da336e5SAlasdair G Kergon printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \ 3250da336e5SAlasdair G Kergon f "\n", ## arg); \ 3260da336e5SAlasdair G Kergon } while (0) 3270da336e5SAlasdair G Kergon 3280da336e5SAlasdair G Kergon #define DMINFO(f, arg...) \ 3290da336e5SAlasdair G Kergon printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 3300da336e5SAlasdair G Kergon #define DMINFO_LIMIT(f, arg...) \ 3310da336e5SAlasdair G Kergon do { \ 3320da336e5SAlasdair G Kergon if (printk_ratelimit()) \ 3330da336e5SAlasdair G Kergon printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \ 3340da336e5SAlasdair G Kergon "\n", ## arg); \ 3350da336e5SAlasdair G Kergon } while (0) 3360da336e5SAlasdair G Kergon 3370da336e5SAlasdair G Kergon #ifdef CONFIG_DM_DEBUG 3380da336e5SAlasdair G Kergon # define DMDEBUG(f, arg...) \ 3390da336e5SAlasdair G Kergon printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg) 3400da336e5SAlasdair G Kergon # define DMDEBUG_LIMIT(f, arg...) \ 3410da336e5SAlasdair G Kergon do { \ 3420da336e5SAlasdair G Kergon if (printk_ratelimit()) \ 3430da336e5SAlasdair G Kergon printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \ 3440da336e5SAlasdair G Kergon "\n", ## arg); \ 3450da336e5SAlasdair G Kergon } while (0) 3460da336e5SAlasdair G Kergon #else 3470da336e5SAlasdair G Kergon # define DMDEBUG(f, arg...) do {} while (0) 3480da336e5SAlasdair G Kergon # define DMDEBUG_LIMIT(f, arg...) do {} while (0) 3490da336e5SAlasdair G Kergon #endif 3500da336e5SAlasdair G Kergon 3510da336e5SAlasdair G Kergon #define DMEMIT(x...) sz += ((sz >= maxlen) ? \ 3520da336e5SAlasdair G Kergon 0 : scnprintf(result + sz, maxlen - sz, x)) 3530da336e5SAlasdair G Kergon 3540da336e5SAlasdair G Kergon #define SECTOR_SHIFT 9 3550da336e5SAlasdair G Kergon 3560da336e5SAlasdair G Kergon /* 3570da336e5SAlasdair G Kergon * Definitions of return values from target end_io function. 3580da336e5SAlasdair G Kergon */ 3590da336e5SAlasdair G Kergon #define DM_ENDIO_INCOMPLETE 1 3600da336e5SAlasdair G Kergon #define DM_ENDIO_REQUEUE 2 3610da336e5SAlasdair G Kergon 3620da336e5SAlasdair G Kergon /* 3630da336e5SAlasdair G Kergon * Definitions of return values from target map function. 3640da336e5SAlasdair G Kergon */ 3650da336e5SAlasdair G Kergon #define DM_MAPIO_SUBMITTED 0 3660da336e5SAlasdair G Kergon #define DM_MAPIO_REMAPPED 1 3670da336e5SAlasdair G Kergon #define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE 3680da336e5SAlasdair G Kergon 3690da336e5SAlasdair G Kergon /* 3700da336e5SAlasdair G Kergon * Ceiling(n / sz) 3710da336e5SAlasdair G Kergon */ 3720da336e5SAlasdair G Kergon #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz)) 3730da336e5SAlasdair G Kergon 3740da336e5SAlasdair G Kergon #define dm_sector_div_up(n, sz) ( \ 3750da336e5SAlasdair G Kergon { \ 3760da336e5SAlasdair G Kergon sector_t _r = ((n) + (sz) - 1); \ 3770da336e5SAlasdair G Kergon sector_div(_r, (sz)); \ 3780da336e5SAlasdair G Kergon _r; \ 3790da336e5SAlasdair G Kergon } \ 3800da336e5SAlasdair G Kergon ) 3810da336e5SAlasdair G Kergon 3820da336e5SAlasdair G Kergon /* 3830da336e5SAlasdair G Kergon * ceiling(n / size) * size 3840da336e5SAlasdair G Kergon */ 3850da336e5SAlasdair G Kergon #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz)) 3860da336e5SAlasdair G Kergon 387d63a5ce3SMikulas Patocka #define dm_array_too_big(fixed, obj, num) \ 388d63a5ce3SMikulas Patocka ((num) > (UINT_MAX - (fixed)) / (obj)) 389d63a5ce3SMikulas Patocka 3900da336e5SAlasdair G Kergon static inline sector_t to_sector(unsigned long n) 3910da336e5SAlasdair G Kergon { 3920da336e5SAlasdair G Kergon return (n >> SECTOR_SHIFT); 3930da336e5SAlasdair G Kergon } 3940da336e5SAlasdair G Kergon 3950da336e5SAlasdair G Kergon static inline unsigned long to_bytes(sector_t n) 3960da336e5SAlasdair G Kergon { 3970da336e5SAlasdair G Kergon return (n << SECTOR_SHIFT); 3980da336e5SAlasdair G Kergon } 3990da336e5SAlasdair G Kergon 400*cec47e3dSKiyoshi Ueda /*----------------------------------------------------------------- 401*cec47e3dSKiyoshi Ueda * Helper for block layer and dm core operations 402*cec47e3dSKiyoshi Ueda *---------------------------------------------------------------*/ 403*cec47e3dSKiyoshi Ueda void dm_dispatch_request(struct request *rq); 404*cec47e3dSKiyoshi Ueda void dm_requeue_unmapped_request(struct request *rq); 405*cec47e3dSKiyoshi Ueda void dm_kill_unmapped_request(struct request *rq, int error); 406*cec47e3dSKiyoshi Ueda int dm_underlying_device_busy(struct request_queue *q); 407*cec47e3dSKiyoshi Ueda 4081da177e4SLinus Torvalds #endif /* _LINUX_DEVICE_MAPPER_H */ 409