clnt.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. /*
  2. * linux/net/sunrpc/clnt.c
  3. *
  4. * This file contains the high-level RPC interface.
  5. * It is modeled as a finite state machine to support both synchronous
  6. * and asynchronous requests.
  7. *
  8. * - RPC header generation and argument serialization.
  9. * - Credential refresh.
  10. * - TCP connect handling.
  11. * - Retry of operation when it is suspected the operation failed because
  12. * of uid squashing on the server, or when the credentials were stale
  13. * and need to be refreshed, or when a packet was damaged in transit.
  14. * This may be have to be moved to the VFS layer.
  15. *
  16. * NB: BSD uses a more intelligent approach to guessing when a request
  17. * or reply has been lost by keeping the RTO estimate for each procedure.
  18. * We currently make do with a constant timeout value.
  19. *
  20. * Copyright (C) 1992,1993 Rick Sladkey <jrs@world.std.com>
  21. * Copyright (C) 1995,1996 Olaf Kirch <okir@monad.swb.de>
  22. */
  23. #include <asm/system.h>
  24. #include <linux/module.h>
  25. #include <linux/types.h>
  26. #include <linux/mm.h>
  27. #include <linux/slab.h>
  28. #include <linux/utsname.h>
  29. #include <linux/workqueue.h>
  30. #include <linux/sunrpc/clnt.h>
  31. #include <linux/sunrpc/rpc_pipe_fs.h>
  32. #include <linux/sunrpc/metrics.h>
  33. #define RPC_SLACK_SPACE (1024) /* total overkill */
  34. #ifdef RPC_DEBUG
  35. # define RPCDBG_FACILITY RPCDBG_CALL
  36. #endif
  37. static DECLARE_WAIT_QUEUE_HEAD(destroy_wait);
  38. static void call_start(struct rpc_task *task);
  39. static void call_reserve(struct rpc_task *task);
  40. static void call_reserveresult(struct rpc_task *task);
  41. static void call_allocate(struct rpc_task *task);
  42. static void call_encode(struct rpc_task *task);
  43. static void call_decode(struct rpc_task *task);
  44. static void call_bind(struct rpc_task *task);
  45. static void call_bind_status(struct rpc_task *task);
  46. static void call_transmit(struct rpc_task *task);
  47. static void call_status(struct rpc_task *task);
  48. static void call_transmit_status(struct rpc_task *task);
  49. static void call_refresh(struct rpc_task *task);
  50. static void call_refreshresult(struct rpc_task *task);
  51. static void call_timeout(struct rpc_task *task);
  52. static void call_connect(struct rpc_task *task);
  53. static void call_connect_status(struct rpc_task *task);
  54. static u32 * call_header(struct rpc_task *task);
  55. static u32 * call_verify(struct rpc_task *task);
  56. static int
  57. rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name)
  58. {
  59. static uint32_t clntid;
  60. int error;
  61. clnt->cl_vfsmnt = ERR_PTR(-ENOENT);
  62. clnt->cl_dentry = ERR_PTR(-ENOENT);
  63. if (dir_name == NULL)
  64. return 0;
  65. clnt->cl_vfsmnt = rpc_get_mount();
  66. if (IS_ERR(clnt->cl_vfsmnt))
  67. return PTR_ERR(clnt->cl_vfsmnt);
  68. for (;;) {
  69. snprintf(clnt->cl_pathname, sizeof(clnt->cl_pathname),
  70. "%s/clnt%x", dir_name,
  71. (unsigned int)clntid++);
  72. clnt->cl_pathname[sizeof(clnt->cl_pathname) - 1] = '\0';
  73. clnt->cl_dentry = rpc_mkdir(clnt->cl_pathname, clnt);
  74. if (!IS_ERR(clnt->cl_dentry))
  75. return 0;
  76. error = PTR_ERR(clnt->cl_dentry);
  77. if (error != -EEXIST) {
  78. printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n",
  79. clnt->cl_pathname, error);
  80. rpc_put_mount();
  81. return error;
  82. }
  83. }
  84. }
  85. /*
  86. * Create an RPC client
  87. * FIXME: This should also take a flags argument (as in task->tk_flags).
  88. * It's called (among others) from pmap_create_client, which may in
  89. * turn be called by an async task. In this case, rpciod should not be
  90. * made to sleep too long.
  91. */
  92. struct rpc_clnt *
  93. rpc_new_client(struct rpc_xprt *xprt, char *servname,
  94. struct rpc_program *program, u32 vers,
  95. rpc_authflavor_t flavor)
  96. {
  97. struct rpc_version *version;
  98. struct rpc_clnt *clnt = NULL;
  99. struct rpc_auth *auth;
  100. int err;
  101. int len;
  102. dprintk("RPC: creating %s client for %s (xprt %p)\n",
  103. program->name, servname, xprt);
  104. err = -EINVAL;
  105. if (!xprt)
  106. goto out_no_xprt;
  107. if (vers >= program->nrvers || !(version = program->version[vers]))
  108. goto out_err;
  109. err = -ENOMEM;
  110. clnt = kzalloc(sizeof(*clnt), GFP_KERNEL);
  111. if (!clnt)
  112. goto out_err;
  113. atomic_set(&clnt->cl_users, 0);
  114. atomic_set(&clnt->cl_count, 1);
  115. clnt->cl_parent = clnt;
  116. clnt->cl_server = clnt->cl_inline_name;
  117. len = strlen(servname) + 1;
  118. if (len > sizeof(clnt->cl_inline_name)) {
  119. char *buf = kmalloc(len, GFP_KERNEL);
  120. if (buf != 0)
  121. clnt->cl_server = buf;
  122. else
  123. len = sizeof(clnt->cl_inline_name);
  124. }
  125. strlcpy(clnt->cl_server, servname, len);
  126. clnt->cl_xprt = xprt;
  127. clnt->cl_procinfo = version->procs;
  128. clnt->cl_maxproc = version->nrprocs;
  129. clnt->cl_protname = program->name;
  130. clnt->cl_pmap = &clnt->cl_pmap_default;
  131. clnt->cl_prog = program->number;
  132. clnt->cl_vers = version->number;
  133. clnt->cl_prot = xprt->prot;
  134. clnt->cl_stats = program->stats;
  135. clnt->cl_metrics = rpc_alloc_iostats(clnt);
  136. rpc_init_wait_queue(&clnt->cl_pmap_default.pm_bindwait, "bindwait");
  137. if (!xprt_bound(clnt->cl_xprt))
  138. clnt->cl_autobind = 1;
  139. clnt->cl_rtt = &clnt->cl_rtt_default;
  140. rpc_init_rtt(&clnt->cl_rtt_default, xprt->timeout.to_initval);
  141. err = rpc_setup_pipedir(clnt, program->pipe_dir_name);
  142. if (err < 0)
  143. goto out_no_path;
  144. auth = rpcauth_create(flavor, clnt);
  145. if (IS_ERR(auth)) {
  146. printk(KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n",
  147. flavor);
  148. err = PTR_ERR(auth);
  149. goto out_no_auth;
  150. }
  151. /* save the nodename */
  152. clnt->cl_nodelen = strlen(system_utsname.nodename);
  153. if (clnt->cl_nodelen > UNX_MAXNODENAME)
  154. clnt->cl_nodelen = UNX_MAXNODENAME;
  155. memcpy(clnt->cl_nodename, system_utsname.nodename, clnt->cl_nodelen);
  156. return clnt;
  157. out_no_auth:
  158. if (!IS_ERR(clnt->cl_dentry)) {
  159. rpc_rmdir(clnt->cl_dentry);
  160. rpc_put_mount();
  161. }
  162. out_no_path:
  163. if (clnt->cl_server != clnt->cl_inline_name)
  164. kfree(clnt->cl_server);
  165. kfree(clnt);
  166. out_err:
  167. xprt_destroy(xprt);
  168. out_no_xprt:
  169. return ERR_PTR(err);
  170. }
  171. /**
  172. * Create an RPC client
  173. * @xprt - pointer to xprt struct
  174. * @servname - name of server
  175. * @info - rpc_program
  176. * @version - rpc_program version
  177. * @authflavor - rpc_auth flavour to use
  178. *
  179. * Creates an RPC client structure, then pings the server in order to
  180. * determine if it is up, and if it supports this program and version.
  181. *
  182. * This function should never be called by asynchronous tasks such as
  183. * the portmapper.
  184. */
  185. struct rpc_clnt *rpc_create_client(struct rpc_xprt *xprt, char *servname,
  186. struct rpc_program *info, u32 version, rpc_authflavor_t authflavor)
  187. {
  188. struct rpc_clnt *clnt;
  189. int err;
  190. clnt = rpc_new_client(xprt, servname, info, version, authflavor);
  191. if (IS_ERR(clnt))
  192. return clnt;
  193. err = rpc_ping(clnt, RPC_TASK_SOFT|RPC_TASK_NOINTR);
  194. if (err == 0)
  195. return clnt;
  196. rpc_shutdown_client(clnt);
  197. return ERR_PTR(err);
  198. }
  199. /*
  200. * This function clones the RPC client structure. It allows us to share the
  201. * same transport while varying parameters such as the authentication
  202. * flavour.
  203. */
  204. struct rpc_clnt *
  205. rpc_clone_client(struct rpc_clnt *clnt)
  206. {
  207. struct rpc_clnt *new;
  208. new = kmalloc(sizeof(*new), GFP_KERNEL);
  209. if (!new)
  210. goto out_no_clnt;
  211. memcpy(new, clnt, sizeof(*new));
  212. atomic_set(&new->cl_count, 1);
  213. atomic_set(&new->cl_users, 0);
  214. new->cl_parent = clnt;
  215. atomic_inc(&clnt->cl_count);
  216. /* Duplicate portmapper */
  217. rpc_init_wait_queue(&new->cl_pmap_default.pm_bindwait, "bindwait");
  218. /* Turn off autobind on clones */
  219. new->cl_autobind = 0;
  220. new->cl_oneshot = 0;
  221. new->cl_dead = 0;
  222. if (!IS_ERR(new->cl_dentry))
  223. dget(new->cl_dentry);
  224. rpc_init_rtt(&new->cl_rtt_default, clnt->cl_xprt->timeout.to_initval);
  225. if (new->cl_auth)
  226. atomic_inc(&new->cl_auth->au_count);
  227. new->cl_pmap = &new->cl_pmap_default;
  228. new->cl_metrics = rpc_alloc_iostats(clnt);
  229. return new;
  230. out_no_clnt:
  231. printk(KERN_INFO "RPC: out of memory in %s\n", __FUNCTION__);
  232. return ERR_PTR(-ENOMEM);
  233. }
  234. /*
  235. * Properly shut down an RPC client, terminating all outstanding
  236. * requests. Note that we must be certain that cl_oneshot and
  237. * cl_dead are cleared, or else the client would be destroyed
  238. * when the last task releases it.
  239. */
  240. int
  241. rpc_shutdown_client(struct rpc_clnt *clnt)
  242. {
  243. dprintk("RPC: shutting down %s client for %s, tasks=%d\n",
  244. clnt->cl_protname, clnt->cl_server,
  245. atomic_read(&clnt->cl_users));
  246. while (atomic_read(&clnt->cl_users) > 0) {
  247. /* Don't let rpc_release_client destroy us */
  248. clnt->cl_oneshot = 0;
  249. clnt->cl_dead = 0;
  250. rpc_killall_tasks(clnt);
  251. wait_event_timeout(destroy_wait,
  252. !atomic_read(&clnt->cl_users), 1*HZ);
  253. }
  254. if (atomic_read(&clnt->cl_users) < 0) {
  255. printk(KERN_ERR "RPC: rpc_shutdown_client clnt %p tasks=%d\n",
  256. clnt, atomic_read(&clnt->cl_users));
  257. #ifdef RPC_DEBUG
  258. rpc_show_tasks();
  259. #endif
  260. BUG();
  261. }
  262. return rpc_destroy_client(clnt);
  263. }
  264. /*
  265. * Delete an RPC client
  266. */
  267. int
  268. rpc_destroy_client(struct rpc_clnt *clnt)
  269. {
  270. if (!atomic_dec_and_test(&clnt->cl_count))
  271. return 1;
  272. BUG_ON(atomic_read(&clnt->cl_users) != 0);
  273. dprintk("RPC: destroying %s client for %s\n",
  274. clnt->cl_protname, clnt->cl_server);
  275. if (clnt->cl_auth) {
  276. rpcauth_destroy(clnt->cl_auth);
  277. clnt->cl_auth = NULL;
  278. }
  279. if (clnt->cl_parent != clnt) {
  280. if (!IS_ERR(clnt->cl_dentry))
  281. dput(clnt->cl_dentry);
  282. rpc_destroy_client(clnt->cl_parent);
  283. goto out_free;
  284. }
  285. if (!IS_ERR(clnt->cl_dentry)) {
  286. rpc_rmdir(clnt->cl_dentry);
  287. rpc_put_mount();
  288. }
  289. if (clnt->cl_xprt) {
  290. xprt_destroy(clnt->cl_xprt);
  291. clnt->cl_xprt = NULL;
  292. }
  293. if (clnt->cl_server != clnt->cl_inline_name)
  294. kfree(clnt->cl_server);
  295. out_free:
  296. rpc_free_iostats(clnt->cl_metrics);
  297. clnt->cl_metrics = NULL;
  298. kfree(clnt);
  299. return 0;
  300. }
  301. /*
  302. * Release an RPC client
  303. */
  304. void
  305. rpc_release_client(struct rpc_clnt *clnt)
  306. {
  307. dprintk("RPC: rpc_release_client(%p, %d)\n",
  308. clnt, atomic_read(&clnt->cl_users));
  309. if (!atomic_dec_and_test(&clnt->cl_users))
  310. return;
  311. wake_up(&destroy_wait);
  312. if (clnt->cl_oneshot || clnt->cl_dead)
  313. rpc_destroy_client(clnt);
  314. }
  315. /**
  316. * rpc_bind_new_program - bind a new RPC program to an existing client
  317. * @old - old rpc_client
  318. * @program - rpc program to set
  319. * @vers - rpc program version
  320. *
  321. * Clones the rpc client and sets up a new RPC program. This is mainly
  322. * of use for enabling different RPC programs to share the same transport.
  323. * The Sun NFSv2/v3 ACL protocol can do this.
  324. */
  325. struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old,
  326. struct rpc_program *program,
  327. int vers)
  328. {
  329. struct rpc_clnt *clnt;
  330. struct rpc_version *version;
  331. int err;
  332. BUG_ON(vers >= program->nrvers || !program->version[vers]);
  333. version = program->version[vers];
  334. clnt = rpc_clone_client(old);
  335. if (IS_ERR(clnt))
  336. goto out;
  337. clnt->cl_procinfo = version->procs;
  338. clnt->cl_maxproc = version->nrprocs;
  339. clnt->cl_protname = program->name;
  340. clnt->cl_prog = program->number;
  341. clnt->cl_vers = version->number;
  342. clnt->cl_stats = program->stats;
  343. err = rpc_ping(clnt, RPC_TASK_SOFT|RPC_TASK_NOINTR);
  344. if (err != 0) {
  345. rpc_shutdown_client(clnt);
  346. clnt = ERR_PTR(err);
  347. }
  348. out:
  349. return clnt;
  350. }
  351. /*
  352. * Default callback for async RPC calls
  353. */
  354. static void
  355. rpc_default_callback(struct rpc_task *task, void *data)
  356. {
  357. }
  358. static const struct rpc_call_ops rpc_default_ops = {
  359. .rpc_call_done = rpc_default_callback,
  360. };
  361. /*
  362. * Export the signal mask handling for synchronous code that
  363. * sleeps on RPC calls
  364. */
  365. #define RPC_INTR_SIGNALS (sigmask(SIGHUP) | sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGTERM))
  366. static void rpc_save_sigmask(sigset_t *oldset, int intr)
  367. {
  368. unsigned long sigallow = sigmask(SIGKILL);
  369. sigset_t sigmask;
  370. /* Block all signals except those listed in sigallow */
  371. if (intr)
  372. sigallow |= RPC_INTR_SIGNALS;
  373. siginitsetinv(&sigmask, sigallow);
  374. sigprocmask(SIG_BLOCK, &sigmask, oldset);
  375. }
  376. static inline void rpc_task_sigmask(struct rpc_task *task, sigset_t *oldset)
  377. {
  378. rpc_save_sigmask(oldset, !RPC_TASK_UNINTERRUPTIBLE(task));
  379. }
  380. static inline void rpc_restore_sigmask(sigset_t *oldset)
  381. {
  382. sigprocmask(SIG_SETMASK, oldset, NULL);
  383. }
  384. void rpc_clnt_sigmask(struct rpc_clnt *clnt, sigset_t *oldset)
  385. {
  386. rpc_save_sigmask(oldset, clnt->cl_intr);
  387. }
  388. void rpc_clnt_sigunmask(struct rpc_clnt *clnt, sigset_t *oldset)
  389. {
  390. rpc_restore_sigmask(oldset);
  391. }
  392. /*
  393. * New rpc_call implementation
  394. */
  395. int rpc_call_sync(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
  396. {
  397. struct rpc_task *task;
  398. sigset_t oldset;
  399. int status;
  400. /* If this client is slain all further I/O fails */
  401. if (clnt->cl_dead)
  402. return -EIO;
  403. BUG_ON(flags & RPC_TASK_ASYNC);
  404. status = -ENOMEM;
  405. task = rpc_new_task(clnt, flags, &rpc_default_ops, NULL);
  406. if (task == NULL)
  407. goto out;
  408. /* Mask signals on RPC calls _and_ GSS_AUTH upcalls */
  409. rpc_task_sigmask(task, &oldset);
  410. rpc_call_setup(task, msg, 0);
  411. /* Set up the call info struct and execute the task */
  412. status = task->tk_status;
  413. if (status == 0) {
  414. atomic_inc(&task->tk_count);
  415. status = rpc_execute(task);
  416. if (status == 0)
  417. status = task->tk_status;
  418. }
  419. rpc_restore_sigmask(&oldset);
  420. rpc_release_task(task);
  421. out:
  422. return status;
  423. }
  424. /*
  425. * New rpc_call implementation
  426. */
  427. int
  428. rpc_call_async(struct rpc_clnt *clnt, struct rpc_message *msg, int flags,
  429. const struct rpc_call_ops *tk_ops, void *data)
  430. {
  431. struct rpc_task *task;
  432. sigset_t oldset;
  433. int status;
  434. /* If this client is slain all further I/O fails */
  435. status = -EIO;
  436. if (clnt->cl_dead)
  437. goto out_release;
  438. flags |= RPC_TASK_ASYNC;
  439. /* Create/initialize a new RPC task */
  440. status = -ENOMEM;
  441. if (!(task = rpc_new_task(clnt, flags, tk_ops, data)))
  442. goto out_release;
  443. /* Mask signals on GSS_AUTH upcalls */
  444. rpc_task_sigmask(task, &oldset);
  445. rpc_call_setup(task, msg, 0);
  446. /* Set up the call info struct and execute the task */
  447. status = task->tk_status;
  448. if (status == 0)
  449. rpc_execute(task);
  450. else
  451. rpc_release_task(task);
  452. rpc_restore_sigmask(&oldset);
  453. return status;
  454. out_release:
  455. if (tk_ops->rpc_release != NULL)
  456. tk_ops->rpc_release(data);
  457. return status;
  458. }
  459. void
  460. rpc_call_setup(struct rpc_task *task, struct rpc_message *msg, int flags)
  461. {
  462. task->tk_msg = *msg;
  463. task->tk_flags |= flags;
  464. /* Bind the user cred */
  465. if (task->tk_msg.rpc_cred != NULL)
  466. rpcauth_holdcred(task);
  467. else
  468. rpcauth_bindcred(task);
  469. if (task->tk_status == 0)
  470. task->tk_action = call_start;
  471. else
  472. task->tk_action = rpc_exit_task;
  473. }
  474. void
  475. rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize)
  476. {
  477. struct rpc_xprt *xprt = clnt->cl_xprt;
  478. if (xprt->ops->set_buffer_size)
  479. xprt->ops->set_buffer_size(xprt, sndsize, rcvsize);
  480. }
  481. /*
  482. * Return size of largest payload RPC client can support, in bytes
  483. *
  484. * For stream transports, this is one RPC record fragment (see RFC
  485. * 1831), as we don't support multi-record requests yet. For datagram
  486. * transports, this is the size of an IP packet minus the IP, UDP, and
  487. * RPC header sizes.
  488. */
  489. size_t rpc_max_payload(struct rpc_clnt *clnt)
  490. {
  491. return clnt->cl_xprt->max_payload;
  492. }
  493. EXPORT_SYMBOL(rpc_max_payload);
  494. /**
  495. * rpc_force_rebind - force transport to check that remote port is unchanged
  496. * @clnt: client to rebind
  497. *
  498. */
  499. void rpc_force_rebind(struct rpc_clnt *clnt)
  500. {
  501. if (clnt->cl_autobind)
  502. xprt_clear_bound(clnt->cl_xprt);
  503. }
  504. EXPORT_SYMBOL(rpc_force_rebind);
  505. /*
  506. * Restart an (async) RPC call. Usually called from within the
  507. * exit handler.
  508. */
  509. void
  510. rpc_restart_call(struct rpc_task *task)
  511. {
  512. if (RPC_ASSASSINATED(task))
  513. return;
  514. task->tk_action = call_start;
  515. }
  516. /*
  517. * 0. Initial state
  518. *
  519. * Other FSM states can be visited zero or more times, but
  520. * this state is visited exactly once for each RPC.
  521. */
  522. static void
  523. call_start(struct rpc_task *task)
  524. {
  525. struct rpc_clnt *clnt = task->tk_client;
  526. dprintk("RPC: %4d call_start %s%d proc %d (%s)\n", task->tk_pid,
  527. clnt->cl_protname, clnt->cl_vers, task->tk_msg.rpc_proc->p_proc,
  528. (RPC_IS_ASYNC(task) ? "async" : "sync"));
  529. /* Increment call count */
  530. task->tk_msg.rpc_proc->p_count++;
  531. clnt->cl_stats->rpccnt++;
  532. task->tk_action = call_reserve;
  533. }
  534. /*
  535. * 1. Reserve an RPC call slot
  536. */
  537. static void
  538. call_reserve(struct rpc_task *task)
  539. {
  540. dprintk("RPC: %4d call_reserve\n", task->tk_pid);
  541. if (!rpcauth_uptodatecred(task)) {
  542. task->tk_action = call_refresh;
  543. return;
  544. }
  545. task->tk_status = 0;
  546. task->tk_action = call_reserveresult;
  547. xprt_reserve(task);
  548. }
  549. /*
  550. * 1b. Grok the result of xprt_reserve()
  551. */
  552. static void
  553. call_reserveresult(struct rpc_task *task)
  554. {
  555. int status = task->tk_status;
  556. dprintk("RPC: %4d call_reserveresult (status %d)\n",
  557. task->tk_pid, task->tk_status);
  558. /*
  559. * After a call to xprt_reserve(), we must have either
  560. * a request slot or else an error status.
  561. */
  562. task->tk_status = 0;
  563. if (status >= 0) {
  564. if (task->tk_rqstp) {
  565. task->tk_action = call_allocate;
  566. return;
  567. }
  568. printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n",
  569. __FUNCTION__, status);
  570. rpc_exit(task, -EIO);
  571. return;
  572. }
  573. /*
  574. * Even though there was an error, we may have acquired
  575. * a request slot somehow. Make sure not to leak it.
  576. */
  577. if (task->tk_rqstp) {
  578. printk(KERN_ERR "%s: status=%d, request allocated anyway\n",
  579. __FUNCTION__, status);
  580. xprt_release(task);
  581. }
  582. switch (status) {
  583. case -EAGAIN: /* woken up; retry */
  584. task->tk_action = call_reserve;
  585. return;
  586. case -EIO: /* probably a shutdown */
  587. break;
  588. default:
  589. printk(KERN_ERR "%s: unrecognized error %d, exiting\n",
  590. __FUNCTION__, status);
  591. break;
  592. }
  593. rpc_exit(task, status);
  594. }
  595. /*
  596. * 2. Allocate the buffer. For details, see sched.c:rpc_malloc.
  597. * (Note: buffer memory is freed in xprt_release).
  598. */
  599. static void
  600. call_allocate(struct rpc_task *task)
  601. {
  602. struct rpc_rqst *req = task->tk_rqstp;
  603. struct rpc_xprt *xprt = task->tk_xprt;
  604. unsigned int bufsiz;
  605. dprintk("RPC: %4d call_allocate (status %d)\n",
  606. task->tk_pid, task->tk_status);
  607. task->tk_action = call_bind;
  608. if (req->rq_buffer)
  609. return;
  610. /* FIXME: compute buffer requirements more exactly using
  611. * auth->au_wslack */
  612. bufsiz = task->tk_msg.rpc_proc->p_bufsiz + RPC_SLACK_SPACE;
  613. if (xprt->ops->buf_alloc(task, bufsiz << 1) != NULL)
  614. return;
  615. printk(KERN_INFO "RPC: buffer allocation failed for task %p\n", task);
  616. if (RPC_IS_ASYNC(task) || !signalled()) {
  617. xprt_release(task);
  618. task->tk_action = call_reserve;
  619. rpc_delay(task, HZ>>4);
  620. return;
  621. }
  622. rpc_exit(task, -ERESTARTSYS);
  623. }
  624. static inline int
  625. rpc_task_need_encode(struct rpc_task *task)
  626. {
  627. return task->tk_rqstp->rq_snd_buf.len == 0;
  628. }
  629. static inline void
  630. rpc_task_force_reencode(struct rpc_task *task)
  631. {
  632. task->tk_rqstp->rq_snd_buf.len = 0;
  633. }
  634. /*
  635. * 3. Encode arguments of an RPC call
  636. */
  637. static void
  638. call_encode(struct rpc_task *task)
  639. {
  640. struct rpc_rqst *req = task->tk_rqstp;
  641. struct xdr_buf *sndbuf = &req->rq_snd_buf;
  642. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  643. unsigned int bufsiz;
  644. kxdrproc_t encode;
  645. u32 *p;
  646. dprintk("RPC: %4d call_encode (status %d)\n",
  647. task->tk_pid, task->tk_status);
  648. /* Default buffer setup */
  649. bufsiz = req->rq_bufsize >> 1;
  650. sndbuf->head[0].iov_base = (void *)req->rq_buffer;
  651. sndbuf->head[0].iov_len = bufsiz;
  652. sndbuf->tail[0].iov_len = 0;
  653. sndbuf->page_len = 0;
  654. sndbuf->len = 0;
  655. sndbuf->buflen = bufsiz;
  656. rcvbuf->head[0].iov_base = (void *)((char *)req->rq_buffer + bufsiz);
  657. rcvbuf->head[0].iov_len = bufsiz;
  658. rcvbuf->tail[0].iov_len = 0;
  659. rcvbuf->page_len = 0;
  660. rcvbuf->len = 0;
  661. rcvbuf->buflen = bufsiz;
  662. /* Encode header and provided arguments */
  663. encode = task->tk_msg.rpc_proc->p_encode;
  664. if (!(p = call_header(task))) {
  665. printk(KERN_INFO "RPC: call_header failed, exit EIO\n");
  666. rpc_exit(task, -EIO);
  667. return;
  668. }
  669. if (encode == NULL)
  670. return;
  671. task->tk_status = rpcauth_wrap_req(task, encode, req, p,
  672. task->tk_msg.rpc_argp);
  673. if (task->tk_status == -ENOMEM) {
  674. /* XXX: Is this sane? */
  675. rpc_delay(task, 3*HZ);
  676. task->tk_status = -EAGAIN;
  677. }
  678. }
  679. /*
  680. * 4. Get the server port number if not yet set
  681. */
  682. static void
  683. call_bind(struct rpc_task *task)
  684. {
  685. struct rpc_clnt *clnt = task->tk_client;
  686. struct rpc_xprt *xprt = task->tk_xprt;
  687. dprintk("RPC: %4d call_bind (status %d)\n",
  688. task->tk_pid, task->tk_status);
  689. task->tk_action = call_connect;
  690. if (!xprt_bound(xprt)) {
  691. task->tk_action = call_bind_status;
  692. task->tk_timeout = xprt->bind_timeout;
  693. rpc_getport(task, clnt);
  694. }
  695. }
  696. /*
  697. * 4a. Sort out bind result
  698. */
  699. static void
  700. call_bind_status(struct rpc_task *task)
  701. {
  702. int status = -EACCES;
  703. if (task->tk_status >= 0) {
  704. dprintk("RPC: %4d call_bind_status (status %d)\n",
  705. task->tk_pid, task->tk_status);
  706. task->tk_status = 0;
  707. task->tk_action = call_connect;
  708. return;
  709. }
  710. switch (task->tk_status) {
  711. case -EACCES:
  712. dprintk("RPC: %4d remote rpcbind: RPC program/version unavailable\n",
  713. task->tk_pid);
  714. rpc_delay(task, 3*HZ);
  715. goto retry_bind;
  716. case -ETIMEDOUT:
  717. dprintk("RPC: %4d rpcbind request timed out\n",
  718. task->tk_pid);
  719. if (RPC_IS_SOFT(task)) {
  720. status = -EIO;
  721. break;
  722. }
  723. goto retry_bind;
  724. case -EPFNOSUPPORT:
  725. dprintk("RPC: %4d remote rpcbind service unavailable\n",
  726. task->tk_pid);
  727. break;
  728. case -EPROTONOSUPPORT:
  729. dprintk("RPC: %4d remote rpcbind version 2 unavailable\n",
  730. task->tk_pid);
  731. break;
  732. default:
  733. dprintk("RPC: %4d unrecognized rpcbind error (%d)\n",
  734. task->tk_pid, -task->tk_status);
  735. status = -EIO;
  736. break;
  737. }
  738. rpc_exit(task, status);
  739. return;
  740. retry_bind:
  741. task->tk_status = 0;
  742. task->tk_action = call_bind;
  743. return;
  744. }
  745. /*
  746. * 4b. Connect to the RPC server
  747. */
  748. static void
  749. call_connect(struct rpc_task *task)
  750. {
  751. struct rpc_xprt *xprt = task->tk_xprt;
  752. dprintk("RPC: %4d call_connect xprt %p %s connected\n",
  753. task->tk_pid, xprt,
  754. (xprt_connected(xprt) ? "is" : "is not"));
  755. task->tk_action = call_transmit;
  756. if (!xprt_connected(xprt)) {
  757. task->tk_action = call_connect_status;
  758. if (task->tk_status < 0)
  759. return;
  760. xprt_connect(task);
  761. }
  762. }
  763. /*
  764. * 4c. Sort out connect result
  765. */
  766. static void
  767. call_connect_status(struct rpc_task *task)
  768. {
  769. struct rpc_clnt *clnt = task->tk_client;
  770. int status = task->tk_status;
  771. dprintk("RPC: %5u call_connect_status (status %d)\n",
  772. task->tk_pid, task->tk_status);
  773. task->tk_status = 0;
  774. if (status >= 0) {
  775. clnt->cl_stats->netreconn++;
  776. task->tk_action = call_transmit;
  777. return;
  778. }
  779. /* Something failed: remote service port may have changed */
  780. rpc_force_rebind(clnt);
  781. switch (status) {
  782. case -ENOTCONN:
  783. case -ETIMEDOUT:
  784. case -EAGAIN:
  785. task->tk_action = call_bind;
  786. break;
  787. default:
  788. rpc_exit(task, -EIO);
  789. break;
  790. }
  791. }
  792. /*
  793. * 5. Transmit the RPC request, and wait for reply
  794. */
  795. static void
  796. call_transmit(struct rpc_task *task)
  797. {
  798. dprintk("RPC: %4d call_transmit (status %d)\n",
  799. task->tk_pid, task->tk_status);
  800. task->tk_action = call_status;
  801. if (task->tk_status < 0)
  802. return;
  803. task->tk_status = xprt_prepare_transmit(task);
  804. if (task->tk_status != 0)
  805. return;
  806. task->tk_action = call_transmit_status;
  807. /* Encode here so that rpcsec_gss can use correct sequence number. */
  808. if (rpc_task_need_encode(task)) {
  809. BUG_ON(task->tk_rqstp->rq_bytes_sent != 0);
  810. call_encode(task);
  811. /* Did the encode result in an error condition? */
  812. if (task->tk_status != 0)
  813. return;
  814. }
  815. xprt_transmit(task);
  816. if (task->tk_status < 0)
  817. return;
  818. /*
  819. * On success, ensure that we call xprt_end_transmit() before sleeping
  820. * in order to allow access to the socket to other RPC requests.
  821. */
  822. call_transmit_status(task);
  823. if (task->tk_msg.rpc_proc->p_decode != NULL)
  824. return;
  825. task->tk_action = rpc_exit_task;
  826. rpc_wake_up_task(task);
  827. }
  828. /*
  829. * 5a. Handle cleanup after a transmission
  830. */
  831. static void
  832. call_transmit_status(struct rpc_task *task)
  833. {
  834. task->tk_action = call_status;
  835. /*
  836. * Special case: if we've been waiting on the socket's write_space()
  837. * callback, then don't call xprt_end_transmit().
  838. */
  839. if (task->tk_status == -EAGAIN)
  840. return;
  841. xprt_end_transmit(task);
  842. rpc_task_force_reencode(task);
  843. }
  844. /*
  845. * 6. Sort out the RPC call status
  846. */
  847. static void
  848. call_status(struct rpc_task *task)
  849. {
  850. struct rpc_clnt *clnt = task->tk_client;
  851. struct rpc_rqst *req = task->tk_rqstp;
  852. int status;
  853. if (req->rq_received > 0 && !req->rq_bytes_sent)
  854. task->tk_status = req->rq_received;
  855. dprintk("RPC: %4d call_status (status %d)\n",
  856. task->tk_pid, task->tk_status);
  857. status = task->tk_status;
  858. if (status >= 0) {
  859. task->tk_action = call_decode;
  860. return;
  861. }
  862. task->tk_status = 0;
  863. switch(status) {
  864. case -ETIMEDOUT:
  865. task->tk_action = call_timeout;
  866. break;
  867. case -ECONNREFUSED:
  868. case -ENOTCONN:
  869. rpc_force_rebind(clnt);
  870. task->tk_action = call_bind;
  871. break;
  872. case -EAGAIN:
  873. task->tk_action = call_transmit;
  874. break;
  875. case -EIO:
  876. /* shutdown or soft timeout */
  877. rpc_exit(task, status);
  878. break;
  879. default:
  880. printk("%s: RPC call returned error %d\n",
  881. clnt->cl_protname, -status);
  882. rpc_exit(task, status);
  883. break;
  884. }
  885. }
  886. /*
  887. * 6a. Handle RPC timeout
  888. * We do not release the request slot, so we keep using the
  889. * same XID for all retransmits.
  890. */
  891. static void
  892. call_timeout(struct rpc_task *task)
  893. {
  894. struct rpc_clnt *clnt = task->tk_client;
  895. if (xprt_adjust_timeout(task->tk_rqstp) == 0) {
  896. dprintk("RPC: %4d call_timeout (minor)\n", task->tk_pid);
  897. goto retry;
  898. }
  899. dprintk("RPC: %4d call_timeout (major)\n", task->tk_pid);
  900. task->tk_timeouts++;
  901. if (RPC_IS_SOFT(task)) {
  902. printk(KERN_NOTICE "%s: server %s not responding, timed out\n",
  903. clnt->cl_protname, clnt->cl_server);
  904. rpc_exit(task, -EIO);
  905. return;
  906. }
  907. if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) {
  908. task->tk_flags |= RPC_CALL_MAJORSEEN;
  909. printk(KERN_NOTICE "%s: server %s not responding, still trying\n",
  910. clnt->cl_protname, clnt->cl_server);
  911. }
  912. rpc_force_rebind(clnt);
  913. retry:
  914. clnt->cl_stats->rpcretrans++;
  915. task->tk_action = call_bind;
  916. task->tk_status = 0;
  917. }
  918. /*
  919. * 7. Decode the RPC reply
  920. */
  921. static void
  922. call_decode(struct rpc_task *task)
  923. {
  924. struct rpc_clnt *clnt = task->tk_client;
  925. struct rpc_rqst *req = task->tk_rqstp;
  926. kxdrproc_t decode = task->tk_msg.rpc_proc->p_decode;
  927. u32 *p;
  928. dprintk("RPC: %4d call_decode (status %d)\n",
  929. task->tk_pid, task->tk_status);
  930. if (task->tk_flags & RPC_CALL_MAJORSEEN) {
  931. printk(KERN_NOTICE "%s: server %s OK\n",
  932. clnt->cl_protname, clnt->cl_server);
  933. task->tk_flags &= ~RPC_CALL_MAJORSEEN;
  934. }
  935. if (task->tk_status < 12) {
  936. if (!RPC_IS_SOFT(task)) {
  937. task->tk_action = call_bind;
  938. clnt->cl_stats->rpcretrans++;
  939. goto out_retry;
  940. }
  941. printk(KERN_WARNING "%s: too small RPC reply size (%d bytes)\n",
  942. clnt->cl_protname, task->tk_status);
  943. rpc_exit(task, -EIO);
  944. return;
  945. }
  946. /*
  947. * Ensure that we see all writes made by xprt_complete_rqst()
  948. * before it changed req->rq_received.
  949. */
  950. smp_rmb();
  951. req->rq_rcv_buf.len = req->rq_private_buf.len;
  952. /* Check that the softirq receive buffer is valid */
  953. WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf,
  954. sizeof(req->rq_rcv_buf)) != 0);
  955. /* Verify the RPC header */
  956. p = call_verify(task);
  957. if (IS_ERR(p)) {
  958. if (p == ERR_PTR(-EAGAIN))
  959. goto out_retry;
  960. return;
  961. }
  962. task->tk_action = rpc_exit_task;
  963. if (decode)
  964. task->tk_status = rpcauth_unwrap_resp(task, decode, req, p,
  965. task->tk_msg.rpc_resp);
  966. dprintk("RPC: %4d call_decode result %d\n", task->tk_pid,
  967. task->tk_status);
  968. return;
  969. out_retry:
  970. req->rq_received = req->rq_private_buf.len = 0;
  971. task->tk_status = 0;
  972. }
  973. /*
  974. * 8. Refresh the credentials if rejected by the server
  975. */
  976. static void
  977. call_refresh(struct rpc_task *task)
  978. {
  979. dprintk("RPC: %4d call_refresh\n", task->tk_pid);
  980. xprt_release(task); /* Must do to obtain new XID */
  981. task->tk_action = call_refreshresult;
  982. task->tk_status = 0;
  983. task->tk_client->cl_stats->rpcauthrefresh++;
  984. rpcauth_refreshcred(task);
  985. }
  986. /*
  987. * 8a. Process the results of a credential refresh
  988. */
  989. static void
  990. call_refreshresult(struct rpc_task *task)
  991. {
  992. int status = task->tk_status;
  993. dprintk("RPC: %4d call_refreshresult (status %d)\n",
  994. task->tk_pid, task->tk_status);
  995. task->tk_status = 0;
  996. task->tk_action = call_reserve;
  997. if (status >= 0 && rpcauth_uptodatecred(task))
  998. return;
  999. if (status == -EACCES) {
  1000. rpc_exit(task, -EACCES);
  1001. return;
  1002. }
  1003. task->tk_action = call_refresh;
  1004. if (status != -ETIMEDOUT)
  1005. rpc_delay(task, 3*HZ);
  1006. return;
  1007. }
  1008. /*
  1009. * Call header serialization
  1010. */
  1011. static u32 *
  1012. call_header(struct rpc_task *task)
  1013. {
  1014. struct rpc_clnt *clnt = task->tk_client;
  1015. struct rpc_rqst *req = task->tk_rqstp;
  1016. u32 *p = req->rq_svec[0].iov_base;
  1017. /* FIXME: check buffer size? */
  1018. p = xprt_skip_transport_header(task->tk_xprt, p);
  1019. *p++ = req->rq_xid; /* XID */
  1020. *p++ = htonl(RPC_CALL); /* CALL */
  1021. *p++ = htonl(RPC_VERSION); /* RPC version */
  1022. *p++ = htonl(clnt->cl_prog); /* program number */
  1023. *p++ = htonl(clnt->cl_vers); /* program version */
  1024. *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */
  1025. p = rpcauth_marshcred(task, p);
  1026. req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
  1027. return p;
  1028. }
  1029. /*
  1030. * Reply header verification
  1031. */
  1032. static u32 *
  1033. call_verify(struct rpc_task *task)
  1034. {
  1035. struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0];
  1036. int len = task->tk_rqstp->rq_rcv_buf.len >> 2;
  1037. u32 *p = iov->iov_base, n;
  1038. int error = -EACCES;
  1039. if ((task->tk_rqstp->rq_rcv_buf.len & 3) != 0) {
  1040. /* RFC-1014 says that the representation of XDR data must be a
  1041. * multiple of four bytes
  1042. * - if it isn't pointer subtraction in the NFS client may give
  1043. * undefined results
  1044. */
  1045. printk(KERN_WARNING
  1046. "call_verify: XDR representation not a multiple of"
  1047. " 4 bytes: 0x%x\n", task->tk_rqstp->rq_rcv_buf.len);
  1048. goto out_eio;
  1049. }
  1050. if ((len -= 3) < 0)
  1051. goto out_overflow;
  1052. p += 1; /* skip XID */
  1053. if ((n = ntohl(*p++)) != RPC_REPLY) {
  1054. printk(KERN_WARNING "call_verify: not an RPC reply: %x\n", n);
  1055. goto out_garbage;
  1056. }
  1057. if ((n = ntohl(*p++)) != RPC_MSG_ACCEPTED) {
  1058. if (--len < 0)
  1059. goto out_overflow;
  1060. switch ((n = ntohl(*p++))) {
  1061. case RPC_AUTH_ERROR:
  1062. break;
  1063. case RPC_MISMATCH:
  1064. dprintk("%s: RPC call version mismatch!\n", __FUNCTION__);
  1065. error = -EPROTONOSUPPORT;
  1066. goto out_err;
  1067. default:
  1068. dprintk("%s: RPC call rejected, unknown error: %x\n", __FUNCTION__, n);
  1069. goto out_eio;
  1070. }
  1071. if (--len < 0)
  1072. goto out_overflow;
  1073. switch ((n = ntohl(*p++))) {
  1074. case RPC_AUTH_REJECTEDCRED:
  1075. case RPC_AUTH_REJECTEDVERF:
  1076. case RPCSEC_GSS_CREDPROBLEM:
  1077. case RPCSEC_GSS_CTXPROBLEM:
  1078. if (!task->tk_cred_retry)
  1079. break;
  1080. task->tk_cred_retry--;
  1081. dprintk("RPC: %4d call_verify: retry stale creds\n",
  1082. task->tk_pid);
  1083. rpcauth_invalcred(task);
  1084. task->tk_action = call_refresh;
  1085. goto out_retry;
  1086. case RPC_AUTH_BADCRED:
  1087. case RPC_AUTH_BADVERF:
  1088. /* possibly garbled cred/verf? */
  1089. if (!task->tk_garb_retry)
  1090. break;
  1091. task->tk_garb_retry--;
  1092. dprintk("RPC: %4d call_verify: retry garbled creds\n",
  1093. task->tk_pid);
  1094. task->tk_action = call_bind;
  1095. goto out_retry;
  1096. case RPC_AUTH_TOOWEAK:
  1097. printk(KERN_NOTICE "call_verify: server %s requires stronger "
  1098. "authentication.\n", task->tk_client->cl_server);
  1099. break;
  1100. default:
  1101. printk(KERN_WARNING "call_verify: unknown auth error: %x\n", n);
  1102. error = -EIO;
  1103. }
  1104. dprintk("RPC: %4d call_verify: call rejected %d\n",
  1105. task->tk_pid, n);
  1106. goto out_err;
  1107. }
  1108. if (!(p = rpcauth_checkverf(task, p))) {
  1109. printk(KERN_WARNING "call_verify: auth check failed\n");
  1110. goto out_garbage; /* bad verifier, retry */
  1111. }
  1112. len = p - (u32 *)iov->iov_base - 1;
  1113. if (len < 0)
  1114. goto out_overflow;
  1115. switch ((n = ntohl(*p++))) {
  1116. case RPC_SUCCESS:
  1117. return p;
  1118. case RPC_PROG_UNAVAIL:
  1119. dprintk("RPC: call_verify: program %u is unsupported by server %s\n",
  1120. (unsigned int)task->tk_client->cl_prog,
  1121. task->tk_client->cl_server);
  1122. error = -EPFNOSUPPORT;
  1123. goto out_err;
  1124. case RPC_PROG_MISMATCH:
  1125. dprintk("RPC: call_verify: program %u, version %u unsupported by server %s\n",
  1126. (unsigned int)task->tk_client->cl_prog,
  1127. (unsigned int)task->tk_client->cl_vers,
  1128. task->tk_client->cl_server);
  1129. error = -EPROTONOSUPPORT;
  1130. goto out_err;
  1131. case RPC_PROC_UNAVAIL:
  1132. dprintk("RPC: call_verify: proc %p unsupported by program %u, version %u on server %s\n",
  1133. task->tk_msg.rpc_proc,
  1134. task->tk_client->cl_prog,
  1135. task->tk_client->cl_vers,
  1136. task->tk_client->cl_server);
  1137. error = -EOPNOTSUPP;
  1138. goto out_err;
  1139. case RPC_GARBAGE_ARGS:
  1140. dprintk("RPC: %4d %s: server saw garbage\n", task->tk_pid, __FUNCTION__);
  1141. break; /* retry */
  1142. default:
  1143. printk(KERN_WARNING "call_verify: server accept status: %x\n", n);
  1144. /* Also retry */
  1145. }
  1146. out_garbage:
  1147. task->tk_client->cl_stats->rpcgarbage++;
  1148. if (task->tk_garb_retry) {
  1149. task->tk_garb_retry--;
  1150. dprintk("RPC %s: retrying %4d\n", __FUNCTION__, task->tk_pid);
  1151. task->tk_action = call_bind;
  1152. out_retry:
  1153. return ERR_PTR(-EAGAIN);
  1154. }
  1155. printk(KERN_WARNING "RPC %s: retry failed, exit EIO\n", __FUNCTION__);
  1156. out_eio:
  1157. error = -EIO;
  1158. out_err:
  1159. rpc_exit(task, error);
  1160. return ERR_PTR(error);
  1161. out_overflow:
  1162. printk(KERN_WARNING "RPC %s: server reply was truncated.\n", __FUNCTION__);
  1163. goto out_garbage;
  1164. }
  1165. static int rpcproc_encode_null(void *rqstp, u32 *data, void *obj)
  1166. {
  1167. return 0;
  1168. }
  1169. static int rpcproc_decode_null(void *rqstp, u32 *data, void *obj)
  1170. {
  1171. return 0;
  1172. }
  1173. static struct rpc_procinfo rpcproc_null = {
  1174. .p_encode = rpcproc_encode_null,
  1175. .p_decode = rpcproc_decode_null,
  1176. };
  1177. int rpc_ping(struct rpc_clnt *clnt, int flags)
  1178. {
  1179. struct rpc_message msg = {
  1180. .rpc_proc = &rpcproc_null,
  1181. };
  1182. int err;
  1183. msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0);
  1184. err = rpc_call_sync(clnt, &msg, flags);
  1185. put_rpccred(msg.rpc_cred);
  1186. return err;
  1187. }