clnt.c 31 KB

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