10 #include <linux/module.h>
14 #include <linux/slab.h>
18 #define DM_MSG_PREFIX "delay"
51 static void handle_delayed_timer(
unsigned long data)
58 static void queue_timeout(
struct delay_c *
dc,
unsigned long expires)
68 static void flush_bios(
struct bio *bio)
80 static struct bio *flush_delayed_bios(
struct delay_c *dc,
int flush_all)
83 unsigned long next_expires = 0;
91 bio_list_add(&flush_bios, delayed->
bio);
92 if ((bio_data_dir(delayed->
bio) ==
WRITE))
102 next_expires = delayed->
expires;
104 next_expires =
min(next_expires, delayed->
expires);
110 queue_timeout(dc, next_expires);
112 return bio_list_get(&flush_bios);
120 flush_bios(flush_delayed_bios(dc, 0));
130 static int delay_ctr(
struct dm_target *ti,
unsigned int argc,
char **argv)
133 unsigned long long tmpll;
136 if (argc != 3 && argc != 6) {
137 ti->
error =
"requires exactly 3 or 6 arguments";
143 ti->
error =
"Cannot allocate context";
149 if (
sscanf(argv[1],
"%llu%c", &tmpll, &dummy) != 1) {
150 ti->
error =
"Invalid device sector";
156 ti->
error =
"Invalid delay";
162 ti->
error =
"Device lookup failed";
170 if (
sscanf(argv[4],
"%llu%c", &tmpll, &dummy) != 1) {
171 ti->
error =
"Invalid write device sector";
177 ti->
error =
"Invalid write delay";
183 ti->
error =
"Write device lookup failed";
188 dc->
delayed_pool = mempool_create_slab_pool(128, delayed_cache);
190 DMERR(
"Couldn't create delayed bio pool.");
216 static void delay_dtr(
struct dm_target *ti)
231 static int delay_bio(
struct delay_c *dc,
int delay,
struct bio *bio)
234 unsigned long expires = 0;
247 if (bio_data_dir(bio) ==
WRITE)
256 queue_timeout(dc, expires);
261 static void delay_presuspend(
struct dm_target *ti)
267 flush_bios(flush_delayed_bios(dc, 1));
270 static void delay_resume(
struct dm_target *ti)
277 static int delay_map(
struct dm_target *ti,
struct bio *bio,
284 if (bio_sectors(bio))
298 unsigned status_flags,
char *
result,
unsigned maxlen)
322 static int delay_iterate_devices(
struct dm_target *ti,
341 .version = {1, 1, 0},
346 .presuspend = delay_presuspend,
347 .resume = delay_resume,
348 .status = delay_status,
349 .iterate_devices = delay_iterate_devices,
352 static int __init dm_delay_init(
void)
358 DMERR(
"Couldn't start kdelayd");
363 if (!delayed_cache) {
364 DMERR(
"Couldn't create delayed bio cache.");
370 DMERR(
"register failed %d", r);
384 static void __exit dm_delay_exit(
void)