xref: /openbmc/linux/fs/nfs/nfs4_fs.h (revision ed5f17f6)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
24ce79717STrond Myklebust /*
34ce79717STrond Myklebust  * linux/fs/nfs/nfs4_fs.h
44ce79717STrond Myklebust  *
54ce79717STrond Myklebust  * Copyright (C) 2005 Trond Myklebust
64ce79717STrond Myklebust  *
74ce79717STrond Myklebust  * NFSv4-specific filesystem definitions and declarations
84ce79717STrond Myklebust  */
94ce79717STrond Myklebust 
104ce79717STrond Myklebust #ifndef __LINUX_FS_NFS_NFS4_FS_H
114ce79717STrond Myklebust #define __LINUX_FS_NFS_NFS4_FS_H
124ce79717STrond Myklebust 
13694e096fSAnna Schumaker #if defined(CONFIG_NFS_V4_2)
14694e096fSAnna Schumaker #define NFS4_MAX_MINOR_VERSION 2
15694e096fSAnna Schumaker #elif defined(CONFIG_NFS_V4_1)
16694e096fSAnna Schumaker #define NFS4_MAX_MINOR_VERSION 1
17694e096fSAnna Schumaker #else
18694e096fSAnna Schumaker #define NFS4_MAX_MINOR_VERSION 0
19694e096fSAnna Schumaker #endif
20694e096fSAnna Schumaker 
2189d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
224ce79717STrond Myklebust 
2333021279STrond Myklebust #define NFS4_MAX_LOOP_ON_RECOVER (10)
2433021279STrond Myklebust 
25c137afabSTrond Myklebust #include <linux/seqlock.h>
265970e15dSJeff Layton #include <linux/filelock.h>
27c137afabSTrond Myklebust 
284ce79717STrond Myklebust struct idmap;
294ce79717STrond Myklebust 
304ce79717STrond Myklebust enum nfs4_client_state {
31e005e804STrond Myklebust 	NFS4CLNT_MANAGER_RUNNING  = 0,
32e598d843STrond Myklebust 	NFS4CLNT_CHECK_LEASE,
3358d9714aSTrond Myklebust 	NFS4CLNT_LEASE_EXPIRED,
34b79a4a1bSTrond Myklebust 	NFS4CLNT_RECLAIM_REBOOT,
35b79a4a1bSTrond Myklebust 	NFS4CLNT_RECLAIM_NOGRACE,
36707fb4b3STrond Myklebust 	NFS4CLNT_DELEGRETURN,
376df08189SAndy Adamson 	NFS4CLNT_SESSION_RESET,
38fd954ae1STrond Myklebust 	NFS4CLNT_LEASE_CONFIRM,
3978fe0f41SWeston Andros Adamson 	NFS4CLNT_SERVER_SCOPE_MISMATCH,
402c820d9aSChuck Lever 	NFS4CLNT_PURGE_STATE,
41a9e64442SWeston Andros Adamson 	NFS4CLNT_BIND_CONN_TO_SESSION,
42c9fdeb28SChuck Lever 	NFS4CLNT_MOVED,
43b7f7a66eSChuck Lever 	NFS4CLNT_LEASE_MOVED,
4445870d69STrond Myklebust 	NFS4CLNT_DELEGATION_EXPIRED,
45aeabb3c9STrond Myklebust 	NFS4CLNT_RUN_MANAGER,
464dc73c67SNeilBrown 	NFS4CLNT_MANAGER_AVAILABLE,
47b5fdf841STrond Myklebust 	NFS4CLNT_RECALL_RUNNING,
48b5fdf841STrond Myklebust 	NFS4CLNT_RECALL_ANY_LAYOUT_READ,
49b5fdf841STrond Myklebust 	NFS4CLNT_RECALL_ANY_LAYOUT_RW,
50be200377STrond Myklebust 	NFS4CLNT_DELEGRETURN_DELAYED,
514ce79717STrond Myklebust };
524ce79717STrond Myklebust 
532f60ea6bSTrond Myklebust #define NFS4_RENEW_TIMEOUT		0x01
542f60ea6bSTrond Myklebust #define NFS4_RENEW_DELEGATION_CB	0x02
552f60ea6bSTrond Myklebust 
5663f5f796STrond Myklebust struct nfs_seqid_counter;
5797dc1359STrond Myklebust struct nfs4_minor_version_ops {
5897dc1359STrond Myklebust 	u32	minor_version;
5939c6daaeSTrond Myklebust 	unsigned init_caps;
6097dc1359STrond Myklebust 
61abf79bb3SChuck Lever 	int	(*init_client)(struct nfs_client *);
62abf79bb3SChuck Lever 	void	(*shutdown_client)(struct nfs_client *);
6336281caaSTrond Myklebust 	bool	(*match_stateid)(const nfs4_stateid *,
64e047a10cSTrond Myklebust 			const nfs4_stateid *);
65fca78d6dSBryan Schumaker 	int	(*find_root_sec)(struct nfs_server *, struct nfs_fh *,
66fca78d6dSBryan Schumaker 			struct nfs_fsinfo *);
67f1cdae87SJeff Layton 	void	(*free_lock_state)(struct nfs_server *,
68c8b2d0bfSTrond Myklebust 			struct nfs4_lock_state *);
6945870d69STrond Myklebust 	int	(*test_and_free_expired)(struct nfs_server *,
70a52458b4SNeilBrown 			nfs4_stateid *, const struct cred *);
7163f5f796STrond Myklebust 	struct nfs_seqid *
7263f5f796STrond Myklebust 		(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
7310e037d1SSantosh kumar pradhan 	void	(*session_trunk)(struct rpc_clnt *clnt,
7410e037d1SSantosh kumar pradhan 			struct rpc_xprt *xprt, void *data);
759915ea7eSChuck Lever 	const struct rpc_call_ops *call_sync_ops;
76c48f4f35STrond Myklebust 	const struct nfs4_state_recovery_ops *reboot_recovery_ops;
77c48f4f35STrond Myklebust 	const struct nfs4_state_recovery_ops *nograce_recovery_ops;
78c48f4f35STrond Myklebust 	const struct nfs4_state_maintenance_ops *state_renewal_ops;
79ec011fe8SChuck Lever 	const struct nfs4_mig_recovery_ops *mig_recovery_ops;
8097dc1359STrond Myklebust };
8197dc1359STrond Myklebust 
82cee54fc9STrond Myklebust #define NFS_SEQID_CONFIRMED 1
83cee54fc9STrond Myklebust struct nfs_seqid_counter {
8495b72eb0STrond Myklebust 	ktime_t create_time;
8548c22eb2STrond Myklebust 	int owner_id;
86cee54fc9STrond Myklebust 	int flags;
87cee54fc9STrond Myklebust 	u32 counter;
887ba127abSTrond Myklebust 	spinlock_t lock;		/* Protects the list */
897ba127abSTrond Myklebust 	struct list_head list;		/* Defines sequence of RPC calls */
907ba127abSTrond Myklebust 	struct rpc_wait_queue	wait;	/* RPC call delay queue */
91cee54fc9STrond Myklebust };
92cee54fc9STrond Myklebust 
93cee54fc9STrond Myklebust struct nfs_seqid {
94cee54fc9STrond Myklebust 	struct nfs_seqid_counter *sequence;
954e51336aSTrond Myklebust 	struct list_head list;
964601df20STrond Myklebust 	struct rpc_task *task;
97cee54fc9STrond Myklebust };
98cee54fc9STrond Myklebust 
nfs_confirm_seqid(struct nfs_seqid_counter * seqid,int status)99cee54fc9STrond Myklebust static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
100cee54fc9STrond Myklebust {
101cee54fc9STrond Myklebust 	if (seqid_mutating_err(-status))
102cee54fc9STrond Myklebust 		seqid->flags |= NFS_SEQID_CONFIRMED;
103cee54fc9STrond Myklebust }
104cee54fc9STrond Myklebust 
105cee54fc9STrond Myklebust /*
1064ce79717STrond Myklebust  * NFS4 state_owners and lock_owners are simply labels for ordered
1074ce79717STrond Myklebust  * sequences of RPC calls. Their sole purpose is to provide once-only
1084ce79717STrond Myklebust  * semantics by allowing the server to identify replayed requests.
1094ce79717STrond Myklebust  */
1104ce79717STrond Myklebust struct nfs4_state_owner {
1116f2e64d3STrond Myklebust 	struct nfs_server    *so_server;
1120aaaf5c4SChuck Lever 	struct list_head     so_lru;
1130aaaf5c4SChuck Lever 	unsigned long        so_expires;
11424d292b8SChuck Lever 	struct rb_node	     so_server_node;
1154ce79717STrond Myklebust 
116a52458b4SNeilBrown 	const struct cred    *so_cred;	 /* Associated cred */
1179f958ab8STrond Myklebust 
1189f958ab8STrond Myklebust 	spinlock_t	     so_lock;
1199f958ab8STrond Myklebust 	atomic_t	     so_count;
1207eff03aeSTrond Myklebust 	unsigned long	     so_flags;
1214ce79717STrond Myklebust 	struct list_head     so_states;
122cee54fc9STrond Myklebust 	struct nfs_seqid_counter so_seqid;
12376246c92SAhmed S. Darwish 	seqcount_spinlock_t  so_reclaim_seqcount;
12465b62a29STrond Myklebust 	struct mutex	     so_delegreturn_mutex;
1254ce79717STrond Myklebust };
1264ce79717STrond Myklebust 
1277eff03aeSTrond Myklebust enum {
1287eff03aeSTrond Myklebust 	NFS_OWNER_RECLAIM_REBOOT,
1297eff03aeSTrond Myklebust 	NFS_OWNER_RECLAIM_NOGRACE
1307eff03aeSTrond Myklebust };
1317eff03aeSTrond Myklebust 
132afe6c27cSAlexandros Batsakis #define NFS_LOCK_NEW		0
133afe6c27cSAlexandros Batsakis #define NFS_LOCK_RECLAIM	1
134afe6c27cSAlexandros Batsakis #define NFS_LOCK_EXPIRED	2
135afe6c27cSAlexandros Batsakis 
1364ce79717STrond Myklebust /*
1374ce79717STrond Myklebust  * struct nfs4_state maintains the client-side state for a given
1384ce79717STrond Myklebust  * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
1394ce79717STrond Myklebust  *
1404ce79717STrond Myklebust  * OPEN:
1414ce79717STrond Myklebust  * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
1424ce79717STrond Myklebust  * we need to know how many files are open for reading or writing on a
1434ce79717STrond Myklebust  * given inode. This information too is stored here.
1444ce79717STrond Myklebust  *
1454ce79717STrond Myklebust  * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
1464ce79717STrond Myklebust  */
1474ce79717STrond Myklebust 
1484ce79717STrond Myklebust struct nfs4_lock_state {
1494ce79717STrond Myklebust 	struct list_head	ls_locks;	/* Other lock stateids */
1508d0a8a9dSTrond Myklebust 	struct nfs4_state *	ls_state;	/* Pointer to open state */
151795a88c9STrond Myklebust #define NFS_LOCK_INITIALIZED 0
152ef1820f9SNeilBrown #define NFS_LOCK_LOST        1
153ef8d98f2SNeilBrown #define NFS_LOCK_UNLOCKING   2
154795a88c9STrond Myklebust 	unsigned long		ls_flags;
155cee54fc9STrond Myklebust 	struct nfs_seqid_counter	ls_seqid;
1564ce79717STrond Myklebust 	nfs4_stateid		ls_stateid;
157194bc1f4SElena Reshetova 	refcount_t		ls_count;
1588003d3c4SJeff Layton 	fl_owner_t		ls_owner;
1594ce79717STrond Myklebust };
1604ce79717STrond Myklebust 
1614ce79717STrond Myklebust /* bits for nfs4_state->flags */
1624ce79717STrond Myklebust enum {
1634ce79717STrond Myklebust 	LK_STATE_IN_USE,
164003707c7STrond Myklebust 	NFS_DELEGATED_STATE,		/* Current stateid is delegation */
16592b40e93STrond Myklebust 	NFS_OPEN_STATE,			/* OPEN stateid is set */
166003707c7STrond Myklebust 	NFS_O_RDONLY_STATE,		/* OPEN stateid has read-only state */
167003707c7STrond Myklebust 	NFS_O_WRONLY_STATE,		/* OPEN stateid has write-only state */
168003707c7STrond Myklebust 	NFS_O_RDWR_STATE,		/* OPEN stateid has read/write state */
169b79a4a1bSTrond Myklebust 	NFS_STATE_RECLAIM_REBOOT,	/* OPEN stateid server rebooted */
170b79a4a1bSTrond Myklebust 	NFS_STATE_RECLAIM_NOGRACE,	/* OPEN stateid needs to recover state */
1718e469ebdSTrond Myklebust 	NFS_STATE_POSIX_LOCKS,		/* Posix locks are supported */
1725d422301STrond Myklebust 	NFS_STATE_RECOVERY_FAILED,	/* OPEN stateid state recovery failed */
173a8ce377aSJeff Layton 	NFS_STATE_MAY_NOTIFY_LOCK,	/* server may CB_NOTIFY_LOCK */
174c9399f21STrond Myklebust 	NFS_STATE_CHANGE_WAIT,		/* A state changing operation is outstanding */
175e4648aa4SOlga Kornievskaia 	NFS_CLNT_DST_SSC_COPY_STATE,    /* dst server open state on client*/
1760e65a32cSOlga Kornievskaia 	NFS_CLNT_SRC_SSC_COPY_STATE,    /* src server open state on client*/
1770b9018b9SOlga Kornievskaia 	NFS_SRV_SSC_COPY_STATE,		/* ssc state on the dst server */
1784ce79717STrond Myklebust };
1794ce79717STrond Myklebust 
1804ce79717STrond Myklebust struct nfs4_state {
1814ce79717STrond Myklebust 	struct list_head open_states;	/* List of states for the same state_owner */
1824ce79717STrond Myklebust 	struct list_head inode_states;	/* List of states for the same inode */
1834ce79717STrond Myklebust 	struct list_head lock_states;	/* List of subservient lock stateids */
1844ce79717STrond Myklebust 
1854ce79717STrond Myklebust 	struct nfs4_state_owner *owner;	/* Pointer to the open owner */
1864ce79717STrond Myklebust 	struct inode *inode;		/* Pointer to the inode */
1874ce79717STrond Myklebust 
1884ce79717STrond Myklebust 	unsigned long flags;		/* Do we hold any locks? */
1898d0a8a9dSTrond Myklebust 	spinlock_t state_lock;		/* Protects the lock_states list */
1904ce79717STrond Myklebust 
1918bda4e4cSTrond Myklebust 	seqlock_t seqlock;		/* Protects the stateid/open_stateid */
192003707c7STrond Myklebust 	nfs4_stateid stateid;		/* Current stateid: may be delegation */
193003707c7STrond Myklebust 	nfs4_stateid open_stateid;	/* OPEN stateid */
1944ce79717STrond Myklebust 
1958bda4e4cSTrond Myklebust 	/* The following 3 fields are protected by owner->so_lock */
196003707c7STrond Myklebust 	unsigned int n_rdonly;		/* Number of read-only references */
197003707c7STrond Myklebust 	unsigned int n_wronly;		/* Number of write-only references */
198003707c7STrond Myklebust 	unsigned int n_rdwr;		/* Number of read/write references */
199dc0b027dSTrond Myklebust 	fmode_t state;			/* State on the server (R,W, or RW) */
200ace9fad4STrond Myklebust 	refcount_t count;
201c9399f21STrond Myklebust 
202c9399f21STrond Myklebust 	wait_queue_head_t waitq;
2039ae075fdSTrond Myklebust 	struct rcu_head rcu_head;
2044ce79717STrond Myklebust };
2054ce79717STrond Myklebust 
2064ce79717STrond Myklebust 
2074ce79717STrond Myklebust struct nfs4_exception {
2089e33bed5STrond Myklebust 	struct nfs4_state *state;
2093114ea7aSTrond Myklebust 	struct inode *inode;
2108487c479STrond Myklebust 	nfs4_stateid *stateid;
211b3c2aa07STrond Myklebust 	long timeout;
212dfe1fe75STrond Myklebust 	unsigned char task_is_privileged : 1;
213b3c2aa07STrond Myklebust 	unsigned char delay : 1,
214b3c2aa07STrond Myklebust 		      recovering : 1,
215b3c2aa07STrond Myklebust 		      retry : 1;
2160688e64bSTrond Myklebust 	bool interruptible;
2174ce79717STrond Myklebust };
2184ce79717STrond Myklebust 
2194ce79717STrond Myklebust struct nfs4_state_recovery_ops {
2207eff03aeSTrond Myklebust 	int owner_flag_bit;
221b79a4a1bSTrond Myklebust 	int state_flag_bit;
2224ce79717STrond Myklebust 	int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
2234ce79717STrond Myklebust 	int (*recover_lock)(struct nfs4_state *, struct file_lock *);
224a52458b4SNeilBrown 	int (*establish_clid)(struct nfs_client *, const struct cred *);
225a52458b4SNeilBrown 	int (*reclaim_complete)(struct nfs_client *, const struct cred *);
22605f4c350SChuck Lever 	int (*detect_trunking)(struct nfs_client *, struct nfs_client **,
227a52458b4SNeilBrown 		const struct cred *);
2284ce79717STrond Myklebust };
2294ce79717STrond Myklebust 
2301b146fcfSFred Isaman struct nfs4_opendata {
2311b146fcfSFred Isaman 	struct kref kref;
2321b146fcfSFred Isaman 	struct nfs_openargs o_arg;
2331b146fcfSFred Isaman 	struct nfs_openres o_res;
2341b146fcfSFred Isaman 	struct nfs_open_confirmargs c_arg;
2351b146fcfSFred Isaman 	struct nfs_open_confirmres c_res;
2361b146fcfSFred Isaman 	struct nfs4_string owner_name;
2371b146fcfSFred Isaman 	struct nfs4_string group_name;
2381b146fcfSFred Isaman 	struct nfs4_label *a_label;
2391b146fcfSFred Isaman 	struct nfs_fattr f_attr;
2401b146fcfSFred Isaman 	struct dentry *dir;
2411b146fcfSFred Isaman 	struct dentry *dentry;
2421b146fcfSFred Isaman 	struct nfs4_state_owner *owner;
2431b146fcfSFred Isaman 	struct nfs4_state *state;
2441b146fcfSFred Isaman 	struct iattr attrs;
2451b146fcfSFred Isaman 	struct nfs4_layoutget *lgp;
2461b146fcfSFred Isaman 	unsigned long timestamp;
2471b146fcfSFred Isaman 	bool rpc_done;
2481b146fcfSFred Isaman 	bool file_created;
2491b146fcfSFred Isaman 	bool is_recover;
2501b146fcfSFred Isaman 	bool cancelled;
2511b146fcfSFred Isaman 	int rpc_status;
2521b146fcfSFred Isaman };
2531b146fcfSFred Isaman 
25404fa2c6bSAndy Adamson struct nfs4_add_xprt_data {
25504fa2c6bSAndy Adamson 	struct nfs_client	*clp;
256a52458b4SNeilBrown 	const struct cred	*cred;
25704fa2c6bSAndy Adamson };
25804fa2c6bSAndy Adamson 
25929fba38bSBenny Halevy struct nfs4_state_maintenance_ops {
260a52458b4SNeilBrown 	int (*sched_state_renewal)(struct nfs_client *, const struct cred *, unsigned);
261a52458b4SNeilBrown 	const struct cred * (*get_state_renewal_cred)(struct nfs_client *);
262a52458b4SNeilBrown 	int (*renew_lease)(struct nfs_client *, const struct cred *);
26329fba38bSBenny Halevy };
26429fba38bSBenny Halevy 
265ec011fe8SChuck Lever struct nfs4_mig_recovery_ops {
2661976b2b3SOlga Kornievskaia 	int (*get_locations)(struct nfs_server *, struct nfs_fh *,
2671976b2b3SOlga Kornievskaia 		struct nfs4_fs_locations *, struct page *, const struct cred *);
268a52458b4SNeilBrown 	int (*fsid_present)(struct inode *, const struct cred *);
269ec011fe8SChuck Lever };
270ec011fe8SChuck Lever 
271f786aa90SAl Viro extern const struct dentry_operations nfs4_dentry_operations;
27273a79706SBryan Schumaker 
27373a79706SBryan Schumaker /* dir.c */
27473a79706SBryan Schumaker int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
27544907d79SAl Viro 		    unsigned, umode_t);
2766b3b5496SJ. Bruce Fields 
277f2aedb71SDavid Howells /* fs_context.c */
2781ae811eeSbjschuma@gmail.com extern struct file_system_type nfs4_fs_type;
2791ae811eeSbjschuma@gmail.com 
28072de53ecSBryan Schumaker /* nfs4namespace.c */
281beffb8feSAl Viro struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *,
282beffb8feSAl Viro 					 const struct qstr *);
283f2aedb71SDavid Howells int nfs4_submount(struct fs_context *, struct nfs_server *);
284800c06a5SChuck Lever int nfs4_replace_transport(struct nfs_server *server,
285800c06a5SChuck Lever 				const struct nfs4_fs_locations *locations);
286cf0d7e7fSKees Cook size_t nfs_parse_server_name(char *string, size_t len, struct sockaddr_storage *ss,
287a8d54babSOlga Kornievskaia 			     size_t salen, struct net *net, int port);
2884ce79717STrond Myklebust /* nfs4proc.c */
289f4ac1674SAnna Schumaker extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *);
2900f913a57SOlga Kornievskaia extern int nfs4_async_handle_error(struct rpc_task *task,
2910f913a57SOlga Kornievskaia 				   struct nfs_server *server,
2920f913a57SOlga Kornievskaia 				   struct nfs4_state *state, long *timeout);
2931c6dcbe5SAnna Schumaker extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
2941c6dcbe5SAnna Schumaker 			  struct rpc_message *, struct nfs4_sequence_args *,
2951c6dcbe5SAnna Schumaker 			  struct nfs4_sequence_res *, int);
296fba83f34SAnna Schumaker extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int);
297a52458b4SNeilBrown extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
298a52458b4SNeilBrown extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *);
2995e6b1990STrond Myklebust extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
300a52458b4SNeilBrown extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
301a52458b4SNeilBrown extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
30266245539STrond Myklebust extern int nfs4_destroy_clientid(struct nfs_client *clp);
303a52458b4SNeilBrown extern int nfs4_init_clientid(struct nfs_client *, const struct cred *);
304a52458b4SNeilBrown extern int nfs41_init_clientid(struct nfs_client *, const struct cred *);
3051f7977c1STrond Myklebust extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait);
30655a97593STrond Myklebust extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
307f05d147fSBryan Schumaker extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
308f05d147fSBryan Schumaker 				  struct nfs4_fs_locations *, struct page *);
3091976b2b3SOlga Kornievskaia extern int nfs4_proc_get_locations(struct nfs_server *, struct nfs_fh *,
3101976b2b3SOlga Kornievskaia 				   struct nfs4_fs_locations *,
311a52458b4SNeilBrown 				   struct page *page, const struct cred *);
312a52458b4SNeilBrown extern int nfs4_proc_fsid_present(struct inode *, const struct cred *);
313f7b37b8bSTrond Myklebust extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *,
314f7b37b8bSTrond Myklebust 						    struct dentry *,
315f7b37b8bSTrond Myklebust 						    struct nfs_fh *,
316f7b37b8bSTrond Myklebust 						    struct nfs_fattr *);
31772de53ecSBryan Schumaker extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
31864c2ce8bSAneesh Kumar K.V extern const struct xattr_handler *nfs4_xattr_handlers[];
3195521abfdSTrond Myklebust extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
3209b206149STrond Myklebust 		const struct nfs_open_context *ctx,
3219b206149STrond Myklebust 		const struct nfs_lock_context *l_ctx,
3229b206149STrond Myklebust 		fmode_t fmode);
32385847280STrond Myklebust extern void nfs4_bitmask_set(__u32 bitmask[], const __u32 src[],
32485847280STrond Myklebust 			     struct inode *inode, unsigned long cache_validity);
325ec4b0925SOlga Kornievskaia extern int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
3262ef61e0eSAnna Schumaker 			     struct nfs_fattr *fattr, struct inode *inode);
327ec4b0925SOlga Kornievskaia extern int update_open_stateid(struct nfs4_state *state,
328ec4b0925SOlga Kornievskaia 				const nfs4_stateid *open_stateid,
329ec4b0925SOlga Kornievskaia 				const nfs4_stateid *deleg_stateid,
330ec4b0925SOlga Kornievskaia 				fmode_t fmode);
331*ed5f17f6SLuca Vizzarro extern int nfs4_proc_setlease(struct file *file, int arg,
332e93a5e93STrond Myklebust 			      struct file_lock **lease, void **priv);
3330efb01b2SDonald Buczek extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
3340efb01b2SDonald Buczek 		struct nfs_fsinfo *fsinfo);
3351b523ca9SFrank van der Linden extern void nfs4_update_changeattr(struct inode *dir,
3361b523ca9SFrank van der Linden 				   struct nfs4_change_info *cinfo,
3371b523ca9SFrank van der Linden 				   unsigned long timestamp,
3381b523ca9SFrank van der Linden 				   unsigned long cache_validity);
339ccde1e9cSFrank van der Linden extern int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen,
340ccde1e9cSFrank van der Linden 				    struct page **pages);
3411b523ca9SFrank van der Linden 
342557134a3SAndy Adamson #if defined(CONFIG_NFS_V4_1)
343f9c96fccSAndy Adamson extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *);
344a52458b4SNeilBrown extern int nfs4_proc_create_session(struct nfs_client *, const struct cred *);
345a52458b4SNeilBrown extern int nfs4_proc_destroy_session(struct nfs4_session *, const struct cred *);
346863a3c6cSAndy Adamson extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
347ef311537SAndy Adamson 				  bool sync);
348ba84db96SAndy Adamson extern int nfs4_detect_session_trunking(struct nfs_client *clp,
349ba84db96SAndy Adamson 		struct nfs41_exchange_id_res *res, struct rpc_xprt *xprt);
35094de8b27SAndy Adamson 
35194de8b27SAndy Adamson static inline bool
is_ds_only_client(struct nfs_client * clp)35294de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp)
35394de8b27SAndy Adamson {
35494de8b27SAndy Adamson 	return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) ==
35594de8b27SAndy Adamson 		EXCHGID4_FLAG_USE_PNFS_DS;
35694de8b27SAndy Adamson }
357d83217c1SAndy Adamson 
358d83217c1SAndy Adamson static inline bool
is_ds_client(struct nfs_client * clp)359d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp)
360d83217c1SAndy Adamson {
361d83217c1SAndy Adamson 	return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
362d83217c1SAndy Adamson }
363ab4c2361SWeston Andros Adamson 
3648c21c62cSWeston Andros Adamson static inline bool
_nfs4_state_protect(struct nfs_client * clp,unsigned long sp4_mode,struct rpc_clnt ** clntp,struct rpc_message * msg)3658c21c62cSWeston Andros Adamson _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
366ab4c2361SWeston Andros Adamson 		    struct rpc_clnt **clntp, struct rpc_message *msg)
367ab4c2361SWeston Andros Adamson {
368ab4c2361SWeston Andros Adamson 	rpc_authflavor_t flavor;
369ab4c2361SWeston Andros Adamson 
370b79e87e0SNeilBrown 	if (sp4_mode == NFS_SP4_MACH_CRED_CLEANUP ||
371b79e87e0SNeilBrown 	    sp4_mode == NFS_SP4_MACH_CRED_PNFS_CLEANUP) {
372b79e87e0SNeilBrown 		/* Using machine creds for cleanup operations
373b79e87e0SNeilBrown 		 * is only relevent if the client credentials
374b79e87e0SNeilBrown 		 * might expire. So don't bother for
375b79e87e0SNeilBrown 		 * RPC_AUTH_UNIX.  If file was only exported to
376b79e87e0SNeilBrown 		 * sec=sys, the PUTFH would fail anyway.
377b79e87e0SNeilBrown 		 */
378b79e87e0SNeilBrown 		if ((*clntp)->cl_auth->au_flavor == RPC_AUTH_UNIX)
379b79e87e0SNeilBrown 			return false;
380b79e87e0SNeilBrown 	}
381ab4c2361SWeston Andros Adamson 	if (test_bit(sp4_mode, &clp->cl_sp4_flags)) {
3825e16923bSNeilBrown 		msg->rpc_cred = rpc_machine_cred();
383ab4c2361SWeston Andros Adamson 
384ab4c2361SWeston Andros Adamson 		flavor = clp->cl_rpcclient->cl_auth->au_flavor;
385312cd958SWeston Andros Adamson 		WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I &&
386ab4c2361SWeston Andros Adamson 			     flavor != RPC_AUTH_GSS_KRB5P);
387ab4c2361SWeston Andros Adamson 		*clntp = clp->cl_rpcclient;
3888c21c62cSWeston Andros Adamson 
3898c21c62cSWeston Andros Adamson 		return true;
390ab4c2361SWeston Andros Adamson 	}
3918c21c62cSWeston Andros Adamson 	return false;
3928c21c62cSWeston Andros Adamson }
3938c21c62cSWeston Andros Adamson 
3948c21c62cSWeston Andros Adamson /*
3958c21c62cSWeston Andros Adamson  * Function responsible for determining if an rpc_message should use the
3968c21c62cSWeston Andros Adamson  * machine cred under SP4_MACH_CRED and if so switching the credential and
3978c21c62cSWeston Andros Adamson  * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p).
3988c21c62cSWeston Andros Adamson  * Should be called before rpc_call_sync/rpc_call_async.
3998c21c62cSWeston Andros Adamson  */
4008c21c62cSWeston Andros Adamson static inline void
nfs4_state_protect(struct nfs_client * clp,unsigned long sp4_mode,struct rpc_clnt ** clntp,struct rpc_message * msg)4018c21c62cSWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
4028c21c62cSWeston Andros Adamson 		   struct rpc_clnt **clntp, struct rpc_message *msg)
4038c21c62cSWeston Andros Adamson {
4048c21c62cSWeston Andros Adamson 	_nfs4_state_protect(clp, sp4_mode, clntp, msg);
4058c21c62cSWeston Andros Adamson }
4068c21c62cSWeston Andros Adamson 
4078c21c62cSWeston Andros Adamson /*
4088c21c62cSWeston Andros Adamson  * Special wrapper to nfs4_state_protect for write.
4098c21c62cSWeston Andros Adamson  * If WRITE can use machine cred but COMMIT cannot, make sure all writes
4108c21c62cSWeston Andros Adamson  * that use machine cred use NFS_FILE_SYNC.
4118c21c62cSWeston Andros Adamson  */
4128c21c62cSWeston Andros Adamson static inline void
nfs4_state_protect_write(struct nfs_client * clp,struct rpc_clnt ** clntp,struct rpc_message * msg,struct nfs_pgio_header * hdr)4138c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
414d45f60c6SWeston Andros Adamson 			 struct rpc_message *msg, struct nfs_pgio_header *hdr)
4158c21c62cSWeston Andros Adamson {
4168c21c62cSWeston Andros Adamson 	if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) &&
4178c21c62cSWeston Andros Adamson 	    !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
418d45f60c6SWeston Andros Adamson 		hdr->args.stable = NFS_FILE_SYNC;
419ab4c2361SWeston Andros Adamson }
420fbcd4abcSAndy Adamson #else /* CONFIG_NFS_v4_1 */
42194de8b27SAndy Adamson static inline bool
is_ds_only_client(struct nfs_client * clp)42294de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp)
42394de8b27SAndy Adamson {
42494de8b27SAndy Adamson 	return false;
42594de8b27SAndy Adamson }
426d83217c1SAndy Adamson 
427d83217c1SAndy Adamson static inline bool
is_ds_client(struct nfs_client * clp)428d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp)
429d83217c1SAndy Adamson {
430d83217c1SAndy Adamson 	return false;
431d83217c1SAndy Adamson }
432ab4c2361SWeston Andros Adamson 
433ab4c2361SWeston Andros Adamson static inline void
nfs4_state_protect(struct nfs_client * clp,unsigned long sp4_flags,struct rpc_clnt ** clntp,struct rpc_message * msg)434ab4c2361SWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags,
435ab4c2361SWeston Andros Adamson 		   struct rpc_clnt **clntp, struct rpc_message *msg)
436ab4c2361SWeston Andros Adamson {
437ab4c2361SWeston Andros Adamson }
4388c21c62cSWeston Andros Adamson 
4398c21c62cSWeston Andros Adamson static inline void
nfs4_state_protect_write(struct nfs_client * clp,struct rpc_clnt ** clntp,struct rpc_message * msg,struct nfs_pgio_header * hdr)4408c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
441d45f60c6SWeston Andros Adamson 			 struct rpc_message *msg, struct nfs_pgio_header *hdr)
4428c21c62cSWeston Andros Adamson {
4438c21c62cSWeston Andros Adamson }
444557134a3SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4454ce79717STrond Myklebust 
44697dc1359STrond Myklebust extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];
44729fba38bSBenny Halevy 
4481549210fSTrond Myklebust extern const u32 nfs4_fattr_bitmap[3];
449a09df2caSDavid Quigley extern const u32 nfs4_statfs_bitmap[3];
450a09df2caSDavid Quigley extern const u32 nfs4_pathconf_bitmap[3];
451dae100c2SFred Isaman extern const u32 nfs4_fsinfo_bitmap[3];
452a09df2caSDavid Quigley extern const u32 nfs4_fs_locations_bitmap[3];
4534ce79717STrond Myklebust 
454abf79bb3SChuck Lever void nfs40_shutdown_client(struct nfs_client *);
455abf79bb3SChuck Lever void nfs41_shutdown_client(struct nfs_client *);
456abf79bb3SChuck Lever int nfs40_init_client(struct nfs_client *);
457abf79bb3SChuck Lever int nfs41_init_client(struct nfs_client *);
458cdb7ecedSBryan Schumaker void nfs4_free_client(struct nfs_client *);
459cdb7ecedSBryan Schumaker 
4606663ee7fSBryan Schumaker struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *);
4616663ee7fSBryan Schumaker 
4624ce79717STrond Myklebust /* nfs4renewd.c */
463adfa6f98SDavid Howells extern void nfs4_schedule_state_renewal(struct nfs_client *);
464adfa6f98SDavid Howells extern void nfs4_kill_renewd(struct nfs_client *);
46565f27f38SDavid Howells extern void nfs4_renew_state(struct work_struct *);
4667dc2993aSRobert Milkowski extern void nfs4_set_lease_period(struct nfs_client *clp, unsigned long lease);
467fb10fb67STrond Myklebust 
4684ce79717STrond Myklebust 
4694ce79717STrond Myklebust /* nfs4state.c */
470d49dd117SBen Dooks extern const nfs4_stateid current_stateid;
471d49dd117SBen Dooks 
472a52458b4SNeilBrown const struct cred *nfs4_get_clid_cred(struct nfs_client *clp);
473a52458b4SNeilBrown const struct cred *nfs4_get_machine_cred(struct nfs_client *clp);
474a52458b4SNeilBrown const struct cred *nfs4_get_renew_cred(struct nfs_client *clp);
47505f4c350SChuck Lever int nfs4_discover_server_trunking(struct nfs_client *clp,
47605f4c350SChuck Lever 			struct nfs_client **);
47705f4c350SChuck Lever int nfs40_discover_server_trunking(struct nfs_client *clp,
478a52458b4SNeilBrown 			struct nfs_client **, const struct cred *);
479a7b72103SAndy Adamson #if defined(CONFIG_NFS_V4_1)
48005f4c350SChuck Lever int nfs41_discover_server_trunking(struct nfs_client *clp,
481a52458b4SNeilBrown 			struct nfs_client **, const struct cred *);
4829f594791STrond Myklebust extern void nfs4_schedule_session_recovery(struct nfs4_session *, int);
4833f10a6afSAnna Schumaker extern void nfs41_notify_server(struct nfs_client *);
4840491567bSOlga Kornievskaia bool nfs4_check_serverowner_major_id(struct nfs41_server_owner *o1,
4850491567bSOlga Kornievskaia 			struct nfs41_server_owner *o2);
4860400a6b0STrond Myklebust #else
nfs4_schedule_session_recovery(struct nfs4_session * session,int err)4879f594791STrond Myklebust static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err)
4880400a6b0STrond Myklebust {
4890400a6b0STrond Myklebust }
490a7b72103SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4914ce79717STrond Myklebust 
492a52458b4SNeilBrown extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, const struct cred *, gfp_t);
4934ce79717STrond Myklebust extern void nfs4_put_state_owner(struct nfs4_state_owner *);
494c77e2283STrond Myklebust extern void nfs4_purge_state_owners(struct nfs_server *, struct list_head *);
495c77e2283STrond Myklebust extern void nfs4_free_state_owners(struct list_head *head);
4964ce79717STrond Myklebust extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
4974ce79717STrond Myklebust extern void nfs4_put_open_state(struct nfs4_state *);
498643168c2SAl Viro extern void nfs4_close_state(struct nfs4_state *, fmode_t);
499643168c2SAl Viro extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
500dc0b027dSTrond Myklebust extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
501a1d0b5eeSTrond Myklebust extern void nfs_inode_find_state_and_recover(struct inode *inode,
502a1d0b5eeSTrond Myklebust 		const nfs4_stateid *stateid);
5034f14c194STrond Myklebust extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *, struct nfs4_state *);
5040400a6b0STrond Myklebust extern void nfs4_schedule_lease_recovery(struct nfs_client *);
50533021279STrond Myklebust extern int nfs4_wait_clnt_recover(struct nfs_client *clp);
50633021279STrond Myklebust extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
507b0d3ded1STrond Myklebust extern void nfs4_schedule_state_manager(struct nfs_client *);
508042b60beSTrond Myklebust extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
5095d422301STrond Myklebust extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
510c9fdeb28SChuck Lever extern int nfs4_schedule_migration_recovery(const struct nfs_server *);
511b7f7a66eSChuck Lever extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
5120a014a44STrond Myklebust extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags, bool);
51378fe0f41SWeston Andros Adamson extern void nfs41_handle_server_scope(struct nfs_client *,
51479d4e1f0SChuck Lever 				      struct nfs41_server_scope **);
515faf5f49cSTrond Myklebust extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
5168d0a8a9dSTrond Myklebust extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
517abf4e13cSTrond Myklebust extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t,
51817393475SNeilBrown 		const struct nfs_lock_context *, nfs4_stateid *,
519a52458b4SNeilBrown 		const struct cred **);
520c82bac6fSTrond Myklebust extern bool nfs4_copy_open_stateid(nfs4_stateid *dst,
521c82bac6fSTrond Myklebust 		struct nfs4_state *state);
5224ce79717STrond Myklebust 
5238535b2beSTrond Myklebust extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
524cee54fc9STrond Myklebust extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
525cee54fc9STrond Myklebust extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
526cee54fc9STrond Myklebust extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
52772211dbeSTrond Myklebust extern void nfs_release_seqid(struct nfs_seqid *seqid);
528cee54fc9STrond Myklebust extern void nfs_free_seqid(struct nfs_seqid *seqid);
5293be0f80bSTrond Myklebust extern int nfs4_setup_sequence(struct nfs_client *client,
530cb04ad2aSPeng Tao 				struct nfs4_sequence_args *args,
531cb04ad2aSPeng Tao 				struct nfs4_sequence_res *res,
532cb04ad2aSPeng Tao 				struct rpc_task *task);
5332c4b131dSPeng Tao extern int nfs4_sequence_done(struct rpc_task *task,
5342c4b131dSPeng Tao 			      struct nfs4_sequence_res *res);
535cee54fc9STrond Myklebust 
5365ae67c4fSTrond Myklebust extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
5376b8d84e2SOlga Kornievskaia extern int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res);
5384ce79717STrond Myklebust extern const nfs4_stateid zero_stateid;
539fcd8843cSTrond Myklebust extern const nfs4_stateid invalid_stateid;
5404ce79717STrond Myklebust 
541129d1977SBryan Schumaker /* nfs4super.c */
542fbdefd64SBryan Schumaker struct nfs_mount_info;
543ab7017a3SBryan Schumaker extern struct nfs_subversion nfs_v4;
544fac1e8e4SBryan Schumaker extern bool nfs4_disable_idmapping;
545fac1e8e4SBryan Schumaker extern unsigned short max_session_slots;
5465405fc44STrond Myklebust extern unsigned short max_session_cb_slots;
547fac1e8e4SBryan Schumaker extern unsigned short send_implementation_id;
548f6de7a39STrond Myklebust extern bool recover_lost_locks;
54989d77c8fSBryan Schumaker 
5506f2ea7f2SChuck Lever #define NFS4_CLIENT_ID_UNIQ_LEN		(64)
5516f2ea7f2SChuck Lever extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
5526f2ea7f2SChuck Lever 
553f2aedb71SDavid Howells extern int nfs4_try_get_tree(struct fs_context *);
554f2aedb71SDavid Howells extern int nfs4_get_referral_tree(struct fs_context *);
555f2aedb71SDavid Howells 
556466bfe7fSBryan Schumaker /* nfs4sysctl.c */
557466bfe7fSBryan Schumaker #ifdef CONFIG_SYSCTL
558466bfe7fSBryan Schumaker int nfs4_register_sysctl(void);
559466bfe7fSBryan Schumaker void nfs4_unregister_sysctl(void);
560466bfe7fSBryan Schumaker #else
nfs4_register_sysctl(void)561466bfe7fSBryan Schumaker static inline int nfs4_register_sysctl(void)
562466bfe7fSBryan Schumaker {
563466bfe7fSBryan Schumaker 	return 0;
564466bfe7fSBryan Schumaker }
565466bfe7fSBryan Schumaker 
nfs4_unregister_sysctl(void)5660add3e85SRandy Dunlap static inline void nfs4_unregister_sysctl(void)
567466bfe7fSBryan Schumaker {
568466bfe7fSBryan Schumaker }
569466bfe7fSBryan Schumaker #endif
570466bfe7fSBryan Schumaker 
5714ce79717STrond Myklebust /* nfs4xdr.c */
572499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs4_procedures[];
5734ce79717STrond Myklebust 
57404a5da69SFrank van der Linden #ifdef CONFIG_NFS_V4_2
57504a5da69SFrank van der Linden extern const u32 nfs42_maxsetxattr_overhead;
57604a5da69SFrank van der Linden extern const u32 nfs42_maxgetxattr_overhead;
57704a5da69SFrank van der Linden extern const u32 nfs42_maxlistxattrs_overhead;
57804a5da69SFrank van der Linden #endif
57904a5da69SFrank van der Linden 
5804ce79717STrond Myklebust struct nfs4_mount_data;
5814ce79717STrond Myklebust 
5824ce79717STrond Myklebust /* callback_xdr.c */
583e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version1;
584e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version4;
5854ce79717STrond Myklebust 
nfs4_stateid_copy(nfs4_stateid * dst,const nfs4_stateid * src)586f597c537STrond Myklebust static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
587f597c537STrond Myklebust {
58893b717fdSTrond Myklebust 	memcpy(dst->data, src->data, sizeof(dst->data));
58993b717fdSTrond Myklebust 	dst->type = src->type;
590f597c537STrond Myklebust }
591f597c537STrond Myklebust 
nfs4_stateid_match(const nfs4_stateid * dst,const nfs4_stateid * src)592f597c537STrond Myklebust static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
593f597c537STrond Myklebust {
59493b717fdSTrond Myklebust 	if (dst->type != src->type)
59593b717fdSTrond Myklebust 		return false;
59693b717fdSTrond Myklebust 	return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
597f597c537STrond Myklebust }
598f597c537STrond Myklebust 
nfs4_stateid_match_other(const nfs4_stateid * dst,const nfs4_stateid * src)599e999e80eSTrond Myklebust static inline bool nfs4_stateid_match_other(const nfs4_stateid *dst, const nfs4_stateid *src)
600e999e80eSTrond Myklebust {
601e999e80eSTrond Myklebust 	return memcmp(dst->other, src->other, NFS4_STATEID_OTHER_SIZE) == 0;
602e999e80eSTrond Myklebust }
603e999e80eSTrond Myklebust 
nfs4_stateid_is_newer(const nfs4_stateid * s1,const nfs4_stateid * s2)604e999e80eSTrond Myklebust static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stateid *s2)
605e999e80eSTrond Myklebust {
606e999e80eSTrond Myklebust 	return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0;
607e999e80eSTrond Myklebust }
608e999e80eSTrond Myklebust 
nfs4_stateid_is_next(const nfs4_stateid * s1,const nfs4_stateid * s2)609b4868b44SBenjamin Coddington static inline bool nfs4_stateid_is_next(const nfs4_stateid *s1, const nfs4_stateid *s2)
610b4868b44SBenjamin Coddington {
611b4868b44SBenjamin Coddington 	u32 seq1 = be32_to_cpu(s1->seqid);
612b4868b44SBenjamin Coddington 	u32 seq2 = be32_to_cpu(s2->seqid);
613b4868b44SBenjamin Coddington 
614b4868b44SBenjamin Coddington 	return seq2 == seq1 + 1U || (seq2 == 1U && seq1 == 0xffffffffU);
615b4868b44SBenjamin Coddington }
616b4868b44SBenjamin Coddington 
nfs4_stateid_match_or_older(const nfs4_stateid * dst,const nfs4_stateid * src)61742c304c3STrond Myklebust static inline bool nfs4_stateid_match_or_older(const nfs4_stateid *dst, const nfs4_stateid *src)
61842c304c3STrond Myklebust {
61942c304c3STrond Myklebust 	return nfs4_stateid_match_other(dst, src) &&
62042c304c3STrond Myklebust 		!(src->seqid && nfs4_stateid_is_newer(dst, src));
62142c304c3STrond Myklebust }
62242c304c3STrond Myklebust 
nfs4_stateid_seqid_inc(nfs4_stateid * s1)62392283957STrond Myklebust static inline void nfs4_stateid_seqid_inc(nfs4_stateid *s1)
62492283957STrond Myklebust {
62592283957STrond Myklebust 	u32 seqid = be32_to_cpu(s1->seqid);
62692283957STrond Myklebust 
62792283957STrond Myklebust 	if (++seqid == 0)
62892283957STrond Myklebust 		++seqid;
62992283957STrond Myklebust 	s1->seqid = cpu_to_be32(seqid);
63092283957STrond Myklebust }
63192283957STrond Myklebust 
nfs4_valid_open_stateid(const struct nfs4_state * state)6325d422301STrond Myklebust static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
6335d422301STrond Myklebust {
6345d422301STrond Myklebust 	return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0;
6355d422301STrond Myklebust }
6365d422301STrond Myklebust 
nfs4_state_match_open_stateid_other(const struct nfs4_state * state,const nfs4_stateid * stateid)6373e7dfb16STrond Myklebust static inline bool nfs4_state_match_open_stateid_other(const struct nfs4_state *state,
6383e7dfb16STrond Myklebust 		const nfs4_stateid *stateid)
6393e7dfb16STrond Myklebust {
6403e7dfb16STrond Myklebust 	return test_bit(NFS_OPEN_STATE, &state->flags) &&
6413e7dfb16STrond Myklebust 		nfs4_stateid_match_other(&state->open_stateid, stateid);
6423e7dfb16STrond Myklebust }
6433e7dfb16STrond Myklebust 
64495ad37f9SFrank van der Linden /* nfs42xattr.c */
64595ad37f9SFrank van der Linden #ifdef CONFIG_NFS_V4_2
64695ad37f9SFrank van der Linden extern int __init nfs4_xattr_cache_init(void);
64795ad37f9SFrank van der Linden extern void nfs4_xattr_cache_exit(void);
64895ad37f9SFrank van der Linden extern void nfs4_xattr_cache_add(struct inode *inode, const char *name,
64995ad37f9SFrank van der Linden 				 const char *buf, struct page **pages,
65095ad37f9SFrank van der Linden 				 ssize_t buflen);
65195ad37f9SFrank van der Linden extern void nfs4_xattr_cache_remove(struct inode *inode, const char *name);
65295ad37f9SFrank van der Linden extern ssize_t nfs4_xattr_cache_get(struct inode *inode, const char *name,
65395ad37f9SFrank van der Linden 				char *buf, ssize_t buflen);
65495ad37f9SFrank van der Linden extern void nfs4_xattr_cache_set_list(struct inode *inode, const char *buf,
65595ad37f9SFrank van der Linden 				      ssize_t buflen);
65695ad37f9SFrank van der Linden extern ssize_t nfs4_xattr_cache_list(struct inode *inode, char *buf,
65795ad37f9SFrank van der Linden 				     ssize_t buflen);
65895ad37f9SFrank van der Linden extern void nfs4_xattr_cache_zap(struct inode *inode);
6594ce79717STrond Myklebust #else
nfs4_xattr_cache_zap(struct inode * inode)66095ad37f9SFrank van der Linden static inline void nfs4_xattr_cache_zap(struct inode *inode)
66195ad37f9SFrank van der Linden {
66295ad37f9SFrank van der Linden }
66395ad37f9SFrank van der Linden #endif /* CONFIG_NFS_V4_2 */
66495ad37f9SFrank van der Linden 
66595ad37f9SFrank van der Linden #else /* CONFIG_NFS_V4 */
6664ce79717STrond Myklebust 
667643168c2SAl Viro #define nfs4_close_state(a, b) do { } while (0)
668643168c2SAl Viro #define nfs4_close_sync(a, b) do { } while (0)
6698c21c62cSWeston Andros Adamson #define nfs4_state_protect(a, b, c, d) do { } while (0)
6708c21c62cSWeston Andros Adamson #define nfs4_state_protect_write(a, b, c, d) do { } while (0)
6714ce79717STrond Myklebust 
67295ad37f9SFrank van der Linden 
6734ce79717STrond Myklebust #endif /* CONFIG_NFS_V4 */
6744ce79717STrond Myklebust #endif /* __LINUX_FS_NFS_NFS4_FS.H */
675