Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * linux/fs/nfs/nfs4_fs.h
0004  *
0005  * Copyright (C) 2005 Trond Myklebust
0006  *
0007  * NFSv4-specific filesystem definitions and declarations
0008  */
0009 
0010 #ifndef __LINUX_FS_NFS_NFS4_FS_H
0011 #define __LINUX_FS_NFS_NFS4_FS_H
0012 
0013 #if defined(CONFIG_NFS_V4_2)
0014 #define NFS4_MAX_MINOR_VERSION 2
0015 #elif defined(CONFIG_NFS_V4_1)
0016 #define NFS4_MAX_MINOR_VERSION 1
0017 #else
0018 #define NFS4_MAX_MINOR_VERSION 0
0019 #endif
0020 
0021 #if IS_ENABLED(CONFIG_NFS_V4)
0022 
0023 #define NFS4_MAX_LOOP_ON_RECOVER (10)
0024 
0025 #include <linux/seqlock.h>
0026 
0027 struct idmap;
0028 
0029 enum nfs4_client_state {
0030     NFS4CLNT_MANAGER_RUNNING  = 0,
0031     NFS4CLNT_CHECK_LEASE,
0032     NFS4CLNT_LEASE_EXPIRED,
0033     NFS4CLNT_RECLAIM_REBOOT,
0034     NFS4CLNT_RECLAIM_NOGRACE,
0035     NFS4CLNT_DELEGRETURN,
0036     NFS4CLNT_SESSION_RESET,
0037     NFS4CLNT_LEASE_CONFIRM,
0038     NFS4CLNT_SERVER_SCOPE_MISMATCH,
0039     NFS4CLNT_PURGE_STATE,
0040     NFS4CLNT_BIND_CONN_TO_SESSION,
0041     NFS4CLNT_MOVED,
0042     NFS4CLNT_LEASE_MOVED,
0043     NFS4CLNT_DELEGATION_EXPIRED,
0044     NFS4CLNT_RUN_MANAGER,
0045     NFS4CLNT_MANAGER_AVAILABLE,
0046     NFS4CLNT_RECALL_RUNNING,
0047     NFS4CLNT_RECALL_ANY_LAYOUT_READ,
0048     NFS4CLNT_RECALL_ANY_LAYOUT_RW,
0049     NFS4CLNT_DELEGRETURN_DELAYED,
0050 };
0051 
0052 #define NFS4_RENEW_TIMEOUT      0x01
0053 #define NFS4_RENEW_DELEGATION_CB    0x02
0054 
0055 struct nfs_seqid_counter;
0056 struct nfs4_minor_version_ops {
0057     u32 minor_version;
0058     unsigned init_caps;
0059 
0060     int (*init_client)(struct nfs_client *);
0061     void    (*shutdown_client)(struct nfs_client *);
0062     bool    (*match_stateid)(const nfs4_stateid *,
0063             const nfs4_stateid *);
0064     int (*find_root_sec)(struct nfs_server *, struct nfs_fh *,
0065             struct nfs_fsinfo *);
0066     void    (*free_lock_state)(struct nfs_server *,
0067             struct nfs4_lock_state *);
0068     int (*test_and_free_expired)(struct nfs_server *,
0069             nfs4_stateid *, const struct cred *);
0070     struct nfs_seqid *
0071         (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
0072     void    (*session_trunk)(struct rpc_clnt *clnt,
0073             struct rpc_xprt *xprt, void *data);
0074     const struct rpc_call_ops *call_sync_ops;
0075     const struct nfs4_state_recovery_ops *reboot_recovery_ops;
0076     const struct nfs4_state_recovery_ops *nograce_recovery_ops;
0077     const struct nfs4_state_maintenance_ops *state_renewal_ops;
0078     const struct nfs4_mig_recovery_ops *mig_recovery_ops;
0079 };
0080 
0081 #define NFS_SEQID_CONFIRMED 1
0082 struct nfs_seqid_counter {
0083     ktime_t create_time;
0084     int owner_id;
0085     int flags;
0086     u32 counter;
0087     spinlock_t lock;        /* Protects the list */
0088     struct list_head list;      /* Defines sequence of RPC calls */
0089     struct rpc_wait_queue   wait;   /* RPC call delay queue */
0090 };
0091 
0092 struct nfs_seqid {
0093     struct nfs_seqid_counter *sequence;
0094     struct list_head list;
0095     struct rpc_task *task;
0096 };
0097 
0098 static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
0099 {
0100     if (seqid_mutating_err(-status))
0101         seqid->flags |= NFS_SEQID_CONFIRMED;
0102 }
0103 
0104 /*
0105  * NFS4 state_owners and lock_owners are simply labels for ordered
0106  * sequences of RPC calls. Their sole purpose is to provide once-only
0107  * semantics by allowing the server to identify replayed requests.
0108  */
0109 struct nfs4_state_owner {
0110     struct nfs_server    *so_server;
0111     struct list_head     so_lru;
0112     unsigned long        so_expires;
0113     struct rb_node       so_server_node;
0114 
0115     const struct cred    *so_cred;   /* Associated cred */
0116 
0117     spinlock_t       so_lock;
0118     atomic_t         so_count;
0119     unsigned long        so_flags;
0120     struct list_head     so_states;
0121     struct nfs_seqid_counter so_seqid;
0122     seqcount_spinlock_t  so_reclaim_seqcount;
0123     struct mutex         so_delegreturn_mutex;
0124 };
0125 
0126 enum {
0127     NFS_OWNER_RECLAIM_REBOOT,
0128     NFS_OWNER_RECLAIM_NOGRACE
0129 };
0130 
0131 #define NFS_LOCK_NEW        0
0132 #define NFS_LOCK_RECLAIM    1
0133 #define NFS_LOCK_EXPIRED    2
0134 
0135 /*
0136  * struct nfs4_state maintains the client-side state for a given
0137  * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
0138  *
0139  * OPEN:
0140  * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
0141  * we need to know how many files are open for reading or writing on a
0142  * given inode. This information too is stored here.
0143  *
0144  * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
0145  */
0146 
0147 struct nfs4_lock_state {
0148     struct list_head    ls_locks;   /* Other lock stateids */
0149     struct nfs4_state * ls_state;   /* Pointer to open state */
0150 #define NFS_LOCK_INITIALIZED 0
0151 #define NFS_LOCK_LOST        1
0152     unsigned long       ls_flags;
0153     struct nfs_seqid_counter    ls_seqid;
0154     nfs4_stateid        ls_stateid;
0155     refcount_t      ls_count;
0156     fl_owner_t      ls_owner;
0157 };
0158 
0159 /* bits for nfs4_state->flags */
0160 enum {
0161     LK_STATE_IN_USE,
0162     NFS_DELEGATED_STATE,        /* Current stateid is delegation */
0163     NFS_OPEN_STATE,         /* OPEN stateid is set */
0164     NFS_O_RDONLY_STATE,     /* OPEN stateid has read-only state */
0165     NFS_O_WRONLY_STATE,     /* OPEN stateid has write-only state */
0166     NFS_O_RDWR_STATE,       /* OPEN stateid has read/write state */
0167     NFS_STATE_RECLAIM_REBOOT,   /* OPEN stateid server rebooted */
0168     NFS_STATE_RECLAIM_NOGRACE,  /* OPEN stateid needs to recover state */
0169     NFS_STATE_POSIX_LOCKS,      /* Posix locks are supported */
0170     NFS_STATE_RECOVERY_FAILED,  /* OPEN stateid state recovery failed */
0171     NFS_STATE_MAY_NOTIFY_LOCK,  /* server may CB_NOTIFY_LOCK */
0172     NFS_STATE_CHANGE_WAIT,      /* A state changing operation is outstanding */
0173     NFS_CLNT_DST_SSC_COPY_STATE,    /* dst server open state on client*/
0174     NFS_CLNT_SRC_SSC_COPY_STATE,    /* src server open state on client*/
0175     NFS_SRV_SSC_COPY_STATE,     /* ssc state on the dst server */
0176 };
0177 
0178 struct nfs4_state {
0179     struct list_head open_states;   /* List of states for the same state_owner */
0180     struct list_head inode_states;  /* List of states for the same inode */
0181     struct list_head lock_states;   /* List of subservient lock stateids */
0182 
0183     struct nfs4_state_owner *owner; /* Pointer to the open owner */
0184     struct inode *inode;        /* Pointer to the inode */
0185 
0186     unsigned long flags;        /* Do we hold any locks? */
0187     spinlock_t state_lock;      /* Protects the lock_states list */
0188 
0189     seqlock_t seqlock;      /* Protects the stateid/open_stateid */
0190     nfs4_stateid stateid;       /* Current stateid: may be delegation */
0191     nfs4_stateid open_stateid;  /* OPEN stateid */
0192 
0193     /* The following 3 fields are protected by owner->so_lock */
0194     unsigned int n_rdonly;      /* Number of read-only references */
0195     unsigned int n_wronly;      /* Number of write-only references */
0196     unsigned int n_rdwr;        /* Number of read/write references */
0197     fmode_t state;          /* State on the server (R,W, or RW) */
0198     refcount_t count;
0199 
0200     wait_queue_head_t waitq;
0201     struct rcu_head rcu_head;
0202 };
0203 
0204 
0205 struct nfs4_exception {
0206     struct nfs4_state *state;
0207     struct inode *inode;
0208     nfs4_stateid *stateid;
0209     long timeout;
0210     unsigned char task_is_privileged : 1;
0211     unsigned char delay : 1,
0212               recovering : 1,
0213               retry : 1;
0214     bool interruptible;
0215 };
0216 
0217 struct nfs4_state_recovery_ops {
0218     int owner_flag_bit;
0219     int state_flag_bit;
0220     int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
0221     int (*recover_lock)(struct nfs4_state *, struct file_lock *);
0222     int (*establish_clid)(struct nfs_client *, const struct cred *);
0223     int (*reclaim_complete)(struct nfs_client *, const struct cred *);
0224     int (*detect_trunking)(struct nfs_client *, struct nfs_client **,
0225         const struct cred *);
0226 };
0227 
0228 struct nfs4_opendata {
0229     struct kref kref;
0230     struct nfs_openargs o_arg;
0231     struct nfs_openres o_res;
0232     struct nfs_open_confirmargs c_arg;
0233     struct nfs_open_confirmres c_res;
0234     struct nfs4_string owner_name;
0235     struct nfs4_string group_name;
0236     struct nfs4_label *a_label;
0237     struct nfs_fattr f_attr;
0238     struct dentry *dir;
0239     struct dentry *dentry;
0240     struct nfs4_state_owner *owner;
0241     struct nfs4_state *state;
0242     struct iattr attrs;
0243     struct nfs4_layoutget *lgp;
0244     unsigned long timestamp;
0245     bool rpc_done;
0246     bool file_created;
0247     bool is_recover;
0248     bool cancelled;
0249     int rpc_status;
0250 };
0251 
0252 struct nfs4_add_xprt_data {
0253     struct nfs_client   *clp;
0254     const struct cred   *cred;
0255 };
0256 
0257 struct nfs4_state_maintenance_ops {
0258     int (*sched_state_renewal)(struct nfs_client *, const struct cred *, unsigned);
0259     const struct cred * (*get_state_renewal_cred)(struct nfs_client *);
0260     int (*renew_lease)(struct nfs_client *, const struct cred *);
0261 };
0262 
0263 struct nfs4_mig_recovery_ops {
0264     int (*get_locations)(struct nfs_server *, struct nfs_fh *,
0265         struct nfs4_fs_locations *, struct page *, const struct cred *);
0266     int (*fsid_present)(struct inode *, const struct cred *);
0267 };
0268 
0269 extern const struct dentry_operations nfs4_dentry_operations;
0270 
0271 /* dir.c */
0272 int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
0273             unsigned, umode_t);
0274 
0275 /* fs_context.c */
0276 extern struct file_system_type nfs4_fs_type;
0277 
0278 /* nfs4namespace.c */
0279 struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *,
0280                      const struct qstr *);
0281 int nfs4_submount(struct fs_context *, struct nfs_server *);
0282 int nfs4_replace_transport(struct nfs_server *server,
0283                 const struct nfs4_fs_locations *locations);
0284 size_t nfs_parse_server_name(char *string, size_t len, struct sockaddr *sa,
0285                  size_t salen, struct net *net, int port);
0286 /* nfs4proc.c */
0287 extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *);
0288 extern int nfs4_async_handle_error(struct rpc_task *task,
0289                    struct nfs_server *server,
0290                    struct nfs4_state *state, long *timeout);
0291 extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
0292               struct rpc_message *, struct nfs4_sequence_args *,
0293               struct nfs4_sequence_res *, int);
0294 extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int);
0295 extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
0296 extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *);
0297 extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
0298 extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
0299 extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
0300 extern int nfs4_destroy_clientid(struct nfs_client *clp);
0301 extern int nfs4_init_clientid(struct nfs_client *, const struct cred *);
0302 extern int nfs41_init_clientid(struct nfs_client *, const struct cred *);
0303 extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait);
0304 extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
0305 extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
0306                   struct nfs4_fs_locations *, struct page *);
0307 extern int nfs4_proc_get_locations(struct nfs_server *, struct nfs_fh *,
0308                    struct nfs4_fs_locations *,
0309                    struct page *page, const struct cred *);
0310 extern int nfs4_proc_fsid_present(struct inode *, const struct cred *);
0311 extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *,
0312                             struct dentry *,
0313                             struct nfs_fh *,
0314                             struct nfs_fattr *);
0315 extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
0316 extern const struct xattr_handler *nfs4_xattr_handlers[];
0317 extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
0318         const struct nfs_open_context *ctx,
0319         const struct nfs_lock_context *l_ctx,
0320         fmode_t fmode);
0321 extern void nfs4_bitmask_set(__u32 bitmask[], const __u32 src[],
0322                  struct inode *inode, unsigned long cache_validity);
0323 extern int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
0324                  struct nfs_fattr *fattr, struct inode *inode);
0325 extern int update_open_stateid(struct nfs4_state *state,
0326                 const nfs4_stateid *open_stateid,
0327                 const nfs4_stateid *deleg_stateid,
0328                 fmode_t fmode);
0329 extern int nfs4_proc_setlease(struct file *file, long arg,
0330                   struct file_lock **lease, void **priv);
0331 extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
0332         struct nfs_fsinfo *fsinfo);
0333 extern void nfs4_update_changeattr(struct inode *dir,
0334                    struct nfs4_change_info *cinfo,
0335                    unsigned long timestamp,
0336                    unsigned long cache_validity);
0337 extern int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen,
0338                     struct page **pages);
0339 
0340 #if defined(CONFIG_NFS_V4_1)
0341 extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *);
0342 extern int nfs4_proc_create_session(struct nfs_client *, const struct cred *);
0343 extern int nfs4_proc_destroy_session(struct nfs4_session *, const struct cred *);
0344 extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
0345                   bool sync);
0346 extern int nfs4_detect_session_trunking(struct nfs_client *clp,
0347         struct nfs41_exchange_id_res *res, struct rpc_xprt *xprt);
0348 
0349 static inline bool
0350 is_ds_only_client(struct nfs_client *clp)
0351 {
0352     return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) ==
0353         EXCHGID4_FLAG_USE_PNFS_DS;
0354 }
0355 
0356 static inline bool
0357 is_ds_client(struct nfs_client *clp)
0358 {
0359     return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
0360 }
0361 
0362 static inline bool
0363 _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
0364             struct rpc_clnt **clntp, struct rpc_message *msg)
0365 {
0366     rpc_authflavor_t flavor;
0367 
0368     if (sp4_mode == NFS_SP4_MACH_CRED_CLEANUP ||
0369         sp4_mode == NFS_SP4_MACH_CRED_PNFS_CLEANUP) {
0370         /* Using machine creds for cleanup operations
0371          * is only relevent if the client credentials
0372          * might expire. So don't bother for
0373          * RPC_AUTH_UNIX.  If file was only exported to
0374          * sec=sys, the PUTFH would fail anyway.
0375          */
0376         if ((*clntp)->cl_auth->au_flavor == RPC_AUTH_UNIX)
0377             return false;
0378     }
0379     if (test_bit(sp4_mode, &clp->cl_sp4_flags)) {
0380         msg->rpc_cred = rpc_machine_cred();
0381 
0382         flavor = clp->cl_rpcclient->cl_auth->au_flavor;
0383         WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I &&
0384                  flavor != RPC_AUTH_GSS_KRB5P);
0385         *clntp = clp->cl_rpcclient;
0386 
0387         return true;
0388     }
0389     return false;
0390 }
0391 
0392 /*
0393  * Function responsible for determining if an rpc_message should use the
0394  * machine cred under SP4_MACH_CRED and if so switching the credential and
0395  * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p).
0396  * Should be called before rpc_call_sync/rpc_call_async.
0397  */
0398 static inline void
0399 nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
0400            struct rpc_clnt **clntp, struct rpc_message *msg)
0401 {
0402     _nfs4_state_protect(clp, sp4_mode, clntp, msg);
0403 }
0404 
0405 /*
0406  * Special wrapper to nfs4_state_protect for write.
0407  * If WRITE can use machine cred but COMMIT cannot, make sure all writes
0408  * that use machine cred use NFS_FILE_SYNC.
0409  */
0410 static inline void
0411 nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
0412              struct rpc_message *msg, struct nfs_pgio_header *hdr)
0413 {
0414     if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) &&
0415         !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
0416         hdr->args.stable = NFS_FILE_SYNC;
0417 }
0418 #else /* CONFIG_NFS_v4_1 */
0419 static inline bool
0420 is_ds_only_client(struct nfs_client *clp)
0421 {
0422     return false;
0423 }
0424 
0425 static inline bool
0426 is_ds_client(struct nfs_client *clp)
0427 {
0428     return false;
0429 }
0430 
0431 static inline void
0432 nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags,
0433            struct rpc_clnt **clntp, struct rpc_message *msg)
0434 {
0435 }
0436 
0437 static inline void
0438 nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
0439              struct rpc_message *msg, struct nfs_pgio_header *hdr)
0440 {
0441 }
0442 #endif /* CONFIG_NFS_V4_1 */
0443 
0444 extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];
0445 
0446 extern const u32 nfs4_fattr_bitmap[3];
0447 extern const u32 nfs4_statfs_bitmap[3];
0448 extern const u32 nfs4_pathconf_bitmap[3];
0449 extern const u32 nfs4_fsinfo_bitmap[3];
0450 extern const u32 nfs4_fs_locations_bitmap[3];
0451 
0452 void nfs40_shutdown_client(struct nfs_client *);
0453 void nfs41_shutdown_client(struct nfs_client *);
0454 int nfs40_init_client(struct nfs_client *);
0455 int nfs41_init_client(struct nfs_client *);
0456 void nfs4_free_client(struct nfs_client *);
0457 
0458 struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *);
0459 
0460 /* nfs4renewd.c */
0461 extern void nfs4_schedule_state_renewal(struct nfs_client *);
0462 extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
0463 extern void nfs4_kill_renewd(struct nfs_client *);
0464 extern void nfs4_renew_state(struct work_struct *);
0465 extern void nfs4_set_lease_period(struct nfs_client *clp, unsigned long lease);
0466 
0467 
0468 /* nfs4state.c */
0469 extern const nfs4_stateid current_stateid;
0470 
0471 const struct cred *nfs4_get_clid_cred(struct nfs_client *clp);
0472 const struct cred *nfs4_get_machine_cred(struct nfs_client *clp);
0473 const struct cred *nfs4_get_renew_cred(struct nfs_client *clp);
0474 int nfs4_discover_server_trunking(struct nfs_client *clp,
0475             struct nfs_client **);
0476 int nfs40_discover_server_trunking(struct nfs_client *clp,
0477             struct nfs_client **, const struct cred *);
0478 #if defined(CONFIG_NFS_V4_1)
0479 int nfs41_discover_server_trunking(struct nfs_client *clp,
0480             struct nfs_client **, const struct cred *);
0481 extern void nfs4_schedule_session_recovery(struct nfs4_session *, int);
0482 extern void nfs41_notify_server(struct nfs_client *);
0483 bool nfs4_check_serverowner_major_id(struct nfs41_server_owner *o1,
0484             struct nfs41_server_owner *o2);
0485 #else
0486 static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err)
0487 {
0488 }
0489 #endif /* CONFIG_NFS_V4_1 */
0490 
0491 extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, const struct cred *, gfp_t);
0492 extern void nfs4_put_state_owner(struct nfs4_state_owner *);
0493 extern void nfs4_purge_state_owners(struct nfs_server *, struct list_head *);
0494 extern void nfs4_free_state_owners(struct list_head *head);
0495 extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
0496 extern void nfs4_put_open_state(struct nfs4_state *);
0497 extern void nfs4_close_state(struct nfs4_state *, fmode_t);
0498 extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
0499 extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
0500 extern void nfs_inode_find_state_and_recover(struct inode *inode,
0501         const nfs4_stateid *stateid);
0502 extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *, struct nfs4_state *);
0503 extern void nfs4_schedule_lease_recovery(struct nfs_client *);
0504 extern int nfs4_wait_clnt_recover(struct nfs_client *clp);
0505 extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
0506 extern void nfs4_schedule_state_manager(struct nfs_client *);
0507 extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
0508 extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
0509 extern int nfs4_schedule_migration_recovery(const struct nfs_server *);
0510 extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
0511 extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags, bool);
0512 extern void nfs41_handle_server_scope(struct nfs_client *,
0513                       struct nfs41_server_scope **);
0514 extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
0515 extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
0516 extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t,
0517         const struct nfs_lock_context *, nfs4_stateid *,
0518         const struct cred **);
0519 extern bool nfs4_copy_open_stateid(nfs4_stateid *dst,
0520         struct nfs4_state *state);
0521 
0522 extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
0523 extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
0524 extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
0525 extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
0526 extern void nfs_release_seqid(struct nfs_seqid *seqid);
0527 extern void nfs_free_seqid(struct nfs_seqid *seqid);
0528 extern int nfs4_setup_sequence(struct nfs_client *client,
0529                 struct nfs4_sequence_args *args,
0530                 struct nfs4_sequence_res *res,
0531                 struct rpc_task *task);
0532 extern int nfs4_sequence_done(struct rpc_task *task,
0533                   struct nfs4_sequence_res *res);
0534 
0535 extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
0536 extern int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res);
0537 extern const nfs4_stateid zero_stateid;
0538 extern const nfs4_stateid invalid_stateid;
0539 
0540 /* nfs4super.c */
0541 struct nfs_mount_info;
0542 extern struct nfs_subversion nfs_v4;
0543 extern bool nfs4_disable_idmapping;
0544 extern unsigned short max_session_slots;
0545 extern unsigned short max_session_cb_slots;
0546 extern unsigned short send_implementation_id;
0547 extern bool recover_lost_locks;
0548 
0549 #define NFS4_CLIENT_ID_UNIQ_LEN     (64)
0550 extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
0551 
0552 extern int nfs4_try_get_tree(struct fs_context *);
0553 extern int nfs4_get_referral_tree(struct fs_context *);
0554 
0555 /* nfs4sysctl.c */
0556 #ifdef CONFIG_SYSCTL
0557 int nfs4_register_sysctl(void);
0558 void nfs4_unregister_sysctl(void);
0559 #else
0560 static inline int nfs4_register_sysctl(void)
0561 {
0562     return 0;
0563 }
0564 
0565 static inline void nfs4_unregister_sysctl(void)
0566 {
0567 }
0568 #endif
0569 
0570 /* nfs4xdr.c */
0571 extern const struct rpc_procinfo nfs4_procedures[];
0572 
0573 #ifdef CONFIG_NFS_V4_2
0574 extern const u32 nfs42_maxsetxattr_overhead;
0575 extern const u32 nfs42_maxgetxattr_overhead;
0576 extern const u32 nfs42_maxlistxattrs_overhead;
0577 #endif
0578 
0579 struct nfs4_mount_data;
0580 
0581 /* callback_xdr.c */
0582 extern const struct svc_version nfs4_callback_version1;
0583 extern const struct svc_version nfs4_callback_version4;
0584 
0585 static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
0586 {
0587     memcpy(dst->data, src->data, sizeof(dst->data));
0588     dst->type = src->type;
0589 }
0590 
0591 static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
0592 {
0593     if (dst->type != src->type)
0594         return false;
0595     return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
0596 }
0597 
0598 static inline bool nfs4_stateid_match_other(const nfs4_stateid *dst, const nfs4_stateid *src)
0599 {
0600     return memcmp(dst->other, src->other, NFS4_STATEID_OTHER_SIZE) == 0;
0601 }
0602 
0603 static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stateid *s2)
0604 {
0605     return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0;
0606 }
0607 
0608 static inline bool nfs4_stateid_is_next(const nfs4_stateid *s1, const nfs4_stateid *s2)
0609 {
0610     u32 seq1 = be32_to_cpu(s1->seqid);
0611     u32 seq2 = be32_to_cpu(s2->seqid);
0612 
0613     return seq2 == seq1 + 1U || (seq2 == 1U && seq1 == 0xffffffffU);
0614 }
0615 
0616 static inline bool nfs4_stateid_match_or_older(const nfs4_stateid *dst, const nfs4_stateid *src)
0617 {
0618     return nfs4_stateid_match_other(dst, src) &&
0619         !(src->seqid && nfs4_stateid_is_newer(dst, src));
0620 }
0621 
0622 static inline void nfs4_stateid_seqid_inc(nfs4_stateid *s1)
0623 {
0624     u32 seqid = be32_to_cpu(s1->seqid);
0625 
0626     if (++seqid == 0)
0627         ++seqid;
0628     s1->seqid = cpu_to_be32(seqid);
0629 }
0630 
0631 static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
0632 {
0633     return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0;
0634 }
0635 
0636 static inline bool nfs4_state_match_open_stateid_other(const struct nfs4_state *state,
0637         const nfs4_stateid *stateid)
0638 {
0639     return test_bit(NFS_OPEN_STATE, &state->flags) &&
0640         nfs4_stateid_match_other(&state->open_stateid, stateid);
0641 }
0642 
0643 /* nfs42xattr.c */
0644 #ifdef CONFIG_NFS_V4_2
0645 extern int __init nfs4_xattr_cache_init(void);
0646 extern void nfs4_xattr_cache_exit(void);
0647 extern void nfs4_xattr_cache_add(struct inode *inode, const char *name,
0648                  const char *buf, struct page **pages,
0649                  ssize_t buflen);
0650 extern void nfs4_xattr_cache_remove(struct inode *inode, const char *name);
0651 extern ssize_t nfs4_xattr_cache_get(struct inode *inode, const char *name,
0652                 char *buf, ssize_t buflen);
0653 extern void nfs4_xattr_cache_set_list(struct inode *inode, const char *buf,
0654                       ssize_t buflen);
0655 extern ssize_t nfs4_xattr_cache_list(struct inode *inode, char *buf,
0656                      ssize_t buflen);
0657 extern void nfs4_xattr_cache_zap(struct inode *inode);
0658 #else
0659 static inline void nfs4_xattr_cache_zap(struct inode *inode)
0660 {
0661 }
0662 #endif /* CONFIG_NFS_V4_2 */
0663 
0664 #else /* CONFIG_NFS_V4 */
0665 
0666 #define nfs4_close_state(a, b) do { } while (0)
0667 #define nfs4_close_sync(a, b) do { } while (0)
0668 #define nfs4_state_protect(a, b, c, d) do { } while (0)
0669 #define nfs4_state_protect_write(a, b, c, d) do { } while (0)
0670 
0671 
0672 #endif /* CONFIG_NFS_V4 */
0673 #endif /* __LINUX_FS_NFS_NFS4_FS.H */