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> 26c137afabSTrond Myklebust 274ce79717STrond Myklebust struct idmap; 284ce79717STrond Myklebust 294ce79717STrond Myklebust enum nfs4_client_state { 30e005e804STrond Myklebust NFS4CLNT_MANAGER_RUNNING = 0, 31e598d843STrond Myklebust NFS4CLNT_CHECK_LEASE, 3258d9714aSTrond Myklebust NFS4CLNT_LEASE_EXPIRED, 33b79a4a1bSTrond Myklebust NFS4CLNT_RECLAIM_REBOOT, 34b79a4a1bSTrond Myklebust NFS4CLNT_RECLAIM_NOGRACE, 35707fb4b3STrond Myklebust NFS4CLNT_DELEGRETURN, 366df08189SAndy Adamson NFS4CLNT_SESSION_RESET, 37fd954ae1STrond Myklebust NFS4CLNT_LEASE_CONFIRM, 3878fe0f41SWeston Andros Adamson NFS4CLNT_SERVER_SCOPE_MISMATCH, 392c820d9aSChuck Lever NFS4CLNT_PURGE_STATE, 40a9e64442SWeston Andros Adamson NFS4CLNT_BIND_CONN_TO_SESSION, 41c9fdeb28SChuck Lever NFS4CLNT_MOVED, 42b7f7a66eSChuck Lever NFS4CLNT_LEASE_MOVED, 4345870d69STrond Myklebust NFS4CLNT_DELEGATION_EXPIRED, 44aeabb3c9STrond Myklebust NFS4CLNT_RUN_MANAGER, 45b5fdf841STrond Myklebust NFS4CLNT_RECALL_RUNNING, 46b5fdf841STrond Myklebust NFS4CLNT_RECALL_ANY_LAYOUT_READ, 47b5fdf841STrond Myklebust NFS4CLNT_RECALL_ANY_LAYOUT_RW, 484ce79717STrond Myklebust }; 494ce79717STrond Myklebust 502f60ea6bSTrond Myklebust #define NFS4_RENEW_TIMEOUT 0x01 512f60ea6bSTrond Myklebust #define NFS4_RENEW_DELEGATION_CB 0x02 522f60ea6bSTrond Myklebust 5363f5f796STrond Myklebust struct nfs_seqid_counter; 5497dc1359STrond Myklebust struct nfs4_minor_version_ops { 5597dc1359STrond Myklebust u32 minor_version; 5639c6daaeSTrond Myklebust unsigned init_caps; 5797dc1359STrond Myklebust 58abf79bb3SChuck Lever int (*init_client)(struct nfs_client *); 59abf79bb3SChuck Lever void (*shutdown_client)(struct nfs_client *); 6036281caaSTrond Myklebust bool (*match_stateid)(const nfs4_stateid *, 61e047a10cSTrond Myklebust const nfs4_stateid *); 62fca78d6dSBryan Schumaker int (*find_root_sec)(struct nfs_server *, struct nfs_fh *, 63fca78d6dSBryan Schumaker struct nfs_fsinfo *); 64f1cdae87SJeff Layton void (*free_lock_state)(struct nfs_server *, 65c8b2d0bfSTrond Myklebust struct nfs4_lock_state *); 6645870d69STrond Myklebust int (*test_and_free_expired)(struct nfs_server *, 67a52458b4SNeilBrown nfs4_stateid *, const struct cred *); 6863f5f796STrond Myklebust struct nfs_seqid * 6963f5f796STrond Myklebust (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); 7010e037d1SSantosh kumar pradhan void (*session_trunk)(struct rpc_clnt *clnt, 7110e037d1SSantosh kumar pradhan struct rpc_xprt *xprt, void *data); 729915ea7eSChuck Lever const struct rpc_call_ops *call_sync_ops; 73c48f4f35STrond Myklebust const struct nfs4_state_recovery_ops *reboot_recovery_ops; 74c48f4f35STrond Myklebust const struct nfs4_state_recovery_ops *nograce_recovery_ops; 75c48f4f35STrond Myklebust const struct nfs4_state_maintenance_ops *state_renewal_ops; 76ec011fe8SChuck Lever const struct nfs4_mig_recovery_ops *mig_recovery_ops; 7797dc1359STrond Myklebust }; 7897dc1359STrond Myklebust 79cee54fc9STrond Myklebust #define NFS_SEQID_CONFIRMED 1 80cee54fc9STrond Myklebust struct nfs_seqid_counter { 8195b72eb0STrond Myklebust ktime_t create_time; 8248c22eb2STrond Myklebust int owner_id; 83cee54fc9STrond Myklebust int flags; 84cee54fc9STrond Myklebust u32 counter; 857ba127abSTrond Myklebust spinlock_t lock; /* Protects the list */ 867ba127abSTrond Myklebust struct list_head list; /* Defines sequence of RPC calls */ 877ba127abSTrond Myklebust struct rpc_wait_queue wait; /* RPC call delay queue */ 88cee54fc9STrond Myklebust }; 89cee54fc9STrond Myklebust 90cee54fc9STrond Myklebust struct nfs_seqid { 91cee54fc9STrond Myklebust struct nfs_seqid_counter *sequence; 924e51336aSTrond Myklebust struct list_head list; 934601df20STrond Myklebust struct rpc_task *task; 94cee54fc9STrond Myklebust }; 95cee54fc9STrond Myklebust 96cee54fc9STrond Myklebust static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status) 97cee54fc9STrond Myklebust { 98cee54fc9STrond Myklebust if (seqid_mutating_err(-status)) 99cee54fc9STrond Myklebust seqid->flags |= NFS_SEQID_CONFIRMED; 100cee54fc9STrond Myklebust } 101cee54fc9STrond Myklebust 102cee54fc9STrond Myklebust /* 1034ce79717STrond Myklebust * NFS4 state_owners and lock_owners are simply labels for ordered 1044ce79717STrond Myklebust * sequences of RPC calls. Their sole purpose is to provide once-only 1054ce79717STrond Myklebust * semantics by allowing the server to identify replayed requests. 1064ce79717STrond Myklebust */ 1074ce79717STrond Myklebust struct nfs4_state_owner { 1086f2e64d3STrond Myklebust struct nfs_server *so_server; 1090aaaf5c4SChuck Lever struct list_head so_lru; 1100aaaf5c4SChuck Lever unsigned long so_expires; 11124d292b8SChuck Lever struct rb_node so_server_node; 1124ce79717STrond Myklebust 113a52458b4SNeilBrown const struct cred *so_cred; /* Associated cred */ 1149f958ab8STrond Myklebust 1159f958ab8STrond Myklebust spinlock_t so_lock; 1169f958ab8STrond Myklebust atomic_t so_count; 1177eff03aeSTrond Myklebust unsigned long so_flags; 1184ce79717STrond Myklebust struct list_head so_states; 119cee54fc9STrond Myklebust struct nfs_seqid_counter so_seqid; 120c137afabSTrond Myklebust seqcount_t so_reclaim_seqcount; 12165b62a29STrond Myklebust struct mutex so_delegreturn_mutex; 1224ce79717STrond Myklebust }; 1234ce79717STrond Myklebust 1247eff03aeSTrond Myklebust enum { 1257eff03aeSTrond Myklebust NFS_OWNER_RECLAIM_REBOOT, 1267eff03aeSTrond Myklebust NFS_OWNER_RECLAIM_NOGRACE 1277eff03aeSTrond Myklebust }; 1287eff03aeSTrond Myklebust 129afe6c27cSAlexandros Batsakis #define NFS_LOCK_NEW 0 130afe6c27cSAlexandros Batsakis #define NFS_LOCK_RECLAIM 1 131afe6c27cSAlexandros Batsakis #define NFS_LOCK_EXPIRED 2 132afe6c27cSAlexandros Batsakis 1334ce79717STrond Myklebust /* 1344ce79717STrond Myklebust * struct nfs4_state maintains the client-side state for a given 1354ce79717STrond Myklebust * (state_owner,inode) tuple (OPEN) or state_owner (LOCK). 1364ce79717STrond Myklebust * 1374ce79717STrond Myklebust * OPEN: 1384ce79717STrond Myklebust * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server, 1394ce79717STrond Myklebust * we need to know how many files are open for reading or writing on a 1404ce79717STrond Myklebust * given inode. This information too is stored here. 1414ce79717STrond Myklebust * 1424ce79717STrond Myklebust * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN) 1434ce79717STrond Myklebust */ 1444ce79717STrond Myklebust 1454ce79717STrond Myklebust struct nfs4_lock_state { 1464ce79717STrond Myklebust struct list_head ls_locks; /* Other lock stateids */ 1478d0a8a9dSTrond Myklebust struct nfs4_state * ls_state; /* Pointer to open state */ 148795a88c9STrond Myklebust #define NFS_LOCK_INITIALIZED 0 149ef1820f9SNeilBrown #define NFS_LOCK_LOST 1 150795a88c9STrond Myklebust unsigned long ls_flags; 151cee54fc9STrond Myklebust struct nfs_seqid_counter ls_seqid; 1524ce79717STrond Myklebust nfs4_stateid ls_stateid; 153194bc1f4SElena Reshetova refcount_t ls_count; 1548003d3c4SJeff Layton fl_owner_t ls_owner; 1554ce79717STrond Myklebust }; 1564ce79717STrond Myklebust 1574ce79717STrond Myklebust /* bits for nfs4_state->flags */ 1584ce79717STrond Myklebust enum { 1594ce79717STrond Myklebust LK_STATE_IN_USE, 160003707c7STrond Myklebust NFS_DELEGATED_STATE, /* Current stateid is delegation */ 16192b40e93STrond Myklebust NFS_OPEN_STATE, /* OPEN stateid is set */ 162003707c7STrond Myklebust NFS_O_RDONLY_STATE, /* OPEN stateid has read-only state */ 163003707c7STrond Myklebust NFS_O_WRONLY_STATE, /* OPEN stateid has write-only state */ 164003707c7STrond Myklebust NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */ 165b79a4a1bSTrond Myklebust NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */ 166b79a4a1bSTrond Myklebust NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */ 1678e469ebdSTrond Myklebust NFS_STATE_POSIX_LOCKS, /* Posix locks are supported */ 1685d422301STrond Myklebust NFS_STATE_RECOVERY_FAILED, /* OPEN stateid state recovery failed */ 169a8ce377aSJeff Layton NFS_STATE_MAY_NOTIFY_LOCK, /* server may CB_NOTIFY_LOCK */ 170c9399f21STrond Myklebust NFS_STATE_CHANGE_WAIT, /* A state changing operation is outstanding */ 171e4648aa4SOlga Kornievskaia NFS_CLNT_DST_SSC_COPY_STATE, /* dst server open state on client*/ 1720e65a32cSOlga Kornievskaia NFS_CLNT_SRC_SSC_COPY_STATE, /* src server open state on client*/ 1730b9018b9SOlga Kornievskaia NFS_SRV_SSC_COPY_STATE, /* ssc state on the dst server */ 1744ce79717STrond Myklebust }; 1754ce79717STrond Myklebust 1764ce79717STrond Myklebust struct nfs4_state { 1774ce79717STrond Myklebust struct list_head open_states; /* List of states for the same state_owner */ 1784ce79717STrond Myklebust struct list_head inode_states; /* List of states for the same inode */ 1794ce79717STrond Myklebust struct list_head lock_states; /* List of subservient lock stateids */ 1804ce79717STrond Myklebust 1814ce79717STrond Myklebust struct nfs4_state_owner *owner; /* Pointer to the open owner */ 1824ce79717STrond Myklebust struct inode *inode; /* Pointer to the inode */ 1834ce79717STrond Myklebust 1844ce79717STrond Myklebust unsigned long flags; /* Do we hold any locks? */ 1858d0a8a9dSTrond Myklebust spinlock_t state_lock; /* Protects the lock_states list */ 1864ce79717STrond Myklebust 1878bda4e4cSTrond Myklebust seqlock_t seqlock; /* Protects the stateid/open_stateid */ 188003707c7STrond Myklebust nfs4_stateid stateid; /* Current stateid: may be delegation */ 189003707c7STrond Myklebust nfs4_stateid open_stateid; /* OPEN stateid */ 1904ce79717STrond Myklebust 1918bda4e4cSTrond Myklebust /* The following 3 fields are protected by owner->so_lock */ 192003707c7STrond Myklebust unsigned int n_rdonly; /* Number of read-only references */ 193003707c7STrond Myklebust unsigned int n_wronly; /* Number of write-only references */ 194003707c7STrond Myklebust unsigned int n_rdwr; /* Number of read/write references */ 195dc0b027dSTrond Myklebust fmode_t state; /* State on the server (R,W, or RW) */ 196ace9fad4STrond Myklebust refcount_t count; 197c9399f21STrond Myklebust 198c9399f21STrond Myklebust wait_queue_head_t waitq; 1999ae075fdSTrond Myklebust struct rcu_head rcu_head; 2004ce79717STrond Myklebust }; 2014ce79717STrond Myklebust 2024ce79717STrond Myklebust 2034ce79717STrond Myklebust struct nfs4_exception { 2049e33bed5STrond Myklebust struct nfs4_state *state; 2053114ea7aSTrond Myklebust struct inode *inode; 2068487c479STrond Myklebust nfs4_stateid *stateid; 207b3c2aa07STrond Myklebust long timeout; 208b3c2aa07STrond Myklebust unsigned char delay : 1, 209b3c2aa07STrond Myklebust recovering : 1, 210b3c2aa07STrond Myklebust retry : 1; 2110688e64bSTrond Myklebust bool interruptible; 2124ce79717STrond Myklebust }; 2134ce79717STrond Myklebust 2144ce79717STrond Myklebust struct nfs4_state_recovery_ops { 2157eff03aeSTrond Myklebust int owner_flag_bit; 216b79a4a1bSTrond Myklebust int state_flag_bit; 2174ce79717STrond Myklebust int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *); 2184ce79717STrond Myklebust int (*recover_lock)(struct nfs4_state *, struct file_lock *); 219a52458b4SNeilBrown int (*establish_clid)(struct nfs_client *, const struct cred *); 220a52458b4SNeilBrown int (*reclaim_complete)(struct nfs_client *, const struct cred *); 22105f4c350SChuck Lever int (*detect_trunking)(struct nfs_client *, struct nfs_client **, 222a52458b4SNeilBrown const struct cred *); 2234ce79717STrond Myklebust }; 2244ce79717STrond Myklebust 2251b146fcfSFred Isaman struct nfs4_opendata { 2261b146fcfSFred Isaman struct kref kref; 2271b146fcfSFred Isaman struct nfs_openargs o_arg; 2281b146fcfSFred Isaman struct nfs_openres o_res; 2291b146fcfSFred Isaman struct nfs_open_confirmargs c_arg; 2301b146fcfSFred Isaman struct nfs_open_confirmres c_res; 2311b146fcfSFred Isaman struct nfs4_string owner_name; 2321b146fcfSFred Isaman struct nfs4_string group_name; 2331b146fcfSFred Isaman struct nfs4_label *a_label; 2341b146fcfSFred Isaman struct nfs_fattr f_attr; 2351b146fcfSFred Isaman struct nfs4_label *f_label; 2361b146fcfSFred Isaman struct dentry *dir; 2371b146fcfSFred Isaman struct dentry *dentry; 2381b146fcfSFred Isaman struct nfs4_state_owner *owner; 2391b146fcfSFred Isaman struct nfs4_state *state; 2401b146fcfSFred Isaman struct iattr attrs; 2411b146fcfSFred Isaman struct nfs4_layoutget *lgp; 2421b146fcfSFred Isaman unsigned long timestamp; 2431b146fcfSFred Isaman bool rpc_done; 2441b146fcfSFred Isaman bool file_created; 2451b146fcfSFred Isaman bool is_recover; 2461b146fcfSFred Isaman bool cancelled; 2471b146fcfSFred Isaman int rpc_status; 2481b146fcfSFred Isaman }; 2491b146fcfSFred Isaman 25004fa2c6bSAndy Adamson struct nfs4_add_xprt_data { 25104fa2c6bSAndy Adamson struct nfs_client *clp; 252a52458b4SNeilBrown const struct cred *cred; 25304fa2c6bSAndy Adamson }; 25404fa2c6bSAndy Adamson 25529fba38bSBenny Halevy struct nfs4_state_maintenance_ops { 256a52458b4SNeilBrown int (*sched_state_renewal)(struct nfs_client *, const struct cred *, unsigned); 257a52458b4SNeilBrown const struct cred * (*get_state_renewal_cred)(struct nfs_client *); 258a52458b4SNeilBrown int (*renew_lease)(struct nfs_client *, const struct cred *); 25929fba38bSBenny Halevy }; 26029fba38bSBenny Halevy 261ec011fe8SChuck Lever struct nfs4_mig_recovery_ops { 262b03d735bSChuck Lever int (*get_locations)(struct inode *, struct nfs4_fs_locations *, 263a52458b4SNeilBrown struct page *, const struct cred *); 264a52458b4SNeilBrown int (*fsid_present)(struct inode *, const struct cred *); 265ec011fe8SChuck Lever }; 266ec011fe8SChuck Lever 267f786aa90SAl Viro extern const struct dentry_operations nfs4_dentry_operations; 26873a79706SBryan Schumaker 26973a79706SBryan Schumaker /* dir.c */ 27073a79706SBryan Schumaker int nfs_atomic_open(struct inode *, struct dentry *, struct file *, 27144907d79SAl Viro unsigned, umode_t); 2726b3b5496SJ. Bruce Fields 273f2aedb71SDavid Howells /* fs_context.c */ 2741ae811eeSbjschuma@gmail.com extern struct file_system_type nfs4_fs_type; 2751ae811eeSbjschuma@gmail.com 27672de53ecSBryan Schumaker /* nfs4namespace.c */ 277beffb8feSAl Viro struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *, 278beffb8feSAl Viro const struct qstr *); 279f2aedb71SDavid Howells int nfs4_submount(struct fs_context *, struct nfs_server *); 280800c06a5SChuck Lever int nfs4_replace_transport(struct nfs_server *server, 281800c06a5SChuck Lever const struct nfs4_fs_locations *locations); 28272de53ecSBryan Schumaker 2834ce79717STrond Myklebust /* nfs4proc.c */ 284f4ac1674SAnna Schumaker extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *); 2850f913a57SOlga Kornievskaia extern int nfs4_async_handle_error(struct rpc_task *task, 2860f913a57SOlga Kornievskaia struct nfs_server *server, 2870f913a57SOlga Kornievskaia struct nfs4_state *state, long *timeout); 2881c6dcbe5SAnna Schumaker extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *, 2891c6dcbe5SAnna Schumaker struct rpc_message *, struct nfs4_sequence_args *, 2901c6dcbe5SAnna Schumaker struct nfs4_sequence_res *, int); 291fba83f34SAnna Schumaker extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int); 292a52458b4SNeilBrown extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *); 293a52458b4SNeilBrown extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *); 2945e6b1990STrond Myklebust extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool); 295a52458b4SNeilBrown extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred); 296a52458b4SNeilBrown extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred); 29766245539STrond Myklebust extern int nfs4_destroy_clientid(struct nfs_client *clp); 298a52458b4SNeilBrown extern int nfs4_init_clientid(struct nfs_client *, const struct cred *); 299a52458b4SNeilBrown extern int nfs41_init_clientid(struct nfs_client *, const struct cred *); 3001f7977c1STrond Myklebust extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait); 30155a97593STrond Myklebust extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); 302f05d147fSBryan Schumaker extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *, 303f05d147fSBryan Schumaker struct nfs4_fs_locations *, struct page *); 304b03d735bSChuck Lever extern int nfs4_proc_get_locations(struct inode *, struct nfs4_fs_locations *, 305a52458b4SNeilBrown struct page *page, const struct cred *); 306a52458b4SNeilBrown extern int nfs4_proc_fsid_present(struct inode *, const struct cred *); 307f7b37b8bSTrond Myklebust extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, 308f7b37b8bSTrond Myklebust struct dentry *, 309f7b37b8bSTrond Myklebust struct nfs_fh *, 310f7b37b8bSTrond Myklebust struct nfs_fattr *); 31172de53ecSBryan Schumaker extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *); 31264c2ce8bSAneesh Kumar K.V extern const struct xattr_handler *nfs4_xattr_handlers[]; 3135521abfdSTrond Myklebust extern int nfs4_set_rw_stateid(nfs4_stateid *stateid, 3149b206149STrond Myklebust const struct nfs_open_context *ctx, 3159b206149STrond Myklebust const struct nfs_lock_context *l_ctx, 3169b206149STrond Myklebust fmode_t fmode); 317ec4b0925SOlga Kornievskaia extern int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, 318ec4b0925SOlga Kornievskaia struct nfs_fattr *fattr, struct nfs4_label *label, 319ec4b0925SOlga Kornievskaia struct inode *inode); 320ec4b0925SOlga Kornievskaia extern int update_open_stateid(struct nfs4_state *state, 321ec4b0925SOlga Kornievskaia const nfs4_stateid *open_stateid, 322ec4b0925SOlga Kornievskaia const nfs4_stateid *deleg_stateid, 323ec4b0925SOlga Kornievskaia fmode_t fmode); 3244ce79717STrond Myklebust 3250efb01b2SDonald Buczek extern int nfs4_proc_get_lease_time(struct nfs_client *clp, 3260efb01b2SDonald Buczek struct nfs_fsinfo *fsinfo); 3271b523ca9SFrank van der Linden extern void nfs4_update_changeattr(struct inode *dir, 3281b523ca9SFrank van der Linden struct nfs4_change_info *cinfo, 3291b523ca9SFrank van der Linden unsigned long timestamp, 3301b523ca9SFrank van der Linden unsigned long cache_validity); 3311b523ca9SFrank van der Linden 332557134a3SAndy Adamson #if defined(CONFIG_NFS_V4_1) 333f9c96fccSAndy Adamson extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *); 334a52458b4SNeilBrown extern int nfs4_proc_create_session(struct nfs_client *, const struct cred *); 335a52458b4SNeilBrown extern int nfs4_proc_destroy_session(struct nfs4_session *, const struct cred *); 336863a3c6cSAndy Adamson extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, 337ef311537SAndy Adamson bool sync); 338ba84db96SAndy Adamson extern int nfs4_detect_session_trunking(struct nfs_client *clp, 339ba84db96SAndy Adamson struct nfs41_exchange_id_res *res, struct rpc_xprt *xprt); 34094de8b27SAndy Adamson 34194de8b27SAndy Adamson static inline bool 34294de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp) 34394de8b27SAndy Adamson { 34494de8b27SAndy Adamson return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) == 34594de8b27SAndy Adamson EXCHGID4_FLAG_USE_PNFS_DS; 34694de8b27SAndy Adamson } 347d83217c1SAndy Adamson 348d83217c1SAndy Adamson static inline bool 349d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp) 350d83217c1SAndy Adamson { 351d83217c1SAndy Adamson return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS; 352d83217c1SAndy Adamson } 353ab4c2361SWeston Andros Adamson 3548c21c62cSWeston Andros Adamson static inline bool 3558c21c62cSWeston Andros Adamson _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode, 356ab4c2361SWeston Andros Adamson struct rpc_clnt **clntp, struct rpc_message *msg) 357ab4c2361SWeston Andros Adamson { 358ab4c2361SWeston Andros Adamson rpc_authflavor_t flavor; 359ab4c2361SWeston Andros Adamson 360b79e87e0SNeilBrown if (sp4_mode == NFS_SP4_MACH_CRED_CLEANUP || 361b79e87e0SNeilBrown sp4_mode == NFS_SP4_MACH_CRED_PNFS_CLEANUP) { 362b79e87e0SNeilBrown /* Using machine creds for cleanup operations 363b79e87e0SNeilBrown * is only relevent if the client credentials 364b79e87e0SNeilBrown * might expire. So don't bother for 365b79e87e0SNeilBrown * RPC_AUTH_UNIX. If file was only exported to 366b79e87e0SNeilBrown * sec=sys, the PUTFH would fail anyway. 367b79e87e0SNeilBrown */ 368b79e87e0SNeilBrown if ((*clntp)->cl_auth->au_flavor == RPC_AUTH_UNIX) 369b79e87e0SNeilBrown return false; 370b79e87e0SNeilBrown } 371ab4c2361SWeston Andros Adamson if (test_bit(sp4_mode, &clp->cl_sp4_flags)) { 3725e16923bSNeilBrown msg->rpc_cred = rpc_machine_cred(); 373ab4c2361SWeston Andros Adamson 374ab4c2361SWeston Andros Adamson flavor = clp->cl_rpcclient->cl_auth->au_flavor; 375312cd958SWeston Andros Adamson WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I && 376ab4c2361SWeston Andros Adamson flavor != RPC_AUTH_GSS_KRB5P); 377ab4c2361SWeston Andros Adamson *clntp = clp->cl_rpcclient; 3788c21c62cSWeston Andros Adamson 3798c21c62cSWeston Andros Adamson return true; 380ab4c2361SWeston Andros Adamson } 3818c21c62cSWeston Andros Adamson return false; 3828c21c62cSWeston Andros Adamson } 3838c21c62cSWeston Andros Adamson 3848c21c62cSWeston Andros Adamson /* 3858c21c62cSWeston Andros Adamson * Function responsible for determining if an rpc_message should use the 3868c21c62cSWeston Andros Adamson * machine cred under SP4_MACH_CRED and if so switching the credential and 3878c21c62cSWeston Andros Adamson * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p). 3888c21c62cSWeston Andros Adamson * Should be called before rpc_call_sync/rpc_call_async. 3898c21c62cSWeston Andros Adamson */ 3908c21c62cSWeston Andros Adamson static inline void 3918c21c62cSWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode, 3928c21c62cSWeston Andros Adamson struct rpc_clnt **clntp, struct rpc_message *msg) 3938c21c62cSWeston Andros Adamson { 3948c21c62cSWeston Andros Adamson _nfs4_state_protect(clp, sp4_mode, clntp, msg); 3958c21c62cSWeston Andros Adamson } 3968c21c62cSWeston Andros Adamson 3978c21c62cSWeston Andros Adamson /* 3988c21c62cSWeston Andros Adamson * Special wrapper to nfs4_state_protect for write. 3998c21c62cSWeston Andros Adamson * If WRITE can use machine cred but COMMIT cannot, make sure all writes 4008c21c62cSWeston Andros Adamson * that use machine cred use NFS_FILE_SYNC. 4018c21c62cSWeston Andros Adamson */ 4028c21c62cSWeston Andros Adamson static inline void 4038c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp, 404d45f60c6SWeston Andros Adamson struct rpc_message *msg, struct nfs_pgio_header *hdr) 4058c21c62cSWeston Andros Adamson { 4068c21c62cSWeston Andros Adamson if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) && 4078c21c62cSWeston Andros Adamson !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags)) 408d45f60c6SWeston Andros Adamson hdr->args.stable = NFS_FILE_SYNC; 409ab4c2361SWeston Andros Adamson } 410fbcd4abcSAndy Adamson #else /* CONFIG_NFS_v4_1 */ 41194de8b27SAndy Adamson static inline bool 41294de8b27SAndy Adamson is_ds_only_client(struct nfs_client *clp) 41394de8b27SAndy Adamson { 41494de8b27SAndy Adamson return false; 41594de8b27SAndy Adamson } 416d83217c1SAndy Adamson 417d83217c1SAndy Adamson static inline bool 418d83217c1SAndy Adamson is_ds_client(struct nfs_client *clp) 419d83217c1SAndy Adamson { 420d83217c1SAndy Adamson return false; 421d83217c1SAndy Adamson } 422ab4c2361SWeston Andros Adamson 423ab4c2361SWeston Andros Adamson static inline void 424ab4c2361SWeston Andros Adamson nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags, 425ab4c2361SWeston Andros Adamson struct rpc_clnt **clntp, struct rpc_message *msg) 426ab4c2361SWeston Andros Adamson { 427ab4c2361SWeston Andros Adamson } 4288c21c62cSWeston Andros Adamson 4298c21c62cSWeston Andros Adamson static inline void 4308c21c62cSWeston Andros Adamson nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp, 431d45f60c6SWeston Andros Adamson struct rpc_message *msg, struct nfs_pgio_header *hdr) 4328c21c62cSWeston Andros Adamson { 4338c21c62cSWeston Andros Adamson } 434557134a3SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4354ce79717STrond Myklebust 43697dc1359STrond Myklebust extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[]; 43729fba38bSBenny Halevy 4381549210fSTrond Myklebust extern const u32 nfs4_fattr_bitmap[3]; 439a09df2caSDavid Quigley extern const u32 nfs4_statfs_bitmap[3]; 440a09df2caSDavid Quigley extern const u32 nfs4_pathconf_bitmap[3]; 441dae100c2SFred Isaman extern const u32 nfs4_fsinfo_bitmap[3]; 442a09df2caSDavid Quigley extern const u32 nfs4_fs_locations_bitmap[3]; 4434ce79717STrond Myklebust 444abf79bb3SChuck Lever void nfs40_shutdown_client(struct nfs_client *); 445abf79bb3SChuck Lever void nfs41_shutdown_client(struct nfs_client *); 446abf79bb3SChuck Lever int nfs40_init_client(struct nfs_client *); 447abf79bb3SChuck Lever int nfs41_init_client(struct nfs_client *); 448cdb7ecedSBryan Schumaker void nfs4_free_client(struct nfs_client *); 449cdb7ecedSBryan Schumaker 4506663ee7fSBryan Schumaker struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *); 4516663ee7fSBryan Schumaker 4524ce79717STrond Myklebust /* nfs4renewd.c */ 453adfa6f98SDavid Howells extern void nfs4_schedule_state_renewal(struct nfs_client *); 4544ce79717STrond Myklebust extern void nfs4_renewd_prepare_shutdown(struct nfs_server *); 455adfa6f98SDavid Howells extern void nfs4_kill_renewd(struct nfs_client *); 45665f27f38SDavid Howells extern void nfs4_renew_state(struct work_struct *); 4577dc2993aSRobert Milkowski extern void nfs4_set_lease_period(struct nfs_client *clp, unsigned long lease); 458fb10fb67STrond Myklebust 4594ce79717STrond Myklebust 4604ce79717STrond Myklebust /* nfs4state.c */ 461d49dd117SBen Dooks extern const nfs4_stateid current_stateid; 462d49dd117SBen Dooks 463a52458b4SNeilBrown const struct cred *nfs4_get_clid_cred(struct nfs_client *clp); 464a52458b4SNeilBrown const struct cred *nfs4_get_machine_cred(struct nfs_client *clp); 465a52458b4SNeilBrown const struct cred *nfs4_get_renew_cred(struct nfs_client *clp); 46605f4c350SChuck Lever int nfs4_discover_server_trunking(struct nfs_client *clp, 46705f4c350SChuck Lever struct nfs_client **); 46805f4c350SChuck Lever int nfs40_discover_server_trunking(struct nfs_client *clp, 469a52458b4SNeilBrown struct nfs_client **, const struct cred *); 470a7b72103SAndy Adamson #if defined(CONFIG_NFS_V4_1) 47105f4c350SChuck Lever int nfs41_discover_server_trunking(struct nfs_client *clp, 472a52458b4SNeilBrown struct nfs_client **, const struct cred *); 4739f594791STrond Myklebust extern void nfs4_schedule_session_recovery(struct nfs4_session *, int); 4743f10a6afSAnna Schumaker extern void nfs41_notify_server(struct nfs_client *); 4750491567bSOlga Kornievskaia bool nfs4_check_serverowner_major_id(struct nfs41_server_owner *o1, 4760491567bSOlga Kornievskaia struct nfs41_server_owner *o2); 4770400a6b0STrond Myklebust #else 4789f594791STrond Myklebust static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err) 4790400a6b0STrond Myklebust { 4800400a6b0STrond Myklebust } 481a7b72103SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4824ce79717STrond Myklebust 483a52458b4SNeilBrown extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, const struct cred *, gfp_t); 4844ce79717STrond Myklebust extern void nfs4_put_state_owner(struct nfs4_state_owner *); 485c77e2283STrond Myklebust extern void nfs4_purge_state_owners(struct nfs_server *, struct list_head *); 486c77e2283STrond Myklebust extern void nfs4_free_state_owners(struct list_head *head); 4874ce79717STrond Myklebust extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *); 4884ce79717STrond Myklebust extern void nfs4_put_open_state(struct nfs4_state *); 489643168c2SAl Viro extern void nfs4_close_state(struct nfs4_state *, fmode_t); 490643168c2SAl Viro extern void nfs4_close_sync(struct nfs4_state *, fmode_t); 491dc0b027dSTrond Myklebust extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t); 492a1d0b5eeSTrond Myklebust extern void nfs_inode_find_state_and_recover(struct inode *inode, 493a1d0b5eeSTrond Myklebust const nfs4_stateid *stateid); 4944f14c194STrond Myklebust extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *, struct nfs4_state *); 4950400a6b0STrond Myklebust extern void nfs4_schedule_lease_recovery(struct nfs_client *); 49633021279STrond Myklebust extern int nfs4_wait_clnt_recover(struct nfs_client *clp); 49733021279STrond Myklebust extern int nfs4_client_recover_expired_lease(struct nfs_client *clp); 498b0d3ded1STrond Myklebust extern void nfs4_schedule_state_manager(struct nfs_client *); 499042b60beSTrond Myklebust extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp); 5005d422301STrond Myklebust extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *); 501c9fdeb28SChuck Lever extern int nfs4_schedule_migration_recovery(const struct nfs_server *); 502b7f7a66eSChuck Lever extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *); 5030a014a44STrond Myklebust extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags, bool); 50478fe0f41SWeston Andros Adamson extern void nfs41_handle_server_scope(struct nfs_client *, 50579d4e1f0SChuck Lever struct nfs41_server_scope **); 506faf5f49cSTrond Myklebust extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp); 5078d0a8a9dSTrond Myklebust extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); 508abf4e13cSTrond Myklebust extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t, 50917393475SNeilBrown const struct nfs_lock_context *, nfs4_stateid *, 510a52458b4SNeilBrown const struct cred **); 511c82bac6fSTrond Myklebust extern bool nfs4_copy_open_stateid(nfs4_stateid *dst, 512c82bac6fSTrond Myklebust struct nfs4_state *state); 5134ce79717STrond Myklebust 5148535b2beSTrond Myklebust extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask); 515cee54fc9STrond Myklebust extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task); 516cee54fc9STrond Myklebust extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid); 517cee54fc9STrond Myklebust extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid); 51872211dbeSTrond Myklebust extern void nfs_release_seqid(struct nfs_seqid *seqid); 519cee54fc9STrond Myklebust extern void nfs_free_seqid(struct nfs_seqid *seqid); 5203be0f80bSTrond Myklebust extern int nfs4_setup_sequence(struct nfs_client *client, 521cb04ad2aSPeng Tao struct nfs4_sequence_args *args, 522cb04ad2aSPeng Tao struct nfs4_sequence_res *res, 523cb04ad2aSPeng Tao struct rpc_task *task); 5242c4b131dSPeng Tao extern int nfs4_sequence_done(struct rpc_task *task, 5252c4b131dSPeng Tao struct nfs4_sequence_res *res); 526cee54fc9STrond Myklebust 5275ae67c4fSTrond Myklebust extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp); 5286b8d84e2SOlga Kornievskaia extern int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res); 5294ce79717STrond Myklebust extern const nfs4_stateid zero_stateid; 530fcd8843cSTrond Myklebust extern const nfs4_stateid invalid_stateid; 5314ce79717STrond Myklebust 532129d1977SBryan Schumaker /* nfs4super.c */ 533fbdefd64SBryan Schumaker struct nfs_mount_info; 534ab7017a3SBryan Schumaker extern struct nfs_subversion nfs_v4; 535fac1e8e4SBryan Schumaker extern bool nfs4_disable_idmapping; 536fac1e8e4SBryan Schumaker extern unsigned short max_session_slots; 5375405fc44STrond Myklebust extern unsigned short max_session_cb_slots; 538fac1e8e4SBryan Schumaker extern unsigned short send_implementation_id; 539f6de7a39STrond Myklebust extern bool recover_lost_locks; 54089d77c8fSBryan Schumaker 5416f2ea7f2SChuck Lever #define NFS4_CLIENT_ID_UNIQ_LEN (64) 5426f2ea7f2SChuck Lever extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN]; 5436f2ea7f2SChuck Lever 544f2aedb71SDavid Howells extern int nfs4_try_get_tree(struct fs_context *); 545f2aedb71SDavid Howells extern int nfs4_get_referral_tree(struct fs_context *); 546f2aedb71SDavid Howells 547466bfe7fSBryan Schumaker /* nfs4sysctl.c */ 548466bfe7fSBryan Schumaker #ifdef CONFIG_SYSCTL 549466bfe7fSBryan Schumaker int nfs4_register_sysctl(void); 550466bfe7fSBryan Schumaker void nfs4_unregister_sysctl(void); 551466bfe7fSBryan Schumaker #else 552466bfe7fSBryan Schumaker static inline int nfs4_register_sysctl(void) 553466bfe7fSBryan Schumaker { 554466bfe7fSBryan Schumaker return 0; 555466bfe7fSBryan Schumaker } 556466bfe7fSBryan Schumaker 5570add3e85SRandy Dunlap static inline void nfs4_unregister_sysctl(void) 558466bfe7fSBryan Schumaker { 559466bfe7fSBryan Schumaker } 560466bfe7fSBryan Schumaker #endif 561466bfe7fSBryan Schumaker 5624ce79717STrond Myklebust /* nfs4xdr.c */ 563499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs4_procedures[]; 5644ce79717STrond Myklebust 56504a5da69SFrank van der Linden #ifdef CONFIG_NFS_V4_2 56604a5da69SFrank van der Linden extern const u32 nfs42_maxsetxattr_overhead; 56704a5da69SFrank van der Linden extern const u32 nfs42_maxgetxattr_overhead; 56804a5da69SFrank van der Linden extern const u32 nfs42_maxlistxattrs_overhead; 56904a5da69SFrank van der Linden #endif 57004a5da69SFrank van der Linden 5714ce79717STrond Myklebust struct nfs4_mount_data; 5724ce79717STrond Myklebust 5734ce79717STrond Myklebust /* callback_xdr.c */ 574e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version1; 575e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version4; 5764ce79717STrond Myklebust 577f597c537STrond Myklebust static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src) 578f597c537STrond Myklebust { 57993b717fdSTrond Myklebust memcpy(dst->data, src->data, sizeof(dst->data)); 58093b717fdSTrond Myklebust dst->type = src->type; 581f597c537STrond Myklebust } 582f597c537STrond Myklebust 583f597c537STrond Myklebust static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src) 584f597c537STrond Myklebust { 58593b717fdSTrond Myklebust if (dst->type != src->type) 58693b717fdSTrond Myklebust return false; 58793b717fdSTrond Myklebust return memcmp(dst->data, src->data, sizeof(dst->data)) == 0; 588f597c537STrond Myklebust } 589f597c537STrond Myklebust 590e999e80eSTrond Myklebust static inline bool nfs4_stateid_match_other(const nfs4_stateid *dst, const nfs4_stateid *src) 591e999e80eSTrond Myklebust { 592e999e80eSTrond Myklebust return memcmp(dst->other, src->other, NFS4_STATEID_OTHER_SIZE) == 0; 593e999e80eSTrond Myklebust } 594e999e80eSTrond Myklebust 595e999e80eSTrond Myklebust static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stateid *s2) 596e999e80eSTrond Myklebust { 597e999e80eSTrond Myklebust return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0; 598e999e80eSTrond Myklebust } 599e999e80eSTrond Myklebust 60042c304c3STrond Myklebust static inline bool nfs4_stateid_match_or_older(const nfs4_stateid *dst, const nfs4_stateid *src) 60142c304c3STrond Myklebust { 60242c304c3STrond Myklebust return nfs4_stateid_match_other(dst, src) && 60342c304c3STrond Myklebust !(src->seqid && nfs4_stateid_is_newer(dst, src)); 60442c304c3STrond Myklebust } 60542c304c3STrond Myklebust 60692283957STrond Myklebust static inline void nfs4_stateid_seqid_inc(nfs4_stateid *s1) 60792283957STrond Myklebust { 60892283957STrond Myklebust u32 seqid = be32_to_cpu(s1->seqid); 60992283957STrond Myklebust 61092283957STrond Myklebust if (++seqid == 0) 61192283957STrond Myklebust ++seqid; 61292283957STrond Myklebust s1->seqid = cpu_to_be32(seqid); 61392283957STrond Myklebust } 61492283957STrond Myklebust 6155d422301STrond Myklebust static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state) 6165d422301STrond Myklebust { 6175d422301STrond Myklebust return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0; 6185d422301STrond Myklebust } 6195d422301STrond Myklebust 6203e7dfb16STrond Myklebust static inline bool nfs4_state_match_open_stateid_other(const struct nfs4_state *state, 6213e7dfb16STrond Myklebust const nfs4_stateid *stateid) 6223e7dfb16STrond Myklebust { 6233e7dfb16STrond Myklebust return test_bit(NFS_OPEN_STATE, &state->flags) && 6243e7dfb16STrond Myklebust nfs4_stateid_match_other(&state->open_stateid, stateid); 6253e7dfb16STrond Myklebust } 6263e7dfb16STrond Myklebust 6274ce79717STrond Myklebust #else 6284ce79717STrond Myklebust 629643168c2SAl Viro #define nfs4_close_state(a, b) do { } while (0) 630643168c2SAl Viro #define nfs4_close_sync(a, b) do { } while (0) 6318c21c62cSWeston Andros Adamson #define nfs4_state_protect(a, b, c, d) do { } while (0) 6328c21c62cSWeston Andros Adamson #define nfs4_state_protect_write(a, b, c, d) do { } while (0) 6334ce79717STrond Myklebust 6344ce79717STrond Myklebust #endif /* CONFIG_NFS_V4 */ 6354ce79717STrond Myklebust #endif /* __LINUX_FS_NFS_NFS4_FS.H */ 636