2 * Internal header file _only_ for device mapper core
4 * Copyright (C) 2016 Red Hat, Inc. All rights reserved.
6 * This file is released under the LGPL.
9 #ifndef DM_CORE_INTERNAL_H
10 #define DM_CORE_INTERNAL_H
12 #include <linux/kthread.h>
13 #include <linux/ktime.h>
14 #include <linux/genhd.h>
15 #include <linux/blk-mq.h>
16 #include <linux/blk-crypto-profile.h>
18 #include <trace/events/block.h>
23 #define DM_RESERVED_MAX_IOS 1024
25 struct dm_kobject_holder {
27 struct completion completion;
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!
36 struct mapped_device {
37 struct mutex suspend_lock;
39 struct mutex table_devices_lock;
40 struct list_head table_devices;
43 * The current mapping (struct dm_table *).
44 * Use dm_get_live_table{_fast} or take suspend_lock for
51 /* Protect queue and type against concurrent access. */
52 struct mutex type_lock;
53 enum dm_queue_mode type;
56 struct request_queue *queue;
61 struct dm_target *immutable_target;
62 struct target_type *immutable_target_type;
66 struct dax_device *dax_dev;
69 * A list of ios that arrived while we were suspended.
71 struct work_struct work;
72 wait_queue_head_t wait;
73 spinlock_t deferred_lock;
74 struct bio_list deferred;
81 wait_queue_head_t eventq;
84 struct list_head uevent_list;
85 spinlock_t uevent_lock; /* Protect access to uevent_list */
87 /* the number of internal suspends */
88 unsigned internal_suspend_count;
91 * io objects are allocated from here.
97 * Processing queue (flush)
99 struct workqueue_struct *wq;
101 /* forced geometry settings */
102 struct hd_geometry geometry;
104 /* kobject and completion */
105 struct dm_kobject_holder kobj_holder;
108 struct semaphore swap_bios_semaphore;
109 struct mutex swap_bios_lock;
111 struct dm_stats stats;
113 /* for blk-mq request-based DM support */
114 struct blk_mq_tag_set *tag_set;
117 struct srcu_struct io_barrier;
119 #ifdef CONFIG_BLK_DEV_ZONED
120 unsigned int nr_zones;
121 unsigned int *zwp_offset;
125 struct dm_ima_measurements ima;
130 * Bits for the flags field of struct mapped_device.
132 #define DMF_BLOCK_IO_FOR_SUSPEND 0
133 #define DMF_SUSPENDED 1
135 #define DMF_FREEING 3
136 #define DMF_DELETING 4
137 #define DMF_NOFLUSH_SUSPENDING 5
138 #define DMF_DEFERRED_REMOVE 6
139 #define DMF_SUSPENDED_INTERNALLY 7
140 #define DMF_POST_SUSPENDING 8
141 #define DMF_EMULATE_ZONE_APPEND 9
143 void disable_discard(struct mapped_device *md);
144 void disable_write_same(struct mapped_device *md);
145 void disable_write_zeroes(struct mapped_device *md);
147 static inline sector_t dm_get_size(struct mapped_device *md)
149 return get_capacity(md->disk);
152 static inline struct dm_stats *dm_get_stats(struct mapped_device *md)
157 static inline bool dm_emulate_zone_append(struct mapped_device *md)
159 if (blk_queue_is_zoned(md->queue))
160 return test_bit(DMF_EMULATE_ZONE_APPEND, &md->flags);
164 #define DM_TABLE_MAX_DEPTH 16
167 struct mapped_device *md;
168 enum dm_queue_mode type;
172 unsigned int counts[DM_TABLE_MAX_DEPTH]; /* in nodes */
173 sector_t *index[DM_TABLE_MAX_DEPTH];
175 unsigned int num_targets;
176 unsigned int num_allocated;
178 struct dm_target *targets;
180 struct target_type *immutable_target_type;
182 bool integrity_supported:1;
184 unsigned integrity_added:1;
187 * Indicates the rw permissions for the new logical
188 * device. This should be a combination of FMODE_READ
193 /* a list of devices used by this table */
194 struct list_head devices;
196 /* events get handed up using this callback */
197 void (*event_fn)(void *);
200 struct dm_md_mempools *mempools;
202 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
203 struct blk_crypto_profile *crypto_profile;
208 * One of these is allocated per clone bio.
210 #define DM_TIO_MAGIC 7282014
211 struct dm_target_io {
214 struct dm_target *ti;
215 unsigned int target_bio_nr;
216 unsigned int *len_ptr;
222 * One of these is allocated per original bio.
223 * It contains the first clone used for that original.
225 #define DM_IO_MAGIC 5191977
228 struct mapped_device *md;
231 struct bio *orig_bio;
232 unsigned long start_time;
233 spinlock_t endio_lock;
234 struct dm_stats_aux stats_aux;
235 /* last member of dm_target_io is 'struct bio' */
236 struct dm_target_io tio;
239 static inline void dm_io_inc_pending(struct dm_io *io)
241 atomic_inc(&io->io_count);
244 void dm_io_dec_pending(struct dm_io *io, blk_status_t error);
246 static inline struct completion *dm_get_completion_from_kobject(struct kobject *kobj)
248 return &container_of(kobj, struct dm_kobject_holder, kobj)->completion;
251 unsigned __dm_get_module_param(unsigned *module_param, unsigned def, unsigned max);
253 static inline bool dm_message_test_buffer_overflow(char *result, unsigned maxlen)
255 return !maxlen || strlen(result) + 1 >= maxlen;
258 extern atomic_t dm_global_event_nr;
259 extern wait_queue_head_t dm_global_eventq;
260 void dm_issue_global_event(void);