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