xref: /openbmc/linux/include/linux/device-mapper.h (revision aeb5d727062a0238a2f96c9c380fbd2be4640c6f)
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 
141da177e4SLinus Torvalds struct dm_target;
151da177e4SLinus Torvalds struct dm_table;
1617b2f66fSAlasdair G Kergon struct mapped_device;
17f6fccb12SMilan Broz struct bio_vec;
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
201da177e4SLinus Torvalds 
211da177e4SLinus Torvalds union map_info {
221da177e4SLinus Torvalds 	void *ptr;
231da177e4SLinus Torvalds 	unsigned long long ll;
241da177e4SLinus Torvalds };
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds /*
271da177e4SLinus Torvalds  * In the constructor the target parameter will already have the
281da177e4SLinus Torvalds  * table, type, begin and len fields filled in.
291da177e4SLinus Torvalds  */
301da177e4SLinus Torvalds typedef int (*dm_ctr_fn) (struct dm_target *target,
311da177e4SLinus Torvalds 			  unsigned int argc, char **argv);
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds /*
341da177e4SLinus Torvalds  * The destructor doesn't need to free the dm_target, just
351da177e4SLinus Torvalds  * anything hidden ti->private.
361da177e4SLinus Torvalds  */
371da177e4SLinus Torvalds typedef void (*dm_dtr_fn) (struct dm_target *ti);
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds /*
401da177e4SLinus Torvalds  * The map function must return:
411da177e4SLinus Torvalds  * < 0: error
421da177e4SLinus Torvalds  * = 0: The target will handle the io by resubmitting it later
4345cbcd79SKiyoshi Ueda  * = 1: simple remap complete
442e93ccc1SKiyoshi Ueda  * = 2: The target wants to push back the io
451da177e4SLinus Torvalds  */
461da177e4SLinus Torvalds typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
471da177e4SLinus Torvalds 			  union map_info *map_context);
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds /*
501da177e4SLinus Torvalds  * Returns:
511da177e4SLinus Torvalds  * < 0 : error (currently ignored)
521da177e4SLinus Torvalds  * 0   : ended successfully
531da177e4SLinus Torvalds  * 1   : for some reason the io has still not completed (eg,
541da177e4SLinus Torvalds  *       multipath target might want to requeue a failed io).
552e93ccc1SKiyoshi Ueda  * 2   : The target wants to push back the io
561da177e4SLinus Torvalds  */
571da177e4SLinus Torvalds typedef int (*dm_endio_fn) (struct dm_target *ti,
581da177e4SLinus Torvalds 			    struct bio *bio, int error,
591da177e4SLinus Torvalds 			    union map_info *map_context);
601da177e4SLinus Torvalds 
61999d8168SBryn Reeves typedef void (*dm_flush_fn) (struct dm_target *ti);
621da177e4SLinus Torvalds typedef void (*dm_presuspend_fn) (struct dm_target *ti);
631da177e4SLinus Torvalds typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
648757b776SMilan Broz typedef int (*dm_preresume_fn) (struct dm_target *ti);
651da177e4SLinus Torvalds typedef void (*dm_resume_fn) (struct dm_target *ti);
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
681da177e4SLinus Torvalds 			     char *result, unsigned int maxlen);
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
711da177e4SLinus Torvalds 
72aa129a22SMilan Broz typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode,
73aa129a22SMilan Broz 			    struct file *filp, unsigned int cmd,
74aa129a22SMilan Broz 			    unsigned long arg);
75aa129a22SMilan Broz 
76f6fccb12SMilan Broz typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
77f6fccb12SMilan Broz 			    struct bio_vec *biovec, int max_size);
78f6fccb12SMilan Broz 
791da177e4SLinus Torvalds void dm_error(const char *message);
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds /*
823cb40214SBryn Reeves  * Combine device limits.
833cb40214SBryn Reeves  */
843cb40214SBryn Reeves void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
853cb40214SBryn Reeves 
8682b1519bSMikulas Patocka struct dm_dev {
8782b1519bSMikulas Patocka 	struct block_device *bdev;
88*aeb5d727SAl Viro 	fmode_t mode;
8982b1519bSMikulas Patocka 	char name[16];
9082b1519bSMikulas Patocka };
9182b1519bSMikulas Patocka 
923cb40214SBryn Reeves /*
931da177e4SLinus Torvalds  * Constructors should call these functions to ensure destination devices
941da177e4SLinus Torvalds  * are opened/closed correctly.
951da177e4SLinus Torvalds  * FIXME: too many arguments.
961da177e4SLinus Torvalds  */
971da177e4SLinus Torvalds int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
98*aeb5d727SAl Viro 		  sector_t len, fmode_t mode, struct dm_dev **result);
991da177e4SLinus Torvalds void dm_put_device(struct dm_target *ti, struct dm_dev *d);
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds /*
1021da177e4SLinus Torvalds  * Information about a target type
1031da177e4SLinus Torvalds  */
1041da177e4SLinus Torvalds struct target_type {
1051da177e4SLinus Torvalds 	const char *name;
1061da177e4SLinus Torvalds 	struct module *module;
1071da177e4SLinus Torvalds 	unsigned version[3];
1081da177e4SLinus Torvalds 	dm_ctr_fn ctr;
1091da177e4SLinus Torvalds 	dm_dtr_fn dtr;
1101da177e4SLinus Torvalds 	dm_map_fn map;
1111da177e4SLinus Torvalds 	dm_endio_fn end_io;
112999d8168SBryn Reeves 	dm_flush_fn flush;
1131da177e4SLinus Torvalds 	dm_presuspend_fn presuspend;
1141da177e4SLinus Torvalds 	dm_postsuspend_fn postsuspend;
1158757b776SMilan Broz 	dm_preresume_fn preresume;
1161da177e4SLinus Torvalds 	dm_resume_fn resume;
1171da177e4SLinus Torvalds 	dm_status_fn status;
1181da177e4SLinus Torvalds 	dm_message_fn message;
119aa129a22SMilan Broz 	dm_ioctl_fn ioctl;
120f6fccb12SMilan Broz 	dm_merge_fn merge;
1211da177e4SLinus Torvalds };
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds struct io_restrictions {
1245ec140e6SVasily Averin 	unsigned long bounce_pfn;
1254f41b09fSVasily Averin 	unsigned long seg_boundary_mask;
1264f41b09fSVasily Averin 	unsigned max_hw_sectors;
1274f41b09fSVasily Averin 	unsigned max_sectors;
1284f41b09fSVasily Averin 	unsigned max_segment_size;
1294f41b09fSVasily Averin 	unsigned short hardsect_size;
1304f41b09fSVasily Averin 	unsigned short max_hw_segments;
1314f41b09fSVasily Averin 	unsigned short max_phys_segments;
132969429b5SNeilBrown 	unsigned char no_cluster; /* inverted so that 0 is default */
1331da177e4SLinus Torvalds };
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds struct dm_target {
1361da177e4SLinus Torvalds 	struct dm_table *table;
1371da177e4SLinus Torvalds 	struct target_type *type;
1381da177e4SLinus Torvalds 
1391da177e4SLinus Torvalds 	/* target limits */
1401da177e4SLinus Torvalds 	sector_t begin;
1411da177e4SLinus Torvalds 	sector_t len;
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds 	/* FIXME: turn this into a mask, and merge with io_restrictions */
1441da177e4SLinus Torvalds 	/* Always a power of 2 */
1451da177e4SLinus Torvalds 	sector_t split_io;
1461da177e4SLinus Torvalds 
1471da177e4SLinus Torvalds 	/*
1481da177e4SLinus Torvalds 	 * These are automatically filled in by
1491da177e4SLinus Torvalds 	 * dm_table_get_device.
1501da177e4SLinus Torvalds 	 */
1511da177e4SLinus Torvalds 	struct io_restrictions limits;
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds 	/* target specific data */
1541da177e4SLinus Torvalds 	void *private;
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds 	/* Used to provide an error string from the ctr */
1571da177e4SLinus Torvalds 	char *error;
1581da177e4SLinus Torvalds };
1591da177e4SLinus Torvalds 
1601da177e4SLinus Torvalds int dm_register_target(struct target_type *t);
1611da177e4SLinus Torvalds int dm_unregister_target(struct target_type *t);
1621da177e4SLinus Torvalds 
16317b2f66fSAlasdair G Kergon 
16417b2f66fSAlasdair G Kergon /*-----------------------------------------------------------------
16517b2f66fSAlasdair G Kergon  * Functions for creating and manipulating mapped devices.
16617b2f66fSAlasdair G Kergon  * Drop the reference with dm_put when you finish with the object.
16717b2f66fSAlasdair G Kergon  *---------------------------------------------------------------*/
16817b2f66fSAlasdair G Kergon 
16917b2f66fSAlasdair G Kergon /*
17017b2f66fSAlasdair G Kergon  * DM_ANY_MINOR chooses the next available minor number.
17117b2f66fSAlasdair G Kergon  */
17217b2f66fSAlasdair G Kergon #define DM_ANY_MINOR (-1)
17317b2f66fSAlasdair G Kergon int dm_create(int minor, struct mapped_device **md);
17417b2f66fSAlasdair G Kergon 
17517b2f66fSAlasdair G Kergon /*
17617b2f66fSAlasdair G Kergon  * Reference counting for md.
17717b2f66fSAlasdair G Kergon  */
17817b2f66fSAlasdair G Kergon struct mapped_device *dm_get_md(dev_t dev);
17917b2f66fSAlasdair G Kergon void dm_get(struct mapped_device *md);
18017b2f66fSAlasdair G Kergon void dm_put(struct mapped_device *md);
18117b2f66fSAlasdair G Kergon 
18217b2f66fSAlasdair G Kergon /*
18317b2f66fSAlasdair G Kergon  * An arbitrary pointer may be stored alongside a mapped device.
18417b2f66fSAlasdair G Kergon  */
18517b2f66fSAlasdair G Kergon void dm_set_mdptr(struct mapped_device *md, void *ptr);
18617b2f66fSAlasdair G Kergon void *dm_get_mdptr(struct mapped_device *md);
18717b2f66fSAlasdair G Kergon 
18817b2f66fSAlasdair G Kergon /*
18917b2f66fSAlasdair G Kergon  * A device can still be used while suspended, but I/O is deferred.
19017b2f66fSAlasdair G Kergon  */
191a3d77d35SKiyoshi Ueda int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
19217b2f66fSAlasdair G Kergon int dm_resume(struct mapped_device *md);
19317b2f66fSAlasdair G Kergon 
19417b2f66fSAlasdair G Kergon /*
19517b2f66fSAlasdair G Kergon  * Event functions.
19617b2f66fSAlasdair G Kergon  */
19717b2f66fSAlasdair G Kergon uint32_t dm_get_event_nr(struct mapped_device *md);
19817b2f66fSAlasdair G Kergon int dm_wait_event(struct mapped_device *md, int event_nr);
1997a8c3d3bSMike Anderson uint32_t dm_next_uevent_seq(struct mapped_device *md);
2007a8c3d3bSMike Anderson void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
20117b2f66fSAlasdair G Kergon 
20217b2f66fSAlasdair G Kergon /*
20317b2f66fSAlasdair G Kergon  * Info functions.
20417b2f66fSAlasdair G Kergon  */
20572d94861SAlasdair G Kergon const char *dm_device_name(struct mapped_device *md);
20696a1f7dbSMike Anderson int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
20717b2f66fSAlasdair G Kergon struct gendisk *dm_disk(struct mapped_device *md);
20817b2f66fSAlasdair G Kergon int dm_suspended(struct mapped_device *md);
2092e93ccc1SKiyoshi Ueda int dm_noflush_suspending(struct dm_target *ti);
21089343da0SMikulas Patocka union map_info *dm_get_mapinfo(struct bio *bio);
21117b2f66fSAlasdair G Kergon 
21217b2f66fSAlasdair G Kergon /*
21317b2f66fSAlasdair G Kergon  * Geometry functions.
21417b2f66fSAlasdair G Kergon  */
21517b2f66fSAlasdair G Kergon int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
21617b2f66fSAlasdair G Kergon int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
21717b2f66fSAlasdair G Kergon 
21817b2f66fSAlasdair G Kergon 
21917b2f66fSAlasdair G Kergon /*-----------------------------------------------------------------
22017b2f66fSAlasdair G Kergon  * Functions for manipulating device-mapper tables.
22117b2f66fSAlasdair G Kergon  *---------------------------------------------------------------*/
22217b2f66fSAlasdair G Kergon 
22317b2f66fSAlasdair G Kergon /*
22417b2f66fSAlasdair G Kergon  * First create an empty table.
22517b2f66fSAlasdair G Kergon  */
226*aeb5d727SAl Viro int dm_table_create(struct dm_table **result, fmode_t mode,
22717b2f66fSAlasdair G Kergon 		    unsigned num_targets, struct mapped_device *md);
22817b2f66fSAlasdair G Kergon 
22917b2f66fSAlasdair G Kergon /*
23017b2f66fSAlasdair G Kergon  * Then call this once for each target.
23117b2f66fSAlasdair G Kergon  */
23217b2f66fSAlasdair G Kergon int dm_table_add_target(struct dm_table *t, const char *type,
23317b2f66fSAlasdair G Kergon 			sector_t start, sector_t len, char *params);
23417b2f66fSAlasdair G Kergon 
23517b2f66fSAlasdair G Kergon /*
23617b2f66fSAlasdair G Kergon  * Finally call this to make the table ready for use.
23717b2f66fSAlasdair G Kergon  */
23817b2f66fSAlasdair G Kergon int dm_table_complete(struct dm_table *t);
23917b2f66fSAlasdair G Kergon 
24017b2f66fSAlasdair G Kergon /*
241ea0ec640SMikulas Patocka  * Unplug all devices in a table.
242ea0ec640SMikulas Patocka  */
243ea0ec640SMikulas Patocka void dm_table_unplug_all(struct dm_table *t);
244ea0ec640SMikulas Patocka 
245ea0ec640SMikulas Patocka /*
24617b2f66fSAlasdair G Kergon  * Table reference counting.
24717b2f66fSAlasdair G Kergon  */
24817b2f66fSAlasdair G Kergon struct dm_table *dm_get_table(struct mapped_device *md);
24917b2f66fSAlasdair G Kergon void dm_table_get(struct dm_table *t);
25017b2f66fSAlasdair G Kergon void dm_table_put(struct dm_table *t);
25117b2f66fSAlasdair G Kergon 
25217b2f66fSAlasdair G Kergon /*
25317b2f66fSAlasdair G Kergon  * Queries
25417b2f66fSAlasdair G Kergon  */
25517b2f66fSAlasdair G Kergon sector_t dm_table_get_size(struct dm_table *t);
25617b2f66fSAlasdair G Kergon unsigned int dm_table_get_num_targets(struct dm_table *t);
257*aeb5d727SAl Viro fmode_t dm_table_get_mode(struct dm_table *t);
25817b2f66fSAlasdair G Kergon struct mapped_device *dm_table_get_md(struct dm_table *t);
25917b2f66fSAlasdair G Kergon 
26017b2f66fSAlasdair G Kergon /*
26117b2f66fSAlasdair G Kergon  * Trigger an event.
26217b2f66fSAlasdair G Kergon  */
26317b2f66fSAlasdair G Kergon void dm_table_event(struct dm_table *t);
26417b2f66fSAlasdair G Kergon 
26517b2f66fSAlasdair G Kergon /*
26617b2f66fSAlasdair G Kergon  * The device must be suspended before calling this method.
26717b2f66fSAlasdair G Kergon  */
26817b2f66fSAlasdair G Kergon int dm_swap_table(struct mapped_device *md, struct dm_table *t);
26917b2f66fSAlasdair G Kergon 
27054160904SMikulas Patocka /*
27154160904SMikulas Patocka  * A wrapper around vmalloc.
27254160904SMikulas Patocka  */
27354160904SMikulas Patocka void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
27454160904SMikulas Patocka 
2750da336e5SAlasdair G Kergon /*-----------------------------------------------------------------
2760da336e5SAlasdair G Kergon  * Macros.
2770da336e5SAlasdair G Kergon  *---------------------------------------------------------------*/
2780da336e5SAlasdair G Kergon #define DM_NAME "device-mapper"
2790da336e5SAlasdair G Kergon 
2800da336e5SAlasdair G Kergon #define DMERR(f, arg...) \
2810da336e5SAlasdair G Kergon 	printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
2820da336e5SAlasdair G Kergon #define DMERR_LIMIT(f, arg...) \
2830da336e5SAlasdair G Kergon 	do { \
2840da336e5SAlasdair G Kergon 		if (printk_ratelimit())	\
2850da336e5SAlasdair G Kergon 			printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \
2860da336e5SAlasdair G Kergon 			       f "\n", ## arg); \
2870da336e5SAlasdair G Kergon 	} while (0)
2880da336e5SAlasdair G Kergon 
2890da336e5SAlasdair G Kergon #define DMWARN(f, arg...) \
2900da336e5SAlasdair G Kergon 	printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
2910da336e5SAlasdair G Kergon #define DMWARN_LIMIT(f, arg...) \
2920da336e5SAlasdair G Kergon 	do { \
2930da336e5SAlasdair G Kergon 		if (printk_ratelimit())	\
2940da336e5SAlasdair G Kergon 			printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \
2950da336e5SAlasdair G Kergon 			       f "\n", ## arg); \
2960da336e5SAlasdair G Kergon 	} while (0)
2970da336e5SAlasdair G Kergon 
2980da336e5SAlasdair G Kergon #define DMINFO(f, arg...) \
2990da336e5SAlasdair G Kergon 	printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
3000da336e5SAlasdair G Kergon #define DMINFO_LIMIT(f, arg...) \
3010da336e5SAlasdair G Kergon 	do { \
3020da336e5SAlasdair G Kergon 		if (printk_ratelimit())	\
3030da336e5SAlasdair G Kergon 			printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \
3040da336e5SAlasdair G Kergon 			       "\n", ## arg); \
3050da336e5SAlasdair G Kergon 	} while (0)
3060da336e5SAlasdair G Kergon 
3070da336e5SAlasdair G Kergon #ifdef CONFIG_DM_DEBUG
3080da336e5SAlasdair G Kergon #  define DMDEBUG(f, arg...) \
3090da336e5SAlasdair G Kergon 	printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
3100da336e5SAlasdair G Kergon #  define DMDEBUG_LIMIT(f, arg...) \
3110da336e5SAlasdair G Kergon 	do { \
3120da336e5SAlasdair G Kergon 		if (printk_ratelimit())	\
3130da336e5SAlasdair G Kergon 			printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \
3140da336e5SAlasdair G Kergon 			       "\n", ## arg); \
3150da336e5SAlasdair G Kergon 	} while (0)
3160da336e5SAlasdair G Kergon #else
3170da336e5SAlasdair G Kergon #  define DMDEBUG(f, arg...) do {} while (0)
3180da336e5SAlasdair G Kergon #  define DMDEBUG_LIMIT(f, arg...) do {} while (0)
3190da336e5SAlasdair G Kergon #endif
3200da336e5SAlasdair G Kergon 
3210da336e5SAlasdair G Kergon #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
3220da336e5SAlasdair G Kergon 			  0 : scnprintf(result + sz, maxlen - sz, x))
3230da336e5SAlasdair G Kergon 
3240da336e5SAlasdair G Kergon #define SECTOR_SHIFT 9
3250da336e5SAlasdair G Kergon 
3260da336e5SAlasdair G Kergon /*
3270da336e5SAlasdair G Kergon  * Definitions of return values from target end_io function.
3280da336e5SAlasdair G Kergon  */
3290da336e5SAlasdair G Kergon #define DM_ENDIO_INCOMPLETE	1
3300da336e5SAlasdair G Kergon #define DM_ENDIO_REQUEUE	2
3310da336e5SAlasdair G Kergon 
3320da336e5SAlasdair G Kergon /*
3330da336e5SAlasdair G Kergon  * Definitions of return values from target map function.
3340da336e5SAlasdair G Kergon  */
3350da336e5SAlasdair G Kergon #define DM_MAPIO_SUBMITTED	0
3360da336e5SAlasdair G Kergon #define DM_MAPIO_REMAPPED	1
3370da336e5SAlasdair G Kergon #define DM_MAPIO_REQUEUE	DM_ENDIO_REQUEUE
3380da336e5SAlasdair G Kergon 
3390da336e5SAlasdair G Kergon /*
3400da336e5SAlasdair G Kergon  * Ceiling(n / sz)
3410da336e5SAlasdair G Kergon  */
3420da336e5SAlasdair G Kergon #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
3430da336e5SAlasdair G Kergon 
3440da336e5SAlasdair G Kergon #define dm_sector_div_up(n, sz) ( \
3450da336e5SAlasdair G Kergon { \
3460da336e5SAlasdair G Kergon 	sector_t _r = ((n) + (sz) - 1); \
3470da336e5SAlasdair G Kergon 	sector_div(_r, (sz)); \
3480da336e5SAlasdair G Kergon 	_r; \
3490da336e5SAlasdair G Kergon } \
3500da336e5SAlasdair G Kergon )
3510da336e5SAlasdair G Kergon 
3520da336e5SAlasdair G Kergon /*
3530da336e5SAlasdair G Kergon  * ceiling(n / size) * size
3540da336e5SAlasdair G Kergon  */
3550da336e5SAlasdair G Kergon #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
3560da336e5SAlasdair G Kergon 
3570da336e5SAlasdair G Kergon static inline sector_t to_sector(unsigned long n)
3580da336e5SAlasdair G Kergon {
3590da336e5SAlasdair G Kergon 	return (n >> SECTOR_SHIFT);
3600da336e5SAlasdair G Kergon }
3610da336e5SAlasdair G Kergon 
3620da336e5SAlasdair G Kergon static inline unsigned long to_bytes(sector_t n)
3630da336e5SAlasdair G Kergon {
3640da336e5SAlasdair G Kergon 	return (n << SECTOR_SHIFT);
3650da336e5SAlasdair G Kergon }
3660da336e5SAlasdair G Kergon 
3671da177e4SLinus Torvalds #endif	/* _LINUX_DEVICE_MAPPER_H */
368