fsclient.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. /* fsclient.c: AFS File Server client stubs
  2. *
  3. * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/sched.h>
  13. #include <rxrpc/rxrpc.h>
  14. #include <rxrpc/transport.h>
  15. #include <rxrpc/connection.h>
  16. #include <rxrpc/call.h>
  17. #include "fsclient.h"
  18. #include "cmservice.h"
  19. #include "vnode.h"
  20. #include "server.h"
  21. #include "errors.h"
  22. #include "internal.h"
  23. #define FSFETCHSTATUS 132 /* AFS Fetch file status */
  24. #define FSFETCHDATA 130 /* AFS Fetch file data */
  25. #define FSGIVEUPCALLBACKS 147 /* AFS Discard callback promises */
  26. #define FSGETVOLUMEINFO 148 /* AFS Get root volume information */
  27. #define FSGETROOTVOLUME 151 /* AFS Get root volume name */
  28. #define FSLOOKUP 161 /* AFS lookup file in directory */
  29. /*****************************************************************************/
  30. /*
  31. * map afs abort codes to/from Linux error codes
  32. * - called with call->lock held
  33. */
  34. static void afs_rxfs_aemap(struct rxrpc_call *call)
  35. {
  36. switch (call->app_err_state) {
  37. case RXRPC_ESTATE_LOCAL_ABORT:
  38. call->app_abort_code = -call->app_errno;
  39. break;
  40. case RXRPC_ESTATE_PEER_ABORT:
  41. call->app_errno = afs_abort_to_error(call->app_abort_code);
  42. break;
  43. default:
  44. break;
  45. }
  46. } /* end afs_rxfs_aemap() */
  47. /*****************************************************************************/
  48. /*
  49. * get the root volume name from a fileserver
  50. * - this operation doesn't seem to work correctly in OpenAFS server 1.2.2
  51. */
  52. #if 0
  53. int afs_rxfs_get_root_volume(struct afs_server *server,
  54. char *buf, size_t *buflen)
  55. {
  56. struct rxrpc_connection *conn;
  57. struct rxrpc_call *call;
  58. struct kvec piov[2];
  59. size_t sent;
  60. int ret;
  61. u32 param[1];
  62. DECLARE_WAITQUEUE(myself, current);
  63. kenter("%p,%p,%u",server, buf, *buflen);
  64. /* get hold of the fileserver connection */
  65. ret = afs_server_get_fsconn(server, &conn);
  66. if (ret < 0)
  67. goto out;
  68. /* create a call through that connection */
  69. ret = rxrpc_create_call(conn, NULL, NULL, afs_rxfs_aemap, &call);
  70. if (ret < 0) {
  71. printk("kAFS: Unable to create call: %d\n", ret);
  72. goto out_put_conn;
  73. }
  74. call->app_opcode = FSGETROOTVOLUME;
  75. /* we want to get event notifications from the call */
  76. add_wait_queue(&call->waitq, &myself);
  77. /* marshall the parameters */
  78. param[0] = htonl(FSGETROOTVOLUME);
  79. piov[0].iov_len = sizeof(param);
  80. piov[0].iov_base = param;
  81. /* send the parameters to the server */
  82. ret = rxrpc_call_write_data(call, 1, piov, RXRPC_LAST_PACKET, GFP_NOFS,
  83. 0, &sent);
  84. if (ret < 0)
  85. goto abort;
  86. /* wait for the reply to completely arrive */
  87. for (;;) {
  88. set_current_state(TASK_INTERRUPTIBLE);
  89. if (call->app_call_state != RXRPC_CSTATE_CLNT_RCV_REPLY ||
  90. signal_pending(current))
  91. break;
  92. schedule();
  93. }
  94. set_current_state(TASK_RUNNING);
  95. ret = -EINTR;
  96. if (signal_pending(current))
  97. goto abort;
  98. switch (call->app_call_state) {
  99. case RXRPC_CSTATE_ERROR:
  100. ret = call->app_errno;
  101. kdebug("Got Error: %d", ret);
  102. goto out_unwait;
  103. case RXRPC_CSTATE_CLNT_GOT_REPLY:
  104. /* read the reply */
  105. kdebug("Got Reply: qty=%d", call->app_ready_qty);
  106. ret = -EBADMSG;
  107. if (call->app_ready_qty <= 4)
  108. goto abort;
  109. ret = rxrpc_call_read_data(call, NULL, call->app_ready_qty, 0);
  110. if (ret < 0)
  111. goto abort;
  112. #if 0
  113. /* unmarshall the reply */
  114. bp = buffer;
  115. for (loop = 0; loop < 65; loop++)
  116. entry->name[loop] = ntohl(*bp++);
  117. entry->name[64] = 0;
  118. entry->type = ntohl(*bp++);
  119. entry->num_servers = ntohl(*bp++);
  120. for (loop = 0; loop < 8; loop++)
  121. entry->servers[loop].addr.s_addr = *bp++;
  122. for (loop = 0; loop < 8; loop++)
  123. entry->servers[loop].partition = ntohl(*bp++);
  124. for (loop = 0; loop < 8; loop++)
  125. entry->servers[loop].flags = ntohl(*bp++);
  126. for (loop = 0; loop < 3; loop++)
  127. entry->volume_ids[loop] = ntohl(*bp++);
  128. entry->clone_id = ntohl(*bp++);
  129. entry->flags = ntohl(*bp);
  130. #endif
  131. /* success */
  132. ret = 0;
  133. goto out_unwait;
  134. default:
  135. BUG();
  136. }
  137. abort:
  138. set_current_state(TASK_UNINTERRUPTIBLE);
  139. rxrpc_call_abort(call, ret);
  140. schedule();
  141. out_unwait:
  142. set_current_state(TASK_RUNNING);
  143. remove_wait_queue(&call->waitq, &myself);
  144. rxrpc_put_call(call);
  145. out_put_conn:
  146. afs_server_release_fsconn(server, conn);
  147. out:
  148. kleave("");
  149. return ret;
  150. } /* end afs_rxfs_get_root_volume() */
  151. #endif
  152. /*****************************************************************************/
  153. /*
  154. * get information about a volume
  155. */
  156. #if 0
  157. int afs_rxfs_get_volume_info(struct afs_server *server,
  158. const char *name,
  159. struct afs_volume_info *vinfo)
  160. {
  161. struct rxrpc_connection *conn;
  162. struct rxrpc_call *call;
  163. struct kvec piov[3];
  164. size_t sent;
  165. int ret;
  166. u32 param[2], *bp, zero;
  167. DECLARE_WAITQUEUE(myself, current);
  168. _enter("%p,%s,%p", server, name, vinfo);
  169. /* get hold of the fileserver connection */
  170. ret = afs_server_get_fsconn(server, &conn);
  171. if (ret < 0)
  172. goto out;
  173. /* create a call through that connection */
  174. ret = rxrpc_create_call(conn, NULL, NULL, afs_rxfs_aemap, &call);
  175. if (ret < 0) {
  176. printk("kAFS: Unable to create call: %d\n", ret);
  177. goto out_put_conn;
  178. }
  179. call->app_opcode = FSGETVOLUMEINFO;
  180. /* we want to get event notifications from the call */
  181. add_wait_queue(&call->waitq, &myself);
  182. /* marshall the parameters */
  183. piov[1].iov_len = strlen(name);
  184. piov[1].iov_base = (char *) name;
  185. zero = 0;
  186. piov[2].iov_len = (4 - (piov[1].iov_len & 3)) & 3;
  187. piov[2].iov_base = &zero;
  188. param[0] = htonl(FSGETVOLUMEINFO);
  189. param[1] = htonl(piov[1].iov_len);
  190. piov[0].iov_len = sizeof(param);
  191. piov[0].iov_base = param;
  192. /* send the parameters to the server */
  193. ret = rxrpc_call_write_data(call, 3, piov, RXRPC_LAST_PACKET, GFP_NOFS,
  194. 0, &sent);
  195. if (ret < 0)
  196. goto abort;
  197. /* wait for the reply to completely arrive */
  198. bp = rxrpc_call_alloc_scratch(call, 64);
  199. ret = rxrpc_call_read_data(call, bp, 64,
  200. RXRPC_CALL_READ_BLOCK |
  201. RXRPC_CALL_READ_ALL);
  202. if (ret < 0) {
  203. if (ret == -ECONNABORTED) {
  204. ret = call->app_errno;
  205. goto out_unwait;
  206. }
  207. goto abort;
  208. }
  209. /* unmarshall the reply */
  210. vinfo->vid = ntohl(*bp++);
  211. vinfo->type = ntohl(*bp++);
  212. vinfo->type_vids[0] = ntohl(*bp++);
  213. vinfo->type_vids[1] = ntohl(*bp++);
  214. vinfo->type_vids[2] = ntohl(*bp++);
  215. vinfo->type_vids[3] = ntohl(*bp++);
  216. vinfo->type_vids[4] = ntohl(*bp++);
  217. vinfo->nservers = ntohl(*bp++);
  218. vinfo->servers[0].addr.s_addr = *bp++;
  219. vinfo->servers[1].addr.s_addr = *bp++;
  220. vinfo->servers[2].addr.s_addr = *bp++;
  221. vinfo->servers[3].addr.s_addr = *bp++;
  222. vinfo->servers[4].addr.s_addr = *bp++;
  223. vinfo->servers[5].addr.s_addr = *bp++;
  224. vinfo->servers[6].addr.s_addr = *bp++;
  225. vinfo->servers[7].addr.s_addr = *bp++;
  226. ret = -EBADMSG;
  227. if (vinfo->nservers > 8)
  228. goto abort;
  229. /* success */
  230. ret = 0;
  231. out_unwait:
  232. set_current_state(TASK_RUNNING);
  233. remove_wait_queue(&call->waitq, &myself);
  234. rxrpc_put_call(call);
  235. out_put_conn:
  236. afs_server_release_fsconn(server, conn);
  237. out:
  238. _leave("");
  239. return ret;
  240. abort:
  241. set_current_state(TASK_UNINTERRUPTIBLE);
  242. rxrpc_call_abort(call, ret);
  243. schedule();
  244. goto out_unwait;
  245. } /* end afs_rxfs_get_volume_info() */
  246. #endif
  247. /*****************************************************************************/
  248. /*
  249. * fetch the status information for a file
  250. */
  251. int afs_rxfs_fetch_file_status(struct afs_server *server,
  252. struct afs_vnode *vnode,
  253. struct afs_volsync *volsync)
  254. {
  255. struct afs_server_callslot callslot;
  256. struct rxrpc_call *call;
  257. struct kvec piov[1];
  258. size_t sent;
  259. int ret;
  260. __be32 *bp;
  261. DECLARE_WAITQUEUE(myself, current);
  262. _enter("%p,{%u,%u,%u}",
  263. server, vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
  264. /* get hold of the fileserver connection */
  265. ret = afs_server_request_callslot(server, &callslot);
  266. if (ret < 0)
  267. goto out;
  268. /* create a call through that connection */
  269. ret = rxrpc_create_call(callslot.conn, NULL, NULL, afs_rxfs_aemap,
  270. &call);
  271. if (ret < 0) {
  272. printk("kAFS: Unable to create call: %d\n", ret);
  273. goto out_put_conn;
  274. }
  275. call->app_opcode = FSFETCHSTATUS;
  276. /* we want to get event notifications from the call */
  277. add_wait_queue(&call->waitq, &myself);
  278. /* marshall the parameters */
  279. bp = rxrpc_call_alloc_scratch(call, 16);
  280. bp[0] = htonl(FSFETCHSTATUS);
  281. bp[1] = htonl(vnode->fid.vid);
  282. bp[2] = htonl(vnode->fid.vnode);
  283. bp[3] = htonl(vnode->fid.unique);
  284. piov[0].iov_len = 16;
  285. piov[0].iov_base = bp;
  286. /* send the parameters to the server */
  287. ret = rxrpc_call_write_data(call, 1, piov, RXRPC_LAST_PACKET, GFP_NOFS,
  288. 0, &sent);
  289. if (ret < 0)
  290. goto abort;
  291. /* wait for the reply to completely arrive */
  292. bp = rxrpc_call_alloc_scratch(call, 120);
  293. ret = rxrpc_call_read_data(call, bp, 120,
  294. RXRPC_CALL_READ_BLOCK |
  295. RXRPC_CALL_READ_ALL);
  296. if (ret < 0) {
  297. if (ret == -ECONNABORTED) {
  298. ret = call->app_errno;
  299. goto out_unwait;
  300. }
  301. goto abort;
  302. }
  303. /* unmarshall the reply */
  304. vnode->status.if_version = ntohl(*bp++);
  305. vnode->status.type = ntohl(*bp++);
  306. vnode->status.nlink = ntohl(*bp++);
  307. vnode->status.size = ntohl(*bp++);
  308. vnode->status.version = ntohl(*bp++);
  309. vnode->status.author = ntohl(*bp++);
  310. vnode->status.owner = ntohl(*bp++);
  311. vnode->status.caller_access = ntohl(*bp++);
  312. vnode->status.anon_access = ntohl(*bp++);
  313. vnode->status.mode = ntohl(*bp++);
  314. vnode->status.parent.vid = vnode->fid.vid;
  315. vnode->status.parent.vnode = ntohl(*bp++);
  316. vnode->status.parent.unique = ntohl(*bp++);
  317. bp++; /* seg size */
  318. vnode->status.mtime_client = ntohl(*bp++);
  319. vnode->status.mtime_server = ntohl(*bp++);
  320. bp++; /* group */
  321. bp++; /* sync counter */
  322. vnode->status.version |= ((unsigned long long) ntohl(*bp++)) << 32;
  323. bp++; /* spare2 */
  324. bp++; /* spare3 */
  325. bp++; /* spare4 */
  326. vnode->cb_version = ntohl(*bp++);
  327. vnode->cb_expiry = ntohl(*bp++);
  328. vnode->cb_type = ntohl(*bp++);
  329. if (volsync) {
  330. volsync->creation = ntohl(*bp++);
  331. bp++; /* spare2 */
  332. bp++; /* spare3 */
  333. bp++; /* spare4 */
  334. bp++; /* spare5 */
  335. bp++; /* spare6 */
  336. }
  337. /* success */
  338. ret = 0;
  339. out_unwait:
  340. set_current_state(TASK_RUNNING);
  341. remove_wait_queue(&call->waitq, &myself);
  342. rxrpc_put_call(call);
  343. out_put_conn:
  344. afs_server_release_callslot(server, &callslot);
  345. out:
  346. _leave("");
  347. return ret;
  348. abort:
  349. set_current_state(TASK_UNINTERRUPTIBLE);
  350. rxrpc_call_abort(call, ret);
  351. schedule();
  352. goto out_unwait;
  353. } /* end afs_rxfs_fetch_file_status() */
  354. /*****************************************************************************/
  355. /*
  356. * fetch the contents of a file or directory
  357. */
  358. int afs_rxfs_fetch_file_data(struct afs_server *server,
  359. struct afs_vnode *vnode,
  360. struct afs_rxfs_fetch_descriptor *desc,
  361. struct afs_volsync *volsync)
  362. {
  363. struct afs_server_callslot callslot;
  364. struct rxrpc_call *call;
  365. struct kvec piov[1];
  366. size_t sent;
  367. int ret;
  368. __be32 *bp;
  369. DECLARE_WAITQUEUE(myself, current);
  370. _enter("%p,{fid={%u,%u,%u},sz=%Zu,of=%lu}",
  371. server,
  372. desc->fid.vid,
  373. desc->fid.vnode,
  374. desc->fid.unique,
  375. desc->size,
  376. desc->offset);
  377. /* get hold of the fileserver connection */
  378. ret = afs_server_request_callslot(server, &callslot);
  379. if (ret < 0)
  380. goto out;
  381. /* create a call through that connection */
  382. ret = rxrpc_create_call(callslot.conn, NULL, NULL, afs_rxfs_aemap, &call);
  383. if (ret < 0) {
  384. printk("kAFS: Unable to create call: %d\n", ret);
  385. goto out_put_conn;
  386. }
  387. call->app_opcode = FSFETCHDATA;
  388. /* we want to get event notifications from the call */
  389. add_wait_queue(&call->waitq, &myself);
  390. /* marshall the parameters */
  391. bp = rxrpc_call_alloc_scratch(call, 24);
  392. bp[0] = htonl(FSFETCHDATA);
  393. bp[1] = htonl(desc->fid.vid);
  394. bp[2] = htonl(desc->fid.vnode);
  395. bp[3] = htonl(desc->fid.unique);
  396. bp[4] = htonl(desc->offset);
  397. bp[5] = htonl(desc->size);
  398. piov[0].iov_len = 24;
  399. piov[0].iov_base = bp;
  400. /* send the parameters to the server */
  401. ret = rxrpc_call_write_data(call, 1, piov, RXRPC_LAST_PACKET, GFP_NOFS,
  402. 0, &sent);
  403. if (ret < 0)
  404. goto abort;
  405. /* wait for the data count to arrive */
  406. ret = rxrpc_call_read_data(call, bp, 4, RXRPC_CALL_READ_BLOCK);
  407. if (ret < 0)
  408. goto read_failed;
  409. desc->actual = ntohl(bp[0]);
  410. if (desc->actual != desc->size) {
  411. ret = -EBADMSG;
  412. goto abort;
  413. }
  414. /* call the app to read the actual data */
  415. rxrpc_call_reset_scratch(call);
  416. ret = rxrpc_call_read_data(call, desc->buffer, desc->actual,
  417. RXRPC_CALL_READ_BLOCK);
  418. if (ret < 0)
  419. goto read_failed;
  420. /* wait for the rest of the reply to completely arrive */
  421. rxrpc_call_reset_scratch(call);
  422. bp = rxrpc_call_alloc_scratch(call, 120);
  423. ret = rxrpc_call_read_data(call, bp, 120,
  424. RXRPC_CALL_READ_BLOCK |
  425. RXRPC_CALL_READ_ALL);
  426. if (ret < 0)
  427. goto read_failed;
  428. /* unmarshall the reply */
  429. vnode->status.if_version = ntohl(*bp++);
  430. vnode->status.type = ntohl(*bp++);
  431. vnode->status.nlink = ntohl(*bp++);
  432. vnode->status.size = ntohl(*bp++);
  433. vnode->status.version = ntohl(*bp++);
  434. vnode->status.author = ntohl(*bp++);
  435. vnode->status.owner = ntohl(*bp++);
  436. vnode->status.caller_access = ntohl(*bp++);
  437. vnode->status.anon_access = ntohl(*bp++);
  438. vnode->status.mode = ntohl(*bp++);
  439. vnode->status.parent.vid = desc->fid.vid;
  440. vnode->status.parent.vnode = ntohl(*bp++);
  441. vnode->status.parent.unique = ntohl(*bp++);
  442. bp++; /* seg size */
  443. vnode->status.mtime_client = ntohl(*bp++);
  444. vnode->status.mtime_server = ntohl(*bp++);
  445. bp++; /* group */
  446. bp++; /* sync counter */
  447. vnode->status.version |= ((unsigned long long) ntohl(*bp++)) << 32;
  448. bp++; /* spare2 */
  449. bp++; /* spare3 */
  450. bp++; /* spare4 */
  451. vnode->cb_version = ntohl(*bp++);
  452. vnode->cb_expiry = ntohl(*bp++);
  453. vnode->cb_type = ntohl(*bp++);
  454. if (volsync) {
  455. volsync->creation = ntohl(*bp++);
  456. bp++; /* spare2 */
  457. bp++; /* spare3 */
  458. bp++; /* spare4 */
  459. bp++; /* spare5 */
  460. bp++; /* spare6 */
  461. }
  462. /* success */
  463. ret = 0;
  464. out_unwait:
  465. set_current_state(TASK_RUNNING);
  466. remove_wait_queue(&call->waitq,&myself);
  467. rxrpc_put_call(call);
  468. out_put_conn:
  469. afs_server_release_callslot(server, &callslot);
  470. out:
  471. _leave(" = %d", ret);
  472. return ret;
  473. read_failed:
  474. if (ret == -ECONNABORTED) {
  475. ret = call->app_errno;
  476. goto out_unwait;
  477. }
  478. abort:
  479. set_current_state(TASK_UNINTERRUPTIBLE);
  480. rxrpc_call_abort(call, ret);
  481. schedule();
  482. goto out_unwait;
  483. } /* end afs_rxfs_fetch_file_data() */
  484. /*****************************************************************************/
  485. /*
  486. * ask the AFS fileserver to discard a callback request on a file
  487. */
  488. int afs_rxfs_give_up_callback(struct afs_server *server,
  489. struct afs_vnode *vnode)
  490. {
  491. struct afs_server_callslot callslot;
  492. struct rxrpc_call *call;
  493. struct kvec piov[1];
  494. size_t sent;
  495. int ret;
  496. __be32 *bp;
  497. DECLARE_WAITQUEUE(myself, current);
  498. _enter("%p,{%u,%u,%u}",
  499. server, vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
  500. /* get hold of the fileserver connection */
  501. ret = afs_server_request_callslot(server, &callslot);
  502. if (ret < 0)
  503. goto out;
  504. /* create a call through that connection */
  505. ret = rxrpc_create_call(callslot.conn, NULL, NULL, afs_rxfs_aemap, &call);
  506. if (ret < 0) {
  507. printk("kAFS: Unable to create call: %d\n", ret);
  508. goto out_put_conn;
  509. }
  510. call->app_opcode = FSGIVEUPCALLBACKS;
  511. /* we want to get event notifications from the call */
  512. add_wait_queue(&call->waitq, &myself);
  513. /* marshall the parameters */
  514. bp = rxrpc_call_alloc_scratch(call, (1 + 4 + 4) * 4);
  515. piov[0].iov_len = (1 + 4 + 4) * 4;
  516. piov[0].iov_base = bp;
  517. *bp++ = htonl(FSGIVEUPCALLBACKS);
  518. *bp++ = htonl(1);
  519. *bp++ = htonl(vnode->fid.vid);
  520. *bp++ = htonl(vnode->fid.vnode);
  521. *bp++ = htonl(vnode->fid.unique);
  522. *bp++ = htonl(1);
  523. *bp++ = htonl(vnode->cb_version);
  524. *bp++ = htonl(vnode->cb_expiry);
  525. *bp++ = htonl(vnode->cb_type);
  526. /* send the parameters to the server */
  527. ret = rxrpc_call_write_data(call, 1, piov, RXRPC_LAST_PACKET, GFP_NOFS,
  528. 0, &sent);
  529. if (ret < 0)
  530. goto abort;
  531. /* wait for the reply to completely arrive */
  532. for (;;) {
  533. set_current_state(TASK_INTERRUPTIBLE);
  534. if (call->app_call_state != RXRPC_CSTATE_CLNT_RCV_REPLY ||
  535. signal_pending(current))
  536. break;
  537. schedule();
  538. }
  539. set_current_state(TASK_RUNNING);
  540. ret = -EINTR;
  541. if (signal_pending(current))
  542. goto abort;
  543. switch (call->app_call_state) {
  544. case RXRPC_CSTATE_ERROR:
  545. ret = call->app_errno;
  546. goto out_unwait;
  547. case RXRPC_CSTATE_CLNT_GOT_REPLY:
  548. ret = 0;
  549. goto out_unwait;
  550. default:
  551. BUG();
  552. }
  553. out_unwait:
  554. set_current_state(TASK_RUNNING);
  555. remove_wait_queue(&call->waitq, &myself);
  556. rxrpc_put_call(call);
  557. out_put_conn:
  558. afs_server_release_callslot(server, &callslot);
  559. out:
  560. _leave("");
  561. return ret;
  562. abort:
  563. set_current_state(TASK_UNINTERRUPTIBLE);
  564. rxrpc_call_abort(call, ret);
  565. schedule();
  566. goto out_unwait;
  567. } /* end afs_rxfs_give_up_callback() */
  568. /*****************************************************************************/
  569. /*
  570. * look a filename up in a directory
  571. * - this operation doesn't seem to work correctly in OpenAFS server 1.2.2
  572. */
  573. #if 0
  574. int afs_rxfs_lookup(struct afs_server *server,
  575. struct afs_vnode *dir,
  576. const char *filename,
  577. struct afs_vnode *vnode,
  578. struct afs_volsync *volsync)
  579. {
  580. struct rxrpc_connection *conn;
  581. struct rxrpc_call *call;
  582. struct kvec piov[3];
  583. size_t sent;
  584. int ret;
  585. u32 *bp, zero;
  586. DECLARE_WAITQUEUE(myself, current);
  587. kenter("%p,{%u,%u,%u},%s",
  588. server, fid->vid, fid->vnode, fid->unique, filename);
  589. /* get hold of the fileserver connection */
  590. ret = afs_server_get_fsconn(server, &conn);
  591. if (ret < 0)
  592. goto out;
  593. /* create a call through that connection */
  594. ret = rxrpc_create_call(conn, NULL, NULL, afs_rxfs_aemap, &call);
  595. if (ret < 0) {
  596. printk("kAFS: Unable to create call: %d\n", ret);
  597. goto out_put_conn;
  598. }
  599. call->app_opcode = FSLOOKUP;
  600. /* we want to get event notifications from the call */
  601. add_wait_queue(&call->waitq,&myself);
  602. /* marshall the parameters */
  603. bp = rxrpc_call_alloc_scratch(call, 20);
  604. zero = 0;
  605. piov[0].iov_len = 20;
  606. piov[0].iov_base = bp;
  607. piov[1].iov_len = strlen(filename);
  608. piov[1].iov_base = (char *) filename;
  609. piov[2].iov_len = (4 - (piov[1].iov_len & 3)) & 3;
  610. piov[2].iov_base = &zero;
  611. *bp++ = htonl(FSLOOKUP);
  612. *bp++ = htonl(dirfid->vid);
  613. *bp++ = htonl(dirfid->vnode);
  614. *bp++ = htonl(dirfid->unique);
  615. *bp++ = htonl(piov[1].iov_len);
  616. /* send the parameters to the server */
  617. ret = rxrpc_call_write_data(call, 3, piov, RXRPC_LAST_PACKET, GFP_NOFS,
  618. 0, &sent);
  619. if (ret < 0)
  620. goto abort;
  621. /* wait for the reply to completely arrive */
  622. bp = rxrpc_call_alloc_scratch(call, 220);
  623. ret = rxrpc_call_read_data(call, bp, 220,
  624. RXRPC_CALL_READ_BLOCK |
  625. RXRPC_CALL_READ_ALL);
  626. if (ret < 0) {
  627. if (ret == -ECONNABORTED) {
  628. ret = call->app_errno;
  629. goto out_unwait;
  630. }
  631. goto abort;
  632. }
  633. /* unmarshall the reply */
  634. fid->vid = ntohl(*bp++);
  635. fid->vnode = ntohl(*bp++);
  636. fid->unique = ntohl(*bp++);
  637. vnode->status.if_version = ntohl(*bp++);
  638. vnode->status.type = ntohl(*bp++);
  639. vnode->status.nlink = ntohl(*bp++);
  640. vnode->status.size = ntohl(*bp++);
  641. vnode->status.version = ntohl(*bp++);
  642. vnode->status.author = ntohl(*bp++);
  643. vnode->status.owner = ntohl(*bp++);
  644. vnode->status.caller_access = ntohl(*bp++);
  645. vnode->status.anon_access = ntohl(*bp++);
  646. vnode->status.mode = ntohl(*bp++);
  647. vnode->status.parent.vid = dirfid->vid;
  648. vnode->status.parent.vnode = ntohl(*bp++);
  649. vnode->status.parent.unique = ntohl(*bp++);
  650. bp++; /* seg size */
  651. vnode->status.mtime_client = ntohl(*bp++);
  652. vnode->status.mtime_server = ntohl(*bp++);
  653. bp++; /* group */
  654. bp++; /* sync counter */
  655. vnode->status.version |= ((unsigned long long) ntohl(*bp++)) << 32;
  656. bp++; /* spare2 */
  657. bp++; /* spare3 */
  658. bp++; /* spare4 */
  659. dir->status.if_version = ntohl(*bp++);
  660. dir->status.type = ntohl(*bp++);
  661. dir->status.nlink = ntohl(*bp++);
  662. dir->status.size = ntohl(*bp++);
  663. dir->status.version = ntohl(*bp++);
  664. dir->status.author = ntohl(*bp++);
  665. dir->status.owner = ntohl(*bp++);
  666. dir->status.caller_access = ntohl(*bp++);
  667. dir->status.anon_access = ntohl(*bp++);
  668. dir->status.mode = ntohl(*bp++);
  669. dir->status.parent.vid = dirfid->vid;
  670. dir->status.parent.vnode = ntohl(*bp++);
  671. dir->status.parent.unique = ntohl(*bp++);
  672. bp++; /* seg size */
  673. dir->status.mtime_client = ntohl(*bp++);
  674. dir->status.mtime_server = ntohl(*bp++);
  675. bp++; /* group */
  676. bp++; /* sync counter */
  677. dir->status.version |= ((unsigned long long) ntohl(*bp++)) << 32;
  678. bp++; /* spare2 */
  679. bp++; /* spare3 */
  680. bp++; /* spare4 */
  681. callback->fid = *fid;
  682. callback->version = ntohl(*bp++);
  683. callback->expiry = ntohl(*bp++);
  684. callback->type = ntohl(*bp++);
  685. if (volsync) {
  686. volsync->creation = ntohl(*bp++);
  687. bp++; /* spare2 */
  688. bp++; /* spare3 */
  689. bp++; /* spare4 */
  690. bp++; /* spare5 */
  691. bp++; /* spare6 */
  692. }
  693. /* success */
  694. ret = 0;
  695. out_unwait:
  696. set_current_state(TASK_RUNNING);
  697. remove_wait_queue(&call->waitq, &myself);
  698. rxrpc_put_call(call);
  699. out_put_conn:
  700. afs_server_release_fsconn(server, conn);
  701. out:
  702. kleave("");
  703. return ret;
  704. abort:
  705. set_current_state(TASK_UNINTERRUPTIBLE);
  706. rxrpc_call_abort(call, ret);
  707. schedule();
  708. goto out_unwait;
  709. } /* end afs_rxfs_lookup() */
  710. #endif