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 12694e096fSAnna Schumaker #if defined(CONFIG_NFS_V4_2) 13694e096fSAnna Schumaker #define NFS4_MAX_MINOR_VERSION 2 14694e096fSAnna Schumaker #elif defined(CONFIG_NFS_V4_1) 15694e096fSAnna Schumaker #define NFS4_MAX_MINOR_VERSION 1 16694e096fSAnna Schumaker #else 17694e096fSAnna Schumaker #define NFS4_MAX_MINOR_VERSION 0 18694e096fSAnna Schumaker #endif 19694e096fSAnna Schumaker 2089d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 214ce79717STrond Myklebust 2233021279STrond Myklebust #define NFS4_MAX_LOOP_ON_RECOVER (10) 2333021279STrond Myklebust 24c137afabSTrond Myklebust #include <linux/seqlock.h> 25c137afabSTrond Myklebust 264ce79717STrond Myklebust struct idmap; 274ce79717STrond Myklebust 284ce79717STrond Myklebust enum nfs4_client_state { 29e005e804STrond Myklebust NFS4CLNT_MANAGER_RUNNING = 0, 30e598d843STrond Myklebust NFS4CLNT_CHECK_LEASE, 3158d9714aSTrond Myklebust NFS4CLNT_LEASE_EXPIRED, 32b79a4a1bSTrond Myklebust NFS4CLNT_RECLAIM_REBOOT, 33b79a4a1bSTrond Myklebust NFS4CLNT_RECLAIM_NOGRACE, 34707fb4b3STrond Myklebust NFS4CLNT_DELEGRETURN, 356df08189SAndy Adamson NFS4CLNT_SESSION_RESET, 36fd954ae1STrond Myklebust NFS4CLNT_LEASE_CONFIRM, 3778fe0f41SWeston Andros Adamson NFS4CLNT_SERVER_SCOPE_MISMATCH, 382c820d9aSChuck Lever NFS4CLNT_PURGE_STATE, 39a9e64442SWeston Andros Adamson NFS4CLNT_BIND_CONN_TO_SESSION, 40c9fdeb28SChuck Lever NFS4CLNT_MOVED, 41b7f7a66eSChuck Lever NFS4CLNT_LEASE_MOVED, 4245870d69STrond Myklebust NFS4CLNT_DELEGATION_EXPIRED, 434ce79717STrond Myklebust }; 444ce79717STrond Myklebust 452f60ea6bSTrond Myklebust #define NFS4_RENEW_TIMEOUT 0x01 462f60ea6bSTrond Myklebust #define NFS4_RENEW_DELEGATION_CB 0x02 472f60ea6bSTrond Myklebust 4863f5f796STrond Myklebust struct nfs_seqid_counter; 4997dc1359STrond Myklebust struct nfs4_minor_version_ops { 5097dc1359STrond Myklebust u32 minor_version; 5139c6daaeSTrond Myklebust unsigned init_caps; 5297dc1359STrond Myklebust 53abf79bb3SChuck Lever int (*init_client)(struct nfs_client *); 54abf79bb3SChuck Lever void (*shutdown_client)(struct nfs_client *); 5536281caaSTrond Myklebust bool (*match_stateid)(const nfs4_stateid *, 56e047a10cSTrond Myklebust const nfs4_stateid *); 57fca78d6dSBryan Schumaker int (*find_root_sec)(struct nfs_server *, struct nfs_fh *, 58fca78d6dSBryan Schumaker struct nfs_fsinfo *); 59f1cdae87SJeff Layton void (*free_lock_state)(struct nfs_server *, 60c8b2d0bfSTrond Myklebust struct nfs4_lock_state *); 6145870d69STrond Myklebust int (*test_and_free_expired)(struct nfs_server *, 6245870d69STrond Myklebust nfs4_stateid *, struct rpc_cred *); 6363f5f796STrond Myklebust struct nfs_seqid * 6463f5f796STrond Myklebust (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); 6504fa2c6bSAndy Adamson int (*session_trunk)(struct rpc_clnt *, struct rpc_xprt *, void *); 669915ea7eSChuck Lever const struct rpc_call_ops *call_sync_ops; 67c48f4f35STrond Myklebust const struct nfs4_state_recovery_ops *reboot_recovery_ops; 68c48f4f35STrond Myklebust const struct nfs4_state_recovery_ops *nograce_recovery_ops; 69c48f4f35STrond Myklebust const struct nfs4_state_maintenance_ops *state_renewal_ops; 70ec011fe8SChuck Lever const struct nfs4_mig_recovery_ops *mig_recovery_ops; 7197dc1359STrond Myklebust }; 7297dc1359STrond Myklebust 73cee54fc9STrond Myklebust #define NFS_SEQID_CONFIRMED 1 74cee54fc9STrond Myklebust struct nfs_seqid_counter { 7595b72eb0STrond Myklebust ktime_t create_time; 7648c22eb2STrond Myklebust int owner_id; 77cee54fc9STrond Myklebust int flags; 78cee54fc9STrond Myklebust u32 counter; 797ba127abSTrond Myklebust spinlock_t lock; /* Protects the list */ 807ba127abSTrond Myklebust struct list_head list; /* Defines sequence of RPC calls */ 817ba127abSTrond Myklebust struct rpc_wait_queue wait; /* RPC call delay queue */ 82cee54fc9STrond Myklebust }; 83cee54fc9STrond Myklebust 84cee54fc9STrond Myklebust struct nfs_seqid { 85cee54fc9STrond Myklebust struct nfs_seqid_counter *sequence; 864e51336aSTrond Myklebust struct list_head list; 874601df20STrond Myklebust struct rpc_task *task; 88cee54fc9STrond Myklebust }; 89cee54fc9STrond Myklebust 90cee54fc9STrond Myklebust static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status) 91cee54fc9STrond Myklebust { 92cee54fc9STrond Myklebust if (seqid_mutating_err(-status)) 93cee54fc9STrond Myklebust seqid->flags |= NFS_SEQID_CONFIRMED; 94cee54fc9STrond Myklebust } 95cee54fc9STrond Myklebust 96cee54fc9STrond Myklebust /* 974ce79717STrond Myklebust * NFS4 state_owners and lock_owners are simply labels for ordered 984ce79717STrond Myklebust * sequences of RPC calls. Their sole purpose is to provide once-only 994ce79717STrond Myklebust * semantics by allowing the server to identify replayed requests. 1004ce79717STrond Myklebust */ 1014ce79717STrond Myklebust struct nfs4_state_owner { 1026f2e64d3STrond Myklebust struct nfs_server *so_server; 1030aaaf5c4SChuck Lever struct list_head so_lru; 1040aaaf5c4SChuck Lever unsigned long so_expires; 10524d292b8SChuck Lever struct rb_node so_server_node; 1064ce79717STrond Myklebust 1074ce79717STrond Myklebust struct rpc_cred *so_cred; /* Associated cred */ 1089f958ab8STrond Myklebust 1099f958ab8STrond Myklebust spinlock_t so_lock; 1109f958ab8STrond Myklebust atomic_t so_count; 1117eff03aeSTrond Myklebust unsigned long so_flags; 1124ce79717STrond Myklebust struct list_head so_states; 113cee54fc9STrond Myklebust struct nfs_seqid_counter so_seqid; 114c137afabSTrond Myklebust seqcount_t so_reclaim_seqcount; 11565b62a29STrond Myklebust struct mutex so_delegreturn_mutex; 1164ce79717STrond Myklebust }; 1174ce79717STrond Myklebust 1187eff03aeSTrond Myklebust enum { 1197eff03aeSTrond Myklebust NFS_OWNER_RECLAIM_REBOOT, 1207eff03aeSTrond Myklebust NFS_OWNER_RECLAIM_NOGRACE 1217eff03aeSTrond Myklebust }; 1227eff03aeSTrond Myklebust 123afe6c27cSAlexandros Batsakis #define NFS_LOCK_NEW 0 124afe6c27cSAlexandros Batsakis #define NFS_LOCK_RECLAIM 1 125afe6c27cSAlexandros Batsakis #define NFS_LOCK_EXPIRED 2 126afe6c27cSAlexandros Batsakis 1274ce79717STrond Myklebust /* 1284ce79717STrond Myklebust * struct nfs4_state maintains the client-side state for a given 1294ce79717STrond Myklebust * (state_owner,inode) tuple (OPEN) or state_owner (LOCK). 1304ce79717STrond Myklebust * 1314ce79717STrond Myklebust * OPEN: 1324ce79717STrond Myklebust * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server, 1334ce79717STrond Myklebust * we need to know how many files are open for reading or writing on a 1344ce79717STrond Myklebust * given inode. This information too is stored here. 1354ce79717STrond Myklebust * 1364ce79717STrond Myklebust * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN) 1374ce79717STrond Myklebust */ 1384ce79717STrond Myklebust 1394ce79717STrond Myklebust struct nfs4_lock_state { 1404ce79717STrond Myklebust struct list_head ls_locks; /* Other lock stateids */ 1418d0a8a9dSTrond Myklebust struct nfs4_state * ls_state; /* Pointer to open state */ 142795a88c9STrond Myklebust #define NFS_LOCK_INITIALIZED 0 143ef1820f9SNeilBrown #define NFS_LOCK_LOST 1 144795a88c9STrond Myklebust unsigned long ls_flags; 145cee54fc9STrond Myklebust struct nfs_seqid_counter ls_seqid; 1464ce79717STrond Myklebust nfs4_stateid ls_stateid; 1474ce79717STrond Myklebust atomic_t ls_count; 1488003d3c4SJeff Layton fl_owner_t ls_owner; 1494ce79717STrond Myklebust }; 1504ce79717STrond Myklebust 1514ce79717STrond Myklebust /* bits for nfs4_state->flags */ 1524ce79717STrond Myklebust enum { 1534ce79717STrond Myklebust LK_STATE_IN_USE, 154003707c7STrond Myklebust NFS_DELEGATED_STATE, /* Current stateid is delegation */ 15592b40e93STrond Myklebust NFS_OPEN_STATE, /* OPEN stateid is set */ 156003707c7STrond Myklebust NFS_O_RDONLY_STATE, /* OPEN stateid has read-only state */ 157003707c7STrond Myklebust NFS_O_WRONLY_STATE, /* OPEN stateid has write-only state */ 158003707c7STrond Myklebust NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */ 159b79a4a1bSTrond Myklebust NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */ 160b79a4a1bSTrond Myklebust NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */ 1618e469ebdSTrond Myklebust NFS_STATE_POSIX_LOCKS, /* Posix locks are supported */ 1625d422301STrond Myklebust NFS_STATE_RECOVERY_FAILED, /* OPEN stateid state recovery failed */ 163a8ce377aSJeff Layton NFS_STATE_MAY_NOTIFY_LOCK, /* server may CB_NOTIFY_LOCK */ 1644ce79717STrond Myklebust }; 1654ce79717STrond Myklebust 1664ce79717STrond Myklebust struct nfs4_state { 1674ce79717STrond Myklebust struct list_head open_states; /* List of states for the same state_owner */ 1684ce79717STrond Myklebust struct list_head inode_states; /* List of states for the same inode */ 1694ce79717STrond Myklebust struct list_head lock_states; /* List of subservient lock stateids */ 1704ce79717STrond Myklebust 1714ce79717STrond Myklebust struct nfs4_state_owner *owner; /* Pointer to the open owner */ 1724ce79717STrond Myklebust struct inode *inode; /* Pointer to the inode */ 1734ce79717STrond Myklebust 1744ce79717STrond Myklebust unsigned long flags; /* Do we hold any locks? */ 1758d0a8a9dSTrond Myklebust spinlock_t state_lock; /* Protects the lock_states list */ 1764ce79717STrond Myklebust 1778bda4e4cSTrond Myklebust seqlock_t seqlock; /* Protects the stateid/open_stateid */ 178003707c7STrond Myklebust nfs4_stateid stateid; /* Current stateid: may be delegation */ 179003707c7STrond Myklebust nfs4_stateid open_stateid; /* OPEN stateid */ 1804ce79717STrond Myklebust 1818bda4e4cSTrond Myklebust /* The following 3 fields are protected by owner->so_lock */ 182003707c7STrond Myklebust unsigned int n_rdonly; /* Number of read-only references */ 183003707c7STrond Myklebust unsigned int n_wronly; /* Number of write-only references */ 184003707c7STrond Myklebust unsigned int n_rdwr; /* Number of read/write references */ 185dc0b027dSTrond Myklebust fmode_t state; /* State on the server (R,W, or RW) */ 1864ce79717STrond Myklebust atomic_t count; 1874ce79717STrond Myklebust }; 1884ce79717STrond Myklebust 1894ce79717STrond Myklebust 1904ce79717STrond Myklebust struct nfs4_exception { 1919e33bed5STrond Myklebust struct nfs4_state *state; 1923114ea7aSTrond Myklebust struct inode *inode; 1938487c479STrond Myklebust nfs4_stateid *stateid; 194b3c2aa07STrond Myklebust long timeout; 195b3c2aa07STrond Myklebust unsigned char delay : 1, 196b3c2aa07STrond Myklebust recovering : 1, 197b3c2aa07STrond Myklebust retry : 1; 1984ce79717STrond Myklebust }; 1994ce79717STrond Myklebust 2004ce79717STrond Myklebust struct nfs4_state_recovery_ops { 2017eff03aeSTrond Myklebust int owner_flag_bit; 202b79a4a1bSTrond Myklebust int state_flag_bit; 2034ce79717STrond Myklebust int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *); 2044ce79717STrond Myklebust int (*recover_lock)(struct nfs4_state *, struct file_lock *); 205591d71cbSAndy Adamson int (*establish_clid)(struct nfs_client *, struct rpc_cred *); 206965e9c23STrond Myklebust int (*reclaim_complete)(struct nfs_client *, struct rpc_cred *); 20705f4c350SChuck Lever int (*detect_trunking)(struct nfs_client *, struct nfs_client **, 20805f4c350SChuck Lever struct rpc_cred *); 2094ce79717STrond Myklebust }; 2104ce79717STrond Myklebust 21104fa2c6bSAndy Adamson struct nfs4_add_xprt_data { 21204fa2c6bSAndy Adamson struct nfs_client *clp; 21304fa2c6bSAndy Adamson struct rpc_cred *cred; 21404fa2c6bSAndy Adamson }; 21504fa2c6bSAndy Adamson 21629fba38bSBenny Halevy struct nfs4_state_maintenance_ops { 2172f60ea6bSTrond Myklebust int (*sched_state_renewal)(struct nfs_client *, struct rpc_cred *, unsigned); 218a7b72103SAndy Adamson struct rpc_cred * (*get_state_renewal_cred_locked)(struct nfs_client *); 2198e69514fSBenny Halevy int (*renew_lease)(struct nfs_client *, struct rpc_cred *); 22029fba38bSBenny Halevy }; 22129fba38bSBenny Halevy 222ec011fe8SChuck Lever struct nfs4_mig_recovery_ops { 223b03d735bSChuck Lever int (*get_locations)(struct inode *, struct nfs4_fs_locations *, 224b03d735bSChuck Lever struct page *, struct rpc_cred *); 22544c99933SChuck Lever int (*fsid_present)(struct inode *, struct rpc_cred *); 226ec011fe8SChuck Lever }; 227ec011fe8SChuck Lever 228f786aa90SAl Viro extern const struct dentry_operations nfs4_dentry_operations; 22973a79706SBryan Schumaker 23073a79706SBryan Schumaker /* dir.c */ 23173a79706SBryan Schumaker int nfs_atomic_open(struct inode *, struct dentry *, struct file *, 23273a79706SBryan Schumaker unsigned, umode_t, int *); 2336b3b5496SJ. Bruce Fields 2341ae811eeSbjschuma@gmail.com /* super.c */ 2351ae811eeSbjschuma@gmail.com extern struct file_system_type nfs4_fs_type; 2361ae811eeSbjschuma@gmail.com 23772de53ecSBryan Schumaker /* nfs4namespace.c */ 238beffb8feSAl Viro struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *, 239beffb8feSAl Viro const struct qstr *); 240281cad46SBryan Schumaker struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *, 241281cad46SBryan Schumaker struct nfs_fh *, struct nfs_fattr *); 242800c06a5SChuck Lever int nfs4_replace_transport(struct nfs_server *server, 243800c06a5SChuck Lever const struct nfs4_fs_locations *locations); 24472de53ecSBryan Schumaker 2454ce79717STrond Myklebust /* nfs4proc.c */ 246f4ac1674SAnna Schumaker extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *); 2471c6dcbe5SAnna Schumaker extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *, 2481c6dcbe5SAnna Schumaker struct rpc_message *, struct nfs4_sequence_args *, 2491c6dcbe5SAnna Schumaker struct nfs4_sequence_res *, int); 250be3a5d23STrond Myklebust extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int); 251bb8b27e5STrond Myklebust extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *); 252bb8b27e5STrond Myklebust extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *); 2535e6b1990STrond Myklebust extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool); 2542cf047c9STrond Myklebust extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, struct rpc_cred *cred); 2554d643d1dSAndy Adamson extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred); 25666245539STrond Myklebust extern int nfs4_destroy_clientid(struct nfs_client *clp); 257591d71cbSAndy Adamson extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *); 2584d643d1dSAndy Adamson extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *); 2591f7977c1STrond Myklebust extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait); 26055a97593STrond Myklebust extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); 261f05d147fSBryan Schumaker extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *, 262f05d147fSBryan Schumaker struct nfs4_fs_locations *, struct page *); 263b03d735bSChuck Lever extern int nfs4_proc_get_locations(struct inode *, struct nfs4_fs_locations *, 264b03d735bSChuck Lever struct page *page, struct rpc_cred *); 26544c99933SChuck Lever extern int nfs4_proc_fsid_present(struct inode *, struct rpc_cred *); 266beffb8feSAl Viro extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, const struct qstr *, 267f05d147fSBryan Schumaker struct nfs_fh *, struct nfs_fattr *); 26872de53ecSBryan Schumaker extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *); 26964c2ce8bSAneesh Kumar K.V extern const struct xattr_handler *nfs4_xattr_handlers[]; 2705521abfdSTrond Myklebust extern int nfs4_set_rw_stateid(nfs4_stateid *stateid, 2719b206149STrond Myklebust const struct nfs_open_context *ctx, 2729b206149STrond Myklebust const struct nfs_lock_context *l_ctx, 2739b206149STrond Myklebust fmode_t fmode); 2744ce79717STrond Myklebust 275557134a3SAndy Adamson #if defined(CONFIG_NFS_V4_1) 276035168abSTrond Myklebust static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server) 277035168abSTrond Myklebust { 278035168abSTrond Myklebust return server->nfs_client->cl_session; 279035168abSTrond Myklebust } 280035168abSTrond Myklebust 281dc70d7b3SAndy Adamson extern int nfs41_setup_sequence(struct nfs4_session *session, 282dc70d7b3SAndy Adamson struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 2839d12b216STrond Myklebust struct rpc_task *task); 284f9c96fccSAndy Adamson extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *); 285848f5bdaSTrond Myklebust extern int nfs4_proc_create_session(struct nfs_client *, struct rpc_cred *); 286848f5bdaSTrond Myklebust extern int nfs4_proc_destroy_session(struct nfs4_session *, struct rpc_cred *); 2879430fb6bSRicardo Labiaga extern int nfs4_proc_get_lease_time(struct nfs_client *clp, 2889430fb6bSRicardo Labiaga struct nfs_fsinfo *fsinfo); 289863a3c6cSAndy Adamson extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, 290ef311537SAndy Adamson bool sync); 291ba84db96SAndy Adamson extern int nfs4_detect_session_trunking(struct nfs_client *clp, 292ba84db96SAndy Adamson struct nfs41_exchange_id_res *res, struct rpc_xprt *xprt); 29394de8b27SAndy Adamson 29494de8b27SAndy Adamson static inline bool 29594de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp) 29694de8b27SAndy Adamson { 29794de8b27SAndy Adamson return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) == 29894de8b27SAndy Adamson EXCHGID4_FLAG_USE_PNFS_DS; 29994de8b27SAndy Adamson } 300d83217c1SAndy Adamson 301d83217c1SAndy Adamson static inline bool 302d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp) 303d83217c1SAndy Adamson { 304d83217c1SAndy Adamson return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS; 305d83217c1SAndy Adamson } 306ab4c2361SWeston Andros Adamson 3078c21c62cSWeston Andros Adamson static inline bool 3088c21c62cSWeston Andros Adamson _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode, 309ab4c2361SWeston Andros Adamson struct rpc_clnt **clntp, struct rpc_message *msg) 310ab4c2361SWeston Andros Adamson { 311ab4c2361SWeston Andros Adamson struct rpc_cred *newcred = NULL; 312ab4c2361SWeston Andros Adamson rpc_authflavor_t flavor; 313ab4c2361SWeston Andros Adamson 314ab4c2361SWeston Andros Adamson if (test_bit(sp4_mode, &clp->cl_sp4_flags)) { 315ab4c2361SWeston Andros Adamson spin_lock(&clp->cl_lock); 316ab4c2361SWeston Andros Adamson if (clp->cl_machine_cred != NULL) 317ade33ff5SWeston Andros Adamson /* don't call get_rpccred on the machine cred - 318ade33ff5SWeston Andros Adamson * a reference will be held for life of clp */ 319ade33ff5SWeston Andros Adamson newcred = clp->cl_machine_cred; 320ab4c2361SWeston Andros Adamson spin_unlock(&clp->cl_lock); 321ab4c2361SWeston Andros Adamson msg->rpc_cred = newcred; 322ab4c2361SWeston Andros Adamson 323ab4c2361SWeston Andros Adamson flavor = clp->cl_rpcclient->cl_auth->au_flavor; 324312cd958SWeston Andros Adamson WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I && 325ab4c2361SWeston Andros Adamson flavor != RPC_AUTH_GSS_KRB5P); 326ab4c2361SWeston Andros Adamson *clntp = clp->cl_rpcclient; 3278c21c62cSWeston Andros Adamson 3288c21c62cSWeston Andros Adamson return true; 329ab4c2361SWeston Andros Adamson } 3308c21c62cSWeston Andros Adamson return false; 3318c21c62cSWeston Andros Adamson } 3328c21c62cSWeston Andros Adamson 3338c21c62cSWeston Andros Adamson /* 3348c21c62cSWeston Andros Adamson * Function responsible for determining if an rpc_message should use the 3358c21c62cSWeston Andros Adamson * machine cred under SP4_MACH_CRED and if so switching the credential and 3368c21c62cSWeston Andros Adamson * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p). 3378c21c62cSWeston Andros Adamson * Should be called before rpc_call_sync/rpc_call_async. 3388c21c62cSWeston Andros Adamson */ 3398c21c62cSWeston Andros Adamson static inline void 3408c21c62cSWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode, 3418c21c62cSWeston Andros Adamson struct rpc_clnt **clntp, struct rpc_message *msg) 3428c21c62cSWeston Andros Adamson { 3438c21c62cSWeston Andros Adamson _nfs4_state_protect(clp, sp4_mode, clntp, msg); 3448c21c62cSWeston Andros Adamson } 3458c21c62cSWeston Andros Adamson 3468c21c62cSWeston Andros Adamson /* 3478c21c62cSWeston Andros Adamson * Special wrapper to nfs4_state_protect for write. 3488c21c62cSWeston Andros Adamson * If WRITE can use machine cred but COMMIT cannot, make sure all writes 3498c21c62cSWeston Andros Adamson * that use machine cred use NFS_FILE_SYNC. 3508c21c62cSWeston Andros Adamson */ 3518c21c62cSWeston Andros Adamson static inline void 3528c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp, 353d45f60c6SWeston Andros Adamson struct rpc_message *msg, struct nfs_pgio_header *hdr) 3548c21c62cSWeston Andros Adamson { 3558c21c62cSWeston Andros Adamson if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) && 3568c21c62cSWeston Andros Adamson !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags)) 357d45f60c6SWeston Andros Adamson hdr->args.stable = NFS_FILE_SYNC; 358ab4c2361SWeston Andros Adamson } 359fbcd4abcSAndy Adamson #else /* CONFIG_NFS_v4_1 */ 360035168abSTrond Myklebust static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server) 361035168abSTrond Myklebust { 362035168abSTrond Myklebust return NULL; 363035168abSTrond Myklebust } 364035168abSTrond Myklebust 36594de8b27SAndy Adamson static inline bool 36694de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp) 36794de8b27SAndy Adamson { 36894de8b27SAndy Adamson return false; 36994de8b27SAndy Adamson } 370d83217c1SAndy Adamson 371d83217c1SAndy Adamson static inline bool 372d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp) 373d83217c1SAndy Adamson { 374d83217c1SAndy Adamson return false; 375d83217c1SAndy Adamson } 376ab4c2361SWeston Andros Adamson 377ab4c2361SWeston Andros Adamson static inline void 378ab4c2361SWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags, 379ab4c2361SWeston Andros Adamson struct rpc_clnt **clntp, struct rpc_message *msg) 380ab4c2361SWeston Andros Adamson { 381ab4c2361SWeston Andros Adamson } 3828c21c62cSWeston Andros Adamson 3838c21c62cSWeston Andros Adamson static inline void 3848c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp, 385d45f60c6SWeston Andros Adamson struct rpc_message *msg, struct nfs_pgio_header *hdr) 3868c21c62cSWeston Andros Adamson { 3878c21c62cSWeston Andros Adamson } 388557134a3SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 3894ce79717STrond Myklebust 39097dc1359STrond Myklebust extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[]; 39129fba38bSBenny Halevy 3921549210fSTrond Myklebust extern const u32 nfs4_fattr_bitmap[3]; 393a09df2caSDavid Quigley extern const u32 nfs4_statfs_bitmap[3]; 394a09df2caSDavid Quigley extern const u32 nfs4_pathconf_bitmap[3]; 395dae100c2SFred Isaman extern const u32 nfs4_fsinfo_bitmap[3]; 396a09df2caSDavid Quigley extern const u32 nfs4_fs_locations_bitmap[3]; 3974ce79717STrond Myklebust 398abf79bb3SChuck Lever void nfs40_shutdown_client(struct nfs_client *); 399abf79bb3SChuck Lever void nfs41_shutdown_client(struct nfs_client *); 400abf79bb3SChuck Lever int nfs40_init_client(struct nfs_client *); 401abf79bb3SChuck Lever int nfs41_init_client(struct nfs_client *); 402cdb7ecedSBryan Schumaker void nfs4_free_client(struct nfs_client *); 403cdb7ecedSBryan Schumaker 4046663ee7fSBryan Schumaker struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *); 4056663ee7fSBryan Schumaker 4064ce79717STrond Myklebust /* nfs4renewd.c */ 407adfa6f98SDavid Howells extern void nfs4_schedule_state_renewal(struct nfs_client *); 4084ce79717STrond Myklebust extern void nfs4_renewd_prepare_shutdown(struct nfs_server *); 409adfa6f98SDavid Howells extern void nfs4_kill_renewd(struct nfs_client *); 41065f27f38SDavid Howells extern void nfs4_renew_state(struct work_struct *); 411fb10fb67STrond Myklebust extern void nfs4_set_lease_period(struct nfs_client *clp, 412fb10fb67STrond Myklebust unsigned long lease, 413fb10fb67STrond Myklebust unsigned long lastrenewed); 414fb10fb67STrond Myklebust 4154ce79717STrond Myklebust 4164ce79717STrond Myklebust /* nfs4state.c */ 41773d8bde5SChuck Lever struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp); 418fe20d7d5STrond Myklebust struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp); 4196dc9d57aSTrond Myklebust struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp); 42005f4c350SChuck Lever int nfs4_discover_server_trunking(struct nfs_client *clp, 42105f4c350SChuck Lever struct nfs_client **); 42205f4c350SChuck Lever int nfs40_discover_server_trunking(struct nfs_client *clp, 42305f4c350SChuck Lever struct nfs_client **, struct rpc_cred *); 424a7b72103SAndy Adamson #if defined(CONFIG_NFS_V4_1) 42505f4c350SChuck Lever int nfs41_discover_server_trunking(struct nfs_client *clp, 42605f4c350SChuck Lever struct nfs_client **, struct rpc_cred *); 4279f594791STrond Myklebust extern void nfs4_schedule_session_recovery(struct nfs4_session *, int); 4283f10a6afSAnna Schumaker extern void nfs41_notify_server(struct nfs_client *); 4290400a6b0STrond Myklebust #else 4309f594791STrond Myklebust static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err) 4310400a6b0STrond Myklebust { 4320400a6b0STrond Myklebust } 433a7b72103SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4344ce79717STrond Myklebust 435d1e284d5STrond Myklebust extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *, gfp_t); 4364ce79717STrond Myklebust extern void nfs4_put_state_owner(struct nfs4_state_owner *); 4370aaaf5c4SChuck Lever extern void nfs4_purge_state_owners(struct nfs_server *); 4384ce79717STrond Myklebust extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *); 4394ce79717STrond Myklebust extern void nfs4_put_open_state(struct nfs4_state *); 440643168c2SAl Viro extern void nfs4_close_state(struct nfs4_state *, fmode_t); 441643168c2SAl Viro extern void nfs4_close_sync(struct nfs4_state *, fmode_t); 442dc0b027dSTrond Myklebust extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t); 443a1d0b5eeSTrond Myklebust extern void nfs_inode_find_state_and_recover(struct inode *inode, 444a1d0b5eeSTrond Myklebust const nfs4_stateid *stateid); 4454f14c194STrond Myklebust extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *, struct nfs4_state *); 4460400a6b0STrond Myklebust extern void nfs4_schedule_lease_recovery(struct nfs_client *); 44733021279STrond Myklebust extern int nfs4_wait_clnt_recover(struct nfs_client *clp); 44833021279STrond Myklebust extern int nfs4_client_recover_expired_lease(struct nfs_client *clp); 449b0d3ded1STrond Myklebust extern void nfs4_schedule_state_manager(struct nfs_client *); 450042b60beSTrond Myklebust extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp); 4515d422301STrond Myklebust extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *); 452c9fdeb28SChuck Lever extern int nfs4_schedule_migration_recovery(const struct nfs_server *); 453b7f7a66eSChuck Lever extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *); 4540a014a44STrond Myklebust extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags, bool); 45578fe0f41SWeston Andros Adamson extern void nfs41_handle_server_scope(struct nfs_client *, 45679d4e1f0SChuck Lever struct nfs41_server_scope **); 457faf5f49cSTrond Myklebust extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp); 4588d0a8a9dSTrond Myklebust extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); 459abf4e13cSTrond Myklebust extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t, 460abf4e13cSTrond Myklebust const struct nfs_lockowner *, nfs4_stateid *, 461abf4e13cSTrond Myklebust struct rpc_cred **); 4624ce79717STrond Myklebust 4638535b2beSTrond Myklebust extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask); 464cee54fc9STrond Myklebust extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task); 465cee54fc9STrond Myklebust extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid); 466cee54fc9STrond Myklebust extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid); 46772211dbeSTrond Myklebust extern void nfs_release_seqid(struct nfs_seqid *seqid); 468cee54fc9STrond Myklebust extern void nfs_free_seqid(struct nfs_seqid *seqid); 469cb04ad2aSPeng Tao extern int nfs40_setup_sequence(struct nfs4_slot_table *tbl, 470cb04ad2aSPeng Tao struct nfs4_sequence_args *args, 471cb04ad2aSPeng Tao struct nfs4_sequence_res *res, 472cb04ad2aSPeng Tao struct rpc_task *task); 4732c4b131dSPeng Tao extern int nfs4_sequence_done(struct rpc_task *task, 4742c4b131dSPeng Tao struct nfs4_sequence_res *res); 475cee54fc9STrond Myklebust 4765ae67c4fSTrond Myklebust extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp); 477cf470c3eSTrond Myklebust 4784ce79717STrond Myklebust extern const nfs4_stateid zero_stateid; 4794ce79717STrond Myklebust 480129d1977SBryan Schumaker /* nfs4super.c */ 481fbdefd64SBryan Schumaker struct nfs_mount_info; 482ab7017a3SBryan Schumaker extern struct nfs_subversion nfs_v4; 483ff9099f2SBryan Schumaker struct dentry *nfs4_try_mount(int, const char *, struct nfs_mount_info *, struct nfs_subversion *); 484fac1e8e4SBryan Schumaker extern bool nfs4_disable_idmapping; 485fac1e8e4SBryan Schumaker extern unsigned short max_session_slots; 4865405fc44STrond Myklebust extern unsigned short max_session_cb_slots; 487fac1e8e4SBryan Schumaker extern unsigned short send_implementation_id; 488f6de7a39STrond Myklebust extern bool recover_lost_locks; 48989d77c8fSBryan Schumaker 4906f2ea7f2SChuck Lever #define NFS4_CLIENT_ID_UNIQ_LEN (64) 4916f2ea7f2SChuck Lever extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN]; 4926f2ea7f2SChuck Lever 493466bfe7fSBryan Schumaker /* nfs4sysctl.c */ 494466bfe7fSBryan Schumaker #ifdef CONFIG_SYSCTL 495466bfe7fSBryan Schumaker int nfs4_register_sysctl(void); 496466bfe7fSBryan Schumaker void nfs4_unregister_sysctl(void); 497466bfe7fSBryan Schumaker #else 498466bfe7fSBryan Schumaker static inline int nfs4_register_sysctl(void) 499466bfe7fSBryan Schumaker { 500466bfe7fSBryan Schumaker return 0; 501466bfe7fSBryan Schumaker } 502466bfe7fSBryan Schumaker 5030add3e85SRandy Dunlap static inline void nfs4_unregister_sysctl(void) 504466bfe7fSBryan Schumaker { 505466bfe7fSBryan Schumaker } 506466bfe7fSBryan Schumaker #endif 507466bfe7fSBryan Schumaker 5084ce79717STrond Myklebust /* nfs4xdr.c */ 5094ce79717STrond Myklebust extern struct rpc_procinfo nfs4_procedures[]; 5104ce79717STrond Myklebust 5114ce79717STrond Myklebust struct nfs4_mount_data; 5124ce79717STrond Myklebust 5134ce79717STrond Myklebust /* callback_xdr.c */ 5144ce79717STrond Myklebust extern struct svc_version nfs4_callback_version1; 51507bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4; 5164ce79717STrond Myklebust 517f597c537STrond Myklebust static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src) 518f597c537STrond Myklebust { 51993b717fdSTrond Myklebust memcpy(dst->data, src->data, sizeof(dst->data)); 52093b717fdSTrond Myklebust dst->type = src->type; 521f597c537STrond Myklebust } 522f597c537STrond Myklebust 523f597c537STrond Myklebust static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src) 524f597c537STrond Myklebust { 52593b717fdSTrond Myklebust if (dst->type != src->type) 52693b717fdSTrond Myklebust return false; 52793b717fdSTrond Myklebust return memcmp(dst->data, src->data, sizeof(dst->data)) == 0; 528f597c537STrond Myklebust } 529f597c537STrond Myklebust 530e999e80eSTrond Myklebust static inline bool nfs4_stateid_match_other(const nfs4_stateid *dst, const nfs4_stateid *src) 531e999e80eSTrond Myklebust { 532e999e80eSTrond Myklebust return memcmp(dst->other, src->other, NFS4_STATEID_OTHER_SIZE) == 0; 533e999e80eSTrond Myklebust } 534e999e80eSTrond Myklebust 535e999e80eSTrond Myklebust static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stateid *s2) 536e999e80eSTrond Myklebust { 537e999e80eSTrond Myklebust return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0; 538e999e80eSTrond Myklebust } 539e999e80eSTrond Myklebust 5405d422301STrond Myklebust static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state) 5415d422301STrond Myklebust { 5425d422301STrond Myklebust return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0; 5435d422301STrond Myklebust } 5445d422301STrond Myklebust 5453e7dfb16STrond Myklebust static inline bool nfs4_state_match_open_stateid_other(const struct nfs4_state *state, 5463e7dfb16STrond Myklebust const nfs4_stateid *stateid) 5473e7dfb16STrond Myklebust { 5483e7dfb16STrond Myklebust return test_bit(NFS_OPEN_STATE, &state->flags) && 5493e7dfb16STrond Myklebust nfs4_stateid_match_other(&state->open_stateid, stateid); 5503e7dfb16STrond Myklebust } 5513e7dfb16STrond Myklebust 5524ce79717STrond Myklebust #else 5534ce79717STrond Myklebust 554643168c2SAl Viro #define nfs4_close_state(a, b) do { } while (0) 555643168c2SAl Viro #define nfs4_close_sync(a, b) do { } while (0) 5568c21c62cSWeston Andros Adamson #define nfs4_state_protect(a, b, c, d) do { } while (0) 5578c21c62cSWeston Andros Adamson #define nfs4_state_protect_write(a, b, c, d) do { } while (0) 5584ce79717STrond Myklebust 5594ce79717STrond Myklebust #endif /* CONFIG_NFS_V4 */ 5604ce79717STrond Myklebust #endif /* __LINUX_FS_NFS_NFS4_FS.H */ 561