clnt.c 32 KB

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