nfs4_fs.h 23 KB

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