blob: 780aec612dac91b9199fffe7f901ba531e44098e [file] [log] [blame]
Mike Snitzer4cc96132016-05-12 16:28:10 -04001/*
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>
Mike Snitzer33bd6f02020-09-19 13:09:11 -040014#include <linux/genhd.h>
Mike Snitzer4cc96132016-05-12 16:28:10 -040015#include <linux/blk-mq.h>
Satya Tangiralac2b86b72020-06-16 14:33:37 -070016#include <linux/keyslot-manager.h>
Mike Snitzer4cc96132016-05-12 16:28:10 -040017
18#include <trace/events/block.h>
19
20#include "dm.h"
21
22#define DM_RESERVED_MAX_IOS 1024
23
24struct dm_kobject_holder {
25 struct kobject kobj;
26 struct completion completion;
27};
28
29/*
Mike Snitzer33bd6f02020-09-19 13:09:11 -040030 * 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!
Mike Snitzer4cc96132016-05-12 16:28:10 -040033 */
Mike Snitzer33bd6f02020-09-19 13:09:11 -040034
Mike Snitzer4cc96132016-05-12 16:28:10 -040035struct mapped_device {
Mike Snitzer4cc96132016-05-12 16:28:10 -040036 struct mutex suspend_lock;
37
Mike Snitzer72d711c2018-05-22 18:26:20 -040038 struct mutex table_devices_lock;
39 struct list_head table_devices;
40
Mike Snitzer4cc96132016-05-12 16:28:10 -040041 /*
42 * The current mapping (struct dm_table *).
43 * Use dm_get_live_table{_fast} or take suspend_lock for
44 * dereference.
45 */
46 void __rcu *map;
47
Mike Snitzer4cc96132016-05-12 16:28:10 -040048 unsigned long flags;
49
Mike Snitzer4cc96132016-05-12 16:28:10 -040050 /* Protect queue and type against concurrent access. */
51 struct mutex type_lock;
Mike Snitzer72d711c2018-05-22 18:26:20 -040052 enum dm_queue_mode type;
53
54 int numa_node_id;
55 struct request_queue *queue;
Mike Snitzer4cc96132016-05-12 16:28:10 -040056
57 atomic_t holders;
58 atomic_t open_count;
59
60 struct dm_target *immutable_target;
61 struct target_type *immutable_target_type;
62
Mike Snitzer72d711c2018-05-22 18:26:20 -040063 char name[16];
Mike Snitzer4cc96132016-05-12 16:28:10 -040064 struct gendisk *disk;
Dan Williamsf26c5712017-04-12 12:35:44 -070065 struct dax_device *dax_dev;
Mike Snitzer4cc96132016-05-12 16:28:10 -040066
67 /*
68 * A list of ios that arrived while we were suspended.
69 */
Mike Snitzer4cc96132016-05-12 16:28:10 -040070 struct work_struct work;
Mike Snitzer72d711c2018-05-22 18:26:20 -040071 wait_queue_head_t wait;
Mike Snitzer4cc96132016-05-12 16:28:10 -040072 spinlock_t deferred_lock;
73 struct bio_list deferred;
74
Mike Snitzer72d711c2018-05-22 18:26:20 -040075 void *interface_ptr;
76
Mike Snitzer4cc96132016-05-12 16:28:10 -040077 /*
78 * Event handling.
79 */
80 wait_queue_head_t eventq;
81 atomic_t event_nr;
82 atomic_t uevent_seq;
83 struct list_head uevent_list;
84 spinlock_t uevent_lock; /* Protect access to uevent_list */
85
86 /* the number of internal suspends */
87 unsigned internal_suspend_count;
88
89 /*
Mike Snitzer4cc96132016-05-12 16:28:10 -040090 * io objects are allocated from here.
91 */
Kent Overstreet6f1c8192018-05-20 18:25:53 -040092 struct bio_set io_bs;
93 struct bio_set bs;
Mike Snitzer4cc96132016-05-12 16:28:10 -040094
95 /*
Mike Snitzer72d711c2018-05-22 18:26:20 -040096 * Processing queue (flush)
97 */
98 struct workqueue_struct *wq;
99
Mike Snitzer4cc96132016-05-12 16:28:10 -0400100 /* forced geometry settings */
101 struct hd_geometry geometry;
102
Mike Snitzer4cc96132016-05-12 16:28:10 -0400103 /* kobject and completion */
104 struct dm_kobject_holder kobj_holder;
105
Mike Snitzer72d711c2018-05-22 18:26:20 -0400106 struct block_device *bdev;
107
Mikulas Patocka1f145072021-02-10 15:26:23 -0500108 int swap_bios;
109 struct semaphore swap_bios_semaphore;
110 struct mutex swap_bios_lock;
111
Mike Snitzer4cc96132016-05-12 16:28:10 -0400112 struct dm_stats stats;
113
Mike Snitzer4cc96132016-05-12 16:28:10 -0400114 /* for blk-mq request-based DM support */
115 struct blk_mq_tag_set *tag_set;
Mike Snitzer4cc96132016-05-12 16:28:10 -0400116 bool init_tio_pdu:1;
Mikulas Patocka856eb092017-10-31 19:33:02 -0400117
118 struct srcu_struct io_barrier;
Mike Snitzer4cc96132016-05-12 16:28:10 -0400119};
120
Mike Snitzerbcb44432019-04-03 12:23:11 -0400121void disable_discard(struct mapped_device *md);
Mike Snitzer4cc96132016-05-12 16:28:10 -0400122void disable_write_same(struct mapped_device *md);
Christoph Hellwigac62d622017-04-05 19:21:05 +0200123void disable_write_zeroes(struct mapped_device *md);
Mike Snitzer4cc96132016-05-12 16:28:10 -0400124
Mike Snitzer33bd6f02020-09-19 13:09:11 -0400125static inline sector_t dm_get_size(struct mapped_device *md)
126{
127 return get_capacity(md->disk);
128}
129
130static inline struct dm_stats *dm_get_stats(struct mapped_device *md)
131{
132 return &md->stats;
133}
134
135#define DM_TABLE_MAX_DEPTH 16
136
137struct dm_table {
138 struct mapped_device *md;
139 enum dm_queue_mode type;
140
141 /* btree table */
142 unsigned int depth;
143 unsigned int counts[DM_TABLE_MAX_DEPTH]; /* in nodes */
144 sector_t *index[DM_TABLE_MAX_DEPTH];
145
146 unsigned int num_targets;
147 unsigned int num_allocated;
148 sector_t *highs;
149 struct dm_target *targets;
150
151 struct target_type *immutable_target_type;
152
153 bool integrity_supported:1;
154 bool singleton:1;
155 unsigned integrity_added:1;
156
157 /*
158 * Indicates the rw permissions for the new logical
159 * device. This should be a combination of FMODE_READ
160 * and FMODE_WRITE.
161 */
162 fmode_t mode;
163
164 /* a list of devices used by this table */
165 struct list_head devices;
166
167 /* events get handed up using this callback */
168 void (*event_fn)(void *);
169 void *event_context;
170
171 struct dm_md_mempools *mempools;
Eric Biggers537d3bb2021-02-12 11:53:49 -0800172
173#ifdef CONFIG_BLK_INLINE_ENCRYPTION
174 struct blk_keyslot_manager *ksm;
175#endif
Mike Snitzer33bd6f02020-09-19 13:09:11 -0400176};
177
Mike Snitzer4cc96132016-05-12 16:28:10 -0400178static inline struct completion *dm_get_completion_from_kobject(struct kobject *kobj)
179{
180 return &container_of(kobj, struct dm_kobject_holder, kobj)->completion;
181}
182
183unsigned __dm_get_module_param(unsigned *module_param, unsigned def, unsigned max);
184
185static inline bool dm_message_test_buffer_overflow(char *result, unsigned maxlen)
186{
187 return !maxlen || strlen(result) + 1 >= maxlen;
188}
189
Mikulas Patocka93e64422017-01-16 16:05:59 -0500190extern atomic_t dm_global_event_nr;
191extern wait_queue_head_t dm_global_eventq;
Mikulas Patocka62e08242017-09-20 07:29:49 -0400192void dm_issue_global_event(void);
Mikulas Patocka93e64422017-01-16 16:05:59 -0500193
Mike Snitzer4cc96132016-05-12 16:28:10 -0400194#endif