client.c 30 KB

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