xref: /openbmc/linux/fs/nfs/nfs4_fs.h (revision 3be0f80b)
14ce79717STrond Myklebust /*
24ce79717STrond Myklebust  * linux/fs/nfs/nfs4_fs.h
34ce79717STrond Myklebust  *
44ce79717STrond Myklebust  * Copyright (C) 2005 Trond Myklebust
54ce79717STrond Myklebust  *
64ce79717STrond Myklebust  * NFSv4-specific filesystem definitions and declarations
74ce79717STrond Myklebust  */
84ce79717STrond Myklebust 
94ce79717STrond Myklebust #ifndef __LINUX_FS_NFS_NFS4_FS_H
104ce79717STrond Myklebust #define __LINUX_FS_NFS_NFS4_FS_H
114ce79717STrond Myklebust 
12694e096fSAnna Schumaker #if defined(CONFIG_NFS_V4_2)
13694e096fSAnna Schumaker #define NFS4_MAX_MINOR_VERSION 2
14694e096fSAnna Schumaker #elif defined(CONFIG_NFS_V4_1)
15694e096fSAnna Schumaker #define NFS4_MAX_MINOR_VERSION 1
16694e096fSAnna Schumaker #else
17694e096fSAnna Schumaker #define NFS4_MAX_MINOR_VERSION 0
18694e096fSAnna Schumaker #endif
19694e096fSAnna Schumaker 
2089d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
214ce79717STrond Myklebust 
2233021279STrond Myklebust #define NFS4_MAX_LOOP_ON_RECOVER (10)
2333021279STrond Myklebust 
24c137afabSTrond Myklebust #include <linux/seqlock.h>
25c137afabSTrond Myklebust 
264ce79717STrond Myklebust struct idmap;
274ce79717STrond Myklebust 
284ce79717STrond Myklebust enum nfs4_client_state {
29e005e804STrond Myklebust 	NFS4CLNT_MANAGER_RUNNING  = 0,
30e598d843STrond Myklebust 	NFS4CLNT_CHECK_LEASE,
3158d9714aSTrond Myklebust 	NFS4CLNT_LEASE_EXPIRED,
32b79a4a1bSTrond Myklebust 	NFS4CLNT_RECLAIM_REBOOT,
33b79a4a1bSTrond Myklebust 	NFS4CLNT_RECLAIM_NOGRACE,
34707fb4b3STrond Myklebust 	NFS4CLNT_DELEGRETURN,
356df08189SAndy Adamson 	NFS4CLNT_SESSION_RESET,
36fd954ae1STrond Myklebust 	NFS4CLNT_LEASE_CONFIRM,
3778fe0f41SWeston Andros Adamson 	NFS4CLNT_SERVER_SCOPE_MISMATCH,
382c820d9aSChuck Lever 	NFS4CLNT_PURGE_STATE,
39a9e64442SWeston Andros Adamson 	NFS4CLNT_BIND_CONN_TO_SESSION,
40c9fdeb28SChuck Lever 	NFS4CLNT_MOVED,
41b7f7a66eSChuck Lever 	NFS4CLNT_LEASE_MOVED,
4245870d69STrond Myklebust 	NFS4CLNT_DELEGATION_EXPIRED,
434ce79717STrond Myklebust };
444ce79717STrond Myklebust 
452f60ea6bSTrond Myklebust #define NFS4_RENEW_TIMEOUT		0x01
462f60ea6bSTrond Myklebust #define NFS4_RENEW_DELEGATION_CB	0x02
472f60ea6bSTrond Myklebust 
4863f5f796STrond Myklebust struct nfs_seqid_counter;
4997dc1359STrond Myklebust struct nfs4_minor_version_ops {
5097dc1359STrond Myklebust 	u32	minor_version;
5139c6daaeSTrond Myklebust 	unsigned init_caps;
5297dc1359STrond Myklebust 
53abf79bb3SChuck Lever 	int	(*init_client)(struct nfs_client *);
54abf79bb3SChuck Lever 	void	(*shutdown_client)(struct nfs_client *);
5536281caaSTrond Myklebust 	bool	(*match_stateid)(const nfs4_stateid *,
56e047a10cSTrond Myklebust 			const nfs4_stateid *);
57fca78d6dSBryan Schumaker 	int	(*find_root_sec)(struct nfs_server *, struct nfs_fh *,
58fca78d6dSBryan Schumaker 			struct nfs_fsinfo *);
59f1cdae87SJeff Layton 	void	(*free_lock_state)(struct nfs_server *,
60c8b2d0bfSTrond Myklebust 			struct nfs4_lock_state *);
6145870d69STrond Myklebust 	int	(*test_and_free_expired)(struct nfs_server *,
6245870d69STrond Myklebust 			nfs4_stateid *, struct rpc_cred *);
6363f5f796STrond Myklebust 	struct nfs_seqid *
6463f5f796STrond Myklebust 		(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
6504fa2c6bSAndy Adamson 	int	(*session_trunk)(struct rpc_clnt *, struct rpc_xprt *, void *);
669915ea7eSChuck Lever 	const struct rpc_call_ops *call_sync_ops;
67c48f4f35STrond Myklebust 	const struct nfs4_state_recovery_ops *reboot_recovery_ops;
68c48f4f35STrond Myklebust 	const struct nfs4_state_recovery_ops *nograce_recovery_ops;
69c48f4f35STrond Myklebust 	const struct nfs4_state_maintenance_ops *state_renewal_ops;
70ec011fe8SChuck Lever 	const struct nfs4_mig_recovery_ops *mig_recovery_ops;
7197dc1359STrond Myklebust };
7297dc1359STrond Myklebust 
73cee54fc9STrond Myklebust #define NFS_SEQID_CONFIRMED 1
74cee54fc9STrond Myklebust struct nfs_seqid_counter {
7595b72eb0STrond Myklebust 	ktime_t create_time;
7648c22eb2STrond Myklebust 	int owner_id;
77cee54fc9STrond Myklebust 	int flags;
78cee54fc9STrond Myklebust 	u32 counter;
797ba127abSTrond Myklebust 	spinlock_t lock;		/* Protects the list */
807ba127abSTrond Myklebust 	struct list_head list;		/* Defines sequence of RPC calls */
817ba127abSTrond Myklebust 	struct rpc_wait_queue	wait;	/* RPC call delay queue */
82cee54fc9STrond Myklebust };
83cee54fc9STrond Myklebust 
84cee54fc9STrond Myklebust struct nfs_seqid {
85cee54fc9STrond Myklebust 	struct nfs_seqid_counter *sequence;
864e51336aSTrond Myklebust 	struct list_head list;
874601df20STrond Myklebust 	struct rpc_task *task;
88cee54fc9STrond Myklebust };
89cee54fc9STrond Myklebust 
90cee54fc9STrond Myklebust static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
91cee54fc9STrond Myklebust {
92cee54fc9STrond Myklebust 	if (seqid_mutating_err(-status))
93cee54fc9STrond Myklebust 		seqid->flags |= NFS_SEQID_CONFIRMED;
94cee54fc9STrond Myklebust }
95cee54fc9STrond Myklebust 
96cee54fc9STrond Myklebust /*
974ce79717STrond Myklebust  * NFS4 state_owners and lock_owners are simply labels for ordered
984ce79717STrond Myklebust  * sequences of RPC calls. Their sole purpose is to provide once-only
994ce79717STrond Myklebust  * semantics by allowing the server to identify replayed requests.
1004ce79717STrond Myklebust  */
1014ce79717STrond Myklebust struct nfs4_state_owner {
1026f2e64d3STrond Myklebust 	struct nfs_server    *so_server;
1030aaaf5c4SChuck Lever 	struct list_head     so_lru;
1040aaaf5c4SChuck Lever 	unsigned long        so_expires;
10524d292b8SChuck Lever 	struct rb_node	     so_server_node;
1064ce79717STrond Myklebust 
1074ce79717STrond Myklebust 	struct rpc_cred	     *so_cred;	 /* Associated cred */
1089f958ab8STrond Myklebust 
1099f958ab8STrond Myklebust 	spinlock_t	     so_lock;
1109f958ab8STrond Myklebust 	atomic_t	     so_count;
1117eff03aeSTrond Myklebust 	unsigned long	     so_flags;
1124ce79717STrond Myklebust 	struct list_head     so_states;
113cee54fc9STrond Myklebust 	struct nfs_seqid_counter so_seqid;
114c137afabSTrond Myklebust 	seqcount_t	     so_reclaim_seqcount;
11565b62a29STrond Myklebust 	struct mutex	     so_delegreturn_mutex;
1164ce79717STrond Myklebust };
1174ce79717STrond Myklebust 
1187eff03aeSTrond Myklebust enum {
1197eff03aeSTrond Myklebust 	NFS_OWNER_RECLAIM_REBOOT,
1207eff03aeSTrond Myklebust 	NFS_OWNER_RECLAIM_NOGRACE
1217eff03aeSTrond Myklebust };
1227eff03aeSTrond Myklebust 
123afe6c27cSAlexandros Batsakis #define NFS_LOCK_NEW		0
124afe6c27cSAlexandros Batsakis #define NFS_LOCK_RECLAIM	1
125afe6c27cSAlexandros Batsakis #define NFS_LOCK_EXPIRED	2
126afe6c27cSAlexandros Batsakis 
1274ce79717STrond Myklebust /*
1284ce79717STrond Myklebust  * struct nfs4_state maintains the client-side state for a given
1294ce79717STrond Myklebust  * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
1304ce79717STrond Myklebust  *
1314ce79717STrond Myklebust  * OPEN:
1324ce79717STrond Myklebust  * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
1334ce79717STrond Myklebust  * we need to know how many files are open for reading or writing on a
1344ce79717STrond Myklebust  * given inode. This information too is stored here.
1354ce79717STrond Myklebust  *
1364ce79717STrond Myklebust  * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
1374ce79717STrond Myklebust  */
1384ce79717STrond Myklebust 
1394ce79717STrond Myklebust struct nfs4_lock_state {
1404ce79717STrond Myklebust 	struct list_head	ls_locks;	/* Other lock stateids */
1418d0a8a9dSTrond Myklebust 	struct nfs4_state *	ls_state;	/* Pointer to open state */
142795a88c9STrond Myklebust #define NFS_LOCK_INITIALIZED 0
143ef1820f9SNeilBrown #define NFS_LOCK_LOST        1
144795a88c9STrond Myklebust 	unsigned long		ls_flags;
145cee54fc9STrond Myklebust 	struct nfs_seqid_counter	ls_seqid;
1464ce79717STrond Myklebust 	nfs4_stateid		ls_stateid;
1474ce79717STrond Myklebust 	atomic_t		ls_count;
1488003d3c4SJeff Layton 	fl_owner_t		ls_owner;
1494ce79717STrond Myklebust };
1504ce79717STrond Myklebust 
1514ce79717STrond Myklebust /* bits for nfs4_state->flags */
1524ce79717STrond Myklebust enum {
1534ce79717STrond Myklebust 	LK_STATE_IN_USE,
154003707c7STrond Myklebust 	NFS_DELEGATED_STATE,		/* Current stateid is delegation */
15592b40e93STrond Myklebust 	NFS_OPEN_STATE,			/* OPEN stateid is set */
156003707c7STrond Myklebust 	NFS_O_RDONLY_STATE,		/* OPEN stateid has read-only state */
157003707c7STrond Myklebust 	NFS_O_WRONLY_STATE,		/* OPEN stateid has write-only state */
158003707c7STrond Myklebust 	NFS_O_RDWR_STATE,		/* OPEN stateid has read/write state */
159b79a4a1bSTrond Myklebust 	NFS_STATE_RECLAIM_REBOOT,	/* OPEN stateid server rebooted */
160b79a4a1bSTrond Myklebust 	NFS_STATE_RECLAIM_NOGRACE,	/* OPEN stateid needs to recover state */
1618e469ebdSTrond Myklebust 	NFS_STATE_POSIX_LOCKS,		/* Posix locks are supported */
1625d422301STrond Myklebust 	NFS_STATE_RECOVERY_FAILED,	/* OPEN stateid state recovery failed */
163a8ce377aSJeff Layton 	NFS_STATE_MAY_NOTIFY_LOCK,	/* server may CB_NOTIFY_LOCK */
1644ce79717STrond Myklebust };
1654ce79717STrond Myklebust 
1664ce79717STrond Myklebust struct nfs4_state {
1674ce79717STrond Myklebust 	struct list_head open_states;	/* List of states for the same state_owner */
1684ce79717STrond Myklebust 	struct list_head inode_states;	/* List of states for the same inode */
1694ce79717STrond Myklebust 	struct list_head lock_states;	/* List of subservient lock stateids */
1704ce79717STrond Myklebust 
1714ce79717STrond Myklebust 	struct nfs4_state_owner *owner;	/* Pointer to the open owner */
1724ce79717STrond Myklebust 	struct inode *inode;		/* Pointer to the inode */
1734ce79717STrond Myklebust 
1744ce79717STrond Myklebust 	unsigned long flags;		/* Do we hold any locks? */
1758d0a8a9dSTrond Myklebust 	spinlock_t state_lock;		/* Protects the lock_states list */
1764ce79717STrond Myklebust 
1778bda4e4cSTrond Myklebust 	seqlock_t seqlock;		/* Protects the stateid/open_stateid */
178003707c7STrond Myklebust 	nfs4_stateid stateid;		/* Current stateid: may be delegation */
179003707c7STrond Myklebust 	nfs4_stateid open_stateid;	/* OPEN stateid */
1804ce79717STrond Myklebust 
1818bda4e4cSTrond Myklebust 	/* The following 3 fields are protected by owner->so_lock */
182003707c7STrond Myklebust 	unsigned int n_rdonly;		/* Number of read-only references */
183003707c7STrond Myklebust 	unsigned int n_wronly;		/* Number of write-only references */
184003707c7STrond Myklebust 	unsigned int n_rdwr;		/* Number of read/write references */
185dc0b027dSTrond Myklebust 	fmode_t state;			/* State on the server (R,W, or RW) */
1864ce79717STrond Myklebust 	atomic_t count;
1874ce79717STrond Myklebust };
1884ce79717STrond Myklebust 
1894ce79717STrond Myklebust 
1904ce79717STrond Myklebust struct nfs4_exception {
1919e33bed5STrond Myklebust 	struct nfs4_state *state;
1923114ea7aSTrond Myklebust 	struct inode *inode;
1938487c479STrond Myklebust 	nfs4_stateid *stateid;
194b3c2aa07STrond Myklebust 	long timeout;
195b3c2aa07STrond Myklebust 	unsigned char delay : 1,
196b3c2aa07STrond Myklebust 		      recovering : 1,
197b3c2aa07STrond Myklebust 		      retry : 1;
1984ce79717STrond Myklebust };
1994ce79717STrond Myklebust 
2004ce79717STrond Myklebust struct nfs4_state_recovery_ops {
2017eff03aeSTrond Myklebust 	int owner_flag_bit;
202b79a4a1bSTrond Myklebust 	int state_flag_bit;
2034ce79717STrond Myklebust 	int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
2044ce79717STrond Myklebust 	int (*recover_lock)(struct nfs4_state *, struct file_lock *);
205591d71cbSAndy Adamson 	int (*establish_clid)(struct nfs_client *, struct rpc_cred *);
206965e9c23STrond Myklebust 	int (*reclaim_complete)(struct nfs_client *, struct rpc_cred *);
20705f4c350SChuck Lever 	int (*detect_trunking)(struct nfs_client *, struct nfs_client **,
20805f4c350SChuck Lever 		struct rpc_cred *);
2094ce79717STrond Myklebust };
2104ce79717STrond Myklebust 
21104fa2c6bSAndy Adamson struct nfs4_add_xprt_data {
21204fa2c6bSAndy Adamson 	struct nfs_client	*clp;
21304fa2c6bSAndy Adamson 	struct rpc_cred		*cred;
21404fa2c6bSAndy Adamson };
21504fa2c6bSAndy Adamson 
21629fba38bSBenny Halevy struct nfs4_state_maintenance_ops {
2172f60ea6bSTrond Myklebust 	int (*sched_state_renewal)(struct nfs_client *, struct rpc_cred *, unsigned);
218a7b72103SAndy Adamson 	struct rpc_cred * (*get_state_renewal_cred_locked)(struct nfs_client *);
2198e69514fSBenny Halevy 	int (*renew_lease)(struct nfs_client *, struct rpc_cred *);
22029fba38bSBenny Halevy };
22129fba38bSBenny Halevy 
222ec011fe8SChuck Lever struct nfs4_mig_recovery_ops {
223b03d735bSChuck Lever 	int (*get_locations)(struct inode *, struct nfs4_fs_locations *,
224b03d735bSChuck Lever 		struct page *, struct rpc_cred *);
22544c99933SChuck Lever 	int (*fsid_present)(struct inode *, struct rpc_cred *);
226ec011fe8SChuck Lever };
227ec011fe8SChuck Lever 
228f786aa90SAl Viro extern const struct dentry_operations nfs4_dentry_operations;
22973a79706SBryan Schumaker 
23073a79706SBryan Schumaker /* dir.c */
23173a79706SBryan Schumaker int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
23273a79706SBryan Schumaker 		    unsigned, umode_t, int *);
2336b3b5496SJ. Bruce Fields 
2341ae811eeSbjschuma@gmail.com /* super.c */
2351ae811eeSbjschuma@gmail.com extern struct file_system_type nfs4_fs_type;
2361ae811eeSbjschuma@gmail.com 
23772de53ecSBryan Schumaker /* nfs4namespace.c */
238beffb8feSAl Viro struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *,
239beffb8feSAl Viro 					 const struct qstr *);
240281cad46SBryan Schumaker struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *,
241281cad46SBryan Schumaker 			       struct nfs_fh *, struct nfs_fattr *);
242800c06a5SChuck Lever int nfs4_replace_transport(struct nfs_server *server,
243800c06a5SChuck Lever 				const struct nfs4_fs_locations *locations);
24472de53ecSBryan Schumaker 
2454ce79717STrond Myklebust /* nfs4proc.c */
246f4ac1674SAnna Schumaker extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *);
2471c6dcbe5SAnna Schumaker extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
2481c6dcbe5SAnna Schumaker 			  struct rpc_message *, struct nfs4_sequence_args *,
2491c6dcbe5SAnna Schumaker 			  struct nfs4_sequence_res *, int);
250be3a5d23STrond Myklebust extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int);
251bb8b27e5STrond Myklebust extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *);
252bb8b27e5STrond Myklebust extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *);
2535e6b1990STrond Myklebust extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
2542cf047c9STrond Myklebust extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, struct rpc_cred *cred);
2554d643d1dSAndy Adamson extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred);
25666245539STrond Myklebust extern int nfs4_destroy_clientid(struct nfs_client *clp);
257591d71cbSAndy Adamson extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
2584d643d1dSAndy Adamson extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
2591f7977c1STrond Myklebust extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait);
26055a97593STrond Myklebust extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
261f05d147fSBryan Schumaker extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
262f05d147fSBryan Schumaker 				  struct nfs4_fs_locations *, struct page *);
263b03d735bSChuck Lever extern int nfs4_proc_get_locations(struct inode *, struct nfs4_fs_locations *,
264b03d735bSChuck Lever 		struct page *page, struct rpc_cred *);
26544c99933SChuck Lever extern int nfs4_proc_fsid_present(struct inode *, struct rpc_cred *);
266beffb8feSAl Viro extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, const struct qstr *,
267f05d147fSBryan Schumaker 			    struct nfs_fh *, struct nfs_fattr *);
26872de53ecSBryan Schumaker extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
26964c2ce8bSAneesh Kumar K.V extern const struct xattr_handler *nfs4_xattr_handlers[];
2705521abfdSTrond Myklebust extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
2719b206149STrond Myklebust 		const struct nfs_open_context *ctx,
2729b206149STrond Myklebust 		const struct nfs_lock_context *l_ctx,
2739b206149STrond Myklebust 		fmode_t fmode);
2744ce79717STrond Myklebust 
275557134a3SAndy Adamson #if defined(CONFIG_NFS_V4_1)
276f9c96fccSAndy Adamson extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *);
277848f5bdaSTrond Myklebust extern int nfs4_proc_create_session(struct nfs_client *, struct rpc_cred *);
278848f5bdaSTrond Myklebust extern int nfs4_proc_destroy_session(struct nfs4_session *, struct rpc_cred *);
2799430fb6bSRicardo Labiaga extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
2809430fb6bSRicardo Labiaga 		struct nfs_fsinfo *fsinfo);
281863a3c6cSAndy Adamson extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
282ef311537SAndy Adamson 				  bool sync);
283ba84db96SAndy Adamson extern int nfs4_detect_session_trunking(struct nfs_client *clp,
284ba84db96SAndy Adamson 		struct nfs41_exchange_id_res *res, struct rpc_xprt *xprt);
28594de8b27SAndy Adamson 
28694de8b27SAndy Adamson static inline bool
28794de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp)
28894de8b27SAndy Adamson {
28994de8b27SAndy Adamson 	return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) ==
29094de8b27SAndy Adamson 		EXCHGID4_FLAG_USE_PNFS_DS;
29194de8b27SAndy Adamson }
292d83217c1SAndy Adamson 
293d83217c1SAndy Adamson static inline bool
294d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp)
295d83217c1SAndy Adamson {
296d83217c1SAndy Adamson 	return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
297d83217c1SAndy Adamson }
298ab4c2361SWeston Andros Adamson 
2998c21c62cSWeston Andros Adamson static inline bool
3008c21c62cSWeston Andros Adamson _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
301ab4c2361SWeston Andros Adamson 		    struct rpc_clnt **clntp, struct rpc_message *msg)
302ab4c2361SWeston Andros Adamson {
303ab4c2361SWeston Andros Adamson 	struct rpc_cred *newcred = NULL;
304ab4c2361SWeston Andros Adamson 	rpc_authflavor_t flavor;
305ab4c2361SWeston Andros Adamson 
306b79e87e0SNeilBrown 	if (sp4_mode == NFS_SP4_MACH_CRED_CLEANUP ||
307b79e87e0SNeilBrown 	    sp4_mode == NFS_SP4_MACH_CRED_PNFS_CLEANUP) {
308b79e87e0SNeilBrown 		/* Using machine creds for cleanup operations
309b79e87e0SNeilBrown 		 * is only relevent if the client credentials
310b79e87e0SNeilBrown 		 * might expire. So don't bother for
311b79e87e0SNeilBrown 		 * RPC_AUTH_UNIX.  If file was only exported to
312b79e87e0SNeilBrown 		 * sec=sys, the PUTFH would fail anyway.
313b79e87e0SNeilBrown 		 */
314b79e87e0SNeilBrown 		if ((*clntp)->cl_auth->au_flavor == RPC_AUTH_UNIX)
315b79e87e0SNeilBrown 			return false;
316b79e87e0SNeilBrown 	}
317ab4c2361SWeston Andros Adamson 	if (test_bit(sp4_mode, &clp->cl_sp4_flags)) {
318ab4c2361SWeston Andros Adamson 		spin_lock(&clp->cl_lock);
319ab4c2361SWeston Andros Adamson 		if (clp->cl_machine_cred != NULL)
320ade33ff5SWeston Andros Adamson 			/* don't call get_rpccred on the machine cred -
321ade33ff5SWeston Andros Adamson 			 * a reference will be held for life of clp */
322ade33ff5SWeston Andros Adamson 			newcred = clp->cl_machine_cred;
323ab4c2361SWeston Andros Adamson 		spin_unlock(&clp->cl_lock);
324ab4c2361SWeston Andros Adamson 		msg->rpc_cred = newcred;
325ab4c2361SWeston Andros Adamson 
326ab4c2361SWeston Andros Adamson 		flavor = clp->cl_rpcclient->cl_auth->au_flavor;
327312cd958SWeston Andros Adamson 		WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I &&
328ab4c2361SWeston Andros Adamson 			     flavor != RPC_AUTH_GSS_KRB5P);
329ab4c2361SWeston Andros Adamson 		*clntp = clp->cl_rpcclient;
3308c21c62cSWeston Andros Adamson 
3318c21c62cSWeston Andros Adamson 		return true;
332ab4c2361SWeston Andros Adamson 	}
3338c21c62cSWeston Andros Adamson 	return false;
3348c21c62cSWeston Andros Adamson }
3358c21c62cSWeston Andros Adamson 
3368c21c62cSWeston Andros Adamson /*
3378c21c62cSWeston Andros Adamson  * Function responsible for determining if an rpc_message should use the
3388c21c62cSWeston Andros Adamson  * machine cred under SP4_MACH_CRED and if so switching the credential and
3398c21c62cSWeston Andros Adamson  * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p).
3408c21c62cSWeston Andros Adamson  * Should be called before rpc_call_sync/rpc_call_async.
3418c21c62cSWeston Andros Adamson  */
3428c21c62cSWeston Andros Adamson static inline void
3438c21c62cSWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
3448c21c62cSWeston Andros Adamson 		   struct rpc_clnt **clntp, struct rpc_message *msg)
3458c21c62cSWeston Andros Adamson {
3468c21c62cSWeston Andros Adamson 	_nfs4_state_protect(clp, sp4_mode, clntp, msg);
3478c21c62cSWeston Andros Adamson }
3488c21c62cSWeston Andros Adamson 
3498c21c62cSWeston Andros Adamson /*
3508c21c62cSWeston Andros Adamson  * Special wrapper to nfs4_state_protect for write.
3518c21c62cSWeston Andros Adamson  * If WRITE can use machine cred but COMMIT cannot, make sure all writes
3528c21c62cSWeston Andros Adamson  * that use machine cred use NFS_FILE_SYNC.
3538c21c62cSWeston Andros Adamson  */
3548c21c62cSWeston Andros Adamson static inline void
3558c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
356d45f60c6SWeston Andros Adamson 			 struct rpc_message *msg, struct nfs_pgio_header *hdr)
3578c21c62cSWeston Andros Adamson {
3588c21c62cSWeston Andros Adamson 	if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) &&
3598c21c62cSWeston Andros Adamson 	    !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
360d45f60c6SWeston Andros Adamson 		hdr->args.stable = NFS_FILE_SYNC;
361ab4c2361SWeston Andros Adamson }
362fbcd4abcSAndy Adamson #else /* CONFIG_NFS_v4_1 */
36394de8b27SAndy Adamson static inline bool
36494de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp)
36594de8b27SAndy Adamson {
36694de8b27SAndy Adamson 	return false;
36794de8b27SAndy Adamson }
368d83217c1SAndy Adamson 
369d83217c1SAndy Adamson static inline bool
370d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp)
371d83217c1SAndy Adamson {
372d83217c1SAndy Adamson 	return false;
373d83217c1SAndy Adamson }
374ab4c2361SWeston Andros Adamson 
375ab4c2361SWeston Andros Adamson static inline void
376ab4c2361SWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags,
377ab4c2361SWeston Andros Adamson 		   struct rpc_clnt **clntp, struct rpc_message *msg)
378ab4c2361SWeston Andros Adamson {
379ab4c2361SWeston Andros Adamson }
3808c21c62cSWeston Andros Adamson 
3818c21c62cSWeston Andros Adamson static inline void
3828c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
383d45f60c6SWeston Andros Adamson 			 struct rpc_message *msg, struct nfs_pgio_header *hdr)
3848c21c62cSWeston Andros Adamson {
3858c21c62cSWeston Andros Adamson }
386557134a3SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
3874ce79717STrond Myklebust 
38897dc1359STrond Myklebust extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];
38929fba38bSBenny Halevy 
3901549210fSTrond Myklebust extern const u32 nfs4_fattr_bitmap[3];
391a09df2caSDavid Quigley extern const u32 nfs4_statfs_bitmap[3];
392a09df2caSDavid Quigley extern const u32 nfs4_pathconf_bitmap[3];
393dae100c2SFred Isaman extern const u32 nfs4_fsinfo_bitmap[3];
394a09df2caSDavid Quigley extern const u32 nfs4_fs_locations_bitmap[3];
3954ce79717STrond Myklebust 
396abf79bb3SChuck Lever void nfs40_shutdown_client(struct nfs_client *);
397abf79bb3SChuck Lever void nfs41_shutdown_client(struct nfs_client *);
398abf79bb3SChuck Lever int nfs40_init_client(struct nfs_client *);
399abf79bb3SChuck Lever int nfs41_init_client(struct nfs_client *);
400cdb7ecedSBryan Schumaker void nfs4_free_client(struct nfs_client *);
401cdb7ecedSBryan Schumaker 
4026663ee7fSBryan Schumaker struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *);
4036663ee7fSBryan Schumaker 
4044ce79717STrond Myklebust /* nfs4renewd.c */
405adfa6f98SDavid Howells extern void nfs4_schedule_state_renewal(struct nfs_client *);
4064ce79717STrond Myklebust extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
407adfa6f98SDavid Howells extern void nfs4_kill_renewd(struct nfs_client *);
40865f27f38SDavid Howells extern void nfs4_renew_state(struct work_struct *);
409fb10fb67STrond Myklebust extern void nfs4_set_lease_period(struct nfs_client *clp,
410fb10fb67STrond Myklebust 		unsigned long lease,
411fb10fb67STrond Myklebust 		unsigned long lastrenewed);
412fb10fb67STrond Myklebust 
4134ce79717STrond Myklebust 
4144ce79717STrond Myklebust /* nfs4state.c */
41573d8bde5SChuck Lever struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp);
416fe20d7d5STrond Myklebust struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp);
4176dc9d57aSTrond Myklebust struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp);
41805f4c350SChuck Lever int nfs4_discover_server_trunking(struct nfs_client *clp,
41905f4c350SChuck Lever 			struct nfs_client **);
42005f4c350SChuck Lever int nfs40_discover_server_trunking(struct nfs_client *clp,
42105f4c350SChuck Lever 			struct nfs_client **, struct rpc_cred *);
422a7b72103SAndy Adamson #if defined(CONFIG_NFS_V4_1)
42305f4c350SChuck Lever int nfs41_discover_server_trunking(struct nfs_client *clp,
42405f4c350SChuck Lever 			struct nfs_client **, struct rpc_cred *);
4259f594791STrond Myklebust extern void nfs4_schedule_session_recovery(struct nfs4_session *, int);
4263f10a6afSAnna Schumaker extern void nfs41_notify_server(struct nfs_client *);
4270400a6b0STrond Myklebust #else
4289f594791STrond Myklebust static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err)
4290400a6b0STrond Myklebust {
4300400a6b0STrond Myklebust }
431a7b72103SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4324ce79717STrond Myklebust 
433d1e284d5STrond Myklebust extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *, gfp_t);
4344ce79717STrond Myklebust extern void nfs4_put_state_owner(struct nfs4_state_owner *);
4350aaaf5c4SChuck Lever extern void nfs4_purge_state_owners(struct nfs_server *);
4364ce79717STrond Myklebust extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
4374ce79717STrond Myklebust extern void nfs4_put_open_state(struct nfs4_state *);
438643168c2SAl Viro extern void nfs4_close_state(struct nfs4_state *, fmode_t);
439643168c2SAl Viro extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
440dc0b027dSTrond Myklebust extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
441a1d0b5eeSTrond Myklebust extern void nfs_inode_find_state_and_recover(struct inode *inode,
442a1d0b5eeSTrond Myklebust 		const nfs4_stateid *stateid);
4434f14c194STrond Myklebust extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *, struct nfs4_state *);
4440400a6b0STrond Myklebust extern void nfs4_schedule_lease_recovery(struct nfs_client *);
44533021279STrond Myklebust extern int nfs4_wait_clnt_recover(struct nfs_client *clp);
44633021279STrond Myklebust extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
447b0d3ded1STrond Myklebust extern void nfs4_schedule_state_manager(struct nfs_client *);
448042b60beSTrond Myklebust extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
4495d422301STrond Myklebust extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
450c9fdeb28SChuck Lever extern int nfs4_schedule_migration_recovery(const struct nfs_server *);
451b7f7a66eSChuck Lever extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
4520a014a44STrond Myklebust extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags, bool);
45378fe0f41SWeston Andros Adamson extern void nfs41_handle_server_scope(struct nfs_client *,
45479d4e1f0SChuck Lever 				      struct nfs41_server_scope **);
455faf5f49cSTrond Myklebust extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
4568d0a8a9dSTrond Myklebust extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
457abf4e13cSTrond Myklebust extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t,
45817393475SNeilBrown 		const struct nfs_lock_context *, nfs4_stateid *,
459abf4e13cSTrond Myklebust 		struct rpc_cred **);
4604ce79717STrond Myklebust 
4618535b2beSTrond Myklebust extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
462cee54fc9STrond Myklebust extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
463cee54fc9STrond Myklebust extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
464cee54fc9STrond Myklebust extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
46572211dbeSTrond Myklebust extern void nfs_release_seqid(struct nfs_seqid *seqid);
466cee54fc9STrond Myklebust extern void nfs_free_seqid(struct nfs_seqid *seqid);
4673be0f80bSTrond Myklebust extern int nfs4_setup_sequence(struct nfs_client *client,
468cb04ad2aSPeng Tao 				struct nfs4_sequence_args *args,
469cb04ad2aSPeng Tao 				struct nfs4_sequence_res *res,
470cb04ad2aSPeng Tao 				struct rpc_task *task);
4712c4b131dSPeng Tao extern int nfs4_sequence_done(struct rpc_task *task,
4722c4b131dSPeng Tao 			      struct nfs4_sequence_res *res);
473cee54fc9STrond Myklebust 
4745ae67c4fSTrond Myklebust extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
475cf470c3eSTrond Myklebust 
4764ce79717STrond Myklebust extern const nfs4_stateid zero_stateid;
4774ce79717STrond Myklebust 
478129d1977SBryan Schumaker /* nfs4super.c */
479fbdefd64SBryan Schumaker struct nfs_mount_info;
480ab7017a3SBryan Schumaker extern struct nfs_subversion nfs_v4;
481ff9099f2SBryan Schumaker struct dentry *nfs4_try_mount(int, const char *, struct nfs_mount_info *, struct nfs_subversion *);
482fac1e8e4SBryan Schumaker extern bool nfs4_disable_idmapping;
483fac1e8e4SBryan Schumaker extern unsigned short max_session_slots;
4845405fc44STrond Myklebust extern unsigned short max_session_cb_slots;
485fac1e8e4SBryan Schumaker extern unsigned short send_implementation_id;
486f6de7a39STrond Myklebust extern bool recover_lost_locks;
48789d77c8fSBryan Schumaker 
4886f2ea7f2SChuck Lever #define NFS4_CLIENT_ID_UNIQ_LEN		(64)
4896f2ea7f2SChuck Lever extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
4906f2ea7f2SChuck Lever 
491466bfe7fSBryan Schumaker /* nfs4sysctl.c */
492466bfe7fSBryan Schumaker #ifdef CONFIG_SYSCTL
493466bfe7fSBryan Schumaker int nfs4_register_sysctl(void);
494466bfe7fSBryan Schumaker void nfs4_unregister_sysctl(void);
495466bfe7fSBryan Schumaker #else
496466bfe7fSBryan Schumaker static inline int nfs4_register_sysctl(void)
497466bfe7fSBryan Schumaker {
498466bfe7fSBryan Schumaker 	return 0;
499466bfe7fSBryan Schumaker }
500466bfe7fSBryan Schumaker 
5010add3e85SRandy Dunlap static inline void nfs4_unregister_sysctl(void)
502466bfe7fSBryan Schumaker {
503466bfe7fSBryan Schumaker }
504466bfe7fSBryan Schumaker #endif
505466bfe7fSBryan Schumaker 
5064ce79717STrond Myklebust /* nfs4xdr.c */
507499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs4_procedures[];
5084ce79717STrond Myklebust 
5094ce79717STrond Myklebust struct nfs4_mount_data;
5104ce79717STrond Myklebust 
5114ce79717STrond Myklebust /* callback_xdr.c */
512e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version1;
513e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version4;
5144ce79717STrond Myklebust 
515f597c537STrond Myklebust static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
516f597c537STrond Myklebust {
51793b717fdSTrond Myklebust 	memcpy(dst->data, src->data, sizeof(dst->data));
51893b717fdSTrond Myklebust 	dst->type = src->type;
519f597c537STrond Myklebust }
520f597c537STrond Myklebust 
521f597c537STrond Myklebust static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
522f597c537STrond Myklebust {
52393b717fdSTrond Myklebust 	if (dst->type != src->type)
52493b717fdSTrond Myklebust 		return false;
52593b717fdSTrond Myklebust 	return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
526f597c537STrond Myklebust }
527f597c537STrond Myklebust 
528e999e80eSTrond Myklebust static inline bool nfs4_stateid_match_other(const nfs4_stateid *dst, const nfs4_stateid *src)
529e999e80eSTrond Myklebust {
530e999e80eSTrond Myklebust 	return memcmp(dst->other, src->other, NFS4_STATEID_OTHER_SIZE) == 0;
531e999e80eSTrond Myklebust }
532e999e80eSTrond Myklebust 
533e999e80eSTrond Myklebust static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stateid *s2)
534e999e80eSTrond Myklebust {
535e999e80eSTrond Myklebust 	return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0;
536e999e80eSTrond Myklebust }
537e999e80eSTrond Myklebust 
5385d422301STrond Myklebust static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
5395d422301STrond Myklebust {
5405d422301STrond Myklebust 	return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0;
5415d422301STrond Myklebust }
5425d422301STrond Myklebust 
5433e7dfb16STrond Myklebust static inline bool nfs4_state_match_open_stateid_other(const struct nfs4_state *state,
5443e7dfb16STrond Myklebust 		const nfs4_stateid *stateid)
5453e7dfb16STrond Myklebust {
5463e7dfb16STrond Myklebust 	return test_bit(NFS_OPEN_STATE, &state->flags) &&
5473e7dfb16STrond Myklebust 		nfs4_stateid_match_other(&state->open_stateid, stateid);
5483e7dfb16STrond Myklebust }
5493e7dfb16STrond Myklebust 
5504ce79717STrond Myklebust #else
5514ce79717STrond Myklebust 
552643168c2SAl Viro #define nfs4_close_state(a, b) do { } while (0)
553643168c2SAl Viro #define nfs4_close_sync(a, b) do { } while (0)
5548c21c62cSWeston Andros Adamson #define nfs4_state_protect(a, b, c, d) do { } while (0)
5558c21c62cSWeston Andros Adamson #define nfs4_state_protect_write(a, b, c, d) do { } while (0)
5564ce79717STrond Myklebust 
5574ce79717STrond Myklebust #endif /* CONFIG_NFS_V4 */
5584ce79717STrond Myklebust #endif /* __LINUX_FS_NFS_NFS4_FS.H */
559