xref: /openbmc/linux/fs/nfs/nfs4_fs.h (revision 694e096f)
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,
424ce79717STrond Myklebust };
434ce79717STrond Myklebust 
442f60ea6bSTrond Myklebust #define NFS4_RENEW_TIMEOUT		0x01
452f60ea6bSTrond Myklebust #define NFS4_RENEW_DELEGATION_CB	0x02
462f60ea6bSTrond Myklebust 
4797dc1359STrond Myklebust struct nfs4_minor_version_ops {
4897dc1359STrond Myklebust 	u32	minor_version;
4939c6daaeSTrond Myklebust 	unsigned init_caps;
5097dc1359STrond Myklebust 
51abf79bb3SChuck Lever 	int	(*init_client)(struct nfs_client *);
52abf79bb3SChuck Lever 	void	(*shutdown_client)(struct nfs_client *);
5336281caaSTrond Myklebust 	bool	(*match_stateid)(const nfs4_stateid *,
54e047a10cSTrond Myklebust 			const nfs4_stateid *);
55fca78d6dSBryan Schumaker 	int	(*find_root_sec)(struct nfs_server *, struct nfs_fh *,
56fca78d6dSBryan Schumaker 			struct nfs_fsinfo *);
57c8b2d0bfSTrond Myklebust 	int	(*free_lock_state)(struct nfs_server *,
58c8b2d0bfSTrond Myklebust 			struct nfs4_lock_state *);
599915ea7eSChuck Lever 	const struct rpc_call_ops *call_sync_ops;
60c48f4f35STrond Myklebust 	const struct nfs4_state_recovery_ops *reboot_recovery_ops;
61c48f4f35STrond Myklebust 	const struct nfs4_state_recovery_ops *nograce_recovery_ops;
62c48f4f35STrond Myklebust 	const struct nfs4_state_maintenance_ops *state_renewal_ops;
63ec011fe8SChuck Lever 	const struct nfs4_mig_recovery_ops *mig_recovery_ops;
6497dc1359STrond Myklebust };
6597dc1359STrond Myklebust 
66cee54fc9STrond Myklebust #define NFS_SEQID_CONFIRMED 1
67cee54fc9STrond Myklebust struct nfs_seqid_counter {
6895b72eb0STrond Myklebust 	ktime_t create_time;
6948c22eb2STrond Myklebust 	int owner_id;
70cee54fc9STrond Myklebust 	int flags;
71cee54fc9STrond Myklebust 	u32 counter;
727ba127abSTrond Myklebust 	spinlock_t lock;		/* Protects the list */
737ba127abSTrond Myklebust 	struct list_head list;		/* Defines sequence of RPC calls */
747ba127abSTrond Myklebust 	struct rpc_wait_queue	wait;	/* RPC call delay queue */
75cee54fc9STrond Myklebust };
76cee54fc9STrond Myklebust 
77cee54fc9STrond Myklebust struct nfs_seqid {
78cee54fc9STrond Myklebust 	struct nfs_seqid_counter *sequence;
794e51336aSTrond Myklebust 	struct list_head list;
804601df20STrond Myklebust 	struct rpc_task *task;
81cee54fc9STrond Myklebust };
82cee54fc9STrond Myklebust 
83cee54fc9STrond Myklebust static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
84cee54fc9STrond Myklebust {
85cee54fc9STrond Myklebust 	if (seqid_mutating_err(-status))
86cee54fc9STrond Myklebust 		seqid->flags |= NFS_SEQID_CONFIRMED;
87cee54fc9STrond Myklebust }
88cee54fc9STrond Myklebust 
89cee54fc9STrond Myklebust /*
904ce79717STrond Myklebust  * NFS4 state_owners and lock_owners are simply labels for ordered
914ce79717STrond Myklebust  * sequences of RPC calls. Their sole purpose is to provide once-only
924ce79717STrond Myklebust  * semantics by allowing the server to identify replayed requests.
934ce79717STrond Myklebust  */
944ce79717STrond Myklebust struct nfs4_state_owner {
956f2e64d3STrond Myklebust 	struct nfs_server    *so_server;
960aaaf5c4SChuck Lever 	struct list_head     so_lru;
970aaaf5c4SChuck Lever 	unsigned long        so_expires;
9824d292b8SChuck Lever 	struct rb_node	     so_server_node;
994ce79717STrond Myklebust 
1004ce79717STrond Myklebust 	struct rpc_cred	     *so_cred;	 /* Associated cred */
1019f958ab8STrond Myklebust 
1029f958ab8STrond Myklebust 	spinlock_t	     so_lock;
1039f958ab8STrond Myklebust 	atomic_t	     so_count;
1047eff03aeSTrond Myklebust 	unsigned long	     so_flags;
1054ce79717STrond Myklebust 	struct list_head     so_states;
106cee54fc9STrond Myklebust 	struct nfs_seqid_counter so_seqid;
107c137afabSTrond Myklebust 	seqcount_t	     so_reclaim_seqcount;
10865b62a29STrond Myklebust 	struct mutex	     so_delegreturn_mutex;
1094ce79717STrond Myklebust };
1104ce79717STrond Myklebust 
1117eff03aeSTrond Myklebust enum {
1127eff03aeSTrond Myklebust 	NFS_OWNER_RECLAIM_REBOOT,
1137eff03aeSTrond Myklebust 	NFS_OWNER_RECLAIM_NOGRACE
1147eff03aeSTrond Myklebust };
1157eff03aeSTrond Myklebust 
116afe6c27cSAlexandros Batsakis #define NFS_LOCK_NEW		0
117afe6c27cSAlexandros Batsakis #define NFS_LOCK_RECLAIM	1
118afe6c27cSAlexandros Batsakis #define NFS_LOCK_EXPIRED	2
119afe6c27cSAlexandros Batsakis 
1204ce79717STrond Myklebust /*
1214ce79717STrond Myklebust  * struct nfs4_state maintains the client-side state for a given
1224ce79717STrond Myklebust  * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
1234ce79717STrond Myklebust  *
1244ce79717STrond Myklebust  * OPEN:
1254ce79717STrond Myklebust  * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
1264ce79717STrond Myklebust  * we need to know how many files are open for reading or writing on a
1274ce79717STrond Myklebust  * given inode. This information too is stored here.
1284ce79717STrond Myklebust  *
1294ce79717STrond Myklebust  * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
1304ce79717STrond Myklebust  */
1314ce79717STrond Myklebust 
13277041ed9STrond Myklebust struct nfs4_lock_owner {
13377041ed9STrond Myklebust 	unsigned int lo_type;
13477041ed9STrond Myklebust #define NFS4_ANY_LOCK_TYPE	(0U)
13577041ed9STrond Myklebust #define NFS4_FLOCK_LOCK_TYPE	(1U << 0)
13677041ed9STrond Myklebust #define NFS4_POSIX_LOCK_TYPE	(1U << 1)
13777041ed9STrond Myklebust 	union {
13877041ed9STrond Myklebust 		fl_owner_t posix_owner;
13977041ed9STrond Myklebust 		pid_t flock_owner;
14077041ed9STrond Myklebust 	} lo_u;
14177041ed9STrond Myklebust };
14277041ed9STrond Myklebust 
1434ce79717STrond Myklebust struct nfs4_lock_state {
1444ce79717STrond Myklebust 	struct list_head	ls_locks;	/* Other lock stateids */
1458d0a8a9dSTrond Myklebust 	struct nfs4_state *	ls_state;	/* Pointer to open state */
146795a88c9STrond Myklebust #define NFS_LOCK_INITIALIZED 0
147ef1820f9SNeilBrown #define NFS_LOCK_LOST        1
148795a88c9STrond Myklebust 	unsigned long		ls_flags;
149cee54fc9STrond Myklebust 	struct nfs_seqid_counter	ls_seqid;
1504ce79717STrond Myklebust 	nfs4_stateid		ls_stateid;
1514ce79717STrond Myklebust 	atomic_t		ls_count;
15277041ed9STrond Myklebust 	struct nfs4_lock_owner	ls_owner;
1534ce79717STrond Myklebust };
1544ce79717STrond Myklebust 
1554ce79717STrond Myklebust /* bits for nfs4_state->flags */
1564ce79717STrond Myklebust enum {
1574ce79717STrond Myklebust 	LK_STATE_IN_USE,
158003707c7STrond Myklebust 	NFS_DELEGATED_STATE,		/* Current stateid is delegation */
15992b40e93STrond Myklebust 	NFS_OPEN_STATE,			/* OPEN stateid is set */
160003707c7STrond Myklebust 	NFS_O_RDONLY_STATE,		/* OPEN stateid has read-only state */
161003707c7STrond Myklebust 	NFS_O_WRONLY_STATE,		/* OPEN stateid has write-only state */
162003707c7STrond Myklebust 	NFS_O_RDWR_STATE,		/* OPEN stateid has read/write state */
163b79a4a1bSTrond Myklebust 	NFS_STATE_RECLAIM_REBOOT,	/* OPEN stateid server rebooted */
164b79a4a1bSTrond Myklebust 	NFS_STATE_RECLAIM_NOGRACE,	/* OPEN stateid needs to recover state */
1658e469ebdSTrond Myklebust 	NFS_STATE_POSIX_LOCKS,		/* Posix locks are supported */
1665d422301STrond Myklebust 	NFS_STATE_RECOVERY_FAILED,	/* OPEN stateid state recovery failed */
1674ce79717STrond Myklebust };
1684ce79717STrond Myklebust 
1694ce79717STrond Myklebust struct nfs4_state {
1704ce79717STrond Myklebust 	struct list_head open_states;	/* List of states for the same state_owner */
1714ce79717STrond Myklebust 	struct list_head inode_states;	/* List of states for the same inode */
1724ce79717STrond Myklebust 	struct list_head lock_states;	/* List of subservient lock stateids */
1734ce79717STrond Myklebust 
1744ce79717STrond Myklebust 	struct nfs4_state_owner *owner;	/* Pointer to the open owner */
1754ce79717STrond Myklebust 	struct inode *inode;		/* Pointer to the inode */
1764ce79717STrond Myklebust 
1774ce79717STrond Myklebust 	unsigned long flags;		/* Do we hold any locks? */
1788d0a8a9dSTrond Myklebust 	spinlock_t state_lock;		/* Protects the lock_states list */
1794ce79717STrond Myklebust 
1808bda4e4cSTrond Myklebust 	seqlock_t seqlock;		/* Protects the stateid/open_stateid */
181003707c7STrond Myklebust 	nfs4_stateid stateid;		/* Current stateid: may be delegation */
182003707c7STrond Myklebust 	nfs4_stateid open_stateid;	/* OPEN stateid */
1834ce79717STrond Myklebust 
1848bda4e4cSTrond Myklebust 	/* The following 3 fields are protected by owner->so_lock */
185003707c7STrond Myklebust 	unsigned int n_rdonly;		/* Number of read-only references */
186003707c7STrond Myklebust 	unsigned int n_wronly;		/* Number of write-only references */
187003707c7STrond Myklebust 	unsigned int n_rdwr;		/* Number of read/write references */
188dc0b027dSTrond Myklebust 	fmode_t state;			/* State on the server (R,W, or RW) */
1894ce79717STrond Myklebust 	atomic_t count;
1904ce79717STrond Myklebust };
1914ce79717STrond Myklebust 
1924ce79717STrond Myklebust 
1934ce79717STrond Myklebust struct nfs4_exception {
1944ce79717STrond Myklebust 	long timeout;
1954ce79717STrond Myklebust 	int retry;
1969e33bed5STrond Myklebust 	struct nfs4_state *state;
1973114ea7aSTrond Myklebust 	struct inode *inode;
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 
21129fba38bSBenny Halevy struct nfs4_state_maintenance_ops {
2122f60ea6bSTrond Myklebust 	int (*sched_state_renewal)(struct nfs_client *, struct rpc_cred *, unsigned);
213a7b72103SAndy Adamson 	struct rpc_cred * (*get_state_renewal_cred_locked)(struct nfs_client *);
2148e69514fSBenny Halevy 	int (*renew_lease)(struct nfs_client *, struct rpc_cred *);
21529fba38bSBenny Halevy };
21629fba38bSBenny Halevy 
217ec011fe8SChuck Lever struct nfs4_mig_recovery_ops {
218b03d735bSChuck Lever 	int (*get_locations)(struct inode *, struct nfs4_fs_locations *,
219b03d735bSChuck Lever 		struct page *, struct rpc_cred *);
22044c99933SChuck Lever 	int (*fsid_present)(struct inode *, struct rpc_cred *);
221ec011fe8SChuck Lever };
222ec011fe8SChuck Lever 
223f786aa90SAl Viro extern const struct dentry_operations nfs4_dentry_operations;
22473a79706SBryan Schumaker 
22573a79706SBryan Schumaker /* dir.c */
22673a79706SBryan Schumaker int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
22773a79706SBryan Schumaker 		    unsigned, umode_t, int *);
2286b3b5496SJ. Bruce Fields 
2291ae811eeSbjschuma@gmail.com /* super.c */
2301ae811eeSbjschuma@gmail.com extern struct file_system_type nfs4_fs_type;
2311ae811eeSbjschuma@gmail.com 
23272de53ecSBryan Schumaker /* nfs4namespace.c */
23372de53ecSBryan Schumaker struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *, struct inode *, struct qstr *);
234281cad46SBryan Schumaker struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *,
235281cad46SBryan Schumaker 			       struct nfs_fh *, struct nfs_fattr *);
236800c06a5SChuck Lever int nfs4_replace_transport(struct nfs_server *server,
237800c06a5SChuck Lever 				const struct nfs4_fs_locations *locations);
23872de53ecSBryan Schumaker 
2394ce79717STrond Myklebust /* nfs4proc.c */
240bb8b27e5STrond Myklebust extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *);
241bb8b27e5STrond Myklebust extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *);
2425e6b1990STrond Myklebust extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
2432cf047c9STrond Myklebust extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, struct rpc_cred *cred);
2444d643d1dSAndy Adamson extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred);
24566245539STrond Myklebust extern int nfs4_destroy_clientid(struct nfs_client *clp);
246591d71cbSAndy Adamson extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
2474d643d1dSAndy Adamson extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
2481f7977c1STrond Myklebust extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait);
24955a97593STrond Myklebust extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
250f05d147fSBryan Schumaker extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
251f05d147fSBryan Schumaker 				  struct nfs4_fs_locations *, struct page *);
252b03d735bSChuck Lever extern int nfs4_proc_get_locations(struct inode *, struct nfs4_fs_locations *,
253b03d735bSChuck Lever 		struct page *page, struct rpc_cred *);
25444c99933SChuck Lever extern int nfs4_proc_fsid_present(struct inode *, struct rpc_cred *);
255f05d147fSBryan Schumaker extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, struct qstr *,
256f05d147fSBryan Schumaker 			    struct nfs_fh *, struct nfs_fattr *);
25772de53ecSBryan Schumaker extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
25864c2ce8bSAneesh Kumar K.V extern const struct xattr_handler *nfs4_xattr_handlers[];
2595521abfdSTrond Myklebust extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
2609b206149STrond Myklebust 		const struct nfs_open_context *ctx,
2619b206149STrond Myklebust 		const struct nfs_lock_context *l_ctx,
2629b206149STrond Myklebust 		fmode_t fmode);
2634ce79717STrond Myklebust 
264557134a3SAndy Adamson #if defined(CONFIG_NFS_V4_1)
265035168abSTrond Myklebust static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server)
266035168abSTrond Myklebust {
267035168abSTrond Myklebust 	return server->nfs_client->cl_session;
268035168abSTrond Myklebust }
269035168abSTrond Myklebust 
270dc70d7b3SAndy Adamson extern int nfs41_setup_sequence(struct nfs4_session *session,
271dc70d7b3SAndy Adamson 		struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
2729d12b216STrond Myklebust 		struct rpc_task *task);
273848f5bdaSTrond Myklebust extern int nfs4_proc_create_session(struct nfs_client *, struct rpc_cred *);
274848f5bdaSTrond Myklebust extern int nfs4_proc_destroy_session(struct nfs4_session *, struct rpc_cred *);
2759430fb6bSRicardo Labiaga extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
2769430fb6bSRicardo Labiaga 		struct nfs_fsinfo *fsinfo);
277863a3c6cSAndy Adamson extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
278ef311537SAndy Adamson 				  bool sync);
27994de8b27SAndy Adamson 
28094de8b27SAndy Adamson static inline bool
28194de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp)
28294de8b27SAndy Adamson {
28394de8b27SAndy Adamson 	return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) ==
28494de8b27SAndy Adamson 		EXCHGID4_FLAG_USE_PNFS_DS;
28594de8b27SAndy Adamson }
286d83217c1SAndy Adamson 
287d83217c1SAndy Adamson static inline bool
288d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp)
289d83217c1SAndy Adamson {
290d83217c1SAndy Adamson 	return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
291d83217c1SAndy Adamson }
292ab4c2361SWeston Andros Adamson 
2938c21c62cSWeston Andros Adamson static inline bool
2948c21c62cSWeston Andros Adamson _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
295ab4c2361SWeston Andros Adamson 		    struct rpc_clnt **clntp, struct rpc_message *msg)
296ab4c2361SWeston Andros Adamson {
297ab4c2361SWeston Andros Adamson 	struct rpc_cred *newcred = NULL;
298ab4c2361SWeston Andros Adamson 	rpc_authflavor_t flavor;
299ab4c2361SWeston Andros Adamson 
300ab4c2361SWeston Andros Adamson 	if (test_bit(sp4_mode, &clp->cl_sp4_flags)) {
301ab4c2361SWeston Andros Adamson 		spin_lock(&clp->cl_lock);
302ab4c2361SWeston Andros Adamson 		if (clp->cl_machine_cred != NULL)
303ade33ff5SWeston Andros Adamson 			/* don't call get_rpccred on the machine cred -
304ade33ff5SWeston Andros Adamson 			 * a reference will be held for life of clp */
305ade33ff5SWeston Andros Adamson 			newcred = clp->cl_machine_cred;
306ab4c2361SWeston Andros Adamson 		spin_unlock(&clp->cl_lock);
307ab4c2361SWeston Andros Adamson 		msg->rpc_cred = newcred;
308ab4c2361SWeston Andros Adamson 
309ab4c2361SWeston Andros Adamson 		flavor = clp->cl_rpcclient->cl_auth->au_flavor;
310312cd958SWeston Andros Adamson 		WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I &&
311ab4c2361SWeston Andros Adamson 			     flavor != RPC_AUTH_GSS_KRB5P);
312ab4c2361SWeston Andros Adamson 		*clntp = clp->cl_rpcclient;
3138c21c62cSWeston Andros Adamson 
3148c21c62cSWeston Andros Adamson 		return true;
315ab4c2361SWeston Andros Adamson 	}
3168c21c62cSWeston Andros Adamson 	return false;
3178c21c62cSWeston Andros Adamson }
3188c21c62cSWeston Andros Adamson 
3198c21c62cSWeston Andros Adamson /*
3208c21c62cSWeston Andros Adamson  * Function responsible for determining if an rpc_message should use the
3218c21c62cSWeston Andros Adamson  * machine cred under SP4_MACH_CRED and if so switching the credential and
3228c21c62cSWeston Andros Adamson  * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p).
3238c21c62cSWeston Andros Adamson  * Should be called before rpc_call_sync/rpc_call_async.
3248c21c62cSWeston Andros Adamson  */
3258c21c62cSWeston Andros Adamson static inline void
3268c21c62cSWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
3278c21c62cSWeston Andros Adamson 		   struct rpc_clnt **clntp, struct rpc_message *msg)
3288c21c62cSWeston Andros Adamson {
3298c21c62cSWeston Andros Adamson 	_nfs4_state_protect(clp, sp4_mode, clntp, msg);
3308c21c62cSWeston Andros Adamson }
3318c21c62cSWeston Andros Adamson 
3328c21c62cSWeston Andros Adamson /*
3338c21c62cSWeston Andros Adamson  * Special wrapper to nfs4_state_protect for write.
3348c21c62cSWeston Andros Adamson  * If WRITE can use machine cred but COMMIT cannot, make sure all writes
3358c21c62cSWeston Andros Adamson  * that use machine cred use NFS_FILE_SYNC.
3368c21c62cSWeston Andros Adamson  */
3378c21c62cSWeston Andros Adamson static inline void
3388c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
3398c21c62cSWeston Andros Adamson 			 struct rpc_message *msg, struct nfs_write_data *wdata)
3408c21c62cSWeston Andros Adamson {
3418c21c62cSWeston Andros Adamson 	if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) &&
3428c21c62cSWeston Andros Adamson 	    !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
3438c21c62cSWeston Andros Adamson 		wdata->args.stable = NFS_FILE_SYNC;
344ab4c2361SWeston Andros Adamson }
345fbcd4abcSAndy Adamson #else /* CONFIG_NFS_v4_1 */
346035168abSTrond Myklebust static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server)
347035168abSTrond Myklebust {
348035168abSTrond Myklebust 	return NULL;
349035168abSTrond Myklebust }
350035168abSTrond Myklebust 
35194de8b27SAndy Adamson static inline bool
35294de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp)
35394de8b27SAndy Adamson {
35494de8b27SAndy Adamson 	return false;
35594de8b27SAndy Adamson }
356d83217c1SAndy Adamson 
357d83217c1SAndy Adamson static inline bool
358d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp)
359d83217c1SAndy Adamson {
360d83217c1SAndy Adamson 	return false;
361d83217c1SAndy Adamson }
362ab4c2361SWeston Andros Adamson 
363ab4c2361SWeston Andros Adamson static inline void
364ab4c2361SWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags,
365ab4c2361SWeston Andros Adamson 		   struct rpc_clnt **clntp, struct rpc_message *msg)
366ab4c2361SWeston Andros Adamson {
367ab4c2361SWeston Andros Adamson }
3688c21c62cSWeston Andros Adamson 
3698c21c62cSWeston Andros Adamson static inline void
3708c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
3718c21c62cSWeston Andros Adamson 			 struct rpc_message *msg, struct nfs_write_data *wdata)
3728c21c62cSWeston Andros Adamson {
3738c21c62cSWeston Andros Adamson }
374557134a3SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
3754ce79717STrond Myklebust 
37697dc1359STrond Myklebust extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];
37729fba38bSBenny Halevy 
3781549210fSTrond Myklebust extern const u32 nfs4_fattr_bitmap[3];
379a09df2caSDavid Quigley extern const u32 nfs4_statfs_bitmap[3];
380a09df2caSDavid Quigley extern const u32 nfs4_pathconf_bitmap[3];
381dae100c2SFred Isaman extern const u32 nfs4_fsinfo_bitmap[3];
382a09df2caSDavid Quigley extern const u32 nfs4_fs_locations_bitmap[3];
3834ce79717STrond Myklebust 
384abf79bb3SChuck Lever void nfs40_shutdown_client(struct nfs_client *);
385abf79bb3SChuck Lever void nfs41_shutdown_client(struct nfs_client *);
386abf79bb3SChuck Lever int nfs40_init_client(struct nfs_client *);
387abf79bb3SChuck Lever int nfs41_init_client(struct nfs_client *);
388cdb7ecedSBryan Schumaker void nfs4_free_client(struct nfs_client *);
389cdb7ecedSBryan Schumaker 
3906663ee7fSBryan Schumaker struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *);
3916663ee7fSBryan Schumaker 
3924ce79717STrond Myklebust /* nfs4renewd.c */
393adfa6f98SDavid Howells extern void nfs4_schedule_state_renewal(struct nfs_client *);
3944ce79717STrond Myklebust extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
395adfa6f98SDavid Howells extern void nfs4_kill_renewd(struct nfs_client *);
39665f27f38SDavid Howells extern void nfs4_renew_state(struct work_struct *);
3974ce79717STrond Myklebust 
3984ce79717STrond Myklebust /* nfs4state.c */
39973d8bde5SChuck Lever struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp);
400fe20d7d5STrond Myklebust struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp);
4016dc9d57aSTrond Myklebust struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp);
40205f4c350SChuck Lever int nfs4_discover_server_trunking(struct nfs_client *clp,
40305f4c350SChuck Lever 			struct nfs_client **);
40405f4c350SChuck Lever int nfs40_discover_server_trunking(struct nfs_client *clp,
40505f4c350SChuck Lever 			struct nfs_client **, struct rpc_cred *);
406a7b72103SAndy Adamson #if defined(CONFIG_NFS_V4_1)
40705f4c350SChuck Lever int nfs41_discover_server_trunking(struct nfs_client *clp,
40805f4c350SChuck Lever 			struct nfs_client **, struct rpc_cred *);
4099f594791STrond Myklebust extern void nfs4_schedule_session_recovery(struct nfs4_session *, int);
410ac074835STrond Myklebust extern void nfs41_server_notify_target_slotid_update(struct nfs_client *clp);
411c10e4498STrond Myklebust extern void nfs41_server_notify_highest_slotid_update(struct nfs_client *clp);
4125d63360dSTrond Myklebust 
4130400a6b0STrond Myklebust #else
4149f594791STrond Myklebust static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err)
4150400a6b0STrond Myklebust {
4160400a6b0STrond Myklebust }
417a7b72103SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4184ce79717STrond Myklebust 
419d1e284d5STrond Myklebust extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *, gfp_t);
4204ce79717STrond Myklebust extern void nfs4_put_state_owner(struct nfs4_state_owner *);
4210aaaf5c4SChuck Lever extern void nfs4_purge_state_owners(struct nfs_server *);
4224ce79717STrond Myklebust extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
4234ce79717STrond Myklebust extern void nfs4_put_open_state(struct nfs4_state *);
424643168c2SAl Viro extern void nfs4_close_state(struct nfs4_state *, fmode_t);
425643168c2SAl Viro extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
426dc0b027dSTrond Myklebust extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
427a1d0b5eeSTrond Myklebust extern void nfs_inode_find_state_and_recover(struct inode *inode,
428a1d0b5eeSTrond Myklebust 		const nfs4_stateid *stateid);
4290400a6b0STrond Myklebust extern void nfs4_schedule_lease_recovery(struct nfs_client *);
43033021279STrond Myklebust extern int nfs4_wait_clnt_recover(struct nfs_client *clp);
43133021279STrond Myklebust extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
432b0d3ded1STrond Myklebust extern void nfs4_schedule_state_manager(struct nfs_client *);
433042b60beSTrond Myklebust extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
4345d422301STrond Myklebust extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
435c9fdeb28SChuck Lever extern int nfs4_schedule_migration_recovery(const struct nfs_server *);
436b7f7a66eSChuck Lever extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
4370629e370SAlexandros Batsakis extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
43878fe0f41SWeston Andros Adamson extern void nfs41_handle_server_scope(struct nfs_client *,
43979d4e1f0SChuck Lever 				      struct nfs41_server_scope **);
440faf5f49cSTrond Myklebust extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
4418d0a8a9dSTrond Myklebust extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
4425521abfdSTrond Myklebust extern int nfs4_select_rw_stateid(nfs4_stateid *, struct nfs4_state *,
4432a369153STrond Myklebust 		fmode_t, const struct nfs_lockowner *);
4444ce79717STrond Myklebust 
4458535b2beSTrond Myklebust extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
446cee54fc9STrond Myklebust extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
447cee54fc9STrond Myklebust extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
448cee54fc9STrond Myklebust extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
44972211dbeSTrond Myklebust extern void nfs_release_seqid(struct nfs_seqid *seqid);
450cee54fc9STrond Myklebust extern void nfs_free_seqid(struct nfs_seqid *seqid);
451cee54fc9STrond Myklebust 
4525ae67c4fSTrond Myklebust extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
453cf470c3eSTrond Myklebust 
4544ce79717STrond Myklebust extern const nfs4_stateid zero_stateid;
4554ce79717STrond Myklebust 
456129d1977SBryan Schumaker /* nfs4super.c */
457fbdefd64SBryan Schumaker struct nfs_mount_info;
458ab7017a3SBryan Schumaker extern struct nfs_subversion nfs_v4;
459ff9099f2SBryan Schumaker struct dentry *nfs4_try_mount(int, const char *, struct nfs_mount_info *, struct nfs_subversion *);
460fac1e8e4SBryan Schumaker extern bool nfs4_disable_idmapping;
461fac1e8e4SBryan Schumaker extern unsigned short max_session_slots;
462fac1e8e4SBryan Schumaker extern unsigned short send_implementation_id;
463f6de7a39STrond Myklebust extern bool recover_lost_locks;
46489d77c8fSBryan Schumaker 
4656f2ea7f2SChuck Lever #define NFS4_CLIENT_ID_UNIQ_LEN		(64)
4666f2ea7f2SChuck Lever extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
4676f2ea7f2SChuck Lever 
468466bfe7fSBryan Schumaker /* nfs4sysctl.c */
469466bfe7fSBryan Schumaker #ifdef CONFIG_SYSCTL
470466bfe7fSBryan Schumaker int nfs4_register_sysctl(void);
471466bfe7fSBryan Schumaker void nfs4_unregister_sysctl(void);
472466bfe7fSBryan Schumaker #else
473466bfe7fSBryan Schumaker static inline int nfs4_register_sysctl(void)
474466bfe7fSBryan Schumaker {
475466bfe7fSBryan Schumaker 	return 0;
476466bfe7fSBryan Schumaker }
477466bfe7fSBryan Schumaker 
4780add3e85SRandy Dunlap static inline void nfs4_unregister_sysctl(void)
479466bfe7fSBryan Schumaker {
480466bfe7fSBryan Schumaker }
481466bfe7fSBryan Schumaker #endif
482466bfe7fSBryan Schumaker 
4834ce79717STrond Myklebust /* nfs4xdr.c */
4844ce79717STrond Myklebust extern struct rpc_procinfo nfs4_procedures[];
4854ce79717STrond Myklebust 
4864ce79717STrond Myklebust struct nfs4_mount_data;
4874ce79717STrond Myklebust 
4884ce79717STrond Myklebust /* callback_xdr.c */
4894ce79717STrond Myklebust extern struct svc_version nfs4_callback_version1;
49007bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4;
4914ce79717STrond Myklebust 
492f597c537STrond Myklebust static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
493f597c537STrond Myklebust {
4942d2f24adSTrond Myklebust 	memcpy(dst, src, sizeof(*dst));
495f597c537STrond Myklebust }
496f597c537STrond Myklebust 
497f597c537STrond Myklebust static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
498f597c537STrond Myklebust {
4992d2f24adSTrond Myklebust 	return memcmp(dst, src, sizeof(*dst)) == 0;
500f597c537STrond Myklebust }
501f597c537STrond Myklebust 
5025d422301STrond Myklebust static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
5035d422301STrond Myklebust {
5045d422301STrond Myklebust 	return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0;
5055d422301STrond Myklebust }
5065d422301STrond Myklebust 
5074ce79717STrond Myklebust #else
5084ce79717STrond Myklebust 
509643168c2SAl Viro #define nfs4_close_state(a, b) do { } while (0)
510643168c2SAl Viro #define nfs4_close_sync(a, b) do { } while (0)
5118c21c62cSWeston Andros Adamson #define nfs4_state_protect(a, b, c, d) do { } while (0)
5128c21c62cSWeston Andros Adamson #define nfs4_state_protect_write(a, b, c, d) do { } while (0)
5134ce79717STrond Myklebust 
5144ce79717STrond Myklebust #endif /* CONFIG_NFS_V4 */
5154ce79717STrond Myklebust #endif /* __LINUX_FS_NFS_NFS4_FS.H */
516