xdr4.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. /*
  2. * Server-side types for NFSv4.
  3. *
  4. * Copyright (c) 2002 The Regents of the University of Michigan.
  5. * All rights reserved.
  6. *
  7. * Kendrick Smith <kmsmith@umich.edu>
  8. * Andy Adamson <andros@umich.edu>
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the University nor the names of its
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #ifndef _LINUX_NFSD_XDR4_H
  37. #define _LINUX_NFSD_XDR4_H
  38. #include "state.h"
  39. #include "nfsd.h"
  40. #define NFSD4_MAX_TAGLEN 128
  41. #define XDR_LEN(n) (((n) + 3) & ~3)
  42. #define CURRENT_STATE_ID_FLAG (1<<0)
  43. #define SAVED_STATE_ID_FLAG (1<<1)
  44. #define SET_CSTATE_FLAG(c, f) ((c)->sid_flags |= (f))
  45. #define HAS_CSTATE_FLAG(c, f) ((c)->sid_flags & (f))
  46. #define CLEAR_CSTATE_FLAG(c, f) ((c)->sid_flags &= ~(f))
  47. /**
  48. * nfsd4_encode_bool - Encode an XDR bool type result
  49. * @xdr: target XDR stream
  50. * @val: boolean value to encode
  51. *
  52. * Return values:
  53. * %nfs_ok: @val encoded; @xdr advanced to next position
  54. * %nfserr_resource: stream buffer space exhausted
  55. */
  56. static __always_inline __be32
  57. nfsd4_encode_bool(struct xdr_stream *xdr, bool val)
  58. {
  59. __be32 *p = xdr_reserve_space(xdr, XDR_UNIT);
  60. if (unlikely(p == NULL))
  61. return nfserr_resource;
  62. *p = val ? xdr_one : xdr_zero;
  63. return nfs_ok;
  64. }
  65. /**
  66. * nfsd4_encode_uint32_t - Encode an XDR uint32_t type result
  67. * @xdr: target XDR stream
  68. * @val: integer value to encode
  69. *
  70. * Return values:
  71. * %nfs_ok: @val encoded; @xdr advanced to next position
  72. * %nfserr_resource: stream buffer space exhausted
  73. */
  74. static __always_inline __be32
  75. nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val)
  76. {
  77. __be32 *p = xdr_reserve_space(xdr, XDR_UNIT);
  78. if (unlikely(p == NULL))
  79. return nfserr_resource;
  80. *p = cpu_to_be32(val);
  81. return nfs_ok;
  82. }
  83. #define nfsd4_encode_aceflag4(x, v) nfsd4_encode_uint32_t(x, v)
  84. #define nfsd4_encode_acemask4(x, v) nfsd4_encode_uint32_t(x, v)
  85. #define nfsd4_encode_acetype4(x, v) nfsd4_encode_uint32_t(x, v)
  86. #define nfsd4_encode_count4(x, v) nfsd4_encode_uint32_t(x, v)
  87. #define nfsd4_encode_mode4(x, v) nfsd4_encode_uint32_t(x, v)
  88. #define nfsd4_encode_nfs_lease4(x, v) nfsd4_encode_uint32_t(x, v)
  89. #define nfsd4_encode_qop4(x, v) nfsd4_encode_uint32_t(x, v)
  90. #define nfsd4_encode_sequenceid4(x, v) nfsd4_encode_uint32_t(x, v)
  91. #define nfsd4_encode_slotid4(x, v) nfsd4_encode_uint32_t(x, v)
  92. /**
  93. * nfsd4_encode_uint64_t - Encode an XDR uint64_t type result
  94. * @xdr: target XDR stream
  95. * @val: integer value to encode
  96. *
  97. * Return values:
  98. * %nfs_ok: @val encoded; @xdr advanced to next position
  99. * %nfserr_resource: stream buffer space exhausted
  100. */
  101. static __always_inline __be32
  102. nfsd4_encode_uint64_t(struct xdr_stream *xdr, u64 val)
  103. {
  104. __be32 *p = xdr_reserve_space(xdr, XDR_UNIT * 2);
  105. if (unlikely(p == NULL))
  106. return nfserr_resource;
  107. put_unaligned_be64(val, p);
  108. return nfs_ok;
  109. }
  110. #define nfsd4_encode_changeid4(x, v) nfsd4_encode_uint64_t(x, v)
  111. #define nfsd4_encode_nfs_cookie4(x, v) nfsd4_encode_uint64_t(x, v)
  112. #define nfsd4_encode_length4(x, v) nfsd4_encode_uint64_t(x, v)
  113. #define nfsd4_encode_offset4(x, v) nfsd4_encode_uint64_t(x, v)
  114. /**
  115. * nfsd4_encode_opaque_fixed - Encode a fixed-length XDR opaque type result
  116. * @xdr: target XDR stream
  117. * @data: pointer to data
  118. * @size: length of data in bytes
  119. *
  120. * Return values:
  121. * %nfs_ok: @data encoded; @xdr advanced to next position
  122. * %nfserr_resource: stream buffer space exhausted
  123. */
  124. static __always_inline __be32
  125. nfsd4_encode_opaque_fixed(struct xdr_stream *xdr, const void *data,
  126. size_t size)
  127. {
  128. __be32 *p = xdr_reserve_space(xdr, xdr_align_size(size));
  129. size_t pad = xdr_pad_size(size);
  130. if (unlikely(p == NULL))
  131. return nfserr_resource;
  132. memcpy(p, data, size);
  133. if (pad)
  134. memset((char *)p + size, 0, pad);
  135. return nfs_ok;
  136. }
  137. /**
  138. * nfsd4_encode_opaque - Encode a variable-length XDR opaque type result
  139. * @xdr: target XDR stream
  140. * @data: pointer to data
  141. * @size: length of data in bytes
  142. *
  143. * Return values:
  144. * %nfs_ok: @data encoded; @xdr advanced to next position
  145. * %nfserr_resource: stream buffer space exhausted
  146. */
  147. static __always_inline __be32
  148. nfsd4_encode_opaque(struct xdr_stream *xdr, const void *data, size_t size)
  149. {
  150. size_t pad = xdr_pad_size(size);
  151. __be32 *p;
  152. p = xdr_reserve_space(xdr, XDR_UNIT + xdr_align_size(size));
  153. if (unlikely(p == NULL))
  154. return nfserr_resource;
  155. *p++ = cpu_to_be32(size);
  156. memcpy(p, data, size);
  157. if (pad)
  158. memset((char *)p + size, 0, pad);
  159. return nfs_ok;
  160. }
  161. #define nfsd4_encode_component4(x, d, s) nfsd4_encode_opaque(x, d, s)
  162. struct nfsd4_compound_state {
  163. struct svc_fh current_fh;
  164. struct svc_fh save_fh;
  165. struct nfs4_stateowner *replay_owner;
  166. struct nfs4_client *clp;
  167. /* For sessions DRC */
  168. struct nfsd4_session *session;
  169. struct nfsd4_slot *slot;
  170. int data_offset;
  171. bool spo_must_allowed;
  172. size_t iovlen;
  173. u32 minorversion;
  174. __be32 status;
  175. stateid_t current_stateid;
  176. stateid_t save_stateid;
  177. /* to indicate current and saved state id presents */
  178. u32 sid_flags;
  179. };
  180. static inline bool nfsd4_has_session(struct nfsd4_compound_state *cs)
  181. {
  182. return cs->slot != NULL;
  183. }
  184. struct nfsd4_change_info {
  185. u32 atomic;
  186. u64 before_change;
  187. u64 after_change;
  188. };
  189. struct nfsd4_access {
  190. u32 ac_req_access; /* request */
  191. u32 ac_supported; /* response */
  192. u32 ac_resp_access; /* response */
  193. };
  194. struct nfsd4_close {
  195. u32 cl_seqid; /* request */
  196. stateid_t cl_stateid; /* request+response */
  197. };
  198. struct nfsd4_commit {
  199. u64 co_offset; /* request */
  200. u32 co_count; /* request */
  201. nfs4_verifier co_verf; /* response */
  202. };
  203. struct nfsd4_create {
  204. u32 cr_namelen; /* request */
  205. char * cr_name; /* request */
  206. u32 cr_type; /* request */
  207. union { /* request */
  208. struct {
  209. u32 datalen;
  210. char *data;
  211. struct kvec first;
  212. } link; /* NF4LNK */
  213. struct {
  214. u32 specdata1;
  215. u32 specdata2;
  216. } dev; /* NF4BLK, NF4CHR */
  217. } u;
  218. u32 cr_bmval[3]; /* request */
  219. struct iattr cr_iattr; /* request */
  220. int cr_umask; /* request */
  221. struct nfsd4_change_info cr_cinfo; /* response */
  222. struct nfs4_acl *cr_acl;
  223. struct xdr_netobj cr_label;
  224. };
  225. #define cr_datalen u.link.datalen
  226. #define cr_data u.link.data
  227. #define cr_first u.link.first
  228. #define cr_specdata1 u.dev.specdata1
  229. #define cr_specdata2 u.dev.specdata2
  230. struct nfsd4_delegreturn {
  231. stateid_t dr_stateid;
  232. };
  233. struct nfsd4_getattr {
  234. u32 ga_bmval[3]; /* request */
  235. struct svc_fh *ga_fhp; /* response */
  236. };
  237. struct nfsd4_link {
  238. u32 li_namelen; /* request */
  239. char * li_name; /* request */
  240. struct nfsd4_change_info li_cinfo; /* response */
  241. };
  242. struct nfsd4_lock_denied {
  243. clientid_t ld_clientid;
  244. struct xdr_netobj ld_owner;
  245. u64 ld_start;
  246. u64 ld_length;
  247. u32 ld_type;
  248. };
  249. struct nfsd4_lock {
  250. /* request */
  251. u32 lk_type;
  252. u32 lk_reclaim; /* boolean */
  253. u64 lk_offset;
  254. u64 lk_length;
  255. u32 lk_is_new;
  256. union {
  257. struct {
  258. u32 open_seqid;
  259. stateid_t open_stateid;
  260. u32 lock_seqid;
  261. clientid_t clientid;
  262. struct xdr_netobj owner;
  263. } new;
  264. struct {
  265. stateid_t lock_stateid;
  266. u32 lock_seqid;
  267. } old;
  268. } v;
  269. /* response */
  270. stateid_t lk_resp_stateid;
  271. struct nfsd4_lock_denied lk_denied;
  272. };
  273. #define lk_new_open_seqid v.new.open_seqid
  274. #define lk_new_open_stateid v.new.open_stateid
  275. #define lk_new_lock_seqid v.new.lock_seqid
  276. #define lk_new_clientid v.new.clientid
  277. #define lk_new_owner v.new.owner
  278. #define lk_old_lock_stateid v.old.lock_stateid
  279. #define lk_old_lock_seqid v.old.lock_seqid
  280. struct nfsd4_lockt {
  281. u32 lt_type;
  282. clientid_t lt_clientid;
  283. struct xdr_netobj lt_owner;
  284. u64 lt_offset;
  285. u64 lt_length;
  286. struct nfsd4_lock_denied lt_denied;
  287. };
  288. struct nfsd4_locku {
  289. u32 lu_type;
  290. u32 lu_seqid;
  291. stateid_t lu_stateid;
  292. u64 lu_offset;
  293. u64 lu_length;
  294. };
  295. struct nfsd4_lookup {
  296. u32 lo_len; /* request */
  297. char * lo_name; /* request */
  298. };
  299. struct nfsd4_putfh {
  300. u32 pf_fhlen; /* request */
  301. char *pf_fhval; /* request */
  302. bool no_verify; /* represents foreigh fh */
  303. };
  304. struct nfsd4_getxattr {
  305. char *getxa_name; /* request */
  306. u32 getxa_len; /* request */
  307. void *getxa_buf;
  308. };
  309. struct nfsd4_setxattr {
  310. u32 setxa_flags; /* request */
  311. char *setxa_name; /* request */
  312. char *setxa_buf; /* request */
  313. u32 setxa_len; /* request */
  314. struct nfsd4_change_info setxa_cinfo; /* response */
  315. };
  316. struct nfsd4_removexattr {
  317. char *rmxa_name; /* request */
  318. struct nfsd4_change_info rmxa_cinfo; /* response */
  319. };
  320. struct nfsd4_listxattrs {
  321. u64 lsxa_cookie; /* request */
  322. u32 lsxa_maxcount; /* request */
  323. char *lsxa_buf; /* unfiltered buffer (reply) */
  324. u32 lsxa_len; /* unfiltered len (reply) */
  325. };
  326. struct nfsd4_open {
  327. u32 op_claim_type; /* request */
  328. u32 op_fnamelen;
  329. char * op_fname; /* request - everything but CLAIM_PREV */
  330. u32 op_delegate_type; /* request - CLAIM_PREV only */
  331. stateid_t op_delegate_stateid; /* request - response */
  332. u32 op_why_no_deleg; /* response - DELEG_NONE_EXT only */
  333. u32 op_create; /* request */
  334. u32 op_createmode; /* request */
  335. int op_umask; /* request */
  336. u32 op_bmval[3]; /* request */
  337. struct iattr op_iattr; /* UNCHECKED4, GUARDED4, EXCLUSIVE4_1 */
  338. nfs4_verifier op_verf __attribute__((aligned(32)));
  339. /* EXCLUSIVE4 */
  340. clientid_t op_clientid; /* request */
  341. struct xdr_netobj op_owner; /* request */
  342. u32 op_seqid; /* request */
  343. u32 op_share_access; /* request */
  344. u32 op_share_deny; /* request */
  345. u32 op_deleg_want; /* request */
  346. stateid_t op_stateid; /* response */
  347. __be32 op_xdr_error; /* see nfsd4_open_omfg() */
  348. struct nfsd4_change_info op_cinfo; /* response */
  349. u32 op_rflags; /* response */
  350. bool op_recall; /* response */
  351. bool op_truncate; /* used during processing */
  352. bool op_created; /* used during processing */
  353. struct nfs4_openowner *op_openowner; /* used during processing */
  354. struct file *op_filp; /* used during processing */
  355. struct nfs4_file *op_file; /* used during processing */
  356. struct nfs4_ol_stateid *op_stp; /* used during processing */
  357. struct nfs4_clnt_odstate *op_odstate; /* used during processing */
  358. struct nfs4_acl *op_acl;
  359. struct xdr_netobj op_label;
  360. struct svc_rqst *op_rqstp;
  361. };
  362. struct nfsd4_open_confirm {
  363. stateid_t oc_req_stateid /* request */;
  364. u32 oc_seqid /* request */;
  365. stateid_t oc_resp_stateid /* response */;
  366. };
  367. struct nfsd4_open_downgrade {
  368. stateid_t od_stateid;
  369. u32 od_seqid;
  370. u32 od_share_access; /* request */
  371. u32 od_deleg_want; /* request */
  372. u32 od_share_deny; /* request */
  373. };
  374. struct nfsd4_read {
  375. stateid_t rd_stateid; /* request */
  376. u64 rd_offset; /* request */
  377. u32 rd_length; /* request */
  378. int rd_vlen;
  379. struct nfsd_file *rd_nf;
  380. struct svc_rqst *rd_rqstp; /* response */
  381. struct svc_fh *rd_fhp; /* response */
  382. u32 rd_eof; /* response */
  383. };
  384. struct nfsd4_readdir {
  385. u64 rd_cookie; /* request */
  386. nfs4_verifier rd_verf; /* request */
  387. u32 rd_dircount; /* request */
  388. u32 rd_maxcount; /* request */
  389. u32 rd_bmval[3]; /* request */
  390. struct svc_rqst *rd_rqstp; /* response */
  391. struct svc_fh * rd_fhp; /* response */
  392. struct readdir_cd common;
  393. struct xdr_stream *xdr;
  394. int cookie_offset;
  395. };
  396. struct nfsd4_release_lockowner {
  397. clientid_t rl_clientid;
  398. struct xdr_netobj rl_owner;
  399. };
  400. struct nfsd4_readlink {
  401. struct svc_rqst *rl_rqstp; /* request */
  402. struct svc_fh * rl_fhp; /* request */
  403. };
  404. struct nfsd4_remove {
  405. u32 rm_namelen; /* request */
  406. char * rm_name; /* request */
  407. struct nfsd4_change_info rm_cinfo; /* response */
  408. };
  409. struct nfsd4_rename {
  410. u32 rn_snamelen; /* request */
  411. char * rn_sname; /* request */
  412. u32 rn_tnamelen; /* request */
  413. char * rn_tname; /* request */
  414. struct nfsd4_change_info rn_sinfo; /* response */
  415. struct nfsd4_change_info rn_tinfo; /* response */
  416. };
  417. struct nfsd4_secinfo {
  418. u32 si_namelen; /* request */
  419. char *si_name; /* request */
  420. struct svc_export *si_exp; /* response */
  421. };
  422. struct nfsd4_secinfo_no_name {
  423. u32 sin_style; /* request */
  424. struct svc_export *sin_exp; /* response */
  425. };
  426. struct nfsd4_setattr {
  427. stateid_t sa_stateid; /* request */
  428. u32 sa_bmval[3]; /* request */
  429. struct iattr sa_iattr; /* request */
  430. struct nfs4_acl *sa_acl;
  431. struct xdr_netobj sa_label;
  432. };
  433. struct nfsd4_setclientid {
  434. nfs4_verifier se_verf; /* request */
  435. struct xdr_netobj se_name;
  436. u32 se_callback_prog; /* request */
  437. u32 se_callback_netid_len; /* request */
  438. char * se_callback_netid_val; /* request */
  439. u32 se_callback_addr_len; /* request */
  440. char * se_callback_addr_val; /* request */
  441. u32 se_callback_ident; /* request */
  442. clientid_t se_clientid; /* response */
  443. nfs4_verifier se_confirm; /* response */
  444. };
  445. struct nfsd4_setclientid_confirm {
  446. clientid_t sc_clientid;
  447. nfs4_verifier sc_confirm;
  448. };
  449. struct nfsd4_test_stateid_id {
  450. __be32 ts_id_status;
  451. stateid_t ts_id_stateid;
  452. struct list_head ts_id_list;
  453. };
  454. struct nfsd4_test_stateid {
  455. u32 ts_num_ids;
  456. struct list_head ts_stateid_list;
  457. };
  458. struct nfsd4_free_stateid {
  459. stateid_t fr_stateid; /* request */
  460. };
  461. struct nfsd4_get_dir_delegation {
  462. /* request */
  463. u32 gdda_signal_deleg_avail;
  464. u32 gdda_notification_types[1];
  465. struct timespec64 gdda_child_attr_delay;
  466. struct timespec64 gdda_dir_attr_delay;
  467. u32 gdda_child_attributes[3];
  468. u32 gdda_dir_attributes[3];
  469. /* response */
  470. u32 gddrnf_status;
  471. nfs4_verifier gddr_cookieverf;
  472. stateid_t gddr_stateid;
  473. u32 gddr_notification[1];
  474. u32 gddr_child_attributes[3];
  475. u32 gddr_dir_attributes[3];
  476. bool gddrnf_will_signal_deleg_avail;
  477. };
  478. /* also used for NVERIFY */
  479. struct nfsd4_verify {
  480. u32 ve_bmval[3]; /* request */
  481. u32 ve_attrlen; /* request */
  482. char * ve_attrval; /* request */
  483. };
  484. struct nfsd4_write {
  485. stateid_t wr_stateid; /* request */
  486. u64 wr_offset; /* request */
  487. u32 wr_stable_how; /* request */
  488. u32 wr_buflen; /* request */
  489. struct xdr_buf wr_payload; /* request */
  490. u32 wr_bytes_written; /* response */
  491. u32 wr_how_written; /* response */
  492. nfs4_verifier wr_verifier; /* response */
  493. };
  494. struct nfsd4_exchange_id {
  495. nfs4_verifier verifier;
  496. struct xdr_netobj clname;
  497. u32 flags;
  498. clientid_t clientid;
  499. u32 seqid;
  500. u32 spa_how;
  501. u32 spo_must_enforce[3];
  502. u32 spo_must_allow[3];
  503. struct xdr_netobj nii_domain;
  504. struct xdr_netobj nii_name;
  505. struct timespec64 nii_time;
  506. };
  507. struct nfsd4_sequence {
  508. struct nfs4_sessionid sessionid; /* request/response */
  509. u32 seqid; /* request/response */
  510. u32 slotid; /* request/response */
  511. u32 maxslots; /* request/response */
  512. u32 cachethis; /* request */
  513. #if 0
  514. u32 target_maxslots; /* response */
  515. #endif /* not yet */
  516. u32 status_flags; /* response */
  517. };
  518. struct nfsd4_destroy_session {
  519. struct nfs4_sessionid sessionid;
  520. };
  521. struct nfsd4_destroy_clientid {
  522. clientid_t clientid;
  523. };
  524. struct nfsd4_reclaim_complete {
  525. u32 rca_one_fs;
  526. };
  527. struct nfsd4_deviceid {
  528. u64 fsid_idx;
  529. u32 generation;
  530. };
  531. static inline __be32 *
  532. svcxdr_encode_deviceid4(__be32 *p, const struct nfsd4_deviceid *devid)
  533. {
  534. __be64 *q = (__be64 *)p;
  535. *q = (__force __be64)devid->fsid_idx;
  536. p += 2;
  537. *p++ = (__force __be32)devid->generation;
  538. *p++ = xdr_zero;
  539. return p;
  540. }
  541. static inline __be32 *
  542. svcxdr_decode_deviceid4(__be32 *p, struct nfsd4_deviceid *devid)
  543. {
  544. __be64 *q = (__be64 *)p;
  545. devid->fsid_idx = (__force u64)(*q);
  546. p += 2;
  547. devid->generation = (__force u32)(*p++);
  548. p++; /* NFSD does not use the remaining octets */
  549. return p;
  550. }
  551. static inline __be32
  552. nfsd4_decode_deviceid4(struct xdr_stream *xdr, struct nfsd4_deviceid *devid)
  553. {
  554. __be32 *p = xdr_inline_decode(xdr, NFS4_DEVICEID4_SIZE);
  555. if (unlikely(!p))
  556. return nfserr_bad_xdr;
  557. svcxdr_decode_deviceid4(p, devid);
  558. return nfs_ok;
  559. }
  560. struct nfsd4_layout_seg {
  561. u32 iomode;
  562. u64 offset;
  563. u64 length;
  564. };
  565. struct nfsd4_getdeviceinfo {
  566. struct nfsd4_deviceid gd_devid; /* request */
  567. u32 gd_layout_type; /* request */
  568. u32 gd_maxcount; /* request */
  569. u32 gd_notify_types;/* request - response */
  570. void *gd_device; /* response */
  571. };
  572. struct nfsd4_layoutget {
  573. u64 lg_minlength; /* request */
  574. u32 lg_signal; /* request */
  575. u32 lg_layout_type; /* request */
  576. u32 lg_maxcount; /* request */
  577. stateid_t lg_sid; /* request/response */
  578. struct nfsd4_layout_seg lg_seg; /* request/response */
  579. void *lg_content; /* response */
  580. };
  581. struct nfsd4_layoutcommit {
  582. stateid_t lc_sid; /* request */
  583. struct nfsd4_layout_seg lc_seg; /* request */
  584. u32 lc_reclaim; /* request */
  585. u32 lc_newoffset; /* request */
  586. u64 lc_last_wr; /* request */
  587. struct timespec64 lc_mtime; /* request */
  588. u32 lc_layout_type; /* request */
  589. struct xdr_buf lc_up_layout; /* decoded by callback */
  590. bool lc_size_chg; /* response */
  591. u64 lc_newsize; /* response */
  592. };
  593. struct nfsd4_layoutreturn {
  594. u32 lr_return_type; /* request */
  595. u32 lr_layout_type; /* request */
  596. struct nfsd4_layout_seg lr_seg; /* request */
  597. u32 lr_reclaim; /* request */
  598. u32 lrf_body_len; /* request */
  599. void *lrf_body; /* request */
  600. stateid_t lr_sid; /* request/response */
  601. bool lrs_present; /* response */
  602. };
  603. struct nfsd4_fallocate {
  604. /* request */
  605. stateid_t falloc_stateid;
  606. loff_t falloc_offset;
  607. u64 falloc_length;
  608. };
  609. struct nfsd4_clone {
  610. /* request */
  611. stateid_t cl_src_stateid;
  612. stateid_t cl_dst_stateid;
  613. u64 cl_src_pos;
  614. u64 cl_dst_pos;
  615. u64 cl_count;
  616. };
  617. struct nfsd42_write_res {
  618. u64 wr_bytes_written;
  619. u32 wr_stable_how;
  620. nfs4_verifier wr_verifier;
  621. stateid_t cb_stateid;
  622. };
  623. struct nfsd4_cb_offload {
  624. struct nfsd4_callback co_cb;
  625. struct nfsd42_write_res co_res;
  626. __be32 co_nfserr;
  627. struct knfsd_fh co_fh;
  628. };
  629. struct nfsd4_copy {
  630. /* request */
  631. stateid_t cp_src_stateid;
  632. stateid_t cp_dst_stateid;
  633. u64 cp_src_pos;
  634. u64 cp_dst_pos;
  635. u64 cp_count;
  636. struct nl4_server *cp_src;
  637. unsigned long cp_flags;
  638. #define NFSD4_COPY_F_STOPPED (0)
  639. #define NFSD4_COPY_F_INTRA (1)
  640. #define NFSD4_COPY_F_SYNCHRONOUS (2)
  641. #define NFSD4_COPY_F_COMMITTED (3)
  642. #define NFSD4_COPY_F_COMPLETED (4)
  643. /* response */
  644. __be32 nfserr;
  645. struct nfsd42_write_res cp_res;
  646. struct knfsd_fh fh;
  647. struct nfs4_client *cp_clp;
  648. struct nfsd_file *nf_src;
  649. struct nfsd_file *nf_dst;
  650. copy_stateid_t cp_stateid;
  651. struct list_head copies;
  652. struct task_struct *copy_task;
  653. refcount_t refcount;
  654. struct nfsd4_ssc_umount_item *ss_nsui;
  655. struct nfs_fh c_fh;
  656. nfs4_stateid stateid;
  657. struct nfsd_net *cp_nn;
  658. };
  659. static inline void nfsd4_copy_set_sync(struct nfsd4_copy *copy, bool sync)
  660. {
  661. if (sync)
  662. set_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
  663. else
  664. clear_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
  665. }
  666. static inline bool nfsd4_copy_is_sync(const struct nfsd4_copy *copy)
  667. {
  668. return test_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
  669. }
  670. static inline bool nfsd4_copy_is_async(const struct nfsd4_copy *copy)
  671. {
  672. return !test_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
  673. }
  674. static inline bool nfsd4_ssc_is_inter(const struct nfsd4_copy *copy)
  675. {
  676. return !test_bit(NFSD4_COPY_F_INTRA, &copy->cp_flags);
  677. }
  678. struct nfsd4_seek {
  679. /* request */
  680. stateid_t seek_stateid;
  681. loff_t seek_offset;
  682. u32 seek_whence;
  683. /* response */
  684. u32 seek_eof;
  685. loff_t seek_pos;
  686. };
  687. struct nfsd4_offload_status {
  688. /* request */
  689. stateid_t stateid;
  690. /* response */
  691. u64 count;
  692. __be32 status;
  693. bool completed;
  694. };
  695. struct nfsd4_copy_notify {
  696. /* request */
  697. stateid_t cpn_src_stateid;
  698. struct nl4_server *cpn_dst;
  699. /* response */
  700. stateid_t cpn_cnr_stateid;
  701. struct timespec64 cpn_lease_time;
  702. struct nl4_server *cpn_src;
  703. };
  704. struct nfsd4_op {
  705. u32 opnum;
  706. __be32 status;
  707. const struct nfsd4_operation *opdesc;
  708. struct nfs4_replay *replay;
  709. union nfsd4_op_u {
  710. struct nfsd4_access access;
  711. struct nfsd4_close close;
  712. struct nfsd4_commit commit;
  713. struct nfsd4_create create;
  714. struct nfsd4_delegreturn delegreturn;
  715. struct nfsd4_getattr getattr;
  716. struct svc_fh * getfh;
  717. struct nfsd4_link link;
  718. struct nfsd4_lock lock;
  719. struct nfsd4_lockt lockt;
  720. struct nfsd4_locku locku;
  721. struct nfsd4_lookup lookup;
  722. struct nfsd4_verify nverify;
  723. struct nfsd4_open open;
  724. struct nfsd4_open_confirm open_confirm;
  725. struct nfsd4_open_downgrade open_downgrade;
  726. struct nfsd4_putfh putfh;
  727. struct nfsd4_read read;
  728. struct nfsd4_readdir readdir;
  729. struct nfsd4_readlink readlink;
  730. struct nfsd4_remove remove;
  731. struct nfsd4_rename rename;
  732. clientid_t renew;
  733. struct nfsd4_secinfo secinfo;
  734. struct nfsd4_setattr setattr;
  735. struct nfsd4_setclientid setclientid;
  736. struct nfsd4_setclientid_confirm setclientid_confirm;
  737. struct nfsd4_verify verify;
  738. struct nfsd4_write write;
  739. struct nfsd4_release_lockowner release_lockowner;
  740. /* NFSv4.1 */
  741. struct nfsd4_exchange_id exchange_id;
  742. struct nfsd4_backchannel_ctl backchannel_ctl;
  743. struct nfsd4_bind_conn_to_session bind_conn_to_session;
  744. struct nfsd4_create_session create_session;
  745. struct nfsd4_destroy_session destroy_session;
  746. struct nfsd4_destroy_clientid destroy_clientid;
  747. struct nfsd4_sequence sequence;
  748. struct nfsd4_reclaim_complete reclaim_complete;
  749. struct nfsd4_test_stateid test_stateid;
  750. struct nfsd4_free_stateid free_stateid;
  751. struct nfsd4_get_dir_delegation get_dir_delegation;
  752. struct nfsd4_getdeviceinfo getdeviceinfo;
  753. struct nfsd4_layoutget layoutget;
  754. struct nfsd4_layoutcommit layoutcommit;
  755. struct nfsd4_layoutreturn layoutreturn;
  756. struct nfsd4_secinfo_no_name secinfo_no_name;
  757. /* NFSv4.2 */
  758. struct nfsd4_fallocate allocate;
  759. struct nfsd4_fallocate deallocate;
  760. struct nfsd4_clone clone;
  761. struct nfsd4_copy copy;
  762. struct nfsd4_offload_status offload_status;
  763. struct nfsd4_copy_notify copy_notify;
  764. struct nfsd4_seek seek;
  765. struct nfsd4_getxattr getxattr;
  766. struct nfsd4_setxattr setxattr;
  767. struct nfsd4_listxattrs listxattrs;
  768. struct nfsd4_removexattr removexattr;
  769. } u;
  770. };
  771. bool nfsd4_cache_this_op(struct nfsd4_op *);
  772. /*
  773. * Memory needed just for the duration of processing one compound:
  774. */
  775. struct svcxdr_tmpbuf {
  776. struct svcxdr_tmpbuf *next;
  777. char buf[];
  778. };
  779. struct nfsd4_compoundargs {
  780. /* scratch variables for XDR decode */
  781. struct xdr_stream *xdr;
  782. struct svcxdr_tmpbuf *to_free;
  783. struct svc_rqst *rqstp;
  784. char * tag;
  785. u32 taglen;
  786. u32 minorversion;
  787. u32 client_opcnt;
  788. u32 opcnt;
  789. bool splice_ok;
  790. struct nfsd4_op *ops;
  791. struct nfsd4_op iops[8];
  792. };
  793. struct nfsd4_compoundres {
  794. /* scratch variables for XDR encode */
  795. struct xdr_stream *xdr;
  796. struct svc_rqst * rqstp;
  797. __be32 *statusp;
  798. char * tag;
  799. u32 taglen;
  800. u32 opcnt;
  801. struct nfsd4_compound_state cstate;
  802. };
  803. static inline bool nfsd4_is_solo_sequence(struct nfsd4_compoundres *resp)
  804. {
  805. struct nfsd4_compoundargs *args = resp->rqstp->rq_argp;
  806. return resp->opcnt == 1 && args->ops[0].opnum == OP_SEQUENCE;
  807. }
  808. /*
  809. * The session reply cache only needs to cache replies that the client
  810. * actually asked us to. But it's almost free for us to cache compounds
  811. * consisting of only a SEQUENCE op, so we may as well cache those too.
  812. * Also, the protocol doesn't give us a convenient response in the case
  813. * of a replay of a solo SEQUENCE op that wasn't cached
  814. * (RETRY_UNCACHED_REP can only be returned in the second op of a
  815. * compound).
  816. */
  817. static inline bool nfsd4_cache_this(struct nfsd4_compoundres *resp)
  818. {
  819. return (resp->cstate.slot->sl_flags & NFSD4_SLOT_CACHETHIS)
  820. || nfsd4_is_solo_sequence(resp);
  821. }
  822. static inline bool nfsd4_last_compound_op(struct svc_rqst *rqstp)
  823. {
  824. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  825. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  826. return argp->opcnt == resp->opcnt;
  827. }
  828. const struct nfsd4_operation *OPDESC(struct nfsd4_op *op);
  829. int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op);
  830. void warn_on_nonidempotent_op(struct nfsd4_op *op);
  831. #define NFS4_SVC_XDRSIZE sizeof(struct nfsd4_compoundargs)
  832. bool nfsd4_mach_creds_match(struct nfs4_client *cl, struct svc_rqst *rqstp);
  833. bool nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
  834. bool nfs4svc_encode_compoundres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
  835. __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *, u32);
  836. void nfsd4_encode_operation(struct nfsd4_compoundres *, struct nfsd4_op *);
  837. void nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op);
  838. __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words,
  839. struct svc_fh *fhp, struct svc_export *exp,
  840. struct dentry *dentry,
  841. u32 *bmval, struct svc_rqst *, int ignore_crossmnt);
  842. extern __be32 nfsd4_setclientid(struct svc_rqst *rqstp,
  843. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  844. extern __be32 nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
  845. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  846. extern __be32 nfsd4_exchange_id(struct svc_rqst *rqstp,
  847. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  848. extern __be32 nfsd4_backchannel_ctl(struct svc_rqst *,
  849. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  850. extern __be32 nfsd4_bind_conn_to_session(struct svc_rqst *,
  851. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  852. extern __be32 nfsd4_create_session(struct svc_rqst *,
  853. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  854. extern __be32 nfsd4_sequence(struct svc_rqst *,
  855. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  856. extern void nfsd4_sequence_done(struct nfsd4_compoundres *resp);
  857. extern __be32 nfsd4_destroy_session(struct svc_rqst *,
  858. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  859. extern __be32 nfsd4_destroy_clientid(struct svc_rqst *, struct nfsd4_compound_state *,
  860. union nfsd4_op_u *u);
  861. __be32 nfsd4_reclaim_complete(struct svc_rqst *, struct nfsd4_compound_state *,
  862. union nfsd4_op_u *u);
  863. extern __be32 nfsd4_process_open1(struct nfsd4_compound_state *,
  864. struct nfsd4_open *open, struct nfsd_net *nn);
  865. extern __be32 nfsd4_process_open2(struct svc_rqst *rqstp,
  866. struct svc_fh *current_fh, struct nfsd4_open *open);
  867. extern void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate);
  868. extern void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate,
  869. struct nfsd4_open *open);
  870. extern __be32 nfsd4_open_confirm(struct svc_rqst *rqstp,
  871. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  872. extern __be32 nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  873. union nfsd4_op_u *u);
  874. extern __be32 nfsd4_open_downgrade(struct svc_rqst *rqstp,
  875. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  876. extern __be32 nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  877. union nfsd4_op_u *u);
  878. extern void nfsd4_lock_release(union nfsd4_op_u *u);
  879. extern __be32 nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  880. union nfsd4_op_u *u);
  881. extern void nfsd4_lockt_release(union nfsd4_op_u *u);
  882. extern __be32 nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  883. union nfsd4_op_u *u);
  884. extern __be32
  885. nfsd4_release_lockowner(struct svc_rqst *rqstp,
  886. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  887. extern void nfsd4_release_compoundargs(struct svc_rqst *rqstp);
  888. extern __be32 nfsd4_delegreturn(struct svc_rqst *rqstp,
  889. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  890. extern __be32 nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  891. union nfsd4_op_u *u);
  892. extern __be32 nfsd4_test_stateid(struct svc_rqst *rqstp,
  893. struct nfsd4_compound_state *, union nfsd4_op_u *);
  894. extern __be32 nfsd4_free_stateid(struct svc_rqst *rqstp,
  895. struct nfsd4_compound_state *, union nfsd4_op_u *);
  896. extern void nfsd4_bump_seqid(struct nfsd4_compound_state *, __be32 nfserr);
  897. enum nfsd4_op_flags {
  898. ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
  899. ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */
  900. ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */
  901. /* For rfc 5661 section 2.6.3.1.1: */
  902. OP_HANDLES_WRONGSEC = 1 << 3,
  903. OP_IS_PUTFH_LIKE = 1 << 4,
  904. /*
  905. * These are the ops whose result size we estimate before
  906. * encoding, to avoid performing an op then not being able to
  907. * respond or cache a response. This includes writes and setattrs
  908. * as well as the operations usually called "nonidempotent":
  909. */
  910. OP_MODIFIES_SOMETHING = 1 << 5,
  911. /*
  912. * Cache compounds containing these ops in the xid-based drc:
  913. * We use the DRC for compounds containing non-idempotent
  914. * operations, *except* those that are 4.1-specific (since
  915. * sessions provide their own EOS), and except for stateful
  916. * operations other than setclientid and setclientid_confirm
  917. * (since sequence numbers provide EOS for open, lock, etc in
  918. * the v4.0 case).
  919. */
  920. OP_CACHEME = 1 << 6,
  921. /*
  922. * These are ops which clear current state id.
  923. */
  924. OP_CLEAR_STATEID = 1 << 7,
  925. /* Most ops return only an error on failure; some may do more: */
  926. OP_NONTRIVIAL_ERROR_ENCODE = 1 << 8,
  927. };
  928. struct nfsd4_operation {
  929. __be32 (*op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
  930. union nfsd4_op_u *);
  931. void (*op_release)(union nfsd4_op_u *);
  932. u32 op_flags;
  933. char *op_name;
  934. /* Try to get response size before operation */
  935. u32 (*op_rsize_bop)(const struct svc_rqst *rqstp,
  936. const struct nfsd4_op *op);
  937. void (*op_get_currentstateid)(struct nfsd4_compound_state *,
  938. union nfsd4_op_u *);
  939. void (*op_set_currentstateid)(struct nfsd4_compound_state *,
  940. union nfsd4_op_u *);
  941. };
  942. struct nfsd4_cb_recall_any {
  943. struct nfsd4_callback ra_cb;
  944. u32 ra_keep;
  945. u32 ra_bmval[1];
  946. };
  947. #endif