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

2  * Copyright (C) 2005-2007 Red Hat GmbH
16 #include <linux/device-mapper.h>
53 struct delay_c *dc = from_timer(dc, t, delay_timer); in handle_delayed_timer() local
55 queue_work(dc->kdelayd_wq, &dc->flush_expired_bios); in handle_delayed_timer()
58 static void queue_timeout(struct delay_c *dc, unsigned long expires) in queue_timeout() argument
60 mutex_lock(&dc->timer_lock); in queue_timeout()
62 if (!timer_pending(&dc->delay_timer) || expires < dc->delay_timer.expires) in queue_timeout()
63 mod_timer(&dc->delay_timer, expires); in queue_timeout()
65 mutex_unlock(&dc->timer_lock); in queue_timeout()
73 n = bio->bi_next; in flush_bios()
74 bio->bi_next = NULL; in flush_bios()
80 static struct bio *flush_delayed_bios(struct delay_c *dc, int flush_all) in flush_delayed_bios() argument
88 list_for_each_entry_safe(delayed, next, &dc->delayed_bios, list) { in flush_delayed_bios()
89 if (flush_all || time_after_eq(jiffies, delayed->expires)) { in flush_delayed_bios()
92 list_del(&delayed->list); in flush_delayed_bios()
94 delayed->class->ops--; in flush_delayed_bios()
100 next_expires = delayed->expires; in flush_delayed_bios()
102 next_expires = min(next_expires, delayed->expires); in flush_delayed_bios()
107 queue_timeout(dc, next_expires); in flush_delayed_bios()
114 struct delay_c *dc; in flush_expired_bios() local
116 dc = container_of(work, struct delay_c, flush_expired_bios); in flush_expired_bios()
117 flush_bios(flush_delayed_bios(dc, 0)); in flush_expired_bios()
122 struct delay_c *dc = ti->private; in delay_dtr() local
124 if (dc->kdelayd_wq) in delay_dtr()
125 destroy_workqueue(dc->kdelayd_wq); in delay_dtr()
127 if (dc->read.dev) in delay_dtr()
128 dm_put_device(ti, dc->read.dev); in delay_dtr()
129 if (dc->write.dev) in delay_dtr()
130 dm_put_device(ti, dc->write.dev); in delay_dtr()
131 if (dc->flush.dev) in delay_dtr()
132 dm_put_device(ti, dc->flush.dev); in delay_dtr()
134 mutex_destroy(&dc->timer_lock); in delay_dtr()
136 kfree(dc); in delay_dtr()
146 ti->error = "Invalid device sector"; in delay_class_ctr()
147 return -EINVAL; in delay_class_ctr()
149 c->start = tmpll; in delay_class_ctr()
151 if (sscanf(argv[2], "%u%c", &c->delay, &dummy) != 1) { in delay_class_ctr()
152 ti->error = "Invalid delay"; in delay_class_ctr()
153 return -EINVAL; in delay_class_ctr()
156 ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &c->dev); in delay_class_ctr()
158 ti->error = "Device lookup failed"; in delay_class_ctr()
175 struct delay_c *dc; in delay_ctr() local
179 ti->error = "Requires exactly 3, 6 or 9 arguments"; in delay_ctr()
180 return -EINVAL; in delay_ctr()
183 dc = kzalloc(sizeof(*dc), GFP_KERNEL); in delay_ctr()
184 if (!dc) { in delay_ctr()
185 ti->error = "Cannot allocate context"; in delay_ctr()
186 return -ENOMEM; in delay_ctr()
189 ti->private = dc; in delay_ctr()
190 timer_setup(&dc->delay_timer, handle_delayed_timer, 0); in delay_ctr()
191 INIT_WORK(&dc->flush_expired_bios, flush_expired_bios); in delay_ctr()
192 INIT_LIST_HEAD(&dc->delayed_bios); in delay_ctr()
193 mutex_init(&dc->timer_lock); in delay_ctr()
194 atomic_set(&dc->may_delay, 1); in delay_ctr()
195 dc->argc = argc; in delay_ctr()
197 ret = delay_class_ctr(ti, &dc->read, argv); in delay_ctr()
202 ret = delay_class_ctr(ti, &dc->write, argv); in delay_ctr()
205 ret = delay_class_ctr(ti, &dc->flush, argv); in delay_ctr()
211 ret = delay_class_ctr(ti, &dc->write, argv + 3); in delay_ctr()
215 ret = delay_class_ctr(ti, &dc->flush, argv + 3); in delay_ctr()
221 ret = delay_class_ctr(ti, &dc->flush, argv + 6); in delay_ctr()
226 dc->kdelayd_wq = alloc_workqueue("kdelayd", WQ_MEM_RECLAIM, 0); in delay_ctr()
227 if (!dc->kdelayd_wq) { in delay_ctr()
228 ret = -EINVAL; in delay_ctr()
233 ti->num_flush_bios = 1; in delay_ctr()
234 ti->num_discard_bios = 1; in delay_ctr()
235 ti->accounts_remapped_io = true; in delay_ctr()
236 ti->per_io_data_size = sizeof(struct dm_delay_info); in delay_ctr()
244 static int delay_bio(struct delay_c *dc, struct delay_class *c, struct bio *bio) in delay_bio() argument
249 if (!c->delay || !atomic_read(&dc->may_delay)) in delay_bio()
254 delayed->context = dc; in delay_bio()
255 delayed->expires = expires = jiffies + msecs_to_jiffies(c->delay); in delay_bio()
258 c->ops++; in delay_bio()
259 list_add_tail(&delayed->list, &dc->delayed_bios); in delay_bio()
262 queue_timeout(dc, expires); in delay_bio()
269 struct delay_c *dc = ti->private; in delay_presuspend() local
271 atomic_set(&dc->may_delay, 0); in delay_presuspend()
272 del_timer_sync(&dc->delay_timer); in delay_presuspend()
273 flush_bios(flush_delayed_bios(dc, 1)); in delay_presuspend()
278 struct delay_c *dc = ti->private; in delay_resume() local
280 atomic_set(&dc->may_delay, 1); in delay_resume()
285 struct delay_c *dc = ti->private; in delay_map() local
290 if (unlikely(bio->bi_opf & REQ_PREFLUSH)) in delay_map()
291 c = &dc->flush; in delay_map()
293 c = &dc->write; in delay_map()
295 c = &dc->read; in delay_map()
297 delayed->class = c; in delay_map()
298 bio_set_dev(bio, c->dev->bdev); in delay_map()
299 bio->bi_iter.bi_sector = c->start + dm_target_offset(ti, bio->bi_iter.bi_sector); in delay_map()
301 return delay_bio(dc, c, bio); in delay_map()
305 DMEMIT("%s %llu %u", (c)->dev->name, (unsigned long long)(c)->start, (c)->delay)
310 struct delay_c *dc = ti->private; in delay_status() local
315 DMEMIT("%u %u %u", dc->read.ops, dc->write.ops, dc->flush.ops); in delay_status()
319 DMEMIT_DELAY_CLASS(&dc->read); in delay_status()
320 if (dc->argc >= 6) { in delay_status()
322 DMEMIT_DELAY_CLASS(&dc->write); in delay_status()
324 if (dc->argc >= 9) { in delay_status()
326 DMEMIT_DELAY_CLASS(&dc->flush); in delay_status()
339 struct delay_c *dc = ti->private; in delay_iterate_devices() local
342 ret = fn(ti, dc->read.dev, dc->read.start, ti->len, data); in delay_iterate_devices()
345 ret = fn(ti, dc->write.dev, dc->write.start, ti->len, data); in delay_iterate_devices()
348 ret = fn(ti, dc->flush.dev, dc->flush.start, ti->len, data); in delay_iterate_devices()