nfs4_fs.h 24 KB

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