blob: 9c9196d30a59f1ca74ef6ef3e5a2dbe7ce27b335 [file] [log] [blame]
Thomas Gleixner1f327612019-05-28 09:57:16 -07001// SPDX-License-Identifier: GPL-2.0-only
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05002/*
3 * linux/fs/9p/trans_fd.c
4 *
5 * Fd transport layer. Includes deprecated socket layer.
6 *
7 * Copyright (C) 2006 by Russ Cox <rsc@swtch.com>
8 * Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net>
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -06009 * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050010 * Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050011 */
12
Joe Perches5d385152011-11-28 10:40:46 -080013#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050015#include <linux/in.h>
16#include <linux/module.h>
17#include <linux/net.h>
18#include <linux/ipv6.h>
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -060019#include <linux/kthread.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050020#include <linux/errno.h>
21#include <linux/kernel.h>
22#include <linux/un.h>
23#include <linux/uaccess.h>
24#include <linux/inet.h>
25#include <linux/idr.h>
26#include <linux/file.h>
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050027#include <linux/parser.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
David Howellsc4fac912017-07-05 16:25:37 +010029#include <linux/seq_file.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050030#include <net/9p/9p.h>
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -050031#include <net/9p/client.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050032#include <net/9p/transport.h>
33
Al Viro6b186622009-08-06 02:02:43 +040034#include <linux/syscalls.h> /* killme */
35
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050036#define P9_PORT 564
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050037#define MAX_SOCK_BUF (64*1024)
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -060038#define MAXPOLLWADDR 2
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050039
David Howellsc4fac912017-07-05 16:25:37 +010040static struct p9_trans_module p9_tcp_trans;
41static struct p9_trans_module p9_fd_trans;
42
Eric Van Hensbergenee443992008-03-05 07:08:09 -060043/**
44 * struct p9_fd_opts - per-transport options
45 * @rfd: file descriptor for reading (trans=fd)
46 * @wfd: file descriptor for writing (trans=fd)
47 * @port: port to connect to (trans=tcp)
48 *
49 */
50
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050051struct p9_fd_opts {
52 int rfd;
53 int wfd;
54 u16 port;
David Howellsc4fac912017-07-05 16:25:37 +010055 bool privport;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050056};
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050057
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050058/*
59 * Option Parsing (code inspired by NFS code)
60 * - a little lazy - parse all fd-transport options
61 */
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050062
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050063enum {
64 /* Options that take integer arguments */
Latchesar Ionkov55762692007-11-06 08:02:53 -060065 Opt_port, Opt_rfdno, Opt_wfdno, Opt_err,
Jim Garlick2f28c8b2013-05-29 12:15:07 -070066 /* Options that take no arguments */
67 Opt_privport,
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050068};
69
Steven Whitehousea447c092008-10-13 10:46:57 +010070static const match_table_t tokens = {
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050071 {Opt_port, "port=%u"},
72 {Opt_rfdno, "rfdno=%u"},
73 {Opt_wfdno, "wfdno=%u"},
Jim Garlick2f28c8b2013-05-29 12:15:07 -070074 {Opt_privport, "privport"},
Latchesar Ionkov55762692007-11-06 08:02:53 -060075 {Opt_err, NULL},
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050076};
77
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -060078enum {
79 Rworksched = 1, /* read work scheduled or running */
80 Rpending = 2, /* can read */
81 Wworksched = 4, /* write work scheduled or running */
82 Wpending = 8, /* can write */
83};
84
Tejun Heo992b3f12008-10-13 18:45:25 -050085struct p9_poll_wait {
86 struct p9_conn *conn;
Ingo Molnarac6424b2017-06-20 12:06:13 +020087 wait_queue_entry_t wait;
Tejun Heo992b3f12008-10-13 18:45:25 -050088 wait_queue_head_t *wait_addr;
Eric Van Hensbergenee443992008-03-05 07:08:09 -060089};
90
91/**
92 * struct p9_conn - fd mux connection state information
Eric Van Hensbergenee443992008-03-05 07:08:09 -060093 * @mux_list: list link for mux to manage multiple connections (?)
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -050094 * @client: reference to client instance for this connection
Eric Van Hensbergenee443992008-03-05 07:08:09 -060095 * @err: error state
Eric Van Hensbergenee443992008-03-05 07:08:09 -060096 * @req_list: accounting for requests which have been sent
97 * @unsent_req_list: accounting for requests that haven't been sent
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -050098 * @req: current request being processed (if any)
99 * @tmp_buf: temporary buffer to read in header
Dominique Martinet947867a2015-09-03 11:28:20 +0200100 * @rc: temporary fcall for reading current frame
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600101 * @wpos: write position for current frame
102 * @wsize: amount of data to write for current frame
103 * @wbuf: current write buffer
Abhishek Kulkarni0e155972009-07-19 13:41:55 -0600104 * @poll_pending_link: pending links to be polled per conn
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600105 * @poll_wait: array of wait_q's for various worker threads
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600106 * @pt: poll state
107 * @rq: current read work
108 * @wq: current write work
109 * @wsched: ????
110 *
111 */
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600112
113struct p9_conn {
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600114 struct list_head mux_list;
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500115 struct p9_client *client;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600116 int err;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600117 struct list_head req_list;
118 struct list_head unsent_req_list;
Tomas Bortoli6d351902018-09-03 18:03:21 +0200119 struct p9_req_t *rreq;
Tomas Bortoli728356d2018-08-14 19:43:42 +0200120 struct p9_req_t *wreq;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500121 char tmp_buf[7];
Dominique Martinet947867a2015-09-03 11:28:20 +0200122 struct p9_fcall rc;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600123 int wpos;
124 int wsize;
125 char *wbuf;
Tejun Heo992b3f12008-10-13 18:45:25 -0500126 struct list_head poll_pending_link;
127 struct p9_poll_wait poll_wait[MAXPOLLWADDR];
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600128 poll_table pt;
129 struct work_struct rq;
130 struct work_struct wq;
131 unsigned long wsched;
132};
133
Simon Derr263c5822014-03-11 10:13:09 +0100134/**
135 * struct p9_trans_fd - transport state
136 * @rd: reference to file to read from
137 * @wr: reference of file to write to
138 * @conn: connection state reference
139 *
140 */
141
142struct p9_trans_fd {
143 struct file *rd;
144 struct file *wr;
145 struct p9_conn conn;
146};
147
Tejun Heoaa70c582011-02-01 11:42:43 +0100148static void p9_poll_workfn(struct work_struct *work);
149
Tejun Heo992b3f12008-10-13 18:45:25 -0500150static DEFINE_SPINLOCK(p9_poll_lock);
151static LIST_HEAD(p9_poll_pending_list);
Tejun Heoaa70c582011-02-01 11:42:43 +0100152static DECLARE_WORK(p9_poll_work, p9_poll_workfn);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600153
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700154static unsigned int p9_ipport_resv_min = P9_DEF_MIN_RESVPORT;
155static unsigned int p9_ipport_resv_max = P9_DEF_MAX_RESVPORT;
156
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600157static void p9_mux_poll_stop(struct p9_conn *m)
158{
Tejun Heo992b3f12008-10-13 18:45:25 -0500159 unsigned long flags;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600160 int i;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600161
Tejun Heo992b3f12008-10-13 18:45:25 -0500162 for (i = 0; i < ARRAY_SIZE(m->poll_wait); i++) {
163 struct p9_poll_wait *pwait = &m->poll_wait[i];
164
165 if (pwait->wait_addr) {
166 remove_wait_queue(pwait->wait_addr, &pwait->wait);
167 pwait->wait_addr = NULL;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600168 }
169 }
Tejun Heo992b3f12008-10-13 18:45:25 -0500170
171 spin_lock_irqsave(&p9_poll_lock, flags);
172 list_del_init(&m->poll_pending_link);
173 spin_unlock_irqrestore(&p9_poll_lock, flags);
Tomas Bortoli430ac662018-07-20 11:27:30 +0200174
175 flush_work(&p9_poll_work);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600176}
177
178/**
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500179 * p9_conn_cancel - cancel all pending requests with error
180 * @m: mux data
181 * @err: error code
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600182 *
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600183 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600184
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500185static void p9_conn_cancel(struct p9_conn *m, int err)
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600186{
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500187 struct p9_req_t *req, *rtmp;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500188 LIST_HEAD(cancel_list);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600189
Joe Perches5d385152011-11-28 10:40:46 -0800190 p9_debug(P9_DEBUG_ERROR, "mux %p err %d\n", m, err);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500191
Tomas Bortoli9f476d72018-07-23 20:42:53 +0200192 spin_lock(&m->client->lock);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500193
194 if (m->err) {
Tomas Bortoli9f476d72018-07-23 20:42:53 +0200195 spin_unlock(&m->client->lock);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500196 return;
197 }
198
199 m->err = err;
200
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500201 list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) {
202 list_move(&req->req_list, &cancel_list);
Tejun Heo992b3f12008-10-13 18:45:25 -0500203 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500204 list_for_each_entry_safe(req, rtmp, &m->unsent_req_list, req_list) {
205 list_move(&req->req_list, &cancel_list);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600206 }
207
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500208 list_for_each_entry_safe(req, rtmp, &cancel_list, req_list) {
Joe Perches5d385152011-11-28 10:40:46 -0800209 p9_debug(P9_DEBUG_ERROR, "call back req %p\n", req);
Latchesar Ionkov1bab88b2009-04-05 16:28:59 -0500210 list_del(&req->req_list);
Dominique Martinet2b6e72e2014-01-17 18:31:00 +0100211 if (!req->t_err)
212 req->t_err = err;
213 p9_client_cb(m->client, req, REQ_STATUS_ERROR);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600214 }
Tomas Bortoli9f476d72018-07-23 20:42:53 +0200215 spin_unlock(&m->client->lock);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600216}
217
Al Viro7594bf32017-07-16 22:53:08 -0400218static __poll_t
219p9_fd_poll(struct p9_client *client, struct poll_table_struct *pt, int *err)
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500220{
Christoph Hellwig9965ed172018-03-05 07:26:05 -0800221 __poll_t ret;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500222 struct p9_trans_fd *ts = NULL;
223
224 if (client && client->status == Connected)
225 ts = client->trans;
226
Al Viro7594bf32017-07-16 22:53:08 -0400227 if (!ts) {
228 if (err)
229 *err = -EREMOTEIO;
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800230 return EPOLLERR;
Al Viro7594bf32017-07-16 22:53:08 -0400231 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500232
Christoph Hellwig9965ed172018-03-05 07:26:05 -0800233 ret = vfs_poll(ts->rd, pt);
234 if (ts->rd != ts->wr)
235 ret = (ret & ~EPOLLOUT) | (vfs_poll(ts->wr, pt) & ~EPOLLIN);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500236 return ret;
237}
238
239/**
240 * p9_fd_read- read from a fd
241 * @client: client instance
242 * @v: buffer to receive data into
243 * @len: size of receive buffer
244 *
245 */
246
247static int p9_fd_read(struct p9_client *client, void *v, int len)
248{
249 int ret;
250 struct p9_trans_fd *ts = NULL;
Christoph Hellwigbdd1d2d2017-09-01 17:39:13 +0200251 loff_t pos;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500252
253 if (client && client->status != Disconnected)
254 ts = client->trans;
255
256 if (!ts)
257 return -EREMOTEIO;
258
259 if (!(ts->rd->f_flags & O_NONBLOCK))
Joe Perches5d385152011-11-28 10:40:46 -0800260 p9_debug(P9_DEBUG_ERROR, "blocking read ...\n");
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500261
Christoph Hellwigbdd1d2d2017-09-01 17:39:13 +0200262 pos = ts->rd->f_pos;
263 ret = kernel_read(ts->rd, v, len, &pos);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500264 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
265 client->status = Disconnected;
266 return ret;
267}
268
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600269/**
270 * p9_read_work - called when there is some data to be read from a transport
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600271 * @work: container of work to be done
272 *
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600273 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600274
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600275static void p9_read_work(struct work_struct *work)
276{
Al Viro7594bf32017-07-16 22:53:08 -0400277 __poll_t n;
278 int err;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600279 struct p9_conn *m;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600280
281 m = container_of(work, struct p9_conn, rq);
282
283 if (m->err < 0)
284 return;
285
Dominique Martinet947867a2015-09-03 11:28:20 +0200286 p9_debug(P9_DEBUG_TRANS, "start mux %p pos %zd\n", m, m->rc.offset);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600287
Dominique Martinet947867a2015-09-03 11:28:20 +0200288 if (!m->rc.sdata) {
289 m->rc.sdata = m->tmp_buf;
290 m->rc.offset = 0;
291 m->rc.capacity = 7; /* start by reading header */
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600292 }
293
294 clear_bit(Rpending, &m->wsched);
Dominique Martinet947867a2015-09-03 11:28:20 +0200295 p9_debug(P9_DEBUG_TRANS, "read mux %p pos %zd size: %zd = %zd\n",
296 m, m->rc.offset, m->rc.capacity,
297 m->rc.capacity - m->rc.offset);
298 err = p9_fd_read(m->client, m->rc.sdata + m->rc.offset,
299 m->rc.capacity - m->rc.offset);
Joe Perches5d385152011-11-28 10:40:46 -0800300 p9_debug(P9_DEBUG_TRANS, "mux %p got %d bytes\n", m, err);
Dominique Martinet947867a2015-09-03 11:28:20 +0200301 if (err == -EAGAIN)
Simon Derr04621942012-09-17 15:16:28 +0200302 goto end_clear;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600303
304 if (err <= 0)
305 goto error;
306
Dominique Martinet947867a2015-09-03 11:28:20 +0200307 m->rc.offset += err;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500308
Dominique Martinet947867a2015-09-03 11:28:20 +0200309 /* header read in */
Tomas Bortoli6d351902018-09-03 18:03:21 +0200310 if ((!m->rreq) && (m->rc.offset == m->rc.capacity)) {
Joe Perches5d385152011-11-28 10:40:46 -0800311 p9_debug(P9_DEBUG_TRANS, "got new header\n");
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500312
Tomas Bortolif9845792018-07-23 17:44:04 +0200313 /* Header size */
314 m->rc.size = 7;
315 err = p9_parse_header(&m->rc, &m->rc.size, NULL, NULL, 0);
Dominique Martinet947867a2015-09-03 11:28:20 +0200316 if (err) {
Joe Perches5d385152011-11-28 10:40:46 -0800317 p9_debug(P9_DEBUG_ERROR,
Dominique Martinet947867a2015-09-03 11:28:20 +0200318 "error parsing header: %d\n", err);
319 goto error;
320 }
321
322 if (m->rc.size >= m->client->msize) {
323 p9_debug(P9_DEBUG_ERROR,
324 "requested packet size too big: %d\n",
325 m->rc.size);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600326 err = -EIO;
327 goto error;
328 }
329
Joe Perches5d385152011-11-28 10:40:46 -0800330 p9_debug(P9_DEBUG_TRANS,
Dominique Martinet947867a2015-09-03 11:28:20 +0200331 "mux %p pkt: size: %d bytes tag: %d\n",
332 m, m->rc.size, m->rc.tag);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600333
Tomas Bortoli6d351902018-09-03 18:03:21 +0200334 m->rreq = p9_tag_lookup(m->client, m->rc.tag);
335 if (!m->rreq || (m->rreq->status != REQ_STATUS_SENT)) {
Joe Perches5d385152011-11-28 10:40:46 -0800336 p9_debug(P9_DEBUG_ERROR, "Unexpected packet tag %d\n",
Dominique Martinet947867a2015-09-03 11:28:20 +0200337 m->rc.tag);
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500338 err = -EIO;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600339 goto error;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500340 }
341
Tomas Bortoli6d351902018-09-03 18:03:21 +0200342 if (!m->rreq->rc.sdata) {
Dominique Martinet30536002015-09-07 17:06:54 +0200343 p9_debug(P9_DEBUG_ERROR,
344 "No recv fcall for tag %d (req %p), disconnecting!\n",
Tomas Bortoli6d351902018-09-03 18:03:21 +0200345 m->rc.tag, m->rreq);
346 m->rreq = NULL;
Dominique Martinet30536002015-09-07 17:06:54 +0200347 err = -EIO;
348 goto error;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500349 }
Tomas Bortoli6d351902018-09-03 18:03:21 +0200350 m->rc.sdata = m->rreq->rc.sdata;
Dominique Martinet947867a2015-09-03 11:28:20 +0200351 memcpy(m->rc.sdata, m->tmp_buf, m->rc.capacity);
352 m->rc.capacity = m->rc.size;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500353 }
354
Dominique Martinet947867a2015-09-03 11:28:20 +0200355 /* packet is read in
356 * not an else because some packets (like clunk) have no payload
357 */
Tomas Bortoli6d351902018-09-03 18:03:21 +0200358 if ((m->rreq) && (m->rc.offset == m->rc.capacity)) {
Joe Perches5d385152011-11-28 10:40:46 -0800359 p9_debug(P9_DEBUG_TRANS, "got new packet\n");
Tomas Bortoli6d351902018-09-03 18:03:21 +0200360 m->rreq->rc.size = m->rc.offset;
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500361 spin_lock(&m->client->lock);
Dominique Martinete4ca13f2018-10-09 11:18:52 +0900362 if (m->rreq->status == REQ_STATUS_SENT) {
363 list_del(&m->rreq->req_list);
364 p9_client_cb(m->client, m->rreq, REQ_STATUS_RCVD);
365 } else {
366 spin_unlock(&m->client->lock);
367 p9_debug(P9_DEBUG_ERROR,
368 "Request tag %d errored out while we were reading the reply\n",
369 m->rc.tag);
370 err = -EIO;
371 goto error;
372 }
Tomas Bortoli9f476d72018-07-23 20:42:53 +0200373 spin_unlock(&m->client->lock);
Dominique Martinet947867a2015-09-03 11:28:20 +0200374 m->rc.sdata = NULL;
375 m->rc.offset = 0;
376 m->rc.capacity = 0;
Tomas Bortoli6d351902018-09-03 18:03:21 +0200377 p9_req_put(m->rreq);
378 m->rreq = NULL;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600379 }
380
Simon Derr04621942012-09-17 15:16:28 +0200381end_clear:
382 clear_bit(Rworksched, &m->wsched);
383
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600384 if (!list_empty(&m->req_list)) {
385 if (test_and_clear_bit(Rpending, &m->wsched))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800386 n = EPOLLIN;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600387 else
Al Viro7594bf32017-07-16 22:53:08 -0400388 n = p9_fd_poll(m->client, NULL, NULL);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600389
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800390 if ((n & EPOLLIN) && !test_and_set_bit(Rworksched, &m->wsched)) {
Joe Perches5d385152011-11-28 10:40:46 -0800391 p9_debug(P9_DEBUG_TRANS, "sched read work %p\n", m);
Tejun Heo61edeee2011-02-01 11:42:43 +0100392 schedule_work(&m->rq);
Simon Derr04621942012-09-17 15:16:28 +0200393 }
394 }
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600395
396 return;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600397error:
398 p9_conn_cancel(m, err);
399 clear_bit(Rworksched, &m->wsched);
400}
401
402/**
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500403 * p9_fd_write - write to a socket
404 * @client: client instance
405 * @v: buffer to send data from
406 * @len: size of send buffer
407 *
408 */
409
410static int p9_fd_write(struct p9_client *client, void *v, int len)
411{
Christoph Hellwig670986e2017-09-01 17:39:18 +0200412 ssize_t ret;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500413 struct p9_trans_fd *ts = NULL;
414
415 if (client && client->status != Disconnected)
416 ts = client->trans;
417
418 if (!ts)
419 return -EREMOTEIO;
420
421 if (!(ts->wr->f_flags & O_NONBLOCK))
Joe Perches5d385152011-11-28 10:40:46 -0800422 p9_debug(P9_DEBUG_ERROR, "blocking write ...\n");
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500423
Christoph Hellwig670986e2017-09-01 17:39:18 +0200424 ret = kernel_write(ts->wr, v, len, &ts->wr->f_pos);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500425 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
426 client->status = Disconnected;
427 return ret;
428}
429
430/**
431 * p9_write_work - called when a transport can send some data
432 * @work: container for work to be done
433 *
434 */
435
436static void p9_write_work(struct work_struct *work)
437{
Al Viro7594bf32017-07-16 22:53:08 -0400438 __poll_t n;
439 int err;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500440 struct p9_conn *m;
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500441 struct p9_req_t *req;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500442
443 m = container_of(work, struct p9_conn, wq);
444
445 if (m->err < 0) {
446 clear_bit(Wworksched, &m->wsched);
447 return;
448 }
449
450 if (!m->wsize) {
Simon Derr759f4292012-09-17 15:16:31 +0200451 spin_lock(&m->client->lock);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500452 if (list_empty(&m->unsent_req_list)) {
453 clear_bit(Wworksched, &m->wsched);
Simon Derr759f4292012-09-17 15:16:31 +0200454 spin_unlock(&m->client->lock);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500455 return;
456 }
457
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500458 req = list_entry(m->unsent_req_list.next, struct p9_req_t,
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500459 req_list);
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500460 req->status = REQ_STATUS_SENT;
Joe Perches5d385152011-11-28 10:40:46 -0800461 p9_debug(P9_DEBUG_TRANS, "move req %p\n", req);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500462 list_move_tail(&req->req_list, &m->req_list);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500463
Dominique Martinet523adb62018-07-30 05:55:19 +0000464 m->wbuf = req->tc.sdata;
465 m->wsize = req->tc.size;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500466 m->wpos = 0;
Tomas Bortoli728356d2018-08-14 19:43:42 +0200467 p9_req_get(req);
468 m->wreq = req;
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500469 spin_unlock(&m->client->lock);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500470 }
471
Joe Perches5d385152011-11-28 10:40:46 -0800472 p9_debug(P9_DEBUG_TRANS, "mux %p pos %d size %d\n",
473 m, m->wpos, m->wsize);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500474 clear_bit(Wpending, &m->wsched);
475 err = p9_fd_write(m->client, m->wbuf + m->wpos, m->wsize - m->wpos);
Joe Perches5d385152011-11-28 10:40:46 -0800476 p9_debug(P9_DEBUG_TRANS, "mux %p sent %d bytes\n", m, err);
Simon Derr584a8c12012-09-17 15:16:30 +0200477 if (err == -EAGAIN)
478 goto end_clear;
479
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500480
481 if (err < 0)
482 goto error;
483 else if (err == 0) {
484 err = -EREMOTEIO;
485 goto error;
486 }
487
488 m->wpos += err;
Tomas Bortoli728356d2018-08-14 19:43:42 +0200489 if (m->wpos == m->wsize) {
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500490 m->wpos = m->wsize = 0;
Tomas Bortoli728356d2018-08-14 19:43:42 +0200491 p9_req_put(m->wreq);
492 m->wreq = NULL;
493 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500494
Simon Derr584a8c12012-09-17 15:16:30 +0200495end_clear:
496 clear_bit(Wworksched, &m->wsched);
497
Simon Derr1957b3a2012-09-17 15:16:29 +0200498 if (m->wsize || !list_empty(&m->unsent_req_list)) {
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500499 if (test_and_clear_bit(Wpending, &m->wsched))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800500 n = EPOLLOUT;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500501 else
Al Viro7594bf32017-07-16 22:53:08 -0400502 n = p9_fd_poll(m->client, NULL, NULL);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500503
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800504 if ((n & EPOLLOUT) &&
Simon Derr584a8c12012-09-17 15:16:30 +0200505 !test_and_set_bit(Wworksched, &m->wsched)) {
Joe Perches5d385152011-11-28 10:40:46 -0800506 p9_debug(P9_DEBUG_TRANS, "sched write work %p\n", m);
Tejun Heo61edeee2011-02-01 11:42:43 +0100507 schedule_work(&m->wq);
Simon Derr584a8c12012-09-17 15:16:30 +0200508 }
509 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500510
511 return;
512
513error:
514 p9_conn_cancel(m, err);
515 clear_bit(Wworksched, &m->wsched);
516}
517
Ingo Molnarac6424b2017-06-20 12:06:13 +0200518static int p9_pollwake(wait_queue_entry_t *wait, unsigned int mode, int sync, void *key)
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500519{
520 struct p9_poll_wait *pwait =
521 container_of(wait, struct p9_poll_wait, wait);
522 struct p9_conn *m = pwait->conn;
523 unsigned long flags;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500524
525 spin_lock_irqsave(&p9_poll_lock, flags);
526 if (list_empty(&m->poll_pending_link))
527 list_add_tail(&m->poll_pending_link, &p9_poll_pending_list);
528 spin_unlock_irqrestore(&p9_poll_lock, flags);
529
Tejun Heoaa70c582011-02-01 11:42:43 +0100530 schedule_work(&p9_poll_work);
531 return 1;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500532}
533
534/**
535 * p9_pollwait - add poll task to the wait queue
536 * @filp: file pointer being polled
537 * @wait_address: wait_q to block on
538 * @p: poll state
539 *
540 * called by files poll operation to add v9fs-poll task to files wait queue
541 */
542
543static void
544p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p)
545{
546 struct p9_conn *m = container_of(p, struct p9_conn, pt);
547 struct p9_poll_wait *pwait = NULL;
548 int i;
549
550 for (i = 0; i < ARRAY_SIZE(m->poll_wait); i++) {
551 if (m->poll_wait[i].wait_addr == NULL) {
552 pwait = &m->poll_wait[i];
553 break;
554 }
555 }
556
557 if (!pwait) {
Joe Perches5d385152011-11-28 10:40:46 -0800558 p9_debug(P9_DEBUG_ERROR, "not enough wait_address slots\n");
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500559 return;
560 }
561
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500562 pwait->conn = m;
563 pwait->wait_addr = wait_address;
564 init_waitqueue_func_entry(&pwait->wait, p9_pollwake);
565 add_wait_queue(wait_address, &pwait->wait);
566}
567
568/**
Simon Derr263c5822014-03-11 10:13:09 +0100569 * p9_conn_create - initialize the per-session mux data
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500570 * @client: client instance
571 *
572 * Note: Creates the polling task if this is the first session.
573 */
574
Simon Derr263c5822014-03-11 10:13:09 +0100575static void p9_conn_create(struct p9_client *client)
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500576{
Al Viro7594bf32017-07-16 22:53:08 -0400577 __poll_t n;
Simon Derr263c5822014-03-11 10:13:09 +0100578 struct p9_trans_fd *ts = client->trans;
579 struct p9_conn *m = &ts->conn;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500580
Joe Perches5d385152011-11-28 10:40:46 -0800581 p9_debug(P9_DEBUG_TRANS, "client %p msize %d\n", client, client->msize);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500582
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500583 INIT_LIST_HEAD(&m->mux_list);
584 m->client = client;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500585
586 INIT_LIST_HEAD(&m->req_list);
587 INIT_LIST_HEAD(&m->unsent_req_list);
588 INIT_WORK(&m->rq, p9_read_work);
589 INIT_WORK(&m->wq, p9_write_work);
590 INIT_LIST_HEAD(&m->poll_pending_link);
591 init_poll_funcptr(&m->pt, p9_pollwait);
592
Al Viro7594bf32017-07-16 22:53:08 -0400593 n = p9_fd_poll(client, &m->pt, NULL);
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800594 if (n & EPOLLIN) {
Joe Perches5d385152011-11-28 10:40:46 -0800595 p9_debug(P9_DEBUG_TRANS, "mux %p can read\n", m);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500596 set_bit(Rpending, &m->wsched);
597 }
598
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800599 if (n & EPOLLOUT) {
Joe Perches5d385152011-11-28 10:40:46 -0800600 p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500601 set_bit(Wpending, &m->wsched);
602 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500603}
604
605/**
606 * p9_poll_mux - polls a mux and schedules read or write works if necessary
607 * @m: connection to poll
608 *
609 */
610
611static void p9_poll_mux(struct p9_conn *m)
612{
Al Viro7594bf32017-07-16 22:53:08 -0400613 __poll_t n;
614 int err = -ECONNRESET;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500615
616 if (m->err < 0)
617 return;
618
Al Viro7594bf32017-07-16 22:53:08 -0400619 n = p9_fd_poll(m->client, NULL, &err);
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800620 if (n & (EPOLLERR | EPOLLHUP | EPOLLNVAL)) {
Joe Perches5d385152011-11-28 10:40:46 -0800621 p9_debug(P9_DEBUG_TRANS, "error mux %p err %d\n", m, n);
Al Viro7594bf32017-07-16 22:53:08 -0400622 p9_conn_cancel(m, err);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500623 }
624
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800625 if (n & EPOLLIN) {
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500626 set_bit(Rpending, &m->wsched);
Joe Perches5d385152011-11-28 10:40:46 -0800627 p9_debug(P9_DEBUG_TRANS, "mux %p can read\n", m);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500628 if (!test_and_set_bit(Rworksched, &m->wsched)) {
Joe Perches5d385152011-11-28 10:40:46 -0800629 p9_debug(P9_DEBUG_TRANS, "sched read work %p\n", m);
Tejun Heo61edeee2011-02-01 11:42:43 +0100630 schedule_work(&m->rq);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500631 }
632 }
633
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800634 if (n & EPOLLOUT) {
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500635 set_bit(Wpending, &m->wsched);
Joe Perches5d385152011-11-28 10:40:46 -0800636 p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m);
Joe Perchesf64f9e72009-11-29 16:55:45 -0800637 if ((m->wsize || !list_empty(&m->unsent_req_list)) &&
638 !test_and_set_bit(Wworksched, &m->wsched)) {
Joe Perches5d385152011-11-28 10:40:46 -0800639 p9_debug(P9_DEBUG_TRANS, "sched write work %p\n", m);
Tejun Heo61edeee2011-02-01 11:42:43 +0100640 schedule_work(&m->wq);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500641 }
642 }
643}
644
645/**
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500646 * p9_fd_request - send 9P request
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600647 * The function can sleep until the request is scheduled for sending.
648 * The function can be interrupted. Return from the function is not
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500649 * a guarantee that the request is sent successfully.
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600650 *
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500651 * @client: client instance
652 * @req: request to be sent
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600653 *
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600654 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600655
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500656static int p9_fd_request(struct p9_client *client, struct p9_req_t *req)
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600657{
Al Viro7594bf32017-07-16 22:53:08 -0400658 __poll_t n;
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500659 struct p9_trans_fd *ts = client->trans;
Simon Derr263c5822014-03-11 10:13:09 +0100660 struct p9_conn *m = &ts->conn;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600661
Joe Perches5d385152011-11-28 10:40:46 -0800662 p9_debug(P9_DEBUG_TRANS, "mux %p task %p tcall %p id %d\n",
Dominique Martinet523adb62018-07-30 05:55:19 +0000663 m, current, &req->tc, req->tc.id);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600664 if (m->err < 0)
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500665 return m->err;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600666
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500667 spin_lock(&client->lock);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500668 req->status = REQ_STATUS_UNSENT;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600669 list_add_tail(&req->req_list, &m->unsent_req_list);
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500670 spin_unlock(&client->lock);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600671
672 if (test_and_clear_bit(Wpending, &m->wsched))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800673 n = EPOLLOUT;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600674 else
Al Viro7594bf32017-07-16 22:53:08 -0400675 n = p9_fd_poll(m->client, NULL, NULL);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600676
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800677 if (n & EPOLLOUT && !test_and_set_bit(Wworksched, &m->wsched))
Tejun Heo61edeee2011-02-01 11:42:43 +0100678 schedule_work(&m->wq);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600679
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500680 return 0;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600681}
682
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500683static int p9_fd_cancel(struct p9_client *client, struct p9_req_t *req)
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600684{
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500685 int ret = 1;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600686
Joe Perches5d385152011-11-28 10:40:46 -0800687 p9_debug(P9_DEBUG_TRANS, "client %p req %p\n", client, req);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600688
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500689 spin_lock(&client->lock);
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500690
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500691 if (req->status == REQ_STATUS_UNSENT) {
Latchesar Ionkov1bab88b2009-04-05 16:28:59 -0500692 list_del(&req->req_list);
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500693 req->status = REQ_STATUS_FLSHD;
Tomas Bortoli728356d2018-08-14 19:43:42 +0200694 p9_req_put(req);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500695 ret = 0;
Simon Derr0bfd6842014-03-10 16:38:52 +0100696 }
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500697 spin_unlock(&client->lock);
698
699 return ret;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600700}
701
Simon Derrafd8d652014-03-10 16:38:49 +0100702static int p9_fd_cancelled(struct p9_client *client, struct p9_req_t *req)
703{
704 p9_debug(P9_DEBUG_TRANS, "client %p req %p\n", client, req);
705
706 /* we haven't received a response for oldreq,
707 * remove it from the list.
708 */
709 spin_lock(&client->lock);
710 list_del(&req->req_list);
711 spin_unlock(&client->lock);
Tomas Bortoli728356d2018-08-14 19:43:42 +0200712 p9_req_put(req);
Simon Derrafd8d652014-03-10 16:38:49 +0100713
714 return 0;
715}
716
David Howellsc4fac912017-07-05 16:25:37 +0100717static int p9_fd_show_options(struct seq_file *m, struct p9_client *clnt)
718{
719 if (clnt->trans_mod == &p9_tcp_trans) {
720 if (clnt->trans_opts.tcp.port != P9_PORT)
Tuomas Tynkkynen61b272c2017-11-19 11:28:43 +0200721 seq_printf(m, ",port=%u", clnt->trans_opts.tcp.port);
David Howellsc4fac912017-07-05 16:25:37 +0100722 } else if (clnt->trans_mod == &p9_fd_trans) {
723 if (clnt->trans_opts.fd.rfd != ~0)
Tuomas Tynkkynen61b272c2017-11-19 11:28:43 +0200724 seq_printf(m, ",rfd=%u", clnt->trans_opts.fd.rfd);
David Howellsc4fac912017-07-05 16:25:37 +0100725 if (clnt->trans_opts.fd.wfd != ~0)
Tuomas Tynkkynen61b272c2017-11-19 11:28:43 +0200726 seq_printf(m, ",wfd=%u", clnt->trans_opts.fd.wfd);
David Howellsc4fac912017-07-05 16:25:37 +0100727 }
728 return 0;
729}
730
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600731/**
Abhishek Kulkarni0e155972009-07-19 13:41:55 -0600732 * parse_opts - parse mount options into p9_fd_opts structure
733 * @params: options string passed from mount
734 * @opts: fd transport-specific structure to parse options into
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500735 *
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600736 * Returns 0 upon success, -ERRNO upon failure
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500737 */
738
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600739static int parse_opts(char *params, struct p9_fd_opts *opts)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500740{
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500741 char *p;
742 substring_t args[MAX_OPT_ARGS];
743 int option;
Eric Van Hensbergend8c8a9e2010-02-08 16:23:23 -0600744 char *options, *tmp_options;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500745
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500746 opts->port = P9_PORT;
747 opts->rfd = ~0;
748 opts->wfd = ~0;
David Howellsc4fac912017-07-05 16:25:37 +0100749 opts->privport = false;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500750
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600751 if (!params)
752 return 0;
753
Eric Van Hensbergend8c8a9e2010-02-08 16:23:23 -0600754 tmp_options = kstrdup(params, GFP_KERNEL);
755 if (!tmp_options) {
Joe Perches5d385152011-11-28 10:40:46 -0800756 p9_debug(P9_DEBUG_ERROR,
757 "failed to allocate copy of option string\n");
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600758 return -ENOMEM;
759 }
Eric Van Hensbergend8c8a9e2010-02-08 16:23:23 -0600760 options = tmp_options;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500761
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500762 while ((p = strsep(&options, ",")) != NULL) {
763 int token;
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600764 int r;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500765 if (!*p)
766 continue;
767 token = match_token(p, tokens, args);
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700768 if ((token != Opt_err) && (token != Opt_privport)) {
Abhishek Kulkarni15da4b12009-07-01 08:50:54 +0000769 r = match_int(&args[0], &option);
770 if (r < 0) {
Joe Perches5d385152011-11-28 10:40:46 -0800771 p9_debug(P9_DEBUG_ERROR,
772 "integer field, but no integer?\n");
Abhishek Kulkarni15da4b12009-07-01 08:50:54 +0000773 continue;
774 }
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500775 }
776 switch (token) {
777 case Opt_port:
778 opts->port = option;
779 break;
780 case Opt_rfdno:
781 opts->rfd = option;
782 break;
783 case Opt_wfdno:
784 opts->wfd = option;
785 break;
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700786 case Opt_privport:
David Howellsc4fac912017-07-05 16:25:37 +0100787 opts->privport = true;
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700788 break;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500789 default:
790 continue;
791 }
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500792 }
Eric Van Hensbergend8c8a9e2010-02-08 16:23:23 -0600793
794 kfree(tmp_options);
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600795 return 0;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500796}
797
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500798static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500799{
Simon Derr263c5822014-03-11 10:13:09 +0100800 struct p9_trans_fd *ts = kzalloc(sizeof(struct p9_trans_fd),
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500801 GFP_KERNEL);
802 if (!ts)
803 return -ENOMEM;
804
805 ts->rd = fget(rfd);
Christoph Hellwiga39c4602020-07-10 10:57:22 +0200806 if (!ts->rd)
807 goto out_free_ts;
808 if (!(ts->rd->f_mode & FMODE_READ))
809 goto out_put_rd;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500810 ts->wr = fget(wfd);
Christoph Hellwiga39c4602020-07-10 10:57:22 +0200811 if (!ts->wr)
812 goto out_put_rd;
813 if (!(ts->wr->f_mode & FMODE_WRITE))
814 goto out_put_wr;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500815
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500816 client->trans = ts;
817 client->status = Connected;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500818
819 return 0;
Christoph Hellwiga39c4602020-07-10 10:57:22 +0200820
821out_put_wr:
822 fput(ts->wr);
823out_put_rd:
824 fput(ts->rd);
825out_free_ts:
826 kfree(ts);
827 return -EIO;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500828}
829
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500830static int p9_socket_open(struct p9_client *client, struct socket *csocket)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500831{
Al Viro6b186622009-08-06 02:02:43 +0400832 struct p9_trans_fd *p;
Al Viro56b31d12012-08-18 00:25:51 -0400833 struct file *file;
Al Viro6b186622009-08-06 02:02:43 +0400834
Simon Derr263c5822014-03-11 10:13:09 +0100835 p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL);
Al Viro6b186622009-08-06 02:02:43 +0400836 if (!p)
837 return -ENOMEM;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500838
839 csocket->sk->sk_allocation = GFP_NOIO;
Linus Torvaldsaab174f2012-10-02 20:25:04 -0700840 file = sock_alloc_file(csocket, 0, NULL);
Al Viro56b31d12012-08-18 00:25:51 -0400841 if (IS_ERR(file)) {
Joe Perches5d385152011-11-28 10:40:46 -0800842 pr_err("%s (%d): failed to map fd\n",
843 __func__, task_pid_nr(current));
Al Viro6b186622009-08-06 02:02:43 +0400844 kfree(p);
Al Viro56b31d12012-08-18 00:25:51 -0400845 return PTR_ERR(file);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500846 }
847
Al Viro56b31d12012-08-18 00:25:51 -0400848 get_file(file);
849 p->wr = p->rd = file;
Al Viro6b186622009-08-06 02:02:43 +0400850 client->trans = p;
851 client->status = Connected;
852
Al Viro6b186622009-08-06 02:02:43 +0400853 p->rd->f_flags |= O_NONBLOCK;
854
Simon Derr263c5822014-03-11 10:13:09 +0100855 p9_conn_create(client);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500856 return 0;
857}
858
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500859/**
Simon Derr263c5822014-03-11 10:13:09 +0100860 * p9_mux_destroy - cancels all pending requests of mux
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500861 * @m: mux to destroy
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500862 *
863 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600864
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500865static void p9_conn_destroy(struct p9_conn *m)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500866{
Joe Perches5d385152011-11-28 10:40:46 -0800867 p9_debug(P9_DEBUG_TRANS, "mux %p prev %p next %p\n",
868 m, m->mux_list.prev, m->mux_list.next);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500869
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500870 p9_mux_poll_stop(m);
871 cancel_work_sync(&m->rq);
Dominique Martinetfb488fc2018-10-09 11:38:00 +0900872 if (m->rreq) {
873 p9_req_put(m->rreq);
874 m->rreq = NULL;
875 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500876 cancel_work_sync(&m->wq);
Dominique Martinetfb488fc2018-10-09 11:38:00 +0900877 if (m->wreq) {
878 p9_req_put(m->wreq);
879 m->wreq = NULL;
880 }
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500881
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500882 p9_conn_cancel(m, -ECONNRESET);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500883
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500884 m->client = NULL;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500885}
886
887/**
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500888 * p9_fd_close - shutdown file descriptor transport
889 * @client: client instance
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500890 *
891 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600892
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500893static void p9_fd_close(struct p9_client *client)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500894{
895 struct p9_trans_fd *ts;
896
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500897 if (!client)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500898 return;
899
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500900 ts = client->trans;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500901 if (!ts)
902 return;
903
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500904 client->status = Disconnected;
905
Simon Derr263c5822014-03-11 10:13:09 +0100906 p9_conn_destroy(&ts->conn);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600907
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500908 if (ts->rd)
909 fput(ts->rd);
910 if (ts->wr)
911 fput(ts->wr);
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500912
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500913 kfree(ts);
914}
915
Eric Van Hensbergen887b3ec2008-05-08 20:26:37 -0500916/*
917 * stolen from NFS - maybe should be made a generic function?
918 */
919static inline int valid_ipaddr4(const char *buf)
920{
921 int rc, count, in[4];
922
923 rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
924 if (rc != 4)
925 return -EINVAL;
926 for (count = 0; count < 4; count++) {
927 if (in[count] > 255)
928 return -EINVAL;
929 }
930 return 0;
931}
932
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700933static int p9_bind_privport(struct socket *sock)
934{
935 struct sockaddr_in cl;
936 int port, err = -EINVAL;
937
938 memset(&cl, 0, sizeof(cl));
939 cl.sin_family = AF_INET;
940 cl.sin_addr.s_addr = INADDR_ANY;
941 for (port = p9_ipport_resv_max; port >= p9_ipport_resv_min; port--) {
942 cl.sin_port = htons((ushort)port);
943 err = kernel_bind(sock, (struct sockaddr *)&cl, sizeof(cl));
944 if (err != -EADDRINUSE)
945 break;
946 }
947 return err;
948}
949
950
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500951static int
952p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500953{
954 int err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500955 struct socket *csocket;
956 struct sockaddr_in sin_server;
957 struct p9_fd_opts opts;
958
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600959 err = parse_opts(args, &opts);
960 if (err < 0)
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500961 return err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500962
Tomas Bortoli10aa1452018-07-27 13:05:58 +0200963 if (addr == NULL || valid_ipaddr4(addr) < 0)
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500964 return -EINVAL;
Eric Van Hensbergen887b3ec2008-05-08 20:26:37 -0500965
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500966 csocket = NULL;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500967
David Howellsc4fac912017-07-05 16:25:37 +0100968 client->trans_opts.tcp.port = opts.port;
969 client->trans_opts.tcp.privport = opts.privport;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500970 sin_server.sin_family = AF_INET;
971 sin_server.sin_addr.s_addr = in_aton(addr);
972 sin_server.sin_port = htons(opts.port);
Eric W. Biederman0c5c9fb2015-03-11 23:06:44 -0500973 err = __sock_create(current->nsproxy->net_ns, PF_INET,
Rob Landleye75762f2011-05-23 21:46:56 -0500974 SOCK_STREAM, IPPROTO_TCP, &csocket, 1);
Al Viro6b186622009-08-06 02:02:43 +0400975 if (err) {
Joe Perches5d385152011-11-28 10:40:46 -0800976 pr_err("%s (%d): problem creating socket\n",
977 __func__, task_pid_nr(current));
Al Viro6b186622009-08-06 02:02:43 +0400978 return err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500979 }
980
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700981 if (opts.privport) {
982 err = p9_bind_privport(csocket);
983 if (err < 0) {
984 pr_err("%s (%d): problem binding to privport\n",
985 __func__, task_pid_nr(current));
986 sock_release(csocket);
987 return err;
988 }
989 }
990
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500991 err = csocket->ops->connect(csocket,
992 (struct sockaddr *)&sin_server,
993 sizeof(struct sockaddr_in), 0);
994 if (err < 0) {
Joe Perches5d385152011-11-28 10:40:46 -0800995 pr_err("%s (%d): problem connecting socket to %s\n",
996 __func__, task_pid_nr(current), addr);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500997 sock_release(csocket);
Al Viro6b186622009-08-06 02:02:43 +0400998 return err;
999 }
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001000
Al Viro6b186622009-08-06 02:02:43 +04001001 return p9_socket_open(client, csocket);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001002}
1003
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001004static int
1005p9_fd_create_unix(struct p9_client *client, const char *addr, char *args)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001006{
1007 int err;
1008 struct socket *csocket;
1009 struct sockaddr_un sun_server;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001010
1011 csocket = NULL;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001012
Tomas Bortoli10aa1452018-07-27 13:05:58 +02001013 if (addr == NULL)
1014 return -EINVAL;
1015
Dan Carpentercff6b8a2010-07-10 11:51:54 +02001016 if (strlen(addr) >= UNIX_PATH_MAX) {
Joe Perches5d385152011-11-28 10:40:46 -08001017 pr_err("%s (%d): address too long: %s\n",
1018 __func__, task_pid_nr(current), addr);
Al Viro6b186622009-08-06 02:02:43 +04001019 return -ENAMETOOLONG;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001020 }
1021
1022 sun_server.sun_family = PF_UNIX;
1023 strcpy(sun_server.sun_path, addr);
Eric W. Biederman0c5c9fb2015-03-11 23:06:44 -05001024 err = __sock_create(current->nsproxy->net_ns, PF_UNIX,
Rob Landleye75762f2011-05-23 21:46:56 -05001025 SOCK_STREAM, 0, &csocket, 1);
Al Viro6b186622009-08-06 02:02:43 +04001026 if (err < 0) {
Joe Perches5d385152011-11-28 10:40:46 -08001027 pr_err("%s (%d): problem creating socket\n",
1028 __func__, task_pid_nr(current));
1029
Al Viro6b186622009-08-06 02:02:43 +04001030 return err;
1031 }
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001032 err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server,
1033 sizeof(struct sockaddr_un) - 1, 0);
1034 if (err < 0) {
Joe Perches5d385152011-11-28 10:40:46 -08001035 pr_err("%s (%d): problem connecting socket: %s: %d\n",
1036 __func__, task_pid_nr(current), addr, err);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001037 sock_release(csocket);
Al Viro6b186622009-08-06 02:02:43 +04001038 return err;
1039 }
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001040
Al Viro6b186622009-08-06 02:02:43 +04001041 return p9_socket_open(client, csocket);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001042}
1043
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001044static int
1045p9_fd_create(struct p9_client *client, const char *addr, char *args)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001046{
1047 int err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001048 struct p9_fd_opts opts;
1049
1050 parse_opts(args, &opts);
David Howellsc4fac912017-07-05 16:25:37 +01001051 client->trans_opts.fd.rfd = opts.rfd;
1052 client->trans_opts.fd.wfd = opts.wfd;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001053
1054 if (opts.rfd == ~0 || opts.wfd == ~0) {
Joe Perches5d385152011-11-28 10:40:46 -08001055 pr_err("Insufficient options for proto=fd\n");
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001056 return -ENOPROTOOPT;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001057 }
1058
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001059 err = p9_fd_open(client, opts.rfd, opts.wfd);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001060 if (err < 0)
Al Viro6b186622009-08-06 02:02:43 +04001061 return err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001062
Simon Derr263c5822014-03-11 10:13:09 +01001063 p9_conn_create(client);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -06001064
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001065 return 0;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001066}
1067
1068static struct p9_trans_module p9_tcp_trans = {
1069 .name = "tcp",
1070 .maxsize = MAX_SOCK_BUF,
Eric Van Hensbergenf94741f2013-11-12 10:20:03 -06001071 .def = 0,
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001072 .create = p9_fd_create_tcp,
1073 .close = p9_fd_close,
Eric Van Hensbergen91b85342008-10-13 18:45:21 -05001074 .request = p9_fd_request,
1075 .cancel = p9_fd_cancel,
Simon Derrafd8d652014-03-10 16:38:49 +01001076 .cancelled = p9_fd_cancelled,
David Howellsc4fac912017-07-05 16:25:37 +01001077 .show_options = p9_fd_show_options,
Tejun Heo72029fe2008-09-24 16:22:23 -05001078 .owner = THIS_MODULE,
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001079};
1080
1081static struct p9_trans_module p9_unix_trans = {
1082 .name = "unix",
1083 .maxsize = MAX_SOCK_BUF,
1084 .def = 0,
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001085 .create = p9_fd_create_unix,
1086 .close = p9_fd_close,
Eric Van Hensbergen91b85342008-10-13 18:45:21 -05001087 .request = p9_fd_request,
1088 .cancel = p9_fd_cancel,
Simon Derrafd8d652014-03-10 16:38:49 +01001089 .cancelled = p9_fd_cancelled,
David Howellsc4fac912017-07-05 16:25:37 +01001090 .show_options = p9_fd_show_options,
Tejun Heo72029fe2008-09-24 16:22:23 -05001091 .owner = THIS_MODULE,
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001092};
1093
1094static struct p9_trans_module p9_fd_trans = {
1095 .name = "fd",
1096 .maxsize = MAX_SOCK_BUF,
1097 .def = 0,
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001098 .create = p9_fd_create,
1099 .close = p9_fd_close,
Eric Van Hensbergen91b85342008-10-13 18:45:21 -05001100 .request = p9_fd_request,
1101 .cancel = p9_fd_cancel,
Simon Derrafd8d652014-03-10 16:38:49 +01001102 .cancelled = p9_fd_cancelled,
David Howellsc4fac912017-07-05 16:25:37 +01001103 .show_options = p9_fd_show_options,
Tejun Heo72029fe2008-09-24 16:22:23 -05001104 .owner = THIS_MODULE,
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001105};
1106
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001107/**
Sun Lianwen4a026da2018-05-08 09:49:38 +08001108 * p9_poll_workfn - poll worker thread
1109 * @work: work queue
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001110 *
1111 * polls all v9fs transports for new events and queues the appropriate
1112 * work to the work queue
1113 *
1114 */
1115
Tejun Heoaa70c582011-02-01 11:42:43 +01001116static void p9_poll_workfn(struct work_struct *work)
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001117{
1118 unsigned long flags;
1119
Joe Perches5d385152011-11-28 10:40:46 -08001120 p9_debug(P9_DEBUG_TRANS, "start %p\n", current);
Tejun Heoaa70c582011-02-01 11:42:43 +01001121
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001122 spin_lock_irqsave(&p9_poll_lock, flags);
1123 while (!list_empty(&p9_poll_pending_list)) {
1124 struct p9_conn *conn = list_first_entry(&p9_poll_pending_list,
1125 struct p9_conn,
1126 poll_pending_link);
1127 list_del_init(&conn->poll_pending_link);
1128 spin_unlock_irqrestore(&p9_poll_lock, flags);
1129
1130 p9_poll_mux(conn);
1131
1132 spin_lock_irqsave(&p9_poll_lock, flags);
1133 }
1134 spin_unlock_irqrestore(&p9_poll_lock, flags);
1135
Joe Perches5d385152011-11-28 10:40:46 -08001136 p9_debug(P9_DEBUG_TRANS, "finish\n");
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001137}
1138
Eric Van Hensbergen887b3ec2008-05-08 20:26:37 -05001139int p9_trans_fd_init(void)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001140{
1141 v9fs_register_trans(&p9_tcp_trans);
1142 v9fs_register_trans(&p9_unix_trans);
1143 v9fs_register_trans(&p9_fd_trans);
1144
Andrew Morton3387b802008-03-28 14:15:57 -07001145 return 0;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001146}
Tejun Heo72029fe2008-09-24 16:22:23 -05001147
1148void p9_trans_fd_exit(void)
1149{
Tejun Heo43829732012-08-20 14:51:24 -07001150 flush_work(&p9_poll_work);
Tejun Heo72029fe2008-09-24 16:22:23 -05001151 v9fs_unregister_trans(&p9_tcp_trans);
1152 v9fs_unregister_trans(&p9_unix_trans);
1153 v9fs_unregister_trans(&p9_fd_trans);
1154}