xdr4.h 17 KB

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