Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/9p/mux.c |
| 3 | * |
| 4 | * Protocol Multiplexer |
| 5 | * |
| 6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 7 | * Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net> |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Eric Van Hensbergen | 42e8c50 | 2006-03-25 03:07:28 -0800 | [diff] [blame] | 10 | * it under the terms of the GNU General Public License version 2 |
| 11 | * as published by the Free Software Foundation. |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to: |
| 20 | * Free Software Foundation |
| 21 | * 51 Franklin Street, Fifth Floor |
| 22 | * Boston, MA 02111-1301 USA |
| 23 | * |
| 24 | */ |
| 25 | |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 26 | #include <linux/module.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/fs.h> |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 29 | #include <linux/poll.h> |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 30 | #include <linux/kthread.h> |
| 31 | #include <linux/idr.h> |
Ingo Molnar | 4f7a07b | 2006-03-23 03:00:19 -0800 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 33 | |
| 34 | #include "debug.h" |
| 35 | #include "v9fs.h" |
| 36 | #include "9p.h" |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 37 | #include "conv.h" |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 38 | #include "transport.h" |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 39 | #include "mux.h" |
| 40 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 41 | #define ERREQFLUSH 1 |
| 42 | #define SCHED_TIMEOUT 10 |
| 43 | #define MAXPOLLWADDR 2 |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 44 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 45 | enum { |
| 46 | Rworksched = 1, /* read work scheduled or running */ |
| 47 | Rpending = 2, /* can read */ |
| 48 | Wworksched = 4, /* write work scheduled or running */ |
| 49 | Wpending = 8, /* can write */ |
| 50 | }; |
| 51 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 52 | enum { |
| 53 | None, |
| 54 | Flushing, |
| 55 | Flushed, |
| 56 | }; |
| 57 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 58 | struct v9fs_mux_poll_task; |
| 59 | |
| 60 | struct v9fs_req { |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 61 | spinlock_t lock; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 62 | int tag; |
| 63 | struct v9fs_fcall *tcall; |
| 64 | struct v9fs_fcall *rcall; |
| 65 | int err; |
| 66 | v9fs_mux_req_callback cb; |
| 67 | void *cba; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 68 | int flush; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 69 | struct list_head req_list; |
| 70 | }; |
| 71 | |
| 72 | struct v9fs_mux_data { |
| 73 | spinlock_t lock; |
| 74 | struct list_head mux_list; |
| 75 | struct v9fs_mux_poll_task *poll_task; |
| 76 | int msize; |
| 77 | unsigned char *extended; |
| 78 | struct v9fs_transport *trans; |
Russ Cox | 4a26c24 | 2006-03-25 03:07:24 -0800 | [diff] [blame] | 79 | struct v9fs_idpool tagpool; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 80 | int err; |
| 81 | wait_queue_head_t equeue; |
| 82 | struct list_head req_list; |
| 83 | struct list_head unsent_req_list; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 84 | struct v9fs_fcall *rcall; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 85 | int rpos; |
| 86 | char *rbuf; |
| 87 | int wpos; |
| 88 | int wsize; |
| 89 | char *wbuf; |
| 90 | wait_queue_t poll_wait[MAXPOLLWADDR]; |
| 91 | wait_queue_head_t *poll_waddr[MAXPOLLWADDR]; |
| 92 | poll_table pt; |
| 93 | struct work_struct rq; |
| 94 | struct work_struct wq; |
| 95 | unsigned long wsched; |
| 96 | }; |
| 97 | |
| 98 | struct v9fs_mux_poll_task { |
| 99 | struct task_struct *task; |
| 100 | struct list_head mux_list; |
| 101 | int muxnum; |
| 102 | }; |
| 103 | |
| 104 | struct v9fs_mux_rpc { |
| 105 | struct v9fs_mux_data *m; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 106 | int err; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 107 | struct v9fs_fcall *tcall; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 108 | struct v9fs_fcall *rcall; |
| 109 | wait_queue_head_t wqueue; |
| 110 | }; |
| 111 | |
| 112 | static int v9fs_poll_proc(void *); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 113 | static void v9fs_read_work(struct work_struct *work); |
| 114 | static void v9fs_write_work(struct work_struct *work); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 115 | static void v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address, |
| 116 | poll_table * p); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 117 | static u16 v9fs_mux_get_tag(struct v9fs_mux_data *); |
| 118 | static void v9fs_mux_put_tag(struct v9fs_mux_data *, u16); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 119 | |
Ingo Molnar | 4f7a07b | 2006-03-23 03:00:19 -0800 | [diff] [blame] | 120 | static DEFINE_MUTEX(v9fs_mux_task_lock); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 121 | static struct workqueue_struct *v9fs_mux_wq; |
| 122 | |
| 123 | static int v9fs_mux_num; |
| 124 | static int v9fs_mux_poll_task_num; |
| 125 | static struct v9fs_mux_poll_task v9fs_mux_poll_tasks[100]; |
| 126 | |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 127 | int v9fs_mux_global_init(void) |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 128 | { |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 129 | int i; |
| 130 | |
| 131 | for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) |
| 132 | v9fs_mux_poll_tasks[i].task = NULL; |
| 133 | |
| 134 | v9fs_mux_wq = create_workqueue("v9fs"); |
Eric Van Hensbergen | f94b347 | 2007-01-26 00:57:04 -0800 | [diff] [blame] | 135 | if (!v9fs_mux_wq) { |
| 136 | printk(KERN_WARNING "v9fs: mux: creating workqueue failed\n"); |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 137 | return -ENOMEM; |
Eric Van Hensbergen | f94b347 | 2007-01-26 00:57:04 -0800 | [diff] [blame] | 138 | } |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 139 | |
| 140 | return 0; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | void v9fs_mux_global_exit(void) |
| 144 | { |
| 145 | destroy_workqueue(v9fs_mux_wq); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /** |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 149 | * v9fs_mux_calc_poll_procs - calculates the number of polling procs |
| 150 | * based on the number of mounted v9fs filesystems. |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 151 | * |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 152 | * The current implementation returns sqrt of the number of mounts. |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 153 | */ |
Adrian Bunk | 29c6e48 | 2006-03-24 03:15:52 -0800 | [diff] [blame] | 154 | static int v9fs_mux_calc_poll_procs(int muxnum) |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 155 | { |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 156 | int n; |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 157 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 158 | if (v9fs_mux_poll_task_num) |
| 159 | n = muxnum / v9fs_mux_poll_task_num + |
| 160 | (muxnum % v9fs_mux_poll_task_num ? 1 : 0); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 161 | else |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 162 | n = 1; |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 163 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 164 | if (n > ARRAY_SIZE(v9fs_mux_poll_tasks)) |
| 165 | n = ARRAY_SIZE(v9fs_mux_poll_tasks); |
| 166 | |
| 167 | return n; |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 170 | static int v9fs_mux_poll_start(struct v9fs_mux_data *m) |
Eric Van Hensbergen | 322b329 | 2005-09-09 13:04:23 -0700 | [diff] [blame] | 171 | { |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 172 | int i, n; |
| 173 | struct v9fs_mux_poll_task *vpt, *vptlast; |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 174 | struct task_struct *pproc; |
Eric Van Hensbergen | 322b329 | 2005-09-09 13:04:23 -0700 | [diff] [blame] | 175 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 176 | dprintk(DEBUG_MUX, "mux %p muxnum %d procnum %d\n", m, v9fs_mux_num, |
| 177 | v9fs_mux_poll_task_num); |
Ingo Molnar | 4f7a07b | 2006-03-23 03:00:19 -0800 | [diff] [blame] | 178 | mutex_lock(&v9fs_mux_task_lock); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 179 | |
| 180 | n = v9fs_mux_calc_poll_procs(v9fs_mux_num + 1); |
| 181 | if (n > v9fs_mux_poll_task_num) { |
| 182 | for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) { |
| 183 | if (v9fs_mux_poll_tasks[i].task == NULL) { |
| 184 | vpt = &v9fs_mux_poll_tasks[i]; |
| 185 | dprintk(DEBUG_MUX, "create proc %p\n", vpt); |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 186 | pproc = kthread_create(v9fs_poll_proc, vpt, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 187 | "v9fs-poll"); |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 188 | |
| 189 | if (!IS_ERR(pproc)) { |
| 190 | vpt->task = pproc; |
| 191 | INIT_LIST_HEAD(&vpt->mux_list); |
| 192 | vpt->muxnum = 0; |
| 193 | v9fs_mux_poll_task_num++; |
| 194 | wake_up_process(vpt->task); |
| 195 | } |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 196 | break; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | if (i >= ARRAY_SIZE(v9fs_mux_poll_tasks)) |
| 201 | dprintk(DEBUG_ERROR, "warning: no free poll slots\n"); |
Eric Van Hensbergen | 322b329 | 2005-09-09 13:04:23 -0700 | [diff] [blame] | 202 | } |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 203 | |
| 204 | n = (v9fs_mux_num + 1) / v9fs_mux_poll_task_num + |
| 205 | ((v9fs_mux_num + 1) % v9fs_mux_poll_task_num ? 1 : 0); |
| 206 | |
| 207 | vptlast = NULL; |
| 208 | for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) { |
| 209 | vpt = &v9fs_mux_poll_tasks[i]; |
| 210 | if (vpt->task != NULL) { |
| 211 | vptlast = vpt; |
| 212 | if (vpt->muxnum < n) { |
| 213 | dprintk(DEBUG_MUX, "put in proc %d\n", i); |
| 214 | list_add(&m->mux_list, &vpt->mux_list); |
| 215 | vpt->muxnum++; |
| 216 | m->poll_task = vpt; |
| 217 | memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); |
| 218 | init_poll_funcptr(&m->pt, v9fs_pollwait); |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if (i >= ARRAY_SIZE(v9fs_mux_poll_tasks)) { |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 225 | if (vptlast == NULL) |
| 226 | return -ENOMEM; |
| 227 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 228 | dprintk(DEBUG_MUX, "put in proc %d\n", i); |
| 229 | list_add(&m->mux_list, &vptlast->mux_list); |
| 230 | vptlast->muxnum++; |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 231 | m->poll_task = vptlast; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 232 | memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); |
| 233 | init_poll_funcptr(&m->pt, v9fs_pollwait); |
| 234 | } |
| 235 | |
| 236 | v9fs_mux_num++; |
Ingo Molnar | 4f7a07b | 2006-03-23 03:00:19 -0800 | [diff] [blame] | 237 | mutex_unlock(&v9fs_mux_task_lock); |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 238 | |
| 239 | return 0; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static void v9fs_mux_poll_stop(struct v9fs_mux_data *m) |
| 243 | { |
| 244 | int i; |
| 245 | struct v9fs_mux_poll_task *vpt; |
| 246 | |
Ingo Molnar | 4f7a07b | 2006-03-23 03:00:19 -0800 | [diff] [blame] | 247 | mutex_lock(&v9fs_mux_task_lock); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 248 | vpt = m->poll_task; |
| 249 | list_del(&m->mux_list); |
| 250 | for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) { |
| 251 | if (m->poll_waddr[i] != NULL) { |
| 252 | remove_wait_queue(m->poll_waddr[i], &m->poll_wait[i]); |
| 253 | m->poll_waddr[i] = NULL; |
| 254 | } |
| 255 | } |
| 256 | vpt->muxnum--; |
| 257 | if (!vpt->muxnum) { |
| 258 | dprintk(DEBUG_MUX, "destroy proc %p\n", vpt); |
| 259 | send_sig(SIGKILL, vpt->task, 1); |
| 260 | vpt->task = NULL; |
| 261 | v9fs_mux_poll_task_num--; |
| 262 | } |
| 263 | v9fs_mux_num--; |
Ingo Molnar | 4f7a07b | 2006-03-23 03:00:19 -0800 | [diff] [blame] | 264 | mutex_unlock(&v9fs_mux_task_lock); |
Eric Van Hensbergen | 322b329 | 2005-09-09 13:04:23 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 268 | * v9fs_mux_init - allocate and initialize the per-session mux data |
| 269 | * Creates the polling task if this is the first session. |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 270 | * |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 271 | * @trans - transport structure |
| 272 | * @msize - maximum message size |
| 273 | * @extended - pointer to the extended flag |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 274 | */ |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 275 | struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize, |
| 276 | unsigned char *extended) |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 277 | { |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 278 | int i, n; |
| 279 | struct v9fs_mux_data *m, *mtmp; |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 280 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 281 | dprintk(DEBUG_MUX, "transport %p msize %d\n", trans, msize); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 282 | m = kmalloc(sizeof(struct v9fs_mux_data), GFP_KERNEL); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 283 | if (!m) |
| 284 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 285 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 286 | spin_lock_init(&m->lock); |
| 287 | INIT_LIST_HEAD(&m->mux_list); |
| 288 | m->msize = msize; |
| 289 | m->extended = extended; |
| 290 | m->trans = trans; |
Russ Cox | 4a26c24 | 2006-03-25 03:07:24 -0800 | [diff] [blame] | 291 | idr_init(&m->tagpool.pool); |
| 292 | init_MUTEX(&m->tagpool.lock); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 293 | m->err = 0; |
| 294 | init_waitqueue_head(&m->equeue); |
| 295 | INIT_LIST_HEAD(&m->req_list); |
| 296 | INIT_LIST_HEAD(&m->unsent_req_list); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 297 | m->rcall = NULL; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 298 | m->rpos = 0; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 299 | m->rbuf = NULL; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 300 | m->wpos = m->wsize = 0; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 301 | m->wbuf = NULL; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 302 | INIT_WORK(&m->rq, v9fs_read_work); |
| 303 | INIT_WORK(&m->wq, v9fs_write_work); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 304 | m->wsched = 0; |
| 305 | memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); |
Latchesar Ionkov | 1dac06b | 2006-01-08 01:05:02 -0800 | [diff] [blame] | 306 | m->poll_task = NULL; |
| 307 | n = v9fs_mux_poll_start(m); |
| 308 | if (n) |
| 309 | return ERR_PTR(n); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 310 | |
| 311 | n = trans->poll(trans, &m->pt); |
| 312 | if (n & POLLIN) { |
| 313 | dprintk(DEBUG_MUX, "mux %p can read\n", m); |
| 314 | set_bit(Rpending, &m->wsched); |
| 315 | } |
| 316 | |
| 317 | if (n & POLLOUT) { |
| 318 | dprintk(DEBUG_MUX, "mux %p can write\n", m); |
| 319 | set_bit(Wpending, &m->wsched); |
| 320 | } |
| 321 | |
| 322 | for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) { |
| 323 | if (IS_ERR(m->poll_waddr[i])) { |
| 324 | v9fs_mux_poll_stop(m); |
| 325 | mtmp = (void *)m->poll_waddr; /* the error code */ |
| 326 | kfree(m); |
| 327 | m = mtmp; |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 328 | break; |
| 329 | } |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 330 | } |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 331 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 332 | return m; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * v9fs_mux_destroy - cancels all pending requests and frees mux resources |
| 337 | */ |
| 338 | void v9fs_mux_destroy(struct v9fs_mux_data *m) |
| 339 | { |
| 340 | dprintk(DEBUG_MUX, "mux %p prev %p next %p\n", m, |
| 341 | m->mux_list.prev, m->mux_list.next); |
| 342 | v9fs_mux_cancel(m, -ECONNRESET); |
| 343 | |
| 344 | if (!list_empty(&m->req_list)) { |
| 345 | /* wait until all processes waiting on this session exit */ |
| 346 | dprintk(DEBUG_MUX, "mux %p waiting for empty request queue\n", |
| 347 | m); |
| 348 | wait_event_timeout(m->equeue, (list_empty(&m->req_list)), 5000); |
| 349 | dprintk(DEBUG_MUX, "mux %p request queue empty: %d\n", m, |
| 350 | list_empty(&m->req_list)); |
| 351 | } |
| 352 | |
| 353 | v9fs_mux_poll_stop(m); |
| 354 | m->trans = NULL; |
| 355 | |
| 356 | kfree(m); |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * v9fs_pollwait - called by files poll operation to add v9fs-poll task |
| 361 | * to files wait queue |
| 362 | */ |
| 363 | static void |
| 364 | v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address, |
| 365 | poll_table * p) |
| 366 | { |
| 367 | int i; |
| 368 | struct v9fs_mux_data *m; |
| 369 | |
| 370 | m = container_of(p, struct v9fs_mux_data, pt); |
| 371 | for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) |
| 372 | if (m->poll_waddr[i] == NULL) |
| 373 | break; |
| 374 | |
| 375 | if (i >= ARRAY_SIZE(m->poll_waddr)) { |
| 376 | dprintk(DEBUG_ERROR, "not enough wait_address slots\n"); |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | m->poll_waddr[i] = wait_address; |
| 381 | |
| 382 | if (!wait_address) { |
| 383 | dprintk(DEBUG_ERROR, "no wait_address\n"); |
| 384 | m->poll_waddr[i] = ERR_PTR(-EIO); |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | init_waitqueue_entry(&m->poll_wait[i], m->poll_task->task); |
| 389 | add_wait_queue(wait_address, &m->poll_wait[i]); |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * v9fs_poll_mux - polls a mux and schedules read or write works if necessary |
| 394 | */ |
Adrian Bunk | 29c6e48 | 2006-03-24 03:15:52 -0800 | [diff] [blame] | 395 | static void v9fs_poll_mux(struct v9fs_mux_data *m) |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 396 | { |
| 397 | int n; |
| 398 | |
| 399 | if (m->err < 0) |
| 400 | return; |
| 401 | |
| 402 | n = m->trans->poll(m->trans, NULL); |
| 403 | if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) { |
| 404 | dprintk(DEBUG_MUX, "error mux %p err %d\n", m, n); |
| 405 | if (n >= 0) |
| 406 | n = -ECONNRESET; |
| 407 | v9fs_mux_cancel(m, n); |
| 408 | } |
| 409 | |
| 410 | if (n & POLLIN) { |
| 411 | set_bit(Rpending, &m->wsched); |
| 412 | dprintk(DEBUG_MUX, "mux %p can read\n", m); |
| 413 | if (!test_and_set_bit(Rworksched, &m->wsched)) { |
| 414 | dprintk(DEBUG_MUX, "schedule read work mux %p\n", m); |
| 415 | queue_work(v9fs_mux_wq, &m->rq); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | if (n & POLLOUT) { |
| 420 | set_bit(Wpending, &m->wsched); |
| 421 | dprintk(DEBUG_MUX, "mux %p can write\n", m); |
| 422 | if ((m->wsize || !list_empty(&m->unsent_req_list)) |
| 423 | && !test_and_set_bit(Wworksched, &m->wsched)) { |
| 424 | dprintk(DEBUG_MUX, "schedule write work mux %p\n", m); |
| 425 | queue_work(v9fs_mux_wq, &m->wq); |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * v9fs_poll_proc - polls all v9fs transports for new events and queues |
| 432 | * the appropriate work to the work queue |
| 433 | */ |
| 434 | static int v9fs_poll_proc(void *a) |
| 435 | { |
| 436 | struct v9fs_mux_data *m, *mtmp; |
| 437 | struct v9fs_mux_poll_task *vpt; |
| 438 | |
| 439 | vpt = a; |
| 440 | dprintk(DEBUG_MUX, "start %p %p\n", current, vpt); |
| 441 | allow_signal(SIGKILL); |
| 442 | while (!kthread_should_stop()) { |
| 443 | set_current_state(TASK_INTERRUPTIBLE); |
| 444 | if (signal_pending(current)) |
| 445 | break; |
| 446 | |
| 447 | list_for_each_entry_safe(m, mtmp, &vpt->mux_list, mux_list) { |
| 448 | v9fs_poll_mux(m); |
| 449 | } |
| 450 | |
| 451 | dprintk(DEBUG_MUX, "sleeping...\n"); |
| 452 | schedule_timeout(SCHED_TIMEOUT * HZ); |
| 453 | } |
| 454 | |
| 455 | __set_current_state(TASK_RUNNING); |
| 456 | dprintk(DEBUG_MUX, "finish\n"); |
| 457 | return 0; |
| 458 | } |
| 459 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 460 | /** |
| 461 | * v9fs_write_work - called when a transport can send some data |
| 462 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 463 | static void v9fs_write_work(struct work_struct *work) |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 464 | { |
| 465 | int n, err; |
| 466 | struct v9fs_mux_data *m; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 467 | struct v9fs_req *req; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 468 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 469 | m = container_of(work, struct v9fs_mux_data, wq); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 470 | |
| 471 | if (m->err < 0) { |
| 472 | clear_bit(Wworksched, &m->wsched); |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | if (!m->wsize) { |
| 477 | if (list_empty(&m->unsent_req_list)) { |
| 478 | clear_bit(Wworksched, &m->wsched); |
| 479 | return; |
| 480 | } |
| 481 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 482 | spin_lock(&m->lock); |
Latchesar Ionkov | 034b91a | 2006-02-03 03:04:20 -0800 | [diff] [blame] | 483 | again: |
| 484 | req = list_entry(m->unsent_req_list.next, struct v9fs_req, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 485 | req_list); |
| 486 | list_move_tail(&req->req_list, &m->req_list); |
Latchesar Ionkov | 034b91a | 2006-02-03 03:04:20 -0800 | [diff] [blame] | 487 | if (req->err == ERREQFLUSH) |
| 488 | goto again; |
| 489 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 490 | m->wbuf = req->tcall->sdata; |
| 491 | m->wsize = req->tcall->size; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 492 | m->wpos = 0; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 493 | dump_data(m->wbuf, m->wsize); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 494 | spin_unlock(&m->lock); |
| 495 | } |
| 496 | |
| 497 | dprintk(DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos, m->wsize); |
| 498 | clear_bit(Wpending, &m->wsched); |
| 499 | err = m->trans->write(m->trans, m->wbuf + m->wpos, m->wsize - m->wpos); |
| 500 | dprintk(DEBUG_MUX, "mux %p sent %d bytes\n", m, err); |
| 501 | if (err == -EAGAIN) { |
| 502 | clear_bit(Wworksched, &m->wsched); |
| 503 | return; |
| 504 | } |
| 505 | |
| 506 | if (err <= 0) |
| 507 | goto error; |
| 508 | |
| 509 | m->wpos += err; |
| 510 | if (m->wpos == m->wsize) |
| 511 | m->wpos = m->wsize = 0; |
| 512 | |
| 513 | if (m->wsize == 0 && !list_empty(&m->unsent_req_list)) { |
| 514 | if (test_and_clear_bit(Wpending, &m->wsched)) |
| 515 | n = POLLOUT; |
| 516 | else |
| 517 | n = m->trans->poll(m->trans, NULL); |
| 518 | |
| 519 | if (n & POLLOUT) { |
| 520 | dprintk(DEBUG_MUX, "schedule write work mux %p\n", m); |
| 521 | queue_work(v9fs_mux_wq, &m->wq); |
| 522 | } else |
| 523 | clear_bit(Wworksched, &m->wsched); |
| 524 | } else |
| 525 | clear_bit(Wworksched, &m->wsched); |
| 526 | |
| 527 | return; |
| 528 | |
| 529 | error: |
| 530 | v9fs_mux_cancel(m, err); |
| 531 | clear_bit(Wworksched, &m->wsched); |
| 532 | } |
| 533 | |
| 534 | static void process_request(struct v9fs_mux_data *m, struct v9fs_req *req) |
| 535 | { |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 536 | int ecode; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 537 | struct v9fs_str *ename; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 538 | |
Latchesar Ionkov | 034b91a | 2006-02-03 03:04:20 -0800 | [diff] [blame] | 539 | if (!req->err && req->rcall->id == RERROR) { |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 540 | ecode = req->rcall->params.rerror.errno; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 541 | ename = &req->rcall->params.rerror.error; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 542 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 543 | dprintk(DEBUG_MUX, "Rerror %.*s\n", ename->len, ename->str); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 544 | |
| 545 | if (*m->extended) |
| 546 | req->err = -ecode; |
| 547 | |
| 548 | if (!req->err) { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 549 | req->err = v9fs_errstr2errno(ename->str, ename->len); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 550 | |
| 551 | if (!req->err) { /* string match failed */ |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 552 | PRINT_FCALL_ERROR("unknown error", req->rcall); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | if (!req->err) |
| 556 | req->err = -ESERVERFAULT; |
| 557 | } |
| 558 | } else if (req->tcall && req->rcall->id != req->tcall->id + 1) { |
| 559 | dprintk(DEBUG_ERROR, "fcall mismatch: expected %d, got %d\n", |
| 560 | req->tcall->id + 1, req->rcall->id); |
| 561 | if (!req->err) |
| 562 | req->err = -EIO; |
| 563 | } |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /** |
| 567 | * v9fs_read_work - called when there is some data to be read from a transport |
| 568 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 569 | static void v9fs_read_work(struct work_struct *work) |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 570 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 571 | int n, err; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 572 | struct v9fs_mux_data *m; |
| 573 | struct v9fs_req *req, *rptr, *rreq; |
| 574 | struct v9fs_fcall *rcall; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 575 | char *rbuf; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 576 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 577 | m = container_of(work, struct v9fs_mux_data, rq); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 578 | |
| 579 | if (m->err < 0) |
| 580 | return; |
| 581 | |
| 582 | rcall = NULL; |
| 583 | dprintk(DEBUG_MUX, "start mux %p pos %d\n", m, m->rpos); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 584 | |
| 585 | if (!m->rcall) { |
| 586 | m->rcall = |
| 587 | kmalloc(sizeof(struct v9fs_fcall) + m->msize, GFP_KERNEL); |
| 588 | if (!m->rcall) { |
| 589 | err = -ENOMEM; |
| 590 | goto error; |
| 591 | } |
| 592 | |
| 593 | m->rbuf = (char *)m->rcall + sizeof(struct v9fs_fcall); |
| 594 | m->rpos = 0; |
| 595 | } |
| 596 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 597 | clear_bit(Rpending, &m->wsched); |
| 598 | err = m->trans->read(m->trans, m->rbuf + m->rpos, m->msize - m->rpos); |
| 599 | dprintk(DEBUG_MUX, "mux %p got %d bytes\n", m, err); |
| 600 | if (err == -EAGAIN) { |
| 601 | clear_bit(Rworksched, &m->wsched); |
| 602 | return; |
| 603 | } |
| 604 | |
| 605 | if (err <= 0) |
| 606 | goto error; |
| 607 | |
| 608 | m->rpos += err; |
| 609 | while (m->rpos > 4) { |
| 610 | n = le32_to_cpu(*(__le32 *) m->rbuf); |
| 611 | if (n >= m->msize) { |
| 612 | dprintk(DEBUG_ERROR, |
| 613 | "requested packet size too big: %d\n", n); |
| 614 | err = -EIO; |
| 615 | goto error; |
| 616 | } |
| 617 | |
| 618 | if (m->rpos < n) |
| 619 | break; |
| 620 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 621 | dump_data(m->rbuf, n); |
| 622 | err = |
| 623 | v9fs_deserialize_fcall(m->rbuf, n, m->rcall, *m->extended); |
| 624 | if (err < 0) { |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 625 | goto error; |
| 626 | } |
| 627 | |
Latchesar Ionkov | 5174fda | 2006-03-25 03:07:25 -0800 | [diff] [blame] | 628 | if ((v9fs_debug_level&DEBUG_FCALL) == DEBUG_FCALL) { |
| 629 | char buf[150]; |
| 630 | |
| 631 | v9fs_printfcall(buf, sizeof(buf), m->rcall, |
| 632 | *m->extended); |
| 633 | printk(KERN_NOTICE ">>> %p %s\n", m, buf); |
| 634 | } |
| 635 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 636 | rcall = m->rcall; |
| 637 | rbuf = m->rbuf; |
| 638 | if (m->rpos > n) { |
| 639 | m->rcall = kmalloc(sizeof(struct v9fs_fcall) + m->msize, |
| 640 | GFP_KERNEL); |
| 641 | if (!m->rcall) { |
| 642 | err = -ENOMEM; |
| 643 | goto error; |
| 644 | } |
| 645 | |
| 646 | m->rbuf = (char *)m->rcall + sizeof(struct v9fs_fcall); |
| 647 | memmove(m->rbuf, rbuf + n, m->rpos - n); |
| 648 | m->rpos -= n; |
| 649 | } else { |
| 650 | m->rcall = NULL; |
| 651 | m->rbuf = NULL; |
| 652 | m->rpos = 0; |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 655 | dprintk(DEBUG_MUX, "mux %p fcall id %d tag %d\n", m, rcall->id, |
| 656 | rcall->tag); |
| 657 | |
| 658 | req = NULL; |
| 659 | spin_lock(&m->lock); |
| 660 | list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) { |
| 661 | if (rreq->tag == rcall->tag) { |
| 662 | req = rreq; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 663 | if (req->flush != Flushing) |
| 664 | list_del(&req->req_list); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 665 | break; |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 666 | } |
| 667 | } |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 668 | spin_unlock(&m->lock); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 669 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 670 | if (req) { |
| 671 | req->rcall = rcall; |
| 672 | process_request(m, req); |
| 673 | |
| 674 | if (req->flush != Flushing) { |
| 675 | if (req->cb) |
| 676 | (*req->cb) (req, req->cba); |
| 677 | else |
| 678 | kfree(req->rcall); |
| 679 | |
| 680 | wake_up(&m->equeue); |
| 681 | } |
| 682 | } else { |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 683 | if (err >= 0 && rcall->id != RFLUSH) |
Eric Van Hensbergen | cb2e87a | 2005-09-09 13:04:28 -0700 | [diff] [blame] | 684 | dprintk(DEBUG_ERROR, |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 685 | "unexpected response mux %p id %d tag %d\n", |
| 686 | m, rcall->id, rcall->tag); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 687 | kfree(rcall); |
| 688 | } |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 691 | if (!list_empty(&m->req_list)) { |
| 692 | if (test_and_clear_bit(Rpending, &m->wsched)) |
| 693 | n = POLLIN; |
| 694 | else |
| 695 | n = m->trans->poll(m->trans, NULL); |
Eric Van Hensbergen | cb2e87a | 2005-09-09 13:04:28 -0700 | [diff] [blame] | 696 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 697 | if (n & POLLIN) { |
| 698 | dprintk(DEBUG_MUX, "schedule read work mux %p\n", m); |
| 699 | queue_work(v9fs_mux_wq, &m->rq); |
| 700 | } else |
| 701 | clear_bit(Rworksched, &m->wsched); |
| 702 | } else |
| 703 | clear_bit(Rworksched, &m->wsched); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 704 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 705 | return; |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 706 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 707 | error: |
| 708 | v9fs_mux_cancel(m, err); |
| 709 | clear_bit(Rworksched, &m->wsched); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /** |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 713 | * v9fs_send_request - send 9P request |
| 714 | * The function can sleep until the request is scheduled for sending. |
| 715 | * The function can be interrupted. Return from the function is not |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 716 | * a guarantee that the request is sent successfully. Can return errors |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 717 | * that can be retrieved by PTR_ERR macros. |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 718 | * |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 719 | * @m: mux data |
| 720 | * @tc: request to be sent |
| 721 | * @cb: callback function to call when response is received |
| 722 | * @cba: parameter to pass to the callback function |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 723 | */ |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 724 | static struct v9fs_req *v9fs_send_request(struct v9fs_mux_data *m, |
| 725 | struct v9fs_fcall *tc, |
| 726 | v9fs_mux_req_callback cb, void *cba) |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 727 | { |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 728 | int n; |
| 729 | struct v9fs_req *req; |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 730 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 731 | dprintk(DEBUG_MUX, "mux %p task %p tcall %p id %d\n", m, current, |
| 732 | tc, tc->id); |
| 733 | if (m->err < 0) |
| 734 | return ERR_PTR(m->err); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 735 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 736 | req = kmalloc(sizeof(struct v9fs_req), GFP_KERNEL); |
| 737 | if (!req) |
| 738 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 739 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 740 | if (tc->id == TVERSION) |
| 741 | n = V9FS_NOTAG; |
| 742 | else |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 743 | n = v9fs_mux_get_tag(m); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 744 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 745 | if (n < 0) |
| 746 | return ERR_PTR(-ENOMEM); |
| 747 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 748 | v9fs_set_tag(tc, n); |
Latchesar Ionkov | 5174fda | 2006-03-25 03:07:25 -0800 | [diff] [blame] | 749 | if ((v9fs_debug_level&DEBUG_FCALL) == DEBUG_FCALL) { |
| 750 | char buf[150]; |
| 751 | |
| 752 | v9fs_printfcall(buf, sizeof(buf), tc, *m->extended); |
| 753 | printk(KERN_NOTICE "<<< %p %s\n", m, buf); |
| 754 | } |
| 755 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 756 | spin_lock_init(&req->lock); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 757 | req->tag = n; |
| 758 | req->tcall = tc; |
| 759 | req->rcall = NULL; |
| 760 | req->err = 0; |
| 761 | req->cb = cb; |
| 762 | req->cba = cba; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 763 | req->flush = None; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 764 | |
| 765 | spin_lock(&m->lock); |
| 766 | list_add_tail(&req->req_list, &m->unsent_req_list); |
| 767 | spin_unlock(&m->lock); |
| 768 | |
| 769 | if (test_and_clear_bit(Wpending, &m->wsched)) |
| 770 | n = POLLOUT; |
| 771 | else |
| 772 | n = m->trans->poll(m->trans, NULL); |
| 773 | |
| 774 | if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched)) |
| 775 | queue_work(v9fs_mux_wq, &m->wq); |
| 776 | |
| 777 | return req; |
| 778 | } |
| 779 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 780 | static void v9fs_mux_free_request(struct v9fs_mux_data *m, struct v9fs_req *req) |
| 781 | { |
| 782 | v9fs_mux_put_tag(m, req->tag); |
| 783 | kfree(req); |
| 784 | } |
| 785 | |
| 786 | static void v9fs_mux_flush_cb(struct v9fs_req *freq, void *a) |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 787 | { |
| 788 | v9fs_mux_req_callback cb; |
| 789 | int tag; |
| 790 | struct v9fs_mux_data *m; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 791 | struct v9fs_req *req, *rreq, *rptr; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 792 | |
| 793 | m = a; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 794 | dprintk(DEBUG_MUX, "mux %p tc %p rc %p err %d oldtag %d\n", m, |
| 795 | freq->tcall, freq->rcall, freq->err, |
| 796 | freq->tcall->params.tflush.oldtag); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 797 | |
| 798 | spin_lock(&m->lock); |
| 799 | cb = NULL; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 800 | tag = freq->tcall->params.tflush.oldtag; |
| 801 | req = NULL; |
| 802 | list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) { |
| 803 | if (rreq->tag == tag) { |
| 804 | req = rreq; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 805 | list_del(&req->req_list); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 806 | break; |
| 807 | } |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 808 | } |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 809 | spin_unlock(&m->lock); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 810 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 811 | if (req) { |
| 812 | spin_lock(&req->lock); |
| 813 | req->flush = Flushed; |
| 814 | spin_unlock(&req->lock); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 815 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 816 | if (req->cb) |
| 817 | (*req->cb) (req, req->cba); |
| 818 | else |
| 819 | kfree(req->rcall); |
| 820 | |
| 821 | wake_up(&m->equeue); |
| 822 | } |
| 823 | |
| 824 | kfree(freq->tcall); |
| 825 | kfree(freq->rcall); |
| 826 | v9fs_mux_free_request(m, freq); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 827 | } |
| 828 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 829 | static int |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 830 | v9fs_mux_flush_request(struct v9fs_mux_data *m, struct v9fs_req *req) |
| 831 | { |
| 832 | struct v9fs_fcall *fc; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 833 | struct v9fs_req *rreq, *rptr; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 834 | |
| 835 | dprintk(DEBUG_MUX, "mux %p req %p tag %d\n", m, req, req->tag); |
| 836 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 837 | /* if a response was received for a request, do nothing */ |
| 838 | spin_lock(&req->lock); |
| 839 | if (req->rcall || req->err) { |
| 840 | spin_unlock(&req->lock); |
| 841 | dprintk(DEBUG_MUX, "mux %p req %p response already received\n", m, req); |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | req->flush = Flushing; |
| 846 | spin_unlock(&req->lock); |
| 847 | |
| 848 | spin_lock(&m->lock); |
| 849 | /* if the request is not sent yet, just remove it from the list */ |
| 850 | list_for_each_entry_safe(rreq, rptr, &m->unsent_req_list, req_list) { |
| 851 | if (rreq->tag == req->tag) { |
| 852 | dprintk(DEBUG_MUX, "mux %p req %p request is not sent yet\n", m, req); |
| 853 | list_del(&rreq->req_list); |
| 854 | req->flush = Flushed; |
| 855 | spin_unlock(&m->lock); |
| 856 | if (req->cb) |
| 857 | (*req->cb) (req, req->cba); |
| 858 | return 0; |
| 859 | } |
| 860 | } |
| 861 | spin_unlock(&m->lock); |
| 862 | |
| 863 | clear_thread_flag(TIF_SIGPENDING); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 864 | fc = v9fs_create_tflush(req->tag); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 865 | v9fs_send_request(m, fc, v9fs_mux_flush_cb, m); |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 866 | return 1; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static void |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 870 | v9fs_mux_rpc_cb(struct v9fs_req *req, void *a) |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 871 | { |
| 872 | struct v9fs_mux_rpc *r; |
| 873 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 874 | dprintk(DEBUG_MUX, "req %p r %p\n", req, a); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 875 | r = a; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 876 | r->rcall = req->rcall; |
| 877 | r->err = req->err; |
| 878 | |
| 879 | if (req->flush!=None && !req->err) |
| 880 | r->err = -ERESTARTSYS; |
| 881 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 882 | wake_up(&r->wqueue); |
| 883 | } |
| 884 | |
| 885 | /** |
| 886 | * v9fs_mux_rpc - sends 9P request and waits until a response is available. |
| 887 | * The function can be interrupted. |
| 888 | * @m: mux data |
| 889 | * @tc: request to be sent |
| 890 | * @rc: pointer where a pointer to the response is stored |
| 891 | */ |
| 892 | int |
| 893 | v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc, |
| 894 | struct v9fs_fcall **rc) |
| 895 | { |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 896 | int err, sigpending; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 897 | unsigned long flags; |
| 898 | struct v9fs_req *req; |
| 899 | struct v9fs_mux_rpc r; |
| 900 | |
| 901 | r.err = 0; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 902 | r.tcall = tc; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 903 | r.rcall = NULL; |
| 904 | r.m = m; |
| 905 | init_waitqueue_head(&r.wqueue); |
| 906 | |
| 907 | if (rc) |
| 908 | *rc = NULL; |
| 909 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 910 | sigpending = 0; |
| 911 | if (signal_pending(current)) { |
| 912 | sigpending = 1; |
| 913 | clear_thread_flag(TIF_SIGPENDING); |
| 914 | } |
| 915 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 916 | req = v9fs_send_request(m, tc, v9fs_mux_rpc_cb, &r); |
| 917 | if (IS_ERR(req)) { |
| 918 | err = PTR_ERR(req); |
| 919 | dprintk(DEBUG_MUX, "error %d\n", err); |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 920 | return err; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 921 | } |
| 922 | |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 923 | err = wait_event_interruptible(r.wqueue, r.rcall != NULL || r.err < 0); |
| 924 | if (r.err < 0) |
| 925 | err = r.err; |
| 926 | |
| 927 | if (err == -ERESTARTSYS && m->trans->status == Connected && m->err == 0) { |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 928 | if (v9fs_mux_flush_request(m, req)) { |
| 929 | /* wait until we get response of the flush message */ |
| 930 | do { |
| 931 | clear_thread_flag(TIF_SIGPENDING); |
| 932 | err = wait_event_interruptible(r.wqueue, |
| 933 | r.rcall || r.err); |
| 934 | } while (!r.rcall && !r.err && err==-ERESTARTSYS && |
| 935 | m->trans->status==Connected && !m->err); |
Latchesar Ionkov | 94374e7 | 2006-06-28 04:26:50 -0700 | [diff] [blame] | 936 | |
| 937 | err = -ERESTARTSYS; |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 938 | } |
| 939 | sigpending = 1; |
| 940 | } |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 941 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 942 | if (sigpending) { |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 943 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
| 944 | recalc_sigpending(); |
| 945 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
| 946 | } |
| 947 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 948 | if (rc) |
| 949 | *rc = r.rcall; |
| 950 | else |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 951 | kfree(r.rcall); |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 952 | |
| 953 | v9fs_mux_free_request(m, req); |
| 954 | if (err > 0) |
| 955 | err = -EIO; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 956 | |
| 957 | return err; |
| 958 | } |
| 959 | |
Adrian Bunk | 29c6e48 | 2006-03-24 03:15:52 -0800 | [diff] [blame] | 960 | #if 0 |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 961 | /** |
| 962 | * v9fs_mux_rpcnb - sends 9P request without waiting for response. |
| 963 | * @m: mux data |
| 964 | * @tc: request to be sent |
| 965 | * @cb: callback function to be called when response arrives |
| 966 | * @cba: value to pass to the callback function |
| 967 | */ |
| 968 | int v9fs_mux_rpcnb(struct v9fs_mux_data *m, struct v9fs_fcall *tc, |
| 969 | v9fs_mux_req_callback cb, void *a) |
| 970 | { |
| 971 | int err; |
| 972 | struct v9fs_req *req; |
| 973 | |
| 974 | req = v9fs_send_request(m, tc, cb, a); |
| 975 | if (IS_ERR(req)) { |
| 976 | err = PTR_ERR(req); |
| 977 | dprintk(DEBUG_MUX, "error %d\n", err); |
| 978 | return PTR_ERR(req); |
| 979 | } |
| 980 | |
| 981 | dprintk(DEBUG_MUX, "mux %p tc %p tag %d\n", m, tc, req->tag); |
Eric Van Hensbergen | 426cc91 | 2005-09-09 13:04:22 -0700 | [diff] [blame] | 982 | return 0; |
| 983 | } |
Adrian Bunk | 29c6e48 | 2006-03-24 03:15:52 -0800 | [diff] [blame] | 984 | #endif /* 0 */ |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 985 | |
| 986 | /** |
| 987 | * v9fs_mux_cancel - cancel all pending requests with error |
| 988 | * @m: mux data |
| 989 | * @err: error code |
| 990 | */ |
| 991 | void v9fs_mux_cancel(struct v9fs_mux_data *m, int err) |
| 992 | { |
| 993 | struct v9fs_req *req, *rtmp; |
| 994 | LIST_HEAD(cancel_list); |
| 995 | |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 996 | dprintk(DEBUG_ERROR, "mux %p err %d\n", m, err); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 997 | m->err = err; |
| 998 | spin_lock(&m->lock); |
| 999 | list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) { |
| 1000 | list_move(&req->req_list, &cancel_list); |
| 1001 | } |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 1002 | list_for_each_entry_safe(req, rtmp, &m->unsent_req_list, req_list) { |
| 1003 | list_move(&req->req_list, &cancel_list); |
| 1004 | } |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 1005 | spin_unlock(&m->lock); |
| 1006 | |
| 1007 | list_for_each_entry_safe(req, rtmp, &cancel_list, req_list) { |
| 1008 | list_del(&req->req_list); |
| 1009 | if (!req->err) |
| 1010 | req->err = err; |
| 1011 | |
| 1012 | if (req->cb) |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 1013 | (*req->cb) (req, req->cba); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 1014 | else |
| 1015 | kfree(req->rcall); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | wake_up(&m->equeue); |
| 1019 | } |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1020 | |
| 1021 | static u16 v9fs_mux_get_tag(struct v9fs_mux_data *m) |
| 1022 | { |
| 1023 | int tag; |
| 1024 | |
Russ Cox | 4a26c24 | 2006-03-25 03:07:24 -0800 | [diff] [blame] | 1025 | tag = v9fs_get_idpool(&m->tagpool); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1026 | if (tag < 0) |
| 1027 | return V9FS_NOTAG; |
| 1028 | else |
| 1029 | return (u16) tag; |
| 1030 | } |
| 1031 | |
| 1032 | static void v9fs_mux_put_tag(struct v9fs_mux_data *m, u16 tag) |
| 1033 | { |
Russ Cox | 4a26c24 | 2006-03-25 03:07:24 -0800 | [diff] [blame] | 1034 | if (tag != V9FS_NOTAG && v9fs_check_idpool(tag, &m->tagpool)) |
| 1035 | v9fs_put_idpool(tag, &m->tagpool); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1036 | } |