xdr4.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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 posix_acl *cr_dpacl;
  224. struct posix_acl *cr_pacl;
  225. struct xdr_netobj cr_label;
  226. };
  227. #define cr_datalen u.link.datalen
  228. #define cr_data u.link.data
  229. #define cr_first u.link.first
  230. #define cr_specdata1 u.dev.specdata1
  231. #define cr_specdata2 u.dev.specdata2
  232. struct nfsd4_delegreturn {
  233. stateid_t dr_stateid;
  234. };
  235. struct nfsd4_getattr {
  236. u32 ga_bmval[3]; /* request */
  237. struct svc_fh *ga_fhp; /* response */
  238. };
  239. struct nfsd4_link {
  240. u32 li_namelen; /* request */
  241. char * li_name; /* request */
  242. struct nfsd4_change_info li_cinfo; /* response */
  243. };
  244. struct nfsd4_lock_denied {
  245. clientid_t ld_clientid;
  246. struct xdr_netobj ld_owner;
  247. u64 ld_start;
  248. u64 ld_length;
  249. u32 ld_type;
  250. };
  251. struct nfsd4_lock {
  252. /* request */
  253. u32 lk_type;
  254. u32 lk_reclaim; /* boolean */
  255. u64 lk_offset;
  256. u64 lk_length;
  257. u32 lk_is_new;
  258. union {
  259. struct {
  260. u32 open_seqid;
  261. stateid_t open_stateid;
  262. u32 lock_seqid;
  263. clientid_t clientid;
  264. struct xdr_netobj owner;
  265. } new;
  266. struct {
  267. stateid_t lock_stateid;
  268. u32 lock_seqid;
  269. } old;
  270. } v;
  271. /* response */
  272. stateid_t lk_resp_stateid;
  273. struct nfsd4_lock_denied lk_denied;
  274. };
  275. #define lk_new_open_seqid v.new.open_seqid
  276. #define lk_new_open_stateid v.new.open_stateid
  277. #define lk_new_lock_seqid v.new.lock_seqid
  278. #define lk_new_clientid v.new.clientid
  279. #define lk_new_owner v.new.owner
  280. #define lk_old_lock_stateid v.old.lock_stateid
  281. #define lk_old_lock_seqid v.old.lock_seqid
  282. struct nfsd4_lockt {
  283. u32 lt_type;
  284. clientid_t lt_clientid;
  285. struct xdr_netobj lt_owner;
  286. u64 lt_offset;
  287. u64 lt_length;
  288. struct nfsd4_lock_denied lt_denied;
  289. };
  290. struct nfsd4_locku {
  291. u32 lu_type;
  292. u32 lu_seqid;
  293. stateid_t lu_stateid;
  294. u64 lu_offset;
  295. u64 lu_length;
  296. };
  297. struct nfsd4_lookup {
  298. u32 lo_len; /* request */
  299. char * lo_name; /* request */
  300. };
  301. struct nfsd4_putfh {
  302. u32 pf_fhlen; /* request */
  303. char *pf_fhval; /* request */
  304. bool no_verify; /* represents foreigh fh */
  305. };
  306. struct nfsd4_getxattr {
  307. char *getxa_name; /* request */
  308. u32 getxa_len; /* request */
  309. void *getxa_buf;
  310. };
  311. struct nfsd4_setxattr {
  312. u32 setxa_flags; /* request */
  313. char *setxa_name; /* request */
  314. char *setxa_buf; /* request */
  315. u32 setxa_len; /* request */
  316. struct nfsd4_change_info setxa_cinfo; /* response */
  317. };
  318. struct nfsd4_removexattr {
  319. char *rmxa_name; /* request */
  320. struct nfsd4_change_info rmxa_cinfo; /* response */
  321. };
  322. struct nfsd4_listxattrs {
  323. u64 lsxa_cookie; /* request */
  324. u32 lsxa_maxcount; /* request */
  325. char *lsxa_buf; /* unfiltered buffer (reply) */
  326. u32 lsxa_len; /* unfiltered len (reply) */
  327. };
  328. struct nfsd4_open {
  329. u32 op_claim_type; /* request */
  330. u32 op_fnamelen;
  331. char * op_fname; /* request - everything but CLAIM_PREV */
  332. u32 op_delegate_type; /* request - CLAIM_PREV only */
  333. stateid_t op_delegate_stateid; /* request - response */
  334. u32 op_why_no_deleg; /* response - DELEG_NONE_EXT only */
  335. u32 op_create; /* request */
  336. u32 op_createmode; /* request */
  337. int op_umask; /* request */
  338. u32 op_bmval[3]; /* request */
  339. struct iattr op_iattr; /* UNCHECKED4, GUARDED4, EXCLUSIVE4_1 */
  340. nfs4_verifier op_verf __attribute__((aligned(32)));
  341. /* EXCLUSIVE4 */
  342. clientid_t op_clientid; /* request */
  343. struct xdr_netobj op_owner; /* request */
  344. u32 op_seqid; /* request */
  345. u32 op_share_access; /* request */
  346. u32 op_share_deny; /* request */
  347. u32 op_deleg_want; /* request */
  348. stateid_t op_stateid; /* response */
  349. __be32 op_xdr_error; /* see nfsd4_open_omfg() */
  350. struct nfsd4_change_info op_cinfo; /* response */
  351. u32 op_rflags; /* response */
  352. bool op_recall; /* response */
  353. bool op_truncate; /* used during processing */
  354. bool op_created; /* used during processing */
  355. struct nfs4_openowner *op_openowner; /* used during processing */
  356. struct file *op_filp; /* used during processing */
  357. struct nfs4_file *op_file; /* used during processing */
  358. struct nfs4_ol_stateid *op_stp; /* used during processing */
  359. struct nfs4_clnt_odstate *op_odstate; /* used during processing */
  360. struct nfs4_acl *op_acl;
  361. struct posix_acl *op_dpacl;
  362. struct posix_acl *op_pacl;
  363. struct xdr_netobj op_label;
  364. struct svc_rqst *op_rqstp;
  365. };
  366. struct nfsd4_open_confirm {
  367. stateid_t oc_req_stateid /* request */;
  368. u32 oc_seqid /* request */;
  369. stateid_t oc_resp_stateid /* response */;
  370. };
  371. struct nfsd4_open_downgrade {
  372. stateid_t od_stateid;
  373. u32 od_seqid;
  374. u32 od_share_access; /* request */
  375. u32 od_deleg_want; /* request */
  376. u32 od_share_deny; /* request */
  377. };
  378. struct nfsd4_read {
  379. stateid_t rd_stateid; /* request */
  380. u64 rd_offset; /* request */
  381. u32 rd_length; /* request */
  382. int rd_vlen;
  383. struct nfsd_file *rd_nf;
  384. struct svc_rqst *rd_rqstp; /* response */
  385. struct svc_fh *rd_fhp; /* response */
  386. u32 rd_eof; /* response */
  387. };
  388. struct nfsd4_readdir {
  389. u64 rd_cookie; /* request */
  390. nfs4_verifier rd_verf; /* request */
  391. u32 rd_dircount; /* request */
  392. u32 rd_maxcount; /* request */
  393. u32 rd_bmval[3]; /* request */
  394. struct svc_rqst *rd_rqstp; /* response */
  395. struct svc_fh * rd_fhp; /* response */
  396. struct readdir_cd common;
  397. struct xdr_stream *xdr;
  398. int cookie_offset;
  399. };
  400. struct nfsd4_release_lockowner {
  401. clientid_t rl_clientid;
  402. struct xdr_netobj rl_owner;
  403. };
  404. struct nfsd4_readlink {
  405. struct svc_rqst *rl_rqstp; /* request */
  406. struct svc_fh * rl_fhp; /* request */
  407. };
  408. struct nfsd4_remove {
  409. u32 rm_namelen; /* request */
  410. char * rm_name; /* request */
  411. struct nfsd4_change_info rm_cinfo; /* response */
  412. };
  413. struct nfsd4_rename {
  414. u32 rn_snamelen; /* request */
  415. char * rn_sname; /* request */
  416. u32 rn_tnamelen; /* request */
  417. char * rn_tname; /* request */
  418. struct nfsd4_change_info rn_sinfo; /* response */
  419. struct nfsd4_change_info rn_tinfo; /* response */
  420. };
  421. struct nfsd4_secinfo {
  422. u32 si_namelen; /* request */
  423. char *si_name; /* request */
  424. struct svc_export *si_exp; /* response */
  425. };
  426. struct nfsd4_secinfo_no_name {
  427. u32 sin_style; /* request */
  428. struct svc_export *sin_exp; /* response */
  429. };
  430. struct nfsd4_setattr {
  431. stateid_t sa_stateid; /* request */
  432. u32 sa_bmval[3]; /* request */
  433. struct iattr sa_iattr; /* request */
  434. struct nfs4_acl *sa_acl;
  435. struct xdr_netobj sa_label;
  436. struct posix_acl *sa_dpacl;
  437. struct posix_acl *sa_pacl;
  438. };
  439. struct nfsd4_setclientid {
  440. nfs4_verifier se_verf; /* request */
  441. struct xdr_netobj se_name;
  442. u32 se_callback_prog; /* request */
  443. u32 se_callback_netid_len; /* request */
  444. char * se_callback_netid_val; /* request */
  445. u32 se_callback_addr_len; /* request */
  446. char * se_callback_addr_val; /* request */
  447. u32 se_callback_ident; /* request */
  448. clientid_t se_clientid; /* response */
  449. nfs4_verifier se_confirm; /* response */
  450. };
  451. struct nfsd4_setclientid_confirm {
  452. clientid_t sc_clientid;
  453. nfs4_verifier sc_confirm;
  454. };
  455. struct nfsd4_test_stateid_id {
  456. __be32 ts_id_status;
  457. stateid_t ts_id_stateid;
  458. struct list_head ts_id_list;
  459. };
  460. struct nfsd4_test_stateid {
  461. u32 ts_num_ids;
  462. struct list_head ts_stateid_list;
  463. };
  464. struct nfsd4_free_stateid {
  465. stateid_t fr_stateid; /* request */
  466. };
  467. struct nfsd4_get_dir_delegation {
  468. /* request */
  469. u32 gdda_signal_deleg_avail;
  470. u32 gdda_notification_types[1];
  471. struct timespec64 gdda_child_attr_delay;
  472. struct timespec64 gdda_dir_attr_delay;
  473. u32 gdda_child_attributes[3];
  474. u32 gdda_dir_attributes[3];
  475. /* response */
  476. u32 gddrnf_status;
  477. nfs4_verifier gddr_cookieverf;
  478. stateid_t gddr_stateid;
  479. u32 gddr_notification[1];
  480. u32 gddr_child_attributes[3];
  481. u32 gddr_dir_attributes[3];
  482. bool gddrnf_will_signal_deleg_avail;
  483. };
  484. /* also used for NVERIFY */
  485. struct nfsd4_verify {
  486. u32 ve_bmval[3]; /* request */
  487. u32 ve_attrlen; /* request */
  488. char * ve_attrval; /* request */
  489. };
  490. struct nfsd4_write {
  491. stateid_t wr_stateid; /* request */
  492. u64 wr_offset; /* request */
  493. u32 wr_stable_how; /* request */
  494. u32 wr_buflen; /* request */
  495. struct xdr_buf wr_payload; /* request */
  496. u32 wr_bytes_written; /* response */
  497. u32 wr_how_written; /* response */
  498. nfs4_verifier wr_verifier; /* response */
  499. };
  500. struct nfsd4_exchange_id {
  501. nfs4_verifier verifier;
  502. struct xdr_netobj clname;
  503. u32 flags;
  504. clientid_t clientid;
  505. u32 seqid;
  506. u32 spa_how;
  507. u32 spo_must_enforce[3];
  508. u32 spo_must_allow[3];
  509. struct xdr_netobj nii_domain;
  510. struct xdr_netobj nii_name;
  511. struct timespec64 nii_time;
  512. char *server_impl_name;
  513. };
  514. struct nfsd4_sequence {
  515. struct nfs4_sessionid sessionid; /* request/response */
  516. u32 seqid; /* request/response */
  517. u32 slotid; /* request/response */
  518. u32 maxslots; /* request */
  519. u32 cachethis; /* request */
  520. u32 maxslots_response; /* response */
  521. u32 target_maxslots; /* response */
  522. u32 status_flags; /* response */
  523. };
  524. struct nfsd4_destroy_session {
  525. struct nfs4_sessionid sessionid;
  526. };
  527. struct nfsd4_destroy_clientid {
  528. clientid_t clientid;
  529. };
  530. struct nfsd4_reclaim_complete {
  531. u32 rca_one_fs;
  532. };
  533. struct nfsd4_deviceid {
  534. u64 fsid_idx;
  535. u32 generation;
  536. };
  537. static inline __be32 *
  538. svcxdr_encode_deviceid4(__be32 *p, const struct nfsd4_deviceid *devid)
  539. {
  540. __be64 *q = (__be64 *)p;
  541. *q = (__force __be64)devid->fsid_idx;
  542. p += 2;
  543. *p++ = (__force __be32)devid->generation;
  544. *p++ = xdr_zero;
  545. return p;
  546. }
  547. static inline __be32 *
  548. svcxdr_decode_deviceid4(__be32 *p, struct nfsd4_deviceid *devid)
  549. {
  550. __be64 *q = (__be64 *)p;
  551. devid->fsid_idx = (__force u64)(*q);
  552. p += 2;
  553. devid->generation = (__force u32)(*p++);
  554. p++; /* NFSD does not use the remaining octets */
  555. return p;
  556. }
  557. static inline __be32
  558. nfsd4_decode_deviceid4(struct xdr_stream *xdr, struct nfsd4_deviceid *devid)
  559. {
  560. __be32 *p = xdr_inline_decode(xdr, NFS4_DEVICEID4_SIZE);
  561. if (unlikely(!p))
  562. return nfserr_bad_xdr;
  563. svcxdr_decode_deviceid4(p, devid);
  564. return nfs_ok;
  565. }
  566. struct nfsd4_layout_seg {
  567. u32 iomode;
  568. u64 offset;
  569. u64 length;
  570. };
  571. struct nfsd4_getdeviceinfo {
  572. struct nfsd4_deviceid gd_devid; /* request */
  573. u32 gd_layout_type; /* request */
  574. u32 gd_maxcount; /* request */
  575. u32 gd_notify_types;/* request - response */
  576. void *gd_device; /* response */
  577. };
  578. struct nfsd4_layoutget {
  579. u64 lg_minlength; /* request */
  580. u32 lg_signal; /* request */
  581. u32 lg_layout_type; /* request */
  582. u32 lg_maxcount; /* request */
  583. stateid_t lg_sid; /* request/response */
  584. struct nfsd4_layout_seg lg_seg; /* request/response */
  585. void *lg_content; /* response */
  586. };
  587. struct nfsd4_layoutcommit {
  588. stateid_t lc_sid; /* request */
  589. struct nfsd4_layout_seg lc_seg; /* request */
  590. u32 lc_reclaim; /* request */
  591. u32 lc_newoffset; /* request */
  592. u64 lc_last_wr; /* request */
  593. struct timespec64 lc_mtime; /* request */
  594. u32 lc_layout_type; /* request */
  595. struct xdr_buf lc_up_layout; /* decoded by callback */
  596. bool lc_size_chg; /* response */
  597. u64 lc_newsize; /* response */
  598. };
  599. struct nfsd4_layoutreturn {
  600. u32 lr_return_type; /* request */
  601. u32 lr_layout_type; /* request */
  602. struct nfsd4_layout_seg lr_seg; /* request */
  603. u32 lr_reclaim; /* request */
  604. u32 lrf_body_len; /* request */
  605. void *lrf_body; /* request */
  606. stateid_t lr_sid; /* request/response */
  607. bool lrs_present; /* response */
  608. };
  609. struct nfsd4_fallocate {
  610. /* request */
  611. stateid_t falloc_stateid;
  612. loff_t falloc_offset;
  613. u64 falloc_length;
  614. };
  615. struct nfsd4_clone {
  616. /* request */
  617. stateid_t cl_src_stateid;
  618. stateid_t cl_dst_stateid;
  619. u64 cl_src_pos;
  620. u64 cl_dst_pos;
  621. u64 cl_count;
  622. };
  623. struct nfsd42_write_res {
  624. u64 wr_bytes_written;
  625. u32 wr_stable_how;
  626. nfs4_verifier wr_verifier;
  627. stateid_t cb_stateid;
  628. };
  629. struct nfsd4_cb_offload {
  630. struct nfsd4_callback co_cb;
  631. struct nfsd42_write_res co_res;
  632. __be32 co_nfserr;
  633. unsigned int co_retries;
  634. struct knfsd_fh co_fh;
  635. struct nfs4_sessionid co_referring_sessionid;
  636. u32 co_referring_slotid;
  637. u32 co_referring_seqno;
  638. };
  639. struct nfsd4_copy {
  640. /* request */
  641. stateid_t cp_src_stateid;
  642. stateid_t cp_dst_stateid;
  643. u64 cp_src_pos;
  644. u64 cp_dst_pos;
  645. u64 cp_count;
  646. struct nl4_server *cp_src;
  647. unsigned long cp_flags;
  648. #define NFSD4_COPY_F_STOPPED (0)
  649. #define NFSD4_COPY_F_INTRA (1)
  650. #define NFSD4_COPY_F_SYNCHRONOUS (2)
  651. #define NFSD4_COPY_F_COMMITTED (3)
  652. #define NFSD4_COPY_F_COMPLETED (4)
  653. #define NFSD4_COPY_F_OFFLOAD_DONE (5)
  654. #define NFSD4_COPY_F_CB_ERROR (6)
  655. /* response */
  656. __be32 nfserr;
  657. struct nfsd42_write_res cp_res;
  658. struct knfsd_fh fh;
  659. /* offload callback */
  660. struct nfsd4_cb_offload cp_cb_offload;
  661. struct nfs4_client *cp_clp;
  662. struct nfsd_file *nf_src;
  663. struct nfsd_file *nf_dst;
  664. copy_stateid_t cp_stateid;
  665. struct list_head copies;
  666. struct task_struct *copy_task;
  667. refcount_t refcount;
  668. unsigned int cp_ttl;
  669. struct nfsd4_ssc_umount_item *ss_nsui;
  670. struct nfs_fh c_fh;
  671. nfs4_stateid stateid;
  672. struct nfsd_net *cp_nn;
  673. };
  674. static inline void nfsd4_copy_set_sync(struct nfsd4_copy *copy, bool sync)
  675. {
  676. if (sync)
  677. set_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
  678. else
  679. clear_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
  680. }
  681. static inline bool nfsd4_copy_is_sync(const struct nfsd4_copy *copy)
  682. {
  683. return test_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
  684. }
  685. static inline bool nfsd4_copy_is_async(const struct nfsd4_copy *copy)
  686. {
  687. return !test_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
  688. }
  689. static inline bool nfsd4_ssc_is_inter(const struct nfsd4_copy *copy)
  690. {
  691. return !test_bit(NFSD4_COPY_F_INTRA, &copy->cp_flags);
  692. }
  693. struct nfsd4_seek {
  694. /* request */
  695. stateid_t seek_stateid;
  696. loff_t seek_offset;
  697. u32 seek_whence;
  698. /* response */
  699. u32 seek_eof;
  700. loff_t seek_pos;
  701. };
  702. struct nfsd4_offload_status {
  703. /* request */
  704. stateid_t stateid;
  705. /* response */
  706. u64 count;
  707. __be32 status;
  708. bool completed;
  709. };
  710. struct nfsd4_copy_notify {
  711. /* request */
  712. stateid_t cpn_src_stateid;
  713. struct nl4_server *cpn_dst;
  714. /* response */
  715. stateid_t cpn_cnr_stateid;
  716. struct timespec64 cpn_lease_time;
  717. struct nl4_server *cpn_src;
  718. };
  719. struct nfsd4_op {
  720. u32 opnum;
  721. __be32 status;
  722. const struct nfsd4_operation *opdesc;
  723. struct nfs4_replay *replay;
  724. union nfsd4_op_u {
  725. struct nfsd4_access access;
  726. struct nfsd4_close close;
  727. struct nfsd4_commit commit;
  728. struct nfsd4_create create;
  729. struct nfsd4_delegreturn delegreturn;
  730. struct nfsd4_getattr getattr;
  731. struct svc_fh * getfh;
  732. struct nfsd4_link link;
  733. struct nfsd4_lock lock;
  734. struct nfsd4_lockt lockt;
  735. struct nfsd4_locku locku;
  736. struct nfsd4_lookup lookup;
  737. struct nfsd4_verify nverify;
  738. struct nfsd4_open open;
  739. struct nfsd4_open_confirm open_confirm;
  740. struct nfsd4_open_downgrade open_downgrade;
  741. struct nfsd4_putfh putfh;
  742. struct nfsd4_read read;
  743. struct nfsd4_readdir readdir;
  744. struct nfsd4_readlink readlink;
  745. struct nfsd4_remove remove;
  746. struct nfsd4_rename rename;
  747. clientid_t renew;
  748. struct nfsd4_secinfo secinfo;
  749. struct nfsd4_setattr setattr;
  750. struct nfsd4_setclientid setclientid;
  751. struct nfsd4_setclientid_confirm setclientid_confirm;
  752. struct nfsd4_verify verify;
  753. struct nfsd4_write write;
  754. struct nfsd4_release_lockowner release_lockowner;
  755. /* NFSv4.1 */
  756. struct nfsd4_exchange_id exchange_id;
  757. struct nfsd4_backchannel_ctl backchannel_ctl;
  758. struct nfsd4_bind_conn_to_session bind_conn_to_session;
  759. struct nfsd4_create_session create_session;
  760. struct nfsd4_destroy_session destroy_session;
  761. struct nfsd4_destroy_clientid destroy_clientid;
  762. struct nfsd4_sequence sequence;
  763. struct nfsd4_reclaim_complete reclaim_complete;
  764. struct nfsd4_test_stateid test_stateid;
  765. struct nfsd4_free_stateid free_stateid;
  766. struct nfsd4_get_dir_delegation get_dir_delegation;
  767. struct nfsd4_getdeviceinfo getdeviceinfo;
  768. struct nfsd4_layoutget layoutget;
  769. struct nfsd4_layoutcommit layoutcommit;
  770. struct nfsd4_layoutreturn layoutreturn;
  771. struct nfsd4_secinfo_no_name secinfo_no_name;
  772. /* NFSv4.2 */
  773. struct nfsd4_fallocate allocate;
  774. struct nfsd4_fallocate deallocate;
  775. struct nfsd4_clone clone;
  776. struct nfsd4_copy copy;
  777. struct nfsd4_offload_status offload_status;
  778. struct nfsd4_copy_notify copy_notify;
  779. struct nfsd4_seek seek;
  780. struct nfsd4_getxattr getxattr;
  781. struct nfsd4_setxattr setxattr;
  782. struct nfsd4_listxattrs listxattrs;
  783. struct nfsd4_removexattr removexattr;
  784. } u;
  785. };
  786. bool nfsd4_cache_this_op(struct nfsd4_op *);
  787. /*
  788. * Memory needed just for the duration of processing one compound:
  789. */
  790. struct svcxdr_tmpbuf {
  791. struct svcxdr_tmpbuf *next;
  792. char buf[];
  793. };
  794. struct nfsd4_compoundargs {
  795. /* scratch variables for XDR decode */
  796. struct xdr_stream *xdr;
  797. struct svcxdr_tmpbuf *to_free;
  798. struct svc_rqst *rqstp;
  799. char * tag;
  800. u32 taglen;
  801. u32 minorversion;
  802. u32 client_opcnt;
  803. u32 opcnt;
  804. bool splice_ok;
  805. struct nfsd4_op *ops;
  806. struct nfsd4_op iops[8];
  807. };
  808. struct nfsd4_compoundres {
  809. /* scratch variables for XDR encode */
  810. struct xdr_stream *xdr;
  811. struct svc_rqst * rqstp;
  812. __be32 *statusp;
  813. char * tag;
  814. u32 taglen;
  815. u32 opcnt;
  816. struct nfsd4_compound_state cstate;
  817. };
  818. static inline bool nfsd4_last_compound_op(struct svc_rqst *rqstp)
  819. {
  820. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  821. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  822. return argp->opcnt == resp->opcnt;
  823. }
  824. const struct nfsd4_operation *OPDESC(struct nfsd4_op *op);
  825. int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op);
  826. void warn_on_nonidempotent_op(struct nfsd4_op *op);
  827. #define NFS4_SVC_XDRSIZE sizeof(struct nfsd4_compoundargs)
  828. bool nfsd4_mach_creds_match(struct nfs4_client *cl, struct svc_rqst *rqstp);
  829. bool nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
  830. bool nfs4svc_encode_compoundres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
  831. __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *, u32);
  832. void nfsd4_encode_operation(struct nfsd4_compoundres *, struct nfsd4_op *);
  833. void nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op);
  834. __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words,
  835. struct svc_fh *fhp, struct svc_export *exp,
  836. struct dentry *dentry,
  837. u32 *bmval, struct svc_rqst *, int ignore_crossmnt);
  838. extern __be32 nfsd4_setclientid(struct svc_rqst *rqstp,
  839. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  840. extern __be32 nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
  841. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  842. void nfsd4_exchange_id_release(union nfsd4_op_u *u);
  843. extern __be32 nfsd4_exchange_id(struct svc_rqst *rqstp,
  844. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  845. extern __be32 nfsd4_backchannel_ctl(struct svc_rqst *,
  846. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  847. extern __be32 nfsd4_bind_conn_to_session(struct svc_rqst *,
  848. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  849. extern __be32 nfsd4_create_session(struct svc_rqst *,
  850. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  851. extern __be32 nfsd4_sequence(struct svc_rqst *,
  852. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  853. extern void nfsd4_sequence_done(struct nfsd4_compoundres *resp);
  854. extern __be32 nfsd4_destroy_session(struct svc_rqst *,
  855. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  856. extern __be32 nfsd4_destroy_clientid(struct svc_rqst *, struct nfsd4_compound_state *,
  857. union nfsd4_op_u *u);
  858. __be32 nfsd4_reclaim_complete(struct svc_rqst *, struct nfsd4_compound_state *,
  859. union nfsd4_op_u *u);
  860. extern __be32 nfsd4_process_open1(struct nfsd4_compound_state *,
  861. struct nfsd4_open *open, struct nfsd_net *nn);
  862. extern __be32 nfsd4_process_open2(struct svc_rqst *rqstp,
  863. struct svc_fh *current_fh, struct nfsd4_open *open);
  864. extern void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate);
  865. extern void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate,
  866. struct nfsd4_open *open);
  867. extern __be32 nfsd4_open_confirm(struct svc_rqst *rqstp,
  868. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  869. extern __be32 nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  870. union nfsd4_op_u *u);
  871. extern __be32 nfsd4_open_downgrade(struct svc_rqst *rqstp,
  872. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  873. extern __be32 nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  874. union nfsd4_op_u *u);
  875. extern void nfsd4_lock_release(union nfsd4_op_u *u);
  876. extern __be32 nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  877. union nfsd4_op_u *u);
  878. extern void nfsd4_lockt_release(union nfsd4_op_u *u);
  879. extern __be32 nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  880. union nfsd4_op_u *u);
  881. extern __be32
  882. nfsd4_release_lockowner(struct svc_rqst *rqstp,
  883. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  884. extern void nfsd4_release_compoundargs(struct svc_rqst *rqstp);
  885. extern __be32 nfsd4_delegreturn(struct svc_rqst *rqstp,
  886. struct nfsd4_compound_state *, union nfsd4_op_u *u);
  887. extern __be32 nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  888. union nfsd4_op_u *u);
  889. extern __be32 nfsd4_test_stateid(struct svc_rqst *rqstp,
  890. struct nfsd4_compound_state *, union nfsd4_op_u *);
  891. extern __be32 nfsd4_free_stateid(struct svc_rqst *rqstp,
  892. struct nfsd4_compound_state *, union nfsd4_op_u *);
  893. extern void nfsd4_bump_seqid(struct nfsd4_compound_state *, __be32 nfserr);
  894. enum nfsd4_op_flags {
  895. ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
  896. ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */
  897. ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */
  898. /* For rfc 5661 section 2.6.3.1.1: */
  899. OP_HANDLES_WRONGSEC = 1 << 3,
  900. OP_IS_PUTFH_LIKE = 1 << 4,
  901. /*
  902. * These are the ops whose result size we estimate before
  903. * encoding, to avoid performing an op then not being able to
  904. * respond or cache a response. This includes writes and setattrs
  905. * as well as the operations usually called "nonidempotent":
  906. */
  907. OP_MODIFIES_SOMETHING = 1 << 5,
  908. /*
  909. * Cache compounds containing these ops in the xid-based drc:
  910. * We use the DRC for compounds containing non-idempotent
  911. * operations, *except* those that are 4.1-specific (since
  912. * sessions provide their own EOS), and except for stateful
  913. * operations other than setclientid and setclientid_confirm
  914. * (since sequence numbers provide EOS for open, lock, etc in
  915. * the v4.0 case).
  916. */
  917. OP_CACHEME = 1 << 6,
  918. /*
  919. * These are ops which clear current state id.
  920. */
  921. OP_CLEAR_STATEID = 1 << 7,
  922. /* Most ops return only an error on failure; some may do more: */
  923. OP_NONTRIVIAL_ERROR_ENCODE = 1 << 8,
  924. };
  925. struct nfsd4_operation {
  926. __be32 (*op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
  927. union nfsd4_op_u *);
  928. void (*op_release)(union nfsd4_op_u *);
  929. u32 op_flags;
  930. char *op_name;
  931. /* Try to get response size before operation */
  932. u32 (*op_rsize_bop)(const struct svc_rqst *rqstp,
  933. const struct nfsd4_op *op);
  934. void (*op_get_currentstateid)(struct nfsd4_compound_state *,
  935. union nfsd4_op_u *);
  936. void (*op_set_currentstateid)(struct nfsd4_compound_state *,
  937. union nfsd4_op_u *);
  938. };
  939. struct nfsd4_cb_recall_any {
  940. struct nfsd4_callback ra_cb;
  941. u32 ra_keep;
  942. u32 ra_bmval[1];
  943. };
  944. #endif