blob: f868cf6fba7946c87d0bb152dbd35ba61e3eb0fb [file] [log] [blame]
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001/*
2 * linux/fs/9p/trans_fd.c
3 *
4 * Fd transport layer. Includes deprecated socket layer.
5 *
6 * Copyright (C) 2006 by Russ Cox <rsc@swtch.com>
7 * Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net>
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -06008 * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05009 * Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to:
22 * Free Software Foundation
23 * 51 Franklin Street, Fifth Floor
24 * Boston, MA 02111-1301 USA
25 *
26 */
27
Joe Perches5d385152011-11-28 10:40:46 -080028#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050030#include <linux/in.h>
31#include <linux/module.h>
32#include <linux/net.h>
33#include <linux/ipv6.h>
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -060034#include <linux/kthread.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050035#include <linux/errno.h>
36#include <linux/kernel.h>
37#include <linux/un.h>
38#include <linux/uaccess.h>
39#include <linux/inet.h>
40#include <linux/idr.h>
41#include <linux/file.h>
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050042#include <linux/parser.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090043#include <linux/slab.h>
David Howellsc4fac912017-07-05 16:25:37 +010044#include <linux/seq_file.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050045#include <net/9p/9p.h>
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -050046#include <net/9p/client.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050047#include <net/9p/transport.h>
48
Al Viro6b186622009-08-06 02:02:43 +040049#include <linux/syscalls.h> /* killme */
50
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050051#define P9_PORT 564
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050052#define MAX_SOCK_BUF (64*1024)
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -060053#define MAXPOLLWADDR 2
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050054
David Howellsc4fac912017-07-05 16:25:37 +010055static struct p9_trans_module p9_tcp_trans;
56static struct p9_trans_module p9_fd_trans;
57
Eric Van Hensbergenee443992008-03-05 07:08:09 -060058/**
59 * struct p9_fd_opts - per-transport options
60 * @rfd: file descriptor for reading (trans=fd)
61 * @wfd: file descriptor for writing (trans=fd)
62 * @port: port to connect to (trans=tcp)
63 *
64 */
65
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050066struct p9_fd_opts {
67 int rfd;
68 int wfd;
69 u16 port;
David Howellsc4fac912017-07-05 16:25:37 +010070 bool privport;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050071};
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050072
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050073/*
74 * Option Parsing (code inspired by NFS code)
75 * - a little lazy - parse all fd-transport options
76 */
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050077
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050078enum {
79 /* Options that take integer arguments */
Latchesar Ionkov55762692007-11-06 08:02:53 -060080 Opt_port, Opt_rfdno, Opt_wfdno, Opt_err,
Jim Garlick2f28c8b2013-05-29 12:15:07 -070081 /* Options that take no arguments */
82 Opt_privport,
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050083};
84
Steven Whitehousea447c092008-10-13 10:46:57 +010085static const match_table_t tokens = {
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050086 {Opt_port, "port=%u"},
87 {Opt_rfdno, "rfdno=%u"},
88 {Opt_wfdno, "wfdno=%u"},
Jim Garlick2f28c8b2013-05-29 12:15:07 -070089 {Opt_privport, "privport"},
Latchesar Ionkov55762692007-11-06 08:02:53 -060090 {Opt_err, NULL},
Eric Van Hensbergena80d9232007-10-17 14:31:07 -050091};
92
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -060093enum {
94 Rworksched = 1, /* read work scheduled or running */
95 Rpending = 2, /* can read */
96 Wworksched = 4, /* write work scheduled or running */
97 Wpending = 8, /* can write */
98};
99
Tejun Heo992b3f12008-10-13 18:45:25 -0500100struct p9_poll_wait {
101 struct p9_conn *conn;
Ingo Molnarac6424b2017-06-20 12:06:13 +0200102 wait_queue_entry_t wait;
Tejun Heo992b3f12008-10-13 18:45:25 -0500103 wait_queue_head_t *wait_addr;
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600104};
105
106/**
107 * struct p9_conn - fd mux connection state information
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600108 * @mux_list: list link for mux to manage multiple connections (?)
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500109 * @client: reference to client instance for this connection
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600110 * @err: error state
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600111 * @req_list: accounting for requests which have been sent
112 * @unsent_req_list: accounting for requests that haven't been sent
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500113 * @req: current request being processed (if any)
114 * @tmp_buf: temporary buffer to read in header
Dominique Martinet947867a2015-09-03 11:28:20 +0200115 * @rc: temporary fcall for reading current frame
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600116 * @wpos: write position for current frame
117 * @wsize: amount of data to write for current frame
118 * @wbuf: current write buffer
Abhishek Kulkarni0e155972009-07-19 13:41:55 -0600119 * @poll_pending_link: pending links to be polled per conn
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600120 * @poll_wait: array of wait_q's for various worker threads
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600121 * @pt: poll state
122 * @rq: current read work
123 * @wq: current write work
124 * @wsched: ????
125 *
126 */
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600127
128struct p9_conn {
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600129 struct list_head mux_list;
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500130 struct p9_client *client;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600131 int err;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600132 struct list_head req_list;
133 struct list_head unsent_req_list;
Tomas Bortoli3dc511c2018-09-03 18:03:21 +0200134 struct p9_req_t *rreq;
Tomas Bortoli3665a4d2018-08-14 19:43:42 +0200135 struct p9_req_t *wreq;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500136 char tmp_buf[7];
Dominique Martinet947867a2015-09-03 11:28:20 +0200137 struct p9_fcall rc;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600138 int wpos;
139 int wsize;
140 char *wbuf;
Tejun Heo992b3f12008-10-13 18:45:25 -0500141 struct list_head poll_pending_link;
142 struct p9_poll_wait poll_wait[MAXPOLLWADDR];
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600143 poll_table pt;
144 struct work_struct rq;
145 struct work_struct wq;
146 unsigned long wsched;
147};
148
Simon Derr263c5822014-03-11 10:13:09 +0100149/**
150 * struct p9_trans_fd - transport state
151 * @rd: reference to file to read from
152 * @wr: reference of file to write to
153 * @conn: connection state reference
154 *
155 */
156
157struct p9_trans_fd {
158 struct file *rd;
159 struct file *wr;
160 struct p9_conn conn;
161};
162
Tejun Heoaa70c582011-02-01 11:42:43 +0100163static void p9_poll_workfn(struct work_struct *work);
164
Tejun Heo992b3f12008-10-13 18:45:25 -0500165static DEFINE_SPINLOCK(p9_poll_lock);
166static LIST_HEAD(p9_poll_pending_list);
Tejun Heoaa70c582011-02-01 11:42:43 +0100167static DECLARE_WORK(p9_poll_work, p9_poll_workfn);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600168
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700169static unsigned int p9_ipport_resv_min = P9_DEF_MIN_RESVPORT;
170static unsigned int p9_ipport_resv_max = P9_DEF_MAX_RESVPORT;
171
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600172static void p9_mux_poll_stop(struct p9_conn *m)
173{
Tejun Heo992b3f12008-10-13 18:45:25 -0500174 unsigned long flags;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600175 int i;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600176
Tejun Heo992b3f12008-10-13 18:45:25 -0500177 for (i = 0; i < ARRAY_SIZE(m->poll_wait); i++) {
178 struct p9_poll_wait *pwait = &m->poll_wait[i];
179
180 if (pwait->wait_addr) {
181 remove_wait_queue(pwait->wait_addr, &pwait->wait);
182 pwait->wait_addr = NULL;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600183 }
184 }
Tejun Heo992b3f12008-10-13 18:45:25 -0500185
186 spin_lock_irqsave(&p9_poll_lock, flags);
187 list_del_init(&m->poll_pending_link);
188 spin_unlock_irqrestore(&p9_poll_lock, flags);
Tomas Bortoli430ac662018-07-20 11:27:30 +0200189
190 flush_work(&p9_poll_work);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600191}
192
193/**
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500194 * p9_conn_cancel - cancel all pending requests with error
195 * @m: mux data
196 * @err: error code
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600197 *
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600198 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600199
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500200static void p9_conn_cancel(struct p9_conn *m, int err)
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600201{
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500202 struct p9_req_t *req, *rtmp;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500203 LIST_HEAD(cancel_list);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600204
Joe Perches5d385152011-11-28 10:40:46 -0800205 p9_debug(P9_DEBUG_ERROR, "mux %p err %d\n", m, err);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500206
Tomas Bortoli9f476d72018-07-23 20:42:53 +0200207 spin_lock(&m->client->lock);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500208
209 if (m->err) {
Tomas Bortoli9f476d72018-07-23 20:42:53 +0200210 spin_unlock(&m->client->lock);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500211 return;
212 }
213
214 m->err = err;
215
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500216 list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) {
217 list_move(&req->req_list, &cancel_list);
Tejun Heo992b3f12008-10-13 18:45:25 -0500218 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500219 list_for_each_entry_safe(req, rtmp, &m->unsent_req_list, req_list) {
220 list_move(&req->req_list, &cancel_list);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600221 }
222
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500223 list_for_each_entry_safe(req, rtmp, &cancel_list, req_list) {
Joe Perches5d385152011-11-28 10:40:46 -0800224 p9_debug(P9_DEBUG_ERROR, "call back req %p\n", req);
Latchesar Ionkov1bab88b2009-04-05 16:28:59 -0500225 list_del(&req->req_list);
Dominique Martinet2b6e72e2014-01-17 18:31:00 +0100226 if (!req->t_err)
227 req->t_err = err;
228 p9_client_cb(m->client, req, REQ_STATUS_ERROR);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600229 }
Tomas Bortoli9f476d72018-07-23 20:42:53 +0200230 spin_unlock(&m->client->lock);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600231}
232
Al Viro7594bf32017-07-16 22:53:08 -0400233static __poll_t
234p9_fd_poll(struct p9_client *client, struct poll_table_struct *pt, int *err)
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500235{
Christoph Hellwig9965ed172018-03-05 07:26:05 -0800236 __poll_t ret;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500237 struct p9_trans_fd *ts = NULL;
238
239 if (client && client->status == Connected)
240 ts = client->trans;
241
Al Viro7594bf32017-07-16 22:53:08 -0400242 if (!ts) {
243 if (err)
244 *err = -EREMOTEIO;
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800245 return EPOLLERR;
Al Viro7594bf32017-07-16 22:53:08 -0400246 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500247
Christoph Hellwig9965ed172018-03-05 07:26:05 -0800248 ret = vfs_poll(ts->rd, pt);
249 if (ts->rd != ts->wr)
250 ret = (ret & ~EPOLLOUT) | (vfs_poll(ts->wr, pt) & ~EPOLLIN);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500251 return ret;
252}
253
254/**
255 * p9_fd_read- read from a fd
256 * @client: client instance
257 * @v: buffer to receive data into
258 * @len: size of receive buffer
259 *
260 */
261
262static int p9_fd_read(struct p9_client *client, void *v, int len)
263{
264 int ret;
265 struct p9_trans_fd *ts = NULL;
Christoph Hellwigbdd1d2d2017-09-01 17:39:13 +0200266 loff_t pos;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500267
268 if (client && client->status != Disconnected)
269 ts = client->trans;
270
271 if (!ts)
272 return -EREMOTEIO;
273
274 if (!(ts->rd->f_flags & O_NONBLOCK))
Joe Perches5d385152011-11-28 10:40:46 -0800275 p9_debug(P9_DEBUG_ERROR, "blocking read ...\n");
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500276
Christoph Hellwigbdd1d2d2017-09-01 17:39:13 +0200277 pos = ts->rd->f_pos;
278 ret = kernel_read(ts->rd, v, len, &pos);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500279 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
280 client->status = Disconnected;
281 return ret;
282}
283
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600284/**
285 * p9_read_work - called when there is some data to be read from a transport
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600286 * @work: container of work to be done
287 *
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600288 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600289
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600290static void p9_read_work(struct work_struct *work)
291{
Al Viro7594bf32017-07-16 22:53:08 -0400292 __poll_t n;
293 int err;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600294 struct p9_conn *m;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600295
296 m = container_of(work, struct p9_conn, rq);
297
298 if (m->err < 0)
299 return;
300
Dominique Martinet947867a2015-09-03 11:28:20 +0200301 p9_debug(P9_DEBUG_TRANS, "start mux %p pos %zd\n", m, m->rc.offset);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600302
Dominique Martinet947867a2015-09-03 11:28:20 +0200303 if (!m->rc.sdata) {
304 m->rc.sdata = m->tmp_buf;
305 m->rc.offset = 0;
306 m->rc.capacity = 7; /* start by reading header */
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600307 }
308
309 clear_bit(Rpending, &m->wsched);
Dominique Martinet947867a2015-09-03 11:28:20 +0200310 p9_debug(P9_DEBUG_TRANS, "read mux %p pos %zd size: %zd = %zd\n",
311 m, m->rc.offset, m->rc.capacity,
312 m->rc.capacity - m->rc.offset);
313 err = p9_fd_read(m->client, m->rc.sdata + m->rc.offset,
314 m->rc.capacity - m->rc.offset);
Joe Perches5d385152011-11-28 10:40:46 -0800315 p9_debug(P9_DEBUG_TRANS, "mux %p got %d bytes\n", m, err);
Dominique Martinet947867a2015-09-03 11:28:20 +0200316 if (err == -EAGAIN)
Simon Derr04621942012-09-17 15:16:28 +0200317 goto end_clear;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600318
319 if (err <= 0)
320 goto error;
321
Dominique Martinet947867a2015-09-03 11:28:20 +0200322 m->rc.offset += err;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500323
Dominique Martinet947867a2015-09-03 11:28:20 +0200324 /* header read in */
Tomas Bortoli3dc511c2018-09-03 18:03:21 +0200325 if ((!m->rreq) && (m->rc.offset == m->rc.capacity)) {
Joe Perches5d385152011-11-28 10:40:46 -0800326 p9_debug(P9_DEBUG_TRANS, "got new header\n");
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500327
Tomas Bortolif9845792018-07-23 17:44:04 +0200328 /* Header size */
329 m->rc.size = 7;
330 err = p9_parse_header(&m->rc, &m->rc.size, NULL, NULL, 0);
Dominique Martinet947867a2015-09-03 11:28:20 +0200331 if (err) {
Joe Perches5d385152011-11-28 10:40:46 -0800332 p9_debug(P9_DEBUG_ERROR,
Dominique Martinet947867a2015-09-03 11:28:20 +0200333 "error parsing header: %d\n", err);
334 goto error;
335 }
336
337 if (m->rc.size >= m->client->msize) {
338 p9_debug(P9_DEBUG_ERROR,
339 "requested packet size too big: %d\n",
340 m->rc.size);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600341 err = -EIO;
342 goto error;
343 }
344
Joe Perches5d385152011-11-28 10:40:46 -0800345 p9_debug(P9_DEBUG_TRANS,
Dominique Martinet947867a2015-09-03 11:28:20 +0200346 "mux %p pkt: size: %d bytes tag: %d\n",
347 m, m->rc.size, m->rc.tag);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600348
Tomas Bortoli3dc511c2018-09-03 18:03:21 +0200349 m->rreq = p9_tag_lookup(m->client, m->rc.tag);
350 if (!m->rreq || (m->rreq->status != REQ_STATUS_SENT)) {
Joe Perches5d385152011-11-28 10:40:46 -0800351 p9_debug(P9_DEBUG_ERROR, "Unexpected packet tag %d\n",
Dominique Martinet947867a2015-09-03 11:28:20 +0200352 m->rc.tag);
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500353 err = -EIO;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600354 goto error;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500355 }
356
Tomas Bortoli3dc511c2018-09-03 18:03:21 +0200357 if (!m->rreq->rc.sdata) {
Dominique Martinet30536002015-09-07 17:06:54 +0200358 p9_debug(P9_DEBUG_ERROR,
359 "No recv fcall for tag %d (req %p), disconnecting!\n",
Tomas Bortoli3dc511c2018-09-03 18:03:21 +0200360 m->rc.tag, m->rreq);
361 m->rreq = NULL;
Dominique Martinet30536002015-09-07 17:06:54 +0200362 err = -EIO;
363 goto error;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500364 }
Tomas Bortoli3dc511c2018-09-03 18:03:21 +0200365 m->rc.sdata = m->rreq->rc.sdata;
Dominique Martinet947867a2015-09-03 11:28:20 +0200366 memcpy(m->rc.sdata, m->tmp_buf, m->rc.capacity);
367 m->rc.capacity = m->rc.size;
Eric Van Hensbergen1b0a7632008-10-13 18:45:22 -0500368 }
369
Dominique Martinet947867a2015-09-03 11:28:20 +0200370 /* packet is read in
371 * not an else because some packets (like clunk) have no payload
372 */
Tomas Bortoli3dc511c2018-09-03 18:03:21 +0200373 if ((m->rreq) && (m->rc.offset == m->rc.capacity)) {
Joe Perches5d385152011-11-28 10:40:46 -0800374 p9_debug(P9_DEBUG_TRANS, "got new packet\n");
Tomas Bortoli3dc511c2018-09-03 18:03:21 +0200375 m->rreq->rc.size = m->rc.offset;
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500376 spin_lock(&m->client->lock);
Dominique Martinet6fad4692018-10-09 11:18:52 +0900377 if (m->rreq->status == REQ_STATUS_SENT) {
378 list_del(&m->rreq->req_list);
379 p9_client_cb(m->client, m->rreq, REQ_STATUS_RCVD);
380 } else {
381 spin_unlock(&m->client->lock);
382 p9_debug(P9_DEBUG_ERROR,
383 "Request tag %d errored out while we were reading the reply\n",
384 m->rc.tag);
385 err = -EIO;
386 goto error;
387 }
Tomas Bortoli9f476d72018-07-23 20:42:53 +0200388 spin_unlock(&m->client->lock);
Dominique Martinet947867a2015-09-03 11:28:20 +0200389 m->rc.sdata = NULL;
390 m->rc.offset = 0;
391 m->rc.capacity = 0;
Tomas Bortoli3dc511c2018-09-03 18:03:21 +0200392 p9_req_put(m->rreq);
393 m->rreq = NULL;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600394 }
395
Simon Derr04621942012-09-17 15:16:28 +0200396end_clear:
397 clear_bit(Rworksched, &m->wsched);
398
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600399 if (!list_empty(&m->req_list)) {
400 if (test_and_clear_bit(Rpending, &m->wsched))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800401 n = EPOLLIN;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600402 else
Al Viro7594bf32017-07-16 22:53:08 -0400403 n = p9_fd_poll(m->client, NULL, NULL);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600404
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800405 if ((n & EPOLLIN) && !test_and_set_bit(Rworksched, &m->wsched)) {
Joe Perches5d385152011-11-28 10:40:46 -0800406 p9_debug(P9_DEBUG_TRANS, "sched read work %p\n", m);
Tejun Heo61edeee2011-02-01 11:42:43 +0100407 schedule_work(&m->rq);
Simon Derr04621942012-09-17 15:16:28 +0200408 }
409 }
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600410
411 return;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600412error:
413 p9_conn_cancel(m, err);
414 clear_bit(Rworksched, &m->wsched);
415}
416
417/**
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500418 * p9_fd_write - write to a socket
419 * @client: client instance
420 * @v: buffer to send data from
421 * @len: size of send buffer
422 *
423 */
424
425static int p9_fd_write(struct p9_client *client, void *v, int len)
426{
Christoph Hellwig670986e2017-09-01 17:39:18 +0200427 ssize_t ret;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500428 struct p9_trans_fd *ts = NULL;
429
430 if (client && client->status != Disconnected)
431 ts = client->trans;
432
433 if (!ts)
434 return -EREMOTEIO;
435
436 if (!(ts->wr->f_flags & O_NONBLOCK))
Joe Perches5d385152011-11-28 10:40:46 -0800437 p9_debug(P9_DEBUG_ERROR, "blocking write ...\n");
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500438
Christoph Hellwig670986e2017-09-01 17:39:18 +0200439 ret = kernel_write(ts->wr, v, len, &ts->wr->f_pos);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500440 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
441 client->status = Disconnected;
442 return ret;
443}
444
445/**
446 * p9_write_work - called when a transport can send some data
447 * @work: container for work to be done
448 *
449 */
450
451static void p9_write_work(struct work_struct *work)
452{
Al Viro7594bf32017-07-16 22:53:08 -0400453 __poll_t n;
454 int err;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500455 struct p9_conn *m;
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500456 struct p9_req_t *req;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500457
458 m = container_of(work, struct p9_conn, wq);
459
460 if (m->err < 0) {
461 clear_bit(Wworksched, &m->wsched);
462 return;
463 }
464
465 if (!m->wsize) {
Simon Derr759f4292012-09-17 15:16:31 +0200466 spin_lock(&m->client->lock);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500467 if (list_empty(&m->unsent_req_list)) {
468 clear_bit(Wworksched, &m->wsched);
Simon Derr759f4292012-09-17 15:16:31 +0200469 spin_unlock(&m->client->lock);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500470 return;
471 }
472
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500473 req = list_entry(m->unsent_req_list.next, struct p9_req_t,
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500474 req_list);
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500475 req->status = REQ_STATUS_SENT;
Joe Perches5d385152011-11-28 10:40:46 -0800476 p9_debug(P9_DEBUG_TRANS, "move req %p\n", req);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500477 list_move_tail(&req->req_list, &m->req_list);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500478
Dominique Martinet15555832018-07-30 05:55:19 +0000479 m->wbuf = req->tc.sdata;
480 m->wsize = req->tc.size;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500481 m->wpos = 0;
Tomas Bortoli3665a4d2018-08-14 19:43:42 +0200482 p9_req_get(req);
483 m->wreq = req;
Eric Van Hensbergen673d62cd2008-10-13 18:45:22 -0500484 spin_unlock(&m->client->lock);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500485 }
486
Joe Perches5d385152011-11-28 10:40:46 -0800487 p9_debug(P9_DEBUG_TRANS, "mux %p pos %d size %d\n",
488 m, m->wpos, m->wsize);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500489 clear_bit(Wpending, &m->wsched);
490 err = p9_fd_write(m->client, m->wbuf + m->wpos, m->wsize - m->wpos);
Joe Perches5d385152011-11-28 10:40:46 -0800491 p9_debug(P9_DEBUG_TRANS, "mux %p sent %d bytes\n", m, err);
Simon Derr584a8c12012-09-17 15:16:30 +0200492 if (err == -EAGAIN)
493 goto end_clear;
494
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500495
496 if (err < 0)
497 goto error;
498 else if (err == 0) {
499 err = -EREMOTEIO;
500 goto error;
501 }
502
503 m->wpos += err;
Tomas Bortoli3665a4d2018-08-14 19:43:42 +0200504 if (m->wpos == m->wsize) {
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500505 m->wpos = m->wsize = 0;
Tomas Bortoli3665a4d2018-08-14 19:43:42 +0200506 p9_req_put(m->wreq);
507 m->wreq = NULL;
508 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500509
Simon Derr584a8c12012-09-17 15:16:30 +0200510end_clear:
511 clear_bit(Wworksched, &m->wsched);
512
Simon Derr1957b3a2012-09-17 15:16:29 +0200513 if (m->wsize || !list_empty(&m->unsent_req_list)) {
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500514 if (test_and_clear_bit(Wpending, &m->wsched))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800515 n = EPOLLOUT;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500516 else
Al Viro7594bf32017-07-16 22:53:08 -0400517 n = p9_fd_poll(m->client, NULL, NULL);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500518
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800519 if ((n & EPOLLOUT) &&
Simon Derr584a8c12012-09-17 15:16:30 +0200520 !test_and_set_bit(Wworksched, &m->wsched)) {
Joe Perches5d385152011-11-28 10:40:46 -0800521 p9_debug(P9_DEBUG_TRANS, "sched write work %p\n", m);
Tejun Heo61edeee2011-02-01 11:42:43 +0100522 schedule_work(&m->wq);
Simon Derr584a8c12012-09-17 15:16:30 +0200523 }
524 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500525
526 return;
527
528error:
529 p9_conn_cancel(m, err);
530 clear_bit(Wworksched, &m->wsched);
531}
532
Ingo Molnarac6424b2017-06-20 12:06:13 +0200533static int p9_pollwake(wait_queue_entry_t *wait, unsigned int mode, int sync, void *key)
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500534{
535 struct p9_poll_wait *pwait =
536 container_of(wait, struct p9_poll_wait, wait);
537 struct p9_conn *m = pwait->conn;
538 unsigned long flags;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500539
540 spin_lock_irqsave(&p9_poll_lock, flags);
541 if (list_empty(&m->poll_pending_link))
542 list_add_tail(&m->poll_pending_link, &p9_poll_pending_list);
543 spin_unlock_irqrestore(&p9_poll_lock, flags);
544
Tejun Heoaa70c582011-02-01 11:42:43 +0100545 schedule_work(&p9_poll_work);
546 return 1;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500547}
548
549/**
550 * p9_pollwait - add poll task to the wait queue
551 * @filp: file pointer being polled
552 * @wait_address: wait_q to block on
553 * @p: poll state
554 *
555 * called by files poll operation to add v9fs-poll task to files wait queue
556 */
557
558static void
559p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p)
560{
561 struct p9_conn *m = container_of(p, struct p9_conn, pt);
562 struct p9_poll_wait *pwait = NULL;
563 int i;
564
565 for (i = 0; i < ARRAY_SIZE(m->poll_wait); i++) {
566 if (m->poll_wait[i].wait_addr == NULL) {
567 pwait = &m->poll_wait[i];
568 break;
569 }
570 }
571
572 if (!pwait) {
Joe Perches5d385152011-11-28 10:40:46 -0800573 p9_debug(P9_DEBUG_ERROR, "not enough wait_address slots\n");
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500574 return;
575 }
576
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500577 pwait->conn = m;
578 pwait->wait_addr = wait_address;
579 init_waitqueue_func_entry(&pwait->wait, p9_pollwake);
580 add_wait_queue(wait_address, &pwait->wait);
581}
582
583/**
Simon Derr263c5822014-03-11 10:13:09 +0100584 * p9_conn_create - initialize the per-session mux data
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500585 * @client: client instance
586 *
587 * Note: Creates the polling task if this is the first session.
588 */
589
Simon Derr263c5822014-03-11 10:13:09 +0100590static void p9_conn_create(struct p9_client *client)
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500591{
Al Viro7594bf32017-07-16 22:53:08 -0400592 __poll_t n;
Simon Derr263c5822014-03-11 10:13:09 +0100593 struct p9_trans_fd *ts = client->trans;
594 struct p9_conn *m = &ts->conn;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500595
Joe Perches5d385152011-11-28 10:40:46 -0800596 p9_debug(P9_DEBUG_TRANS, "client %p msize %d\n", client, client->msize);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500597
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500598 INIT_LIST_HEAD(&m->mux_list);
599 m->client = client;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500600
601 INIT_LIST_HEAD(&m->req_list);
602 INIT_LIST_HEAD(&m->unsent_req_list);
603 INIT_WORK(&m->rq, p9_read_work);
604 INIT_WORK(&m->wq, p9_write_work);
605 INIT_LIST_HEAD(&m->poll_pending_link);
606 init_poll_funcptr(&m->pt, p9_pollwait);
607
Al Viro7594bf32017-07-16 22:53:08 -0400608 n = p9_fd_poll(client, &m->pt, NULL);
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800609 if (n & EPOLLIN) {
Joe Perches5d385152011-11-28 10:40:46 -0800610 p9_debug(P9_DEBUG_TRANS, "mux %p can read\n", m);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500611 set_bit(Rpending, &m->wsched);
612 }
613
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800614 if (n & EPOLLOUT) {
Joe Perches5d385152011-11-28 10:40:46 -0800615 p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500616 set_bit(Wpending, &m->wsched);
617 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500618}
619
620/**
621 * p9_poll_mux - polls a mux and schedules read or write works if necessary
622 * @m: connection to poll
623 *
624 */
625
626static void p9_poll_mux(struct p9_conn *m)
627{
Al Viro7594bf32017-07-16 22:53:08 -0400628 __poll_t n;
629 int err = -ECONNRESET;
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500630
631 if (m->err < 0)
632 return;
633
Al Viro7594bf32017-07-16 22:53:08 -0400634 n = p9_fd_poll(m->client, NULL, &err);
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800635 if (n & (EPOLLERR | EPOLLHUP | EPOLLNVAL)) {
Joe Perches5d385152011-11-28 10:40:46 -0800636 p9_debug(P9_DEBUG_TRANS, "error mux %p err %d\n", m, n);
Al Viro7594bf32017-07-16 22:53:08 -0400637 p9_conn_cancel(m, err);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500638 }
639
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800640 if (n & EPOLLIN) {
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500641 set_bit(Rpending, &m->wsched);
Joe Perches5d385152011-11-28 10:40:46 -0800642 p9_debug(P9_DEBUG_TRANS, "mux %p can read\n", m);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500643 if (!test_and_set_bit(Rworksched, &m->wsched)) {
Joe Perches5d385152011-11-28 10:40:46 -0800644 p9_debug(P9_DEBUG_TRANS, "sched read work %p\n", m);
Tejun Heo61edeee2011-02-01 11:42:43 +0100645 schedule_work(&m->rq);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500646 }
647 }
648
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800649 if (n & EPOLLOUT) {
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500650 set_bit(Wpending, &m->wsched);
Joe Perches5d385152011-11-28 10:40:46 -0800651 p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m);
Joe Perchesf64f9e72009-11-29 16:55:45 -0800652 if ((m->wsize || !list_empty(&m->unsent_req_list)) &&
653 !test_and_set_bit(Wworksched, &m->wsched)) {
Joe Perches5d385152011-11-28 10:40:46 -0800654 p9_debug(P9_DEBUG_TRANS, "sched write work %p\n", m);
Tejun Heo61edeee2011-02-01 11:42:43 +0100655 schedule_work(&m->wq);
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500656 }
657 }
658}
659
660/**
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500661 * p9_fd_request - send 9P request
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600662 * The function can sleep until the request is scheduled for sending.
663 * The function can be interrupted. Return from the function is not
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500664 * a guarantee that the request is sent successfully.
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600665 *
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500666 * @client: client instance
667 * @req: request to be sent
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600668 *
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600669 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600670
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500671static int p9_fd_request(struct p9_client *client, struct p9_req_t *req)
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600672{
Al Viro7594bf32017-07-16 22:53:08 -0400673 __poll_t n;
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500674 struct p9_trans_fd *ts = client->trans;
Simon Derr263c5822014-03-11 10:13:09 +0100675 struct p9_conn *m = &ts->conn;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600676
Joe Perches5d385152011-11-28 10:40:46 -0800677 p9_debug(P9_DEBUG_TRANS, "mux %p task %p tcall %p id %d\n",
Dominique Martinet15555832018-07-30 05:55:19 +0000678 m, current, &req->tc, req->tc.id);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600679 if (m->err < 0)
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500680 return m->err;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600681
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500682 spin_lock(&client->lock);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500683 req->status = REQ_STATUS_UNSENT;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600684 list_add_tail(&req->req_list, &m->unsent_req_list);
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500685 spin_unlock(&client->lock);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600686
687 if (test_and_clear_bit(Wpending, &m->wsched))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800688 n = EPOLLOUT;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600689 else
Al Viro7594bf32017-07-16 22:53:08 -0400690 n = p9_fd_poll(m->client, NULL, NULL);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600691
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800692 if (n & EPOLLOUT && !test_and_set_bit(Wworksched, &m->wsched))
Tejun Heo61edeee2011-02-01 11:42:43 +0100693 schedule_work(&m->wq);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600694
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500695 return 0;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600696}
697
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500698static int p9_fd_cancel(struct p9_client *client, struct p9_req_t *req)
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600699{
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500700 int ret = 1;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600701
Joe Perches5d385152011-11-28 10:40:46 -0800702 p9_debug(P9_DEBUG_TRANS, "client %p req %p\n", client, req);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600703
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500704 spin_lock(&client->lock);
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500705
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500706 if (req->status == REQ_STATUS_UNSENT) {
Latchesar Ionkov1bab88b2009-04-05 16:28:59 -0500707 list_del(&req->req_list);
Eric Van Hensbergen91b85342008-10-13 18:45:21 -0500708 req->status = REQ_STATUS_FLSHD;
Tomas Bortoli3665a4d2018-08-14 19:43:42 +0200709 p9_req_put(req);
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500710 ret = 0;
Simon Derr0bfd6842014-03-10 16:38:52 +0100711 }
Eric Van Hensbergen7eb923b2008-10-17 12:45:40 -0500712 spin_unlock(&client->lock);
713
714 return ret;
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600715}
716
Simon Derrafd8d652014-03-10 16:38:49 +0100717static int p9_fd_cancelled(struct p9_client *client, struct p9_req_t *req)
718{
719 p9_debug(P9_DEBUG_TRANS, "client %p req %p\n", client, req);
720
721 /* we haven't received a response for oldreq,
722 * remove it from the list.
723 */
724 spin_lock(&client->lock);
725 list_del(&req->req_list);
726 spin_unlock(&client->lock);
Tomas Bortoli3665a4d2018-08-14 19:43:42 +0200727 p9_req_put(req);
Simon Derrafd8d652014-03-10 16:38:49 +0100728
729 return 0;
730}
731
David Howellsc4fac912017-07-05 16:25:37 +0100732static int p9_fd_show_options(struct seq_file *m, struct p9_client *clnt)
733{
734 if (clnt->trans_mod == &p9_tcp_trans) {
735 if (clnt->trans_opts.tcp.port != P9_PORT)
Tuomas Tynkkynen61b272c2017-11-19 11:28:43 +0200736 seq_printf(m, ",port=%u", clnt->trans_opts.tcp.port);
David Howellsc4fac912017-07-05 16:25:37 +0100737 } else if (clnt->trans_mod == &p9_fd_trans) {
738 if (clnt->trans_opts.fd.rfd != ~0)
Tuomas Tynkkynen61b272c2017-11-19 11:28:43 +0200739 seq_printf(m, ",rfd=%u", clnt->trans_opts.fd.rfd);
David Howellsc4fac912017-07-05 16:25:37 +0100740 if (clnt->trans_opts.fd.wfd != ~0)
Tuomas Tynkkynen61b272c2017-11-19 11:28:43 +0200741 seq_printf(m, ",wfd=%u", clnt->trans_opts.fd.wfd);
David Howellsc4fac912017-07-05 16:25:37 +0100742 }
743 return 0;
744}
745
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600746/**
Abhishek Kulkarni0e155972009-07-19 13:41:55 -0600747 * parse_opts - parse mount options into p9_fd_opts structure
748 * @params: options string passed from mount
749 * @opts: fd transport-specific structure to parse options into
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500750 *
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600751 * Returns 0 upon success, -ERRNO upon failure
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500752 */
753
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600754static int parse_opts(char *params, struct p9_fd_opts *opts)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500755{
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500756 char *p;
757 substring_t args[MAX_OPT_ARGS];
758 int option;
Eric Van Hensbergend8c8a9e2010-02-08 16:23:23 -0600759 char *options, *tmp_options;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500760
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500761 opts->port = P9_PORT;
762 opts->rfd = ~0;
763 opts->wfd = ~0;
David Howellsc4fac912017-07-05 16:25:37 +0100764 opts->privport = false;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500765
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600766 if (!params)
767 return 0;
768
Eric Van Hensbergend8c8a9e2010-02-08 16:23:23 -0600769 tmp_options = kstrdup(params, GFP_KERNEL);
770 if (!tmp_options) {
Joe Perches5d385152011-11-28 10:40:46 -0800771 p9_debug(P9_DEBUG_ERROR,
772 "failed to allocate copy of option string\n");
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600773 return -ENOMEM;
774 }
Eric Van Hensbergend8c8a9e2010-02-08 16:23:23 -0600775 options = tmp_options;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500776
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500777 while ((p = strsep(&options, ",")) != NULL) {
778 int token;
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600779 int r;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500780 if (!*p)
781 continue;
782 token = match_token(p, tokens, args);
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700783 if ((token != Opt_err) && (token != Opt_privport)) {
Abhishek Kulkarni15da4b12009-07-01 08:50:54 +0000784 r = match_int(&args[0], &option);
785 if (r < 0) {
Joe Perches5d385152011-11-28 10:40:46 -0800786 p9_debug(P9_DEBUG_ERROR,
787 "integer field, but no integer?\n");
Abhishek Kulkarni15da4b12009-07-01 08:50:54 +0000788 continue;
789 }
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500790 }
791 switch (token) {
792 case Opt_port:
793 opts->port = option;
794 break;
795 case Opt_rfdno:
796 opts->rfd = option;
797 break;
798 case Opt_wfdno:
799 opts->wfd = option;
800 break;
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700801 case Opt_privport:
David Howellsc4fac912017-07-05 16:25:37 +0100802 opts->privport = true;
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700803 break;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500804 default:
805 continue;
806 }
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500807 }
Eric Van Hensbergend8c8a9e2010-02-08 16:23:23 -0600808
809 kfree(tmp_options);
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600810 return 0;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500811}
812
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500813static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500814{
Simon Derr263c5822014-03-11 10:13:09 +0100815 struct p9_trans_fd *ts = kzalloc(sizeof(struct p9_trans_fd),
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500816 GFP_KERNEL);
817 if (!ts)
818 return -ENOMEM;
819
820 ts->rd = fget(rfd);
821 ts->wr = fget(wfd);
822 if (!ts->rd || !ts->wr) {
823 if (ts->rd)
824 fput(ts->rd);
825 if (ts->wr)
826 fput(ts->wr);
827 kfree(ts);
828 return -EIO;
829 }
830
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500831 client->trans = ts;
832 client->status = Connected;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500833
834 return 0;
835}
836
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500837static int p9_socket_open(struct p9_client *client, struct socket *csocket)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500838{
Al Viro6b186622009-08-06 02:02:43 +0400839 struct p9_trans_fd *p;
Al Viro56b31d12012-08-18 00:25:51 -0400840 struct file *file;
Al Viro6b186622009-08-06 02:02:43 +0400841
Simon Derr263c5822014-03-11 10:13:09 +0100842 p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL);
Al Viro6b186622009-08-06 02:02:43 +0400843 if (!p)
844 return -ENOMEM;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500845
846 csocket->sk->sk_allocation = GFP_NOIO;
Linus Torvaldsaab174f2012-10-02 20:25:04 -0700847 file = sock_alloc_file(csocket, 0, NULL);
Al Viro56b31d12012-08-18 00:25:51 -0400848 if (IS_ERR(file)) {
Joe Perches5d385152011-11-28 10:40:46 -0800849 pr_err("%s (%d): failed to map fd\n",
850 __func__, task_pid_nr(current));
Al Viro6b186622009-08-06 02:02:43 +0400851 kfree(p);
Al Viro56b31d12012-08-18 00:25:51 -0400852 return PTR_ERR(file);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500853 }
854
Al Viro56b31d12012-08-18 00:25:51 -0400855 get_file(file);
856 p->wr = p->rd = file;
Al Viro6b186622009-08-06 02:02:43 +0400857 client->trans = p;
858 client->status = Connected;
859
Al Viro6b186622009-08-06 02:02:43 +0400860 p->rd->f_flags |= O_NONBLOCK;
861
Simon Derr263c5822014-03-11 10:13:09 +0100862 p9_conn_create(client);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500863 return 0;
864}
865
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500866/**
Simon Derr263c5822014-03-11 10:13:09 +0100867 * p9_mux_destroy - cancels all pending requests of mux
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500868 * @m: mux to destroy
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500869 *
870 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600871
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500872static void p9_conn_destroy(struct p9_conn *m)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500873{
Joe Perches5d385152011-11-28 10:40:46 -0800874 p9_debug(P9_DEBUG_TRANS, "mux %p prev %p next %p\n",
875 m, m->mux_list.prev, m->mux_list.next);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500876
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500877 p9_mux_poll_stop(m);
878 cancel_work_sync(&m->rq);
Dominique Martinet6518b412018-10-09 11:38:00 +0900879 if (m->rreq) {
880 p9_req_put(m->rreq);
881 m->rreq = NULL;
882 }
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500883 cancel_work_sync(&m->wq);
Dominique Martinet6518b412018-10-09 11:38:00 +0900884 if (m->wreq) {
885 p9_req_put(m->wreq);
886 m->wreq = NULL;
887 }
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500888
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500889 p9_conn_cancel(m, -ECONNRESET);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500890
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -0500891 m->client = NULL;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500892}
893
894/**
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500895 * p9_fd_close - shutdown file descriptor transport
896 * @client: client instance
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500897 *
898 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600899
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500900static void p9_fd_close(struct p9_client *client)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500901{
902 struct p9_trans_fd *ts;
903
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500904 if (!client)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500905 return;
906
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500907 ts = client->trans;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500908 if (!ts)
909 return;
910
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500911 client->status = Disconnected;
912
Simon Derr263c5822014-03-11 10:13:09 +0100913 p9_conn_destroy(&ts->conn);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600914
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500915 if (ts->rd)
916 fput(ts->rd);
917 if (ts->wr)
918 fput(ts->wr);
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500919
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500920 kfree(ts);
921}
922
Eric Van Hensbergen887b3ec2008-05-08 20:26:37 -0500923/*
924 * stolen from NFS - maybe should be made a generic function?
925 */
926static inline int valid_ipaddr4(const char *buf)
927{
928 int rc, count, in[4];
929
930 rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
931 if (rc != 4)
932 return -EINVAL;
933 for (count = 0; count < 4; count++) {
934 if (in[count] > 255)
935 return -EINVAL;
936 }
937 return 0;
938}
939
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700940static int p9_bind_privport(struct socket *sock)
941{
942 struct sockaddr_in cl;
943 int port, err = -EINVAL;
944
945 memset(&cl, 0, sizeof(cl));
946 cl.sin_family = AF_INET;
947 cl.sin_addr.s_addr = INADDR_ANY;
948 for (port = p9_ipport_resv_max; port >= p9_ipport_resv_min; port--) {
949 cl.sin_port = htons((ushort)port);
950 err = kernel_bind(sock, (struct sockaddr *)&cl, sizeof(cl));
951 if (err != -EADDRINUSE)
952 break;
953 }
954 return err;
955}
956
957
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500958static int
959p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500960{
961 int err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500962 struct socket *csocket;
963 struct sockaddr_in sin_server;
964 struct p9_fd_opts opts;
965
Eric Van Hensbergenbb8ffdf2008-03-07 10:53:53 -0600966 err = parse_opts(args, &opts);
967 if (err < 0)
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500968 return err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500969
Tomas Bortoli10aa1452018-07-27 13:05:58 +0200970 if (addr == NULL || valid_ipaddr4(addr) < 0)
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -0500971 return -EINVAL;
Eric Van Hensbergen887b3ec2008-05-08 20:26:37 -0500972
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500973 csocket = NULL;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500974
David Howellsc4fac912017-07-05 16:25:37 +0100975 client->trans_opts.tcp.port = opts.port;
976 client->trans_opts.tcp.privport = opts.privport;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500977 sin_server.sin_family = AF_INET;
978 sin_server.sin_addr.s_addr = in_aton(addr);
979 sin_server.sin_port = htons(opts.port);
Eric W. Biederman0c5c9fb2015-03-11 23:06:44 -0500980 err = __sock_create(current->nsproxy->net_ns, PF_INET,
Rob Landleye75762f2011-05-23 21:46:56 -0500981 SOCK_STREAM, IPPROTO_TCP, &csocket, 1);
Al Viro6b186622009-08-06 02:02:43 +0400982 if (err) {
Joe Perches5d385152011-11-28 10:40:46 -0800983 pr_err("%s (%d): problem creating socket\n",
984 __func__, task_pid_nr(current));
Al Viro6b186622009-08-06 02:02:43 +0400985 return err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500986 }
987
Jim Garlick2f28c8b2013-05-29 12:15:07 -0700988 if (opts.privport) {
989 err = p9_bind_privport(csocket);
990 if (err < 0) {
991 pr_err("%s (%d): problem binding to privport\n",
992 __func__, task_pid_nr(current));
993 sock_release(csocket);
994 return err;
995 }
996 }
997
Eric Van Hensbergena80d9232007-10-17 14:31:07 -0500998 err = csocket->ops->connect(csocket,
999 (struct sockaddr *)&sin_server,
1000 sizeof(struct sockaddr_in), 0);
1001 if (err < 0) {
Joe Perches5d385152011-11-28 10:40:46 -08001002 pr_err("%s (%d): problem connecting socket to %s\n",
1003 __func__, task_pid_nr(current), addr);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001004 sock_release(csocket);
Al Viro6b186622009-08-06 02:02:43 +04001005 return err;
1006 }
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001007
Al Viro6b186622009-08-06 02:02:43 +04001008 return p9_socket_open(client, csocket);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001009}
1010
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001011static int
1012p9_fd_create_unix(struct p9_client *client, const char *addr, char *args)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001013{
1014 int err;
1015 struct socket *csocket;
1016 struct sockaddr_un sun_server;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001017
1018 csocket = NULL;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001019
Tomas Bortoli10aa1452018-07-27 13:05:58 +02001020 if (addr == NULL)
1021 return -EINVAL;
1022
Dan Carpentercff6b8a2010-07-10 11:51:54 +02001023 if (strlen(addr) >= UNIX_PATH_MAX) {
Joe Perches5d385152011-11-28 10:40:46 -08001024 pr_err("%s (%d): address too long: %s\n",
1025 __func__, task_pid_nr(current), addr);
Al Viro6b186622009-08-06 02:02:43 +04001026 return -ENAMETOOLONG;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001027 }
1028
1029 sun_server.sun_family = PF_UNIX;
1030 strcpy(sun_server.sun_path, addr);
Eric W. Biederman0c5c9fb2015-03-11 23:06:44 -05001031 err = __sock_create(current->nsproxy->net_ns, PF_UNIX,
Rob Landleye75762f2011-05-23 21:46:56 -05001032 SOCK_STREAM, 0, &csocket, 1);
Al Viro6b186622009-08-06 02:02:43 +04001033 if (err < 0) {
Joe Perches5d385152011-11-28 10:40:46 -08001034 pr_err("%s (%d): problem creating socket\n",
1035 __func__, task_pid_nr(current));
1036
Al Viro6b186622009-08-06 02:02:43 +04001037 return err;
1038 }
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001039 err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server,
1040 sizeof(struct sockaddr_un) - 1, 0);
1041 if (err < 0) {
Joe Perches5d385152011-11-28 10:40:46 -08001042 pr_err("%s (%d): problem connecting socket: %s: %d\n",
1043 __func__, task_pid_nr(current), addr, err);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001044 sock_release(csocket);
Al Viro6b186622009-08-06 02:02:43 +04001045 return err;
1046 }
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001047
Al Viro6b186622009-08-06 02:02:43 +04001048 return p9_socket_open(client, csocket);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001049}
1050
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001051static int
1052p9_fd_create(struct p9_client *client, const char *addr, char *args)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001053{
1054 int err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001055 struct p9_fd_opts opts;
1056
1057 parse_opts(args, &opts);
David Howellsc4fac912017-07-05 16:25:37 +01001058 client->trans_opts.fd.rfd = opts.rfd;
1059 client->trans_opts.fd.wfd = opts.wfd;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001060
1061 if (opts.rfd == ~0 || opts.wfd == ~0) {
Joe Perches5d385152011-11-28 10:40:46 -08001062 pr_err("Insufficient options for proto=fd\n");
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001063 return -ENOPROTOOPT;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001064 }
1065
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001066 err = p9_fd_open(client, opts.rfd, opts.wfd);
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001067 if (err < 0)
Al Viro6b186622009-08-06 02:02:43 +04001068 return err;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001069
Simon Derr263c5822014-03-11 10:13:09 +01001070 p9_conn_create(client);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -06001071
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001072 return 0;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001073}
1074
1075static struct p9_trans_module p9_tcp_trans = {
1076 .name = "tcp",
1077 .maxsize = MAX_SOCK_BUF,
Eric Van Hensbergenf94741f2013-11-12 10:20:03 -06001078 .def = 0,
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001079 .create = p9_fd_create_tcp,
1080 .close = p9_fd_close,
Eric Van Hensbergen91b85342008-10-13 18:45:21 -05001081 .request = p9_fd_request,
1082 .cancel = p9_fd_cancel,
Simon Derrafd8d652014-03-10 16:38:49 +01001083 .cancelled = p9_fd_cancelled,
David Howellsc4fac912017-07-05 16:25:37 +01001084 .show_options = p9_fd_show_options,
Tejun Heo72029fe2008-09-24 16:22:23 -05001085 .owner = THIS_MODULE,
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001086};
1087
1088static struct p9_trans_module p9_unix_trans = {
1089 .name = "unix",
1090 .maxsize = MAX_SOCK_BUF,
1091 .def = 0,
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001092 .create = p9_fd_create_unix,
1093 .close = p9_fd_close,
Eric Van Hensbergen91b85342008-10-13 18:45:21 -05001094 .request = p9_fd_request,
1095 .cancel = p9_fd_cancel,
Simon Derrafd8d652014-03-10 16:38:49 +01001096 .cancelled = p9_fd_cancelled,
David Howellsc4fac912017-07-05 16:25:37 +01001097 .show_options = p9_fd_show_options,
Tejun Heo72029fe2008-09-24 16:22:23 -05001098 .owner = THIS_MODULE,
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001099};
1100
1101static struct p9_trans_module p9_fd_trans = {
1102 .name = "fd",
1103 .maxsize = MAX_SOCK_BUF,
1104 .def = 0,
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -05001105 .create = p9_fd_create,
1106 .close = p9_fd_close,
Eric Van Hensbergen91b85342008-10-13 18:45:21 -05001107 .request = p9_fd_request,
1108 .cancel = p9_fd_cancel,
Simon Derrafd8d652014-03-10 16:38:49 +01001109 .cancelled = p9_fd_cancelled,
David Howellsc4fac912017-07-05 16:25:37 +01001110 .show_options = p9_fd_show_options,
Tejun Heo72029fe2008-09-24 16:22:23 -05001111 .owner = THIS_MODULE,
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001112};
1113
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001114/**
Sun Lianwen4a026da2018-05-08 09:49:38 +08001115 * p9_poll_workfn - poll worker thread
1116 * @work: work queue
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001117 *
1118 * polls all v9fs transports for new events and queues the appropriate
1119 * work to the work queue
1120 *
1121 */
1122
Tejun Heoaa70c582011-02-01 11:42:43 +01001123static void p9_poll_workfn(struct work_struct *work)
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001124{
1125 unsigned long flags;
1126
Joe Perches5d385152011-11-28 10:40:46 -08001127 p9_debug(P9_DEBUG_TRANS, "start %p\n", current);
Tejun Heoaa70c582011-02-01 11:42:43 +01001128
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001129 spin_lock_irqsave(&p9_poll_lock, flags);
1130 while (!list_empty(&p9_poll_pending_list)) {
1131 struct p9_conn *conn = list_first_entry(&p9_poll_pending_list,
1132 struct p9_conn,
1133 poll_pending_link);
1134 list_del_init(&conn->poll_pending_link);
1135 spin_unlock_irqrestore(&p9_poll_lock, flags);
1136
1137 p9_poll_mux(conn);
1138
1139 spin_lock_irqsave(&p9_poll_lock, flags);
1140 }
1141 spin_unlock_irqrestore(&p9_poll_lock, flags);
1142
Joe Perches5d385152011-11-28 10:40:46 -08001143 p9_debug(P9_DEBUG_TRANS, "finish\n");
Eric Van Hensbergen5503ac52008-10-13 18:45:24 -05001144}
1145
Eric Van Hensbergen887b3ec2008-05-08 20:26:37 -05001146int p9_trans_fd_init(void)
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001147{
1148 v9fs_register_trans(&p9_tcp_trans);
1149 v9fs_register_trans(&p9_unix_trans);
1150 v9fs_register_trans(&p9_fd_trans);
1151
Andrew Morton3387b802008-03-28 14:15:57 -07001152 return 0;
Eric Van Hensbergena80d9232007-10-17 14:31:07 -05001153}
Tejun Heo72029fe2008-09-24 16:22:23 -05001154
1155void p9_trans_fd_exit(void)
1156{
Tejun Heo43829732012-08-20 14:51:24 -07001157 flush_work(&p9_poll_work);
Tejun Heo72029fe2008-09-24 16:22:23 -05001158 v9fs_unregister_trans(&p9_tcp_trans);
1159 v9fs_unregister_trans(&p9_unix_trans);
1160 v9fs_unregister_trans(&p9_fd_trans);
1161}