Lines Matching +full:dc +full:- +full:dc

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2005-2007 Red Hat GmbH
18 #include <linux/device-mapper.h>
55 struct delay_c *dc = from_timer(dc, t, delay_timer); in handle_delayed_timer() local
57 queue_work(dc->kdelayd_wq, &dc->flush_expired_bios); in handle_delayed_timer()
60 static void queue_timeout(struct delay_c *dc, unsigned long expires) in queue_timeout() argument
62 timer_reduce(&dc->delay_timer, expires); in queue_timeout()
65 static inline bool delay_is_fast(struct delay_c *dc) in delay_is_fast() argument
67 return !!dc->worker; in delay_is_fast()
75 n = bio->bi_next; in flush_bios()
76 bio->bi_next = NULL; in flush_bios()
82 static void flush_delayed_bios(struct delay_c *dc, bool flush_all) in flush_delayed_bios() argument
91 mutex_lock(&dc->process_bios_lock); in flush_delayed_bios()
92 spin_lock(&dc->delayed_bios_lock); in flush_delayed_bios()
93 list_replace_init(&dc->delayed_bios, &local_list); in flush_delayed_bios()
94 spin_unlock(&dc->delayed_bios_lock); in flush_delayed_bios()
97 if (flush_all || time_after_eq(jiffies, delayed->expires)) { in flush_delayed_bios()
100 list_del(&delayed->list); in flush_delayed_bios()
102 delayed->class->ops--; in flush_delayed_bios()
106 if (!delay_is_fast(dc)) { in flush_delayed_bios()
109 next_expires = delayed->expires; in flush_delayed_bios()
111 next_expires = min(next_expires, delayed->expires); in flush_delayed_bios()
115 spin_lock(&dc->delayed_bios_lock); in flush_delayed_bios()
116 list_splice(&local_list, &dc->delayed_bios); in flush_delayed_bios()
117 spin_unlock(&dc->delayed_bios_lock); in flush_delayed_bios()
118 mutex_unlock(&dc->process_bios_lock); in flush_delayed_bios()
121 queue_timeout(dc, next_expires); in flush_delayed_bios()
128 struct delay_c *dc = data; in flush_worker_fn() local
131 flush_delayed_bios(dc, false); in flush_worker_fn()
132 spin_lock(&dc->delayed_bios_lock); in flush_worker_fn()
133 if (unlikely(list_empty(&dc->delayed_bios))) { in flush_worker_fn()
135 spin_unlock(&dc->delayed_bios_lock); in flush_worker_fn()
138 spin_unlock(&dc->delayed_bios_lock); in flush_worker_fn()
148 struct delay_c *dc; in flush_expired_bios() local
150 dc = container_of(work, struct delay_c, flush_expired_bios); in flush_expired_bios()
151 flush_delayed_bios(dc, false); in flush_expired_bios()
156 struct delay_c *dc = ti->private; in delay_dtr() local
158 if (dc->kdelayd_wq) { in delay_dtr()
159 timer_shutdown_sync(&dc->delay_timer); in delay_dtr()
160 destroy_workqueue(dc->kdelayd_wq); in delay_dtr()
163 if (dc->read.dev) in delay_dtr()
164 dm_put_device(ti, dc->read.dev); in delay_dtr()
165 if (dc->write.dev) in delay_dtr()
166 dm_put_device(ti, dc->write.dev); in delay_dtr()
167 if (dc->flush.dev) in delay_dtr()
168 dm_put_device(ti, dc->flush.dev); in delay_dtr()
169 if (dc->worker) in delay_dtr()
170 kthread_stop(dc->worker); in delay_dtr()
172 mutex_destroy(&dc->process_bios_lock); in delay_dtr()
174 kfree(dc); in delay_dtr()
184 ti->error = "Invalid device sector"; in delay_class_ctr()
185 return -EINVAL; in delay_class_ctr()
187 c->start = tmpll; in delay_class_ctr()
189 if (sscanf(argv[2], "%u%c", &c->delay, &dummy) != 1) { in delay_class_ctr()
190 ti->error = "Invalid delay"; in delay_class_ctr()
191 return -EINVAL; in delay_class_ctr()
194 ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &c->dev); in delay_class_ctr()
196 ti->error = "Device lookup failed"; in delay_class_ctr()
213 struct delay_c *dc; in delay_ctr() local
218 ti->error = "Requires exactly 3, 6 or 9 arguments"; in delay_ctr()
219 return -EINVAL; in delay_ctr()
222 dc = kzalloc(sizeof(*dc), GFP_KERNEL); in delay_ctr()
223 if (!dc) { in delay_ctr()
224 ti->error = "Cannot allocate context"; in delay_ctr()
225 return -ENOMEM; in delay_ctr()
228 ti->private = dc; in delay_ctr()
229 INIT_LIST_HEAD(&dc->delayed_bios); in delay_ctr()
230 mutex_init(&dc->process_bios_lock); in delay_ctr()
231 spin_lock_init(&dc->delayed_bios_lock); in delay_ctr()
232 dc->may_delay = true; in delay_ctr()
233 dc->argc = argc; in delay_ctr()
235 ret = delay_class_ctr(ti, &dc->read, argv); in delay_ctr()
238 max_delay = dc->read.delay; in delay_ctr()
241 ret = delay_class_ctr(ti, &dc->write, argv); in delay_ctr()
244 ret = delay_class_ctr(ti, &dc->flush, argv); in delay_ctr()
250 ret = delay_class_ctr(ti, &dc->write, argv + 3); in delay_ctr()
253 max_delay = max(max_delay, dc->write.delay); in delay_ctr()
256 ret = delay_class_ctr(ti, &dc->flush, argv + 3); in delay_ctr()
262 ret = delay_class_ctr(ti, &dc->flush, argv + 6); in delay_ctr()
265 max_delay = max(max_delay, dc->flush.delay); in delay_ctr()
273 dc->worker = kthread_run(&flush_worker_fn, dc, "dm-delay-flush-worker"); in delay_ctr()
274 if (IS_ERR(dc->worker)) { in delay_ctr()
275 ret = PTR_ERR(dc->worker); in delay_ctr()
276 dc->worker = NULL; in delay_ctr()
280 timer_setup(&dc->delay_timer, handle_delayed_timer, 0); in delay_ctr()
281 INIT_WORK(&dc->flush_expired_bios, flush_expired_bios); in delay_ctr()
282 dc->kdelayd_wq = alloc_workqueue("kdelayd", WQ_MEM_RECLAIM, 0); in delay_ctr()
283 if (!dc->kdelayd_wq) { in delay_ctr()
284 ret = -EINVAL; in delay_ctr()
290 ti->num_flush_bios = 1; in delay_ctr()
291 ti->num_discard_bios = 1; in delay_ctr()
292 ti->accounts_remapped_io = true; in delay_ctr()
293 ti->per_io_data_size = sizeof(struct dm_delay_info); in delay_ctr()
301 static int delay_bio(struct delay_c *dc, struct delay_class *c, struct bio *bio) in delay_bio() argument
306 if (!c->delay) in delay_bio()
311 delayed->context = dc; in delay_bio()
312 delayed->expires = expires = jiffies + msecs_to_jiffies(c->delay); in delay_bio()
314 spin_lock(&dc->delayed_bios_lock); in delay_bio()
315 if (unlikely(!dc->may_delay)) { in delay_bio()
316 spin_unlock(&dc->delayed_bios_lock); in delay_bio()
319 c->ops++; in delay_bio()
320 list_add_tail(&delayed->list, &dc->delayed_bios); in delay_bio()
321 spin_unlock(&dc->delayed_bios_lock); in delay_bio()
323 if (delay_is_fast(dc)) in delay_bio()
324 wake_up_process(dc->worker); in delay_bio()
326 queue_timeout(dc, expires); in delay_bio()
333 struct delay_c *dc = ti->private; in delay_presuspend() local
335 spin_lock(&dc->delayed_bios_lock); in delay_presuspend()
336 dc->may_delay = false; in delay_presuspend()
337 spin_unlock(&dc->delayed_bios_lock); in delay_presuspend()
339 if (!delay_is_fast(dc)) in delay_presuspend()
340 timer_delete(&dc->delay_timer); in delay_presuspend()
341 flush_delayed_bios(dc, true); in delay_presuspend()
346 struct delay_c *dc = ti->private; in delay_resume() local
348 dc->may_delay = true; in delay_resume()
353 struct delay_c *dc = ti->private; in delay_map() local
358 if (unlikely(bio->bi_opf & REQ_PREFLUSH)) in delay_map()
359 c = &dc->flush; in delay_map()
361 c = &dc->write; in delay_map()
363 c = &dc->read; in delay_map()
365 delayed->class = c; in delay_map()
366 bio_set_dev(bio, c->dev->bdev); in delay_map()
367 bio->bi_iter.bi_sector = c->start + dm_target_offset(ti, bio->bi_iter.bi_sector); in delay_map()
369 return delay_bio(dc, c, bio); in delay_map()
373 DMEMIT("%s %llu %u", (c)->dev->name, (unsigned long long)(c)->start, (c)->delay)
378 struct delay_c *dc = ti->private; in delay_status() local
383 DMEMIT("%u %u %u", dc->read.ops, dc->write.ops, dc->flush.ops); in delay_status()
387 DMEMIT_DELAY_CLASS(&dc->read); in delay_status()
388 if (dc->argc >= 6) { in delay_status()
390 DMEMIT_DELAY_CLASS(&dc->write); in delay_status()
392 if (dc->argc >= 9) { in delay_status()
394 DMEMIT_DELAY_CLASS(&dc->flush); in delay_status()
407 struct delay_c *dc = ti->private; in delay_iterate_devices() local
410 ret = fn(ti, dc->read.dev, dc->read.start, ti->len, data); in delay_iterate_devices()
413 ret = fn(ti, dc->write.dev, dc->write.start, ti->len, data); in delay_iterate_devices()
416 ret = fn(ti, dc->flush.dev, dc->flush.start, ti->len, data); in delay_iterate_devices()