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 { 41e005e804STrond Myklebust NFS4CLNT_MANAGER_RUNNING = 0, 42e598d843STrond Myklebust NFS4CLNT_CHECK_LEASE, 4358d9714aSTrond Myklebust NFS4CLNT_LEASE_EXPIRED, 44b79a4a1bSTrond Myklebust NFS4CLNT_RECLAIM_REBOOT, 45b79a4a1bSTrond Myklebust NFS4CLNT_RECLAIM_NOGRACE, 46707fb4b3STrond Myklebust NFS4CLNT_DELEGRETURN, 476df08189SAndy Adamson NFS4CLNT_SESSION_RESET, 48ea028ac9SAndy Adamson NFS4CLNT_SESSION_DRAINING, 494ce79717STrond Myklebust }; 504ce79717STrond Myklebust 514ce79717STrond Myklebust /* 52cee54fc9STrond Myklebust * struct rpc_sequence ensures that RPC calls are sent in the exact 53cee54fc9STrond Myklebust * order that they appear on the list. 54cee54fc9STrond Myklebust */ 55cee54fc9STrond Myklebust struct rpc_sequence { 56cee54fc9STrond Myklebust struct rpc_wait_queue wait; /* RPC call delay queue */ 57cee54fc9STrond Myklebust spinlock_t lock; /* Protects the list */ 58cee54fc9STrond Myklebust struct list_head list; /* Defines sequence of RPC calls */ 59cee54fc9STrond Myklebust }; 60cee54fc9STrond Myklebust 61cee54fc9STrond Myklebust #define NFS_SEQID_CONFIRMED 1 62cee54fc9STrond Myklebust struct nfs_seqid_counter { 63cee54fc9STrond Myklebust struct rpc_sequence *sequence; 64cee54fc9STrond Myklebust int flags; 65cee54fc9STrond Myklebust u32 counter; 66cee54fc9STrond Myklebust }; 67cee54fc9STrond Myklebust 68cee54fc9STrond Myklebust struct nfs_seqid { 69cee54fc9STrond Myklebust struct nfs_seqid_counter *sequence; 704e51336aSTrond Myklebust struct list_head list; 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 799f958ab8STrond Myklebust struct nfs_unique_id { 809f958ab8STrond Myklebust struct rb_node rb_node; 819f958ab8STrond Myklebust __u64 id; 829f958ab8STrond Myklebust }; 839f958ab8STrond Myklebust 84cee54fc9STrond Myklebust /* 854ce79717STrond Myklebust * NFS4 state_owners and lock_owners are simply labels for ordered 864ce79717STrond Myklebust * sequences of RPC calls. Their sole purpose is to provide once-only 874ce79717STrond Myklebust * semantics by allowing the server to identify replayed requests. 884ce79717STrond Myklebust */ 894ce79717STrond Myklebust struct nfs4_state_owner { 909f958ab8STrond Myklebust struct nfs_unique_id so_owner_id; 91adfa6f98SDavid Howells struct nfs_client *so_client; 926f2e64d3STrond Myklebust struct nfs_server *so_server; 939f958ab8STrond Myklebust struct rb_node so_client_node; 944ce79717STrond Myklebust 954ce79717STrond Myklebust struct rpc_cred *so_cred; /* Associated cred */ 969f958ab8STrond Myklebust 979f958ab8STrond Myklebust spinlock_t so_lock; 989f958ab8STrond Myklebust atomic_t so_count; 997eff03aeSTrond Myklebust unsigned long so_flags; 1004ce79717STrond Myklebust struct list_head so_states; 1014ce79717STrond Myklebust struct list_head so_delegations; 102cee54fc9STrond Myklebust struct nfs_seqid_counter so_seqid; 103cee54fc9STrond Myklebust struct rpc_sequence so_sequence; 1044ce79717STrond Myklebust }; 1054ce79717STrond Myklebust 1067eff03aeSTrond Myklebust enum { 1077eff03aeSTrond Myklebust NFS_OWNER_RECLAIM_REBOOT, 1087eff03aeSTrond Myklebust NFS_OWNER_RECLAIM_NOGRACE 1097eff03aeSTrond Myklebust }; 1107eff03aeSTrond Myklebust 111afe6c27cSAlexandros Batsakis #define NFS_LOCK_NEW 0 112afe6c27cSAlexandros Batsakis #define NFS_LOCK_RECLAIM 1 113afe6c27cSAlexandros Batsakis #define NFS_LOCK_EXPIRED 2 114afe6c27cSAlexandros Batsakis 1154ce79717STrond Myklebust /* 1164ce79717STrond Myklebust * struct nfs4_state maintains the client-side state for a given 1174ce79717STrond Myklebust * (state_owner,inode) tuple (OPEN) or state_owner (LOCK). 1184ce79717STrond Myklebust * 1194ce79717STrond Myklebust * OPEN: 1204ce79717STrond Myklebust * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server, 1214ce79717STrond Myklebust * we need to know how many files are open for reading or writing on a 1224ce79717STrond Myklebust * given inode. This information too is stored here. 1234ce79717STrond Myklebust * 1244ce79717STrond Myklebust * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN) 1254ce79717STrond Myklebust */ 1264ce79717STrond Myklebust 1274ce79717STrond Myklebust struct nfs4_lock_state { 1284ce79717STrond Myklebust struct list_head ls_locks; /* Other lock stateids */ 1298d0a8a9dSTrond Myklebust struct nfs4_state * ls_state; /* Pointer to open state */ 1304ce79717STrond Myklebust fl_owner_t ls_owner; /* POSIX lock owner */ 1314ce79717STrond Myklebust #define NFS_LOCK_INITIALIZED 1 1324ce79717STrond Myklebust int ls_flags; 133cee54fc9STrond Myklebust struct nfs_seqid_counter ls_seqid; 134d0dc3701STrond Myklebust struct rpc_sequence ls_sequence; 1359f958ab8STrond Myklebust struct nfs_unique_id ls_id; 1364ce79717STrond Myklebust nfs4_stateid ls_stateid; 1374ce79717STrond Myklebust atomic_t ls_count; 1384ce79717STrond Myklebust }; 1394ce79717STrond Myklebust 1404ce79717STrond Myklebust /* bits for nfs4_state->flags */ 1414ce79717STrond Myklebust enum { 1424ce79717STrond Myklebust LK_STATE_IN_USE, 143003707c7STrond Myklebust NFS_DELEGATED_STATE, /* Current stateid is delegation */ 144003707c7STrond Myklebust NFS_O_RDONLY_STATE, /* OPEN stateid has read-only state */ 145003707c7STrond Myklebust NFS_O_WRONLY_STATE, /* OPEN stateid has write-only state */ 146003707c7STrond Myklebust NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */ 147b79a4a1bSTrond Myklebust NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */ 148b79a4a1bSTrond Myklebust NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */ 1498e469ebdSTrond Myklebust NFS_STATE_POSIX_LOCKS, /* Posix locks are supported */ 1504ce79717STrond Myklebust }; 1514ce79717STrond Myklebust 1524ce79717STrond Myklebust struct nfs4_state { 1534ce79717STrond Myklebust struct list_head open_states; /* List of states for the same state_owner */ 1544ce79717STrond Myklebust struct list_head inode_states; /* List of states for the same inode */ 1554ce79717STrond Myklebust struct list_head lock_states; /* List of subservient lock stateids */ 1564ce79717STrond Myklebust 1574ce79717STrond Myklebust struct nfs4_state_owner *owner; /* Pointer to the open owner */ 1584ce79717STrond Myklebust struct inode *inode; /* Pointer to the inode */ 1594ce79717STrond Myklebust 1604ce79717STrond Myklebust unsigned long flags; /* Do we hold any locks? */ 1618d0a8a9dSTrond Myklebust spinlock_t state_lock; /* Protects the lock_states list */ 1624ce79717STrond Myklebust 1638bda4e4cSTrond Myklebust seqlock_t seqlock; /* Protects the stateid/open_stateid */ 164003707c7STrond Myklebust nfs4_stateid stateid; /* Current stateid: may be delegation */ 165003707c7STrond Myklebust nfs4_stateid open_stateid; /* OPEN stateid */ 1664ce79717STrond Myklebust 1678bda4e4cSTrond Myklebust /* The following 3 fields are protected by owner->so_lock */ 168003707c7STrond Myklebust unsigned int n_rdonly; /* Number of read-only references */ 169003707c7STrond Myklebust unsigned int n_wronly; /* Number of write-only references */ 170003707c7STrond Myklebust unsigned int n_rdwr; /* Number of read/write references */ 171dc0b027dSTrond Myklebust fmode_t state; /* State on the server (R,W, or RW) */ 1724ce79717STrond Myklebust atomic_t count; 1734ce79717STrond Myklebust }; 1744ce79717STrond Myklebust 1754ce79717STrond Myklebust 1764ce79717STrond Myklebust struct nfs4_exception { 1774ce79717STrond Myklebust long timeout; 1784ce79717STrond Myklebust int retry; 1799e33bed5STrond Myklebust struct nfs4_state *state; 1804ce79717STrond Myklebust }; 1814ce79717STrond Myklebust 1824ce79717STrond Myklebust struct nfs4_state_recovery_ops { 1837eff03aeSTrond Myklebust int owner_flag_bit; 184b79a4a1bSTrond Myklebust int state_flag_bit; 1854ce79717STrond Myklebust int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *); 1864ce79717STrond Myklebust int (*recover_lock)(struct nfs4_state *, struct file_lock *); 187591d71cbSAndy Adamson int (*establish_clid)(struct nfs_client *, struct rpc_cred *); 18890a16617SAndy Adamson struct rpc_cred * (*get_clid_cred)(struct nfs_client *); 189fce5c838SRicardo Labiaga int (*reclaim_complete)(struct nfs_client *); 1904ce79717STrond Myklebust }; 1914ce79717STrond Myklebust 19229fba38bSBenny Halevy struct nfs4_state_maintenance_ops { 19329fba38bSBenny Halevy int (*sched_state_renewal)(struct nfs_client *, struct rpc_cred *); 194a7b72103SAndy Adamson struct rpc_cred * (*get_state_renewal_cred_locked)(struct nfs_client *); 1958e69514fSBenny Halevy int (*renew_lease)(struct nfs_client *, struct rpc_cred *); 19629fba38bSBenny Halevy }; 19729fba38bSBenny Halevy 198f786aa90SAl Viro extern const struct dentry_operations nfs4_dentry_operations; 19992e1d5beSArjan van de Ven extern const struct inode_operations nfs4_dir_inode_operations; 2006b3b5496SJ. Bruce Fields 2016b3b5496SJ. Bruce Fields /* inode.c */ 2026b3b5496SJ. Bruce Fields extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t); 2036b3b5496SJ. Bruce Fields extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int); 2046b3b5496SJ. Bruce Fields extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t); 2056b3b5496SJ. Bruce Fields 2064ce79717STrond Myklebust 2074ce79717STrond Myklebust /* nfs4proc.c */ 208adfa6f98SDavid Howells extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *); 209adfa6f98SDavid Howells extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct rpc_cred *); 2104d643d1dSAndy Adamson extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred); 211adfa6f98SDavid Howells extern int nfs4_proc_async_renew(struct nfs_client *, struct rpc_cred *); 212adfa6f98SDavid Howells extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *); 213591d71cbSAndy Adamson extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *); 2144d643d1dSAndy Adamson extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *); 215a49c3c77STrond Myklebust extern int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait); 21602a913a7STrond Myklebust extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *); 21702a913a7STrond Myklebust extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *); 21855a97593STrond Myklebust extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); 21956659e99STrond Myklebust extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, 2207aaa0b3bSManoj Naik struct nfs4_fs_locations *fs_locations, struct page *page); 2214ce79717STrond Myklebust 222591d71cbSAndy Adamson extern struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[]; 223591d71cbSAndy Adamson extern struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[]; 224557134a3SAndy Adamson #if defined(CONFIG_NFS_V4_1) 225fbcd4abcSAndy Adamson extern int nfs4_setup_sequence(struct nfs_client *clp, 226fbcd4abcSAndy Adamson struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 227fbcd4abcSAndy Adamson int cache_reply, struct rpc_task *task); 228557134a3SAndy Adamson extern void nfs4_destroy_session(struct nfs4_session *session); 229557134a3SAndy Adamson extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp); 230f26468fbSTrond Myklebust extern int nfs4_proc_create_session(struct nfs_client *); 231c3fad1b1SAndy Adamson extern int nfs4_proc_destroy_session(struct nfs4_session *); 232fccba804STrond Myklebust extern int nfs4_init_session(struct nfs_server *server); 2339430fb6bSRicardo Labiaga extern int nfs4_proc_get_lease_time(struct nfs_client *clp, 2349430fb6bSRicardo Labiaga struct nfs_fsinfo *fsinfo); 235fbcd4abcSAndy Adamson #else /* CONFIG_NFS_v4_1 */ 236fbcd4abcSAndy Adamson static inline int nfs4_setup_sequence(struct nfs_client *clp, 237fbcd4abcSAndy Adamson struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 238fbcd4abcSAndy Adamson int cache_reply, struct rpc_task *task) 239fbcd4abcSAndy Adamson { 240fbcd4abcSAndy Adamson return 0; 241fbcd4abcSAndy Adamson } 242fccba804STrond Myklebust 243fccba804STrond Myklebust static inline int nfs4_init_session(struct nfs_server *server) 244fccba804STrond Myklebust { 245fccba804STrond Myklebust return 0; 246fccba804STrond Myklebust } 247557134a3SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2484ce79717STrond Myklebust 24929fba38bSBenny Halevy extern struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[]; 25029fba38bSBenny Halevy 2514ce79717STrond Myklebust extern const u32 nfs4_fattr_bitmap[2]; 2524ce79717STrond Myklebust extern const u32 nfs4_statfs_bitmap[2]; 2534ce79717STrond Myklebust extern const u32 nfs4_pathconf_bitmap[2]; 2544ce79717STrond Myklebust extern const u32 nfs4_fsinfo_bitmap[2]; 255830b8e33SManoj Naik extern const u32 nfs4_fs_locations_bitmap[2]; 2564ce79717STrond Myklebust 2574ce79717STrond Myklebust /* nfs4renewd.c */ 258adfa6f98SDavid Howells extern void nfs4_schedule_state_renewal(struct nfs_client *); 2594ce79717STrond Myklebust extern void nfs4_renewd_prepare_shutdown(struct nfs_server *); 260adfa6f98SDavid Howells extern void nfs4_kill_renewd(struct nfs_client *); 26165f27f38SDavid Howells extern void nfs4_renew_state(struct work_struct *); 2624ce79717STrond Myklebust 2634ce79717STrond Myklebust /* nfs4state.c */ 264a7b72103SAndy Adamson struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp); 2656dc9d57aSTrond Myklebust struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp); 266a7b72103SAndy Adamson #if defined(CONFIG_NFS_V4_1) 267a7b72103SAndy Adamson struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp); 268b4b82607SAndy Adamson struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp); 269a7b72103SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2704ce79717STrond Myklebust 2714ce79717STrond Myklebust extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *); 2724ce79717STrond Myklebust extern void nfs4_put_state_owner(struct nfs4_state_owner *); 2734ce79717STrond Myklebust extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *); 2744ce79717STrond Myklebust extern void nfs4_put_open_state(struct nfs4_state *); 275dc0b027dSTrond Myklebust extern void nfs4_close_state(struct path *, struct nfs4_state *, fmode_t); 276dc0b027dSTrond Myklebust extern void nfs4_close_sync(struct path *, struct nfs4_state *, fmode_t); 277dc0b027dSTrond Myklebust extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t); 278adfa6f98SDavid Howells extern void nfs4_schedule_state_recovery(struct nfs_client *); 279b0d3ded1STrond Myklebust extern void nfs4_schedule_state_manager(struct nfs_client *); 2809e33bed5STrond Myklebust extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state); 281a2c0b9e2STrond Myklebust extern int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state); 2820629e370SAlexandros Batsakis extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags); 283faf5f49cSTrond Myklebust extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp); 2848d0a8a9dSTrond Myklebust extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); 2854ce79717STrond Myklebust extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t); 2864ce79717STrond Myklebust 287cee54fc9STrond Myklebust extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter); 288cee54fc9STrond Myklebust extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task); 289cee54fc9STrond Myklebust extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid); 290cee54fc9STrond Myklebust extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid); 29172211dbeSTrond Myklebust extern void nfs_release_seqid(struct nfs_seqid *seqid); 292cee54fc9STrond Myklebust extern void nfs_free_seqid(struct nfs_seqid *seqid); 293cee54fc9STrond Myklebust 2944ce79717STrond Myklebust extern const nfs4_stateid zero_stateid; 2954ce79717STrond Myklebust 2964ce79717STrond Myklebust /* nfs4xdr.c */ 2970dbb4c67SAl Viro extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus); 2984ce79717STrond Myklebust extern struct rpc_procinfo nfs4_procedures[]; 2994ce79717STrond Myklebust 3004ce79717STrond Myklebust struct nfs4_mount_data; 3014ce79717STrond Myklebust 3024ce79717STrond Myklebust /* callback_xdr.c */ 3034ce79717STrond Myklebust extern struct svc_version nfs4_callback_version1; 30407bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4; 3054ce79717STrond Myklebust 3064ce79717STrond Myklebust #else 3074ce79717STrond Myklebust 3084a35bd41STrond Myklebust #define nfs4_close_state(a, b, c) do { } while (0) 309e9a40458SOlof Johansson #define nfs4_close_sync(a, b, c) do { } while (0) 3104ce79717STrond Myklebust 3114ce79717STrond Myklebust #endif /* CONFIG_NFS_V4 */ 3124ce79717STrond Myklebust #endif /* __LINUX_FS_NFS_NFS4_FS.H */ 313