clnt.c 32 KB

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