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/keyslot-manager.h>
18 #include <trace/events/block.h>
22 #define DM_RESERVED_MAX_IOS 1024
24 struct dm_kobject_holder {
26 struct completion completion;
30 * DM core internal structures used directly by dm.c, dm-rq.c and dm-table.c.
31 * DM targets must _not_ deference a mapped_device or dm_table to directly
32 * access their members!
35 struct mapped_device {
36 struct mutex suspend_lock;
38 struct mutex table_devices_lock;
39 struct list_head table_devices;
42 * The current mapping (struct dm_table *).
43 * Use dm_get_live_table{_fast} or take suspend_lock for
50 /* Protect queue and type against concurrent access. */
51 struct mutex type_lock;
52 enum dm_queue_mode type;
55 struct request_queue *queue;
60 struct dm_target *immutable_target;
61 struct target_type *immutable_target_type;
65 struct dax_device *dax_dev;
68 * A list of ios that arrived while we were suspended.
70 struct work_struct work;
71 wait_queue_head_t wait;
72 spinlock_t deferred_lock;
73 struct bio_list deferred;
80 wait_queue_head_t eventq;
83 struct list_head uevent_list;
84 spinlock_t uevent_lock; /* Protect access to uevent_list */
86 /* the number of internal suspends */
87 unsigned internal_suspend_count;
90 * io objects are allocated from here.
96 * Processing queue (flush)
98 struct workqueue_struct *wq;
100 /* forced geometry settings */
101 struct hd_geometry geometry;
103 /* kobject and completion */
104 struct dm_kobject_holder kobj_holder;
107 struct semaphore swap_bios_semaphore;
108 struct mutex swap_bios_lock;
110 struct dm_stats stats;
112 /* for blk-mq request-based DM support */
113 struct blk_mq_tag_set *tag_set;
116 struct srcu_struct io_barrier;
118 #ifdef CONFIG_BLK_DEV_ZONED
119 unsigned int nr_zones;
120 unsigned int *zwp_offset;
125 * Bits for the flags field of struct mapped_device.
127 #define DMF_BLOCK_IO_FOR_SUSPEND 0
128 #define DMF_SUSPENDED 1
130 #define DMF_FREEING 3
131 #define DMF_DELETING 4
132 #define DMF_NOFLUSH_SUSPENDING 5
133 #define DMF_DEFERRED_REMOVE 6
134 #define DMF_SUSPENDED_INTERNALLY 7
135 #define DMF_POST_SUSPENDING 8
136 #define DMF_EMULATE_ZONE_APPEND 9
138 void disable_discard(struct mapped_device *md);
139 void disable_write_same(struct mapped_device *md);
140 void disable_write_zeroes(struct mapped_device *md);
142 static inline sector_t dm_get_size(struct mapped_device *md)
144 return get_capacity(md->disk);
147 static inline struct dm_stats *dm_get_stats(struct mapped_device *md)
152 static inline bool dm_emulate_zone_append(struct mapped_device *md)
154 if (blk_queue_is_zoned(md->queue))
155 return test_bit(DMF_EMULATE_ZONE_APPEND, &md->flags);
159 #define DM_TABLE_MAX_DEPTH 16
162 struct mapped_device *md;
163 enum dm_queue_mode type;
167 unsigned int counts[DM_TABLE_MAX_DEPTH]; /* in nodes */
168 sector_t *index[DM_TABLE_MAX_DEPTH];
170 unsigned int num_targets;
171 unsigned int num_allocated;
173 struct dm_target *targets;
175 struct target_type *immutable_target_type;
177 bool integrity_supported:1;
179 unsigned integrity_added:1;
182 * Indicates the rw permissions for the new logical
183 * device. This should be a combination of FMODE_READ
188 /* a list of devices used by this table */
189 struct list_head devices;
191 /* events get handed up using this callback */
192 void (*event_fn)(void *);
195 struct dm_md_mempools *mempools;
197 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
198 struct blk_keyslot_manager *ksm;
203 * One of these is allocated per clone bio.
205 #define DM_TIO_MAGIC 7282014
206 struct dm_target_io {
209 struct dm_target *ti;
210 unsigned int target_bio_nr;
211 unsigned int *len_ptr;
217 * One of these is allocated per original bio.
218 * It contains the first clone used for that original.
220 #define DM_IO_MAGIC 5191977
223 struct mapped_device *md;
226 struct bio *orig_bio;
227 unsigned long start_time;
228 spinlock_t endio_lock;
229 struct dm_stats_aux stats_aux;
230 /* last member of dm_target_io is 'struct bio' */
231 struct dm_target_io tio;
234 static inline void dm_io_inc_pending(struct dm_io *io)
236 atomic_inc(&io->io_count);
239 void dm_io_dec_pending(struct dm_io *io, blk_status_t error);
241 static inline struct completion *dm_get_completion_from_kobject(struct kobject *kobj)
243 return &container_of(kobj, struct dm_kobject_holder, kobj)->completion;
246 unsigned __dm_get_module_param(unsigned *module_param, unsigned def, unsigned max);
248 static inline bool dm_message_test_buffer_overflow(char *result, unsigned maxlen)
250 return !maxlen || strlen(result) + 1 >= maxlen;
253 extern atomic_t dm_global_event_nr;
254 extern wait_queue_head_t dm_global_eventq;
255 void dm_issue_global_event(void);