clnt.c 32 KB

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