client.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. /*
  2. * net/9p/clnt.c
  3. *
  4. * 9P Client
  5. *
  6. * Copyright (C) 2008 by Eric Van Hensbergen <ericvh@gmail.com>
  7. * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to:
  20. * Free Software Foundation
  21. * 51 Franklin Street, Fifth Floor
  22. * Boston, MA 02111-1301 USA
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/errno.h>
  27. #include <linux/fs.h>
  28. #include <linux/poll.h>
  29. #include <linux/idr.h>
  30. #include <linux/mutex.h>
  31. #include <linux/sched.h>
  32. #include <linux/uaccess.h>
  33. #include <net/9p/9p.h>
  34. #include <linux/parser.h>
  35. #include <net/9p/client.h>
  36. #include <net/9p/transport.h>
  37. #include "protocol.h"
  38. /*
  39. * Client Option Parsing (code inspired by NFS code)
  40. * - a little lazy - parse all client options
  41. */
  42. enum {
  43. Opt_msize,
  44. Opt_trans,
  45. Opt_legacy,
  46. Opt_version,
  47. Opt_err,
  48. };
  49. static const match_table_t tokens = {
  50. {Opt_msize, "msize=%u"},
  51. {Opt_legacy, "noextend"},
  52. {Opt_trans, "trans=%s"},
  53. {Opt_version, "version=%s"},
  54. {Opt_err, NULL},
  55. };
  56. inline int p9_is_proto_dotl(struct p9_client *clnt)
  57. {
  58. return (clnt->proto_version == p9_proto_2000L);
  59. }
  60. EXPORT_SYMBOL(p9_is_proto_dotl);
  61. inline int p9_is_proto_dotu(struct p9_client *clnt)
  62. {
  63. return (clnt->proto_version == p9_proto_2000u);
  64. }
  65. EXPORT_SYMBOL(p9_is_proto_dotu);
  66. /* Interpret mount option for protocol version */
  67. static unsigned char get_protocol_version(const substring_t *name)
  68. {
  69. unsigned char version = -EINVAL;
  70. if (!strncmp("9p2000", name->from, name->to-name->from)) {
  71. version = p9_proto_legacy;
  72. P9_DPRINTK(P9_DEBUG_9P, "Protocol version: Legacy\n");
  73. } else if (!strncmp("9p2000.u", name->from, name->to-name->from)) {
  74. version = p9_proto_2000u;
  75. P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.u\n");
  76. } else if (!strncmp("9p2000.L", name->from, name->to-name->from)) {
  77. version = p9_proto_2000L;
  78. P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.L\n");
  79. } else {
  80. P9_DPRINTK(P9_DEBUG_ERROR, "Unknown protocol version %s. ",
  81. name->from);
  82. }
  83. return version;
  84. }
  85. static struct p9_req_t *
  86. p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...);
  87. /**
  88. * parse_options - parse mount options into client structure
  89. * @opts: options string passed from mount
  90. * @clnt: existing v9fs client information
  91. *
  92. * Return 0 upon success, -ERRNO upon failure
  93. */
  94. static int parse_opts(char *opts, struct p9_client *clnt)
  95. {
  96. char *options, *tmp_options;
  97. char *p;
  98. substring_t args[MAX_OPT_ARGS];
  99. int option;
  100. int ret = 0;
  101. clnt->proto_version = p9_proto_2000u;
  102. clnt->msize = 8192;
  103. if (!opts)
  104. return 0;
  105. tmp_options = kstrdup(opts, GFP_KERNEL);
  106. if (!tmp_options) {
  107. P9_DPRINTK(P9_DEBUG_ERROR,
  108. "failed to allocate copy of option string\n");
  109. return -ENOMEM;
  110. }
  111. options = tmp_options;
  112. while ((p = strsep(&options, ",")) != NULL) {
  113. int token;
  114. if (!*p)
  115. continue;
  116. token = match_token(p, tokens, args);
  117. if (token < Opt_trans) {
  118. int r = match_int(&args[0], &option);
  119. if (r < 0) {
  120. P9_DPRINTK(P9_DEBUG_ERROR,
  121. "integer field, but no integer?\n");
  122. ret = r;
  123. continue;
  124. }
  125. }
  126. switch (token) {
  127. case Opt_msize:
  128. clnt->msize = option;
  129. break;
  130. case Opt_trans:
  131. clnt->trans_mod = v9fs_get_trans_by_name(&args[0]);
  132. if(clnt->trans_mod == NULL) {
  133. P9_DPRINTK(P9_DEBUG_ERROR,
  134. "Could not find request transport: %s\n",
  135. (char *) &args[0]);
  136. ret = -EINVAL;
  137. goto free_and_return;
  138. }
  139. break;
  140. case Opt_legacy:
  141. clnt->proto_version = p9_proto_legacy;
  142. break;
  143. case Opt_version:
  144. ret = get_protocol_version(&args[0]);
  145. if (ret == -EINVAL)
  146. goto free_and_return;
  147. clnt->proto_version = ret;
  148. break;
  149. default:
  150. continue;
  151. }
  152. }
  153. free_and_return:
  154. kfree(tmp_options);
  155. return ret;
  156. }
  157. /**
  158. * p9_tag_alloc - lookup/allocate a request by tag
  159. * @c: client session to lookup tag within
  160. * @tag: numeric id for transaction
  161. *
  162. * this is a simple array lookup, but will grow the
  163. * request_slots as necessary to accomodate transaction
  164. * ids which did not previously have a slot.
  165. *
  166. * this code relies on the client spinlock to manage locks, its
  167. * possible we should switch to something else, but I'd rather
  168. * stick with something low-overhead for the common case.
  169. *
  170. */
  171. static struct p9_req_t *p9_tag_alloc(struct p9_client *c, u16 tag)
  172. {
  173. unsigned long flags;
  174. int row, col;
  175. struct p9_req_t *req;
  176. /* This looks up the original request by tag so we know which
  177. * buffer to read the data into */
  178. tag++;
  179. if (tag >= c->max_tag) {
  180. spin_lock_irqsave(&c->lock, flags);
  181. /* check again since original check was outside of lock */
  182. while (tag >= c->max_tag) {
  183. row = (tag / P9_ROW_MAXTAG);
  184. c->reqs[row] = kcalloc(P9_ROW_MAXTAG,
  185. sizeof(struct p9_req_t), GFP_ATOMIC);
  186. if (!c->reqs[row]) {
  187. printk(KERN_ERR "Couldn't grow tag array\n");
  188. spin_unlock_irqrestore(&c->lock, flags);
  189. return ERR_PTR(-ENOMEM);
  190. }
  191. for (col = 0; col < P9_ROW_MAXTAG; col++) {
  192. c->reqs[row][col].status = REQ_STATUS_IDLE;
  193. c->reqs[row][col].tc = NULL;
  194. }
  195. c->max_tag += P9_ROW_MAXTAG;
  196. }
  197. spin_unlock_irqrestore(&c->lock, flags);
  198. }
  199. row = tag / P9_ROW_MAXTAG;
  200. col = tag % P9_ROW_MAXTAG;
  201. req = &c->reqs[row][col];
  202. if (!req->tc) {
  203. req->wq = kmalloc(sizeof(wait_queue_head_t), GFP_KERNEL);
  204. if (!req->wq) {
  205. printk(KERN_ERR "Couldn't grow tag array\n");
  206. return ERR_PTR(-ENOMEM);
  207. }
  208. init_waitqueue_head(req->wq);
  209. req->tc = kmalloc(sizeof(struct p9_fcall)+c->msize,
  210. GFP_KERNEL);
  211. req->rc = kmalloc(sizeof(struct p9_fcall)+c->msize,
  212. GFP_KERNEL);
  213. if ((!req->tc) || (!req->rc)) {
  214. printk(KERN_ERR "Couldn't grow tag array\n");
  215. kfree(req->tc);
  216. kfree(req->rc);
  217. kfree(req->wq);
  218. req->tc = req->rc = NULL;
  219. req->wq = NULL;
  220. return ERR_PTR(-ENOMEM);
  221. }
  222. req->tc->sdata = (char *) req->tc + sizeof(struct p9_fcall);
  223. req->tc->capacity = c->msize;
  224. req->rc->sdata = (char *) req->rc + sizeof(struct p9_fcall);
  225. req->rc->capacity = c->msize;
  226. }
  227. p9pdu_reset(req->tc);
  228. p9pdu_reset(req->rc);
  229. req->tc->tag = tag-1;
  230. req->status = REQ_STATUS_ALLOC;
  231. return &c->reqs[row][col];
  232. }
  233. /**
  234. * p9_tag_lookup - lookup a request by tag
  235. * @c: client session to lookup tag within
  236. * @tag: numeric id for transaction
  237. *
  238. */
  239. struct p9_req_t *p9_tag_lookup(struct p9_client *c, u16 tag)
  240. {
  241. int row, col;
  242. /* This looks up the original request by tag so we know which
  243. * buffer to read the data into */
  244. tag++;
  245. BUG_ON(tag >= c->max_tag);
  246. row = tag / P9_ROW_MAXTAG;
  247. col = tag % P9_ROW_MAXTAG;
  248. return &c->reqs[row][col];
  249. }
  250. EXPORT_SYMBOL(p9_tag_lookup);
  251. /**
  252. * p9_tag_init - setup tags structure and contents
  253. * @c: v9fs client struct
  254. *
  255. * This initializes the tags structure for each client instance.
  256. *
  257. */
  258. static int p9_tag_init(struct p9_client *c)
  259. {
  260. int err = 0;
  261. c->tagpool = p9_idpool_create();
  262. if (IS_ERR(c->tagpool)) {
  263. err = PTR_ERR(c->tagpool);
  264. c->tagpool = NULL;
  265. goto error;
  266. }
  267. p9_idpool_get(c->tagpool); /* reserve tag 0 */
  268. c->max_tag = 0;
  269. error:
  270. return err;
  271. }
  272. /**
  273. * p9_tag_cleanup - cleans up tags structure and reclaims resources
  274. * @c: v9fs client struct
  275. *
  276. * This frees resources associated with the tags structure
  277. *
  278. */
  279. static void p9_tag_cleanup(struct p9_client *c)
  280. {
  281. int row, col;
  282. /* check to insure all requests are idle */
  283. for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) {
  284. for (col = 0; col < P9_ROW_MAXTAG; col++) {
  285. if (c->reqs[row][col].status != REQ_STATUS_IDLE) {
  286. P9_DPRINTK(P9_DEBUG_MUX,
  287. "Attempting to cleanup non-free tag %d,%d\n",
  288. row, col);
  289. /* TODO: delay execution of cleanup */
  290. return;
  291. }
  292. }
  293. }
  294. if (c->tagpool)
  295. p9_idpool_destroy(c->tagpool);
  296. /* free requests associated with tags */
  297. for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) {
  298. for (col = 0; col < P9_ROW_MAXTAG; col++) {
  299. kfree(c->reqs[row][col].wq);
  300. kfree(c->reqs[row][col].tc);
  301. kfree(c->reqs[row][col].rc);
  302. }
  303. kfree(c->reqs[row]);
  304. }
  305. c->max_tag = 0;
  306. }
  307. /**
  308. * p9_free_req - free a request and clean-up as necessary
  309. * c: client state
  310. * r: request to release
  311. *
  312. */
  313. static void p9_free_req(struct p9_client *c, struct p9_req_t *r)
  314. {
  315. int tag = r->tc->tag;
  316. P9_DPRINTK(P9_DEBUG_MUX, "clnt %p req %p tag: %d\n", c, r, tag);
  317. r->status = REQ_STATUS_IDLE;
  318. if (tag != P9_NOTAG && p9_idpool_check(tag, c->tagpool))
  319. p9_idpool_put(tag, c->tagpool);
  320. }
  321. /**
  322. * p9_client_cb - call back from transport to client
  323. * c: client state
  324. * req: request received
  325. *
  326. */
  327. void p9_client_cb(struct p9_client *c, struct p9_req_t *req)
  328. {
  329. P9_DPRINTK(P9_DEBUG_MUX, " tag %d\n", req->tc->tag);
  330. wake_up(req->wq);
  331. P9_DPRINTK(P9_DEBUG_MUX, "wakeup: %d\n", req->tc->tag);
  332. }
  333. EXPORT_SYMBOL(p9_client_cb);
  334. /**
  335. * p9_parse_header - parse header arguments out of a packet
  336. * @pdu: packet to parse
  337. * @size: size of packet
  338. * @type: type of request
  339. * @tag: tag of packet
  340. * @rewind: set if we need to rewind offset afterwards
  341. */
  342. int
  343. p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, int16_t *tag,
  344. int rewind)
  345. {
  346. int8_t r_type;
  347. int16_t r_tag;
  348. int32_t r_size;
  349. int offset = pdu->offset;
  350. int err;
  351. pdu->offset = 0;
  352. if (pdu->size == 0)
  353. pdu->size = 7;
  354. err = p9pdu_readf(pdu, 0, "dbw", &r_size, &r_type, &r_tag);
  355. if (err)
  356. goto rewind_and_exit;
  357. pdu->size = r_size;
  358. pdu->id = r_type;
  359. pdu->tag = r_tag;
  360. P9_DPRINTK(P9_DEBUG_9P, "<<< size=%d type: %d tag: %d\n", pdu->size,
  361. pdu->id, pdu->tag);
  362. if (type)
  363. *type = r_type;
  364. if (tag)
  365. *tag = r_tag;
  366. if (size)
  367. *size = r_size;
  368. rewind_and_exit:
  369. if (rewind)
  370. pdu->offset = offset;
  371. return err;
  372. }
  373. EXPORT_SYMBOL(p9_parse_header);
  374. /**
  375. * p9_check_errors - check 9p packet for error return and process it
  376. * @c: current client instance
  377. * @req: request to parse and check for error conditions
  378. *
  379. * returns error code if one is discovered, otherwise returns 0
  380. *
  381. * this will have to be more complicated if we have multiple
  382. * error packet types
  383. */
  384. static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
  385. {
  386. int8_t type;
  387. int err;
  388. err = p9_parse_header(req->rc, NULL, &type, NULL, 0);
  389. if (err) {
  390. P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse header %d\n", err);
  391. return err;
  392. }
  393. if (type == P9_RERROR) {
  394. int ecode;
  395. char *ename;
  396. err = p9pdu_readf(req->rc, c->proto_version, "s?d",
  397. &ename, &ecode);
  398. if (err) {
  399. P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n",
  400. err);
  401. return err;
  402. }
  403. if (p9_is_proto_dotu(c))
  404. err = -ecode;
  405. if (!err || !IS_ERR_VALUE(err))
  406. err = p9_errstr2errno(ename, strlen(ename));
  407. P9_DPRINTK(P9_DEBUG_9P, "<<< RERROR (%d) %s\n", -ecode, ename);
  408. kfree(ename);
  409. } else
  410. err = 0;
  411. return err;
  412. }
  413. /**
  414. * p9_client_flush - flush (cancel) a request
  415. * @c: client state
  416. * @oldreq: request to cancel
  417. *
  418. * This sents a flush for a particular requests and links
  419. * the flush request to the original request. The current
  420. * code only supports a single flush request although the protocol
  421. * allows for multiple flush requests to be sent for a single request.
  422. *
  423. */
  424. static int p9_client_flush(struct p9_client *c, struct p9_req_t *oldreq)
  425. {
  426. struct p9_req_t *req;
  427. int16_t oldtag;
  428. int err;
  429. err = p9_parse_header(oldreq->tc, NULL, NULL, &oldtag, 1);
  430. if (err)
  431. return err;
  432. P9_DPRINTK(P9_DEBUG_9P, ">>> TFLUSH tag %d\n", oldtag);
  433. req = p9_client_rpc(c, P9_TFLUSH, "w", oldtag);
  434. if (IS_ERR(req))
  435. return PTR_ERR(req);
  436. /* if we haven't received a response for oldreq,
  437. remove it from the list. */
  438. spin_lock(&c->lock);
  439. if (oldreq->status == REQ_STATUS_FLSH)
  440. list_del(&oldreq->req_list);
  441. spin_unlock(&c->lock);
  442. p9_free_req(c, req);
  443. return 0;
  444. }
  445. /**
  446. * p9_client_rpc - issue a request and wait for a response
  447. * @c: client session
  448. * @type: type of request
  449. * @fmt: protocol format string (see protocol.c)
  450. *
  451. * Returns request structure (which client must free using p9_free_req)
  452. */
  453. static struct p9_req_t *
  454. p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
  455. {
  456. va_list ap;
  457. int tag, err;
  458. struct p9_req_t *req;
  459. unsigned long flags;
  460. int sigpending;
  461. P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type);
  462. if (c->status != Connected)
  463. return ERR_PTR(-EIO);
  464. if (signal_pending(current)) {
  465. sigpending = 1;
  466. clear_thread_flag(TIF_SIGPENDING);
  467. } else
  468. sigpending = 0;
  469. tag = P9_NOTAG;
  470. if (type != P9_TVERSION) {
  471. tag = p9_idpool_get(c->tagpool);
  472. if (tag < 0)
  473. return ERR_PTR(-ENOMEM);
  474. }
  475. req = p9_tag_alloc(c, tag);
  476. if (IS_ERR(req))
  477. return req;
  478. /* marshall the data */
  479. p9pdu_prepare(req->tc, tag, type);
  480. va_start(ap, fmt);
  481. err = p9pdu_vwritef(req->tc, c->proto_version, fmt, ap);
  482. va_end(ap);
  483. p9pdu_finalize(req->tc);
  484. err = c->trans_mod->request(c, req);
  485. if (err < 0) {
  486. c->status = Disconnected;
  487. goto reterr;
  488. }
  489. P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d\n", req->wq, tag);
  490. err = wait_event_interruptible(*req->wq,
  491. req->status >= REQ_STATUS_RCVD);
  492. P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d returned %d\n",
  493. req->wq, tag, err);
  494. if (req->status == REQ_STATUS_ERROR) {
  495. P9_DPRINTK(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err);
  496. err = req->t_err;
  497. }
  498. if ((err == -ERESTARTSYS) && (c->status == Connected)) {
  499. P9_DPRINTK(P9_DEBUG_MUX, "flushing\n");
  500. sigpending = 1;
  501. clear_thread_flag(TIF_SIGPENDING);
  502. if (c->trans_mod->cancel(c, req))
  503. p9_client_flush(c, req);
  504. /* if we received the response anyway, don't signal error */
  505. if (req->status == REQ_STATUS_RCVD)
  506. err = 0;
  507. }
  508. if (sigpending) {
  509. spin_lock_irqsave(&current->sighand->siglock, flags);
  510. recalc_sigpending();
  511. spin_unlock_irqrestore(&current->sighand->siglock, flags);
  512. }
  513. if (err < 0)
  514. goto reterr;
  515. err = p9_check_errors(c, req);
  516. if (!err) {
  517. P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d\n", c, type);
  518. return req;
  519. }
  520. reterr:
  521. P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d error: %d\n", c, type,
  522. err);
  523. p9_free_req(c, req);
  524. return ERR_PTR(err);
  525. }
  526. static struct p9_fid *p9_fid_create(struct p9_client *clnt)
  527. {
  528. int ret;
  529. struct p9_fid *fid;
  530. unsigned long flags;
  531. P9_DPRINTK(P9_DEBUG_FID, "clnt %p\n", clnt);
  532. fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL);
  533. if (!fid)
  534. return ERR_PTR(-ENOMEM);
  535. ret = p9_idpool_get(clnt->fidpool);
  536. if (ret < 0) {
  537. ret = -ENOSPC;
  538. goto error;
  539. }
  540. fid->fid = ret;
  541. memset(&fid->qid, 0, sizeof(struct p9_qid));
  542. fid->mode = -1;
  543. fid->uid = current_fsuid();
  544. fid->clnt = clnt;
  545. fid->rdir = NULL;
  546. spin_lock_irqsave(&clnt->lock, flags);
  547. list_add(&fid->flist, &clnt->fidlist);
  548. spin_unlock_irqrestore(&clnt->lock, flags);
  549. return fid;
  550. error:
  551. kfree(fid);
  552. return ERR_PTR(ret);
  553. }
  554. static void p9_fid_destroy(struct p9_fid *fid)
  555. {
  556. struct p9_client *clnt;
  557. unsigned long flags;
  558. P9_DPRINTK(P9_DEBUG_FID, "fid %d\n", fid->fid);
  559. clnt = fid->clnt;
  560. p9_idpool_put(fid->fid, clnt->fidpool);
  561. spin_lock_irqsave(&clnt->lock, flags);
  562. list_del(&fid->flist);
  563. spin_unlock_irqrestore(&clnt->lock, flags);
  564. kfree(fid->rdir);
  565. kfree(fid);
  566. }
  567. int p9_client_version(struct p9_client *c)
  568. {
  569. int err = 0;
  570. struct p9_req_t *req;
  571. char *version;
  572. int msize;
  573. P9_DPRINTK(P9_DEBUG_9P, ">>> TVERSION msize %d protocol %d\n",
  574. c->msize, c->proto_version);
  575. switch (c->proto_version) {
  576. case p9_proto_2000L:
  577. req = p9_client_rpc(c, P9_TVERSION, "ds",
  578. c->msize, "9P2000.L");
  579. break;
  580. case p9_proto_2000u:
  581. req = p9_client_rpc(c, P9_TVERSION, "ds",
  582. c->msize, "9P2000.u");
  583. break;
  584. case p9_proto_legacy:
  585. req = p9_client_rpc(c, P9_TVERSION, "ds",
  586. c->msize, "9P2000");
  587. break;
  588. default:
  589. return -EINVAL;
  590. break;
  591. }
  592. if (IS_ERR(req))
  593. return PTR_ERR(req);
  594. err = p9pdu_readf(req->rc, c->proto_version, "ds", &msize, &version);
  595. if (err) {
  596. P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err);
  597. p9pdu_dump(1, req->rc);
  598. goto error;
  599. }
  600. P9_DPRINTK(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version);
  601. if (!strncmp(version, "9P2000.L", 8))
  602. c->proto_version = p9_proto_2000L;
  603. else if (!strncmp(version, "9P2000.u", 8))
  604. c->proto_version = p9_proto_2000u;
  605. else if (!strncmp(version, "9P2000", 6))
  606. c->proto_version = p9_proto_legacy;
  607. else {
  608. err = -EREMOTEIO;
  609. goto error;
  610. }
  611. if (msize < c->msize)
  612. c->msize = msize;
  613. error:
  614. kfree(version);
  615. p9_free_req(c, req);
  616. return err;
  617. }
  618. EXPORT_SYMBOL(p9_client_version);
  619. struct p9_client *p9_client_create(const char *dev_name, char *options)
  620. {
  621. int err;
  622. struct p9_client *clnt;
  623. err = 0;
  624. clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL);
  625. if (!clnt)
  626. return ERR_PTR(-ENOMEM);
  627. clnt->trans_mod = NULL;
  628. clnt->trans = NULL;
  629. spin_lock_init(&clnt->lock);
  630. INIT_LIST_HEAD(&clnt->fidlist);
  631. p9_tag_init(clnt);
  632. err = parse_opts(options, clnt);
  633. if (err < 0)
  634. goto free_client;
  635. if (!clnt->trans_mod)
  636. clnt->trans_mod = v9fs_get_default_trans();
  637. if (clnt->trans_mod == NULL) {
  638. err = -EPROTONOSUPPORT;
  639. P9_DPRINTK(P9_DEBUG_ERROR,
  640. "No transport defined or default transport\n");
  641. goto free_client;
  642. }
  643. clnt->fidpool = p9_idpool_create();
  644. if (IS_ERR(clnt->fidpool)) {
  645. err = PTR_ERR(clnt->fidpool);
  646. clnt->fidpool = NULL;
  647. goto put_trans;
  648. }
  649. P9_DPRINTK(P9_DEBUG_MUX, "clnt %p trans %p msize %d protocol %d\n",
  650. clnt, clnt->trans_mod, clnt->msize, clnt->proto_version);
  651. err = clnt->trans_mod->create(clnt, dev_name, options);
  652. if (err)
  653. goto destroy_fidpool;
  654. if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize)
  655. clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ;
  656. err = p9_client_version(clnt);
  657. if (err)
  658. goto close_trans;
  659. return clnt;
  660. close_trans:
  661. clnt->trans_mod->close(clnt);
  662. destroy_fidpool:
  663. p9_idpool_destroy(clnt->fidpool);
  664. put_trans:
  665. v9fs_put_trans(clnt->trans_mod);
  666. free_client:
  667. kfree(clnt);
  668. return ERR_PTR(err);
  669. }
  670. EXPORT_SYMBOL(p9_client_create);
  671. void p9_client_destroy(struct p9_client *clnt)
  672. {
  673. struct p9_fid *fid, *fidptr;
  674. P9_DPRINTK(P9_DEBUG_MUX, "clnt %p\n", clnt);
  675. if (clnt->trans_mod)
  676. clnt->trans_mod->close(clnt);
  677. v9fs_put_trans(clnt->trans_mod);
  678. list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist)
  679. p9_fid_destroy(fid);
  680. if (clnt->fidpool)
  681. p9_idpool_destroy(clnt->fidpool);
  682. p9_tag_cleanup(clnt);
  683. kfree(clnt);
  684. }
  685. EXPORT_SYMBOL(p9_client_destroy);
  686. void p9_client_disconnect(struct p9_client *clnt)
  687. {
  688. P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
  689. clnt->status = Disconnected;
  690. }
  691. EXPORT_SYMBOL(p9_client_disconnect);
  692. struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
  693. char *uname, u32 n_uname, char *aname)
  694. {
  695. int err;
  696. struct p9_req_t *req;
  697. struct p9_fid *fid;
  698. struct p9_qid qid;
  699. P9_DPRINTK(P9_DEBUG_9P, ">>> TATTACH afid %d uname %s aname %s\n",
  700. afid ? afid->fid : -1, uname, aname);
  701. err = 0;
  702. fid = p9_fid_create(clnt);
  703. if (IS_ERR(fid)) {
  704. err = PTR_ERR(fid);
  705. fid = NULL;
  706. goto error;
  707. }
  708. req = p9_client_rpc(clnt, P9_TATTACH, "ddss?d", fid->fid,
  709. afid ? afid->fid : P9_NOFID, uname, aname, n_uname);
  710. if (IS_ERR(req)) {
  711. err = PTR_ERR(req);
  712. goto error;
  713. }
  714. err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid);
  715. if (err) {
  716. p9pdu_dump(1, req->rc);
  717. p9_free_req(clnt, req);
  718. goto error;
  719. }
  720. P9_DPRINTK(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n",
  721. qid.type,
  722. (unsigned long long)qid.path,
  723. qid.version);
  724. memmove(&fid->qid, &qid, sizeof(struct p9_qid));
  725. p9_free_req(clnt, req);
  726. return fid;
  727. error:
  728. if (fid)
  729. p9_fid_destroy(fid);
  730. return ERR_PTR(err);
  731. }
  732. EXPORT_SYMBOL(p9_client_attach);
  733. struct p9_fid *
  734. p9_client_auth(struct p9_client *clnt, char *uname, u32 n_uname, char *aname)
  735. {
  736. int err;
  737. struct p9_req_t *req;
  738. struct p9_qid qid;
  739. struct p9_fid *afid;
  740. P9_DPRINTK(P9_DEBUG_9P, ">>> TAUTH uname %s aname %s\n", uname, aname);
  741. err = 0;
  742. afid = p9_fid_create(clnt);
  743. if (IS_ERR(afid)) {
  744. err = PTR_ERR(afid);
  745. afid = NULL;
  746. goto error;
  747. }
  748. req = p9_client_rpc(clnt, P9_TAUTH, "dss?d",
  749. afid ? afid->fid : P9_NOFID, uname, aname, n_uname);
  750. if (IS_ERR(req)) {
  751. err = PTR_ERR(req);
  752. goto error;
  753. }
  754. err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid);
  755. if (err) {
  756. p9pdu_dump(1, req->rc);
  757. p9_free_req(clnt, req);
  758. goto error;
  759. }
  760. P9_DPRINTK(P9_DEBUG_9P, "<<< RAUTH qid %x.%llx.%x\n",
  761. qid.type,
  762. (unsigned long long)qid.path,
  763. qid.version);
  764. memmove(&afid->qid, &qid, sizeof(struct p9_qid));
  765. p9_free_req(clnt, req);
  766. return afid;
  767. error:
  768. if (afid)
  769. p9_fid_destroy(afid);
  770. return ERR_PTR(err);
  771. }
  772. EXPORT_SYMBOL(p9_client_auth);
  773. struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
  774. int clone)
  775. {
  776. int err;
  777. struct p9_client *clnt;
  778. struct p9_fid *fid;
  779. struct p9_qid *wqids;
  780. struct p9_req_t *req;
  781. int16_t nwqids, count;
  782. err = 0;
  783. clnt = oldfid->clnt;
  784. if (clone) {
  785. fid = p9_fid_create(clnt);
  786. if (IS_ERR(fid)) {
  787. err = PTR_ERR(fid);
  788. fid = NULL;
  789. goto error;
  790. }
  791. fid->uid = oldfid->uid;
  792. } else
  793. fid = oldfid;
  794. P9_DPRINTK(P9_DEBUG_9P, ">>> TWALK fids %d,%d nwname %d wname[0] %s\n",
  795. oldfid->fid, fid->fid, nwname, wnames ? wnames[0] : NULL);
  796. req = p9_client_rpc(clnt, P9_TWALK, "ddT", oldfid->fid, fid->fid,
  797. nwname, wnames);
  798. if (IS_ERR(req)) {
  799. err = PTR_ERR(req);
  800. goto error;
  801. }
  802. err = p9pdu_readf(req->rc, clnt->proto_version, "R", &nwqids, &wqids);
  803. if (err) {
  804. p9pdu_dump(1, req->rc);
  805. p9_free_req(clnt, req);
  806. goto clunk_fid;
  807. }
  808. p9_free_req(clnt, req);
  809. P9_DPRINTK(P9_DEBUG_9P, "<<< RWALK nwqid %d:\n", nwqids);
  810. if (nwqids != nwname) {
  811. err = -ENOENT;
  812. goto clunk_fid;
  813. }
  814. for (count = 0; count < nwqids; count++)
  815. P9_DPRINTK(P9_DEBUG_9P, "<<< [%d] %x.%llx.%x\n",
  816. count, wqids[count].type,
  817. (unsigned long long)wqids[count].path,
  818. wqids[count].version);
  819. if (nwname)
  820. memmove(&fid->qid, &wqids[nwqids - 1], sizeof(struct p9_qid));
  821. else
  822. fid->qid = oldfid->qid;
  823. return fid;
  824. clunk_fid:
  825. p9_client_clunk(fid);
  826. fid = NULL;
  827. error:
  828. if (fid && (fid != oldfid))
  829. p9_fid_destroy(fid);
  830. return ERR_PTR(err);
  831. }
  832. EXPORT_SYMBOL(p9_client_walk);
  833. int p9_client_open(struct p9_fid *fid, int mode)
  834. {
  835. int err;
  836. struct p9_client *clnt;
  837. struct p9_req_t *req;
  838. struct p9_qid qid;
  839. int iounit;
  840. P9_DPRINTK(P9_DEBUG_9P, ">>> TOPEN fid %d mode %d\n", fid->fid, mode);
  841. err = 0;
  842. clnt = fid->clnt;
  843. if (fid->mode != -1)
  844. return -EINVAL;
  845. req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode);
  846. if (IS_ERR(req)) {
  847. err = PTR_ERR(req);
  848. goto error;
  849. }
  850. err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit);
  851. if (err) {
  852. p9pdu_dump(1, req->rc);
  853. goto free_and_error;
  854. }
  855. P9_DPRINTK(P9_DEBUG_9P, "<<< ROPEN qid %x.%llx.%x iounit %x\n",
  856. qid.type,
  857. (unsigned long long)qid.path,
  858. qid.version, iounit);
  859. fid->mode = mode;
  860. fid->iounit = iounit;
  861. free_and_error:
  862. p9_free_req(clnt, req);
  863. error:
  864. return err;
  865. }
  866. EXPORT_SYMBOL(p9_client_open);
  867. int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
  868. char *extension)
  869. {
  870. int err;
  871. struct p9_client *clnt;
  872. struct p9_req_t *req;
  873. struct p9_qid qid;
  874. int iounit;
  875. P9_DPRINTK(P9_DEBUG_9P, ">>> TCREATE fid %d name %s perm %d mode %d\n",
  876. fid->fid, name, perm, mode);
  877. err = 0;
  878. clnt = fid->clnt;
  879. if (fid->mode != -1)
  880. return -EINVAL;
  881. req = p9_client_rpc(clnt, P9_TCREATE, "dsdb?s", fid->fid, name, perm,
  882. mode, extension);
  883. if (IS_ERR(req)) {
  884. err = PTR_ERR(req);
  885. goto error;
  886. }
  887. err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit);
  888. if (err) {
  889. p9pdu_dump(1, req->rc);
  890. goto free_and_error;
  891. }
  892. P9_DPRINTK(P9_DEBUG_9P, "<<< RCREATE qid %x.%llx.%x iounit %x\n",
  893. qid.type,
  894. (unsigned long long)qid.path,
  895. qid.version, iounit);
  896. fid->mode = mode;
  897. fid->iounit = iounit;
  898. free_and_error:
  899. p9_free_req(clnt, req);
  900. error:
  901. return err;
  902. }
  903. EXPORT_SYMBOL(p9_client_fcreate);
  904. int p9_client_clunk(struct p9_fid *fid)
  905. {
  906. int err;
  907. struct p9_client *clnt;
  908. struct p9_req_t *req;
  909. P9_DPRINTK(P9_DEBUG_9P, ">>> TCLUNK fid %d\n", fid->fid);
  910. err = 0;
  911. clnt = fid->clnt;
  912. req = p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid);
  913. if (IS_ERR(req)) {
  914. err = PTR_ERR(req);
  915. goto error;
  916. }
  917. P9_DPRINTK(P9_DEBUG_9P, "<<< RCLUNK fid %d\n", fid->fid);
  918. p9_free_req(clnt, req);
  919. p9_fid_destroy(fid);
  920. error:
  921. return err;
  922. }
  923. EXPORT_SYMBOL(p9_client_clunk);
  924. int p9_client_remove(struct p9_fid *fid)
  925. {
  926. int err;
  927. struct p9_client *clnt;
  928. struct p9_req_t *req;
  929. P9_DPRINTK(P9_DEBUG_9P, ">>> TREMOVE fid %d\n", fid->fid);
  930. err = 0;
  931. clnt = fid->clnt;
  932. req = p9_client_rpc(clnt, P9_TREMOVE, "d", fid->fid);
  933. if (IS_ERR(req)) {
  934. err = PTR_ERR(req);
  935. goto error;
  936. }
  937. P9_DPRINTK(P9_DEBUG_9P, "<<< RREMOVE fid %d\n", fid->fid);
  938. p9_free_req(clnt, req);
  939. p9_fid_destroy(fid);
  940. error:
  941. return err;
  942. }
  943. EXPORT_SYMBOL(p9_client_remove);
  944. int
  945. p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
  946. u32 count)
  947. {
  948. int err, rsize, total;
  949. struct p9_client *clnt;
  950. struct p9_req_t *req;
  951. char *dataptr;
  952. P9_DPRINTK(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n", fid->fid,
  953. (long long unsigned) offset, count);
  954. err = 0;
  955. clnt = fid->clnt;
  956. total = 0;
  957. rsize = fid->iounit;
  958. if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
  959. rsize = clnt->msize - P9_IOHDRSZ;
  960. if (count < rsize)
  961. rsize = count;
  962. req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset, rsize);
  963. if (IS_ERR(req)) {
  964. err = PTR_ERR(req);
  965. goto error;
  966. }
  967. err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr);
  968. if (err) {
  969. p9pdu_dump(1, req->rc);
  970. goto free_and_error;
  971. }
  972. P9_DPRINTK(P9_DEBUG_9P, "<<< RREAD count %d\n", count);
  973. if (data) {
  974. memmove(data, dataptr, count);
  975. }
  976. if (udata) {
  977. err = copy_to_user(udata, dataptr, count);
  978. if (err) {
  979. err = -EFAULT;
  980. goto free_and_error;
  981. }
  982. }
  983. p9_free_req(clnt, req);
  984. return count;
  985. free_and_error:
  986. p9_free_req(clnt, req);
  987. error:
  988. return err;
  989. }
  990. EXPORT_SYMBOL(p9_client_read);
  991. int
  992. p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
  993. u64 offset, u32 count)
  994. {
  995. int err, rsize, total;
  996. struct p9_client *clnt;
  997. struct p9_req_t *req;
  998. P9_DPRINTK(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %d\n",
  999. fid->fid, (long long unsigned) offset, count);
  1000. err = 0;
  1001. clnt = fid->clnt;
  1002. total = 0;
  1003. rsize = fid->iounit;
  1004. if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
  1005. rsize = clnt->msize - P9_IOHDRSZ;
  1006. if (count < rsize)
  1007. rsize = count;
  1008. if (data)
  1009. req = p9_client_rpc(clnt, P9_TWRITE, "dqD", fid->fid, offset,
  1010. rsize, data);
  1011. else
  1012. req = p9_client_rpc(clnt, P9_TWRITE, "dqU", fid->fid, offset,
  1013. rsize, udata);
  1014. if (IS_ERR(req)) {
  1015. err = PTR_ERR(req);
  1016. goto error;
  1017. }
  1018. err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count);
  1019. if (err) {
  1020. p9pdu_dump(1, req->rc);
  1021. goto free_and_error;
  1022. }
  1023. P9_DPRINTK(P9_DEBUG_9P, "<<< RWRITE count %d\n", count);
  1024. p9_free_req(clnt, req);
  1025. return count;
  1026. free_and_error:
  1027. p9_free_req(clnt, req);
  1028. error:
  1029. return err;
  1030. }
  1031. EXPORT_SYMBOL(p9_client_write);
  1032. struct p9_wstat *p9_client_stat(struct p9_fid *fid)
  1033. {
  1034. int err;
  1035. struct p9_client *clnt;
  1036. struct p9_wstat *ret = kmalloc(sizeof(struct p9_wstat), GFP_KERNEL);
  1037. struct p9_req_t *req;
  1038. u16 ignored;
  1039. P9_DPRINTK(P9_DEBUG_9P, ">>> TSTAT fid %d\n", fid->fid);
  1040. if (!ret)
  1041. return ERR_PTR(-ENOMEM);
  1042. err = 0;
  1043. clnt = fid->clnt;
  1044. req = p9_client_rpc(clnt, P9_TSTAT, "d", fid->fid);
  1045. if (IS_ERR(req)) {
  1046. err = PTR_ERR(req);
  1047. goto error;
  1048. }
  1049. err = p9pdu_readf(req->rc, clnt->proto_version, "wS", &ignored, ret);
  1050. if (err) {
  1051. p9pdu_dump(1, req->rc);
  1052. p9_free_req(clnt, req);
  1053. goto error;
  1054. }
  1055. P9_DPRINTK(P9_DEBUG_9P,
  1056. "<<< RSTAT sz=%x type=%x dev=%x qid=%x.%llx.%x\n"
  1057. "<<< mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n"
  1058. "<<< name=%s uid=%s gid=%s muid=%s extension=(%s)\n"
  1059. "<<< uid=%d gid=%d n_muid=%d\n",
  1060. ret->size, ret->type, ret->dev, ret->qid.type,
  1061. (unsigned long long)ret->qid.path, ret->qid.version, ret->mode,
  1062. ret->atime, ret->mtime, (unsigned long long)ret->length,
  1063. ret->name, ret->uid, ret->gid, ret->muid, ret->extension,
  1064. ret->n_uid, ret->n_gid, ret->n_muid);
  1065. p9_free_req(clnt, req);
  1066. return ret;
  1067. error:
  1068. kfree(ret);
  1069. return ERR_PTR(err);
  1070. }
  1071. EXPORT_SYMBOL(p9_client_stat);
  1072. static int p9_client_statsize(struct p9_wstat *wst, int proto_version)
  1073. {
  1074. int ret;
  1075. /* NOTE: size shouldn't include its own length */
  1076. /* size[2] type[2] dev[4] qid[13] */
  1077. /* mode[4] atime[4] mtime[4] length[8]*/
  1078. /* name[s] uid[s] gid[s] muid[s] */
  1079. ret = 2+4+13+4+4+4+8+2+2+2+2;
  1080. if (wst->name)
  1081. ret += strlen(wst->name);
  1082. if (wst->uid)
  1083. ret += strlen(wst->uid);
  1084. if (wst->gid)
  1085. ret += strlen(wst->gid);
  1086. if (wst->muid)
  1087. ret += strlen(wst->muid);
  1088. if (proto_version == p9_proto_2000u) {
  1089. ret += 2+4+4+4; /* extension[s] n_uid[4] n_gid[4] n_muid[4] */
  1090. if (wst->extension)
  1091. ret += strlen(wst->extension);
  1092. }
  1093. return ret;
  1094. }
  1095. int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst)
  1096. {
  1097. int err;
  1098. struct p9_req_t *req;
  1099. struct p9_client *clnt;
  1100. err = 0;
  1101. clnt = fid->clnt;
  1102. wst->size = p9_client_statsize(wst, clnt->proto_version);
  1103. P9_DPRINTK(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", fid->fid);
  1104. P9_DPRINTK(P9_DEBUG_9P,
  1105. " sz=%x type=%x dev=%x qid=%x.%llx.%x\n"
  1106. " mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n"
  1107. " name=%s uid=%s gid=%s muid=%s extension=(%s)\n"
  1108. " uid=%d gid=%d n_muid=%d\n",
  1109. wst->size, wst->type, wst->dev, wst->qid.type,
  1110. (unsigned long long)wst->qid.path, wst->qid.version, wst->mode,
  1111. wst->atime, wst->mtime, (unsigned long long)wst->length,
  1112. wst->name, wst->uid, wst->gid, wst->muid, wst->extension,
  1113. wst->n_uid, wst->n_gid, wst->n_muid);
  1114. req = p9_client_rpc(clnt, P9_TWSTAT, "dwS", fid->fid, wst->size+2, wst);
  1115. if (IS_ERR(req)) {
  1116. err = PTR_ERR(req);
  1117. goto error;
  1118. }
  1119. P9_DPRINTK(P9_DEBUG_9P, "<<< RWSTAT fid %d\n", fid->fid);
  1120. p9_free_req(clnt, req);
  1121. error:
  1122. return err;
  1123. }
  1124. EXPORT_SYMBOL(p9_client_wstat);