1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Internal header file for device mapper 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Copyright (C) 2001, 2002 Sistina Software 5*4882a593Smuzhiyun * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * This file is released under the LGPL. 8*4882a593Smuzhiyun */ 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #ifndef DM_INTERNAL_H 11*4882a593Smuzhiyun #define DM_INTERNAL_H 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun #include <linux/fs.h> 14*4882a593Smuzhiyun #include <linux/device-mapper.h> 15*4882a593Smuzhiyun #include <linux/list.h> 16*4882a593Smuzhiyun #include <linux/moduleparam.h> 17*4882a593Smuzhiyun #include <linux/blkdev.h> 18*4882a593Smuzhiyun #include <linux/backing-dev.h> 19*4882a593Smuzhiyun #include <linux/hdreg.h> 20*4882a593Smuzhiyun #include <linux/completion.h> 21*4882a593Smuzhiyun #include <linux/kobject.h> 22*4882a593Smuzhiyun #include <linux/refcount.h> 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun #include "dm-stats.h" 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun /* 27*4882a593Smuzhiyun * Suspend feature flags 28*4882a593Smuzhiyun */ 29*4882a593Smuzhiyun #define DM_SUSPEND_LOCKFS_FLAG (1 << 0) 30*4882a593Smuzhiyun #define DM_SUSPEND_NOFLUSH_FLAG (1 << 1) 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun /* 33*4882a593Smuzhiyun * Status feature flags 34*4882a593Smuzhiyun */ 35*4882a593Smuzhiyun #define DM_STATUS_NOFLUSH_FLAG (1 << 0) 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun /* 38*4882a593Smuzhiyun * List of devices that a metadevice uses and should open/close. 39*4882a593Smuzhiyun */ 40*4882a593Smuzhiyun struct dm_dev_internal { 41*4882a593Smuzhiyun struct list_head list; 42*4882a593Smuzhiyun refcount_t count; 43*4882a593Smuzhiyun struct dm_dev *dm_dev; 44*4882a593Smuzhiyun }; 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun struct dm_table; 47*4882a593Smuzhiyun struct dm_md_mempools; 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun /*----------------------------------------------------------------- 50*4882a593Smuzhiyun * Internal table functions. 51*4882a593Smuzhiyun *---------------------------------------------------------------*/ 52*4882a593Smuzhiyun void dm_table_event_callback(struct dm_table *t, 53*4882a593Smuzhiyun void (*fn)(void *), void *context); 54*4882a593Smuzhiyun struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index); 55*4882a593Smuzhiyun struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector); 56*4882a593Smuzhiyun bool dm_table_has_no_data_devices(struct dm_table *table); 57*4882a593Smuzhiyun int dm_calculate_queue_limits(struct dm_table *table, 58*4882a593Smuzhiyun struct queue_limits *limits); 59*4882a593Smuzhiyun void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, 60*4882a593Smuzhiyun struct queue_limits *limits); 61*4882a593Smuzhiyun struct list_head *dm_table_get_devices(struct dm_table *t); 62*4882a593Smuzhiyun void dm_table_presuspend_targets(struct dm_table *t); 63*4882a593Smuzhiyun void dm_table_presuspend_undo_targets(struct dm_table *t); 64*4882a593Smuzhiyun void dm_table_postsuspend_targets(struct dm_table *t); 65*4882a593Smuzhiyun int dm_table_resume_targets(struct dm_table *t); 66*4882a593Smuzhiyun enum dm_queue_mode dm_table_get_type(struct dm_table *t); 67*4882a593Smuzhiyun struct target_type *dm_table_get_immutable_target_type(struct dm_table *t); 68*4882a593Smuzhiyun struct dm_target *dm_table_get_immutable_target(struct dm_table *t); 69*4882a593Smuzhiyun struct dm_target *dm_table_get_wildcard_target(struct dm_table *t); 70*4882a593Smuzhiyun bool dm_table_bio_based(struct dm_table *t); 71*4882a593Smuzhiyun bool dm_table_request_based(struct dm_table *t); 72*4882a593Smuzhiyun void dm_table_free_md_mempools(struct dm_table *t); 73*4882a593Smuzhiyun struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t); 74*4882a593Smuzhiyun bool dm_table_supports_dax(struct dm_table *t, iterate_devices_callout_fn fn, 75*4882a593Smuzhiyun int *blocksize); 76*4882a593Smuzhiyun int device_not_dax_capable(struct dm_target *ti, struct dm_dev *dev, 77*4882a593Smuzhiyun sector_t start, sector_t len, void *data); 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun void dm_lock_md_type(struct mapped_device *md); 80*4882a593Smuzhiyun void dm_unlock_md_type(struct mapped_device *md); 81*4882a593Smuzhiyun void dm_set_md_type(struct mapped_device *md, enum dm_queue_mode type); 82*4882a593Smuzhiyun enum dm_queue_mode dm_get_md_type(struct mapped_device *md); 83*4882a593Smuzhiyun struct target_type *dm_get_immutable_target_type(struct mapped_device *md); 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t); 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun /* 88*4882a593Smuzhiyun * To check whether the target type is bio-based or not (request-based). 89*4882a593Smuzhiyun */ 90*4882a593Smuzhiyun #define dm_target_bio_based(t) ((t)->type->map != NULL) 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun /* 93*4882a593Smuzhiyun * To check whether the target type is request-based or not (bio-based). 94*4882a593Smuzhiyun */ 95*4882a593Smuzhiyun #define dm_target_request_based(t) ((t)->type->clone_and_map_rq != NULL) 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun /* 98*4882a593Smuzhiyun * To check whether the target type is a hybrid (capable of being 99*4882a593Smuzhiyun * either request-based or bio-based). 100*4882a593Smuzhiyun */ 101*4882a593Smuzhiyun #define dm_target_hybrid(t) (dm_target_bio_based(t) && dm_target_request_based(t)) 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun /*----------------------------------------------------------------- 104*4882a593Smuzhiyun * A registry of target types. 105*4882a593Smuzhiyun *---------------------------------------------------------------*/ 106*4882a593Smuzhiyun int dm_target_init(void); 107*4882a593Smuzhiyun void dm_target_exit(void); 108*4882a593Smuzhiyun struct target_type *dm_get_target_type(const char *name); 109*4882a593Smuzhiyun void dm_put_target_type(struct target_type *tt); 110*4882a593Smuzhiyun int dm_target_iterate(void (*iter_func)(struct target_type *tt, 111*4882a593Smuzhiyun void *param), void *param); 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun int dm_split_args(int *argc, char ***argvp, char *input); 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun /* 116*4882a593Smuzhiyun * Is this mapped_device being deleted? 117*4882a593Smuzhiyun */ 118*4882a593Smuzhiyun int dm_deleting_md(struct mapped_device *md); 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun /* 121*4882a593Smuzhiyun * Is this mapped_device suspended? 122*4882a593Smuzhiyun */ 123*4882a593Smuzhiyun int dm_suspended_md(struct mapped_device *md); 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun /* 126*4882a593Smuzhiyun * Internal suspend and resume methods. 127*4882a593Smuzhiyun */ 128*4882a593Smuzhiyun int dm_suspended_internally_md(struct mapped_device *md); 129*4882a593Smuzhiyun void dm_internal_suspend_fast(struct mapped_device *md); 130*4882a593Smuzhiyun void dm_internal_resume_fast(struct mapped_device *md); 131*4882a593Smuzhiyun void dm_internal_suspend_noflush(struct mapped_device *md); 132*4882a593Smuzhiyun void dm_internal_resume(struct mapped_device *md); 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun /* 135*4882a593Smuzhiyun * Test if the device is scheduled for deferred remove. 136*4882a593Smuzhiyun */ 137*4882a593Smuzhiyun int dm_test_deferred_remove_flag(struct mapped_device *md); 138*4882a593Smuzhiyun 139*4882a593Smuzhiyun /* 140*4882a593Smuzhiyun * Try to remove devices marked for deferred removal. 141*4882a593Smuzhiyun */ 142*4882a593Smuzhiyun void dm_deferred_remove(void); 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun /* 145*4882a593Smuzhiyun * The device-mapper can be driven through one of two interfaces; 146*4882a593Smuzhiyun * ioctl or filesystem, depending which patch you have applied. 147*4882a593Smuzhiyun */ 148*4882a593Smuzhiyun int dm_interface_init(void); 149*4882a593Smuzhiyun void dm_interface_exit(void); 150*4882a593Smuzhiyun 151*4882a593Smuzhiyun /* 152*4882a593Smuzhiyun * sysfs interface 153*4882a593Smuzhiyun */ 154*4882a593Smuzhiyun int dm_sysfs_init(struct mapped_device *md); 155*4882a593Smuzhiyun void dm_sysfs_exit(struct mapped_device *md); 156*4882a593Smuzhiyun struct kobject *dm_kobject(struct mapped_device *md); 157*4882a593Smuzhiyun struct mapped_device *dm_get_from_kobject(struct kobject *kobj); 158*4882a593Smuzhiyun 159*4882a593Smuzhiyun /* 160*4882a593Smuzhiyun * The kobject helper 161*4882a593Smuzhiyun */ 162*4882a593Smuzhiyun void dm_kobject_release(struct kobject *kobj); 163*4882a593Smuzhiyun 164*4882a593Smuzhiyun /* 165*4882a593Smuzhiyun * Targets for linear and striped mappings 166*4882a593Smuzhiyun */ 167*4882a593Smuzhiyun int dm_linear_init(void); 168*4882a593Smuzhiyun void dm_linear_exit(void); 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun int dm_stripe_init(void); 171*4882a593Smuzhiyun void dm_stripe_exit(void); 172*4882a593Smuzhiyun 173*4882a593Smuzhiyun /* 174*4882a593Smuzhiyun * mapped_device operations 175*4882a593Smuzhiyun */ 176*4882a593Smuzhiyun void dm_destroy(struct mapped_device *md); 177*4882a593Smuzhiyun void dm_destroy_immediate(struct mapped_device *md); 178*4882a593Smuzhiyun int dm_open_count(struct mapped_device *md); 179*4882a593Smuzhiyun int dm_lock_for_deletion(struct mapped_device *md, bool mark_deferred, bool only_deferred); 180*4882a593Smuzhiyun int dm_cancel_deferred_remove(struct mapped_device *md); 181*4882a593Smuzhiyun int dm_request_based(struct mapped_device *md); 182*4882a593Smuzhiyun int dm_get_table_device(struct mapped_device *md, dev_t dev, fmode_t mode, 183*4882a593Smuzhiyun struct dm_dev **result); 184*4882a593Smuzhiyun void dm_put_table_device(struct mapped_device *md, struct dm_dev *d); 185*4882a593Smuzhiyun 186*4882a593Smuzhiyun int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action, 187*4882a593Smuzhiyun unsigned cookie); 188*4882a593Smuzhiyun 189*4882a593Smuzhiyun void dm_internal_suspend(struct mapped_device *md); 190*4882a593Smuzhiyun void dm_internal_resume(struct mapped_device *md); 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun int dm_io_init(void); 193*4882a593Smuzhiyun void dm_io_exit(void); 194*4882a593Smuzhiyun 195*4882a593Smuzhiyun int dm_kcopyd_init(void); 196*4882a593Smuzhiyun void dm_kcopyd_exit(void); 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun /* 199*4882a593Smuzhiyun * Mempool operations 200*4882a593Smuzhiyun */ 201*4882a593Smuzhiyun struct dm_md_mempools *dm_alloc_md_mempools(struct mapped_device *md, enum dm_queue_mode type, 202*4882a593Smuzhiyun unsigned integrity, unsigned per_bio_data_size, 203*4882a593Smuzhiyun unsigned min_pool_size); 204*4882a593Smuzhiyun void dm_free_md_mempools(struct dm_md_mempools *pools); 205*4882a593Smuzhiyun 206*4882a593Smuzhiyun /* 207*4882a593Smuzhiyun * Various helpers 208*4882a593Smuzhiyun */ 209*4882a593Smuzhiyun unsigned dm_get_reserved_bio_based_ios(void); 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun #endif 212