writeback: split writeback_inodes_wb
[linux-2.6/next.git] / drivers / staging / line6 / dumprequest.c
blobcd468c39da5c75fb16823a5269b4a7106c9fcbdc
1 /*
2 * Line6 Linux USB driver - 0.8.0
4 * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
12 #include "driver.h"
14 #include <linux/slab.h>
16 #include "dumprequest.h"
20 Set "dump in progress" flag.
22 void line6_dump_started(struct line6_dump_request *l6dr, int dest)
24 l6dr->in_progress = dest;
28 Invalidate current channel, i.e., set "dump in progress" flag.
29 Reading from the "dump" special file blocks until dump is completed.
31 void line6_invalidate_current(struct line6_dump_request *l6dr)
33 line6_dump_started(l6dr, LINE6_DUMP_CURRENT);
37 Clear "dump in progress" flag and notify waiting processes.
39 void line6_dump_finished(struct line6_dump_request *l6dr)
41 l6dr->in_progress = LINE6_DUMP_NONE;
42 wake_up_interruptible(&l6dr->wait);
46 Send an asynchronous channel dump request.
48 int line6_dump_request_async(struct line6_dump_request *l6dr,
49 struct usb_line6 *line6, int num)
51 int ret;
52 line6_invalidate_current(l6dr);
53 ret = line6_send_raw_message_async(line6, l6dr->reqbufs[num].buffer,
54 l6dr->reqbufs[num].length);
56 if (ret < 0)
57 line6_dump_finished(l6dr);
59 return ret;
63 Send an asynchronous dump request after a given interval.
65 void line6_startup_delayed(struct line6_dump_request *l6dr, int seconds,
66 void (*function)(unsigned long), void *data)
68 l6dr->timer.expires = jiffies + seconds * HZ;
69 l6dr->timer.function = function;
70 l6dr->timer.data = (unsigned long)data;
71 add_timer(&l6dr->timer);
75 Wait for completion.
77 int line6_wait_dump(struct line6_dump_request *l6dr, int nonblock)
79 int retval = 0;
80 DECLARE_WAITQUEUE(wait, current);
81 add_wait_queue(&l6dr->wait, &wait);
82 current->state = TASK_INTERRUPTIBLE;
84 while (l6dr->in_progress) {
85 if (nonblock) {
86 retval = -EAGAIN;
87 break;
90 if (signal_pending(current)) {
91 retval = -ERESTARTSYS;
92 break;
93 } else
94 schedule();
97 current->state = TASK_RUNNING;
98 remove_wait_queue(&l6dr->wait, &wait);
99 return retval;
103 Initialize dump request buffer.
105 int line6_dumpreq_initbuf(struct line6_dump_request *l6dr, const void *buf,
106 size_t len, int num)
108 l6dr->reqbufs[num].buffer = kmemdup(buf, len, GFP_KERNEL);
109 if (l6dr->reqbufs[num].buffer == NULL)
110 return -ENOMEM;
111 l6dr->reqbufs[num].length = len;
112 return 0;
116 Initialize dump request data structure (including one buffer).
118 int line6_dumpreq_init(struct line6_dump_request *l6dr, const void *buf,
119 size_t len)
121 int ret;
122 ret = line6_dumpreq_initbuf(l6dr, buf, len, 0);
123 if (ret < 0)
124 return ret;
125 init_waitqueue_head(&l6dr->wait);
126 init_timer(&l6dr->timer);
127 return 0;
131 Destruct dump request data structure.
133 void line6_dumpreq_destructbuf(struct line6_dump_request *l6dr, int num)
135 if (l6dr == NULL)
136 return;
137 if (l6dr->reqbufs[num].buffer == NULL)
138 return;
139 kfree(l6dr->reqbufs[num].buffer);
140 l6dr->reqbufs[num].buffer = NULL;
144 Destruct dump request data structure.
146 void line6_dumpreq_destruct(struct line6_dump_request *l6dr)
148 if (l6dr->reqbufs[0].buffer == NULL)
149 return;
150 line6_dumpreq_destructbuf(l6dr, 0);
151 l6dr->ok = 1;
152 del_timer_sync(&l6dr->timer);