Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005-2007 Red Hat GmbH |
| 3 | * |
| 4 | * A target that delays reads and/or writes and can send |
| 5 | * them to different devices. |
| 6 | * |
| 7 | * This file is released under the GPL. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/blkdev.h> |
| 13 | #include <linux/bio.h> |
| 14 | #include <linux/slab.h> |
| 15 | |
Mikulas Patocka | 586e80e | 2008-10-21 17:44:59 +0100 | [diff] [blame] | 16 | #include <linux/device-mapper.h> |
| 17 | |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 18 | #define DM_MSG_PREFIX "delay" |
| 19 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 20 | struct delay_class { |
| 21 | struct dm_dev *dev; |
| 22 | sector_t start; |
| 23 | unsigned delay; |
| 24 | unsigned ops; |
| 25 | }; |
| 26 | |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 27 | struct delay_c { |
| 28 | struct timer_list delay_timer; |
Alasdair G Kergon | ac81864 | 2007-07-12 17:26:47 +0100 | [diff] [blame] | 29 | struct mutex timer_lock; |
Mikulas Patocka | 718822c | 2013-11-15 16:12:20 -0500 | [diff] [blame] | 30 | struct workqueue_struct *kdelayd_wq; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 31 | struct work_struct flush_expired_bios; |
| 32 | struct list_head delayed_bios; |
| 33 | atomic_t may_delay; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 34 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 35 | struct delay_class read; |
| 36 | struct delay_class write; |
Mikulas Patocka | cda6b5a | 2018-04-17 00:33:14 +0200 | [diff] [blame] | 37 | struct delay_class flush; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 38 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 39 | int argc; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 42 | struct dm_delay_info { |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 43 | struct delay_c *context; |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 44 | struct delay_class *class; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 45 | struct list_head list; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 46 | unsigned long expires; |
| 47 | }; |
| 48 | |
| 49 | static DEFINE_MUTEX(delayed_bios_lock); |
| 50 | |
Kees Cook | 8376d3c | 2017-10-16 17:01:48 -0700 | [diff] [blame] | 51 | static void handle_delayed_timer(struct timer_list *t) |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 52 | { |
Kees Cook | 8376d3c | 2017-10-16 17:01:48 -0700 | [diff] [blame] | 53 | struct delay_c *dc = from_timer(dc, t, delay_timer); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 54 | |
Mikulas Patocka | 718822c | 2013-11-15 16:12:20 -0500 | [diff] [blame] | 55 | queue_work(dc->kdelayd_wq, &dc->flush_expired_bios); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static void queue_timeout(struct delay_c *dc, unsigned long expires) |
| 59 | { |
Alasdair G Kergon | ac81864 | 2007-07-12 17:26:47 +0100 | [diff] [blame] | 60 | mutex_lock(&dc->timer_lock); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 61 | |
| 62 | if (!timer_pending(&dc->delay_timer) || expires < dc->delay_timer.expires) |
| 63 | mod_timer(&dc->delay_timer, expires); |
| 64 | |
Alasdair G Kergon | ac81864 | 2007-07-12 17:26:47 +0100 | [diff] [blame] | 65 | mutex_unlock(&dc->timer_lock); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static void flush_bios(struct bio *bio) |
| 69 | { |
| 70 | struct bio *n; |
| 71 | |
| 72 | while (bio) { |
| 73 | n = bio->bi_next; |
| 74 | bio->bi_next = NULL; |
Christoph Hellwig | ed00aab | 2020-07-01 10:59:44 +0200 | [diff] [blame] | 75 | submit_bio_noacct(bio); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 76 | bio = n; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | static struct bio *flush_delayed_bios(struct delay_c *dc, int flush_all) |
| 81 | { |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 82 | struct dm_delay_info *delayed, *next; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 83 | unsigned long next_expires = 0; |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 84 | unsigned long start_timer = 0; |
Alasdair G Kergon | 051814c | 2007-10-19 22:38:55 +0100 | [diff] [blame] | 85 | struct bio_list flush_bios = { }; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 86 | |
| 87 | mutex_lock(&delayed_bios_lock); |
| 88 | list_for_each_entry_safe(delayed, next, &dc->delayed_bios, list) { |
| 89 | if (flush_all || time_after_eq(jiffies, delayed->expires)) { |
Mikulas Patocka | 4206546 | 2013-11-15 16:12:51 -0500 | [diff] [blame] | 90 | struct bio *bio = dm_bio_from_per_bio_data(delayed, |
| 91 | sizeof(struct dm_delay_info)); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 92 | list_del(&delayed->list); |
Mikulas Patocka | 4206546 | 2013-11-15 16:12:51 -0500 | [diff] [blame] | 93 | bio_list_add(&flush_bios, bio); |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 94 | delayed->class->ops--; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 95 | continue; |
| 96 | } |
| 97 | |
| 98 | if (!start_timer) { |
| 99 | start_timer = 1; |
| 100 | next_expires = delayed->expires; |
| 101 | } else |
| 102 | next_expires = min(next_expires, delayed->expires); |
| 103 | } |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 104 | mutex_unlock(&delayed_bios_lock); |
| 105 | |
| 106 | if (start_timer) |
| 107 | queue_timeout(dc, next_expires); |
| 108 | |
| 109 | return bio_list_get(&flush_bios); |
| 110 | } |
| 111 | |
| 112 | static void flush_expired_bios(struct work_struct *work) |
| 113 | { |
| 114 | struct delay_c *dc; |
| 115 | |
| 116 | dc = container_of(work, struct delay_c, flush_expired_bios); |
| 117 | flush_bios(flush_delayed_bios(dc, 0)); |
| 118 | } |
| 119 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 120 | static void delay_dtr(struct dm_target *ti) |
| 121 | { |
| 122 | struct delay_c *dc = ti->private; |
| 123 | |
Mikulas Patocka | 81bc6d1 | 2019-04-25 12:07:54 -0400 | [diff] [blame] | 124 | if (dc->kdelayd_wq) |
| 125 | destroy_workqueue(dc->kdelayd_wq); |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 126 | |
| 127 | if (dc->read.dev) |
| 128 | dm_put_device(ti, dc->read.dev); |
| 129 | if (dc->write.dev) |
| 130 | dm_put_device(ti, dc->write.dev); |
Mikulas Patocka | cda6b5a | 2018-04-17 00:33:14 +0200 | [diff] [blame] | 131 | if (dc->flush.dev) |
| 132 | dm_put_device(ti, dc->flush.dev); |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 133 | |
| 134 | mutex_destroy(&dc->timer_lock); |
| 135 | |
| 136 | kfree(dc); |
| 137 | } |
| 138 | |
| 139 | static int delay_class_ctr(struct dm_target *ti, struct delay_class *c, char **argv) |
| 140 | { |
| 141 | int ret; |
| 142 | unsigned long long tmpll; |
| 143 | char dummy; |
| 144 | |
Milan Broz | ef87bfc | 2018-11-07 22:24:55 +0100 | [diff] [blame] | 145 | if (sscanf(argv[1], "%llu%c", &tmpll, &dummy) != 1 || tmpll != (sector_t)tmpll) { |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 146 | ti->error = "Invalid device sector"; |
| 147 | return -EINVAL; |
| 148 | } |
| 149 | c->start = tmpll; |
| 150 | |
| 151 | if (sscanf(argv[2], "%u%c", &c->delay, &dummy) != 1) { |
| 152 | ti->error = "Invalid delay"; |
| 153 | return -EINVAL; |
| 154 | } |
| 155 | |
| 156 | ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &c->dev); |
| 157 | if (ret) { |
| 158 | ti->error = "Device lookup failed"; |
| 159 | return ret; |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 165 | /* |
| 166 | * Mapping parameters: |
| 167 | * <device> <offset> <delay> [<write_device> <write_offset> <write_delay>] |
| 168 | * |
| 169 | * With separate write parameters, the first set is only used for reads. |
Tomohiro Kusumi | f49e869 | 2015-10-28 04:38:56 +0900 | [diff] [blame] | 170 | * Offsets are specified in sectors. |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 171 | * Delays are specified in milliseconds. |
| 172 | */ |
| 173 | static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv) |
| 174 | { |
| 175 | struct delay_c *dc; |
Vivek Goyal | e80d1c8 | 2015-07-31 09:20:36 -0400 | [diff] [blame] | 176 | int ret; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 177 | |
Mikulas Patocka | cda6b5a | 2018-04-17 00:33:14 +0200 | [diff] [blame] | 178 | if (argc != 3 && argc != 6 && argc != 9) { |
| 179 | ti->error = "Requires exactly 3, 6 or 9 arguments"; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 180 | return -EINVAL; |
| 181 | } |
| 182 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 183 | dc = kzalloc(sizeof(*dc), GFP_KERNEL); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 184 | if (!dc) { |
| 185 | ti->error = "Cannot allocate context"; |
| 186 | return -ENOMEM; |
| 187 | } |
| 188 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 189 | ti->private = dc; |
Kees Cook | 8376d3c | 2017-10-16 17:01:48 -0700 | [diff] [blame] | 190 | timer_setup(&dc->delay_timer, handle_delayed_timer, 0); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 191 | INIT_WORK(&dc->flush_expired_bios, flush_expired_bios); |
| 192 | INIT_LIST_HEAD(&dc->delayed_bios); |
Alasdair G Kergon | ac81864 | 2007-07-12 17:26:47 +0100 | [diff] [blame] | 193 | mutex_init(&dc->timer_lock); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 194 | atomic_set(&dc->may_delay, 1); |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 195 | dc->argc = argc; |
| 196 | |
| 197 | ret = delay_class_ctr(ti, &dc->read, argv); |
| 198 | if (ret) |
| 199 | goto bad; |
| 200 | |
| 201 | if (argc == 3) { |
| 202 | ret = delay_class_ctr(ti, &dc->write, argv); |
| 203 | if (ret) |
| 204 | goto bad; |
Mikulas Patocka | cda6b5a | 2018-04-17 00:33:14 +0200 | [diff] [blame] | 205 | ret = delay_class_ctr(ti, &dc->flush, argv); |
| 206 | if (ret) |
| 207 | goto bad; |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 208 | goto out; |
| 209 | } |
| 210 | |
| 211 | ret = delay_class_ctr(ti, &dc->write, argv + 3); |
| 212 | if (ret) |
| 213 | goto bad; |
Mikulas Patocka | cda6b5a | 2018-04-17 00:33:14 +0200 | [diff] [blame] | 214 | if (argc == 6) { |
| 215 | ret = delay_class_ctr(ti, &dc->flush, argv + 3); |
| 216 | if (ret) |
| 217 | goto bad; |
| 218 | goto out; |
| 219 | } |
| 220 | |
| 221 | ret = delay_class_ctr(ti, &dc->flush, argv + 6); |
| 222 | if (ret) |
| 223 | goto bad; |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 224 | |
| 225 | out: |
| 226 | dc->kdelayd_wq = alloc_workqueue("kdelayd", WQ_MEM_RECLAIM, 0); |
| 227 | if (!dc->kdelayd_wq) { |
| 228 | ret = -EINVAL; |
| 229 | DMERR("Couldn't start kdelayd"); |
| 230 | goto bad; |
| 231 | } |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 232 | |
Alasdair G Kergon | 55a62ee | 2013-03-01 22:45:47 +0000 | [diff] [blame] | 233 | ti->num_flush_bios = 1; |
| 234 | ti->num_discard_bios = 1; |
Mike Snitzer | 30187e1 | 2016-01-31 13:28:26 -0500 | [diff] [blame] | 235 | ti->per_io_data_size = sizeof(struct dm_delay_info); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 236 | return 0; |
| 237 | |
| 238 | bad: |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 239 | delay_dtr(ti); |
Vivek Goyal | e80d1c8 | 2015-07-31 09:20:36 -0400 | [diff] [blame] | 240 | return ret; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 243 | static int delay_bio(struct delay_c *dc, struct delay_class *c, struct bio *bio) |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 244 | { |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 245 | struct dm_delay_info *delayed; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 246 | unsigned long expires = 0; |
| 247 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 248 | if (!c->delay || !atomic_read(&dc->may_delay)) |
Tomohiro Kusumi | 340c9ec | 2015-10-28 04:38:55 +0900 | [diff] [blame] | 249 | return DM_MAPIO_REMAPPED; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 250 | |
Mikulas Patocka | 4206546 | 2013-11-15 16:12:51 -0500 | [diff] [blame] | 251 | delayed = dm_per_bio_data(bio, sizeof(struct dm_delay_info)); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 252 | |
| 253 | delayed->context = dc; |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 254 | delayed->expires = expires = jiffies + msecs_to_jiffies(c->delay); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 255 | |
| 256 | mutex_lock(&delayed_bios_lock); |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 257 | c->ops++; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 258 | list_add_tail(&delayed->list, &dc->delayed_bios); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 259 | mutex_unlock(&delayed_bios_lock); |
| 260 | |
| 261 | queue_timeout(dc, expires); |
| 262 | |
Tomohiro Kusumi | 340c9ec | 2015-10-28 04:38:55 +0900 | [diff] [blame] | 263 | return DM_MAPIO_SUBMITTED; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static void delay_presuspend(struct dm_target *ti) |
| 267 | { |
| 268 | struct delay_c *dc = ti->private; |
| 269 | |
| 270 | atomic_set(&dc->may_delay, 0); |
| 271 | del_timer_sync(&dc->delay_timer); |
| 272 | flush_bios(flush_delayed_bios(dc, 1)); |
| 273 | } |
| 274 | |
| 275 | static void delay_resume(struct dm_target *ti) |
| 276 | { |
| 277 | struct delay_c *dc = ti->private; |
| 278 | |
| 279 | atomic_set(&dc->may_delay, 1); |
| 280 | } |
| 281 | |
Mikulas Patocka | 7de3ee5 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 282 | static int delay_map(struct dm_target *ti, struct bio *bio) |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 283 | { |
| 284 | struct delay_c *dc = ti->private; |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 285 | struct delay_class *c; |
| 286 | struct dm_delay_info *delayed = dm_per_bio_data(bio, sizeof(struct dm_delay_info)); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 287 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 288 | if (bio_data_dir(bio) == WRITE) { |
Mikulas Patocka | cda6b5a | 2018-04-17 00:33:14 +0200 | [diff] [blame] | 289 | if (unlikely(bio->bi_opf & REQ_PREFLUSH)) |
| 290 | c = &dc->flush; |
| 291 | else |
| 292 | c = &dc->write; |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 293 | } else { |
| 294 | c = &dc->read; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 295 | } |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 296 | delayed->class = c; |
| 297 | bio_set_dev(bio, c->dev->bdev); |
| 298 | if (bio_sectors(bio)) |
| 299 | bio->bi_iter.bi_sector = c->start + dm_target_offset(ti, bio->bi_iter.bi_sector); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 300 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 301 | return delay_bio(dc, c, bio); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 304 | #define DMEMIT_DELAY_CLASS(c) \ |
| 305 | DMEMIT("%s %llu %u", (c)->dev->name, (unsigned long long)(c)->start, (c)->delay) |
| 306 | |
Mikulas Patocka | fd7c092 | 2013-03-01 22:45:44 +0000 | [diff] [blame] | 307 | static void delay_status(struct dm_target *ti, status_type_t type, |
| 308 | unsigned status_flags, char *result, unsigned maxlen) |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 309 | { |
| 310 | struct delay_c *dc = ti->private; |
| 311 | int sz = 0; |
| 312 | |
| 313 | switch (type) { |
| 314 | case STATUSTYPE_INFO: |
Mikulas Patocka | cda6b5a | 2018-04-17 00:33:14 +0200 | [diff] [blame] | 315 | DMEMIT("%u %u %u", dc->read.ops, dc->write.ops, dc->flush.ops); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 316 | break; |
| 317 | |
| 318 | case STATUSTYPE_TABLE: |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 319 | DMEMIT_DELAY_CLASS(&dc->read); |
| 320 | if (dc->argc >= 6) { |
| 321 | DMEMIT(" "); |
| 322 | DMEMIT_DELAY_CLASS(&dc->write); |
| 323 | } |
Mikulas Patocka | cda6b5a | 2018-04-17 00:33:14 +0200 | [diff] [blame] | 324 | if (dc->argc >= 9) { |
| 325 | DMEMIT(" "); |
| 326 | DMEMIT_DELAY_CLASS(&dc->flush); |
| 327 | } |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 328 | break; |
| 329 | } |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Mike Snitzer | af4874e | 2009-06-22 10:12:33 +0100 | [diff] [blame] | 332 | static int delay_iterate_devices(struct dm_target *ti, |
| 333 | iterate_devices_callout_fn fn, void *data) |
| 334 | { |
| 335 | struct delay_c *dc = ti->private; |
| 336 | int ret = 0; |
| 337 | |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 338 | ret = fn(ti, dc->read.dev, dc->read.start, ti->len, data); |
Mike Snitzer | af4874e | 2009-06-22 10:12:33 +0100 | [diff] [blame] | 339 | if (ret) |
| 340 | goto out; |
Mikulas Patocka | 3876ac7 | 2018-04-17 00:33:13 +0200 | [diff] [blame] | 341 | ret = fn(ti, dc->write.dev, dc->write.start, ti->len, data); |
| 342 | if (ret) |
| 343 | goto out; |
Mikulas Patocka | cda6b5a | 2018-04-17 00:33:14 +0200 | [diff] [blame] | 344 | ret = fn(ti, dc->flush.dev, dc->flush.start, ti->len, data); |
| 345 | if (ret) |
| 346 | goto out; |
Mike Snitzer | af4874e | 2009-06-22 10:12:33 +0100 | [diff] [blame] | 347 | |
| 348 | out: |
| 349 | return ret; |
| 350 | } |
| 351 | |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 352 | static struct target_type delay_target = { |
| 353 | .name = "delay", |
Mikulas Patocka | fd7c092 | 2013-03-01 22:45:44 +0000 | [diff] [blame] | 354 | .version = {1, 2, 1}, |
Mikulas Patocka | e2460f2 | 2017-04-18 16:51:48 -0400 | [diff] [blame] | 355 | .features = DM_TARGET_PASSES_INTEGRITY, |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 356 | .module = THIS_MODULE, |
| 357 | .ctr = delay_ctr, |
| 358 | .dtr = delay_dtr, |
| 359 | .map = delay_map, |
| 360 | .presuspend = delay_presuspend, |
| 361 | .resume = delay_resume, |
| 362 | .status = delay_status, |
Mike Snitzer | af4874e | 2009-06-22 10:12:33 +0100 | [diff] [blame] | 363 | .iterate_devices = delay_iterate_devices, |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 364 | }; |
| 365 | |
| 366 | static int __init dm_delay_init(void) |
| 367 | { |
Mikulas Patocka | 4206546 | 2013-11-15 16:12:51 -0500 | [diff] [blame] | 368 | int r; |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 369 | |
| 370 | r = dm_register_target(&delay_target); |
| 371 | if (r < 0) { |
| 372 | DMERR("register failed %d", r); |
| 373 | goto bad_register; |
| 374 | } |
| 375 | |
| 376 | return 0; |
| 377 | |
| 378 | bad_register: |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 379 | return r; |
| 380 | } |
| 381 | |
| 382 | static void __exit dm_delay_exit(void) |
| 383 | { |
Mikulas Patocka | 10d3bd0 | 2009-01-06 03:04:58 +0000 | [diff] [blame] | 384 | dm_unregister_target(&delay_target); |
Heinz Mauelshagen | 26b9f22 | 2007-05-09 02:33:06 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /* Module hooks */ |
| 388 | module_init(dm_delay_init); |
| 389 | module_exit(dm_delay_exit); |
| 390 | |
| 391 | MODULE_DESCRIPTION(DM_NAME " delay target"); |
| 392 | MODULE_AUTHOR("Heinz Mauelshagen <mauelshagen@redhat.com>"); |
| 393 | MODULE_LICENSE("GPL"); |