hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/9p/trans_fd.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/fs/9p/trans_fd.c
34 *
....@@ -7,22 +8,6 @@
78 * Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net>
89 * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
910 * 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
- *
2611 */
2712
2813 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -133,7 +118,7 @@
133118 struct list_head unsent_req_list;
134119 struct p9_req_t *rreq;
135120 struct p9_req_t *wreq;
136
- char tmp_buf[7];
121
+ char tmp_buf[P9_HDRSZ];
137122 struct p9_fcall rc;
138123 int wpos;
139124 int wsize;
....@@ -215,10 +200,14 @@
215200
216201 list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) {
217202 list_move(&req->req_list, &cancel_list);
203
+ req->status = REQ_STATUS_ERROR;
218204 }
219205 list_for_each_entry_safe(req, rtmp, &m->unsent_req_list, req_list) {
220206 list_move(&req->req_list, &cancel_list);
207
+ req->status = REQ_STATUS_ERROR;
221208 }
209
+
210
+ spin_unlock(&m->client->lock);
222211
223212 list_for_each_entry_safe(req, rtmp, &cancel_list, req_list) {
224213 p9_debug(P9_DEBUG_ERROR, "call back req %p\n", req);
....@@ -227,7 +216,6 @@
227216 req->t_err = err;
228217 p9_client_cb(m->client, req, REQ_STATUS_ERROR);
229218 }
230
- spin_unlock(&m->client->lock);
231219 }
232220
233221 static __poll_t
....@@ -303,7 +291,7 @@
303291 if (!m->rc.sdata) {
304292 m->rc.sdata = m->tmp_buf;
305293 m->rc.offset = 0;
306
- m->rc.capacity = 7; /* start by reading header */
294
+ m->rc.capacity = P9_HDRSZ; /* start by reading header */
307295 }
308296
309297 clear_bit(Rpending, &m->wsched);
....@@ -326,7 +314,7 @@
326314 p9_debug(P9_DEBUG_TRANS, "got new header\n");
327315
328316 /* Header size */
329
- m->rc.size = 7;
317
+ m->rc.size = P9_HDRSZ;
330318 err = p9_parse_header(&m->rc, &m->rc.size, NULL, NULL, 0);
331319 if (err) {
332320 p9_debug(P9_DEBUG_ERROR,
....@@ -835,11 +823,14 @@
835823 goto out_free_ts;
836824 if (!(ts->rd->f_mode & FMODE_READ))
837825 goto out_put_rd;
826
+ /* prevent workers from hanging on IO when fd is a pipe */
827
+ ts->rd->f_flags |= O_NONBLOCK;
838828 ts->wr = fget(wfd);
839829 if (!ts->wr)
840830 goto out_put_rd;
841831 if (!(ts->wr->f_mode & FMODE_WRITE))
842832 goto out_put_wr;
833
+ ts->wr->f_flags |= O_NONBLOCK;
843834
844835 client->trans = ts;
845836 client->status = Connected;
....@@ -861,8 +852,10 @@
861852 struct file *file;
862853
863854 p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL);
864
- if (!p)
855
+ if (!p) {
856
+ sock_release(csocket);
865857 return -ENOMEM;
858
+ }
866859
867860 csocket->sk->sk_allocation = GFP_NOIO;
868861 file = sock_alloc_file(csocket, 0, NULL);
....@@ -965,7 +958,7 @@
965958
966959 memset(&cl, 0, sizeof(cl));
967960 cl.sin_family = AF_INET;
968
- cl.sin_addr.s_addr = INADDR_ANY;
961
+ cl.sin_addr.s_addr = htonl(INADDR_ANY);
969962 for (port = p9_ipport_resv_max; port >= p9_ipport_resv_min; port--) {
970963 cl.sin_port = htons((ushort)port);
971964 err = kernel_bind(sock, (struct sockaddr *)&cl, sizeof(cl));