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 { 41433fbe4cSTrond Myklebust NFS4CLNT_STATE_RECOVER = 0, 42e598d843STrond Myklebust NFS4CLNT_CHECK_LEASE, 4358d9714aSTrond Myklebust NFS4CLNT_LEASE_EXPIRED, 44b79a4a1bSTrond Myklebust NFS4CLNT_RECLAIM_REBOOT, 45b79a4a1bSTrond Myklebust NFS4CLNT_RECLAIM_NOGRACE, 46b79a4a1bSTrond Myklebust NFS4CLNT_CB_PATH_DOWN, 474ce79717STrond Myklebust }; 484ce79717STrond Myklebust 494ce79717STrond Myklebust /* 50cee54fc9STrond Myklebust * struct rpc_sequence ensures that RPC calls are sent in the exact 51cee54fc9STrond Myklebust * order that they appear on the list. 52cee54fc9STrond Myklebust */ 53cee54fc9STrond Myklebust struct rpc_sequence { 54cee54fc9STrond Myklebust struct rpc_wait_queue wait; /* RPC call delay queue */ 55cee54fc9STrond Myklebust spinlock_t lock; /* Protects the list */ 56cee54fc9STrond Myklebust struct list_head list; /* Defines sequence of RPC calls */ 57cee54fc9STrond Myklebust }; 58cee54fc9STrond Myklebust 59cee54fc9STrond Myklebust #define NFS_SEQID_CONFIRMED 1 60cee54fc9STrond Myklebust struct nfs_seqid_counter { 61cee54fc9STrond Myklebust struct rpc_sequence *sequence; 62cee54fc9STrond Myklebust int flags; 63cee54fc9STrond Myklebust u32 counter; 64cee54fc9STrond Myklebust }; 65cee54fc9STrond Myklebust 66cee54fc9STrond Myklebust struct nfs_seqid { 67cee54fc9STrond Myklebust struct nfs_seqid_counter *sequence; 684e51336aSTrond Myklebust struct list_head list; 69cee54fc9STrond Myklebust }; 70cee54fc9STrond Myklebust 71cee54fc9STrond Myklebust static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status) 72cee54fc9STrond Myklebust { 73cee54fc9STrond Myklebust if (seqid_mutating_err(-status)) 74cee54fc9STrond Myklebust seqid->flags |= NFS_SEQID_CONFIRMED; 75cee54fc9STrond Myklebust } 76cee54fc9STrond Myklebust 779f958ab8STrond Myklebust struct nfs_unique_id { 789f958ab8STrond Myklebust struct rb_node rb_node; 799f958ab8STrond Myklebust __u64 id; 809f958ab8STrond Myklebust }; 819f958ab8STrond Myklebust 82cee54fc9STrond Myklebust /* 834ce79717STrond Myklebust * NFS4 state_owners and lock_owners are simply labels for ordered 844ce79717STrond Myklebust * sequences of RPC calls. Their sole purpose is to provide once-only 854ce79717STrond Myklebust * semantics by allowing the server to identify replayed requests. 864ce79717STrond Myklebust */ 874ce79717STrond Myklebust struct nfs4_state_owner { 889f958ab8STrond Myklebust struct nfs_unique_id so_owner_id; 89adfa6f98SDavid Howells struct nfs_client *so_client; 906f2e64d3STrond Myklebust struct nfs_server *so_server; 919f958ab8STrond Myklebust struct rb_node so_client_node; 924ce79717STrond Myklebust 934ce79717STrond Myklebust struct rpc_cred *so_cred; /* Associated cred */ 949f958ab8STrond Myklebust 959f958ab8STrond Myklebust spinlock_t so_lock; 969f958ab8STrond Myklebust atomic_t so_count; 974ce79717STrond Myklebust struct list_head so_states; 984ce79717STrond Myklebust struct list_head so_delegations; 99cee54fc9STrond Myklebust struct nfs_seqid_counter so_seqid; 100cee54fc9STrond Myklebust struct rpc_sequence so_sequence; 1014ce79717STrond Myklebust }; 1024ce79717STrond Myklebust 1034ce79717STrond Myklebust /* 1044ce79717STrond Myklebust * struct nfs4_state maintains the client-side state for a given 1054ce79717STrond Myklebust * (state_owner,inode) tuple (OPEN) or state_owner (LOCK). 1064ce79717STrond Myklebust * 1074ce79717STrond Myklebust * OPEN: 1084ce79717STrond Myklebust * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server, 1094ce79717STrond Myklebust * we need to know how many files are open for reading or writing on a 1104ce79717STrond Myklebust * given inode. This information too is stored here. 1114ce79717STrond Myklebust * 1124ce79717STrond Myklebust * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN) 1134ce79717STrond Myklebust */ 1144ce79717STrond Myklebust 1154ce79717STrond Myklebust struct nfs4_lock_state { 1164ce79717STrond Myklebust struct list_head ls_locks; /* Other lock stateids */ 1178d0a8a9dSTrond Myklebust struct nfs4_state * ls_state; /* Pointer to open state */ 1184ce79717STrond Myklebust fl_owner_t ls_owner; /* POSIX lock owner */ 1194ce79717STrond Myklebust #define NFS_LOCK_INITIALIZED 1 1204ce79717STrond Myklebust int ls_flags; 121cee54fc9STrond Myklebust struct nfs_seqid_counter ls_seqid; 122d0dc3701STrond Myklebust struct rpc_sequence ls_sequence; 1239f958ab8STrond Myklebust struct nfs_unique_id ls_id; 1244ce79717STrond Myklebust nfs4_stateid ls_stateid; 1254ce79717STrond Myklebust atomic_t ls_count; 1264ce79717STrond Myklebust }; 1274ce79717STrond Myklebust 1284ce79717STrond Myklebust /* bits for nfs4_state->flags */ 1294ce79717STrond Myklebust enum { 1304ce79717STrond Myklebust LK_STATE_IN_USE, 131003707c7STrond Myklebust NFS_DELEGATED_STATE, /* Current stateid is delegation */ 132003707c7STrond Myklebust NFS_O_RDONLY_STATE, /* OPEN stateid has read-only state */ 133003707c7STrond Myklebust NFS_O_WRONLY_STATE, /* OPEN stateid has write-only state */ 134003707c7STrond Myklebust NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */ 135b79a4a1bSTrond Myklebust NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */ 136b79a4a1bSTrond Myklebust NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */ 1374ce79717STrond Myklebust }; 1384ce79717STrond Myklebust 1394ce79717STrond Myklebust struct nfs4_state { 1404ce79717STrond Myklebust struct list_head open_states; /* List of states for the same state_owner */ 1414ce79717STrond Myklebust struct list_head inode_states; /* List of states for the same inode */ 1424ce79717STrond Myklebust struct list_head lock_states; /* List of subservient lock stateids */ 1434ce79717STrond Myklebust 1444ce79717STrond Myklebust struct nfs4_state_owner *owner; /* Pointer to the open owner */ 1454ce79717STrond Myklebust struct inode *inode; /* Pointer to the inode */ 1464ce79717STrond Myklebust 1474ce79717STrond Myklebust unsigned long flags; /* Do we hold any locks? */ 1488d0a8a9dSTrond Myklebust spinlock_t state_lock; /* Protects the lock_states list */ 1494ce79717STrond Myklebust 1508bda4e4cSTrond Myklebust seqlock_t seqlock; /* Protects the stateid/open_stateid */ 151003707c7STrond Myklebust nfs4_stateid stateid; /* Current stateid: may be delegation */ 152003707c7STrond Myklebust nfs4_stateid open_stateid; /* OPEN stateid */ 1534ce79717STrond Myklebust 1548bda4e4cSTrond Myklebust /* The following 3 fields are protected by owner->so_lock */ 155003707c7STrond Myklebust unsigned int n_rdonly; /* Number of read-only references */ 156003707c7STrond Myklebust unsigned int n_wronly; /* Number of write-only references */ 157003707c7STrond Myklebust unsigned int n_rdwr; /* Number of read/write references */ 1584ce79717STrond Myklebust int state; /* State on the server (R,W, or RW) */ 1594ce79717STrond Myklebust atomic_t count; 1604ce79717STrond Myklebust }; 1614ce79717STrond Myklebust 1624ce79717STrond Myklebust 1634ce79717STrond Myklebust struct nfs4_exception { 1644ce79717STrond Myklebust long timeout; 1654ce79717STrond Myklebust int retry; 1664ce79717STrond Myklebust }; 1674ce79717STrond Myklebust 1684ce79717STrond Myklebust struct nfs4_state_recovery_ops { 169b79a4a1bSTrond Myklebust int state_flag_bit; 1704ce79717STrond Myklebust int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *); 1714ce79717STrond Myklebust int (*recover_lock)(struct nfs4_state *, struct file_lock *); 1724ce79717STrond Myklebust }; 1734ce79717STrond Myklebust 1744ce79717STrond Myklebust extern struct dentry_operations nfs4_dentry_operations; 17592e1d5beSArjan van de Ven extern const struct inode_operations nfs4_dir_inode_operations; 1766b3b5496SJ. Bruce Fields 1776b3b5496SJ. Bruce Fields /* inode.c */ 1786b3b5496SJ. Bruce Fields extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t); 1796b3b5496SJ. Bruce Fields extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int); 1806b3b5496SJ. Bruce Fields extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t); 1816b3b5496SJ. Bruce Fields 1824ce79717STrond Myklebust 1834ce79717STrond Myklebust /* nfs4proc.c */ 1844ce79717STrond Myklebust extern int nfs4_map_errors(int err); 185adfa6f98SDavid Howells extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *); 186adfa6f98SDavid Howells extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct rpc_cred *); 187adfa6f98SDavid Howells extern int nfs4_proc_async_renew(struct nfs_client *, struct rpc_cred *); 188adfa6f98SDavid Howells extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *); 189a49c3c77STrond Myklebust extern int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait); 19002a913a7STrond Myklebust extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *); 19102a913a7STrond Myklebust extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *); 19255a97593STrond Myklebust extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); 19356659e99STrond Myklebust extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, 1947aaa0b3bSManoj Naik struct nfs4_fs_locations *fs_locations, struct page *page); 1954ce79717STrond Myklebust 1964ce79717STrond Myklebust extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops; 197b79a4a1bSTrond Myklebust extern struct nfs4_state_recovery_ops nfs4_nograce_recovery_ops; 1984ce79717STrond Myklebust 1994ce79717STrond Myklebust extern const u32 nfs4_fattr_bitmap[2]; 2004ce79717STrond Myklebust extern const u32 nfs4_statfs_bitmap[2]; 2014ce79717STrond Myklebust extern const u32 nfs4_pathconf_bitmap[2]; 2024ce79717STrond Myklebust extern const u32 nfs4_fsinfo_bitmap[2]; 203830b8e33SManoj Naik extern const u32 nfs4_fs_locations_bitmap[2]; 2044ce79717STrond Myklebust 2054ce79717STrond Myklebust /* nfs4renewd.c */ 206adfa6f98SDavid Howells extern void nfs4_schedule_state_renewal(struct nfs_client *); 2074ce79717STrond Myklebust extern void nfs4_renewd_prepare_shutdown(struct nfs_server *); 208adfa6f98SDavid Howells extern void nfs4_kill_renewd(struct nfs_client *); 20965f27f38SDavid Howells extern void nfs4_renew_state(struct work_struct *); 2104ce79717STrond Myklebust 2114ce79717STrond Myklebust /* nfs4state.c */ 2126dc9d57aSTrond Myklebust struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp); 2134ce79717STrond Myklebust 2144ce79717STrond Myklebust extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *); 2154ce79717STrond Myklebust extern void nfs4_put_state_owner(struct nfs4_state_owner *); 2164ce79717STrond Myklebust extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *); 2174ce79717STrond Myklebust extern void nfs4_put_open_state(struct nfs4_state *); 2184a35bd41STrond Myklebust extern void nfs4_close_state(struct path *, struct nfs4_state *, mode_t); 219a49c3c77STrond Myklebust extern void nfs4_close_sync(struct path *, struct nfs4_state *, mode_t); 2204cecb76fSTrond Myklebust extern void nfs4_state_set_mode_locked(struct nfs4_state *, mode_t); 221adfa6f98SDavid Howells extern void nfs4_schedule_state_recovery(struct nfs_client *); 222faf5f49cSTrond Myklebust extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp); 2238d0a8a9dSTrond Myklebust extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); 2244ce79717STrond Myklebust extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t); 2254ce79717STrond Myklebust 226cee54fc9STrond Myklebust extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter); 227cee54fc9STrond Myklebust extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task); 228cee54fc9STrond Myklebust extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid); 229cee54fc9STrond Myklebust extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid); 230cee54fc9STrond Myklebust extern void nfs_free_seqid(struct nfs_seqid *seqid); 231cee54fc9STrond Myklebust 2324ce79717STrond Myklebust extern const nfs4_stateid zero_stateid; 2334ce79717STrond Myklebust 2344ce79717STrond Myklebust /* nfs4xdr.c */ 2350dbb4c67SAl Viro extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus); 2364ce79717STrond Myklebust extern struct rpc_procinfo nfs4_procedures[]; 2374ce79717STrond Myklebust 2384ce79717STrond Myklebust struct nfs4_mount_data; 2394ce79717STrond Myklebust 2404ce79717STrond Myklebust /* callback_xdr.c */ 2414ce79717STrond Myklebust extern struct svc_version nfs4_callback_version1; 2424ce79717STrond Myklebust 2434ce79717STrond Myklebust #else 2444ce79717STrond Myklebust 2454a35bd41STrond Myklebust #define nfs4_close_state(a, b, c) do { } while (0) 246e9a40458SOlof Johansson #define nfs4_close_sync(a, b, c) do { } while (0) 2474ce79717STrond Myklebust 2484ce79717STrond Myklebust #endif /* CONFIG_NFS_V4 */ 2494ce79717STrond Myklebust #endif /* __LINUX_FS_NFS_NFS4_FS.H */ 250