Thomas Gleixner | 1f32761 | 2019-05-28 09:57:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 2 | /* |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 3 | * 9P Client |
| 4 | * |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 5 | * Copyright (C) 2008 by Eric Van Hensbergen <ericvh@gmail.com> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 6 | * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 9 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 10 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/fs.h> |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 14 | #include <linux/poll.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 15 | #include <linux/idr.h> |
| 16 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Ingo Molnar | 3f07c01 | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 18 | #include <linux/sched/signal.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 19 | #include <linux/uaccess.h> |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 20 | #include <linux/uio.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 21 | #include <net/9p/9p.h> |
Eric Van Hensbergen | fb0466c | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 22 | #include <linux/parser.h> |
David Howells | c4fac91 | 2017-07-05 16:25:37 +0100 | [diff] [blame] | 23 | #include <linux/seq_file.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 24 | #include <net/9p/client.h> |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 25 | #include <net/9p/transport.h> |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 26 | #include "protocol.h" |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 27 | |
Aneesh Kumar K.V | 348b590 | 2011-08-07 00:46:59 +0530 | [diff] [blame] | 28 | #define CREATE_TRACE_POINTS |
| 29 | #include <trace/events/9p.h> |
| 30 | |
Christian Schoenebeck | 9c4d94d | 2021-09-04 17:12:51 +0200 | [diff] [blame] | 31 | #define DEFAULT_MSIZE (128 * 1024) |
Christian Schoenebeck | 9210fc0 | 2021-09-04 17:07:12 +0200 | [diff] [blame] | 32 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 33 | /* Client Option Parsing (code inspired by NFS code) |
| 34 | * - a little lazy - parse all client options |
| 35 | */ |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 36 | |
| 37 | enum { |
| 38 | Opt_msize, |
| 39 | Opt_trans, |
| 40 | Opt_legacy, |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 41 | Opt_version, |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 42 | Opt_err, |
| 43 | }; |
| 44 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 45 | static const match_table_t tokens = { |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 46 | {Opt_msize, "msize=%u"}, |
| 47 | {Opt_legacy, "noextend"}, |
| 48 | {Opt_trans, "trans=%s"}, |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 49 | {Opt_version, "version=%s"}, |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 50 | {Opt_err, NULL}, |
| 51 | }; |
| 52 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 53 | inline int p9_is_proto_dotl(struct p9_client *clnt) |
| 54 | { |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 55 | return clnt->proto_version == p9_proto_2000L; |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 56 | } |
| 57 | EXPORT_SYMBOL(p9_is_proto_dotl); |
| 58 | |
| 59 | inline int p9_is_proto_dotu(struct p9_client *clnt) |
| 60 | { |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 61 | return clnt->proto_version == p9_proto_2000u; |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 62 | } |
| 63 | EXPORT_SYMBOL(p9_is_proto_dotu); |
| 64 | |
David Howells | c4fac91 | 2017-07-05 16:25:37 +0100 | [diff] [blame] | 65 | int p9_show_client_options(struct seq_file *m, struct p9_client *clnt) |
| 66 | { |
Christian Schoenebeck | 9210fc0 | 2021-09-04 17:07:12 +0200 | [diff] [blame] | 67 | if (clnt->msize != DEFAULT_MSIZE) |
David Howells | c4fac91 | 2017-07-05 16:25:37 +0100 | [diff] [blame] | 68 | seq_printf(m, ",msize=%u", clnt->msize); |
Tuomas Tynkkynen | 61b272c | 2017-11-19 11:28:43 +0200 | [diff] [blame] | 69 | seq_printf(m, ",trans=%s", clnt->trans_mod->name); |
David Howells | c4fac91 | 2017-07-05 16:25:37 +0100 | [diff] [blame] | 70 | |
| 71 | switch (clnt->proto_version) { |
| 72 | case p9_proto_legacy: |
| 73 | seq_puts(m, ",noextend"); |
| 74 | break; |
| 75 | case p9_proto_2000u: |
| 76 | seq_puts(m, ",version=9p2000.u"); |
| 77 | break; |
| 78 | case p9_proto_2000L: |
| 79 | /* Default */ |
| 80 | break; |
| 81 | } |
| 82 | |
| 83 | if (clnt->trans_mod->show_options) |
| 84 | return clnt->trans_mod->show_options(m, clnt); |
| 85 | return 0; |
| 86 | } |
| 87 | EXPORT_SYMBOL(p9_show_client_options); |
| 88 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 89 | /* Some error codes are taken directly from the server replies, |
Simon Derr | 43def35 | 2012-08-10 15:52:06 +0200 | [diff] [blame] | 90 | * make sure they are valid. |
| 91 | */ |
| 92 | static int safe_errno(int err) |
| 93 | { |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 94 | if (err > 0 || err < -MAX_ERRNO) { |
Simon Derr | 43def35 | 2012-08-10 15:52:06 +0200 | [diff] [blame] | 95 | p9_debug(P9_DEBUG_ERROR, "Invalid error code %d\n", err); |
| 96 | return -EPROTO; |
| 97 | } |
| 98 | return err; |
| 99 | } |
| 100 | |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 101 | /* Interpret mount option for protocol version */ |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 102 | static int get_protocol_version(char *s) |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 103 | { |
Dan Carpenter | 3dc9fef | 2010-04-05 14:37:28 -0500 | [diff] [blame] | 104 | int version = -EINVAL; |
| 105 | |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 106 | if (!strcmp(s, "9p2000")) { |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 107 | version = p9_proto_legacy; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 108 | p9_debug(P9_DEBUG_9P, "Protocol version: Legacy\n"); |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 109 | } else if (!strcmp(s, "9p2000.u")) { |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 110 | version = p9_proto_2000u; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 111 | p9_debug(P9_DEBUG_9P, "Protocol version: 9P2000.u\n"); |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 112 | } else if (!strcmp(s, "9p2000.L")) { |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 113 | version = p9_proto_2000L; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 114 | p9_debug(P9_DEBUG_9P, "Protocol version: 9P2000.L\n"); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 115 | } else { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 116 | pr_info("Unknown protocol version %s\n", s); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 117 | } |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 118 | |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 119 | return version; |
| 120 | } |
| 121 | |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 122 | /** |
Xiongfeng Wang | 03ff737 | 2021-03-27 16:15:54 +0800 | [diff] [blame] | 123 | * parse_opts - parse mount options into client structure |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 124 | * @opts: options string passed from mount |
| 125 | * @clnt: existing v9fs client information |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 126 | * |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 127 | * Return 0 upon success, -ERRNO upon failure |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 128 | */ |
| 129 | |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 130 | static int parse_opts(char *opts, struct p9_client *clnt) |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 131 | { |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 132 | char *options, *tmp_options; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 133 | char *p; |
| 134 | substring_t args[MAX_OPT_ARGS]; |
| 135 | int option; |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 136 | char *s; |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 137 | int ret = 0; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 138 | |
Aneesh Kumar K.V | 095e799 | 2013-05-20 12:20:54 +0530 | [diff] [blame] | 139 | clnt->proto_version = p9_proto_2000L; |
Christian Schoenebeck | 9210fc0 | 2021-09-04 17:07:12 +0200 | [diff] [blame] | 140 | clnt->msize = DEFAULT_MSIZE; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 141 | |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 142 | if (!opts) |
| 143 | return 0; |
| 144 | |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 145 | tmp_options = kstrdup(opts, GFP_KERNEL); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 146 | if (!tmp_options) |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 147 | return -ENOMEM; |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 148 | options = tmp_options; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 149 | |
| 150 | while ((p = strsep(&options, ",")) != NULL) { |
Aneesh Kumar K.V | 4d5077f | 2011-08-30 12:19:34 +0530 | [diff] [blame] | 151 | int token, r; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 152 | |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 153 | if (!*p) |
| 154 | continue; |
| 155 | token = match_token(p, tokens, args); |
Aneesh Kumar K.V | 4d5077f | 2011-08-30 12:19:34 +0530 | [diff] [blame] | 156 | switch (token) { |
| 157 | case Opt_msize: |
| 158 | r = match_int(&args[0], &option); |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 159 | if (r < 0) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 160 | p9_debug(P9_DEBUG_ERROR, |
| 161 | "integer field, but no integer?\n"); |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 162 | ret = r; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 163 | continue; |
| 164 | } |
Dominique Martinet | 574d356 | 2018-11-05 09:52:48 +0100 | [diff] [blame] | 165 | if (option < 4096) { |
| 166 | p9_debug(P9_DEBUG_ERROR, |
| 167 | "msize should be at least 4k\n"); |
| 168 | ret = -EINVAL; |
| 169 | continue; |
| 170 | } |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 171 | clnt->msize = option; |
| 172 | break; |
| 173 | case Opt_trans: |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 174 | s = match_strdup(&args[0]); |
| 175 | if (!s) { |
| 176 | ret = -ENOMEM; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 177 | p9_debug(P9_DEBUG_ERROR, |
| 178 | "problem allocating copy of trans arg\n"); |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 179 | goto free_and_return; |
Chengguang Xu | 9421c3e | 2018-04-05 16:20:01 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | v9fs_put_trans(clnt->trans_mod); |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 183 | clnt->trans_mod = v9fs_get_trans_by_name(s); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 184 | if (!clnt->trans_mod) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 185 | pr_info("Could not find request transport: %s\n", |
| 186 | s); |
Eric Van Hensbergen | 349d3bb | 2010-01-15 19:01:10 -0600 | [diff] [blame] | 187 | ret = -EINVAL; |
Eric Van Hensbergen | 349d3bb | 2010-01-15 19:01:10 -0600 | [diff] [blame] | 188 | } |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 189 | kfree(s); |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 190 | break; |
| 191 | case Opt_legacy: |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 192 | clnt->proto_version = p9_proto_legacy; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 193 | break; |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 194 | case Opt_version: |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 195 | s = match_strdup(&args[0]); |
| 196 | if (!s) { |
| 197 | ret = -ENOMEM; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 198 | p9_debug(P9_DEBUG_ERROR, |
| 199 | "problem allocating copy of version arg\n"); |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 200 | goto free_and_return; |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 201 | } |
Chengguang Xu | 8d856c7 | 2018-06-07 17:05:03 -0700 | [diff] [blame] | 202 | r = get_protocol_version(s); |
| 203 | if (r < 0) |
| 204 | ret = r; |
| 205 | else |
| 206 | clnt->proto_version = r; |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 207 | kfree(s); |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 208 | break; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 209 | default: |
| 210 | continue; |
| 211 | } |
| 212 | } |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 213 | |
Eric Van Hensbergen | 349d3bb | 2010-01-15 19:01:10 -0600 | [diff] [blame] | 214 | free_and_return: |
piaojun | c290fba | 2018-07-13 16:59:06 -0700 | [diff] [blame] | 215 | if (ret) |
| 216 | v9fs_put_trans(clnt->trans_mod); |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 217 | kfree(tmp_options); |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 218 | return ret; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 219 | } |
| 220 | |
Dominique Martinet | 91a76be | 2018-07-30 15:14:37 +0900 | [diff] [blame] | 221 | static int p9_fcall_init(struct p9_client *c, struct p9_fcall *fc, |
| 222 | int alloc_msize) |
Simon Derr | 5387320 | 2013-06-21 15:32:36 +0200 | [diff] [blame] | 223 | { |
Dominique Martinet | 91a76be | 2018-07-30 15:14:37 +0900 | [diff] [blame] | 224 | if (likely(c->fcall_cache) && alloc_msize == c->msize) { |
| 225 | fc->sdata = kmem_cache_alloc(c->fcall_cache, GFP_NOFS); |
| 226 | fc->cache = c->fcall_cache; |
| 227 | } else { |
| 228 | fc->sdata = kmalloc(alloc_msize, GFP_NOFS); |
| 229 | fc->cache = NULL; |
| 230 | } |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 231 | if (!fc->sdata) |
| 232 | return -ENOMEM; |
Simon Derr | 5387320 | 2013-06-21 15:32:36 +0200 | [diff] [blame] | 233 | fc->capacity = alloc_msize; |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 234 | return 0; |
Simon Derr | 5387320 | 2013-06-21 15:32:36 +0200 | [diff] [blame] | 235 | } |
| 236 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 237 | void p9_fcall_fini(struct p9_fcall *fc) |
| 238 | { |
Dominique Martinet | 91a76be | 2018-07-30 15:14:37 +0900 | [diff] [blame] | 239 | /* sdata can be NULL for interrupted requests in trans_rdma, |
| 240 | * and kmem_cache_free does not do NULL-check for us |
| 241 | */ |
| 242 | if (unlikely(!fc->sdata)) |
| 243 | return; |
| 244 | |
| 245 | if (fc->cache) |
| 246 | kmem_cache_free(fc->cache, fc->sdata); |
| 247 | else |
| 248 | kfree(fc->sdata); |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 249 | } |
| 250 | EXPORT_SYMBOL(p9_fcall_fini); |
| 251 | |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 252 | static struct kmem_cache *p9_req_cache; |
| 253 | |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 254 | /** |
Xiongfeng Wang | 03ff737 | 2021-03-27 16:15:54 +0800 | [diff] [blame] | 255 | * p9_tag_alloc - Allocate a new request. |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 256 | * @c: Client session. |
| 257 | * @type: Transaction type. |
| 258 | * @max_size: Maximum packet size for this request. |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 259 | * |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 260 | * Context: Process context. |
| 261 | * Return: Pointer to new request. |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 262 | */ |
Dan Carpenter | ef6b080 | 2011-08-26 19:57:40 +0300 | [diff] [blame] | 263 | static struct p9_req_t * |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 264 | p9_tag_alloc(struct p9_client *c, int8_t type, unsigned int max_size) |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 265 | { |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 266 | struct p9_req_t *req = kmem_cache_alloc(p9_req_cache, GFP_NOFS); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 267 | int alloc_msize = min(c->msize, max_size); |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 268 | int tag; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 269 | |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 270 | if (!req) |
Dan Carpenter | 72ea032 | 2018-09-26 13:39:34 +0300 | [diff] [blame] | 271 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 272 | |
Dominique Martinet | 91a76be | 2018-07-30 15:14:37 +0900 | [diff] [blame] | 273 | if (p9_fcall_init(c, &req->tc, alloc_msize)) |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 274 | goto free_req; |
Dominique Martinet | 91a76be | 2018-07-30 15:14:37 +0900 | [diff] [blame] | 275 | if (p9_fcall_init(c, &req->rc, alloc_msize)) |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 276 | goto free; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 277 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 278 | p9pdu_reset(&req->tc); |
| 279 | p9pdu_reset(&req->rc); |
Lu Shuaibing | 0ce772f | 2019-06-13 15:08:54 +0800 | [diff] [blame] | 280 | req->t_err = 0; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 281 | req->status = REQ_STATUS_ALLOC; |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 282 | init_waitqueue_head(&req->wq); |
| 283 | INIT_LIST_HEAD(&req->req_list); |
| 284 | |
| 285 | idr_preload(GFP_NOFS); |
| 286 | spin_lock_irq(&c->lock); |
| 287 | if (type == P9_TVERSION) |
| 288 | tag = idr_alloc(&c->reqs, req, P9_NOTAG, P9_NOTAG + 1, |
| 289 | GFP_NOWAIT); |
| 290 | else |
| 291 | tag = idr_alloc(&c->reqs, req, 0, P9_NOTAG, GFP_NOWAIT); |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 292 | req->tc.tag = tag; |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 293 | spin_unlock_irq(&c->lock); |
| 294 | idr_preload_end(); |
| 295 | if (tag < 0) |
| 296 | goto free; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 297 | |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 298 | /* Init ref to two because in the general case there is one ref |
| 299 | * that is put asynchronously by a writer thread, one ref |
| 300 | * temporarily given by p9_tag_lookup and put by p9_client_cb |
| 301 | * in the recv thread, and one ref put by p9_tag_remove in the |
| 302 | * main thread. The only exception is virtio that does not use |
| 303 | * p9_tag_lookup but does not have a writer thread either |
| 304 | * (the write happens synchronously in the request/zc_request |
| 305 | * callback), so p9_client_cb eats the second ref there |
| 306 | * as the pointer is duplicated directly by virtqueue_add_sgs() |
| 307 | */ |
| 308 | refcount_set(&req->refcount.refcount, 2); |
| 309 | |
Simon Derr | ea071aa | 2013-06-21 15:32:34 +0200 | [diff] [blame] | 310 | return req; |
| 311 | |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 312 | free: |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 313 | p9_fcall_fini(&req->tc); |
| 314 | p9_fcall_fini(&req->rc); |
| 315 | free_req: |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 316 | kmem_cache_free(p9_req_cache, req); |
Simon Derr | ea071aa | 2013-06-21 15:32:34 +0200 | [diff] [blame] | 317 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 318 | } |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 319 | |
| 320 | /** |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 321 | * p9_tag_lookup - Look up a request by tag. |
| 322 | * @c: Client session. |
| 323 | * @tag: Transaction ID. |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 324 | * |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 325 | * Context: Any context. |
| 326 | * Return: A request, or %NULL if there is no request with that tag. |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 327 | */ |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 328 | struct p9_req_t *p9_tag_lookup(struct p9_client *c, u16 tag) |
| 329 | { |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 330 | struct p9_req_t *req; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 331 | |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 332 | rcu_read_lock(); |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 333 | again: |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 334 | req = idr_find(&c->reqs, tag); |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 335 | if (req) { |
| 336 | /* We have to be careful with the req found under rcu_read_lock |
| 337 | * Thanks to SLAB_TYPESAFE_BY_RCU we can safely try to get the |
| 338 | * ref again without corrupting other data, then check again |
| 339 | * that the tag matches once we have the ref |
| 340 | */ |
| 341 | if (!p9_req_try_get(req)) |
| 342 | goto again; |
| 343 | if (req->tc.tag != tag) { |
| 344 | p9_req_put(req); |
| 345 | goto again; |
| 346 | } |
| 347 | } |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 348 | rcu_read_unlock(); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 349 | |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 350 | return req; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 351 | } |
| 352 | EXPORT_SYMBOL(p9_tag_lookup); |
| 353 | |
| 354 | /** |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 355 | * p9_tag_remove - Remove a tag. |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 356 | * @c: Client session. |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 357 | * @r: Request of reference. |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 358 | * |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 359 | * Context: Any context. |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 360 | */ |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 361 | static int p9_tag_remove(struct p9_client *c, struct p9_req_t *r) |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 362 | { |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 363 | unsigned long flags; |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 364 | u16 tag = r->tc.tag; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 365 | |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 366 | p9_debug(P9_DEBUG_MUX, "clnt %p req %p tag: %d\n", c, r, tag); |
| 367 | spin_lock_irqsave(&c->lock, flags); |
| 368 | idr_remove(&c->reqs, tag); |
| 369 | spin_unlock_irqrestore(&c->lock, flags); |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 370 | return p9_req_put(r); |
| 371 | } |
| 372 | |
| 373 | static void p9_req_free(struct kref *ref) |
| 374 | { |
| 375 | struct p9_req_t *r = container_of(ref, struct p9_req_t, refcount); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 376 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 377 | p9_fcall_fini(&r->tc); |
| 378 | p9_fcall_fini(&r->rc); |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 379 | kmem_cache_free(p9_req_cache, r); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 380 | } |
| 381 | |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 382 | int p9_req_put(struct p9_req_t *r) |
| 383 | { |
| 384 | return kref_put(&r->refcount, p9_req_free); |
| 385 | } |
| 386 | EXPORT_SYMBOL(p9_req_put); |
| 387 | |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 388 | /** |
| 389 | * p9_tag_cleanup - cleans up tags structure and reclaims resources |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 390 | * @c: v9fs client struct |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 391 | * |
| 392 | * This frees resources associated with the tags structure |
| 393 | * |
| 394 | */ |
| 395 | static void p9_tag_cleanup(struct p9_client *c) |
| 396 | { |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 397 | struct p9_req_t *req; |
| 398 | int id; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 399 | |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 400 | rcu_read_lock(); |
| 401 | idr_for_each_entry(&c->reqs, req, id) { |
| 402 | pr_info("Tag %d still in use\n", id); |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 403 | if (p9_tag_remove(c, req) == 0) |
| 404 | pr_warn("Packet with tag %d has still references", |
| 405 | req->tc.tag); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 406 | } |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 407 | rcu_read_unlock(); |
Eric Van Hensbergen | 673d62cd | 2008-10-13 18:45:22 -0500 | [diff] [blame] | 408 | } |
| 409 | |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 410 | /** |
| 411 | * p9_client_cb - call back from transport to client |
Andrew Lunn | 760b3d6 | 2020-10-31 19:26:55 +0100 | [diff] [blame] | 412 | * @c: client state |
| 413 | * @req: request received |
| 414 | * @status: request status, one of REQ_STATUS_* |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 415 | * |
| 416 | */ |
Dominique Martinet | 2b6e72e | 2014-01-17 18:31:00 +0100 | [diff] [blame] | 417 | void p9_client_cb(struct p9_client *c, struct p9_req_t *req, int status) |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 418 | { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 419 | p9_debug(P9_DEBUG_MUX, " tag %d\n", req->tc.tag); |
Dominique Martinet | 2b6e72e | 2014-01-17 18:31:00 +0100 | [diff] [blame] | 420 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 421 | /* This barrier is needed to make sure any change made to req before |
Matthew Wilcox | 2d58f63 | 2018-07-11 14:02:20 -0700 | [diff] [blame] | 422 | * the status change is visible to another thread |
Dominique Martinet | 2b6e72e | 2014-01-17 18:31:00 +0100 | [diff] [blame] | 423 | */ |
| 424 | smp_wmb(); |
| 425 | req->status = status; |
| 426 | |
Matthew Wilcox | 2557d0c | 2018-07-11 14:02:23 -0700 | [diff] [blame] | 427 | wake_up(&req->wq); |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 428 | p9_debug(P9_DEBUG_MUX, "wakeup: %d\n", req->tc.tag); |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 429 | p9_req_put(req); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 430 | } |
| 431 | EXPORT_SYMBOL(p9_client_cb); |
| 432 | |
| 433 | /** |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 434 | * p9_parse_header - parse header arguments out of a packet |
| 435 | * @pdu: packet to parse |
| 436 | * @size: size of packet |
| 437 | * @type: type of request |
| 438 | * @tag: tag of packet |
| 439 | * @rewind: set if we need to rewind offset afterwards |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 440 | */ |
| 441 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 442 | int |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 443 | p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, |
| 444 | int16_t *tag, int rewind) |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 445 | { |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 446 | s8 r_type; |
| 447 | s16 r_tag; |
| 448 | s32 r_size; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 449 | int offset = pdu->offset; |
| 450 | int err; |
| 451 | |
| 452 | pdu->offset = 0; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 453 | |
| 454 | err = p9pdu_readf(pdu, 0, "dbw", &r_size, &r_type, &r_tag); |
| 455 | if (err) |
| 456 | goto rewind_and_exit; |
| 457 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 458 | if (type) |
| 459 | *type = r_type; |
| 460 | if (tag) |
| 461 | *tag = r_tag; |
| 462 | if (size) |
| 463 | *size = r_size; |
| 464 | |
Tomas Bortoli | f984579 | 2018-07-23 17:44:04 +0200 | [diff] [blame] | 465 | if (pdu->size != r_size || r_size < 7) { |
| 466 | err = -EINVAL; |
| 467 | goto rewind_and_exit; |
| 468 | } |
| 469 | |
| 470 | pdu->id = r_type; |
| 471 | pdu->tag = r_tag; |
| 472 | |
| 473 | p9_debug(P9_DEBUG_9P, "<<< size=%d type: %d tag: %d\n", |
| 474 | pdu->size, pdu->id, pdu->tag); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 475 | |
| 476 | rewind_and_exit: |
| 477 | if (rewind) |
| 478 | pdu->offset = offset; |
| 479 | return err; |
| 480 | } |
| 481 | EXPORT_SYMBOL(p9_parse_header); |
| 482 | |
| 483 | /** |
| 484 | * p9_check_errors - check 9p packet for error return and process it |
| 485 | * @c: current client instance |
| 486 | * @req: request to parse and check for error conditions |
| 487 | * |
| 488 | * returns error code if one is discovered, otherwise returns 0 |
| 489 | * |
| 490 | * this will have to be more complicated if we have multiple |
| 491 | * error packet types |
| 492 | */ |
| 493 | |
| 494 | static int p9_check_errors(struct p9_client *c, struct p9_req_t *req) |
| 495 | { |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 496 | s8 type; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 497 | int err; |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 498 | int ecode; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 499 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 500 | err = p9_parse_header(&req->rc, NULL, &type, NULL, 0); |
| 501 | if (req->rc.size >= c->msize) { |
Tomas Bortoli | f984579 | 2018-07-23 17:44:04 +0200 | [diff] [blame] | 502 | p9_debug(P9_DEBUG_ERROR, |
| 503 | "requested packet size too big: %d\n", |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 504 | req->rc.size); |
Tomas Bortoli | f984579 | 2018-07-23 17:44:04 +0200 | [diff] [blame] | 505 | return -EIO; |
| 506 | } |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 507 | /* dump the response from server |
Aneesh Kumar K.V | 348b590 | 2011-08-07 00:46:59 +0530 | [diff] [blame] | 508 | * This should be after check errors which poplulate pdu_fcall. |
| 509 | */ |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 510 | trace_9p_protocol_dump(c, &req->rc); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 511 | if (err) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 512 | p9_debug(P9_DEBUG_ERROR, "couldn't parse header %d\n", err); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 513 | return err; |
| 514 | } |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 515 | if (type != P9_RERROR && type != P9_RLERROR) |
| 516 | return 0; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 517 | |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 518 | if (!p9_is_proto_dotl(c)) { |
| 519 | char *ename; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 520 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 521 | err = p9pdu_readf(&req->rc, c->proto_version, "s?d", |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 522 | &ename, &ecode); |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 523 | if (err) |
| 524 | goto out_err; |
| 525 | |
Arnd Bergmann | 287980e | 2016-05-27 23:23:25 +0200 | [diff] [blame] | 526 | if (p9_is_proto_dotu(c) && ecode < 512) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 527 | err = -ecode; |
| 528 | |
Arnd Bergmann | 287980e | 2016-05-27 23:23:25 +0200 | [diff] [blame] | 529 | if (!err) { |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 530 | err = p9_errstr2errno(ename, strlen(ename)); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 531 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 532 | p9_debug(P9_DEBUG_9P, "<<< RERROR (%d) %s\n", |
| 533 | -ecode, ename); |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 534 | } |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 535 | kfree(ename); |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 536 | } else { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 537 | err = p9pdu_readf(&req->rc, c->proto_version, "d", &ecode); |
Dominique Martinet | 27eb4c3 | 2021-11-02 19:47:47 +0900 | [diff] [blame] | 538 | if (err) |
| 539 | goto out_err; |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 540 | err = -ecode; |
| 541 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 542 | p9_debug(P9_DEBUG_9P, "<<< RLERROR (%d)\n", -ecode); |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 543 | } |
| 544 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 545 | return err; |
Arun R Bharadwaj | 4f7ebe8 | 2010-07-28 14:17:26 +0530 | [diff] [blame] | 546 | |
| 547 | out_err: |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 548 | p9_debug(P9_DEBUG_ERROR, "couldn't parse error%d\n", err); |
Arun R Bharadwaj | 4f7ebe8 | 2010-07-28 14:17:26 +0530 | [diff] [blame] | 549 | |
| 550 | return err; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 551 | } |
| 552 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 553 | /** |
| 554 | * p9_check_zc_errors - check 9p packet for error return and process it |
| 555 | * @c: current client instance |
| 556 | * @req: request to parse and check for error conditions |
Andrew Lunn | 760b3d6 | 2020-10-31 19:26:55 +0100 | [diff] [blame] | 557 | * @uidata: external buffer containing error |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 558 | * @in_hdrlen: Size of response protocol buffer. |
| 559 | * |
| 560 | * returns error code if one is discovered, otherwise returns 0 |
| 561 | * |
| 562 | * this will have to be more complicated if we have multiple |
| 563 | * error packet types |
| 564 | */ |
| 565 | |
| 566 | static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req, |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 567 | struct iov_iter *uidata, int in_hdrlen) |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 568 | { |
| 569 | int err; |
| 570 | int ecode; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 571 | s8 type; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 572 | char *ename = NULL; |
| 573 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 574 | err = p9_parse_header(&req->rc, NULL, &type, NULL, 0); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 575 | /* dump the response from server |
Aneesh Kumar K.V | 348b590 | 2011-08-07 00:46:59 +0530 | [diff] [blame] | 576 | * This should be after parse_header which poplulate pdu_fcall. |
| 577 | */ |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 578 | trace_9p_protocol_dump(c, &req->rc); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 579 | if (err) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 580 | p9_debug(P9_DEBUG_ERROR, "couldn't parse header %d\n", err); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 581 | return err; |
| 582 | } |
| 583 | |
| 584 | if (type != P9_RERROR && type != P9_RLERROR) |
| 585 | return 0; |
| 586 | |
| 587 | if (!p9_is_proto_dotl(c)) { |
| 588 | /* Error is reported in string format */ |
Aneesh Kumar K.V | 42fe648 | 2013-05-20 23:05:15 +0530 | [diff] [blame] | 589 | int len; |
| 590 | /* 7 = header size for RERROR; */ |
| 591 | int inline_len = in_hdrlen - 7; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 592 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 593 | len = req->rc.size - req->rc.offset; |
Aneesh Kumar K.V | 42fe648 | 2013-05-20 23:05:15 +0530 | [diff] [blame] | 594 | if (len > (P9_ZC_HDR_SZ - 7)) { |
| 595 | err = -EFAULT; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 596 | goto out_err; |
| 597 | } |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 598 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 599 | ename = &req->rc.sdata[req->rc.offset]; |
Aneesh Kumar K.V | 42fe648 | 2013-05-20 23:05:15 +0530 | [diff] [blame] | 600 | if (len > inline_len) { |
| 601 | /* We have error in external buffer */ |
Al Viro | 1c512a7 | 2017-02-17 23:16:09 -0500 | [diff] [blame] | 602 | if (!copy_from_iter_full(ename + inline_len, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 603 | len - inline_len, uidata)) { |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 604 | err = -EFAULT; |
| 605 | goto out_err; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 606 | } |
| 607 | } |
Aneesh Kumar K.V | 42fe648 | 2013-05-20 23:05:15 +0530 | [diff] [blame] | 608 | ename = NULL; |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 609 | err = p9pdu_readf(&req->rc, c->proto_version, "s?d", |
Aneesh Kumar K.V | 42fe648 | 2013-05-20 23:05:15 +0530 | [diff] [blame] | 610 | &ename, &ecode); |
| 611 | if (err) |
| 612 | goto out_err; |
| 613 | |
Arnd Bergmann | 287980e | 2016-05-27 23:23:25 +0200 | [diff] [blame] | 614 | if (p9_is_proto_dotu(c) && ecode < 512) |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 615 | err = -ecode; |
Aneesh Kumar K.V | 42fe648 | 2013-05-20 23:05:15 +0530 | [diff] [blame] | 616 | |
Arnd Bergmann | 287980e | 2016-05-27 23:23:25 +0200 | [diff] [blame] | 617 | if (!err) { |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 618 | err = p9_errstr2errno(ename, strlen(ename)); |
| 619 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 620 | p9_debug(P9_DEBUG_9P, "<<< RERROR (%d) %s\n", |
| 621 | -ecode, ename); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 622 | } |
| 623 | kfree(ename); |
| 624 | } else { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 625 | err = p9pdu_readf(&req->rc, c->proto_version, "d", &ecode); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 626 | err = -ecode; |
| 627 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 628 | p9_debug(P9_DEBUG_9P, "<<< RLERROR (%d)\n", -ecode); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 629 | } |
| 630 | return err; |
| 631 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 632 | out_err: |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 633 | p9_debug(P9_DEBUG_ERROR, "couldn't parse error%d\n", err); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 634 | return err; |
| 635 | } |
| 636 | |
Rob Landley | aca0076 | 2011-05-08 18:46:38 +0000 | [diff] [blame] | 637 | static struct p9_req_t * |
| 638 | p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...); |
| 639 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 640 | /** |
| 641 | * p9_client_flush - flush (cancel) a request |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 642 | * @c: client state |
| 643 | * @oldreq: request to cancel |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 644 | * |
Rob Landley | aca0076 | 2011-05-08 18:46:38 +0000 | [diff] [blame] | 645 | * This sents a flush for a particular request and links |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 646 | * the flush request to the original request. The current |
| 647 | * code only supports a single flush request although the protocol |
| 648 | * allows for multiple flush requests to be sent for a single request. |
| 649 | * |
| 650 | */ |
| 651 | |
| 652 | static int p9_client_flush(struct p9_client *c, struct p9_req_t *oldreq) |
| 653 | { |
| 654 | struct p9_req_t *req; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 655 | s16 oldtag; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 656 | int err; |
| 657 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 658 | err = p9_parse_header(&oldreq->tc, NULL, NULL, &oldtag, 1); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 659 | if (err) |
| 660 | return err; |
| 661 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 662 | p9_debug(P9_DEBUG_9P, ">>> TFLUSH tag %d\n", oldtag); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 663 | |
| 664 | req = p9_client_rpc(c, P9_TFLUSH, "w", oldtag); |
| 665 | if (IS_ERR(req)) |
| 666 | return PTR_ERR(req); |
| 667 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 668 | /* if we haven't received a response for oldreq, |
Andi Shyti | 60ff779 | 2013-07-25 10:54:24 +0200 | [diff] [blame] | 669 | * remove it from the list |
Simon Derr | 1cff330 | 2013-06-21 15:32:42 +0200 | [diff] [blame] | 670 | */ |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 671 | if (oldreq->status == REQ_STATUS_SENT) { |
Simon Derr | afd8d65 | 2014-03-10 16:38:49 +0100 | [diff] [blame] | 672 | if (c->trans_mod->cancelled) |
| 673 | c->trans_mod->cancelled(c, oldreq); |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 674 | } |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 675 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 676 | p9_tag_remove(c, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 680 | static struct p9_req_t *p9_client_prepare_req(struct p9_client *c, |
| 681 | int8_t type, int req_size, |
| 682 | const char *fmt, va_list ap) |
| 683 | { |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 684 | int err; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 685 | struct p9_req_t *req; |
| 686 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 687 | p9_debug(P9_DEBUG_MUX, "client %p op %d\n", c, type); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 688 | |
| 689 | /* we allow for any status other than disconnected */ |
| 690 | if (c->status == Disconnected) |
| 691 | return ERR_PTR(-EIO); |
| 692 | |
| 693 | /* if status is begin_disconnected we allow only clunk request */ |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 694 | if (c->status == BeginDisconnect && type != P9_TCLUNK) |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 695 | return ERR_PTR(-EIO); |
| 696 | |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 697 | req = p9_tag_alloc(c, type, req_size); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 698 | if (IS_ERR(req)) |
| 699 | return req; |
| 700 | |
| 701 | /* marshall the data */ |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 702 | p9pdu_prepare(&req->tc, req->tc.tag, type); |
| 703 | err = p9pdu_vwritef(&req->tc, c->proto_version, fmt, ap); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 704 | if (err) |
| 705 | goto reterr; |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 706 | p9pdu_finalize(c, &req->tc); |
| 707 | trace_9p_client_req(c, type, req->tc.tag); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 708 | return req; |
| 709 | reterr: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 710 | p9_tag_remove(c, req); |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 711 | /* We have to put also the 2nd reference as it won't be used */ |
| 712 | p9_req_put(req); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 713 | return ERR_PTR(err); |
| 714 | } |
| 715 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 716 | /** |
| 717 | * p9_client_rpc - issue a request and wait for a response |
| 718 | * @c: client session |
| 719 | * @type: type of request |
| 720 | * @fmt: protocol format string (see protocol.c) |
| 721 | * |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 722 | * Returns request structure (which client must free using p9_tag_remove) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 723 | */ |
| 724 | |
| 725 | static struct p9_req_t * |
| 726 | p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...) |
| 727 | { |
| 728 | va_list ap; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 729 | int sigpending, err; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 730 | unsigned long flags; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 731 | struct p9_req_t *req; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 732 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 733 | va_start(ap, fmt); |
| 734 | req = p9_client_prepare_req(c, type, c->msize, fmt, ap); |
| 735 | va_end(ap); |
| 736 | if (IS_ERR(req)) |
| 737 | return req; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 738 | |
| 739 | if (signal_pending(current)) { |
| 740 | sigpending = 1; |
| 741 | clear_thread_flag(TIF_SIGPENDING); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 742 | } else { |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 743 | sigpending = 0; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 744 | } |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 745 | |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 746 | err = c->trans_mod->request(c, req); |
| 747 | if (err < 0) { |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 748 | /* write won't happen */ |
| 749 | p9_req_put(req); |
M. Mohan Kumar | 3cd7967 | 2011-04-15 13:59:33 +0530 | [diff] [blame] | 750 | if (err != -ERESTARTSYS && err != -EFAULT) |
Venkateswararao Jujjuri (JV) | 52f44e0 | 2010-09-29 18:33:41 -0700 | [diff] [blame] | 751 | c->status = Disconnected; |
Greg Kurz | a852224 | 2018-04-05 16:19:44 -0700 | [diff] [blame] | 752 | goto recalc_sigpending; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 753 | } |
Jim Garlick | a314f27 | 2012-02-01 12:48:53 -0800 | [diff] [blame] | 754 | again: |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 755 | /* Wait for the response */ |
Matthew Wilcox | 2557d0c | 2018-07-11 14:02:23 -0700 | [diff] [blame] | 756 | err = wait_event_killable(req->wq, req->status >= REQ_STATUS_RCVD); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 757 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 758 | /* Make sure our req is coherent with regard to updates in other |
Dominique Martinet | 2b6e72e | 2014-01-17 18:31:00 +0100 | [diff] [blame] | 759 | * threads - echoes to wmb() in the callback |
| 760 | */ |
| 761 | smp_rmb(); |
| 762 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 763 | if (err == -ERESTARTSYS && c->status == Connected && |
| 764 | type == P9_TFLUSH) { |
Jim Garlick | a314f27 | 2012-02-01 12:48:53 -0800 | [diff] [blame] | 765 | sigpending = 1; |
| 766 | clear_thread_flag(TIF_SIGPENDING); |
| 767 | goto again; |
| 768 | } |
| 769 | |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 770 | if (req->status == REQ_STATUS_ERROR) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 771 | p9_debug(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 772 | err = req->t_err; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 773 | } |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 774 | if (err == -ERESTARTSYS && c->status == Connected) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 775 | p9_debug(P9_DEBUG_MUX, "flushing\n"); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 776 | sigpending = 1; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 777 | clear_thread_flag(TIF_SIGPENDING); |
| 778 | |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 779 | if (c->trans_mod->cancel(c, req)) |
| 780 | p9_client_flush(c, req); |
| 781 | |
| 782 | /* if we received the response anyway, don't signal error */ |
| 783 | if (req->status == REQ_STATUS_RCVD) |
| 784 | err = 0; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 785 | } |
Greg Kurz | a852224 | 2018-04-05 16:19:44 -0700 | [diff] [blame] | 786 | recalc_sigpending: |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 787 | if (sigpending) { |
| 788 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
| 789 | recalc_sigpending(); |
| 790 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
| 791 | } |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 792 | if (err < 0) |
| 793 | goto reterr; |
| 794 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 795 | err = p9_check_errors(c, req); |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 796 | trace_9p_client_res(c, type, req->rc.tag, err); |
Aneesh Kumar K.V | 348b590 | 2011-08-07 00:46:59 +0530 | [diff] [blame] | 797 | if (!err) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 798 | return req; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 799 | reterr: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 800 | p9_tag_remove(c, req); |
Simon Derr | 43def35 | 2012-08-10 15:52:06 +0200 | [diff] [blame] | 801 | return ERR_PTR(safe_errno(err)); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 802 | } |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 803 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 804 | /** |
| 805 | * p9_client_zc_rpc - issue a request and wait for a response |
| 806 | * @c: client session |
| 807 | * @type: type of request |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 808 | * @uidata: destination for zero copy read |
| 809 | * @uodata: source for zero copy write |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 810 | * @inlen: read buffer size |
| 811 | * @olen: write buffer size |
Andrew Lunn | 15e522a | 2020-07-13 01:14:57 +0200 | [diff] [blame] | 812 | * @in_hdrlen: reader header size, This is the size of response protocol data |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 813 | * @fmt: protocol format string (see protocol.c) |
| 814 | * |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 815 | * Returns request structure (which client must free using p9_tag_remove) |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 816 | */ |
| 817 | static struct p9_req_t *p9_client_zc_rpc(struct p9_client *c, int8_t type, |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 818 | struct iov_iter *uidata, |
| 819 | struct iov_iter *uodata, |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 820 | int inlen, int olen, int in_hdrlen, |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 821 | const char *fmt, ...) |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 822 | { |
| 823 | va_list ap; |
| 824 | int sigpending, err; |
| 825 | unsigned long flags; |
| 826 | struct p9_req_t *req; |
| 827 | |
| 828 | va_start(ap, fmt); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 829 | /* We allocate a inline protocol data of only 4k bytes. |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 830 | * The actual content is passed in zero-copy fashion. |
| 831 | */ |
| 832 | req = p9_client_prepare_req(c, type, P9_ZC_HDR_SZ, fmt, ap); |
| 833 | va_end(ap); |
| 834 | if (IS_ERR(req)) |
| 835 | return req; |
| 836 | |
| 837 | if (signal_pending(current)) { |
| 838 | sigpending = 1; |
| 839 | clear_thread_flag(TIF_SIGPENDING); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 840 | } else { |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 841 | sigpending = 0; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 842 | } |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 843 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 844 | err = c->trans_mod->zc_request(c, req, uidata, uodata, |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 845 | inlen, olen, in_hdrlen); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 846 | if (err < 0) { |
| 847 | if (err == -EIO) |
| 848 | c->status = Disconnected; |
Al Viro | a84b69c | 2015-07-04 16:04:19 -0400 | [diff] [blame] | 849 | if (err != -ERESTARTSYS) |
Greg Kurz | a852224 | 2018-04-05 16:19:44 -0700 | [diff] [blame] | 850 | goto recalc_sigpending; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 851 | } |
| 852 | if (req->status == REQ_STATUS_ERROR) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 853 | p9_debug(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 854 | err = req->t_err; |
| 855 | } |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 856 | if (err == -ERESTARTSYS && c->status == Connected) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 857 | p9_debug(P9_DEBUG_MUX, "flushing\n"); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 858 | sigpending = 1; |
| 859 | clear_thread_flag(TIF_SIGPENDING); |
| 860 | |
| 861 | if (c->trans_mod->cancel(c, req)) |
| 862 | p9_client_flush(c, req); |
| 863 | |
| 864 | /* if we received the response anyway, don't signal error */ |
| 865 | if (req->status == REQ_STATUS_RCVD) |
| 866 | err = 0; |
| 867 | } |
Greg Kurz | a852224 | 2018-04-05 16:19:44 -0700 | [diff] [blame] | 868 | recalc_sigpending: |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 869 | if (sigpending) { |
| 870 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
| 871 | recalc_sigpending(); |
| 872 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
| 873 | } |
| 874 | if (err < 0) |
| 875 | goto reterr; |
| 876 | |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 877 | err = p9_check_zc_errors(c, req, uidata, in_hdrlen); |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 878 | trace_9p_client_res(c, type, req->rc.tag, err); |
Aneesh Kumar K.V | 348b590 | 2011-08-07 00:46:59 +0530 | [diff] [blame] | 879 | if (!err) |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 880 | return req; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 881 | reterr: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 882 | p9_tag_remove(c, req); |
Simon Derr | 43def35 | 2012-08-10 15:52:06 +0200 | [diff] [blame] | 883 | return ERR_PTR(safe_errno(err)); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 884 | } |
| 885 | |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 886 | static struct p9_fid *p9_fid_create(struct p9_client *clnt) |
| 887 | { |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 888 | int ret; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 889 | struct p9_fid *fid; |
| 890 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 891 | p9_debug(P9_DEBUG_FID, "clnt %p\n", clnt); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 892 | fid = kmalloc(sizeof(*fid), GFP_KERNEL); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 893 | if (!fid) |
Matthew Wilcox | b5303be | 2018-07-11 14:02:21 -0700 | [diff] [blame] | 894 | return NULL; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 895 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 896 | memset(&fid->qid, 0, sizeof(fid->qid)); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 897 | fid->mode = -1; |
David Howells | f8b9d53 | 2008-11-14 10:38:44 +1100 | [diff] [blame] | 898 | fid->uid = current_fsuid(); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 899 | fid->clnt = clnt; |
Eric Van Hensbergen | 3e2796a | 2009-11-02 08:39:28 -0600 | [diff] [blame] | 900 | fid->rdir = NULL; |
Matthew Wilcox | f28cdf0 | 2018-07-11 14:02:22 -0700 | [diff] [blame] | 901 | fid->fid = 0; |
Dominique Martinet | ff5e72e | 2020-11-03 09:35:57 +0100 | [diff] [blame] | 902 | refcount_set(&fid->count, 1); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 903 | |
Matthew Wilcox | f28cdf0 | 2018-07-11 14:02:22 -0700 | [diff] [blame] | 904 | idr_preload(GFP_KERNEL); |
| 905 | spin_lock_irq(&clnt->lock); |
| 906 | ret = idr_alloc_u32(&clnt->fids, fid, &fid->fid, P9_NOFID - 1, |
| 907 | GFP_NOWAIT); |
| 908 | spin_unlock_irq(&clnt->lock); |
| 909 | idr_preload_end(); |
Matthew Wilcox | f28cdf0 | 2018-07-11 14:02:22 -0700 | [diff] [blame] | 910 | if (!ret) |
| 911 | return fid; |
| 912 | |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 913 | kfree(fid); |
Matthew Wilcox | b5303be | 2018-07-11 14:02:21 -0700 | [diff] [blame] | 914 | return NULL; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | static void p9_fid_destroy(struct p9_fid *fid) |
| 918 | { |
| 919 | struct p9_client *clnt; |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 920 | unsigned long flags; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 921 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 922 | p9_debug(P9_DEBUG_FID, "fid %d\n", fid->fid); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 923 | clnt = fid->clnt; |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 924 | spin_lock_irqsave(&clnt->lock, flags); |
Matthew Wilcox | f28cdf0 | 2018-07-11 14:02:22 -0700 | [diff] [blame] | 925 | idr_remove(&clnt->fids, fid->fid); |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 926 | spin_unlock_irqrestore(&clnt->lock, flags); |
Eric Van Hensbergen | 3e2796a | 2009-11-02 08:39:28 -0600 | [diff] [blame] | 927 | kfree(fid->rdir); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 928 | kfree(fid); |
| 929 | } |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 930 | |
stephen hemminger | 32a875a | 2010-10-19 06:48:16 +0000 | [diff] [blame] | 931 | static int p9_client_version(struct p9_client *c) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 932 | { |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 933 | int err = 0; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 934 | struct p9_req_t *req; |
Tomas Bortoli | 7913690 | 2018-07-10 00:29:43 +0200 | [diff] [blame] | 935 | char *version = NULL; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 936 | int msize; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 937 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 938 | p9_debug(P9_DEBUG_9P, ">>> TVERSION msize %d protocol %d\n", |
| 939 | c->msize, c->proto_version); |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 940 | |
| 941 | switch (c->proto_version) { |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 942 | case p9_proto_2000L: |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 943 | req = p9_client_rpc(c, P9_TVERSION, "ds", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 944 | c->msize, "9P2000.L"); |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 945 | break; |
| 946 | case p9_proto_2000u: |
| 947 | req = p9_client_rpc(c, P9_TVERSION, "ds", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 948 | c->msize, "9P2000.u"); |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 949 | break; |
| 950 | case p9_proto_legacy: |
| 951 | req = p9_client_rpc(c, P9_TVERSION, "ds", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 952 | c->msize, "9P2000"); |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 953 | break; |
| 954 | default: |
| 955 | return -EINVAL; |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 958 | if (IS_ERR(req)) |
| 959 | return PTR_ERR(req); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 960 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 961 | err = p9pdu_readf(&req->rc, c->proto_version, "ds", &msize, &version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 962 | if (err) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 963 | p9_debug(P9_DEBUG_9P, "version error %d\n", err); |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 964 | trace_9p_protocol_dump(c, &req->rc); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 965 | goto error; |
| 966 | } |
| 967 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 968 | p9_debug(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 969 | if (!strncmp(version, "9P2000.L", 8)) { |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 970 | c->proto_version = p9_proto_2000L; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 971 | } else if (!strncmp(version, "9P2000.u", 8)) { |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 972 | c->proto_version = p9_proto_2000u; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 973 | } else if (!strncmp(version, "9P2000", 6)) { |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 974 | c->proto_version = p9_proto_legacy; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 975 | } else { |
Dominique Martinet | 574d356 | 2018-11-05 09:52:48 +0100 | [diff] [blame] | 976 | p9_debug(P9_DEBUG_ERROR, |
| 977 | "server returned an unknown version: %s\n", version); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 978 | err = -EREMOTEIO; |
| 979 | goto error; |
| 980 | } |
| 981 | |
Dominique Martinet | 574d356 | 2018-11-05 09:52:48 +0100 | [diff] [blame] | 982 | if (msize < 4096) { |
| 983 | p9_debug(P9_DEBUG_ERROR, |
| 984 | "server returned a msize < 4096: %d\n", msize); |
| 985 | err = -EREMOTEIO; |
| 986 | goto error; |
| 987 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 988 | if (msize < c->msize) |
| 989 | c->msize = msize; |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 990 | |
| 991 | error: |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 992 | kfree(version); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 993 | p9_tag_remove(c, req); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 994 | |
| 995 | return err; |
| 996 | } |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 997 | |
| 998 | struct p9_client *p9_client_create(const char *dev_name, char *options) |
| 999 | { |
| 1000 | int err; |
| 1001 | struct p9_client *clnt; |
Will Deacon | 50192ab | 2013-08-21 18:24:47 +0100 | [diff] [blame] | 1002 | char *client_id; |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 1003 | |
| 1004 | err = 0; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1005 | clnt = kmalloc(sizeof(*clnt), GFP_KERNEL); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1006 | if (!clnt) |
| 1007 | return ERR_PTR(-ENOMEM); |
| 1008 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 1009 | clnt->trans_mod = NULL; |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 1010 | clnt->trans = NULL; |
Dominique Martinet | 91a76be | 2018-07-30 15:14:37 +0900 | [diff] [blame] | 1011 | clnt->fcall_cache = NULL; |
Will Deacon | 50192ab | 2013-08-21 18:24:47 +0100 | [diff] [blame] | 1012 | |
| 1013 | client_id = utsname()->nodename; |
| 1014 | memcpy(clnt->name, client_id, strlen(client_id) + 1); |
| 1015 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1016 | spin_lock_init(&clnt->lock); |
Matthew Wilcox | f28cdf0 | 2018-07-11 14:02:22 -0700 | [diff] [blame] | 1017 | idr_init(&clnt->fids); |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 1018 | idr_init(&clnt->reqs); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 1019 | |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 1020 | err = parse_opts(options, clnt); |
| 1021 | if (err < 0) |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 1022 | goto free_client; |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 1023 | |
Abhishek Kulkarni | a17d172 | 2009-07-14 13:24:10 -0500 | [diff] [blame] | 1024 | if (!clnt->trans_mod) |
| 1025 | clnt->trans_mod = v9fs_get_default_trans(); |
| 1026 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1027 | if (!clnt->trans_mod) { |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 1028 | err = -EPROTONOSUPPORT; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1029 | p9_debug(P9_DEBUG_ERROR, |
| 1030 | "No transport defined or default transport\n"); |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 1031 | goto free_client; |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 1032 | } |
| 1033 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1034 | p9_debug(P9_DEBUG_MUX, "clnt %p trans %p msize %d protocol %d\n", |
| 1035 | clnt, clnt->trans_mod, clnt->msize, clnt->proto_version); |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 1036 | |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 1037 | err = clnt->trans_mod->create(clnt, dev_name, options); |
| 1038 | if (err) |
Matthew Wilcox | f28cdf0 | 2018-07-11 14:02:22 -0700 | [diff] [blame] | 1039 | goto put_trans; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 1040 | |
Christian Schoenebeck | 15e2721 | 2021-12-30 14:23:18 +0100 | [diff] [blame] | 1041 | if (clnt->msize > clnt->trans_mod->maxsize) { |
Venkateswararao Jujjuri (JV) | c9ffb05 | 2011-06-29 18:06:33 -0700 | [diff] [blame] | 1042 | clnt->msize = clnt->trans_mod->maxsize; |
Christian Schoenebeck | 15e2721 | 2021-12-30 14:23:18 +0100 | [diff] [blame] | 1043 | pr_info("Limiting 'msize' to %d as this is the maximum " |
| 1044 | "supported by transport %s\n", |
| 1045 | clnt->msize, clnt->trans_mod->name |
| 1046 | ); |
| 1047 | } |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 1048 | |
Dominique Martinet | 574d356 | 2018-11-05 09:52:48 +0100 | [diff] [blame] | 1049 | if (clnt->msize < 4096) { |
| 1050 | p9_debug(P9_DEBUG_ERROR, |
| 1051 | "Please specify a msize of at least 4k\n"); |
| 1052 | err = -EINVAL; |
zhengbin | bb06c38 | 2019-03-13 16:01:37 +0800 | [diff] [blame] | 1053 | goto close_trans; |
Dominique Martinet | 574d356 | 2018-11-05 09:52:48 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 1056 | err = p9_client_version(clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1057 | if (err) |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 1058 | goto close_trans; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1059 | |
Dominique Martinet | 91a76be | 2018-07-30 15:14:37 +0900 | [diff] [blame] | 1060 | /* P9_HDRSZ + 4 is the smallest packet header we can have that is |
| 1061 | * followed by data accessed from userspace by read |
| 1062 | */ |
| 1063 | clnt->fcall_cache = |
| 1064 | kmem_cache_create_usercopy("9p-fcall-cache", clnt->msize, |
| 1065 | 0, 0, P9_HDRSZ + 4, |
| 1066 | clnt->msize - (P9_HDRSZ + 4), |
| 1067 | NULL); |
| 1068 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1069 | return clnt; |
| 1070 | |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 1071 | close_trans: |
| 1072 | clnt->trans_mod->close(clnt); |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 1073 | put_trans: |
| 1074 | v9fs_put_trans(clnt->trans_mod); |
| 1075 | free_client: |
| 1076 | kfree(clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1077 | return ERR_PTR(err); |
| 1078 | } |
| 1079 | EXPORT_SYMBOL(p9_client_create); |
| 1080 | |
| 1081 | void p9_client_destroy(struct p9_client *clnt) |
| 1082 | { |
Matthew Wilcox | f28cdf0 | 2018-07-11 14:02:22 -0700 | [diff] [blame] | 1083 | struct p9_fid *fid; |
| 1084 | int id; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1085 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1086 | p9_debug(P9_DEBUG_MUX, "clnt %p\n", clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1087 | |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 1088 | if (clnt->trans_mod) |
| 1089 | clnt->trans_mod->close(clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1090 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 1091 | v9fs_put_trans(clnt->trans_mod); |
| 1092 | |
Matthew Wilcox | f28cdf0 | 2018-07-11 14:02:22 -0700 | [diff] [blame] | 1093 | idr_for_each_entry(&clnt->fids, fid, id) { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1094 | pr_info("Found fid %d not clunked\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1095 | p9_fid_destroy(fid); |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 1096 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1097 | |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 1098 | p9_tag_cleanup(clnt); |
| 1099 | |
Dominique Martinet | 91a76be | 2018-07-30 15:14:37 +0900 | [diff] [blame] | 1100 | kmem_cache_destroy(clnt->fcall_cache); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1101 | kfree(clnt); |
| 1102 | } |
| 1103 | EXPORT_SYMBOL(p9_client_destroy); |
| 1104 | |
| 1105 | void p9_client_disconnect(struct p9_client *clnt) |
| 1106 | { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1107 | p9_debug(P9_DEBUG_9P, "clnt %p\n", clnt); |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 1108 | clnt->status = Disconnected; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1109 | } |
| 1110 | EXPORT_SYMBOL(p9_client_disconnect); |
| 1111 | |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 1112 | void p9_client_begin_disconnect(struct p9_client *clnt) |
| 1113 | { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1114 | p9_debug(P9_DEBUG_9P, "clnt %p\n", clnt); |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 1115 | clnt->status = BeginDisconnect; |
| 1116 | } |
| 1117 | EXPORT_SYMBOL(p9_client_begin_disconnect); |
| 1118 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1119 | struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1120 | const char *uname, kuid_t n_uname, |
| 1121 | const char *aname) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1122 | { |
Aneesh Kumar K.V | 348b590 | 2011-08-07 00:46:59 +0530 | [diff] [blame] | 1123 | int err = 0; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1124 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1125 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1126 | struct p9_qid qid; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1127 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1128 | p9_debug(P9_DEBUG_9P, ">>> TATTACH afid %d uname %s aname %s\n", |
| 1129 | afid ? afid->fid : -1, uname, aname); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1130 | fid = p9_fid_create(clnt); |
Matthew Wilcox | b5303be | 2018-07-11 14:02:21 -0700 | [diff] [blame] | 1131 | if (!fid) { |
| 1132 | err = -ENOMEM; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1133 | goto error; |
| 1134 | } |
Al Viro | 21c9f5c | 2015-04-02 21:47:49 -0400 | [diff] [blame] | 1135 | fid->uid = n_uname; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1136 | |
Eric W. Biederman | f791f7c | 2013-01-29 16:09:41 -0800 | [diff] [blame] | 1137 | req = p9_client_rpc(clnt, P9_TATTACH, "ddss?u", fid->fid, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1138 | afid ? afid->fid : P9_NOFID, uname, aname, n_uname); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1139 | if (IS_ERR(req)) { |
| 1140 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1141 | goto error; |
| 1142 | } |
| 1143 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1144 | err = p9pdu_readf(&req->rc, clnt->proto_version, "Q", &qid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1145 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1146 | trace_9p_protocol_dump(clnt, &req->rc); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1147 | p9_tag_remove(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1148 | goto error; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1149 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1150 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1151 | p9_debug(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1152 | qid.type, qid.path, qid.version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1153 | |
| 1154 | memmove(&fid->qid, &qid, sizeof(struct p9_qid)); |
| 1155 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1156 | p9_tag_remove(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1157 | return fid; |
| 1158 | |
| 1159 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1160 | if (fid) |
| 1161 | p9_fid_destroy(fid); |
| 1162 | return ERR_PTR(err); |
| 1163 | } |
| 1164 | EXPORT_SYMBOL(p9_client_attach); |
| 1165 | |
Harsh Prateek Bora | b76225e | 2011-03-31 15:49:39 +0530 | [diff] [blame] | 1166 | struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1167 | const unsigned char * const *wnames, int clone) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1168 | { |
| 1169 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1170 | struct p9_client *clnt; |
| 1171 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1172 | struct p9_qid *wqids; |
| 1173 | struct p9_req_t *req; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1174 | u16 nwqids, count; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1175 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1176 | err = 0; |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1177 | wqids = NULL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1178 | clnt = oldfid->clnt; |
| 1179 | if (clone) { |
| 1180 | fid = p9_fid_create(clnt); |
Matthew Wilcox | b5303be | 2018-07-11 14:02:21 -0700 | [diff] [blame] | 1181 | if (!fid) { |
| 1182 | err = -ENOMEM; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1183 | goto error; |
| 1184 | } |
| 1185 | |
| 1186 | fid->uid = oldfid->uid; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1187 | } else { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1188 | fid = oldfid; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1189 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1190 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1191 | p9_debug(P9_DEBUG_9P, ">>> TWALK fids %d,%d nwname %ud wname[0] %s\n", |
| 1192 | oldfid->fid, fid->fid, nwname, wnames ? wnames[0] : NULL); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1193 | req = p9_client_rpc(clnt, P9_TWALK, "ddT", oldfid->fid, fid->fid, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1194 | nwname, wnames); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1195 | if (IS_ERR(req)) { |
| 1196 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1197 | goto error; |
| 1198 | } |
| 1199 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1200 | err = p9pdu_readf(&req->rc, clnt->proto_version, "R", &nwqids, &wqids); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1201 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1202 | trace_9p_protocol_dump(clnt, &req->rc); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1203 | p9_tag_remove(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1204 | goto clunk_fid; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1205 | } |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1206 | p9_tag_remove(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1207 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1208 | p9_debug(P9_DEBUG_9P, "<<< RWALK nwqid %d:\n", nwqids); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1209 | |
| 1210 | if (nwqids != nwname) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1211 | err = -ENOENT; |
| 1212 | goto clunk_fid; |
| 1213 | } |
| 1214 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1215 | for (count = 0; count < nwqids; count++) |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1216 | p9_debug(P9_DEBUG_9P, "<<< [%d] %x.%llx.%x\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1217 | count, wqids[count].type, |
| 1218 | wqids[count].path, |
| 1219 | wqids[count].version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1220 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1221 | if (nwname) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1222 | memmove(&fid->qid, &wqids[nwqids - 1], sizeof(struct p9_qid)); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1223 | else |
Eric Van Hensbergen | 154372e | 2020-09-23 22:11:43 +0800 | [diff] [blame] | 1224 | memmove(&fid->qid, &oldfid->qid, sizeof(struct p9_qid)); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1225 | |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1226 | kfree(wqids); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1227 | return fid; |
| 1228 | |
| 1229 | clunk_fid: |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1230 | kfree(wqids); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1231 | p9_client_clunk(fid); |
| 1232 | fid = NULL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1233 | |
| 1234 | error: |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1235 | if (fid && fid != oldfid) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1236 | p9_fid_destroy(fid); |
| 1237 | |
| 1238 | return ERR_PTR(err); |
| 1239 | } |
| 1240 | EXPORT_SYMBOL(p9_client_walk); |
| 1241 | |
| 1242 | int p9_client_open(struct p9_fid *fid, int mode) |
| 1243 | { |
| 1244 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1245 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1246 | struct p9_req_t *req; |
| 1247 | struct p9_qid qid; |
| 1248 | int iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1249 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1250 | clnt = fid->clnt; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1251 | p9_debug(P9_DEBUG_9P, ">>> %s fid %d mode %d\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1252 | p9_is_proto_dotl(clnt) ? "TLOPEN" : "TOPEN", fid->fid, mode); |
M. Mohan Kumar | ef56547 | 2010-06-22 19:47:50 +0530 | [diff] [blame] | 1253 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1254 | |
| 1255 | if (fid->mode != -1) |
| 1256 | return -EINVAL; |
| 1257 | |
M. Mohan Kumar | ef56547 | 2010-06-22 19:47:50 +0530 | [diff] [blame] | 1258 | if (p9_is_proto_dotl(clnt)) |
| 1259 | req = p9_client_rpc(clnt, P9_TLOPEN, "dd", fid->fid, mode); |
| 1260 | else |
| 1261 | req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1262 | if (IS_ERR(req)) { |
| 1263 | err = PTR_ERR(req); |
| 1264 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1265 | } |
| 1266 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1267 | err = p9pdu_readf(&req->rc, clnt->proto_version, "Qd", &qid, &iounit); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1268 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1269 | trace_9p_protocol_dump(clnt, &req->rc); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1270 | goto free_and_error; |
| 1271 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1272 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1273 | p9_debug(P9_DEBUG_9P, "<<< %s qid %x.%llx.%x iounit %x\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1274 | p9_is_proto_dotl(clnt) ? "RLOPEN" : "ROPEN", qid.type, |
| 1275 | qid.path, qid.version, iounit); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1276 | |
Eric Van Hensbergen | 154372e | 2020-09-23 22:11:43 +0800 | [diff] [blame] | 1277 | memmove(&fid->qid, &qid, sizeof(struct p9_qid)); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1278 | fid->mode = mode; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1279 | fid->iounit = iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1280 | |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1281 | free_and_error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1282 | p9_tag_remove(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1283 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1284 | return err; |
| 1285 | } |
| 1286 | EXPORT_SYMBOL(p9_client_open); |
| 1287 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1288 | int p9_client_create_dotl(struct p9_fid *ofid, const char *name, u32 flags, |
| 1289 | u32 mode, kgid_t gid, struct p9_qid *qid) |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1290 | { |
| 1291 | int err = 0; |
| 1292 | struct p9_client *clnt; |
| 1293 | struct p9_req_t *req; |
| 1294 | int iounit; |
| 1295 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1296 | p9_debug(P9_DEBUG_9P, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1297 | ">>> TLCREATE fid %d name %s flags %d mode %d gid %d\n", |
| 1298 | ofid->fid, name, flags, mode, |
| 1299 | from_kgid(&init_user_ns, gid)); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1300 | clnt = ofid->clnt; |
| 1301 | |
| 1302 | if (ofid->mode != -1) |
| 1303 | return -EINVAL; |
| 1304 | |
Eric W. Biederman | f791f7c | 2013-01-29 16:09:41 -0800 | [diff] [blame] | 1305 | req = p9_client_rpc(clnt, P9_TLCREATE, "dsddg", ofid->fid, name, flags, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1306 | mode, gid); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1307 | if (IS_ERR(req)) { |
| 1308 | err = PTR_ERR(req); |
| 1309 | goto error; |
| 1310 | } |
| 1311 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1312 | err = p9pdu_readf(&req->rc, clnt->proto_version, "Qd", qid, &iounit); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1313 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1314 | trace_9p_protocol_dump(clnt, &req->rc); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1315 | goto free_and_error; |
| 1316 | } |
| 1317 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1318 | p9_debug(P9_DEBUG_9P, "<<< RLCREATE qid %x.%llx.%x iounit %x\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1319 | qid->type, qid->path, qid->version, iounit); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1320 | |
Eric Van Hensbergen | 154372e | 2020-09-23 22:11:43 +0800 | [diff] [blame] | 1321 | memmove(&ofid->qid, qid, sizeof(struct p9_qid)); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1322 | ofid->mode = mode; |
| 1323 | ofid->iounit = iounit; |
| 1324 | |
| 1325 | free_and_error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1326 | p9_tag_remove(clnt, req); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1327 | error: |
| 1328 | return err; |
| 1329 | } |
| 1330 | EXPORT_SYMBOL(p9_client_create_dotl); |
| 1331 | |
Al Viro | 7880b43 | 2017-01-12 04:01:17 -0500 | [diff] [blame] | 1332 | int p9_client_fcreate(struct p9_fid *fid, const char *name, u32 perm, int mode, |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1333 | char *extension) |
| 1334 | { |
| 1335 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1336 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1337 | struct p9_req_t *req; |
| 1338 | struct p9_qid qid; |
| 1339 | int iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1340 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1341 | p9_debug(P9_DEBUG_9P, ">>> TCREATE fid %d name %s perm %d mode %d\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1342 | fid->fid, name, perm, mode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1343 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1344 | clnt = fid->clnt; |
| 1345 | |
| 1346 | if (fid->mode != -1) |
| 1347 | return -EINVAL; |
| 1348 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1349 | req = p9_client_rpc(clnt, P9_TCREATE, "dsdb?s", fid->fid, name, perm, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1350 | mode, extension); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1351 | if (IS_ERR(req)) { |
| 1352 | err = PTR_ERR(req); |
| 1353 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1354 | } |
| 1355 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1356 | err = p9pdu_readf(&req->rc, clnt->proto_version, "Qd", &qid, &iounit); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1357 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1358 | trace_9p_protocol_dump(clnt, &req->rc); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1359 | goto free_and_error; |
| 1360 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1361 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1362 | p9_debug(P9_DEBUG_9P, "<<< RCREATE qid %x.%llx.%x iounit %x\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1363 | qid.type, qid.path, qid.version, iounit); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1364 | |
Eric Van Hensbergen | 154372e | 2020-09-23 22:11:43 +0800 | [diff] [blame] | 1365 | memmove(&fid->qid, &qid, sizeof(struct p9_qid)); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1366 | fid->mode = mode; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1367 | fid->iounit = iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1368 | |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1369 | free_and_error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1370 | p9_tag_remove(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1371 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1372 | return err; |
| 1373 | } |
| 1374 | EXPORT_SYMBOL(p9_client_fcreate); |
| 1375 | |
Al Viro | 7880b43 | 2017-01-12 04:01:17 -0500 | [diff] [blame] | 1376 | int p9_client_symlink(struct p9_fid *dfid, const char *name, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1377 | const char *symtgt, kgid_t gid, struct p9_qid *qid) |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1378 | { |
| 1379 | int err = 0; |
| 1380 | struct p9_client *clnt; |
| 1381 | struct p9_req_t *req; |
| 1382 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1383 | p9_debug(P9_DEBUG_9P, ">>> TSYMLINK dfid %d name %s symtgt %s\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1384 | dfid->fid, name, symtgt); |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1385 | clnt = dfid->clnt; |
| 1386 | |
Eric W. Biederman | f791f7c | 2013-01-29 16:09:41 -0800 | [diff] [blame] | 1387 | req = p9_client_rpc(clnt, P9_TSYMLINK, "dssg", dfid->fid, name, symtgt, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1388 | gid); |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1389 | if (IS_ERR(req)) { |
| 1390 | err = PTR_ERR(req); |
| 1391 | goto error; |
| 1392 | } |
| 1393 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1394 | err = p9pdu_readf(&req->rc, clnt->proto_version, "Q", qid); |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1395 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1396 | trace_9p_protocol_dump(clnt, &req->rc); |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1397 | goto free_and_error; |
| 1398 | } |
| 1399 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1400 | p9_debug(P9_DEBUG_9P, "<<< RSYMLINK qid %x.%llx.%x\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1401 | qid->type, qid->path, qid->version); |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1402 | |
| 1403 | free_and_error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1404 | p9_tag_remove(clnt, req); |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1405 | error: |
| 1406 | return err; |
| 1407 | } |
| 1408 | EXPORT_SYMBOL(p9_client_symlink); |
| 1409 | |
Al Viro | 7880b43 | 2017-01-12 04:01:17 -0500 | [diff] [blame] | 1410 | int p9_client_link(struct p9_fid *dfid, struct p9_fid *oldfid, const char *newname) |
Venkateswararao Jujjuri (JV) | 652df9a | 2010-06-03 15:16:59 -0700 | [diff] [blame] | 1411 | { |
| 1412 | struct p9_client *clnt; |
| 1413 | struct p9_req_t *req; |
| 1414 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1415 | p9_debug(P9_DEBUG_9P, ">>> TLINK dfid %d oldfid %d newname %s\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1416 | dfid->fid, oldfid->fid, newname); |
Venkateswararao Jujjuri (JV) | 652df9a | 2010-06-03 15:16:59 -0700 | [diff] [blame] | 1417 | clnt = dfid->clnt; |
| 1418 | req = p9_client_rpc(clnt, P9_TLINK, "dds", dfid->fid, oldfid->fid, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1419 | newname); |
Venkateswararao Jujjuri (JV) | 652df9a | 2010-06-03 15:16:59 -0700 | [diff] [blame] | 1420 | if (IS_ERR(req)) |
| 1421 | return PTR_ERR(req); |
| 1422 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1423 | p9_debug(P9_DEBUG_9P, "<<< RLINK\n"); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1424 | p9_tag_remove(clnt, req); |
Venkateswararao Jujjuri (JV) | 652df9a | 2010-06-03 15:16:59 -0700 | [diff] [blame] | 1425 | return 0; |
| 1426 | } |
| 1427 | EXPORT_SYMBOL(p9_client_link); |
| 1428 | |
Venkateswararao Jujjuri (JV) | b165d60 | 2010-10-22 10:13:12 -0700 | [diff] [blame] | 1429 | int p9_client_fsync(struct p9_fid *fid, int datasync) |
Venkateswararao Jujjuri (JV) | 920e65d | 2010-09-22 17:19:19 -0700 | [diff] [blame] | 1430 | { |
| 1431 | int err; |
| 1432 | struct p9_client *clnt; |
| 1433 | struct p9_req_t *req; |
| 1434 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1435 | p9_debug(P9_DEBUG_9P, ">>> TFSYNC fid %d datasync:%d\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1436 | fid->fid, datasync); |
Venkateswararao Jujjuri (JV) | 920e65d | 2010-09-22 17:19:19 -0700 | [diff] [blame] | 1437 | err = 0; |
| 1438 | clnt = fid->clnt; |
| 1439 | |
Venkateswararao Jujjuri (JV) | b165d60 | 2010-10-22 10:13:12 -0700 | [diff] [blame] | 1440 | req = p9_client_rpc(clnt, P9_TFSYNC, "dd", fid->fid, datasync); |
Venkateswararao Jujjuri (JV) | 920e65d | 2010-09-22 17:19:19 -0700 | [diff] [blame] | 1441 | if (IS_ERR(req)) { |
| 1442 | err = PTR_ERR(req); |
| 1443 | goto error; |
| 1444 | } |
| 1445 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1446 | p9_debug(P9_DEBUG_9P, "<<< RFSYNC fid %d\n", fid->fid); |
Venkateswararao Jujjuri (JV) | 920e65d | 2010-09-22 17:19:19 -0700 | [diff] [blame] | 1447 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1448 | p9_tag_remove(clnt, req); |
Venkateswararao Jujjuri (JV) | 920e65d | 2010-09-22 17:19:19 -0700 | [diff] [blame] | 1449 | |
| 1450 | error: |
| 1451 | return err; |
| 1452 | } |
| 1453 | EXPORT_SYMBOL(p9_client_fsync); |
| 1454 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1455 | int p9_client_clunk(struct p9_fid *fid) |
| 1456 | { |
| 1457 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1458 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1459 | struct p9_req_t *req; |
Jim Garlick | 208f3c2 | 2012-02-26 14:49:57 -0600 | [diff] [blame] | 1460 | int retries = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1461 | |
Jianyong Wu | 6636b6d | 2020-09-23 22:11:46 +0800 | [diff] [blame] | 1462 | if (!fid || IS_ERR(fid)) { |
| 1463 | pr_warn("%s (%d): Trying to clunk with invalid fid\n", |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1464 | __func__, task_pid_nr(current)); |
jvrao | 8e44a08 | 2010-08-25 16:27:06 +0000 | [diff] [blame] | 1465 | dump_stack(); |
| 1466 | return 0; |
| 1467 | } |
Dominique Martinet | ff5e72e | 2020-11-03 09:35:57 +0100 | [diff] [blame] | 1468 | if (!refcount_dec_and_test(&fid->count)) |
Jianyong Wu | 6636b6d | 2020-09-23 22:11:46 +0800 | [diff] [blame] | 1469 | return 0; |
jvrao | 8e44a08 | 2010-08-25 16:27:06 +0000 | [diff] [blame] | 1470 | |
Jim Garlick | 208f3c2 | 2012-02-26 14:49:57 -0600 | [diff] [blame] | 1471 | again: |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1472 | p9_debug(P9_DEBUG_9P, ">>> TCLUNK fid %d (try %d)\n", |
| 1473 | fid->fid, retries); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1474 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1475 | clnt = fid->clnt; |
| 1476 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1477 | req = p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid); |
| 1478 | if (IS_ERR(req)) { |
| 1479 | err = PTR_ERR(req); |
| 1480 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1481 | } |
| 1482 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1483 | p9_debug(P9_DEBUG_9P, "<<< RCLUNK fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1484 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1485 | p9_tag_remove(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1486 | error: |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1487 | /* Fid is not valid even after a failed clunk |
Jim Garlick | 208f3c2 | 2012-02-26 14:49:57 -0600 | [diff] [blame] | 1488 | * If interrupted, retry once then give up and |
| 1489 | * leak fid until umount. |
Aneesh Kumar K.V | 5034990 | 2011-07-11 16:40:58 +0000 | [diff] [blame] | 1490 | */ |
Jim Garlick | 208f3c2 | 2012-02-26 14:49:57 -0600 | [diff] [blame] | 1491 | if (err == -ERESTARTSYS) { |
| 1492 | if (retries++ == 0) |
| 1493 | goto again; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1494 | } else { |
Jim Garlick | 208f3c2 | 2012-02-26 14:49:57 -0600 | [diff] [blame] | 1495 | p9_fid_destroy(fid); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1496 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1497 | return err; |
| 1498 | } |
| 1499 | EXPORT_SYMBOL(p9_client_clunk); |
| 1500 | |
| 1501 | int p9_client_remove(struct p9_fid *fid) |
| 1502 | { |
| 1503 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1504 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1505 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1506 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1507 | p9_debug(P9_DEBUG_9P, ">>> TREMOVE fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1508 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1509 | clnt = fid->clnt; |
| 1510 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1511 | req = p9_client_rpc(clnt, P9_TREMOVE, "d", fid->fid); |
| 1512 | if (IS_ERR(req)) { |
| 1513 | err = PTR_ERR(req); |
| 1514 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1515 | } |
| 1516 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1517 | p9_debug(P9_DEBUG_9P, "<<< RREMOVE fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1518 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1519 | p9_tag_remove(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1520 | error: |
Jim Garlick | 208f3c2 | 2012-02-26 14:49:57 -0600 | [diff] [blame] | 1521 | if (err == -ERESTARTSYS) |
| 1522 | p9_client_clunk(fid); |
| 1523 | else |
| 1524 | p9_fid_destroy(fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1525 | return err; |
| 1526 | } |
| 1527 | EXPORT_SYMBOL(p9_client_remove); |
| 1528 | |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 1529 | int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags) |
| 1530 | { |
| 1531 | int err = 0; |
| 1532 | struct p9_req_t *req; |
| 1533 | struct p9_client *clnt; |
| 1534 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1535 | p9_debug(P9_DEBUG_9P, ">>> TUNLINKAT fid %d %s %d\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1536 | dfid->fid, name, flags); |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 1537 | |
| 1538 | clnt = dfid->clnt; |
| 1539 | req = p9_client_rpc(clnt, P9_TUNLINKAT, "dsd", dfid->fid, name, flags); |
| 1540 | if (IS_ERR(req)) { |
| 1541 | err = PTR_ERR(req); |
| 1542 | goto error; |
| 1543 | } |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1544 | p9_debug(P9_DEBUG_9P, "<<< RUNLINKAT fid %d %s\n", dfid->fid, name); |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 1545 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1546 | p9_tag_remove(clnt, req); |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 1547 | error: |
| 1548 | return err; |
| 1549 | } |
| 1550 | EXPORT_SYMBOL(p9_client_unlinkat); |
| 1551 | |
Eric Van Hensbergen | 0fc9655 | 2008-10-13 20:36:17 -0500 | [diff] [blame] | 1552 | int |
Al Viro | e1200fe6 | 2015-04-01 23:42:28 -0400 | [diff] [blame] | 1553 | p9_client_read(struct p9_fid *fid, u64 offset, struct iov_iter *to, int *err) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1554 | { |
Al Viro | e1200fe6 | 2015-04-01 23:42:28 -0400 | [diff] [blame] | 1555 | int total = 0; |
Vincent Bernat | 999b8b8 | 2015-08-15 15:49:13 +0200 | [diff] [blame] | 1556 | *err = 0; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 1557 | |
Al Viro | e1200fe6 | 2015-04-01 23:42:28 -0400 | [diff] [blame] | 1558 | while (iov_iter_count(to)) { |
Sergey Alirzaev | 388f696 | 2020-02-05 23:40:53 +0300 | [diff] [blame] | 1559 | int count; |
Stephen Hemminger | c69f297d | 2018-07-24 12:29:10 -0700 | [diff] [blame] | 1560 | |
Sergey Alirzaev | 388f696 | 2020-02-05 23:40:53 +0300 | [diff] [blame] | 1561 | count = p9_client_read_once(fid, offset, to, err); |
| 1562 | if (!count || *err) |
Al Viro | e1200fe6 | 2015-04-01 23:42:28 -0400 | [diff] [blame] | 1563 | break; |
Sergey Alirzaev | 388f696 | 2020-02-05 23:40:53 +0300 | [diff] [blame] | 1564 | offset += count; |
| 1565 | total += count; |
Venkateswararao Jujjuri (JV) | bb2f8a5 | 2011-01-28 17:05:59 -0800 | [diff] [blame] | 1566 | } |
Al Viro | e1200fe6 | 2015-04-01 23:42:28 -0400 | [diff] [blame] | 1567 | return total; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1568 | } |
| 1569 | EXPORT_SYMBOL(p9_client_read); |
| 1570 | |
Eric Van Hensbergen | 0fc9655 | 2008-10-13 20:36:17 -0500 | [diff] [blame] | 1571 | int |
Sergey Alirzaev | 388f696 | 2020-02-05 23:40:53 +0300 | [diff] [blame] | 1572 | p9_client_read_once(struct p9_fid *fid, u64 offset, struct iov_iter *to, |
| 1573 | int *err) |
| 1574 | { |
| 1575 | struct p9_client *clnt = fid->clnt; |
| 1576 | struct p9_req_t *req; |
| 1577 | int count = iov_iter_count(to); |
| 1578 | int rsize, non_zc = 0; |
| 1579 | char *dataptr; |
| 1580 | |
| 1581 | *err = 0; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1582 | p9_debug(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %zu\n", |
| 1583 | fid->fid, offset, iov_iter_count(to)); |
Sergey Alirzaev | 388f696 | 2020-02-05 23:40:53 +0300 | [diff] [blame] | 1584 | |
| 1585 | rsize = fid->iounit; |
| 1586 | if (!rsize || rsize > clnt->msize - P9_IOHDRSZ) |
| 1587 | rsize = clnt->msize - P9_IOHDRSZ; |
| 1588 | |
| 1589 | if (count < rsize) |
| 1590 | rsize = count; |
| 1591 | |
| 1592 | /* Don't bother zerocopy for small IO (< 1024) */ |
| 1593 | if (clnt->trans_mod->zc_request && rsize > 1024) { |
| 1594 | /* response header len is 11 |
| 1595 | * PDU Header(7) + IO Size (4) |
| 1596 | */ |
| 1597 | req = p9_client_zc_rpc(clnt, P9_TREAD, to, NULL, rsize, |
| 1598 | 0, 11, "dqd", fid->fid, |
| 1599 | offset, rsize); |
| 1600 | } else { |
| 1601 | non_zc = 1; |
| 1602 | req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset, |
| 1603 | rsize); |
| 1604 | } |
| 1605 | if (IS_ERR(req)) { |
| 1606 | *err = PTR_ERR(req); |
| 1607 | return 0; |
| 1608 | } |
| 1609 | |
| 1610 | *err = p9pdu_readf(&req->rc, clnt->proto_version, |
| 1611 | "D", &count, &dataptr); |
| 1612 | if (*err) { |
| 1613 | trace_9p_protocol_dump(clnt, &req->rc); |
| 1614 | p9_tag_remove(clnt, req); |
| 1615 | return 0; |
| 1616 | } |
| 1617 | if (rsize < count) { |
| 1618 | pr_err("bogus RREAD count (%d > %d)\n", count, rsize); |
| 1619 | count = rsize; |
| 1620 | } |
| 1621 | |
| 1622 | p9_debug(P9_DEBUG_9P, "<<< RREAD count %d\n", count); |
Sergey Alirzaev | 388f696 | 2020-02-05 23:40:53 +0300 | [diff] [blame] | 1623 | |
| 1624 | if (non_zc) { |
| 1625 | int n = copy_to_iter(dataptr, count, to); |
| 1626 | |
| 1627 | if (n != count) { |
| 1628 | *err = -EFAULT; |
| 1629 | p9_tag_remove(clnt, req); |
| 1630 | return n; |
| 1631 | } |
| 1632 | } else { |
| 1633 | iov_iter_advance(to, count); |
| 1634 | } |
| 1635 | p9_tag_remove(clnt, req); |
| 1636 | return count; |
| 1637 | } |
| 1638 | EXPORT_SYMBOL(p9_client_read_once); |
| 1639 | |
| 1640 | int |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1641 | p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1642 | { |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1643 | struct p9_client *clnt = fid->clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1644 | struct p9_req_t *req; |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1645 | int total = 0; |
Vincent Bernat | 999b8b8 | 2015-08-15 15:49:13 +0200 | [diff] [blame] | 1646 | *err = 0; |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 1647 | |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1648 | p9_debug(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %zd\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1649 | fid->fid, offset, iov_iter_count(from)); |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1650 | |
| 1651 | while (iov_iter_count(from)) { |
| 1652 | int count = iov_iter_count(from); |
| 1653 | int rsize = fid->iounit; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1654 | |
| 1655 | if (!rsize || rsize > clnt->msize - P9_IOHDRSZ) |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1656 | rsize = clnt->msize - P9_IOHDRSZ; |
| 1657 | |
| 1658 | if (count < rsize) |
| 1659 | rsize = count; |
| 1660 | |
| 1661 | /* Don't bother zerocopy for small IO (< 1024) */ |
| 1662 | if (clnt->trans_mod->zc_request && rsize > 1024) { |
| 1663 | req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, from, 0, |
| 1664 | rsize, P9_ZC_HDR_SZ, "dqd", |
| 1665 | fid->fid, offset, rsize); |
| 1666 | } else { |
| 1667 | req = p9_client_rpc(clnt, P9_TWRITE, "dqV", fid->fid, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1668 | offset, rsize, from); |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1669 | } |
| 1670 | if (IS_ERR(req)) { |
| 1671 | *err = PTR_ERR(req); |
| 1672 | break; |
| 1673 | } |
| 1674 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1675 | *err = p9pdu_readf(&req->rc, clnt->proto_version, "d", &count); |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1676 | if (*err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1677 | trace_9p_protocol_dump(clnt, &req->rc); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1678 | p9_tag_remove(clnt, req); |
Al Viro | 67e808f | 2015-07-04 16:11:05 -0400 | [diff] [blame] | 1679 | break; |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1680 | } |
Al Viro | 0f1db7d | 2015-07-04 16:17:39 -0400 | [diff] [blame] | 1681 | if (rsize < count) { |
| 1682 | pr_err("bogus RWRITE count (%d > %d)\n", count, rsize); |
| 1683 | count = rsize; |
| 1684 | } |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1685 | |
| 1686 | p9_debug(P9_DEBUG_9P, "<<< RWRITE count %d\n", count); |
| 1687 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1688 | p9_tag_remove(clnt, req); |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1689 | iov_iter_advance(from, count); |
| 1690 | total += count; |
| 1691 | offset += count; |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 1692 | } |
Al Viro | 070b365 | 2015-04-01 20:17:51 -0400 | [diff] [blame] | 1693 | return total; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1694 | } |
| 1695 | EXPORT_SYMBOL(p9_client_write); |
| 1696 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1697 | struct p9_wstat *p9_client_stat(struct p9_fid *fid) |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1698 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1699 | int err; |
| 1700 | struct p9_client *clnt; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1701 | struct p9_wstat *ret; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1702 | struct p9_req_t *req; |
| 1703 | u16 ignored; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1704 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1705 | p9_debug(P9_DEBUG_9P, ">>> TSTAT fid %d\n", fid->fid); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1706 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1707 | ret = kmalloc(sizeof(*ret), GFP_KERNEL); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1708 | if (!ret) |
| 1709 | return ERR_PTR(-ENOMEM); |
| 1710 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1711 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1712 | clnt = fid->clnt; |
| 1713 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1714 | req = p9_client_rpc(clnt, P9_TSTAT, "d", fid->fid); |
| 1715 | if (IS_ERR(req)) { |
| 1716 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1717 | goto error; |
| 1718 | } |
| 1719 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1720 | err = p9pdu_readf(&req->rc, clnt->proto_version, "wS", &ignored, ret); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1721 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1722 | trace_9p_protocol_dump(clnt, &req->rc); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1723 | p9_tag_remove(clnt, req); |
Abhishek Kulkarni | eedfe1c | 2009-07-14 13:25:41 -0500 | [diff] [blame] | 1724 | goto error; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1725 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1726 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1727 | p9_debug(P9_DEBUG_9P, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1728 | "<<< RSTAT sz=%x type=%x dev=%x qid=%x.%llx.%x\n" |
| 1729 | "<<< mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n" |
| 1730 | "<<< name=%s uid=%s gid=%s muid=%s extension=(%s)\n" |
| 1731 | "<<< uid=%d gid=%d n_muid=%d\n", |
| 1732 | ret->size, ret->type, ret->dev, ret->qid.type, ret->qid.path, |
| 1733 | ret->qid.version, ret->mode, |
| 1734 | ret->atime, ret->mtime, ret->length, |
| 1735 | ret->name, ret->uid, ret->gid, ret->muid, ret->extension, |
| 1736 | from_kuid(&init_user_ns, ret->n_uid), |
| 1737 | from_kgid(&init_user_ns, ret->n_gid), |
| 1738 | from_kuid(&init_user_ns, ret->n_muid)); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1739 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1740 | p9_tag_remove(clnt, req); |
Latchesar Ionkov | 742b11a | 2009-04-05 16:26:41 -0500 | [diff] [blame] | 1741 | return ret; |
| 1742 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1743 | error: |
Latchesar Ionkov | 742b11a | 2009-04-05 16:26:41 -0500 | [diff] [blame] | 1744 | kfree(ret); |
| 1745 | return ERR_PTR(err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1746 | } |
| 1747 | EXPORT_SYMBOL(p9_client_stat); |
| 1748 | |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1749 | struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1750 | u64 request_mask) |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1751 | { |
| 1752 | int err; |
| 1753 | struct p9_client *clnt; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1754 | struct p9_stat_dotl *ret; |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1755 | struct p9_req_t *req; |
| 1756 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1757 | p9_debug(P9_DEBUG_9P, ">>> TGETATTR fid %d, request_mask %lld\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1758 | fid->fid, request_mask); |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1759 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1760 | ret = kmalloc(sizeof(*ret), GFP_KERNEL); |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1761 | if (!ret) |
| 1762 | return ERR_PTR(-ENOMEM); |
| 1763 | |
| 1764 | err = 0; |
| 1765 | clnt = fid->clnt; |
| 1766 | |
| 1767 | req = p9_client_rpc(clnt, P9_TGETATTR, "dq", fid->fid, request_mask); |
| 1768 | if (IS_ERR(req)) { |
| 1769 | err = PTR_ERR(req); |
| 1770 | goto error; |
| 1771 | } |
| 1772 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1773 | err = p9pdu_readf(&req->rc, clnt->proto_version, "A", ret); |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1774 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1775 | trace_9p_protocol_dump(clnt, &req->rc); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1776 | p9_tag_remove(clnt, req); |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1777 | goto error; |
| 1778 | } |
| 1779 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1780 | p9_debug(P9_DEBUG_9P, "<<< RGETATTR st_result_mask=%lld\n" |
| 1781 | "<<< qid=%x.%llx.%x\n" |
| 1782 | "<<< st_mode=%8.8x st_nlink=%llu\n" |
| 1783 | "<<< st_uid=%d st_gid=%d\n" |
| 1784 | "<<< st_rdev=%llx st_size=%llx st_blksize=%llu st_blocks=%llu\n" |
| 1785 | "<<< st_atime_sec=%lld st_atime_nsec=%lld\n" |
| 1786 | "<<< st_mtime_sec=%lld st_mtime_nsec=%lld\n" |
| 1787 | "<<< st_ctime_sec=%lld st_ctime_nsec=%lld\n" |
| 1788 | "<<< st_btime_sec=%lld st_btime_nsec=%lld\n" |
| 1789 | "<<< st_gen=%lld st_data_version=%lld\n", |
| 1790 | ret->st_result_mask, |
| 1791 | ret->qid.type, ret->qid.path, ret->qid.version, |
| 1792 | ret->st_mode, ret->st_nlink, |
| 1793 | from_kuid(&init_user_ns, ret->st_uid), |
| 1794 | from_kgid(&init_user_ns, ret->st_gid), |
| 1795 | ret->st_rdev, ret->st_size, ret->st_blksize, ret->st_blocks, |
| 1796 | ret->st_atime_sec, ret->st_atime_nsec, |
| 1797 | ret->st_mtime_sec, ret->st_mtime_nsec, |
| 1798 | ret->st_ctime_sec, ret->st_ctime_nsec, |
| 1799 | ret->st_btime_sec, ret->st_btime_nsec, |
| 1800 | ret->st_gen, ret->st_data_version); |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1801 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1802 | p9_tag_remove(clnt, req); |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1803 | return ret; |
| 1804 | |
| 1805 | error: |
| 1806 | kfree(ret); |
| 1807 | return ERR_PTR(err); |
| 1808 | } |
| 1809 | EXPORT_SYMBOL(p9_client_getattr_dotl); |
| 1810 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1811 | static int p9_client_statsize(struct p9_wstat *wst, int proto_version) |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1812 | { |
| 1813 | int ret; |
| 1814 | |
Eric Van Hensbergen | 9d6939d | 2010-01-15 19:01:56 -0600 | [diff] [blame] | 1815 | /* NOTE: size shouldn't include its own length */ |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1816 | /* size[2] type[2] dev[4] qid[13] */ |
| 1817 | /* mode[4] atime[4] mtime[4] length[8]*/ |
| 1818 | /* name[s] uid[s] gid[s] muid[s] */ |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1819 | ret = 2 + 4 + 13 + 4 + 4 + 4 + 8 + 2 + 2 + 2 + 2; |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1820 | |
| 1821 | if (wst->name) |
| 1822 | ret += strlen(wst->name); |
| 1823 | if (wst->uid) |
| 1824 | ret += strlen(wst->uid); |
| 1825 | if (wst->gid) |
| 1826 | ret += strlen(wst->gid); |
| 1827 | if (wst->muid) |
| 1828 | ret += strlen(wst->muid); |
| 1829 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1830 | if (proto_version == p9_proto_2000u || |
| 1831 | proto_version == p9_proto_2000L) { |
| 1832 | /* extension[s] n_uid[4] n_gid[4] n_muid[4] */ |
| 1833 | ret += 2 + 4 + 4 + 4; |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1834 | if (wst->extension) |
| 1835 | ret += strlen(wst->extension); |
| 1836 | } |
| 1837 | |
| 1838 | return ret; |
| 1839 | } |
| 1840 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1841 | int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst) |
| 1842 | { |
| 1843 | int err; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1844 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1845 | struct p9_client *clnt; |
| 1846 | |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1847 | err = 0; |
| 1848 | clnt = fid->clnt; |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1849 | wst->size = p9_client_statsize(wst, clnt->proto_version); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1850 | p9_debug(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", |
| 1851 | fid->fid); |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1852 | p9_debug(P9_DEBUG_9P, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1853 | " sz=%x type=%x dev=%x qid=%x.%llx.%x\n" |
| 1854 | " mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n" |
| 1855 | " name=%s uid=%s gid=%s muid=%s extension=(%s)\n" |
| 1856 | " uid=%d gid=%d n_muid=%d\n", |
| 1857 | wst->size, wst->type, wst->dev, wst->qid.type, |
| 1858 | wst->qid.path, wst->qid.version, |
| 1859 | wst->mode, wst->atime, wst->mtime, wst->length, |
| 1860 | wst->name, wst->uid, wst->gid, wst->muid, wst->extension, |
| 1861 | from_kuid(&init_user_ns, wst->n_uid), |
| 1862 | from_kgid(&init_user_ns, wst->n_gid), |
| 1863 | from_kuid(&init_user_ns, wst->n_muid)); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1864 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1865 | req = p9_client_rpc(clnt, P9_TWSTAT, "dwS", |
| 1866 | fid->fid, wst->size + 2, wst); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1867 | if (IS_ERR(req)) { |
| 1868 | err = PTR_ERR(req); |
| 1869 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1870 | } |
| 1871 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1872 | p9_debug(P9_DEBUG_9P, "<<< RWSTAT fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1873 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1874 | p9_tag_remove(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1875 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1876 | return err; |
| 1877 | } |
| 1878 | EXPORT_SYMBOL(p9_client_wstat); |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1879 | |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1880 | int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *p9attr) |
| 1881 | { |
| 1882 | int err; |
| 1883 | struct p9_req_t *req; |
| 1884 | struct p9_client *clnt; |
| 1885 | |
| 1886 | err = 0; |
| 1887 | clnt = fid->clnt; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1888 | p9_debug(P9_DEBUG_9P, ">>> TSETATTR fid %d\n", fid->fid); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1889 | p9_debug(P9_DEBUG_9P, " valid=%x mode=%x uid=%d gid=%d size=%lld\n", |
| 1890 | p9attr->valid, p9attr->mode, |
| 1891 | from_kuid(&init_user_ns, p9attr->uid), |
| 1892 | from_kgid(&init_user_ns, p9attr->gid), |
| 1893 | p9attr->size); |
| 1894 | p9_debug(P9_DEBUG_9P, " atime_sec=%lld atime_nsec=%lld\n", |
| 1895 | p9attr->atime_sec, p9attr->atime_nsec); |
| 1896 | p9_debug(P9_DEBUG_9P, " mtime_sec=%lld mtime_nsec=%lld\n", |
| 1897 | p9attr->mtime_sec, p9attr->mtime_nsec); |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1898 | |
| 1899 | req = p9_client_rpc(clnt, P9_TSETATTR, "dI", fid->fid, p9attr); |
| 1900 | |
| 1901 | if (IS_ERR(req)) { |
| 1902 | err = PTR_ERR(req); |
| 1903 | goto error; |
| 1904 | } |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1905 | p9_debug(P9_DEBUG_9P, "<<< RSETATTR fid %d\n", fid->fid); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1906 | p9_tag_remove(clnt, req); |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1907 | error: |
| 1908 | return err; |
| 1909 | } |
| 1910 | EXPORT_SYMBOL(p9_client_setattr); |
| 1911 | |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1912 | int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb) |
| 1913 | { |
| 1914 | int err; |
| 1915 | struct p9_req_t *req; |
| 1916 | struct p9_client *clnt; |
| 1917 | |
| 1918 | err = 0; |
| 1919 | clnt = fid->clnt; |
| 1920 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1921 | p9_debug(P9_DEBUG_9P, ">>> TSTATFS fid %d\n", fid->fid); |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1922 | |
| 1923 | req = p9_client_rpc(clnt, P9_TSTATFS, "d", fid->fid); |
| 1924 | if (IS_ERR(req)) { |
| 1925 | err = PTR_ERR(req); |
| 1926 | goto error; |
| 1927 | } |
| 1928 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1929 | err = p9pdu_readf(&req->rc, clnt->proto_version, "ddqqqqqqd", &sb->type, |
| 1930 | &sb->bsize, &sb->blocks, &sb->bfree, &sb->bavail, |
| 1931 | &sb->files, &sb->ffree, &sb->fsid, &sb->namelen); |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1932 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 1933 | trace_9p_protocol_dump(clnt, &req->rc); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1934 | p9_tag_remove(clnt, req); |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1935 | goto error; |
| 1936 | } |
| 1937 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1938 | p9_debug(P9_DEBUG_9P, |
| 1939 | "<<< RSTATFS fid %d type 0x%x bsize %u blocks %llu bfree %llu bavail %llu files %llu ffree %llu fsid %llu namelen %u\n", |
| 1940 | fid->fid, sb->type, sb->bsize, sb->blocks, sb->bfree, |
| 1941 | sb->bavail, sb->files, sb->ffree, sb->fsid, sb->namelen); |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1942 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1943 | p9_tag_remove(clnt, req); |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1944 | error: |
| 1945 | return err; |
| 1946 | } |
| 1947 | EXPORT_SYMBOL(p9_client_statfs); |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1948 | |
Aneesh Kumar K.V | 9e8fb38 | 2011-06-28 15:41:16 +0530 | [diff] [blame] | 1949 | int p9_client_rename(struct p9_fid *fid, |
| 1950 | struct p9_fid *newdirfid, const char *name) |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1951 | { |
| 1952 | int err; |
| 1953 | struct p9_req_t *req; |
| 1954 | struct p9_client *clnt; |
| 1955 | |
| 1956 | err = 0; |
| 1957 | clnt = fid->clnt; |
| 1958 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1959 | p9_debug(P9_DEBUG_9P, ">>> TRENAME fid %d newdirfid %d name %s\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1960 | fid->fid, newdirfid->fid, name); |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1961 | |
| 1962 | req = p9_client_rpc(clnt, P9_TRENAME, "dds", fid->fid, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1963 | newdirfid->fid, name); |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1964 | if (IS_ERR(req)) { |
| 1965 | err = PTR_ERR(req); |
| 1966 | goto error; |
| 1967 | } |
| 1968 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1969 | p9_debug(P9_DEBUG_9P, "<<< RRENAME fid %d\n", fid->fid); |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1970 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 1971 | p9_tag_remove(clnt, req); |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1972 | error: |
| 1973 | return err; |
| 1974 | } |
| 1975 | EXPORT_SYMBOL(p9_client_rename); |
| 1976 | |
Aneesh Kumar K.V | 9e8fb38 | 2011-06-28 15:41:16 +0530 | [diff] [blame] | 1977 | int p9_client_renameat(struct p9_fid *olddirfid, const char *old_name, |
| 1978 | struct p9_fid *newdirfid, const char *new_name) |
| 1979 | { |
| 1980 | int err; |
| 1981 | struct p9_req_t *req; |
| 1982 | struct p9_client *clnt; |
| 1983 | |
| 1984 | err = 0; |
| 1985 | clnt = olddirfid->clnt; |
| 1986 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1987 | p9_debug(P9_DEBUG_9P, |
| 1988 | ">>> TRENAMEAT olddirfid %d old name %s newdirfid %d new name %s\n", |
| 1989 | olddirfid->fid, old_name, newdirfid->fid, new_name); |
Aneesh Kumar K.V | 9e8fb38 | 2011-06-28 15:41:16 +0530 | [diff] [blame] | 1990 | |
| 1991 | req = p9_client_rpc(clnt, P9_TRENAMEAT, "dsds", olddirfid->fid, |
| 1992 | old_name, newdirfid->fid, new_name); |
| 1993 | if (IS_ERR(req)) { |
| 1994 | err = PTR_ERR(req); |
| 1995 | goto error; |
| 1996 | } |
| 1997 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 1998 | p9_debug(P9_DEBUG_9P, "<<< RRENAMEAT newdirfid %d new name %s\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 1999 | newdirfid->fid, new_name); |
Aneesh Kumar K.V | 9e8fb38 | 2011-06-28 15:41:16 +0530 | [diff] [blame] | 2000 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2001 | p9_tag_remove(clnt, req); |
Aneesh Kumar K.V | 9e8fb38 | 2011-06-28 15:41:16 +0530 | [diff] [blame] | 2002 | error: |
| 2003 | return err; |
| 2004 | } |
| 2005 | EXPORT_SYMBOL(p9_client_renameat); |
| 2006 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2007 | /* An xattrwalk without @attr_name gives the fid for the lisxattr namespace |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 2008 | */ |
| 2009 | struct p9_fid *p9_client_xattrwalk(struct p9_fid *file_fid, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2010 | const char *attr_name, u64 *attr_size) |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 2011 | { |
| 2012 | int err; |
| 2013 | struct p9_req_t *req; |
| 2014 | struct p9_client *clnt; |
| 2015 | struct p9_fid *attr_fid; |
| 2016 | |
| 2017 | err = 0; |
| 2018 | clnt = file_fid->clnt; |
| 2019 | attr_fid = p9_fid_create(clnt); |
Matthew Wilcox | b5303be | 2018-07-11 14:02:21 -0700 | [diff] [blame] | 2020 | if (!attr_fid) { |
| 2021 | err = -ENOMEM; |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 2022 | goto error; |
| 2023 | } |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2024 | p9_debug(P9_DEBUG_9P, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2025 | ">>> TXATTRWALK file_fid %d, attr_fid %d name %s\n", |
| 2026 | file_fid->fid, attr_fid->fid, attr_name); |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 2027 | |
| 2028 | req = p9_client_rpc(clnt, P9_TXATTRWALK, "dds", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2029 | file_fid->fid, attr_fid->fid, attr_name); |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 2030 | if (IS_ERR(req)) { |
| 2031 | err = PTR_ERR(req); |
| 2032 | goto error; |
| 2033 | } |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2034 | err = p9pdu_readf(&req->rc, clnt->proto_version, "q", attr_size); |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 2035 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2036 | trace_9p_protocol_dump(clnt, &req->rc); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2037 | p9_tag_remove(clnt, req); |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 2038 | goto clunk_fid; |
| 2039 | } |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2040 | p9_tag_remove(clnt, req); |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2041 | p9_debug(P9_DEBUG_9P, "<<< RXATTRWALK fid %d size %llu\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2042 | attr_fid->fid, *attr_size); |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 2043 | return attr_fid; |
| 2044 | clunk_fid: |
| 2045 | p9_client_clunk(attr_fid); |
| 2046 | attr_fid = NULL; |
| 2047 | error: |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2048 | if (attr_fid && attr_fid != file_fid) |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 2049 | p9_fid_destroy(attr_fid); |
| 2050 | |
| 2051 | return ERR_PTR(err); |
| 2052 | } |
| 2053 | EXPORT_SYMBOL_GPL(p9_client_xattrwalk); |
| 2054 | |
Aneesh Kumar K.V | eda25e46 | 2010-05-31 13:22:50 +0530 | [diff] [blame] | 2055 | int p9_client_xattrcreate(struct p9_fid *fid, const char *name, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2056 | u64 attr_size, int flags) |
Aneesh Kumar K.V | eda25e46 | 2010-05-31 13:22:50 +0530 | [diff] [blame] | 2057 | { |
| 2058 | int err; |
| 2059 | struct p9_req_t *req; |
| 2060 | struct p9_client *clnt; |
| 2061 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2062 | p9_debug(P9_DEBUG_9P, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2063 | ">>> TXATTRCREATE fid %d name %s size %llu flag %d\n", |
| 2064 | fid->fid, name, attr_size, flags); |
Aneesh Kumar K.V | eda25e46 | 2010-05-31 13:22:50 +0530 | [diff] [blame] | 2065 | err = 0; |
| 2066 | clnt = fid->clnt; |
| 2067 | req = p9_client_rpc(clnt, P9_TXATTRCREATE, "dsqd", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2068 | fid->fid, name, attr_size, flags); |
Aneesh Kumar K.V | eda25e46 | 2010-05-31 13:22:50 +0530 | [diff] [blame] | 2069 | if (IS_ERR(req)) { |
| 2070 | err = PTR_ERR(req); |
| 2071 | goto error; |
| 2072 | } |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2073 | p9_debug(P9_DEBUG_9P, "<<< RXATTRCREATE fid %d\n", fid->fid); |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2074 | p9_tag_remove(clnt, req); |
Aneesh Kumar K.V | eda25e46 | 2010-05-31 13:22:50 +0530 | [diff] [blame] | 2075 | error: |
| 2076 | return err; |
| 2077 | } |
| 2078 | EXPORT_SYMBOL_GPL(p9_client_xattrcreate); |
| 2079 | |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2080 | int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset) |
| 2081 | { |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 2082 | int err, rsize, non_zc = 0; |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2083 | struct p9_client *clnt; |
| 2084 | struct p9_req_t *req; |
| 2085 | char *dataptr; |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 2086 | struct kvec kv = {.iov_base = data, .iov_len = count}; |
| 2087 | struct iov_iter to; |
| 2088 | |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 2089 | iov_iter_kvec(&to, READ, &kv, 1, count); |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2090 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2091 | p9_debug(P9_DEBUG_9P, ">>> TREADDIR fid %d offset %llu count %d\n", |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2092 | fid->fid, offset, count); |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2093 | |
| 2094 | err = 0; |
| 2095 | clnt = fid->clnt; |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2096 | |
| 2097 | rsize = fid->iounit; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2098 | if (!rsize || rsize > clnt->msize - P9_READDIRHDRSZ) |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2099 | rsize = clnt->msize - P9_READDIRHDRSZ; |
| 2100 | |
| 2101 | if (count < rsize) |
| 2102 | rsize = count; |
| 2103 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 2104 | /* Don't bother zerocopy for small IO (< 1024) */ |
| 2105 | if (clnt->trans_mod->zc_request && rsize > 1024) { |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2106 | /* response header len is 11 |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 2107 | * PDU Header(7) + IO Size (4) |
| 2108 | */ |
Al Viro | 4f3b35c | 2015-04-01 19:57:53 -0400 | [diff] [blame] | 2109 | req = p9_client_zc_rpc(clnt, P9_TREADDIR, &to, NULL, rsize, 0, |
| 2110 | 11, "dqd", fid->fid, offset, rsize); |
Venkateswararao Jujjuri (JV) | 2c66523 | 2011-02-16 18:43:20 -0800 | [diff] [blame] | 2111 | } else { |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 2112 | non_zc = 1; |
Venkateswararao Jujjuri (JV) | 2c66523 | 2011-02-16 18:43:20 -0800 | [diff] [blame] | 2113 | req = p9_client_rpc(clnt, P9_TREADDIR, "dqd", fid->fid, |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 2114 | offset, rsize); |
Venkateswararao Jujjuri (JV) | 2c66523 | 2011-02-16 18:43:20 -0800 | [diff] [blame] | 2115 | } |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2116 | if (IS_ERR(req)) { |
| 2117 | err = PTR_ERR(req); |
| 2118 | goto error; |
| 2119 | } |
| 2120 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2121 | err = p9pdu_readf(&req->rc, clnt->proto_version, "D", &count, &dataptr); |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2122 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2123 | trace_9p_protocol_dump(clnt, &req->rc); |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2124 | goto free_and_error; |
| 2125 | } |
Al Viro | 71d6ad0 | 2017-04-14 17:22:18 -0400 | [diff] [blame] | 2126 | if (rsize < count) { |
| 2127 | pr_err("bogus RREADDIR count (%d > %d)\n", count, rsize); |
| 2128 | count = rsize; |
| 2129 | } |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2130 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2131 | p9_debug(P9_DEBUG_9P, "<<< RREADDIR count %d\n", count); |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2132 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 2133 | if (non_zc) |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2134 | memmove(data, dataptr, count); |
| 2135 | |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2136 | p9_tag_remove(clnt, req); |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2137 | return count; |
| 2138 | |
| 2139 | free_and_error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2140 | p9_tag_remove(clnt, req); |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2141 | error: |
| 2142 | return err; |
| 2143 | } |
| 2144 | EXPORT_SYMBOL(p9_client_readdir); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2145 | |
Al Viro | 7880b43 | 2017-01-12 04:01:17 -0500 | [diff] [blame] | 2146 | int p9_client_mknod_dotl(struct p9_fid *fid, const char *name, int mode, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2147 | dev_t rdev, kgid_t gid, struct p9_qid *qid) |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2148 | { |
| 2149 | int err; |
| 2150 | struct p9_client *clnt; |
| 2151 | struct p9_req_t *req; |
| 2152 | |
| 2153 | err = 0; |
| 2154 | clnt = fid->clnt; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2155 | p9_debug(P9_DEBUG_9P, |
| 2156 | ">>> TMKNOD fid %d name %s mode %d major %d minor %d\n", |
| 2157 | fid->fid, name, mode, MAJOR(rdev), MINOR(rdev)); |
Eric W. Biederman | f791f7c | 2013-01-29 16:09:41 -0800 | [diff] [blame] | 2158 | req = p9_client_rpc(clnt, P9_TMKNOD, "dsdddg", fid->fid, name, mode, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2159 | MAJOR(rdev), MINOR(rdev), gid); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2160 | if (IS_ERR(req)) |
| 2161 | return PTR_ERR(req); |
| 2162 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2163 | err = p9pdu_readf(&req->rc, clnt->proto_version, "Q", qid); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2164 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2165 | trace_9p_protocol_dump(clnt, &req->rc); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2166 | goto error; |
| 2167 | } |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2168 | p9_debug(P9_DEBUG_9P, "<<< RMKNOD qid %x.%llx.%x\n", |
| 2169 | qid->type, qid->path, qid->version); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2170 | |
| 2171 | error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2172 | p9_tag_remove(clnt, req); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2173 | return err; |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2174 | } |
| 2175 | EXPORT_SYMBOL(p9_client_mknod_dotl); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2176 | |
Al Viro | 7880b43 | 2017-01-12 04:01:17 -0500 | [diff] [blame] | 2177 | int p9_client_mkdir_dotl(struct p9_fid *fid, const char *name, int mode, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2178 | kgid_t gid, struct p9_qid *qid) |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2179 | { |
| 2180 | int err; |
| 2181 | struct p9_client *clnt; |
| 2182 | struct p9_req_t *req; |
| 2183 | |
| 2184 | err = 0; |
| 2185 | clnt = fid->clnt; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2186 | p9_debug(P9_DEBUG_9P, ">>> TMKDIR fid %d name %s mode %d gid %d\n", |
Eric W. Biederman | f791f7c | 2013-01-29 16:09:41 -0800 | [diff] [blame] | 2187 | fid->fid, name, mode, from_kgid(&init_user_ns, gid)); |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2188 | req = p9_client_rpc(clnt, P9_TMKDIR, "dsdg", |
| 2189 | fid->fid, name, mode, gid); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2190 | if (IS_ERR(req)) |
| 2191 | return PTR_ERR(req); |
| 2192 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2193 | err = p9pdu_readf(&req->rc, clnt->proto_version, "Q", qid); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2194 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2195 | trace_9p_protocol_dump(clnt, &req->rc); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2196 | goto error; |
| 2197 | } |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2198 | p9_debug(P9_DEBUG_9P, "<<< RMKDIR qid %x.%llx.%x\n", qid->type, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2199 | qid->path, qid->version); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2200 | |
| 2201 | error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2202 | p9_tag_remove(clnt, req); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2203 | return err; |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2204 | } |
| 2205 | EXPORT_SYMBOL(p9_client_mkdir_dotl); |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2206 | |
| 2207 | int p9_client_lock_dotl(struct p9_fid *fid, struct p9_flock *flock, u8 *status) |
| 2208 | { |
| 2209 | int err; |
| 2210 | struct p9_client *clnt; |
| 2211 | struct p9_req_t *req; |
| 2212 | |
| 2213 | err = 0; |
| 2214 | clnt = fid->clnt; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2215 | p9_debug(P9_DEBUG_9P, |
| 2216 | ">>> TLOCK fid %d type %i flags %d start %lld length %lld proc_id %d client_id %s\n", |
| 2217 | fid->fid, flock->type, flock->flags, flock->start, |
| 2218 | flock->length, flock->proc_id, flock->client_id); |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2219 | |
| 2220 | req = p9_client_rpc(clnt, P9_TLOCK, "dbdqqds", fid->fid, flock->type, |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2221 | flock->flags, flock->start, flock->length, |
| 2222 | flock->proc_id, flock->client_id); |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2223 | |
| 2224 | if (IS_ERR(req)) |
| 2225 | return PTR_ERR(req); |
| 2226 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2227 | err = p9pdu_readf(&req->rc, clnt->proto_version, "b", status); |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2228 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2229 | trace_9p_protocol_dump(clnt, &req->rc); |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2230 | goto error; |
| 2231 | } |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2232 | p9_debug(P9_DEBUG_9P, "<<< RLOCK status %i\n", *status); |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2233 | error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2234 | p9_tag_remove(clnt, req); |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2235 | return err; |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2236 | } |
| 2237 | EXPORT_SYMBOL(p9_client_lock_dotl); |
M. Mohan Kumar | 1d769cd | 2010-09-27 12:22:13 +0530 | [diff] [blame] | 2238 | |
| 2239 | int p9_client_getlock_dotl(struct p9_fid *fid, struct p9_getlock *glock) |
| 2240 | { |
| 2241 | int err; |
| 2242 | struct p9_client *clnt; |
| 2243 | struct p9_req_t *req; |
| 2244 | |
| 2245 | err = 0; |
| 2246 | clnt = fid->clnt; |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2247 | p9_debug(P9_DEBUG_9P, |
| 2248 | ">>> TGETLOCK fid %d, type %i start %lld length %lld proc_id %d client_id %s\n", |
| 2249 | fid->fid, glock->type, glock->start, glock->length, |
| 2250 | glock->proc_id, glock->client_id); |
M. Mohan Kumar | 1d769cd | 2010-09-27 12:22:13 +0530 | [diff] [blame] | 2251 | |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2252 | req = p9_client_rpc(clnt, P9_TGETLOCK, "dbqqds", fid->fid, |
| 2253 | glock->type, glock->start, glock->length, |
| 2254 | glock->proc_id, glock->client_id); |
M. Mohan Kumar | 1d769cd | 2010-09-27 12:22:13 +0530 | [diff] [blame] | 2255 | |
| 2256 | if (IS_ERR(req)) |
| 2257 | return PTR_ERR(req); |
| 2258 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2259 | err = p9pdu_readf(&req->rc, clnt->proto_version, "bqqds", &glock->type, |
| 2260 | &glock->start, &glock->length, &glock->proc_id, |
| 2261 | &glock->client_id); |
M. Mohan Kumar | 1d769cd | 2010-09-27 12:22:13 +0530 | [diff] [blame] | 2262 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2263 | trace_9p_protocol_dump(clnt, &req->rc); |
M. Mohan Kumar | 1d769cd | 2010-09-27 12:22:13 +0530 | [diff] [blame] | 2264 | goto error; |
| 2265 | } |
Dominique Martinet | 6e195b0 | 2021-11-02 22:16:43 +0900 | [diff] [blame] | 2266 | p9_debug(P9_DEBUG_9P, |
| 2267 | "<<< RGETLOCK type %i start %lld length %lld proc_id %d client_id %s\n", |
| 2268 | glock->type, glock->start, glock->length, |
| 2269 | glock->proc_id, glock->client_id); |
M. Mohan Kumar | 1d769cd | 2010-09-27 12:22:13 +0530 | [diff] [blame] | 2270 | error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2271 | p9_tag_remove(clnt, req); |
M. Mohan Kumar | 1d769cd | 2010-09-27 12:22:13 +0530 | [diff] [blame] | 2272 | return err; |
| 2273 | } |
| 2274 | EXPORT_SYMBOL(p9_client_getlock_dotl); |
M. Mohan Kumar | 329176cc | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2275 | |
| 2276 | int p9_client_readlink(struct p9_fid *fid, char **target) |
| 2277 | { |
| 2278 | int err; |
| 2279 | struct p9_client *clnt; |
| 2280 | struct p9_req_t *req; |
| 2281 | |
| 2282 | err = 0; |
| 2283 | clnt = fid->clnt; |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2284 | p9_debug(P9_DEBUG_9P, ">>> TREADLINK fid %d\n", fid->fid); |
M. Mohan Kumar | 329176cc | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2285 | |
| 2286 | req = p9_client_rpc(clnt, P9_TREADLINK, "d", fid->fid); |
| 2287 | if (IS_ERR(req)) |
| 2288 | return PTR_ERR(req); |
| 2289 | |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2290 | err = p9pdu_readf(&req->rc, clnt->proto_version, "s", target); |
M. Mohan Kumar | 329176cc | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2291 | if (err) { |
Dominique Martinet | 523adb6 | 2018-07-30 05:55:19 +0000 | [diff] [blame] | 2292 | trace_9p_protocol_dump(clnt, &req->rc); |
M. Mohan Kumar | 329176cc | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2293 | goto error; |
| 2294 | } |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 2295 | p9_debug(P9_DEBUG_9P, "<<< RREADLINK target %s\n", *target); |
M. Mohan Kumar | 329176cc | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2296 | error: |
Tomas Bortoli | 43cbcbe | 2018-08-11 16:42:53 +0200 | [diff] [blame] | 2297 | p9_tag_remove(clnt, req); |
M. Mohan Kumar | 329176cc | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2298 | return err; |
| 2299 | } |
| 2300 | EXPORT_SYMBOL(p9_client_readlink); |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 2301 | |
| 2302 | int __init p9_client_init(void) |
| 2303 | { |
Tomas Bortoli | 728356d | 2018-08-14 19:43:42 +0200 | [diff] [blame] | 2304 | p9_req_cache = KMEM_CACHE(p9_req_t, SLAB_TYPESAFE_BY_RCU); |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 2305 | return p9_req_cache ? 0 : -ENOMEM; |
| 2306 | } |
| 2307 | |
| 2308 | void __exit p9_client_exit(void) |
| 2309 | { |
| 2310 | kmem_cache_destroy(p9_req_cache); |
| 2311 | } |