nfs4_fs.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/fs/nfs/nfs4_fs.h
  4. *
  5. * Copyright (C) 2005 Trond Myklebust
  6. *
  7. * NFSv4-specific filesystem definitions and declarations
  8. */
  9. #ifndef __LINUX_FS_NFS_NFS4_FS_H
  10. #define __LINUX_FS_NFS_NFS4_FS_H
  11. #if defined(CONFIG_NFS_V4_2)
  12. #define NFS4_MAX_MINOR_VERSION 2
  13. #elif defined(CONFIG_NFS_V4_1)
  14. #define NFS4_MAX_MINOR_VERSION 1
  15. #else
  16. #define NFS4_MAX_MINOR_VERSION 0
  17. #endif
  18. #if IS_ENABLED(CONFIG_NFS_V4)
  19. #define NFS4_MAX_LOOP_ON_RECOVER (10)
  20. #include <linux/seqlock.h>
  21. struct idmap;
  22. enum nfs4_client_state {
  23. NFS4CLNT_MANAGER_RUNNING = 0,
  24. NFS4CLNT_CHECK_LEASE,
  25. NFS4CLNT_LEASE_EXPIRED,
  26. NFS4CLNT_RECLAIM_REBOOT,
  27. NFS4CLNT_RECLAIM_NOGRACE,
  28. NFS4CLNT_DELEGRETURN,
  29. NFS4CLNT_SESSION_RESET,
  30. NFS4CLNT_LEASE_CONFIRM,
  31. NFS4CLNT_SERVER_SCOPE_MISMATCH,
  32. NFS4CLNT_PURGE_STATE,
  33. NFS4CLNT_BIND_CONN_TO_SESSION,
  34. NFS4CLNT_MOVED,
  35. NFS4CLNT_LEASE_MOVED,
  36. NFS4CLNT_DELEGATION_EXPIRED,
  37. NFS4CLNT_RUN_MANAGER,
  38. NFS4CLNT_RECALL_RUNNING,
  39. NFS4CLNT_RECALL_ANY_LAYOUT_READ,
  40. NFS4CLNT_RECALL_ANY_LAYOUT_RW,
  41. NFS4CLNT_DELEGRETURN_DELAYED,
  42. };
  43. #define NFS4_RENEW_TIMEOUT 0x01
  44. #define NFS4_RENEW_DELEGATION_CB 0x02
  45. struct nfs_seqid_counter;
  46. struct nfs4_minor_version_ops {
  47. u32 minor_version;
  48. unsigned init_caps;
  49. int (*init_client)(struct nfs_client *);
  50. void (*shutdown_client)(struct nfs_client *);
  51. bool (*match_stateid)(const nfs4_stateid *,
  52. const nfs4_stateid *);
  53. int (*find_root_sec)(struct nfs_server *, struct nfs_fh *,
  54. struct nfs_fsinfo *);
  55. void (*free_lock_state)(struct nfs_server *,
  56. struct nfs4_lock_state *);
  57. int (*test_and_free_expired)(struct nfs_server *,
  58. nfs4_stateid *, const struct cred *);
  59. struct nfs_seqid *
  60. (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
  61. void (*session_trunk)(struct rpc_clnt *clnt,
  62. struct rpc_xprt *xprt, void *data);
  63. const struct rpc_call_ops *call_sync_ops;
  64. const struct nfs4_state_recovery_ops *reboot_recovery_ops;
  65. const struct nfs4_state_recovery_ops *nograce_recovery_ops;
  66. const struct nfs4_state_maintenance_ops *state_renewal_ops;
  67. const struct nfs4_mig_recovery_ops *mig_recovery_ops;
  68. };
  69. #define NFS_SEQID_CONFIRMED 1
  70. struct nfs_seqid_counter {
  71. ktime_t create_time;
  72. int owner_id;
  73. int flags;
  74. u32 counter;
  75. spinlock_t lock; /* Protects the list */
  76. struct list_head list; /* Defines sequence of RPC calls */
  77. struct rpc_wait_queue wait; /* RPC call delay queue */
  78. };
  79. struct nfs_seqid {
  80. struct nfs_seqid_counter *sequence;
  81. struct list_head list;
  82. struct rpc_task *task;
  83. };
  84. static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
  85. {
  86. if (seqid_mutating_err(-status))
  87. seqid->flags |= NFS_SEQID_CONFIRMED;
  88. }
  89. /*
  90. * NFS4 state_owners and lock_owners are simply labels for ordered
  91. * sequences of RPC calls. Their sole purpose is to provide once-only
  92. * semantics by allowing the server to identify replayed requests.
  93. */
  94. struct nfs4_state_owner {
  95. struct nfs_server *so_server;
  96. struct list_head so_lru;
  97. unsigned long so_expires;
  98. struct rb_node so_server_node;
  99. const struct cred *so_cred; /* Associated cred */
  100. spinlock_t so_lock;
  101. atomic_t so_count;
  102. unsigned long so_flags;
  103. struct list_head so_states;
  104. struct nfs_seqid_counter so_seqid;
  105. seqcount_spinlock_t so_reclaim_seqcount;
  106. struct mutex so_delegreturn_mutex;
  107. };
  108. enum {
  109. NFS_OWNER_RECLAIM_REBOOT,
  110. NFS_OWNER_RECLAIM_NOGRACE
  111. };
  112. #define NFS_LOCK_NEW 0
  113. #define NFS_LOCK_RECLAIM 1
  114. #define NFS_LOCK_EXPIRED 2
  115. /*
  116. * struct nfs4_state maintains the client-side state for a given
  117. * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
  118. *
  119. * OPEN:
  120. * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
  121. * we need to know how many files are open for reading or writing on a
  122. * given inode. This information too is stored here.
  123. *
  124. * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
  125. */
  126. struct nfs4_lock_state {
  127. struct list_head ls_locks; /* Other lock stateids */
  128. struct nfs4_state * ls_state; /* Pointer to open state */
  129. #define NFS_LOCK_INITIALIZED 0
  130. #define NFS_LOCK_LOST 1
  131. unsigned long ls_flags;
  132. struct nfs_seqid_counter ls_seqid;
  133. nfs4_stateid ls_stateid;
  134. refcount_t ls_count;
  135. fl_owner_t ls_owner;
  136. };
  137. /* bits for nfs4_state->flags */
  138. enum {
  139. LK_STATE_IN_USE,
  140. NFS_DELEGATED_STATE, /* Current stateid is delegation */
  141. NFS_OPEN_STATE, /* OPEN stateid is set */
  142. NFS_O_RDONLY_STATE, /* OPEN stateid has read-only state */
  143. NFS_O_WRONLY_STATE, /* OPEN stateid has write-only state */
  144. NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */
  145. NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */
  146. NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */
  147. NFS_STATE_POSIX_LOCKS, /* Posix locks are supported */
  148. NFS_STATE_RECOVERY_FAILED, /* OPEN stateid state recovery failed */
  149. NFS_STATE_MAY_NOTIFY_LOCK, /* server may CB_NOTIFY_LOCK */
  150. NFS_STATE_CHANGE_WAIT, /* A state changing operation is outstanding */
  151. NFS_CLNT_DST_SSC_COPY_STATE, /* dst server open state on client*/
  152. NFS_CLNT_SRC_SSC_COPY_STATE, /* src server open state on client*/
  153. NFS_SRV_SSC_COPY_STATE, /* ssc state on the dst server */
  154. };
  155. struct nfs4_state {
  156. struct list_head open_states; /* List of states for the same state_owner */
  157. struct list_head inode_states; /* List of states for the same inode */
  158. struct list_head lock_states; /* List of subservient lock stateids */
  159. struct nfs4_state_owner *owner; /* Pointer to the open owner */
  160. struct inode *inode; /* Pointer to the inode */
  161. unsigned long flags; /* Do we hold any locks? */
  162. spinlock_t state_lock; /* Protects the lock_states list */
  163. seqlock_t seqlock; /* Protects the stateid/open_stateid */
  164. nfs4_stateid stateid; /* Current stateid: may be delegation */
  165. nfs4_stateid open_stateid; /* OPEN stateid */
  166. /* The following 3 fields are protected by owner->so_lock */
  167. unsigned int n_rdonly; /* Number of read-only references */
  168. unsigned int n_wronly; /* Number of write-only references */
  169. unsigned int n_rdwr; /* Number of read/write references */
  170. fmode_t state; /* State on the server (R,W, or RW) */
  171. refcount_t count;
  172. wait_queue_head_t waitq;
  173. struct rcu_head rcu_head;
  174. };
  175. struct nfs4_exception {
  176. struct nfs4_state *state;
  177. struct inode *inode;
  178. nfs4_stateid *stateid;
  179. long timeout;
  180. unsigned char task_is_privileged : 1;
  181. unsigned char delay : 1,
  182. recovering : 1,
  183. retry : 1;
  184. bool interruptible;
  185. };
  186. struct nfs4_state_recovery_ops {
  187. int owner_flag_bit;
  188. int state_flag_bit;
  189. int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
  190. int (*recover_lock)(struct nfs4_state *, struct file_lock *);
  191. int (*establish_clid)(struct nfs_client *, const struct cred *);
  192. int (*reclaim_complete)(struct nfs_client *, const struct cred *);
  193. int (*detect_trunking)(struct nfs_client *, struct nfs_client **,
  194. const struct cred *);
  195. };
  196. struct nfs4_opendata {
  197. struct kref kref;
  198. struct nfs_openargs o_arg;
  199. struct nfs_openres o_res;
  200. struct nfs_open_confirmargs c_arg;
  201. struct nfs_open_confirmres c_res;
  202. struct nfs4_string owner_name;
  203. struct nfs4_string group_name;
  204. struct nfs4_label *a_label;
  205. struct nfs_fattr f_attr;
  206. struct nfs4_label *f_label;
  207. struct dentry *dir;
  208. struct dentry *dentry;
  209. struct nfs4_state_owner *owner;
  210. struct nfs4_state *state;
  211. struct iattr attrs;
  212. struct nfs4_layoutget *lgp;
  213. unsigned long timestamp;
  214. bool rpc_done;
  215. bool file_created;
  216. bool is_recover;
  217. bool cancelled;
  218. int rpc_status;
  219. };
  220. struct nfs4_add_xprt_data {
  221. struct nfs_client *clp;
  222. const struct cred *cred;
  223. };
  224. struct nfs4_state_maintenance_ops {
  225. int (*sched_state_renewal)(struct nfs_client *, const struct cred *, unsigned);
  226. const struct cred * (*get_state_renewal_cred)(struct nfs_client *);
  227. int (*renew_lease)(struct nfs_client *, const struct cred *);
  228. };
  229. struct nfs4_mig_recovery_ops {
  230. int (*get_locations)(struct inode *, struct nfs4_fs_locations *,
  231. struct page *, const struct cred *);
  232. int (*fsid_present)(struct inode *, const struct cred *);
  233. };
  234. extern const struct dentry_operations nfs4_dentry_operations;
  235. /* dir.c */
  236. int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
  237. unsigned, umode_t);
  238. /* fs_context.c */
  239. extern struct file_system_type nfs4_fs_type;
  240. /* nfs4namespace.c */
  241. struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *,
  242. const struct qstr *);
  243. int nfs4_submount(struct fs_context *, struct nfs_server *);
  244. int nfs4_replace_transport(struct nfs_server *server,
  245. const struct nfs4_fs_locations *locations);
  246. size_t nfs_parse_server_name(char *string, size_t len, struct sockaddr *sa,
  247. size_t salen, struct net *net, int port);
  248. /* nfs4proc.c */
  249. extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *);
  250. extern int nfs4_async_handle_error(struct rpc_task *task,
  251. struct nfs_server *server,
  252. struct nfs4_state *state, long *timeout);
  253. extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
  254. struct rpc_message *, struct nfs4_sequence_args *,
  255. struct nfs4_sequence_res *, int);
  256. extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int);
  257. extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
  258. extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *);
  259. extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
  260. extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
  261. extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
  262. extern int nfs4_destroy_clientid(struct nfs_client *clp);
  263. extern int nfs4_init_clientid(struct nfs_client *, const struct cred *);
  264. extern int nfs41_init_clientid(struct nfs_client *, const struct cred *);
  265. extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait);
  266. extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
  267. extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
  268. struct nfs4_fs_locations *, struct page *);
  269. extern int nfs4_proc_get_locations(struct inode *, struct nfs4_fs_locations *,
  270. struct page *page, const struct cred *);
  271. extern int nfs4_proc_fsid_present(struct inode *, const struct cred *);
  272. extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *,
  273. struct dentry *,
  274. struct nfs_fh *,
  275. struct nfs_fattr *);
  276. extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
  277. extern const struct xattr_handler *nfs4_xattr_handlers[];
  278. extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
  279. const struct nfs_open_context *ctx,
  280. const struct nfs_lock_context *l_ctx,
  281. fmode_t fmode);
  282. extern int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
  283. struct nfs_fattr *fattr, struct nfs4_label *label,
  284. struct inode *inode);
  285. extern int update_open_stateid(struct nfs4_state *state,
  286. const nfs4_stateid *open_stateid,
  287. const nfs4_stateid *deleg_stateid,
  288. fmode_t fmode);
  289. extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
  290. struct nfs_fsinfo *fsinfo);
  291. extern void nfs4_update_changeattr(struct inode *dir,
  292. struct nfs4_change_info *cinfo,
  293. unsigned long timestamp,
  294. unsigned long cache_validity);
  295. extern int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen,
  296. struct page **pages);
  297. #if defined(CONFIG_NFS_V4_1)
  298. extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *);
  299. extern int nfs4_proc_create_session(struct nfs_client *, const struct cred *);
  300. extern int nfs4_proc_destroy_session(struct nfs4_session *, const struct cred *);
  301. extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
  302. bool sync);
  303. extern int nfs4_detect_session_trunking(struct nfs_client *clp,
  304. struct nfs41_exchange_id_res *res, struct rpc_xprt *xprt);
  305. static inline bool
  306. is_ds_only_client(struct nfs_client *clp)
  307. {
  308. return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) ==
  309. EXCHGID4_FLAG_USE_PNFS_DS;
  310. }
  311. static inline bool
  312. is_ds_client(struct nfs_client *clp)
  313. {
  314. return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
  315. }
  316. static inline bool
  317. _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
  318. struct rpc_clnt **clntp, struct rpc_message *msg)
  319. {
  320. rpc_authflavor_t flavor;
  321. if (sp4_mode == NFS_SP4_MACH_CRED_CLEANUP ||
  322. sp4_mode == NFS_SP4_MACH_CRED_PNFS_CLEANUP) {
  323. /* Using machine creds for cleanup operations
  324. * is only relevent if the client credentials
  325. * might expire. So don't bother for
  326. * RPC_AUTH_UNIX. If file was only exported to
  327. * sec=sys, the PUTFH would fail anyway.
  328. */
  329. if ((*clntp)->cl_auth->au_flavor == RPC_AUTH_UNIX)
  330. return false;
  331. }
  332. if (test_bit(sp4_mode, &clp->cl_sp4_flags)) {
  333. msg->rpc_cred = rpc_machine_cred();
  334. flavor = clp->cl_rpcclient->cl_auth->au_flavor;
  335. WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I &&
  336. flavor != RPC_AUTH_GSS_KRB5P);
  337. *clntp = clp->cl_rpcclient;
  338. return true;
  339. }
  340. return false;
  341. }
  342. /*
  343. * Function responsible for determining if an rpc_message should use the
  344. * machine cred under SP4_MACH_CRED and if so switching the credential and
  345. * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p).
  346. * Should be called before rpc_call_sync/rpc_call_async.
  347. */
  348. static inline void
  349. nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
  350. struct rpc_clnt **clntp, struct rpc_message *msg)
  351. {
  352. _nfs4_state_protect(clp, sp4_mode, clntp, msg);
  353. }
  354. /*
  355. * Special wrapper to nfs4_state_protect for write.
  356. * If WRITE can use machine cred but COMMIT cannot, make sure all writes
  357. * that use machine cred use NFS_FILE_SYNC.
  358. */
  359. static inline void
  360. nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
  361. struct rpc_message *msg, struct nfs_pgio_header *hdr)
  362. {
  363. if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) &&
  364. !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
  365. hdr->args.stable = NFS_FILE_SYNC;
  366. }
  367. #else /* CONFIG_NFS_v4_1 */
  368. static inline bool
  369. is_ds_only_client(struct nfs_client *clp)
  370. {
  371. return false;
  372. }
  373. static inline bool
  374. is_ds_client(struct nfs_client *clp)
  375. {
  376. return false;
  377. }
  378. static inline void
  379. nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags,
  380. struct rpc_clnt **clntp, struct rpc_message *msg)
  381. {
  382. }
  383. static inline void
  384. nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
  385. struct rpc_message *msg, struct nfs_pgio_header *hdr)
  386. {
  387. }
  388. #endif /* CONFIG_NFS_V4_1 */
  389. extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];
  390. extern const u32 nfs4_fattr_bitmap[3];
  391. extern const u32 nfs4_statfs_bitmap[3];
  392. extern const u32 nfs4_pathconf_bitmap[3];
  393. extern const u32 nfs4_fsinfo_bitmap[3];
  394. extern const u32 nfs4_fs_locations_bitmap[3];
  395. void nfs40_shutdown_client(struct nfs_client *);
  396. void nfs41_shutdown_client(struct nfs_client *);
  397. int nfs40_init_client(struct nfs_client *);
  398. int nfs41_init_client(struct nfs_client *);
  399. void nfs4_free_client(struct nfs_client *);
  400. struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *);
  401. /* nfs4renewd.c */
  402. extern void nfs4_schedule_state_renewal(struct nfs_client *);
  403. extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
  404. extern void nfs4_kill_renewd(struct nfs_client *);
  405. extern void nfs4_renew_state(struct work_struct *);
  406. extern void nfs4_set_lease_period(struct nfs_client *clp, unsigned long lease);
  407. /* nfs4state.c */
  408. extern const nfs4_stateid current_stateid;
  409. const struct cred *nfs4_get_clid_cred(struct nfs_client *clp);
  410. const struct cred *nfs4_get_machine_cred(struct nfs_client *clp);
  411. const struct cred *nfs4_get_renew_cred(struct nfs_client *clp);
  412. int nfs4_discover_server_trunking(struct nfs_client *clp,
  413. struct nfs_client **);
  414. int nfs40_discover_server_trunking(struct nfs_client *clp,
  415. struct nfs_client **, const struct cred *);
  416. #if defined(CONFIG_NFS_V4_1)
  417. int nfs41_discover_server_trunking(struct nfs_client *clp,
  418. struct nfs_client **, const struct cred *);
  419. extern void nfs4_schedule_session_recovery(struct nfs4_session *, int);
  420. extern void nfs41_notify_server(struct nfs_client *);
  421. bool nfs4_check_serverowner_major_id(struct nfs41_server_owner *o1,
  422. struct nfs41_server_owner *o2);
  423. #else
  424. static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err)
  425. {
  426. }
  427. #endif /* CONFIG_NFS_V4_1 */
  428. extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, const struct cred *, gfp_t);
  429. extern void nfs4_put_state_owner(struct nfs4_state_owner *);
  430. extern void nfs4_purge_state_owners(struct nfs_server *, struct list_head *);
  431. extern void nfs4_free_state_owners(struct list_head *head);
  432. extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
  433. extern void nfs4_put_open_state(struct nfs4_state *);
  434. extern void nfs4_close_state(struct nfs4_state *, fmode_t);
  435. extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
  436. extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
  437. extern void nfs_inode_find_state_and_recover(struct inode *inode,
  438. const nfs4_stateid *stateid);
  439. extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *, struct nfs4_state *);
  440. extern void nfs4_schedule_lease_recovery(struct nfs_client *);
  441. extern int nfs4_wait_clnt_recover(struct nfs_client *clp);
  442. extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
  443. extern void nfs4_schedule_state_manager(struct nfs_client *);
  444. extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
  445. extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
  446. extern int nfs4_schedule_migration_recovery(const struct nfs_server *);
  447. extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
  448. extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags, bool);
  449. extern void nfs41_handle_server_scope(struct nfs_client *,
  450. struct nfs41_server_scope **);
  451. extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
  452. extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
  453. extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t,
  454. const struct nfs_lock_context *, nfs4_stateid *,
  455. const struct cred **);
  456. extern bool nfs4_copy_open_stateid(nfs4_stateid *dst,
  457. struct nfs4_state *state);
  458. extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
  459. extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
  460. extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
  461. extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
  462. extern void nfs_release_seqid(struct nfs_seqid *seqid);
  463. extern void nfs_free_seqid(struct nfs_seqid *seqid);
  464. extern int nfs4_setup_sequence(struct nfs_client *client,
  465. struct nfs4_sequence_args *args,
  466. struct nfs4_sequence_res *res,
  467. struct rpc_task *task);
  468. extern int nfs4_sequence_done(struct rpc_task *task,
  469. struct nfs4_sequence_res *res);
  470. extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
  471. extern int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res);
  472. extern const nfs4_stateid zero_stateid;
  473. extern const nfs4_stateid invalid_stateid;
  474. /* nfs4super.c */
  475. struct nfs_mount_info;
  476. extern struct nfs_subversion nfs_v4;
  477. extern bool nfs4_disable_idmapping;
  478. extern unsigned short max_session_slots;
  479. extern unsigned short max_session_cb_slots;
  480. extern unsigned short send_implementation_id;
  481. extern bool recover_lost_locks;
  482. #define NFS4_CLIENT_ID_UNIQ_LEN (64)
  483. extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
  484. extern int nfs4_try_get_tree(struct fs_context *);
  485. extern int nfs4_get_referral_tree(struct fs_context *);
  486. /* nfs4sysctl.c */
  487. #ifdef CONFIG_SYSCTL
  488. int nfs4_register_sysctl(void);
  489. void nfs4_unregister_sysctl(void);
  490. #else
  491. static inline int nfs4_register_sysctl(void)
  492. {
  493. return 0;
  494. }
  495. static inline void nfs4_unregister_sysctl(void)
  496. {
  497. }
  498. #endif
  499. /* nfs4xdr.c */
  500. extern const struct rpc_procinfo nfs4_procedures[];
  501. #ifdef CONFIG_NFS_V4_2
  502. extern const u32 nfs42_maxsetxattr_overhead;
  503. extern const u32 nfs42_maxgetxattr_overhead;
  504. extern const u32 nfs42_maxlistxattrs_overhead;
  505. #endif
  506. struct nfs4_mount_data;
  507. /* callback_xdr.c */
  508. extern const struct svc_version nfs4_callback_version1;
  509. extern const struct svc_version nfs4_callback_version4;
  510. static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
  511. {
  512. memcpy(dst->data, src->data, sizeof(dst->data));
  513. dst->type = src->type;
  514. }
  515. static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
  516. {
  517. if (dst->type != src->type)
  518. return false;
  519. return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
  520. }
  521. static inline bool nfs4_stateid_match_other(const nfs4_stateid *dst, const nfs4_stateid *src)
  522. {
  523. return memcmp(dst->other, src->other, NFS4_STATEID_OTHER_SIZE) == 0;
  524. }
  525. static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stateid *s2)
  526. {
  527. return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0;
  528. }
  529. static inline bool nfs4_stateid_is_next(const nfs4_stateid *s1, const nfs4_stateid *s2)
  530. {
  531. u32 seq1 = be32_to_cpu(s1->seqid);
  532. u32 seq2 = be32_to_cpu(s2->seqid);
  533. return seq2 == seq1 + 1U || (seq2 == 1U && seq1 == 0xffffffffU);
  534. }
  535. static inline bool nfs4_stateid_match_or_older(const nfs4_stateid *dst, const nfs4_stateid *src)
  536. {
  537. return nfs4_stateid_match_other(dst, src) &&
  538. !(src->seqid && nfs4_stateid_is_newer(dst, src));
  539. }
  540. static inline void nfs4_stateid_seqid_inc(nfs4_stateid *s1)
  541. {
  542. u32 seqid = be32_to_cpu(s1->seqid);
  543. if (++seqid == 0)
  544. ++seqid;
  545. s1->seqid = cpu_to_be32(seqid);
  546. }
  547. static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
  548. {
  549. return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0;
  550. }
  551. static inline bool nfs4_state_match_open_stateid_other(const struct nfs4_state *state,
  552. const nfs4_stateid *stateid)
  553. {
  554. return test_bit(NFS_OPEN_STATE, &state->flags) &&
  555. nfs4_stateid_match_other(&state->open_stateid, stateid);
  556. }
  557. /* nfs42xattr.c */
  558. #ifdef CONFIG_NFS_V4_2
  559. extern int __init nfs4_xattr_cache_init(void);
  560. extern void nfs4_xattr_cache_exit(void);
  561. extern void nfs4_xattr_cache_add(struct inode *inode, const char *name,
  562. const char *buf, struct page **pages,
  563. ssize_t buflen);
  564. extern void nfs4_xattr_cache_remove(struct inode *inode, const char *name);
  565. extern ssize_t nfs4_xattr_cache_get(struct inode *inode, const char *name,
  566. char *buf, ssize_t buflen);
  567. extern void nfs4_xattr_cache_set_list(struct inode *inode, const char *buf,
  568. ssize_t buflen);
  569. extern ssize_t nfs4_xattr_cache_list(struct inode *inode, char *buf,
  570. ssize_t buflen);
  571. extern void nfs4_xattr_cache_zap(struct inode *inode);
  572. #else
  573. static inline void nfs4_xattr_cache_zap(struct inode *inode)
  574. {
  575. }
  576. #endif /* CONFIG_NFS_V4_2 */
  577. #else /* CONFIG_NFS_V4 */
  578. #define nfs4_close_state(a, b) do { } while (0)
  579. #define nfs4_close_sync(a, b) do { } while (0)
  580. #define nfs4_state_protect(a, b, c, d) do { } while (0)
  581. #define nfs4_state_protect_write(a, b, c, d) do { } while (0)
  582. #endif /* CONFIG_NFS_V4 */
  583. #endif /* __LINUX_FS_NFS_NFS4_FS.H */