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, 875dea271bSMike Snitzer sector_t start, sector_t len, 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 9440bea431SMike Snitzer typedef void (*dm_io_hints_fn) (struct dm_target *ti, 9540bea431SMike Snitzer struct queue_limits *limits); 9640bea431SMike Snitzer 977d76345dSKiyoshi Ueda /* 987d76345dSKiyoshi Ueda * Returns: 997d76345dSKiyoshi Ueda * 0: The target can handle the next I/O immediately. 1007d76345dSKiyoshi Ueda * 1: The target can't handle the next I/O immediately. 1017d76345dSKiyoshi Ueda */ 1027d76345dSKiyoshi Ueda typedef int (*dm_busy_fn) (struct dm_target *ti); 1037d76345dSKiyoshi Ueda 1041da177e4SLinus Torvalds void dm_error(const char *message); 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds /* 1073cb40214SBryn Reeves * Combine device limits. 1083cb40214SBryn Reeves */ 109754c5fc7SMike Snitzer int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev, 1105dea271bSMike Snitzer sector_t start, sector_t len, void *data); 1113cb40214SBryn Reeves 11282b1519bSMikulas Patocka struct dm_dev { 11382b1519bSMikulas Patocka struct block_device *bdev; 114aeb5d727SAl Viro fmode_t mode; 11582b1519bSMikulas Patocka char name[16]; 11682b1519bSMikulas Patocka }; 11782b1519bSMikulas Patocka 1183cb40214SBryn Reeves /* 1191da177e4SLinus Torvalds * Constructors should call these functions to ensure destination devices 1201da177e4SLinus Torvalds * are opened/closed correctly. 1211da177e4SLinus Torvalds * FIXME: too many arguments. 1221da177e4SLinus Torvalds */ 1231da177e4SLinus Torvalds int dm_get_device(struct dm_target *ti, const char *path, sector_t start, 124aeb5d727SAl Viro sector_t len, fmode_t mode, struct dm_dev **result); 1251da177e4SLinus Torvalds void dm_put_device(struct dm_target *ti, struct dm_dev *d); 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds /* 1281da177e4SLinus Torvalds * Information about a target type 1291da177e4SLinus Torvalds */ 130ab4c1424SAndi Kleen 131ab4c1424SAndi Kleen /* 132ab4c1424SAndi Kleen * Target features 133ab4c1424SAndi Kleen */ 134ab4c1424SAndi Kleen 1351da177e4SLinus Torvalds struct target_type { 136ab4c1424SAndi Kleen uint64_t features; 1371da177e4SLinus Torvalds const char *name; 1381da177e4SLinus Torvalds struct module *module; 1391da177e4SLinus Torvalds unsigned version[3]; 1401da177e4SLinus Torvalds dm_ctr_fn ctr; 1411da177e4SLinus Torvalds dm_dtr_fn dtr; 1421da177e4SLinus Torvalds dm_map_fn map; 1437d76345dSKiyoshi Ueda dm_map_request_fn map_rq; 1441da177e4SLinus Torvalds dm_endio_fn end_io; 1457d76345dSKiyoshi Ueda dm_request_endio_fn rq_end_io; 146999d8168SBryn Reeves dm_flush_fn flush; 1471da177e4SLinus Torvalds dm_presuspend_fn presuspend; 1481da177e4SLinus Torvalds dm_postsuspend_fn postsuspend; 1498757b776SMilan Broz dm_preresume_fn preresume; 1501da177e4SLinus Torvalds dm_resume_fn resume; 1511da177e4SLinus Torvalds dm_status_fn status; 1521da177e4SLinus Torvalds dm_message_fn message; 153aa129a22SMilan Broz dm_ioctl_fn ioctl; 154f6fccb12SMilan Broz dm_merge_fn merge; 1557d76345dSKiyoshi Ueda dm_busy_fn busy; 156af4874e0SMike Snitzer dm_iterate_devices_fn iterate_devices; 15740bea431SMike Snitzer dm_io_hints_fn io_hints; 15845194e4fSCheng Renquan 15945194e4fSCheng Renquan /* For internal device-mapper use. */ 16045194e4fSCheng Renquan struct list_head list; 1611da177e4SLinus Torvalds }; 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds struct dm_target { 1641da177e4SLinus Torvalds struct dm_table *table; 1651da177e4SLinus Torvalds struct target_type *type; 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds /* target limits */ 1681da177e4SLinus Torvalds sector_t begin; 1691da177e4SLinus Torvalds sector_t len; 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds /* Always a power of 2 */ 1721da177e4SLinus Torvalds sector_t split_io; 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds /* 175f9ab94ceSMikulas Patocka * A number of zero-length barrier requests that will be submitted 176f9ab94ceSMikulas Patocka * to the target for the purpose of flushing cache. 177f9ab94ceSMikulas Patocka * 178f9ab94ceSMikulas Patocka * The request number will be placed in union map_info->flush_request. 179f9ab94ceSMikulas Patocka * It is a responsibility of the target driver to remap these requests 180f9ab94ceSMikulas Patocka * to the real underlying devices. 181f9ab94ceSMikulas Patocka */ 182f9ab94ceSMikulas Patocka unsigned num_flush_requests; 183f9ab94ceSMikulas Patocka 1841da177e4SLinus Torvalds /* target specific data */ 1851da177e4SLinus Torvalds void *private; 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds /* Used to provide an error string from the ctr */ 1881da177e4SLinus Torvalds char *error; 1891da177e4SLinus Torvalds }; 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds int dm_register_target(struct target_type *t); 19210d3bd09SMikulas Patocka void dm_unregister_target(struct target_type *t); 19317b2f66fSAlasdair G Kergon 19417b2f66fSAlasdair G Kergon /*----------------------------------------------------------------- 19517b2f66fSAlasdair G Kergon * Functions for creating and manipulating mapped devices. 19617b2f66fSAlasdair G Kergon * Drop the reference with dm_put when you finish with the object. 19717b2f66fSAlasdair G Kergon *---------------------------------------------------------------*/ 19817b2f66fSAlasdair G Kergon 19917b2f66fSAlasdair G Kergon /* 20017b2f66fSAlasdair G Kergon * DM_ANY_MINOR chooses the next available minor number. 20117b2f66fSAlasdair G Kergon */ 20217b2f66fSAlasdair G Kergon #define DM_ANY_MINOR (-1) 20317b2f66fSAlasdair G Kergon int dm_create(int minor, struct mapped_device **md); 20417b2f66fSAlasdair G Kergon 20517b2f66fSAlasdair G Kergon /* 20617b2f66fSAlasdair G Kergon * Reference counting for md. 20717b2f66fSAlasdair G Kergon */ 20817b2f66fSAlasdair G Kergon struct mapped_device *dm_get_md(dev_t dev); 20917b2f66fSAlasdair G Kergon void dm_get(struct mapped_device *md); 21017b2f66fSAlasdair G Kergon void dm_put(struct mapped_device *md); 21117b2f66fSAlasdair G Kergon 21217b2f66fSAlasdair G Kergon /* 21317b2f66fSAlasdair G Kergon * An arbitrary pointer may be stored alongside a mapped device. 21417b2f66fSAlasdair G Kergon */ 21517b2f66fSAlasdair G Kergon void dm_set_mdptr(struct mapped_device *md, void *ptr); 21617b2f66fSAlasdair G Kergon void *dm_get_mdptr(struct mapped_device *md); 21717b2f66fSAlasdair G Kergon 21817b2f66fSAlasdair G Kergon /* 21917b2f66fSAlasdair G Kergon * A device can still be used while suspended, but I/O is deferred. 22017b2f66fSAlasdair G Kergon */ 221a3d77d35SKiyoshi Ueda int dm_suspend(struct mapped_device *md, unsigned suspend_flags); 22217b2f66fSAlasdair G Kergon int dm_resume(struct mapped_device *md); 22317b2f66fSAlasdair G Kergon 22417b2f66fSAlasdair G Kergon /* 22517b2f66fSAlasdair G Kergon * Event functions. 22617b2f66fSAlasdair G Kergon */ 22717b2f66fSAlasdair G Kergon uint32_t dm_get_event_nr(struct mapped_device *md); 22817b2f66fSAlasdair G Kergon int dm_wait_event(struct mapped_device *md, int event_nr); 2297a8c3d3bSMike Anderson uint32_t dm_next_uevent_seq(struct mapped_device *md); 2307a8c3d3bSMike Anderson void dm_uevent_add(struct mapped_device *md, struct list_head *elist); 23117b2f66fSAlasdair G Kergon 23217b2f66fSAlasdair G Kergon /* 23317b2f66fSAlasdair G Kergon * Info functions. 23417b2f66fSAlasdair G Kergon */ 23572d94861SAlasdair G Kergon const char *dm_device_name(struct mapped_device *md); 23696a1f7dbSMike Anderson int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid); 23717b2f66fSAlasdair G Kergon struct gendisk *dm_disk(struct mapped_device *md); 23817b2f66fSAlasdair G Kergon int dm_suspended(struct mapped_device *md); 2392e93ccc1SKiyoshi Ueda int dm_noflush_suspending(struct dm_target *ti); 24089343da0SMikulas Patocka union map_info *dm_get_mapinfo(struct bio *bio); 241cec47e3dSKiyoshi Ueda union map_info *dm_get_rq_mapinfo(struct request *rq); 24217b2f66fSAlasdair G Kergon 24317b2f66fSAlasdair G Kergon /* 24417b2f66fSAlasdair G Kergon * Geometry functions. 24517b2f66fSAlasdair G Kergon */ 24617b2f66fSAlasdair G Kergon int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo); 24717b2f66fSAlasdair G Kergon int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo); 24817b2f66fSAlasdair G Kergon 24917b2f66fSAlasdair G Kergon 25017b2f66fSAlasdair G Kergon /*----------------------------------------------------------------- 25117b2f66fSAlasdair G Kergon * Functions for manipulating device-mapper tables. 25217b2f66fSAlasdair G Kergon *---------------------------------------------------------------*/ 25317b2f66fSAlasdair G Kergon 25417b2f66fSAlasdair G Kergon /* 25517b2f66fSAlasdair G Kergon * First create an empty table. 25617b2f66fSAlasdair G Kergon */ 257aeb5d727SAl Viro int dm_table_create(struct dm_table **result, fmode_t mode, 25817b2f66fSAlasdair G Kergon unsigned num_targets, struct mapped_device *md); 25917b2f66fSAlasdair G Kergon 26017b2f66fSAlasdair G Kergon /* 26117b2f66fSAlasdair G Kergon * Then call this once for each target. 26217b2f66fSAlasdair G Kergon */ 26317b2f66fSAlasdair G Kergon int dm_table_add_target(struct dm_table *t, const char *type, 26417b2f66fSAlasdair G Kergon sector_t start, sector_t len, char *params); 26517b2f66fSAlasdair G Kergon 26617b2f66fSAlasdair G Kergon /* 26717b2f66fSAlasdair G Kergon * Finally call this to make the table ready for use. 26817b2f66fSAlasdair G Kergon */ 26917b2f66fSAlasdair G Kergon int dm_table_complete(struct dm_table *t); 27017b2f66fSAlasdair G Kergon 27117b2f66fSAlasdair G Kergon /* 272ea0ec640SMikulas Patocka * Unplug all devices in a table. 273ea0ec640SMikulas Patocka */ 274ea0ec640SMikulas Patocka void dm_table_unplug_all(struct dm_table *t); 275ea0ec640SMikulas Patocka 276ea0ec640SMikulas Patocka /* 27717b2f66fSAlasdair G Kergon * Table reference counting. 27817b2f66fSAlasdair G Kergon */ 2797c666411SAlasdair G Kergon struct dm_table *dm_get_live_table(struct mapped_device *md); 28017b2f66fSAlasdair G Kergon void dm_table_get(struct dm_table *t); 28117b2f66fSAlasdair G Kergon void dm_table_put(struct dm_table *t); 28217b2f66fSAlasdair G Kergon 28317b2f66fSAlasdair G Kergon /* 28417b2f66fSAlasdair G Kergon * Queries 28517b2f66fSAlasdair G Kergon */ 28617b2f66fSAlasdair G Kergon sector_t dm_table_get_size(struct dm_table *t); 28717b2f66fSAlasdair G Kergon unsigned int dm_table_get_num_targets(struct dm_table *t); 288aeb5d727SAl Viro fmode_t dm_table_get_mode(struct dm_table *t); 28917b2f66fSAlasdair G Kergon struct mapped_device *dm_table_get_md(struct dm_table *t); 29017b2f66fSAlasdair G Kergon 29117b2f66fSAlasdair G Kergon /* 29217b2f66fSAlasdair G Kergon * Trigger an event. 29317b2f66fSAlasdair G Kergon */ 29417b2f66fSAlasdair G Kergon void dm_table_event(struct dm_table *t); 29517b2f66fSAlasdair G Kergon 29617b2f66fSAlasdair G Kergon /* 29717b2f66fSAlasdair G Kergon * The device must be suspended before calling this method. 298*042d2a9bSAlasdair G Kergon * Returns the previous table, which the caller must destroy. 29917b2f66fSAlasdair G Kergon */ 300*042d2a9bSAlasdair G Kergon struct dm_table *dm_swap_table(struct mapped_device *md, 301*042d2a9bSAlasdair G Kergon struct dm_table *t); 30217b2f66fSAlasdair G Kergon 30354160904SMikulas Patocka /* 30454160904SMikulas Patocka * A wrapper around vmalloc. 30554160904SMikulas Patocka */ 30654160904SMikulas Patocka void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size); 30754160904SMikulas Patocka 3080da336e5SAlasdair G Kergon /*----------------------------------------------------------------- 3090da336e5SAlasdair G Kergon * Macros. 3100da336e5SAlasdair G Kergon *---------------------------------------------------------------*/ 3110da336e5SAlasdair G Kergon #define DM_NAME "device-mapper" 3120da336e5SAlasdair G Kergon 31310d3bd09SMikulas Patocka #define DMCRIT(f, arg...) \ 31410d3bd09SMikulas Patocka printk(KERN_CRIT DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 31510d3bd09SMikulas Patocka 3160da336e5SAlasdair G Kergon #define DMERR(f, arg...) \ 3170da336e5SAlasdair G Kergon printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 3180da336e5SAlasdair G Kergon #define DMERR_LIMIT(f, arg...) \ 3190da336e5SAlasdair G Kergon do { \ 3200da336e5SAlasdair G Kergon if (printk_ratelimit()) \ 3210da336e5SAlasdair G Kergon printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \ 3220da336e5SAlasdair G Kergon f "\n", ## arg); \ 3230da336e5SAlasdair G Kergon } while (0) 3240da336e5SAlasdair G Kergon 3250da336e5SAlasdair G Kergon #define DMWARN(f, arg...) \ 3260da336e5SAlasdair G Kergon printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 3270da336e5SAlasdair G Kergon #define DMWARN_LIMIT(f, arg...) \ 3280da336e5SAlasdair G Kergon do { \ 3290da336e5SAlasdair G Kergon if (printk_ratelimit()) \ 3300da336e5SAlasdair G Kergon printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \ 3310da336e5SAlasdair G Kergon f "\n", ## arg); \ 3320da336e5SAlasdair G Kergon } while (0) 3330da336e5SAlasdair G Kergon 3340da336e5SAlasdair G Kergon #define DMINFO(f, arg...) \ 3350da336e5SAlasdair G Kergon printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 3360da336e5SAlasdair G Kergon #define DMINFO_LIMIT(f, arg...) \ 3370da336e5SAlasdair G Kergon do { \ 3380da336e5SAlasdair G Kergon if (printk_ratelimit()) \ 3390da336e5SAlasdair G Kergon printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \ 3400da336e5SAlasdair G Kergon "\n", ## arg); \ 3410da336e5SAlasdair G Kergon } while (0) 3420da336e5SAlasdair G Kergon 3430da336e5SAlasdair G Kergon #ifdef CONFIG_DM_DEBUG 3440da336e5SAlasdair G Kergon # define DMDEBUG(f, arg...) \ 3450da336e5SAlasdair G Kergon printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg) 3460da336e5SAlasdair G Kergon # define DMDEBUG_LIMIT(f, arg...) \ 3470da336e5SAlasdair G Kergon do { \ 3480da336e5SAlasdair G Kergon if (printk_ratelimit()) \ 3490da336e5SAlasdair G Kergon printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \ 3500da336e5SAlasdair G Kergon "\n", ## arg); \ 3510da336e5SAlasdair G Kergon } while (0) 3520da336e5SAlasdair G Kergon #else 3530da336e5SAlasdair G Kergon # define DMDEBUG(f, arg...) do {} while (0) 3540da336e5SAlasdair G Kergon # define DMDEBUG_LIMIT(f, arg...) do {} while (0) 3550da336e5SAlasdair G Kergon #endif 3560da336e5SAlasdair G Kergon 3570da336e5SAlasdair G Kergon #define DMEMIT(x...) sz += ((sz >= maxlen) ? \ 3580da336e5SAlasdair G Kergon 0 : scnprintf(result + sz, maxlen - sz, x)) 3590da336e5SAlasdair G Kergon 3600da336e5SAlasdair G Kergon #define SECTOR_SHIFT 9 3610da336e5SAlasdair G Kergon 3620da336e5SAlasdair G Kergon /* 3630da336e5SAlasdair G Kergon * Definitions of return values from target end_io function. 3640da336e5SAlasdair G Kergon */ 3650da336e5SAlasdair G Kergon #define DM_ENDIO_INCOMPLETE 1 3660da336e5SAlasdair G Kergon #define DM_ENDIO_REQUEUE 2 3670da336e5SAlasdair G Kergon 3680da336e5SAlasdair G Kergon /* 3690da336e5SAlasdair G Kergon * Definitions of return values from target map function. 3700da336e5SAlasdair G Kergon */ 3710da336e5SAlasdair G Kergon #define DM_MAPIO_SUBMITTED 0 3720da336e5SAlasdair G Kergon #define DM_MAPIO_REMAPPED 1 3730da336e5SAlasdair G Kergon #define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE 3740da336e5SAlasdair G Kergon 3750da336e5SAlasdair G Kergon /* 3760da336e5SAlasdair G Kergon * Ceiling(n / sz) 3770da336e5SAlasdair G Kergon */ 3780da336e5SAlasdair G Kergon #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz)) 3790da336e5SAlasdair G Kergon 3800da336e5SAlasdair G Kergon #define dm_sector_div_up(n, sz) ( \ 3810da336e5SAlasdair G Kergon { \ 3820da336e5SAlasdair G Kergon sector_t _r = ((n) + (sz) - 1); \ 3830da336e5SAlasdair G Kergon sector_div(_r, (sz)); \ 3840da336e5SAlasdair G Kergon _r; \ 3850da336e5SAlasdair G Kergon } \ 3860da336e5SAlasdair G Kergon ) 3870da336e5SAlasdair G Kergon 3880da336e5SAlasdair G Kergon /* 3890da336e5SAlasdair G Kergon * ceiling(n / size) * size 3900da336e5SAlasdair G Kergon */ 3910da336e5SAlasdair G Kergon #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz)) 3920da336e5SAlasdair G Kergon 393d63a5ce3SMikulas Patocka #define dm_array_too_big(fixed, obj, num) \ 394d63a5ce3SMikulas Patocka ((num) > (UINT_MAX - (fixed)) / (obj)) 395d63a5ce3SMikulas Patocka 3960da336e5SAlasdair G Kergon static inline sector_t to_sector(unsigned long n) 3970da336e5SAlasdair G Kergon { 3980da336e5SAlasdair G Kergon return (n >> SECTOR_SHIFT); 3990da336e5SAlasdair G Kergon } 4000da336e5SAlasdair G Kergon 4010da336e5SAlasdair G Kergon static inline unsigned long to_bytes(sector_t n) 4020da336e5SAlasdair G Kergon { 4030da336e5SAlasdair G Kergon return (n << SECTOR_SHIFT); 4040da336e5SAlasdair G Kergon } 4050da336e5SAlasdair G Kergon 406cec47e3dSKiyoshi Ueda /*----------------------------------------------------------------- 407cec47e3dSKiyoshi Ueda * Helper for block layer and dm core operations 408cec47e3dSKiyoshi Ueda *---------------------------------------------------------------*/ 409cec47e3dSKiyoshi Ueda void dm_dispatch_request(struct request *rq); 410cec47e3dSKiyoshi Ueda void dm_requeue_unmapped_request(struct request *rq); 411cec47e3dSKiyoshi Ueda void dm_kill_unmapped_request(struct request *rq, int error); 412cec47e3dSKiyoshi Ueda int dm_underlying_device_busy(struct request_queue *q); 413cec47e3dSKiyoshi Ueda 4141da177e4SLinus Torvalds #endif /* _LINUX_DEVICE_MAPPER_H */ 415