nfs4callback.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. /*
  2. * Copyright (c) 2001 The Regents of the University of Michigan.
  3. * All rights reserved.
  4. *
  5. * Kendrick Smith <kmsmith@umich.edu>
  6. * Andy Adamson <andros@umich.edu>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the University nor the names of its
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  28. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include <linux/sunrpc/clnt.h>
  34. #include <linux/sunrpc/xprt.h>
  35. #include <linux/sunrpc/svc_xprt.h>
  36. #include <linux/slab.h>
  37. #include "nfsd.h"
  38. #include "state.h"
  39. #include "netns.h"
  40. #include "xdr4cb.h"
  41. #define NFSDDBG_FACILITY NFSDDBG_PROC
  42. static void nfsd4_mark_cb_fault(struct nfs4_client *, int reason);
  43. #define NFSPROC4_CB_NULL 0
  44. #define NFSPROC4_CB_COMPOUND 1
  45. /* Index of predefined Linux callback client operations */
  46. struct nfs4_cb_compound_hdr {
  47. /* args */
  48. u32 ident; /* minorversion 0 only */
  49. u32 nops;
  50. __be32 *nops_p;
  51. u32 minorversion;
  52. /* res */
  53. int status;
  54. };
  55. /*
  56. * Handle decode buffer overflows out-of-line.
  57. */
  58. static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
  59. {
  60. dprintk("NFS: %s prematurely hit the end of our receive buffer. "
  61. "Remaining buffer length is %tu words.\n",
  62. func, xdr->end - xdr->p);
  63. }
  64. static __be32 *xdr_encode_empty_array(__be32 *p)
  65. {
  66. *p++ = xdr_zero;
  67. return p;
  68. }
  69. /*
  70. * Encode/decode NFSv4 CB basic data types
  71. *
  72. * Basic NFSv4 callback data types are defined in section 15 of RFC
  73. * 3530: "Network File System (NFS) version 4 Protocol" and section
  74. * 20 of RFC 5661: "Network File System (NFS) Version 4 Minor Version
  75. * 1 Protocol"
  76. */
  77. /*
  78. * nfs_cb_opnum4
  79. *
  80. * enum nfs_cb_opnum4 {
  81. * OP_CB_GETATTR = 3,
  82. * ...
  83. * };
  84. */
  85. enum nfs_cb_opnum4 {
  86. OP_CB_GETATTR = 3,
  87. OP_CB_RECALL = 4,
  88. OP_CB_LAYOUTRECALL = 5,
  89. OP_CB_NOTIFY = 6,
  90. OP_CB_PUSH_DELEG = 7,
  91. OP_CB_RECALL_ANY = 8,
  92. OP_CB_RECALLABLE_OBJ_AVAIL = 9,
  93. OP_CB_RECALL_SLOT = 10,
  94. OP_CB_SEQUENCE = 11,
  95. OP_CB_WANTS_CANCELLED = 12,
  96. OP_CB_NOTIFY_LOCK = 13,
  97. OP_CB_NOTIFY_DEVICEID = 14,
  98. OP_CB_ILLEGAL = 10044
  99. };
  100. static void encode_nfs_cb_opnum4(struct xdr_stream *xdr, enum nfs_cb_opnum4 op)
  101. {
  102. __be32 *p;
  103. p = xdr_reserve_space(xdr, 4);
  104. *p = cpu_to_be32(op);
  105. }
  106. /*
  107. * nfs_fh4
  108. *
  109. * typedef opaque nfs_fh4<NFS4_FHSIZE>;
  110. */
  111. static void encode_nfs_fh4(struct xdr_stream *xdr, const struct knfsd_fh *fh)
  112. {
  113. u32 length = fh->fh_size;
  114. __be32 *p;
  115. BUG_ON(length > NFS4_FHSIZE);
  116. p = xdr_reserve_space(xdr, 4 + length);
  117. xdr_encode_opaque(p, &fh->fh_base, length);
  118. }
  119. /*
  120. * stateid4
  121. *
  122. * struct stateid4 {
  123. * uint32_t seqid;
  124. * opaque other[12];
  125. * };
  126. */
  127. static void encode_stateid4(struct xdr_stream *xdr, const stateid_t *sid)
  128. {
  129. __be32 *p;
  130. p = xdr_reserve_space(xdr, NFS4_STATEID_SIZE);
  131. *p++ = cpu_to_be32(sid->si_generation);
  132. xdr_encode_opaque_fixed(p, &sid->si_opaque, NFS4_STATEID_OTHER_SIZE);
  133. }
  134. /*
  135. * sessionid4
  136. *
  137. * typedef opaque sessionid4[NFS4_SESSIONID_SIZE];
  138. */
  139. static void encode_sessionid4(struct xdr_stream *xdr,
  140. const struct nfsd4_session *session)
  141. {
  142. __be32 *p;
  143. p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN);
  144. xdr_encode_opaque_fixed(p, session->se_sessionid.data,
  145. NFS4_MAX_SESSIONID_LEN);
  146. }
  147. /*
  148. * nfsstat4
  149. */
  150. static const struct {
  151. int stat;
  152. int errno;
  153. } nfs_cb_errtbl[] = {
  154. { NFS4_OK, 0 },
  155. { NFS4ERR_PERM, -EPERM },
  156. { NFS4ERR_NOENT, -ENOENT },
  157. { NFS4ERR_IO, -EIO },
  158. { NFS4ERR_NXIO, -ENXIO },
  159. { NFS4ERR_ACCESS, -EACCES },
  160. { NFS4ERR_EXIST, -EEXIST },
  161. { NFS4ERR_XDEV, -EXDEV },
  162. { NFS4ERR_NOTDIR, -ENOTDIR },
  163. { NFS4ERR_ISDIR, -EISDIR },
  164. { NFS4ERR_INVAL, -EINVAL },
  165. { NFS4ERR_FBIG, -EFBIG },
  166. { NFS4ERR_NOSPC, -ENOSPC },
  167. { NFS4ERR_ROFS, -EROFS },
  168. { NFS4ERR_MLINK, -EMLINK },
  169. { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
  170. { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
  171. { NFS4ERR_DQUOT, -EDQUOT },
  172. { NFS4ERR_STALE, -ESTALE },
  173. { NFS4ERR_BADHANDLE, -EBADHANDLE },
  174. { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
  175. { NFS4ERR_NOTSUPP, -ENOTSUPP },
  176. { NFS4ERR_TOOSMALL, -ETOOSMALL },
  177. { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
  178. { NFS4ERR_BADTYPE, -EBADTYPE },
  179. { NFS4ERR_LOCKED, -EAGAIN },
  180. { NFS4ERR_RESOURCE, -EREMOTEIO },
  181. { NFS4ERR_SYMLINK, -ELOOP },
  182. { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
  183. { NFS4ERR_DEADLOCK, -EDEADLK },
  184. { -1, -EIO }
  185. };
  186. /*
  187. * If we cannot translate the error, the recovery routines should
  188. * handle it.
  189. *
  190. * Note: remaining NFSv4 error codes have values > 10000, so should
  191. * not conflict with native Linux error codes.
  192. */
  193. static int nfs_cb_stat_to_errno(int status)
  194. {
  195. int i;
  196. for (i = 0; nfs_cb_errtbl[i].stat != -1; i++) {
  197. if (nfs_cb_errtbl[i].stat == status)
  198. return nfs_cb_errtbl[i].errno;
  199. }
  200. dprintk("NFSD: Unrecognized NFS CB status value: %u\n", status);
  201. return -status;
  202. }
  203. static int decode_cb_op_status(struct xdr_stream *xdr,
  204. enum nfs_cb_opnum4 expected, int *status)
  205. {
  206. __be32 *p;
  207. u32 op;
  208. p = xdr_inline_decode(xdr, 4 + 4);
  209. if (unlikely(p == NULL))
  210. goto out_overflow;
  211. op = be32_to_cpup(p++);
  212. if (unlikely(op != expected))
  213. goto out_unexpected;
  214. *status = nfs_cb_stat_to_errno(be32_to_cpup(p));
  215. return 0;
  216. out_overflow:
  217. print_overflow_msg(__func__, xdr);
  218. return -EIO;
  219. out_unexpected:
  220. dprintk("NFSD: Callback server returned operation %d but "
  221. "we issued a request for %d\n", op, expected);
  222. return -EIO;
  223. }
  224. /*
  225. * CB_COMPOUND4args
  226. *
  227. * struct CB_COMPOUND4args {
  228. * utf8str_cs tag;
  229. * uint32_t minorversion;
  230. * uint32_t callback_ident;
  231. * nfs_cb_argop4 argarray<>;
  232. * };
  233. */
  234. static void encode_cb_compound4args(struct xdr_stream *xdr,
  235. struct nfs4_cb_compound_hdr *hdr)
  236. {
  237. __be32 * p;
  238. p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4);
  239. p = xdr_encode_empty_array(p); /* empty tag */
  240. *p++ = cpu_to_be32(hdr->minorversion);
  241. *p++ = cpu_to_be32(hdr->ident);
  242. hdr->nops_p = p;
  243. *p = cpu_to_be32(hdr->nops); /* argarray element count */
  244. }
  245. /*
  246. * Update argarray element count
  247. */
  248. static void encode_cb_nops(struct nfs4_cb_compound_hdr *hdr)
  249. {
  250. BUG_ON(hdr->nops > NFS4_MAX_BACK_CHANNEL_OPS);
  251. *hdr->nops_p = cpu_to_be32(hdr->nops);
  252. }
  253. /*
  254. * CB_COMPOUND4res
  255. *
  256. * struct CB_COMPOUND4res {
  257. * nfsstat4 status;
  258. * utf8str_cs tag;
  259. * nfs_cb_resop4 resarray<>;
  260. * };
  261. */
  262. static int decode_cb_compound4res(struct xdr_stream *xdr,
  263. struct nfs4_cb_compound_hdr *hdr)
  264. {
  265. u32 length;
  266. __be32 *p;
  267. p = xdr_inline_decode(xdr, 4 + 4);
  268. if (unlikely(p == NULL))
  269. goto out_overflow;
  270. hdr->status = be32_to_cpup(p++);
  271. /* Ignore the tag */
  272. length = be32_to_cpup(p++);
  273. p = xdr_inline_decode(xdr, length + 4);
  274. if (unlikely(p == NULL))
  275. goto out_overflow;
  276. p += XDR_QUADLEN(length);
  277. hdr->nops = be32_to_cpup(p);
  278. return 0;
  279. out_overflow:
  280. print_overflow_msg(__func__, xdr);
  281. return -EIO;
  282. }
  283. /*
  284. * CB_RECALL4args
  285. *
  286. * struct CB_RECALL4args {
  287. * stateid4 stateid;
  288. * bool truncate;
  289. * nfs_fh4 fh;
  290. * };
  291. */
  292. static void encode_cb_recall4args(struct xdr_stream *xdr,
  293. const struct nfs4_delegation *dp,
  294. struct nfs4_cb_compound_hdr *hdr)
  295. {
  296. __be32 *p;
  297. encode_nfs_cb_opnum4(xdr, OP_CB_RECALL);
  298. encode_stateid4(xdr, &dp->dl_stid.sc_stateid);
  299. p = xdr_reserve_space(xdr, 4);
  300. *p++ = xdr_zero; /* truncate */
  301. encode_nfs_fh4(xdr, &dp->dl_stid.sc_file->fi_fhandle);
  302. hdr->nops++;
  303. }
  304. /*
  305. * CB_SEQUENCE4args
  306. *
  307. * struct CB_SEQUENCE4args {
  308. * sessionid4 csa_sessionid;
  309. * sequenceid4 csa_sequenceid;
  310. * slotid4 csa_slotid;
  311. * slotid4 csa_highest_slotid;
  312. * bool csa_cachethis;
  313. * referring_call_list4 csa_referring_call_lists<>;
  314. * };
  315. */
  316. static void encode_cb_sequence4args(struct xdr_stream *xdr,
  317. const struct nfsd4_callback *cb,
  318. struct nfs4_cb_compound_hdr *hdr)
  319. {
  320. struct nfsd4_session *session = cb->cb_clp->cl_cb_session;
  321. __be32 *p;
  322. if (hdr->minorversion == 0)
  323. return;
  324. encode_nfs_cb_opnum4(xdr, OP_CB_SEQUENCE);
  325. encode_sessionid4(xdr, session);
  326. p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4 + 4);
  327. *p++ = cpu_to_be32(session->se_cb_seq_nr); /* csa_sequenceid */
  328. *p++ = xdr_zero; /* csa_slotid */
  329. *p++ = xdr_zero; /* csa_highest_slotid */
  330. *p++ = xdr_zero; /* csa_cachethis */
  331. xdr_encode_empty_array(p); /* csa_referring_call_lists */
  332. hdr->nops++;
  333. }
  334. /*
  335. * CB_SEQUENCE4resok
  336. *
  337. * struct CB_SEQUENCE4resok {
  338. * sessionid4 csr_sessionid;
  339. * sequenceid4 csr_sequenceid;
  340. * slotid4 csr_slotid;
  341. * slotid4 csr_highest_slotid;
  342. * slotid4 csr_target_highest_slotid;
  343. * };
  344. *
  345. * union CB_SEQUENCE4res switch (nfsstat4 csr_status) {
  346. * case NFS4_OK:
  347. * CB_SEQUENCE4resok csr_resok4;
  348. * default:
  349. * void;
  350. * };
  351. *
  352. * Our current back channel implmentation supports a single backchannel
  353. * with a single slot.
  354. */
  355. static int decode_cb_sequence4resok(struct xdr_stream *xdr,
  356. struct nfsd4_callback *cb)
  357. {
  358. struct nfsd4_session *session = cb->cb_clp->cl_cb_session;
  359. int status = -ESERVERFAULT;
  360. __be32 *p;
  361. u32 dummy;
  362. /*
  363. * If the server returns different values for sessionID, slotID or
  364. * sequence number, the server is looney tunes.
  365. */
  366. p = xdr_inline_decode(xdr, NFS4_MAX_SESSIONID_LEN + 4 + 4 + 4 + 4);
  367. if (unlikely(p == NULL))
  368. goto out_overflow;
  369. if (memcmp(p, session->se_sessionid.data, NFS4_MAX_SESSIONID_LEN)) {
  370. dprintk("NFS: %s Invalid session id\n", __func__);
  371. goto out;
  372. }
  373. p += XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN);
  374. dummy = be32_to_cpup(p++);
  375. if (dummy != session->se_cb_seq_nr) {
  376. dprintk("NFS: %s Invalid sequence number\n", __func__);
  377. goto out;
  378. }
  379. dummy = be32_to_cpup(p++);
  380. if (dummy != 0) {
  381. dprintk("NFS: %s Invalid slotid\n", __func__);
  382. goto out;
  383. }
  384. /*
  385. * FIXME: process highest slotid and target highest slotid
  386. */
  387. status = 0;
  388. out:
  389. cb->cb_seq_status = status;
  390. return status;
  391. out_overflow:
  392. print_overflow_msg(__func__, xdr);
  393. status = -EIO;
  394. goto out;
  395. }
  396. static int decode_cb_sequence4res(struct xdr_stream *xdr,
  397. struct nfsd4_callback *cb)
  398. {
  399. int status;
  400. if (cb->cb_clp->cl_minorversion == 0)
  401. return 0;
  402. status = decode_cb_op_status(xdr, OP_CB_SEQUENCE, &cb->cb_seq_status);
  403. if (unlikely(status || cb->cb_seq_status))
  404. return status;
  405. return decode_cb_sequence4resok(xdr, cb);
  406. }
  407. /*
  408. * NFSv4.0 and NFSv4.1 XDR encode functions
  409. *
  410. * NFSv4.0 callback argument types are defined in section 15 of RFC
  411. * 3530: "Network File System (NFS) version 4 Protocol" and section 20
  412. * of RFC 5661: "Network File System (NFS) Version 4 Minor Version 1
  413. * Protocol".
  414. */
  415. /*
  416. * NB: Without this zero space reservation, callbacks over krb5p fail
  417. */
  418. static void nfs4_xdr_enc_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr,
  419. const void *__unused)
  420. {
  421. xdr_reserve_space(xdr, 0);
  422. }
  423. /*
  424. * 20.2. Operation 4: CB_RECALL - Recall a Delegation
  425. */
  426. static void nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, struct xdr_stream *xdr,
  427. const void *data)
  428. {
  429. const struct nfsd4_callback *cb = data;
  430. const struct nfs4_delegation *dp = cb_to_delegation(cb);
  431. struct nfs4_cb_compound_hdr hdr = {
  432. .ident = cb->cb_clp->cl_cb_ident,
  433. .minorversion = cb->cb_clp->cl_minorversion,
  434. };
  435. encode_cb_compound4args(xdr, &hdr);
  436. encode_cb_sequence4args(xdr, cb, &hdr);
  437. encode_cb_recall4args(xdr, dp, &hdr);
  438. encode_cb_nops(&hdr);
  439. }
  440. /*
  441. * NFSv4.0 and NFSv4.1 XDR decode functions
  442. *
  443. * NFSv4.0 callback result types are defined in section 15 of RFC
  444. * 3530: "Network File System (NFS) version 4 Protocol" and section 20
  445. * of RFC 5661: "Network File System (NFS) Version 4 Minor Version 1
  446. * Protocol".
  447. */
  448. static int nfs4_xdr_dec_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr,
  449. void *__unused)
  450. {
  451. return 0;
  452. }
  453. /*
  454. * 20.2. Operation 4: CB_RECALL - Recall a Delegation
  455. */
  456. static int nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp,
  457. struct xdr_stream *xdr,
  458. void *data)
  459. {
  460. struct nfsd4_callback *cb = data;
  461. struct nfs4_cb_compound_hdr hdr;
  462. int status;
  463. status = decode_cb_compound4res(xdr, &hdr);
  464. if (unlikely(status))
  465. return status;
  466. if (cb != NULL) {
  467. status = decode_cb_sequence4res(xdr, cb);
  468. if (unlikely(status || cb->cb_seq_status))
  469. return status;
  470. }
  471. return decode_cb_op_status(xdr, OP_CB_RECALL, &cb->cb_status);
  472. }
  473. #ifdef CONFIG_NFSD_PNFS
  474. /*
  475. * CB_LAYOUTRECALL4args
  476. *
  477. * struct layoutrecall_file4 {
  478. * nfs_fh4 lor_fh;
  479. * offset4 lor_offset;
  480. * length4 lor_length;
  481. * stateid4 lor_stateid;
  482. * };
  483. *
  484. * union layoutrecall4 switch(layoutrecall_type4 lor_recalltype) {
  485. * case LAYOUTRECALL4_FILE:
  486. * layoutrecall_file4 lor_layout;
  487. * case LAYOUTRECALL4_FSID:
  488. * fsid4 lor_fsid;
  489. * case LAYOUTRECALL4_ALL:
  490. * void;
  491. * };
  492. *
  493. * struct CB_LAYOUTRECALL4args {
  494. * layouttype4 clora_type;
  495. * layoutiomode4 clora_iomode;
  496. * bool clora_changed;
  497. * layoutrecall4 clora_recall;
  498. * };
  499. */
  500. static void encode_cb_layout4args(struct xdr_stream *xdr,
  501. const struct nfs4_layout_stateid *ls,
  502. struct nfs4_cb_compound_hdr *hdr)
  503. {
  504. __be32 *p;
  505. BUG_ON(hdr->minorversion == 0);
  506. p = xdr_reserve_space(xdr, 5 * 4);
  507. *p++ = cpu_to_be32(OP_CB_LAYOUTRECALL);
  508. *p++ = cpu_to_be32(ls->ls_layout_type);
  509. *p++ = cpu_to_be32(IOMODE_ANY);
  510. *p++ = cpu_to_be32(1);
  511. *p = cpu_to_be32(RETURN_FILE);
  512. encode_nfs_fh4(xdr, &ls->ls_stid.sc_file->fi_fhandle);
  513. p = xdr_reserve_space(xdr, 2 * 8);
  514. p = xdr_encode_hyper(p, 0);
  515. xdr_encode_hyper(p, NFS4_MAX_UINT64);
  516. encode_stateid4(xdr, &ls->ls_recall_sid);
  517. hdr->nops++;
  518. }
  519. static void nfs4_xdr_enc_cb_layout(struct rpc_rqst *req,
  520. struct xdr_stream *xdr,
  521. const void *data)
  522. {
  523. const struct nfsd4_callback *cb = data;
  524. const struct nfs4_layout_stateid *ls =
  525. container_of(cb, struct nfs4_layout_stateid, ls_recall);
  526. struct nfs4_cb_compound_hdr hdr = {
  527. .ident = 0,
  528. .minorversion = cb->cb_clp->cl_minorversion,
  529. };
  530. encode_cb_compound4args(xdr, &hdr);
  531. encode_cb_sequence4args(xdr, cb, &hdr);
  532. encode_cb_layout4args(xdr, ls, &hdr);
  533. encode_cb_nops(&hdr);
  534. }
  535. static int nfs4_xdr_dec_cb_layout(struct rpc_rqst *rqstp,
  536. struct xdr_stream *xdr,
  537. void *data)
  538. {
  539. struct nfsd4_callback *cb = data;
  540. struct nfs4_cb_compound_hdr hdr;
  541. int status;
  542. status = decode_cb_compound4res(xdr, &hdr);
  543. if (unlikely(status))
  544. return status;
  545. if (cb) {
  546. status = decode_cb_sequence4res(xdr, cb);
  547. if (unlikely(status || cb->cb_seq_status))
  548. return status;
  549. }
  550. return decode_cb_op_status(xdr, OP_CB_LAYOUTRECALL, &cb->cb_status);
  551. }
  552. #endif /* CONFIG_NFSD_PNFS */
  553. static void encode_stateowner(struct xdr_stream *xdr, struct nfs4_stateowner *so)
  554. {
  555. __be32 *p;
  556. p = xdr_reserve_space(xdr, 8 + 4 + so->so_owner.len);
  557. p = xdr_encode_opaque_fixed(p, &so->so_client->cl_clientid, 8);
  558. xdr_encode_opaque(p, so->so_owner.data, so->so_owner.len);
  559. }
  560. static void nfs4_xdr_enc_cb_notify_lock(struct rpc_rqst *req,
  561. struct xdr_stream *xdr,
  562. const void *data)
  563. {
  564. const struct nfsd4_callback *cb = data;
  565. const struct nfsd4_blocked_lock *nbl =
  566. container_of(cb, struct nfsd4_blocked_lock, nbl_cb);
  567. struct nfs4_lockowner *lo = (struct nfs4_lockowner *)nbl->nbl_lock.fl_owner;
  568. struct nfs4_cb_compound_hdr hdr = {
  569. .ident = 0,
  570. .minorversion = cb->cb_clp->cl_minorversion,
  571. };
  572. __be32 *p;
  573. BUG_ON(hdr.minorversion == 0);
  574. encode_cb_compound4args(xdr, &hdr);
  575. encode_cb_sequence4args(xdr, cb, &hdr);
  576. p = xdr_reserve_space(xdr, 4);
  577. *p = cpu_to_be32(OP_CB_NOTIFY_LOCK);
  578. encode_nfs_fh4(xdr, &nbl->nbl_fh);
  579. encode_stateowner(xdr, &lo->lo_owner);
  580. hdr.nops++;
  581. encode_cb_nops(&hdr);
  582. }
  583. static int nfs4_xdr_dec_cb_notify_lock(struct rpc_rqst *rqstp,
  584. struct xdr_stream *xdr,
  585. void *data)
  586. {
  587. struct nfsd4_callback *cb = data;
  588. struct nfs4_cb_compound_hdr hdr;
  589. int status;
  590. status = decode_cb_compound4res(xdr, &hdr);
  591. if (unlikely(status))
  592. return status;
  593. if (cb) {
  594. status = decode_cb_sequence4res(xdr, cb);
  595. if (unlikely(status || cb->cb_seq_status))
  596. return status;
  597. }
  598. return decode_cb_op_status(xdr, OP_CB_NOTIFY_LOCK, &cb->cb_status);
  599. }
  600. /*
  601. * RPC procedure tables
  602. */
  603. #define PROC(proc, call, argtype, restype) \
  604. [NFSPROC4_CLNT_##proc] = { \
  605. .p_proc = NFSPROC4_CB_##call, \
  606. .p_encode = nfs4_xdr_enc_##argtype, \
  607. .p_decode = nfs4_xdr_dec_##restype, \
  608. .p_arglen = NFS4_enc_##argtype##_sz, \
  609. .p_replen = NFS4_dec_##restype##_sz, \
  610. .p_statidx = NFSPROC4_CB_##call, \
  611. .p_name = #proc, \
  612. }
  613. static const struct rpc_procinfo nfs4_cb_procedures[] = {
  614. PROC(CB_NULL, NULL, cb_null, cb_null),
  615. PROC(CB_RECALL, COMPOUND, cb_recall, cb_recall),
  616. #ifdef CONFIG_NFSD_PNFS
  617. PROC(CB_LAYOUT, COMPOUND, cb_layout, cb_layout),
  618. #endif
  619. PROC(CB_NOTIFY_LOCK, COMPOUND, cb_notify_lock, cb_notify_lock),
  620. };
  621. static unsigned int nfs4_cb_counts[ARRAY_SIZE(nfs4_cb_procedures)];
  622. static const struct rpc_version nfs_cb_version4 = {
  623. /*
  624. * Note on the callback rpc program version number: despite language in rfc
  625. * 5661 section 18.36.3 requiring servers to use 4 in this field, the
  626. * official xdr descriptions for both 4.0 and 4.1 specify version 1, and
  627. * in practice that appears to be what implementations use. The section
  628. * 18.36.3 language is expected to be fixed in an erratum.
  629. */
  630. .number = 1,
  631. .nrprocs = ARRAY_SIZE(nfs4_cb_procedures),
  632. .procs = nfs4_cb_procedures,
  633. .counts = nfs4_cb_counts,
  634. };
  635. static const struct rpc_version *nfs_cb_version[2] = {
  636. [1] = &nfs_cb_version4,
  637. };
  638. static const struct rpc_program cb_program;
  639. static struct rpc_stat cb_stats = {
  640. .program = &cb_program
  641. };
  642. #define NFS4_CALLBACK 0x40000000
  643. static const struct rpc_program cb_program = {
  644. .name = "nfs4_cb",
  645. .number = NFS4_CALLBACK,
  646. .nrvers = ARRAY_SIZE(nfs_cb_version),
  647. .version = nfs_cb_version,
  648. .stats = &cb_stats,
  649. .pipe_dir_name = "nfsd4_cb",
  650. };
  651. static int max_cb_time(struct net *net)
  652. {
  653. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  654. return max(nn->nfsd4_lease/10, (time_t)1) * HZ;
  655. }
  656. static struct rpc_cred *get_backchannel_cred(struct nfs4_client *clp, struct rpc_clnt *client, struct nfsd4_session *ses)
  657. {
  658. if (clp->cl_minorversion == 0) {
  659. char *principal = clp->cl_cred.cr_targ_princ ?
  660. clp->cl_cred.cr_targ_princ : "nfs";
  661. struct rpc_cred *cred;
  662. cred = rpc_lookup_machine_cred(principal);
  663. if (!IS_ERR(cred))
  664. get_rpccred(cred);
  665. return cred;
  666. } else {
  667. struct rpc_auth *auth = client->cl_auth;
  668. struct auth_cred acred = {};
  669. acred.uid = ses->se_cb_sec.uid;
  670. acred.gid = ses->se_cb_sec.gid;
  671. return auth->au_ops->lookup_cred(client->cl_auth, &acred, 0);
  672. }
  673. }
  674. static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *conn, struct nfsd4_session *ses)
  675. {
  676. int maxtime = max_cb_time(clp->net);
  677. struct rpc_timeout timeparms = {
  678. .to_initval = maxtime,
  679. .to_retries = 0,
  680. .to_maxval = maxtime,
  681. };
  682. struct rpc_create_args args = {
  683. .net = clp->net,
  684. .address = (struct sockaddr *) &conn->cb_addr,
  685. .addrsize = conn->cb_addrlen,
  686. .saddress = (struct sockaddr *) &conn->cb_saddr,
  687. .timeout = &timeparms,
  688. .program = &cb_program,
  689. .version = 1,
  690. .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET),
  691. };
  692. struct rpc_clnt *client;
  693. struct rpc_cred *cred;
  694. if (clp->cl_minorversion == 0) {
  695. if (!clp->cl_cred.cr_principal &&
  696. (clp->cl_cred.cr_flavor >= RPC_AUTH_GSS_KRB5))
  697. return -EINVAL;
  698. args.client_name = clp->cl_cred.cr_principal;
  699. args.prognumber = conn->cb_prog;
  700. args.protocol = XPRT_TRANSPORT_TCP;
  701. args.authflavor = clp->cl_cred.cr_flavor;
  702. clp->cl_cb_ident = conn->cb_ident;
  703. } else {
  704. if (!conn->cb_xprt)
  705. return -EINVAL;
  706. clp->cl_cb_conn.cb_xprt = conn->cb_xprt;
  707. clp->cl_cb_session = ses;
  708. args.bc_xprt = conn->cb_xprt;
  709. args.prognumber = clp->cl_cb_session->se_cb_prog;
  710. args.protocol = conn->cb_xprt->xpt_class->xcl_ident |
  711. XPRT_TRANSPORT_BC;
  712. args.authflavor = ses->se_cb_sec.flavor;
  713. }
  714. /* Create RPC client */
  715. client = rpc_create(&args);
  716. if (IS_ERR(client)) {
  717. dprintk("NFSD: couldn't create callback client: %ld\n",
  718. PTR_ERR(client));
  719. return PTR_ERR(client);
  720. }
  721. cred = get_backchannel_cred(clp, client, ses);
  722. if (IS_ERR(cred)) {
  723. rpc_shutdown_client(client);
  724. return PTR_ERR(cred);
  725. }
  726. clp->cl_cb_client = client;
  727. clp->cl_cb_cred = cred;
  728. return 0;
  729. }
  730. static void warn_no_callback_path(struct nfs4_client *clp, int reason)
  731. {
  732. dprintk("NFSD: warning: no callback path to client %.*s: error %d\n",
  733. (int)clp->cl_name.len, clp->cl_name.data, reason);
  734. }
  735. static void nfsd4_mark_cb_down(struct nfs4_client *clp, int reason)
  736. {
  737. if (test_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_flags))
  738. return;
  739. clp->cl_cb_state = NFSD4_CB_DOWN;
  740. warn_no_callback_path(clp, reason);
  741. }
  742. static void nfsd4_mark_cb_fault(struct nfs4_client *clp, int reason)
  743. {
  744. if (test_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_flags))
  745. return;
  746. clp->cl_cb_state = NFSD4_CB_FAULT;
  747. warn_no_callback_path(clp, reason);
  748. }
  749. static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata)
  750. {
  751. struct nfs4_client *clp = container_of(calldata, struct nfs4_client, cl_cb_null);
  752. if (task->tk_status)
  753. nfsd4_mark_cb_down(clp, task->tk_status);
  754. else
  755. clp->cl_cb_state = NFSD4_CB_UP;
  756. }
  757. static const struct rpc_call_ops nfsd4_cb_probe_ops = {
  758. /* XXX: release method to ensure we set the cb channel down if
  759. * necessary on early failure? */
  760. .rpc_call_done = nfsd4_cb_probe_done,
  761. };
  762. static struct workqueue_struct *callback_wq;
  763. /*
  764. * Poke the callback thread to process any updates to the callback
  765. * parameters, and send a null probe.
  766. */
  767. void nfsd4_probe_callback(struct nfs4_client *clp)
  768. {
  769. clp->cl_cb_state = NFSD4_CB_UNKNOWN;
  770. set_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_flags);
  771. nfsd4_run_cb(&clp->cl_cb_null);
  772. }
  773. void nfsd4_probe_callback_sync(struct nfs4_client *clp)
  774. {
  775. nfsd4_probe_callback(clp);
  776. flush_workqueue(callback_wq);
  777. }
  778. void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *conn)
  779. {
  780. clp->cl_cb_state = NFSD4_CB_UNKNOWN;
  781. spin_lock(&clp->cl_lock);
  782. memcpy(&clp->cl_cb_conn, conn, sizeof(struct nfs4_cb_conn));
  783. spin_unlock(&clp->cl_lock);
  784. }
  785. /*
  786. * There's currently a single callback channel slot.
  787. * If the slot is available, then mark it busy. Otherwise, set the
  788. * thread for sleeping on the callback RPC wait queue.
  789. */
  790. static bool nfsd41_cb_get_slot(struct nfs4_client *clp, struct rpc_task *task)
  791. {
  792. if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) {
  793. rpc_sleep_on(&clp->cl_cb_waitq, task, NULL);
  794. /* Race breaker */
  795. if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) {
  796. dprintk("%s slot is busy\n", __func__);
  797. return false;
  798. }
  799. rpc_wake_up_queued_task(&clp->cl_cb_waitq, task);
  800. }
  801. return true;
  802. }
  803. /*
  804. * TODO: cb_sequence should support referring call lists, cachethis, multiple
  805. * slots, and mark callback channel down on communication errors.
  806. */
  807. static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata)
  808. {
  809. struct nfsd4_callback *cb = calldata;
  810. struct nfs4_client *clp = cb->cb_clp;
  811. u32 minorversion = clp->cl_minorversion;
  812. /*
  813. * cb_seq_status is only set in decode_cb_sequence4res,
  814. * and so will remain 1 if an rpc level failure occurs.
  815. */
  816. cb->cb_seq_status = 1;
  817. cb->cb_status = 0;
  818. if (minorversion) {
  819. if (!cb->cb_holds_slot && !nfsd41_cb_get_slot(clp, task))
  820. return;
  821. cb->cb_holds_slot = true;
  822. }
  823. rpc_call_start(task);
  824. }
  825. static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callback *cb)
  826. {
  827. struct nfs4_client *clp = cb->cb_clp;
  828. struct nfsd4_session *session = clp->cl_cb_session;
  829. bool ret = true;
  830. if (!clp->cl_minorversion) {
  831. /*
  832. * If the backchannel connection was shut down while this
  833. * task was queued, we need to resubmit it after setting up
  834. * a new backchannel connection.
  835. *
  836. * Note that if we lost our callback connection permanently
  837. * the submission code will error out, so we don't need to
  838. * handle that case here.
  839. */
  840. if (task->tk_flags & RPC_TASK_KILLED)
  841. goto need_restart;
  842. return true;
  843. }
  844. if (!cb->cb_holds_slot)
  845. goto need_restart;
  846. switch (cb->cb_seq_status) {
  847. case 0:
  848. /*
  849. * No need for lock, access serialized in nfsd4_cb_prepare
  850. *
  851. * RFC5661 20.9.3
  852. * If CB_SEQUENCE returns an error, then the state of the slot
  853. * (sequence ID, cached reply) MUST NOT change.
  854. */
  855. ++session->se_cb_seq_nr;
  856. break;
  857. case -ESERVERFAULT:
  858. ++session->se_cb_seq_nr;
  859. /* Fall through */
  860. case 1:
  861. case -NFS4ERR_BADSESSION:
  862. nfsd4_mark_cb_fault(cb->cb_clp, cb->cb_seq_status);
  863. ret = false;
  864. break;
  865. case -NFS4ERR_DELAY:
  866. if (!rpc_restart_call(task))
  867. goto out;
  868. rpc_delay(task, 2 * HZ);
  869. return false;
  870. case -NFS4ERR_BADSLOT:
  871. goto retry_nowait;
  872. case -NFS4ERR_SEQ_MISORDERED:
  873. if (session->se_cb_seq_nr != 1) {
  874. session->se_cb_seq_nr = 1;
  875. goto retry_nowait;
  876. }
  877. break;
  878. default:
  879. dprintk("%s: unprocessed error %d\n", __func__,
  880. cb->cb_seq_status);
  881. }
  882. cb->cb_holds_slot = false;
  883. clear_bit(0, &clp->cl_cb_slot_busy);
  884. rpc_wake_up_next(&clp->cl_cb_waitq);
  885. dprintk("%s: freed slot, new seqid=%d\n", __func__,
  886. clp->cl_cb_session->se_cb_seq_nr);
  887. if (task->tk_flags & RPC_TASK_KILLED)
  888. goto need_restart;
  889. out:
  890. return ret;
  891. retry_nowait:
  892. if (rpc_restart_call_prepare(task))
  893. ret = false;
  894. goto out;
  895. need_restart:
  896. task->tk_status = 0;
  897. cb->cb_need_restart = true;
  898. return false;
  899. }
  900. static void nfsd4_cb_done(struct rpc_task *task, void *calldata)
  901. {
  902. struct nfsd4_callback *cb = calldata;
  903. struct nfs4_client *clp = cb->cb_clp;
  904. dprintk("%s: minorversion=%d\n", __func__,
  905. clp->cl_minorversion);
  906. if (!nfsd4_cb_sequence_done(task, cb))
  907. return;
  908. if (cb->cb_status) {
  909. WARN_ON_ONCE(task->tk_status);
  910. task->tk_status = cb->cb_status;
  911. }
  912. switch (cb->cb_ops->done(cb, task)) {
  913. case 0:
  914. task->tk_status = 0;
  915. rpc_restart_call_prepare(task);
  916. return;
  917. case 1:
  918. break;
  919. case -1:
  920. /* Network partition? */
  921. nfsd4_mark_cb_down(clp, task->tk_status);
  922. break;
  923. default:
  924. BUG();
  925. }
  926. }
  927. static void nfsd4_cb_release(void *calldata)
  928. {
  929. struct nfsd4_callback *cb = calldata;
  930. if (cb->cb_need_restart)
  931. nfsd4_run_cb(cb);
  932. else
  933. cb->cb_ops->release(cb);
  934. }
  935. static const struct rpc_call_ops nfsd4_cb_ops = {
  936. .rpc_call_prepare = nfsd4_cb_prepare,
  937. .rpc_call_done = nfsd4_cb_done,
  938. .rpc_release = nfsd4_cb_release,
  939. };
  940. int nfsd4_create_callback_queue(void)
  941. {
  942. callback_wq = alloc_ordered_workqueue("nfsd4_callbacks", 0);
  943. if (!callback_wq)
  944. return -ENOMEM;
  945. return 0;
  946. }
  947. void nfsd4_destroy_callback_queue(void)
  948. {
  949. destroy_workqueue(callback_wq);
  950. }
  951. /* must be called under the state lock */
  952. void nfsd4_shutdown_callback(struct nfs4_client *clp)
  953. {
  954. set_bit(NFSD4_CLIENT_CB_KILL, &clp->cl_flags);
  955. /*
  956. * Note this won't actually result in a null callback;
  957. * instead, nfsd4_run_cb_null() will detect the killed
  958. * client, destroy the rpc client, and stop:
  959. */
  960. nfsd4_run_cb(&clp->cl_cb_null);
  961. flush_workqueue(callback_wq);
  962. }
  963. /* requires cl_lock: */
  964. static struct nfsd4_conn * __nfsd4_find_backchannel(struct nfs4_client *clp)
  965. {
  966. struct nfsd4_session *s;
  967. struct nfsd4_conn *c;
  968. list_for_each_entry(s, &clp->cl_sessions, se_perclnt) {
  969. list_for_each_entry(c, &s->se_conns, cn_persession) {
  970. if (c->cn_flags & NFS4_CDFC4_BACK)
  971. return c;
  972. }
  973. }
  974. return NULL;
  975. }
  976. static void nfsd4_process_cb_update(struct nfsd4_callback *cb)
  977. {
  978. struct nfs4_cb_conn conn;
  979. struct nfs4_client *clp = cb->cb_clp;
  980. struct nfsd4_session *ses = NULL;
  981. struct nfsd4_conn *c;
  982. int err;
  983. /*
  984. * This is either an update, or the client dying; in either case,
  985. * kill the old client:
  986. */
  987. if (clp->cl_cb_client) {
  988. rpc_shutdown_client(clp->cl_cb_client);
  989. clp->cl_cb_client = NULL;
  990. put_rpccred(clp->cl_cb_cred);
  991. clp->cl_cb_cred = NULL;
  992. }
  993. if (clp->cl_cb_conn.cb_xprt) {
  994. svc_xprt_put(clp->cl_cb_conn.cb_xprt);
  995. clp->cl_cb_conn.cb_xprt = NULL;
  996. }
  997. if (test_bit(NFSD4_CLIENT_CB_KILL, &clp->cl_flags))
  998. return;
  999. spin_lock(&clp->cl_lock);
  1000. /*
  1001. * Only serialized callback code is allowed to clear these
  1002. * flags; main nfsd code can only set them:
  1003. */
  1004. BUG_ON(!(clp->cl_flags & NFSD4_CLIENT_CB_FLAG_MASK));
  1005. clear_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_flags);
  1006. memcpy(&conn, &cb->cb_clp->cl_cb_conn, sizeof(struct nfs4_cb_conn));
  1007. c = __nfsd4_find_backchannel(clp);
  1008. if (c) {
  1009. svc_xprt_get(c->cn_xprt);
  1010. conn.cb_xprt = c->cn_xprt;
  1011. ses = c->cn_session;
  1012. }
  1013. spin_unlock(&clp->cl_lock);
  1014. err = setup_callback_client(clp, &conn, ses);
  1015. if (err) {
  1016. nfsd4_mark_cb_down(clp, err);
  1017. return;
  1018. }
  1019. }
  1020. static void
  1021. nfsd4_run_cb_work(struct work_struct *work)
  1022. {
  1023. struct nfsd4_callback *cb =
  1024. container_of(work, struct nfsd4_callback, cb_work);
  1025. struct nfs4_client *clp = cb->cb_clp;
  1026. struct rpc_clnt *clnt;
  1027. if (cb->cb_need_restart) {
  1028. cb->cb_need_restart = false;
  1029. } else {
  1030. if (cb->cb_ops && cb->cb_ops->prepare)
  1031. cb->cb_ops->prepare(cb);
  1032. }
  1033. if (clp->cl_flags & NFSD4_CLIENT_CB_FLAG_MASK)
  1034. nfsd4_process_cb_update(cb);
  1035. clnt = clp->cl_cb_client;
  1036. if (!clnt) {
  1037. /* Callback channel broken, or client killed; give up: */
  1038. if (cb->cb_ops && cb->cb_ops->release)
  1039. cb->cb_ops->release(cb);
  1040. return;
  1041. }
  1042. /*
  1043. * Don't send probe messages for 4.1 or later.
  1044. */
  1045. if (!cb->cb_ops && clp->cl_minorversion) {
  1046. clp->cl_cb_state = NFSD4_CB_UP;
  1047. return;
  1048. }
  1049. cb->cb_msg.rpc_cred = clp->cl_cb_cred;
  1050. rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN,
  1051. cb->cb_ops ? &nfsd4_cb_ops : &nfsd4_cb_probe_ops, cb);
  1052. }
  1053. void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
  1054. const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op)
  1055. {
  1056. cb->cb_clp = clp;
  1057. cb->cb_msg.rpc_proc = &nfs4_cb_procedures[op];
  1058. cb->cb_msg.rpc_argp = cb;
  1059. cb->cb_msg.rpc_resp = cb;
  1060. cb->cb_ops = ops;
  1061. INIT_WORK(&cb->cb_work, nfsd4_run_cb_work);
  1062. cb->cb_seq_status = 1;
  1063. cb->cb_status = 0;
  1064. cb->cb_need_restart = false;
  1065. cb->cb_holds_slot = false;
  1066. }
  1067. void nfsd4_run_cb(struct nfsd4_callback *cb)
  1068. {
  1069. queue_work(callback_wq, &cb->cb_work);
  1070. }