xdr4.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  2. * include/linux/nfsd/xdr4.h
  3. *
  4. * Server-side types for NFSv4.
  5. *
  6. * Copyright (c) 2002 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Kendrick Smith <kmsmith@umich.edu>
  10. * Andy Adamson <andros@umich.edu>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  32. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. */
  38. #ifndef _LINUX_NFSD_XDR4_H
  39. #define _LINUX_NFSD_XDR4_H
  40. #include <linux/nfs4.h>
  41. #define NFSD4_MAX_TAGLEN 128
  42. #define XDR_LEN(n) (((n) + 3) & ~3)
  43. struct nfsd4_compound_state {
  44. struct svc_fh current_fh;
  45. struct svc_fh save_fh;
  46. struct nfs4_stateowner *replay_owner;
  47. /* For sessions DRC */
  48. struct nfsd4_session *session;
  49. struct nfsd4_slot *slot;
  50. __be32 *statp;
  51. size_t iovlen;
  52. u32 minorversion;
  53. u32 status;
  54. };
  55. static inline bool nfsd4_has_session(struct nfsd4_compound_state *cs)
  56. {
  57. return cs->slot != NULL;
  58. }
  59. struct nfsd4_change_info {
  60. u32 atomic;
  61. bool change_supported;
  62. u32 before_ctime_sec;
  63. u32 before_ctime_nsec;
  64. u64 before_change;
  65. u32 after_ctime_sec;
  66. u32 after_ctime_nsec;
  67. u64 after_change;
  68. };
  69. struct nfsd4_access {
  70. u32 ac_req_access; /* request */
  71. u32 ac_supported; /* response */
  72. u32 ac_resp_access; /* response */
  73. };
  74. struct nfsd4_close {
  75. u32 cl_seqid; /* request */
  76. stateid_t cl_stateid; /* request+response */
  77. struct nfs4_stateowner * cl_stateowner; /* response */
  78. };
  79. struct nfsd4_commit {
  80. u64 co_offset; /* request */
  81. u32 co_count; /* request */
  82. nfs4_verifier co_verf; /* response */
  83. };
  84. struct nfsd4_create {
  85. u32 cr_namelen; /* request */
  86. char * cr_name; /* request */
  87. u32 cr_type; /* request */
  88. union { /* request */
  89. struct {
  90. u32 namelen;
  91. char *name;
  92. } link; /* NF4LNK */
  93. struct {
  94. u32 specdata1;
  95. u32 specdata2;
  96. } dev; /* NF4BLK, NF4CHR */
  97. } u;
  98. u32 cr_bmval[3]; /* request */
  99. struct iattr cr_iattr; /* request */
  100. struct nfsd4_change_info cr_cinfo; /* response */
  101. struct nfs4_acl *cr_acl;
  102. };
  103. #define cr_linklen u.link.namelen
  104. #define cr_linkname u.link.name
  105. #define cr_specdata1 u.dev.specdata1
  106. #define cr_specdata2 u.dev.specdata2
  107. struct nfsd4_delegreturn {
  108. stateid_t dr_stateid;
  109. };
  110. struct nfsd4_getattr {
  111. u32 ga_bmval[3]; /* request */
  112. struct svc_fh *ga_fhp; /* response */
  113. };
  114. struct nfsd4_link {
  115. u32 li_namelen; /* request */
  116. char * li_name; /* request */
  117. struct nfsd4_change_info li_cinfo; /* response */
  118. };
  119. struct nfsd4_lock_denied {
  120. clientid_t ld_clientid;
  121. struct nfs4_stateowner *ld_sop;
  122. u64 ld_start;
  123. u64 ld_length;
  124. u32 ld_type;
  125. };
  126. struct nfsd4_lock {
  127. /* request */
  128. u32 lk_type;
  129. u32 lk_reclaim; /* boolean */
  130. u64 lk_offset;
  131. u64 lk_length;
  132. u32 lk_is_new;
  133. union {
  134. struct {
  135. u32 open_seqid;
  136. stateid_t open_stateid;
  137. u32 lock_seqid;
  138. clientid_t clientid;
  139. struct xdr_netobj owner;
  140. } new;
  141. struct {
  142. stateid_t lock_stateid;
  143. u32 lock_seqid;
  144. } old;
  145. } v;
  146. /* response */
  147. union {
  148. struct {
  149. stateid_t stateid;
  150. } ok;
  151. struct nfsd4_lock_denied denied;
  152. } u;
  153. /* The lk_replay_owner is the open owner in the open_to_lock_owner
  154. * case and the lock owner otherwise: */
  155. struct nfs4_stateowner *lk_replay_owner;
  156. };
  157. #define lk_new_open_seqid v.new.open_seqid
  158. #define lk_new_open_stateid v.new.open_stateid
  159. #define lk_new_lock_seqid v.new.lock_seqid
  160. #define lk_new_clientid v.new.clientid
  161. #define lk_new_owner v.new.owner
  162. #define lk_old_lock_stateid v.old.lock_stateid
  163. #define lk_old_lock_seqid v.old.lock_seqid
  164. #define lk_rflags u.ok.rflags
  165. #define lk_resp_stateid u.ok.stateid
  166. #define lk_denied u.denied
  167. struct nfsd4_lockt {
  168. u32 lt_type;
  169. clientid_t lt_clientid;
  170. struct xdr_netobj lt_owner;
  171. u64 lt_offset;
  172. u64 lt_length;
  173. struct nfs4_stateowner * lt_stateowner;
  174. struct nfsd4_lock_denied lt_denied;
  175. };
  176. struct nfsd4_locku {
  177. u32 lu_type;
  178. u32 lu_seqid;
  179. stateid_t lu_stateid;
  180. u64 lu_offset;
  181. u64 lu_length;
  182. struct nfs4_stateowner *lu_stateowner;
  183. };
  184. struct nfsd4_lookup {
  185. u32 lo_len; /* request */
  186. char * lo_name; /* request */
  187. };
  188. struct nfsd4_putfh {
  189. u32 pf_fhlen; /* request */
  190. char *pf_fhval; /* request */
  191. };
  192. struct nfsd4_open {
  193. u32 op_claim_type; /* request */
  194. struct xdr_netobj op_fname; /* request - everything but CLAIM_PREV */
  195. u32 op_delegate_type; /* request - CLAIM_PREV only */
  196. stateid_t op_delegate_stateid; /* request - response */
  197. u32 op_create; /* request */
  198. u32 op_createmode; /* request */
  199. u32 op_bmval[3]; /* request */
  200. struct iattr iattr; /* UNCHECKED4, GUARDED4, EXCLUSIVE4_1 */
  201. nfs4_verifier verf; /* EXCLUSIVE4 */
  202. clientid_t op_clientid; /* request */
  203. struct xdr_netobj op_owner; /* request */
  204. u32 op_seqid; /* request */
  205. u32 op_share_access; /* request */
  206. u32 op_share_deny; /* request */
  207. stateid_t op_stateid; /* response */
  208. u32 op_recall; /* recall */
  209. struct nfsd4_change_info op_cinfo; /* response */
  210. u32 op_rflags; /* response */
  211. int op_truncate; /* used during processing */
  212. struct nfs4_stateowner *op_stateowner; /* used during processing */
  213. struct nfs4_acl *op_acl;
  214. };
  215. #define op_iattr iattr
  216. #define op_verf verf
  217. struct nfsd4_open_confirm {
  218. stateid_t oc_req_stateid /* request */;
  219. u32 oc_seqid /* request */;
  220. stateid_t oc_resp_stateid /* response */;
  221. struct nfs4_stateowner * oc_stateowner; /* response */
  222. };
  223. struct nfsd4_open_downgrade {
  224. stateid_t od_stateid;
  225. u32 od_seqid;
  226. u32 od_share_access;
  227. u32 od_share_deny;
  228. struct nfs4_stateowner *od_stateowner;
  229. };
  230. struct nfsd4_read {
  231. stateid_t rd_stateid; /* request */
  232. u64 rd_offset; /* request */
  233. u32 rd_length; /* request */
  234. int rd_vlen;
  235. struct file *rd_filp;
  236. struct svc_rqst *rd_rqstp; /* response */
  237. struct svc_fh * rd_fhp; /* response */
  238. };
  239. struct nfsd4_readdir {
  240. u64 rd_cookie; /* request */
  241. nfs4_verifier rd_verf; /* request */
  242. u32 rd_dircount; /* request */
  243. u32 rd_maxcount; /* request */
  244. u32 rd_bmval[3]; /* request */
  245. struct svc_rqst *rd_rqstp; /* response */
  246. struct svc_fh * rd_fhp; /* response */
  247. struct readdir_cd common;
  248. __be32 * buffer;
  249. int buflen;
  250. __be32 * offset;
  251. };
  252. struct nfsd4_release_lockowner {
  253. clientid_t rl_clientid;
  254. struct xdr_netobj rl_owner;
  255. };
  256. struct nfsd4_readlink {
  257. struct svc_rqst *rl_rqstp; /* request */
  258. struct svc_fh * rl_fhp; /* request */
  259. };
  260. struct nfsd4_remove {
  261. u32 rm_namelen; /* request */
  262. char * rm_name; /* request */
  263. struct nfsd4_change_info rm_cinfo; /* response */
  264. };
  265. struct nfsd4_rename {
  266. u32 rn_snamelen; /* request */
  267. char * rn_sname; /* request */
  268. u32 rn_tnamelen; /* request */
  269. char * rn_tname; /* request */
  270. struct nfsd4_change_info rn_sinfo; /* response */
  271. struct nfsd4_change_info rn_tinfo; /* response */
  272. };
  273. struct nfsd4_secinfo {
  274. u32 si_namelen; /* request */
  275. char *si_name; /* request */
  276. struct svc_export *si_exp; /* response */
  277. };
  278. struct nfsd4_setattr {
  279. stateid_t sa_stateid; /* request */
  280. u32 sa_bmval[3]; /* request */
  281. struct iattr sa_iattr; /* request */
  282. struct nfs4_acl *sa_acl;
  283. };
  284. struct nfsd4_setclientid {
  285. nfs4_verifier se_verf; /* request */
  286. u32 se_namelen; /* request */
  287. char * se_name; /* request */
  288. u32 se_callback_prog; /* request */
  289. u32 se_callback_netid_len; /* request */
  290. char * se_callback_netid_val; /* request */
  291. u32 se_callback_addr_len; /* request */
  292. char * se_callback_addr_val; /* request */
  293. u32 se_callback_ident; /* request */
  294. clientid_t se_clientid; /* response */
  295. nfs4_verifier se_confirm; /* response */
  296. };
  297. struct nfsd4_setclientid_confirm {
  298. clientid_t sc_clientid;
  299. nfs4_verifier sc_confirm;
  300. };
  301. /* also used for NVERIFY */
  302. struct nfsd4_verify {
  303. u32 ve_bmval[3]; /* request */
  304. u32 ve_attrlen; /* request */
  305. char * ve_attrval; /* request */
  306. };
  307. struct nfsd4_write {
  308. stateid_t wr_stateid; /* request */
  309. u64 wr_offset; /* request */
  310. u32 wr_stable_how; /* request */
  311. u32 wr_buflen; /* request */
  312. int wr_vlen;
  313. u32 wr_bytes_written; /* response */
  314. u32 wr_how_written; /* response */
  315. nfs4_verifier wr_verifier; /* response */
  316. };
  317. struct nfsd4_exchange_id {
  318. nfs4_verifier verifier;
  319. struct xdr_netobj clname;
  320. u32 flags;
  321. clientid_t clientid;
  322. u32 seqid;
  323. int spa_how;
  324. };
  325. struct nfsd4_channel_attrs {
  326. u32 headerpadsz;
  327. u32 maxreq_sz;
  328. u32 maxresp_sz;
  329. u32 maxresp_cached;
  330. u32 maxops;
  331. u32 maxreqs;
  332. u32 nr_rdma_attrs;
  333. u32 rdma_attrs;
  334. };
  335. struct nfsd4_create_session {
  336. clientid_t clientid;
  337. struct nfs4_sessionid sessionid;
  338. u32 seqid;
  339. u32 flags;
  340. struct nfsd4_channel_attrs fore_channel;
  341. struct nfsd4_channel_attrs back_channel;
  342. u32 callback_prog;
  343. u32 uid;
  344. u32 gid;
  345. };
  346. struct nfsd4_sequence {
  347. struct nfs4_sessionid sessionid; /* request/response */
  348. u32 seqid; /* request/response */
  349. u32 slotid; /* request/response */
  350. u32 maxslots; /* request/response */
  351. u32 cachethis; /* request */
  352. #if 0
  353. u32 target_maxslots; /* response */
  354. u32 status_flags; /* response */
  355. #endif /* not yet */
  356. };
  357. struct nfsd4_destroy_session {
  358. struct nfs4_sessionid sessionid;
  359. };
  360. struct nfsd4_op {
  361. int opnum;
  362. __be32 status;
  363. union {
  364. struct nfsd4_access access;
  365. struct nfsd4_close close;
  366. struct nfsd4_commit commit;
  367. struct nfsd4_create create;
  368. struct nfsd4_delegreturn delegreturn;
  369. struct nfsd4_getattr getattr;
  370. struct svc_fh * getfh;
  371. struct nfsd4_link link;
  372. struct nfsd4_lock lock;
  373. struct nfsd4_lockt lockt;
  374. struct nfsd4_locku locku;
  375. struct nfsd4_lookup lookup;
  376. struct nfsd4_verify nverify;
  377. struct nfsd4_open open;
  378. struct nfsd4_open_confirm open_confirm;
  379. struct nfsd4_open_downgrade open_downgrade;
  380. struct nfsd4_putfh putfh;
  381. struct nfsd4_read read;
  382. struct nfsd4_readdir readdir;
  383. struct nfsd4_readlink readlink;
  384. struct nfsd4_remove remove;
  385. struct nfsd4_rename rename;
  386. clientid_t renew;
  387. struct nfsd4_secinfo secinfo;
  388. struct nfsd4_setattr setattr;
  389. struct nfsd4_setclientid setclientid;
  390. struct nfsd4_setclientid_confirm setclientid_confirm;
  391. struct nfsd4_verify verify;
  392. struct nfsd4_write write;
  393. struct nfsd4_release_lockowner release_lockowner;
  394. /* NFSv4.1 */
  395. struct nfsd4_exchange_id exchange_id;
  396. struct nfsd4_create_session create_session;
  397. struct nfsd4_destroy_session destroy_session;
  398. struct nfsd4_sequence sequence;
  399. } u;
  400. struct nfs4_replay * replay;
  401. };
  402. struct nfsd4_compoundargs {
  403. /* scratch variables for XDR decode */
  404. __be32 * p;
  405. __be32 * end;
  406. struct page ** pagelist;
  407. int pagelen;
  408. __be32 tmp[8];
  409. __be32 * tmpp;
  410. struct tmpbuf {
  411. struct tmpbuf *next;
  412. void (*release)(const void *);
  413. void *buf;
  414. } *to_free;
  415. struct svc_rqst *rqstp;
  416. u32 taglen;
  417. char * tag;
  418. u32 minorversion;
  419. u32 opcnt;
  420. struct nfsd4_op *ops;
  421. struct nfsd4_op iops[8];
  422. };
  423. struct nfsd4_compoundres {
  424. /* scratch variables for XDR encode */
  425. __be32 * p;
  426. __be32 * end;
  427. struct xdr_buf * xbuf;
  428. struct svc_rqst * rqstp;
  429. u32 taglen;
  430. char * tag;
  431. u32 opcnt;
  432. __be32 * tagp; /* tag, opcount encode location */
  433. struct nfsd4_compound_state cstate;
  434. };
  435. static inline bool nfsd4_is_solo_sequence(struct nfsd4_compoundres *resp)
  436. {
  437. struct nfsd4_compoundargs *args = resp->rqstp->rq_argp;
  438. return args->opcnt == 1;
  439. }
  440. static inline bool nfsd4_not_cached(struct nfsd4_compoundres *resp)
  441. {
  442. return !resp->cstate.slot->sl_cache_entry.ce_cachethis ||
  443. nfsd4_is_solo_sequence(resp);
  444. }
  445. #define NFS4_SVC_XDRSIZE sizeof(struct nfsd4_compoundargs)
  446. static inline void
  447. set_change_info(struct nfsd4_change_info *cinfo, struct svc_fh *fhp)
  448. {
  449. BUG_ON(!fhp->fh_pre_saved || !fhp->fh_post_saved);
  450. cinfo->atomic = 1;
  451. cinfo->change_supported = IS_I_VERSION(fhp->fh_dentry->d_inode);
  452. if (cinfo->change_supported) {
  453. cinfo->before_change = fhp->fh_pre_change;
  454. cinfo->after_change = fhp->fh_post_change;
  455. } else {
  456. cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec;
  457. cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec;
  458. cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec;
  459. cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec;
  460. }
  461. }
  462. int nfs4svc_encode_voidres(struct svc_rqst *, __be32 *, void *);
  463. int nfs4svc_decode_compoundargs(struct svc_rqst *, __be32 *,
  464. struct nfsd4_compoundargs *);
  465. int nfs4svc_encode_compoundres(struct svc_rqst *, __be32 *,
  466. struct nfsd4_compoundres *);
  467. void nfsd4_encode_operation(struct nfsd4_compoundres *, struct nfsd4_op *);
  468. void nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op);
  469. __be32 nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
  470. struct dentry *dentry, __be32 *buffer, int *countp,
  471. u32 *bmval, struct svc_rqst *, int ignore_crossmnt);
  472. extern __be32 nfsd4_setclientid(struct svc_rqst *rqstp,
  473. struct nfsd4_compound_state *,
  474. struct nfsd4_setclientid *setclid);
  475. extern __be32 nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
  476. struct nfsd4_compound_state *,
  477. struct nfsd4_setclientid_confirm *setclientid_confirm);
  478. extern void nfsd4_store_cache_entry(struct nfsd4_compoundres *resp);
  479. extern __be32 nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp,
  480. struct nfsd4_sequence *seq);
  481. extern __be32 nfsd4_exchange_id(struct svc_rqst *rqstp,
  482. struct nfsd4_compound_state *,
  483. struct nfsd4_exchange_id *);
  484. extern __be32 nfsd4_create_session(struct svc_rqst *,
  485. struct nfsd4_compound_state *,
  486. struct nfsd4_create_session *);
  487. extern __be32 nfsd4_sequence(struct svc_rqst *,
  488. struct nfsd4_compound_state *,
  489. struct nfsd4_sequence *);
  490. extern __be32 nfsd4_destroy_session(struct svc_rqst *,
  491. struct nfsd4_compound_state *,
  492. struct nfsd4_destroy_session *);
  493. extern __be32 nfsd4_process_open1(struct nfsd4_compound_state *,
  494. struct nfsd4_open *open);
  495. extern __be32 nfsd4_process_open2(struct svc_rqst *rqstp,
  496. struct svc_fh *current_fh, struct nfsd4_open *open);
  497. extern __be32 nfsd4_open_confirm(struct svc_rqst *rqstp,
  498. struct nfsd4_compound_state *, struct nfsd4_open_confirm *oc);
  499. extern __be32 nfsd4_close(struct svc_rqst *rqstp,
  500. struct nfsd4_compound_state *,
  501. struct nfsd4_close *close);
  502. extern __be32 nfsd4_open_downgrade(struct svc_rqst *rqstp,
  503. struct nfsd4_compound_state *,
  504. struct nfsd4_open_downgrade *od);
  505. extern __be32 nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *,
  506. struct nfsd4_lock *lock);
  507. extern __be32 nfsd4_lockt(struct svc_rqst *rqstp,
  508. struct nfsd4_compound_state *,
  509. struct nfsd4_lockt *lockt);
  510. extern __be32 nfsd4_locku(struct svc_rqst *rqstp,
  511. struct nfsd4_compound_state *,
  512. struct nfsd4_locku *locku);
  513. extern __be32
  514. nfsd4_release_lockowner(struct svc_rqst *rqstp,
  515. struct nfsd4_compound_state *,
  516. struct nfsd4_release_lockowner *rlockowner);
  517. extern void nfsd4_release_compoundargs(struct nfsd4_compoundargs *);
  518. extern __be32 nfsd4_delegreturn(struct svc_rqst *rqstp,
  519. struct nfsd4_compound_state *, struct nfsd4_delegreturn *dr);
  520. extern __be32 nfsd4_renew(struct svc_rqst *rqstp,
  521. struct nfsd4_compound_state *, clientid_t *clid);
  522. #endif
  523. /*
  524. * Local variables:
  525. * c-basic-offset: 8
  526. * End:
  527. */