1 /* 2 * Internal header file _only_ for device mapper core 3 * 4 * Copyright (C) 2016 Red Hat, Inc. All rights reserved. 5 * 6 * This file is released under the LGPL. 7 */ 8 9 #ifndef DM_CORE_INTERNAL_H 10 #define DM_CORE_INTERNAL_H 11 12 #include <linux/kthread.h> 13 #include <linux/ktime.h> 14 #include <linux/genhd.h> 15 #include <linux/blk-mq.h> 16 17 #include <trace/events/block.h> 18 19 #include "dm.h" 20 21 #define DM_RESERVED_MAX_IOS 1024 22 #define DM_MAX_TARGETS 1048576 23 #define DM_MAX_TARGET_PARAMS 1024 24 25 struct dm_kobject_holder { 26 struct kobject kobj; 27 struct completion completion; 28 }; 29 30 /* 31 * DM core internal structures used directly by dm.c, dm-rq.c and dm-table.c. 32 * DM targets must _not_ deference a mapped_device or dm_table to directly 33 * access their members! 34 */ 35 36 struct mapped_device { 37 struct mutex suspend_lock; 38 39 struct mutex table_devices_lock; 40 struct list_head table_devices; 41 42 /* 43 * The current mapping (struct dm_table *). 44 * Use dm_get_live_table{_fast} or take suspend_lock for 45 * dereference. 46 */ 47 void __rcu *map; 48 49 unsigned long flags; 50 51 /* Protect queue and type against concurrent access. */ 52 struct mutex type_lock; 53 enum dm_queue_mode type; 54 55 int numa_node_id; 56 struct request_queue *queue; 57 58 atomic_t holders; 59 atomic_t open_count; 60 61 struct dm_target *immutable_target; 62 struct target_type *immutable_target_type; 63 64 char name[16]; 65 struct gendisk *disk; 66 struct dax_device *dax_dev; 67 68 /* 69 * A list of ios that arrived while we were suspended. 70 */ 71 struct work_struct work; 72 wait_queue_head_t wait; 73 spinlock_t deferred_lock; 74 struct bio_list deferred; 75 76 void *interface_ptr; 77 78 /* 79 * Event handling. 80 */ 81 wait_queue_head_t eventq; 82 atomic_t event_nr; 83 atomic_t uevent_seq; 84 struct list_head uevent_list; 85 spinlock_t uevent_lock; /* Protect access to uevent_list */ 86 87 /* the number of internal suspends */ 88 unsigned internal_suspend_count; 89 90 /* 91 * io objects are allocated from here. 92 */ 93 struct bio_set io_bs; 94 struct bio_set bs; 95 96 /* 97 * Processing queue (flush) 98 */ 99 struct workqueue_struct *wq; 100 101 /* 102 * freeze/thaw support require holding onto a super block 103 */ 104 struct super_block *frozen_sb; 105 106 /* forced geometry settings */ 107 struct hd_geometry geometry; 108 109 /* kobject and completion */ 110 struct dm_kobject_holder kobj_holder; 111 112 struct block_device *bdev; 113 114 int swap_bios; 115 struct semaphore swap_bios_semaphore; 116 struct mutex swap_bios_lock; 117 118 struct dm_stats stats; 119 120 /* for blk-mq request-based DM support */ 121 struct blk_mq_tag_set *tag_set; 122 bool init_tio_pdu:1; 123 124 struct srcu_struct io_barrier; 125 }; 126 127 void disable_discard(struct mapped_device *md); 128 void disable_write_same(struct mapped_device *md); 129 void disable_write_zeroes(struct mapped_device *md); 130 dm_get_size(struct mapped_device * md)131static inline sector_t dm_get_size(struct mapped_device *md) 132 { 133 return get_capacity(md->disk); 134 } 135 dm_get_stats(struct mapped_device * md)136static inline struct dm_stats *dm_get_stats(struct mapped_device *md) 137 { 138 return &md->stats; 139 } 140 141 #define DM_TABLE_MAX_DEPTH 16 142 143 struct dm_table { 144 struct mapped_device *md; 145 enum dm_queue_mode type; 146 147 /* btree table */ 148 unsigned int depth; 149 unsigned int counts[DM_TABLE_MAX_DEPTH]; /* in nodes */ 150 sector_t *index[DM_TABLE_MAX_DEPTH]; 151 152 unsigned int num_targets; 153 unsigned int num_allocated; 154 sector_t *highs; 155 struct dm_target *targets; 156 157 struct target_type *immutable_target_type; 158 159 bool integrity_supported:1; 160 bool singleton:1; 161 unsigned integrity_added:1; 162 163 /* 164 * Indicates the rw permissions for the new logical 165 * device. This should be a combination of FMODE_READ 166 * and FMODE_WRITE. 167 */ 168 fmode_t mode; 169 170 /* a list of devices used by this table */ 171 struct list_head devices; 172 173 /* events get handed up using this callback */ 174 void (*event_fn)(void *); 175 void *event_context; 176 177 struct dm_md_mempools *mempools; 178 }; 179 dm_get_completion_from_kobject(struct kobject * kobj)180static inline struct completion *dm_get_completion_from_kobject(struct kobject *kobj) 181 { 182 return &container_of(kobj, struct dm_kobject_holder, kobj)->completion; 183 } 184 185 unsigned __dm_get_module_param(unsigned *module_param, unsigned def, unsigned max); 186 dm_message_test_buffer_overflow(char * result,unsigned maxlen)187static inline bool dm_message_test_buffer_overflow(char *result, unsigned maxlen) 188 { 189 return !maxlen || strlen(result) + 1 >= maxlen; 190 } 191 192 extern atomic_t dm_global_event_nr; 193 extern wait_queue_head_t dm_global_eventq; 194 void dm_issue_global_event(void); 195 196 #endif 197