clnt.c 32 KB

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