xref: /openbmc/linux/fs/nfs/nfs4_fs.h (revision cee54fc9)
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 
124ce79717STrond Myklebust #ifdef CONFIG_NFS_V4
134ce79717STrond Myklebust 
144ce79717STrond Myklebust struct idmap;
154ce79717STrond Myklebust 
164ce79717STrond Myklebust /*
174ce79717STrond Myklebust  * In a seqid-mutating op, this macro controls which error return
184ce79717STrond Myklebust  * values trigger incrementation of the seqid.
194ce79717STrond Myklebust  *
204ce79717STrond Myklebust  * from rfc 3010:
214ce79717STrond Myklebust  * The client MUST monotonically increment the sequence number for the
224ce79717STrond Myklebust  * CLOSE, LOCK, LOCKU, OPEN, OPEN_CONFIRM, and OPEN_DOWNGRADE
234ce79717STrond Myklebust  * operations.  This is true even in the event that the previous
244ce79717STrond Myklebust  * operation that used the sequence number received an error.  The only
254ce79717STrond Myklebust  * exception to this rule is if the previous operation received one of
264ce79717STrond Myklebust  * the following errors: NFSERR_STALE_CLIENTID, NFSERR_STALE_STATEID,
274ce79717STrond Myklebust  * NFSERR_BAD_STATEID, NFSERR_BAD_SEQID, NFSERR_BADXDR,
284ce79717STrond Myklebust  * NFSERR_RESOURCE, NFSERR_NOFILEHANDLE.
294ce79717STrond Myklebust  *
304ce79717STrond Myklebust  */
314ce79717STrond Myklebust #define seqid_mutating_err(err)       \
324ce79717STrond Myklebust (((err) != NFSERR_STALE_CLIENTID) &&  \
334ce79717STrond Myklebust  ((err) != NFSERR_STALE_STATEID)  &&  \
344ce79717STrond Myklebust  ((err) != NFSERR_BAD_STATEID)    &&  \
354ce79717STrond Myklebust  ((err) != NFSERR_BAD_SEQID)      &&  \
364ce79717STrond Myklebust  ((err) != NFSERR_BAD_XDR)        &&  \
374ce79717STrond Myklebust  ((err) != NFSERR_RESOURCE)       &&  \
384ce79717STrond Myklebust  ((err) != NFSERR_NOFILEHANDLE))
394ce79717STrond Myklebust 
404ce79717STrond Myklebust enum nfs4_client_state {
414ce79717STrond Myklebust 	NFS4CLNT_OK  = 0,
424ce79717STrond Myklebust };
434ce79717STrond Myklebust 
444ce79717STrond Myklebust /*
454ce79717STrond Myklebust  * The nfs4_client identifies our client state to the server.
464ce79717STrond Myklebust  */
474ce79717STrond Myklebust struct nfs4_client {
484ce79717STrond Myklebust 	struct list_head	cl_servers;	/* Global list of servers */
494ce79717STrond Myklebust 	struct in_addr		cl_addr;	/* Server identifier */
504ce79717STrond Myklebust 	u64			cl_clientid;	/* constant */
514ce79717STrond Myklebust 	nfs4_verifier		cl_confirm;
524ce79717STrond Myklebust 	unsigned long		cl_state;
534ce79717STrond Myklebust 
544ce79717STrond Myklebust 	u32			cl_lockowner_id;
554ce79717STrond Myklebust 
564ce79717STrond Myklebust 	/*
574ce79717STrond Myklebust 	 * The following rwsem ensures exclusive access to the server
584ce79717STrond Myklebust 	 * while we recover the state following a lease expiration.
594ce79717STrond Myklebust 	 */
604ce79717STrond Myklebust 	struct rw_semaphore	cl_sem;
614ce79717STrond Myklebust 
624ce79717STrond Myklebust 	struct list_head	cl_delegations;
634ce79717STrond Myklebust 	struct list_head	cl_state_owners;
644ce79717STrond Myklebust 	struct list_head	cl_unused;
654ce79717STrond Myklebust 	int			cl_nunused;
664ce79717STrond Myklebust 	spinlock_t		cl_lock;
674ce79717STrond Myklebust 	atomic_t		cl_count;
684ce79717STrond Myklebust 
694ce79717STrond Myklebust 	struct rpc_clnt *	cl_rpcclient;
704ce79717STrond Myklebust 	struct rpc_cred *	cl_cred;
714ce79717STrond Myklebust 
724ce79717STrond Myklebust 	struct list_head	cl_superblocks;	/* List of nfs_server structs */
734ce79717STrond Myklebust 
744ce79717STrond Myklebust 	unsigned long		cl_lease_time;
754ce79717STrond Myklebust 	unsigned long		cl_last_renewal;
764ce79717STrond Myklebust 	struct work_struct	cl_renewd;
774ce79717STrond Myklebust 	struct work_struct	cl_recoverd;
784ce79717STrond Myklebust 
794ce79717STrond Myklebust 	wait_queue_head_t	cl_waitq;
804ce79717STrond Myklebust 	struct rpc_wait_queue	cl_rpcwaitq;
814ce79717STrond Myklebust 
824ce79717STrond Myklebust 	/* used for the setclientid verifier */
834ce79717STrond Myklebust 	struct timespec		cl_boot_time;
844ce79717STrond Myklebust 
854ce79717STrond Myklebust 	/* idmapper */
864ce79717STrond Myklebust 	struct idmap *		cl_idmap;
874ce79717STrond Myklebust 
884ce79717STrond Myklebust 	/* Our own IP address, as a null-terminated string.
894ce79717STrond Myklebust 	 * This is used to generate the clientid, and the callback address.
904ce79717STrond Myklebust 	 */
914ce79717STrond Myklebust 	char			cl_ipaddr[16];
924ce79717STrond Myklebust 	unsigned char		cl_id_uniquifier;
934ce79717STrond Myklebust };
944ce79717STrond Myklebust 
954ce79717STrond Myklebust /*
96cee54fc9STrond Myklebust  * struct rpc_sequence ensures that RPC calls are sent in the exact
97cee54fc9STrond Myklebust  * order that they appear on the list.
98cee54fc9STrond Myklebust  */
99cee54fc9STrond Myklebust struct rpc_sequence {
100cee54fc9STrond Myklebust 	struct rpc_wait_queue	wait;	/* RPC call delay queue */
101cee54fc9STrond Myklebust 	spinlock_t lock;		/* Protects the list */
102cee54fc9STrond Myklebust 	struct list_head list;		/* Defines sequence of RPC calls */
103cee54fc9STrond Myklebust };
104cee54fc9STrond Myklebust 
105cee54fc9STrond Myklebust #define NFS_SEQID_CONFIRMED 1
106cee54fc9STrond Myklebust struct nfs_seqid_counter {
107cee54fc9STrond Myklebust 	struct rpc_sequence *sequence;
108cee54fc9STrond Myklebust 	int flags;
109cee54fc9STrond Myklebust 	u32 counter;
110cee54fc9STrond Myklebust };
111cee54fc9STrond Myklebust 
112cee54fc9STrond Myklebust struct nfs_seqid {
113cee54fc9STrond Myklebust 	struct list_head list;
114cee54fc9STrond Myklebust 	struct nfs_seqid_counter *sequence;
115cee54fc9STrond Myklebust 	struct rpc_task *task;
116cee54fc9STrond Myklebust };
117cee54fc9STrond Myklebust 
118cee54fc9STrond Myklebust static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
119cee54fc9STrond Myklebust {
120cee54fc9STrond Myklebust 	if (seqid_mutating_err(-status))
121cee54fc9STrond Myklebust 		seqid->flags |= NFS_SEQID_CONFIRMED;
122cee54fc9STrond Myklebust }
123cee54fc9STrond Myklebust 
124cee54fc9STrond Myklebust /*
1254ce79717STrond Myklebust  * NFS4 state_owners and lock_owners are simply labels for ordered
1264ce79717STrond Myklebust  * sequences of RPC calls. Their sole purpose is to provide once-only
1274ce79717STrond Myklebust  * semantics by allowing the server to identify replayed requests.
1284ce79717STrond Myklebust  *
1294ce79717STrond Myklebust  * The ->so_sema is held during all state_owner seqid-mutating operations:
1304ce79717STrond Myklebust  * OPEN, OPEN_DOWNGRADE, and CLOSE. Its purpose is to properly serialize
1314ce79717STrond Myklebust  * so_seqid.
1324ce79717STrond Myklebust  */
1334ce79717STrond Myklebust struct nfs4_state_owner {
1344ce79717STrond Myklebust 	struct list_head     so_list;	 /* per-clientid list of state_owners */
1354ce79717STrond Myklebust 	struct nfs4_client   *so_client;
1364ce79717STrond Myklebust 	u32                  so_id;      /* 32-bit identifier, unique */
1374ce79717STrond Myklebust 	struct semaphore     so_sema;
1384ce79717STrond Myklebust 	atomic_t	     so_count;
1394ce79717STrond Myklebust 
1404ce79717STrond Myklebust 	struct rpc_cred	     *so_cred;	 /* Associated cred */
1414ce79717STrond Myklebust 	struct list_head     so_states;
1424ce79717STrond Myklebust 	struct list_head     so_delegations;
143cee54fc9STrond Myklebust 	struct nfs_seqid_counter so_seqid;
144cee54fc9STrond Myklebust 	struct rpc_sequence  so_sequence;
1454ce79717STrond Myklebust };
1464ce79717STrond Myklebust 
1474ce79717STrond Myklebust /*
1484ce79717STrond Myklebust  * struct nfs4_state maintains the client-side state for a given
1494ce79717STrond Myklebust  * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
1504ce79717STrond Myklebust  *
1514ce79717STrond Myklebust  * OPEN:
1524ce79717STrond Myklebust  * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
1534ce79717STrond Myklebust  * we need to know how many files are open for reading or writing on a
1544ce79717STrond Myklebust  * given inode. This information too is stored here.
1554ce79717STrond Myklebust  *
1564ce79717STrond Myklebust  * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
1574ce79717STrond Myklebust  */
1584ce79717STrond Myklebust 
1594ce79717STrond Myklebust struct nfs4_lock_state {
1604ce79717STrond Myklebust 	struct list_head	ls_locks;	/* Other lock stateids */
1618d0a8a9dSTrond Myklebust 	struct nfs4_state *	ls_state;	/* Pointer to open state */
1624ce79717STrond Myklebust 	fl_owner_t		ls_owner;	/* POSIX lock owner */
1634ce79717STrond Myklebust #define NFS_LOCK_INITIALIZED 1
1644ce79717STrond Myklebust 	int			ls_flags;
165cee54fc9STrond Myklebust 	struct nfs_seqid_counter	ls_seqid;
1664ce79717STrond Myklebust 	u32			ls_id;
1674ce79717STrond Myklebust 	nfs4_stateid		ls_stateid;
1684ce79717STrond Myklebust 	atomic_t		ls_count;
1694ce79717STrond Myklebust };
1704ce79717STrond Myklebust 
1714ce79717STrond Myklebust /* bits for nfs4_state->flags */
1724ce79717STrond Myklebust enum {
1734ce79717STrond Myklebust 	LK_STATE_IN_USE,
1744ce79717STrond Myklebust 	NFS_DELEGATED_STATE,
1754ce79717STrond Myklebust };
1764ce79717STrond Myklebust 
1774ce79717STrond Myklebust struct nfs4_state {
1784ce79717STrond Myklebust 	struct list_head open_states;	/* List of states for the same state_owner */
1794ce79717STrond Myklebust 	struct list_head inode_states;	/* List of states for the same inode */
1804ce79717STrond Myklebust 	struct list_head lock_states;	/* List of subservient lock stateids */
1814ce79717STrond Myklebust 
1824ce79717STrond Myklebust 	struct nfs4_state_owner *owner;	/* Pointer to the open owner */
1834ce79717STrond Myklebust 	struct inode *inode;		/* Pointer to the inode */
1844ce79717STrond Myklebust 
1854ce79717STrond Myklebust 	unsigned long flags;		/* Do we hold any locks? */
1864ce79717STrond Myklebust 	struct semaphore lock_sema;	/* Serializes file locking operations */
1878d0a8a9dSTrond Myklebust 	spinlock_t state_lock;		/* Protects the lock_states list */
1884ce79717STrond Myklebust 
1894ce79717STrond Myklebust 	nfs4_stateid stateid;
1904ce79717STrond Myklebust 
1914ce79717STrond Myklebust 	unsigned int nreaders;
1924ce79717STrond Myklebust 	unsigned int nwriters;
1934ce79717STrond Myklebust 	int state;			/* State on the server (R,W, or RW) */
1944ce79717STrond Myklebust 	atomic_t count;
1954ce79717STrond Myklebust };
1964ce79717STrond Myklebust 
1974ce79717STrond Myklebust 
1984ce79717STrond Myklebust struct nfs4_exception {
1994ce79717STrond Myklebust 	long timeout;
2004ce79717STrond Myklebust 	int retry;
2014ce79717STrond Myklebust };
2024ce79717STrond Myklebust 
2034ce79717STrond Myklebust struct nfs4_state_recovery_ops {
2044ce79717STrond Myklebust 	int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
2054ce79717STrond Myklebust 	int (*recover_lock)(struct nfs4_state *, struct file_lock *);
2064ce79717STrond Myklebust };
2074ce79717STrond Myklebust 
2084ce79717STrond Myklebust extern struct dentry_operations nfs4_dentry_operations;
2094ce79717STrond Myklebust extern struct inode_operations nfs4_dir_inode_operations;
2106b3b5496SJ. Bruce Fields 
2116b3b5496SJ. Bruce Fields /* inode.c */
2126b3b5496SJ. Bruce Fields extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t);
2136b3b5496SJ. Bruce Fields extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int);
2146b3b5496SJ. Bruce Fields extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
2156b3b5496SJ. Bruce Fields 
2164ce79717STrond Myklebust 
2174ce79717STrond Myklebust /* nfs4proc.c */
2184ce79717STrond Myklebust extern int nfs4_map_errors(int err);
2194ce79717STrond Myklebust extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short);
2204ce79717STrond Myklebust extern int nfs4_proc_setclientid_confirm(struct nfs4_client *);
2214ce79717STrond Myklebust extern int nfs4_proc_async_renew(struct nfs4_client *);
2224ce79717STrond Myklebust extern int nfs4_proc_renew(struct nfs4_client *);
2234ce79717STrond Myklebust extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode);
2244ce79717STrond Myklebust extern struct inode *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
2254ce79717STrond Myklebust extern int nfs4_open_revalidate(struct inode *, struct dentry *, int);
2264ce79717STrond Myklebust 
2274ce79717STrond Myklebust extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops;
2284ce79717STrond Myklebust extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops;
2294ce79717STrond Myklebust 
2304ce79717STrond Myklebust extern const u32 nfs4_fattr_bitmap[2];
2314ce79717STrond Myklebust extern const u32 nfs4_statfs_bitmap[2];
2324ce79717STrond Myklebust extern const u32 nfs4_pathconf_bitmap[2];
2334ce79717STrond Myklebust extern const u32 nfs4_fsinfo_bitmap[2];
2344ce79717STrond Myklebust 
2354ce79717STrond Myklebust /* nfs4renewd.c */
2364ce79717STrond Myklebust extern void nfs4_schedule_state_renewal(struct nfs4_client *);
2374ce79717STrond Myklebust extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
2384ce79717STrond Myklebust extern void nfs4_kill_renewd(struct nfs4_client *);
2394ce79717STrond Myklebust extern void nfs4_renew_state(void *);
2404ce79717STrond Myklebust 
2414ce79717STrond Myklebust /* nfs4state.c */
2424ce79717STrond Myklebust extern void init_nfsv4_state(struct nfs_server *);
2434ce79717STrond Myklebust extern void destroy_nfsv4_state(struct nfs_server *);
2444ce79717STrond Myklebust extern struct nfs4_client *nfs4_get_client(struct in_addr *);
2454ce79717STrond Myklebust extern void nfs4_put_client(struct nfs4_client *clp);
2464ce79717STrond Myklebust extern int nfs4_init_client(struct nfs4_client *clp);
2474ce79717STrond Myklebust extern struct nfs4_client *nfs4_find_client(struct in_addr *);
2484ce79717STrond Myklebust extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
2494ce79717STrond Myklebust 
2504ce79717STrond Myklebust extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
2514ce79717STrond Myklebust extern void nfs4_put_state_owner(struct nfs4_state_owner *);
2524ce79717STrond Myklebust extern void nfs4_drop_state_owner(struct nfs4_state_owner *);
2534ce79717STrond Myklebust extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
2544ce79717STrond Myklebust extern void nfs4_put_open_state(struct nfs4_state *);
2554ce79717STrond Myklebust extern void nfs4_close_state(struct nfs4_state *, mode_t);
2564ce79717STrond Myklebust extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode);
2574ce79717STrond Myklebust extern void nfs4_schedule_state_recovery(struct nfs4_client *);
2588d0a8a9dSTrond Myklebust extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
2594ce79717STrond Myklebust extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
2604ce79717STrond Myklebust 
261cee54fc9STrond Myklebust extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter);
262cee54fc9STrond Myklebust extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
263cee54fc9STrond Myklebust extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
264cee54fc9STrond Myklebust extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
265cee54fc9STrond Myklebust extern void nfs_free_seqid(struct nfs_seqid *seqid);
266cee54fc9STrond Myklebust 
2674ce79717STrond Myklebust extern const nfs4_stateid zero_stateid;
2684ce79717STrond Myklebust 
2694ce79717STrond Myklebust /* nfs4xdr.c */
2704ce79717STrond Myklebust extern uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus);
2714ce79717STrond Myklebust extern struct rpc_procinfo nfs4_procedures[];
2724ce79717STrond Myklebust 
2734ce79717STrond Myklebust struct nfs4_mount_data;
2744ce79717STrond Myklebust 
2754ce79717STrond Myklebust /* callback_xdr.c */
2764ce79717STrond Myklebust extern struct svc_version nfs4_callback_version1;
2774ce79717STrond Myklebust 
2784ce79717STrond Myklebust #else
2794ce79717STrond Myklebust 
2804ce79717STrond Myklebust #define init_nfsv4_state(server)  do { } while (0)
2814ce79717STrond Myklebust #define destroy_nfsv4_state(server)       do { } while (0)
2824ce79717STrond Myklebust #define nfs4_put_state_owner(inode, owner) do { } while (0)
2834ce79717STrond Myklebust #define nfs4_put_open_state(state) do { } while (0)
2844ce79717STrond Myklebust #define nfs4_close_state(a, b) do { } while (0)
2854ce79717STrond Myklebust 
2864ce79717STrond Myklebust #endif /* CONFIG_NFS_V4 */
2874ce79717STrond Myklebust #endif /* __LINUX_FS_NFS_NFS4_FS.H */
288