xref: /openbmc/linux/fs/nfs/nfs4_fs.h (revision b03d735b)
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 
1289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
134ce79717STrond Myklebust 
1433021279STrond Myklebust #define NFS4_MAX_LOOP_ON_RECOVER (10)
1533021279STrond Myklebust 
16c137afabSTrond Myklebust #include <linux/seqlock.h>
17c137afabSTrond Myklebust 
184ce79717STrond Myklebust struct idmap;
194ce79717STrond Myklebust 
204ce79717STrond Myklebust enum nfs4_client_state {
21e005e804STrond Myklebust 	NFS4CLNT_MANAGER_RUNNING  = 0,
22e598d843STrond Myklebust 	NFS4CLNT_CHECK_LEASE,
2358d9714aSTrond Myklebust 	NFS4CLNT_LEASE_EXPIRED,
24b79a4a1bSTrond Myklebust 	NFS4CLNT_RECLAIM_REBOOT,
25b79a4a1bSTrond Myklebust 	NFS4CLNT_RECLAIM_NOGRACE,
26707fb4b3STrond Myklebust 	NFS4CLNT_DELEGRETURN,
276df08189SAndy Adamson 	NFS4CLNT_SESSION_RESET,
28fd954ae1STrond Myklebust 	NFS4CLNT_LEASE_CONFIRM,
2978fe0f41SWeston Andros Adamson 	NFS4CLNT_SERVER_SCOPE_MISMATCH,
302c820d9aSChuck Lever 	NFS4CLNT_PURGE_STATE,
31a9e64442SWeston Andros Adamson 	NFS4CLNT_BIND_CONN_TO_SESSION,
324ce79717STrond Myklebust };
334ce79717STrond Myklebust 
342f60ea6bSTrond Myklebust #define NFS4_RENEW_TIMEOUT		0x01
352f60ea6bSTrond Myklebust #define NFS4_RENEW_DELEGATION_CB	0x02
362f60ea6bSTrond Myklebust 
3797dc1359STrond Myklebust struct nfs4_minor_version_ops {
3897dc1359STrond Myklebust 	u32	minor_version;
3939c6daaeSTrond Myklebust 	unsigned init_caps;
4097dc1359STrond Myklebust 
41abf79bb3SChuck Lever 	int	(*init_client)(struct nfs_client *);
42abf79bb3SChuck Lever 	void	(*shutdown_client)(struct nfs_client *);
4336281caaSTrond Myklebust 	bool	(*match_stateid)(const nfs4_stateid *,
44e047a10cSTrond Myklebust 			const nfs4_stateid *);
45fca78d6dSBryan Schumaker 	int	(*find_root_sec)(struct nfs_server *, struct nfs_fh *,
46fca78d6dSBryan Schumaker 			struct nfs_fsinfo *);
47c8b2d0bfSTrond Myklebust 	int	(*free_lock_state)(struct nfs_server *,
48c8b2d0bfSTrond Myklebust 			struct nfs4_lock_state *);
499915ea7eSChuck Lever 	const struct rpc_call_ops *call_sync_ops;
50c48f4f35STrond Myklebust 	const struct nfs4_state_recovery_ops *reboot_recovery_ops;
51c48f4f35STrond Myklebust 	const struct nfs4_state_recovery_ops *nograce_recovery_ops;
52c48f4f35STrond Myklebust 	const struct nfs4_state_maintenance_ops *state_renewal_ops;
53ec011fe8SChuck Lever 	const struct nfs4_mig_recovery_ops *mig_recovery_ops;
5497dc1359STrond Myklebust };
5597dc1359STrond Myklebust 
56cee54fc9STrond Myklebust #define NFS_SEQID_CONFIRMED 1
57cee54fc9STrond Myklebust struct nfs_seqid_counter {
5895b72eb0STrond Myklebust 	ktime_t create_time;
5948c22eb2STrond Myklebust 	int owner_id;
60cee54fc9STrond Myklebust 	int flags;
61cee54fc9STrond Myklebust 	u32 counter;
627ba127abSTrond Myklebust 	spinlock_t lock;		/* Protects the list */
637ba127abSTrond Myklebust 	struct list_head list;		/* Defines sequence of RPC calls */
647ba127abSTrond Myklebust 	struct rpc_wait_queue	wait;	/* RPC call delay queue */
65cee54fc9STrond Myklebust };
66cee54fc9STrond Myklebust 
67cee54fc9STrond Myklebust struct nfs_seqid {
68cee54fc9STrond Myklebust 	struct nfs_seqid_counter *sequence;
694e51336aSTrond Myklebust 	struct list_head list;
704601df20STrond Myklebust 	struct rpc_task *task;
71cee54fc9STrond Myklebust };
72cee54fc9STrond Myklebust 
73cee54fc9STrond Myklebust static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
74cee54fc9STrond Myklebust {
75cee54fc9STrond Myklebust 	if (seqid_mutating_err(-status))
76cee54fc9STrond Myklebust 		seqid->flags |= NFS_SEQID_CONFIRMED;
77cee54fc9STrond Myklebust }
78cee54fc9STrond Myklebust 
79cee54fc9STrond Myklebust /*
804ce79717STrond Myklebust  * NFS4 state_owners and lock_owners are simply labels for ordered
814ce79717STrond Myklebust  * sequences of RPC calls. Their sole purpose is to provide once-only
824ce79717STrond Myklebust  * semantics by allowing the server to identify replayed requests.
834ce79717STrond Myklebust  */
844ce79717STrond Myklebust struct nfs4_state_owner {
856f2e64d3STrond Myklebust 	struct nfs_server    *so_server;
860aaaf5c4SChuck Lever 	struct list_head     so_lru;
870aaaf5c4SChuck Lever 	unsigned long        so_expires;
8824d292b8SChuck Lever 	struct rb_node	     so_server_node;
894ce79717STrond Myklebust 
904ce79717STrond Myklebust 	struct rpc_cred	     *so_cred;	 /* Associated cred */
919f958ab8STrond Myklebust 
929f958ab8STrond Myklebust 	spinlock_t	     so_lock;
939f958ab8STrond Myklebust 	atomic_t	     so_count;
947eff03aeSTrond Myklebust 	unsigned long	     so_flags;
954ce79717STrond Myklebust 	struct list_head     so_states;
96cee54fc9STrond Myklebust 	struct nfs_seqid_counter so_seqid;
97c137afabSTrond Myklebust 	seqcount_t	     so_reclaim_seqcount;
9865b62a29STrond Myklebust 	struct mutex	     so_delegreturn_mutex;
994ce79717STrond Myklebust };
1004ce79717STrond Myklebust 
1017eff03aeSTrond Myklebust enum {
1027eff03aeSTrond Myklebust 	NFS_OWNER_RECLAIM_REBOOT,
1037eff03aeSTrond Myklebust 	NFS_OWNER_RECLAIM_NOGRACE
1047eff03aeSTrond Myklebust };
1057eff03aeSTrond Myklebust 
106afe6c27cSAlexandros Batsakis #define NFS_LOCK_NEW		0
107afe6c27cSAlexandros Batsakis #define NFS_LOCK_RECLAIM	1
108afe6c27cSAlexandros Batsakis #define NFS_LOCK_EXPIRED	2
109afe6c27cSAlexandros Batsakis 
1104ce79717STrond Myklebust /*
1114ce79717STrond Myklebust  * struct nfs4_state maintains the client-side state for a given
1124ce79717STrond Myklebust  * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
1134ce79717STrond Myklebust  *
1144ce79717STrond Myklebust  * OPEN:
1154ce79717STrond Myklebust  * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
1164ce79717STrond Myklebust  * we need to know how many files are open for reading or writing on a
1174ce79717STrond Myklebust  * given inode. This information too is stored here.
1184ce79717STrond Myklebust  *
1194ce79717STrond Myklebust  * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
1204ce79717STrond Myklebust  */
1214ce79717STrond Myklebust 
12277041ed9STrond Myklebust struct nfs4_lock_owner {
12377041ed9STrond Myklebust 	unsigned int lo_type;
12477041ed9STrond Myklebust #define NFS4_ANY_LOCK_TYPE	(0U)
12577041ed9STrond Myklebust #define NFS4_FLOCK_LOCK_TYPE	(1U << 0)
12677041ed9STrond Myklebust #define NFS4_POSIX_LOCK_TYPE	(1U << 1)
12777041ed9STrond Myklebust 	union {
12877041ed9STrond Myklebust 		fl_owner_t posix_owner;
12977041ed9STrond Myklebust 		pid_t flock_owner;
13077041ed9STrond Myklebust 	} lo_u;
13177041ed9STrond Myklebust };
13277041ed9STrond Myklebust 
1334ce79717STrond Myklebust struct nfs4_lock_state {
1344ce79717STrond Myklebust 	struct list_head	ls_locks;	/* Other lock stateids */
1358d0a8a9dSTrond Myklebust 	struct nfs4_state *	ls_state;	/* Pointer to open state */
136795a88c9STrond Myklebust #define NFS_LOCK_INITIALIZED 0
137ef1820f9SNeilBrown #define NFS_LOCK_LOST        1
138795a88c9STrond Myklebust 	unsigned long		ls_flags;
139cee54fc9STrond Myklebust 	struct nfs_seqid_counter	ls_seqid;
1404ce79717STrond Myklebust 	nfs4_stateid		ls_stateid;
1414ce79717STrond Myklebust 	atomic_t		ls_count;
14277041ed9STrond Myklebust 	struct nfs4_lock_owner	ls_owner;
1434ce79717STrond Myklebust };
1444ce79717STrond Myklebust 
1454ce79717STrond Myklebust /* bits for nfs4_state->flags */
1464ce79717STrond Myklebust enum {
1474ce79717STrond Myklebust 	LK_STATE_IN_USE,
148003707c7STrond Myklebust 	NFS_DELEGATED_STATE,		/* Current stateid is delegation */
14992b40e93STrond Myklebust 	NFS_OPEN_STATE,			/* OPEN stateid is set */
150003707c7STrond Myklebust 	NFS_O_RDONLY_STATE,		/* OPEN stateid has read-only state */
151003707c7STrond Myklebust 	NFS_O_WRONLY_STATE,		/* OPEN stateid has write-only state */
152003707c7STrond Myklebust 	NFS_O_RDWR_STATE,		/* OPEN stateid has read/write state */
153b79a4a1bSTrond Myklebust 	NFS_STATE_RECLAIM_REBOOT,	/* OPEN stateid server rebooted */
154b79a4a1bSTrond Myklebust 	NFS_STATE_RECLAIM_NOGRACE,	/* OPEN stateid needs to recover state */
1558e469ebdSTrond Myklebust 	NFS_STATE_POSIX_LOCKS,		/* Posix locks are supported */
1565d422301STrond Myklebust 	NFS_STATE_RECOVERY_FAILED,	/* OPEN stateid state recovery failed */
1574ce79717STrond Myklebust };
1584ce79717STrond Myklebust 
1594ce79717STrond Myklebust struct nfs4_state {
1604ce79717STrond Myklebust 	struct list_head open_states;	/* List of states for the same state_owner */
1614ce79717STrond Myklebust 	struct list_head inode_states;	/* List of states for the same inode */
1624ce79717STrond Myklebust 	struct list_head lock_states;	/* List of subservient lock stateids */
1634ce79717STrond Myklebust 
1644ce79717STrond Myklebust 	struct nfs4_state_owner *owner;	/* Pointer to the open owner */
1654ce79717STrond Myklebust 	struct inode *inode;		/* Pointer to the inode */
1664ce79717STrond Myklebust 
1674ce79717STrond Myklebust 	unsigned long flags;		/* Do we hold any locks? */
1688d0a8a9dSTrond Myklebust 	spinlock_t state_lock;		/* Protects the lock_states list */
1694ce79717STrond Myklebust 
1708bda4e4cSTrond Myklebust 	seqlock_t seqlock;		/* Protects the stateid/open_stateid */
171003707c7STrond Myklebust 	nfs4_stateid stateid;		/* Current stateid: may be delegation */
172003707c7STrond Myklebust 	nfs4_stateid open_stateid;	/* OPEN stateid */
1734ce79717STrond Myklebust 
1748bda4e4cSTrond Myklebust 	/* The following 3 fields are protected by owner->so_lock */
175003707c7STrond Myklebust 	unsigned int n_rdonly;		/* Number of read-only references */
176003707c7STrond Myklebust 	unsigned int n_wronly;		/* Number of write-only references */
177003707c7STrond Myklebust 	unsigned int n_rdwr;		/* Number of read/write references */
178dc0b027dSTrond Myklebust 	fmode_t state;			/* State on the server (R,W, or RW) */
1794ce79717STrond Myklebust 	atomic_t count;
1804ce79717STrond Myklebust };
1814ce79717STrond Myklebust 
1824ce79717STrond Myklebust 
1834ce79717STrond Myklebust struct nfs4_exception {
1844ce79717STrond Myklebust 	long timeout;
1854ce79717STrond Myklebust 	int retry;
1869e33bed5STrond Myklebust 	struct nfs4_state *state;
1873114ea7aSTrond Myklebust 	struct inode *inode;
1884ce79717STrond Myklebust };
1894ce79717STrond Myklebust 
1904ce79717STrond Myklebust struct nfs4_state_recovery_ops {
1917eff03aeSTrond Myklebust 	int owner_flag_bit;
192b79a4a1bSTrond Myklebust 	int state_flag_bit;
1934ce79717STrond Myklebust 	int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
1944ce79717STrond Myklebust 	int (*recover_lock)(struct nfs4_state *, struct file_lock *);
195591d71cbSAndy Adamson 	int (*establish_clid)(struct nfs_client *, struct rpc_cred *);
196965e9c23STrond Myklebust 	int (*reclaim_complete)(struct nfs_client *, struct rpc_cred *);
19705f4c350SChuck Lever 	int (*detect_trunking)(struct nfs_client *, struct nfs_client **,
19805f4c350SChuck Lever 		struct rpc_cred *);
1994ce79717STrond Myklebust };
2004ce79717STrond Myklebust 
20129fba38bSBenny Halevy struct nfs4_state_maintenance_ops {
2022f60ea6bSTrond Myklebust 	int (*sched_state_renewal)(struct nfs_client *, struct rpc_cred *, unsigned);
203a7b72103SAndy Adamson 	struct rpc_cred * (*get_state_renewal_cred_locked)(struct nfs_client *);
2048e69514fSBenny Halevy 	int (*renew_lease)(struct nfs_client *, struct rpc_cred *);
20529fba38bSBenny Halevy };
20629fba38bSBenny Halevy 
207ec011fe8SChuck Lever struct nfs4_mig_recovery_ops {
208b03d735bSChuck Lever 	int (*get_locations)(struct inode *, struct nfs4_fs_locations *,
209b03d735bSChuck Lever 		struct page *, struct rpc_cred *);
210ec011fe8SChuck Lever };
211ec011fe8SChuck Lever 
212f786aa90SAl Viro extern const struct dentry_operations nfs4_dentry_operations;
21373a79706SBryan Schumaker 
21473a79706SBryan Schumaker /* dir.c */
21573a79706SBryan Schumaker int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
21673a79706SBryan Schumaker 		    unsigned, umode_t, int *);
2176b3b5496SJ. Bruce Fields 
2181ae811eeSbjschuma@gmail.com /* super.c */
2191ae811eeSbjschuma@gmail.com extern struct file_system_type nfs4_fs_type;
2201ae811eeSbjschuma@gmail.com 
22172de53ecSBryan Schumaker /* nfs4namespace.c */
2222671bfc3SBryan Schumaker rpc_authflavor_t nfs_find_best_sec(struct nfs4_secinfo_flavors *);
22372de53ecSBryan Schumaker struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *, struct inode *, struct qstr *);
224281cad46SBryan Schumaker struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *,
225281cad46SBryan Schumaker 			       struct nfs_fh *, struct nfs_fattr *);
226800c06a5SChuck Lever int nfs4_replace_transport(struct nfs_server *server,
227800c06a5SChuck Lever 				const struct nfs4_fs_locations *locations);
22872de53ecSBryan Schumaker 
2294ce79717STrond Myklebust /* nfs4proc.c */
230bb8b27e5STrond Myklebust extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *);
231bb8b27e5STrond Myklebust extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *);
2325e6b1990STrond Myklebust extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
2332cf047c9STrond Myklebust extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, struct rpc_cred *cred);
2344d643d1dSAndy Adamson extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred);
23566245539STrond Myklebust extern int nfs4_destroy_clientid(struct nfs_client *clp);
236591d71cbSAndy Adamson extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
2374d643d1dSAndy Adamson extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
2381f7977c1STrond Myklebust extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait);
23955a97593STrond Myklebust extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
240f05d147fSBryan Schumaker extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
241f05d147fSBryan Schumaker 				  struct nfs4_fs_locations *, struct page *);
242b03d735bSChuck Lever extern int nfs4_proc_get_locations(struct inode *, struct nfs4_fs_locations *,
243b03d735bSChuck Lever 		struct page *page, struct rpc_cred *);
244f05d147fSBryan Schumaker extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, struct qstr *,
245f05d147fSBryan Schumaker 			    struct nfs_fh *, struct nfs_fattr *);
24672de53ecSBryan Schumaker extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
24764c2ce8bSAneesh Kumar K.V extern const struct xattr_handler *nfs4_xattr_handlers[];
2485521abfdSTrond Myklebust extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
2499b206149STrond Myklebust 		const struct nfs_open_context *ctx,
2509b206149STrond Myklebust 		const struct nfs_lock_context *l_ctx,
2519b206149STrond Myklebust 		fmode_t fmode);
2524ce79717STrond Myklebust 
253557134a3SAndy Adamson #if defined(CONFIG_NFS_V4_1)
254035168abSTrond Myklebust static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server)
255035168abSTrond Myklebust {
256035168abSTrond Myklebust 	return server->nfs_client->cl_session;
257035168abSTrond Myklebust }
258035168abSTrond Myklebust 
259dc70d7b3SAndy Adamson extern int nfs41_setup_sequence(struct nfs4_session *session,
260dc70d7b3SAndy Adamson 		struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
2619d12b216STrond Myklebust 		struct rpc_task *task);
262848f5bdaSTrond Myklebust extern int nfs4_proc_create_session(struct nfs_client *, struct rpc_cred *);
263848f5bdaSTrond Myklebust extern int nfs4_proc_destroy_session(struct nfs4_session *, struct rpc_cred *);
2649430fb6bSRicardo Labiaga extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
2659430fb6bSRicardo Labiaga 		struct nfs_fsinfo *fsinfo);
266863a3c6cSAndy Adamson extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
267ef311537SAndy Adamson 				  bool sync);
26894de8b27SAndy Adamson 
26994de8b27SAndy Adamson static inline bool
27094de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp)
27194de8b27SAndy Adamson {
27294de8b27SAndy Adamson 	return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) ==
27394de8b27SAndy Adamson 		EXCHGID4_FLAG_USE_PNFS_DS;
27494de8b27SAndy Adamson }
275d83217c1SAndy Adamson 
276d83217c1SAndy Adamson static inline bool
277d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp)
278d83217c1SAndy Adamson {
279d83217c1SAndy Adamson 	return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
280d83217c1SAndy Adamson }
281ab4c2361SWeston Andros Adamson 
2828c21c62cSWeston Andros Adamson static inline bool
2838c21c62cSWeston Andros Adamson _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
284ab4c2361SWeston Andros Adamson 		    struct rpc_clnt **clntp, struct rpc_message *msg)
285ab4c2361SWeston Andros Adamson {
286ab4c2361SWeston Andros Adamson 	struct rpc_cred *newcred = NULL;
287ab4c2361SWeston Andros Adamson 	rpc_authflavor_t flavor;
288ab4c2361SWeston Andros Adamson 
289ab4c2361SWeston Andros Adamson 	if (test_bit(sp4_mode, &clp->cl_sp4_flags)) {
290ab4c2361SWeston Andros Adamson 		spin_lock(&clp->cl_lock);
291ab4c2361SWeston Andros Adamson 		if (clp->cl_machine_cred != NULL)
292ade33ff5SWeston Andros Adamson 			/* don't call get_rpccred on the machine cred -
293ade33ff5SWeston Andros Adamson 			 * a reference will be held for life of clp */
294ade33ff5SWeston Andros Adamson 			newcred = clp->cl_machine_cred;
295ab4c2361SWeston Andros Adamson 		spin_unlock(&clp->cl_lock);
296ab4c2361SWeston Andros Adamson 		msg->rpc_cred = newcred;
297ab4c2361SWeston Andros Adamson 
298ab4c2361SWeston Andros Adamson 		flavor = clp->cl_rpcclient->cl_auth->au_flavor;
299312cd958SWeston Andros Adamson 		WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I &&
300ab4c2361SWeston Andros Adamson 			     flavor != RPC_AUTH_GSS_KRB5P);
301ab4c2361SWeston Andros Adamson 		*clntp = clp->cl_rpcclient;
3028c21c62cSWeston Andros Adamson 
3038c21c62cSWeston Andros Adamson 		return true;
304ab4c2361SWeston Andros Adamson 	}
3058c21c62cSWeston Andros Adamson 	return false;
3068c21c62cSWeston Andros Adamson }
3078c21c62cSWeston Andros Adamson 
3088c21c62cSWeston Andros Adamson /*
3098c21c62cSWeston Andros Adamson  * Function responsible for determining if an rpc_message should use the
3108c21c62cSWeston Andros Adamson  * machine cred under SP4_MACH_CRED and if so switching the credential and
3118c21c62cSWeston Andros Adamson  * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p).
3128c21c62cSWeston Andros Adamson  * Should be called before rpc_call_sync/rpc_call_async.
3138c21c62cSWeston Andros Adamson  */
3148c21c62cSWeston Andros Adamson static inline void
3158c21c62cSWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
3168c21c62cSWeston Andros Adamson 		   struct rpc_clnt **clntp, struct rpc_message *msg)
3178c21c62cSWeston Andros Adamson {
3188c21c62cSWeston Andros Adamson 	_nfs4_state_protect(clp, sp4_mode, clntp, msg);
3198c21c62cSWeston Andros Adamson }
3208c21c62cSWeston Andros Adamson 
3218c21c62cSWeston Andros Adamson /*
3228c21c62cSWeston Andros Adamson  * Special wrapper to nfs4_state_protect for write.
3238c21c62cSWeston Andros Adamson  * If WRITE can use machine cred but COMMIT cannot, make sure all writes
3248c21c62cSWeston Andros Adamson  * that use machine cred use NFS_FILE_SYNC.
3258c21c62cSWeston Andros Adamson  */
3268c21c62cSWeston Andros Adamson static inline void
3278c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
3288c21c62cSWeston Andros Adamson 			 struct rpc_message *msg, struct nfs_write_data *wdata)
3298c21c62cSWeston Andros Adamson {
3308c21c62cSWeston Andros Adamson 	if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) &&
3318c21c62cSWeston Andros Adamson 	    !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
3328c21c62cSWeston Andros Adamson 		wdata->args.stable = NFS_FILE_SYNC;
333ab4c2361SWeston Andros Adamson }
334fbcd4abcSAndy Adamson #else /* CONFIG_NFS_v4_1 */
335035168abSTrond Myklebust static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server)
336035168abSTrond Myklebust {
337035168abSTrond Myklebust 	return NULL;
338035168abSTrond Myklebust }
339035168abSTrond Myklebust 
34094de8b27SAndy Adamson static inline bool
34194de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp)
34294de8b27SAndy Adamson {
34394de8b27SAndy Adamson 	return false;
34494de8b27SAndy Adamson }
345d83217c1SAndy Adamson 
346d83217c1SAndy Adamson static inline bool
347d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp)
348d83217c1SAndy Adamson {
349d83217c1SAndy Adamson 	return false;
350d83217c1SAndy Adamson }
351ab4c2361SWeston Andros Adamson 
352ab4c2361SWeston Andros Adamson static inline void
353ab4c2361SWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags,
354ab4c2361SWeston Andros Adamson 		   struct rpc_clnt **clntp, struct rpc_message *msg)
355ab4c2361SWeston Andros Adamson {
356ab4c2361SWeston Andros Adamson }
3578c21c62cSWeston Andros Adamson 
3588c21c62cSWeston Andros Adamson static inline void
3598c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
3608c21c62cSWeston Andros Adamson 			 struct rpc_message *msg, struct nfs_write_data *wdata)
3618c21c62cSWeston Andros Adamson {
3628c21c62cSWeston Andros Adamson }
363557134a3SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
3644ce79717STrond Myklebust 
36597dc1359STrond Myklebust extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];
36629fba38bSBenny Halevy 
3671549210fSTrond Myklebust extern const u32 nfs4_fattr_bitmap[3];
368a09df2caSDavid Quigley extern const u32 nfs4_statfs_bitmap[3];
369a09df2caSDavid Quigley extern const u32 nfs4_pathconf_bitmap[3];
370dae100c2SFred Isaman extern const u32 nfs4_fsinfo_bitmap[3];
371a09df2caSDavid Quigley extern const u32 nfs4_fs_locations_bitmap[3];
3724ce79717STrond Myklebust 
373abf79bb3SChuck Lever void nfs40_shutdown_client(struct nfs_client *);
374abf79bb3SChuck Lever void nfs41_shutdown_client(struct nfs_client *);
375abf79bb3SChuck Lever int nfs40_init_client(struct nfs_client *);
376abf79bb3SChuck Lever int nfs41_init_client(struct nfs_client *);
377cdb7ecedSBryan Schumaker void nfs4_free_client(struct nfs_client *);
378cdb7ecedSBryan Schumaker 
3796663ee7fSBryan Schumaker struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *);
3806663ee7fSBryan Schumaker 
3814ce79717STrond Myklebust /* nfs4renewd.c */
382adfa6f98SDavid Howells extern void nfs4_schedule_state_renewal(struct nfs_client *);
3834ce79717STrond Myklebust extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
384adfa6f98SDavid Howells extern void nfs4_kill_renewd(struct nfs_client *);
38565f27f38SDavid Howells extern void nfs4_renew_state(struct work_struct *);
3864ce79717STrond Myklebust 
3874ce79717STrond Myklebust /* nfs4state.c */
38873d8bde5SChuck Lever struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp);
389fe20d7d5STrond Myklebust struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp);
3906dc9d57aSTrond Myklebust struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp);
39105f4c350SChuck Lever int nfs4_discover_server_trunking(struct nfs_client *clp,
39205f4c350SChuck Lever 			struct nfs_client **);
39305f4c350SChuck Lever int nfs40_discover_server_trunking(struct nfs_client *clp,
39405f4c350SChuck Lever 			struct nfs_client **, struct rpc_cred *);
395a7b72103SAndy Adamson #if defined(CONFIG_NFS_V4_1)
39605f4c350SChuck Lever int nfs41_discover_server_trunking(struct nfs_client *clp,
39705f4c350SChuck Lever 			struct nfs_client **, struct rpc_cred *);
3989f594791STrond Myklebust extern void nfs4_schedule_session_recovery(struct nfs4_session *, int);
399ac074835STrond Myklebust extern void nfs41_server_notify_target_slotid_update(struct nfs_client *clp);
400c10e4498STrond Myklebust extern void nfs41_server_notify_highest_slotid_update(struct nfs_client *clp);
4015d63360dSTrond Myklebust 
4020400a6b0STrond Myklebust #else
4039f594791STrond Myklebust static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err)
4040400a6b0STrond Myklebust {
4050400a6b0STrond Myklebust }
406a7b72103SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4074ce79717STrond Myklebust 
408d1e284d5STrond Myklebust extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *, gfp_t);
4094ce79717STrond Myklebust extern void nfs4_put_state_owner(struct nfs4_state_owner *);
4100aaaf5c4SChuck Lever extern void nfs4_purge_state_owners(struct nfs_server *);
4114ce79717STrond Myklebust extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
4124ce79717STrond Myklebust extern void nfs4_put_open_state(struct nfs4_state *);
413643168c2SAl Viro extern void nfs4_close_state(struct nfs4_state *, fmode_t);
414643168c2SAl Viro extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
415dc0b027dSTrond Myklebust extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
416a1d0b5eeSTrond Myklebust extern void nfs_inode_find_state_and_recover(struct inode *inode,
417a1d0b5eeSTrond Myklebust 		const nfs4_stateid *stateid);
4180400a6b0STrond Myklebust extern void nfs4_schedule_lease_recovery(struct nfs_client *);
41933021279STrond Myklebust extern int nfs4_wait_clnt_recover(struct nfs_client *clp);
42033021279STrond Myklebust extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
421b0d3ded1STrond Myklebust extern void nfs4_schedule_state_manager(struct nfs_client *);
422042b60beSTrond Myklebust extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
4235d422301STrond Myklebust extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
4240629e370SAlexandros Batsakis extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
42578fe0f41SWeston Andros Adamson extern void nfs41_handle_server_scope(struct nfs_client *,
42679d4e1f0SChuck Lever 				      struct nfs41_server_scope **);
427faf5f49cSTrond Myklebust extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
4288d0a8a9dSTrond Myklebust extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
4295521abfdSTrond Myklebust extern int nfs4_select_rw_stateid(nfs4_stateid *, struct nfs4_state *,
4302a369153STrond Myklebust 		fmode_t, const struct nfs_lockowner *);
4314ce79717STrond Myklebust 
4328535b2beSTrond Myklebust extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
433cee54fc9STrond Myklebust extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
434cee54fc9STrond Myklebust extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
435cee54fc9STrond Myklebust extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
43672211dbeSTrond Myklebust extern void nfs_release_seqid(struct nfs_seqid *seqid);
437cee54fc9STrond Myklebust extern void nfs_free_seqid(struct nfs_seqid *seqid);
438cee54fc9STrond Myklebust 
4395ae67c4fSTrond Myklebust extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
440cf470c3eSTrond Myklebust 
4414ce79717STrond Myklebust extern const nfs4_stateid zero_stateid;
4424ce79717STrond Myklebust 
443129d1977SBryan Schumaker /* nfs4super.c */
444fbdefd64SBryan Schumaker struct nfs_mount_info;
445ab7017a3SBryan Schumaker extern struct nfs_subversion nfs_v4;
446ff9099f2SBryan Schumaker struct dentry *nfs4_try_mount(int, const char *, struct nfs_mount_info *, struct nfs_subversion *);
447fac1e8e4SBryan Schumaker extern bool nfs4_disable_idmapping;
448fac1e8e4SBryan Schumaker extern unsigned short max_session_slots;
449fac1e8e4SBryan Schumaker extern unsigned short send_implementation_id;
450f6de7a39STrond Myklebust extern bool recover_lost_locks;
45189d77c8fSBryan Schumaker 
4526f2ea7f2SChuck Lever #define NFS4_CLIENT_ID_UNIQ_LEN		(64)
4536f2ea7f2SChuck Lever extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
4546f2ea7f2SChuck Lever 
455466bfe7fSBryan Schumaker /* nfs4sysctl.c */
456466bfe7fSBryan Schumaker #ifdef CONFIG_SYSCTL
457466bfe7fSBryan Schumaker int nfs4_register_sysctl(void);
458466bfe7fSBryan Schumaker void nfs4_unregister_sysctl(void);
459466bfe7fSBryan Schumaker #else
460466bfe7fSBryan Schumaker static inline int nfs4_register_sysctl(void)
461466bfe7fSBryan Schumaker {
462466bfe7fSBryan Schumaker 	return 0;
463466bfe7fSBryan Schumaker }
464466bfe7fSBryan Schumaker 
4650add3e85SRandy Dunlap static inline void nfs4_unregister_sysctl(void)
466466bfe7fSBryan Schumaker {
467466bfe7fSBryan Schumaker }
468466bfe7fSBryan Schumaker #endif
469466bfe7fSBryan Schumaker 
4704ce79717STrond Myklebust /* nfs4xdr.c */
4714ce79717STrond Myklebust extern struct rpc_procinfo nfs4_procedures[];
4724ce79717STrond Myklebust 
4734ce79717STrond Myklebust struct nfs4_mount_data;
4744ce79717STrond Myklebust 
4754ce79717STrond Myklebust /* callback_xdr.c */
4764ce79717STrond Myklebust extern struct svc_version nfs4_callback_version1;
47707bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4;
4784ce79717STrond Myklebust 
479f597c537STrond Myklebust static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
480f597c537STrond Myklebust {
4812d2f24adSTrond Myklebust 	memcpy(dst, src, sizeof(*dst));
482f597c537STrond Myklebust }
483f597c537STrond Myklebust 
484f597c537STrond Myklebust static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
485f597c537STrond Myklebust {
4862d2f24adSTrond Myklebust 	return memcmp(dst, src, sizeof(*dst)) == 0;
487f597c537STrond Myklebust }
488f597c537STrond Myklebust 
4895d422301STrond Myklebust static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
4905d422301STrond Myklebust {
4915d422301STrond Myklebust 	return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0;
4925d422301STrond Myklebust }
4935d422301STrond Myklebust 
4944ce79717STrond Myklebust #else
4954ce79717STrond Myklebust 
496643168c2SAl Viro #define nfs4_close_state(a, b) do { } while (0)
497643168c2SAl Viro #define nfs4_close_sync(a, b) do { } while (0)
4988c21c62cSWeston Andros Adamson #define nfs4_state_protect(a, b, c, d) do { } while (0)
4998c21c62cSWeston Andros Adamson #define nfs4_state_protect_write(a, b, c, d) do { } while (0)
5004ce79717STrond Myklebust 
5014ce79717STrond Myklebust #endif /* CONFIG_NFS_V4 */
5024ce79717STrond Myklebust #endif /* __LINUX_FS_NFS_NFS4_FS.H */
503