xdr4.h 16 KB

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