1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * linux/fs/nfs/nfs4_fs.h
4 *
5 * Copyright (C) 2005 Trond Myklebust
6 *
7 * NFSv4-specific filesystem definitions and declarations
8 */
9
10 #ifndef __LINUX_FS_NFS_NFS4_FS_H
11 #define __LINUX_FS_NFS_NFS4_FS_H
12
13 #if defined(CONFIG_NFS_V4_0)
14 #define NFS4_MIN_MINOR_VERSION 0
15 #else
16 #define NFS4_MIN_MINOR_VERSION 1
17 #endif
18
19 #if defined(CONFIG_NFS_V4_2)
20 #define NFS4_MAX_MINOR_VERSION 2
21 #else
22 #define NFS4_MAX_MINOR_VERSION 1
23 #endif
24
25 #if IS_ENABLED(CONFIG_NFS_V4)
26
27 #define NFS4_MAX_LOOP_ON_RECOVER (10)
28
29 #include <linux/seqlock.h>
30 #include <linux/filelock.h>
31
32 struct idmap;
33
34 enum nfs4_client_state {
35 NFS4CLNT_MANAGER_RUNNING = 0,
36 NFS4CLNT_CHECK_LEASE,
37 NFS4CLNT_LEASE_EXPIRED,
38 NFS4CLNT_RECLAIM_REBOOT,
39 NFS4CLNT_RECLAIM_NOGRACE,
40 NFS4CLNT_DELEGRETURN,
41 NFS4CLNT_SESSION_RESET,
42 NFS4CLNT_LEASE_CONFIRM,
43 NFS4CLNT_SERVER_SCOPE_MISMATCH,
44 NFS4CLNT_PURGE_STATE,
45 NFS4CLNT_BIND_CONN_TO_SESSION,
46 NFS4CLNT_MOVED,
47 NFS4CLNT_LEASE_MOVED,
48 NFS4CLNT_DELEGATION_EXPIRED,
49 NFS4CLNT_RUN_MANAGER,
50 NFS4CLNT_MANAGER_AVAILABLE,
51 NFS4CLNT_RECALL_RUNNING,
52 NFS4CLNT_RECALL_ANY_LAYOUT_READ,
53 NFS4CLNT_RECALL_ANY_LAYOUT_RW,
54 NFS4CLNT_DELEGRETURN_DELAYED,
55 };
56
57 #define NFS4_RENEW_TIMEOUT 0x01
58 #define NFS4_RENEW_DELEGATION_CB 0x02
59
60 struct nfs_seqid_counter;
61 struct nfs4_minor_version_ops {
62 u32 minor_version;
63 unsigned init_caps;
64
65 int (*init_client)(struct nfs_client *);
66 void (*shutdown_client)(struct nfs_client *);
67 bool (*match_stateid)(const nfs4_stateid *,
68 const nfs4_stateid *);
69 int (*find_root_sec)(struct nfs_server *, struct nfs_fh *,
70 struct nfs_fattr *);
71 void (*free_lock_state)(struct nfs_server *,
72 struct nfs4_lock_state *);
73 int (*test_and_free_expired)(struct nfs_server *,
74 nfs4_stateid *, const struct cred *);
75 struct nfs_seqid *
76 (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
77 void (*session_trunk)(struct rpc_clnt *clnt,
78 struct rpc_xprt *xprt, void *data);
79 const struct rpc_call_ops *call_sync_ops;
80 const struct nfs4_sequence_slot_ops *sequence_slot_ops;
81 const struct nfs4_state_recovery_ops *reboot_recovery_ops;
82 const struct nfs4_state_recovery_ops *nograce_recovery_ops;
83 const struct nfs4_state_maintenance_ops *state_renewal_ops;
84 const struct nfs4_mig_recovery_ops *mig_recovery_ops;
85 };
86
87 #define NFS_SEQID_CONFIRMED 1
88 struct nfs_seqid_counter {
89 ktime_t create_time;
90 u64 owner_id;
91 int flags;
92 u32 counter;
93 spinlock_t lock; /* Protects the list */
94 struct list_head list; /* Defines sequence of RPC calls */
95 struct rpc_wait_queue wait; /* RPC call delay queue */
96 };
97
98 struct nfs_seqid {
99 struct nfs_seqid_counter *sequence;
100 struct list_head list;
101 struct rpc_task *task;
102 };
103
nfs_confirm_seqid(struct nfs_seqid_counter * seqid,int status)104 static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
105 {
106 if (seqid_mutating_err(-status))
107 seqid->flags |= NFS_SEQID_CONFIRMED;
108 }
109
110 /*
111 * NFS4 state_owners and lock_owners are simply labels for ordered
112 * sequences of RPC calls. Their sole purpose is to provide once-only
113 * semantics by allowing the server to identify replayed requests.
114 */
115 struct nfs4_state_owner {
116 struct nfs_server *so_server;
117 struct list_head so_lru;
118 unsigned long so_expires;
119 struct rb_node so_server_node;
120
121 const struct cred *so_cred; /* Associated cred */
122
123 spinlock_t so_lock;
124 atomic_t so_count;
125 unsigned long so_flags;
126 struct list_head so_states;
127 struct nfs_seqid_counter so_seqid;
128 struct mutex so_delegreturn_mutex;
129 };
130
131 enum {
132 NFS_OWNER_RECLAIM_REBOOT,
133 NFS_OWNER_RECLAIM_NOGRACE
134 };
135
136 #define NFS_LOCK_NEW 0
137 #define NFS_LOCK_RECLAIM 1
138 #define NFS_LOCK_EXPIRED 2
139
140 /*
141 * struct nfs4_state maintains the client-side state for a given
142 * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
143 *
144 * OPEN:
145 * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
146 * we need to know how many files are open for reading or writing on a
147 * given inode. This information too is stored here.
148 *
149 * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
150 */
151
152 struct nfs4_lock_state {
153 struct list_head ls_locks; /* Other lock stateids */
154 struct nfs4_state * ls_state; /* Pointer to open state */
155 #define NFS_LOCK_INITIALIZED 0
156 #define NFS_LOCK_LOST 1
157 #define NFS_LOCK_UNLOCKING 2
158 unsigned long ls_flags;
159 struct nfs_seqid_counter ls_seqid;
160 nfs4_stateid ls_stateid;
161 refcount_t ls_count;
162 fl_owner_t ls_owner;
163 };
164
165 /* bits for nfs4_state->flags */
166 enum {
167 LK_STATE_IN_USE,
168 NFS_DELEGATED_STATE, /* Current stateid is delegation */
169 NFS_OPEN_STATE, /* OPEN stateid is set */
170 NFS_O_RDONLY_STATE, /* OPEN stateid has read-only state */
171 NFS_O_WRONLY_STATE, /* OPEN stateid has write-only state */
172 NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */
173 NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */
174 NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */
175 NFS_STATE_POSIX_LOCKS, /* Posix locks are supported */
176 NFS_STATE_RECOVERY_FAILED, /* OPEN stateid state recovery failed */
177 NFS_STATE_MAY_NOTIFY_LOCK, /* server may CB_NOTIFY_LOCK */
178 NFS_STATE_CHANGE_WAIT, /* A state changing operation is outstanding */
179 NFS_CLNT_DST_SSC_COPY_STATE, /* dst server open state on client*/
180 NFS_CLNT_SRC_SSC_COPY_STATE, /* src server open state on client*/
181 NFS_SRV_SSC_COPY_STATE, /* ssc state on the dst server */
182 };
183
184 struct nfs4_state {
185 struct list_head open_states; /* List of states for the same state_owner */
186 struct list_head inode_states; /* List of states for the same inode */
187 struct list_head lock_states; /* List of subservient lock stateids */
188
189 struct nfs4_state_owner *owner; /* Pointer to the open owner */
190 struct inode *inode; /* Pointer to the inode */
191
192 unsigned long flags; /* Do we hold any locks? */
193 spinlock_t state_lock; /* Protects the lock_states list */
194
195 seqlock_t seqlock; /* Protects the stateid/open_stateid */
196 nfs4_stateid stateid; /* Current stateid: may be delegation */
197 nfs4_stateid open_stateid; /* OPEN stateid */
198
199 /* The following 3 fields are protected by owner->so_lock */
200 unsigned int n_rdonly; /* Number of read-only references */
201 unsigned int n_wronly; /* Number of write-only references */
202 unsigned int n_rdwr; /* Number of read/write references */
203 fmode_t state; /* State on the server (R,W, or RW) */
204 refcount_t count;
205
206 wait_queue_head_t waitq;
207 struct rcu_head rcu_head;
208 };
209
210
211 struct nfs4_exception {
212 struct nfs4_state *state;
213 struct inode *inode;
214 nfs4_stateid *stateid;
215 long timeout;
216 unsigned short retrans;
217 unsigned char task_is_privileged : 1;
218 unsigned char delay : 1,
219 recovering : 1,
220 retry : 1;
221 bool interruptible;
222 };
223
224 struct nfs4_state_recovery_ops {
225 int owner_flag_bit;
226 int state_flag_bit;
227 int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
228 int (*recover_lock)(struct nfs4_state *, struct file_lock *);
229 int (*establish_clid)(struct nfs_client *, const struct cred *);
230 int (*reclaim_complete)(struct nfs_client *, const struct cred *);
231 int (*detect_trunking)(struct nfs_client *, struct nfs_client **,
232 const struct cred *);
233 };
234
235 struct nfs4_opendata {
236 struct kref kref;
237 struct nfs_openargs o_arg;
238 struct nfs_openres o_res;
239 struct nfs_open_confirmargs c_arg;
240 struct nfs_open_confirmres c_res;
241 struct nfs4_string owner_name;
242 struct nfs4_string group_name;
243 struct nfs4_label *a_label;
244 struct nfs_fattr f_attr;
245 struct dentry *dir;
246 struct dentry *dentry;
247 struct nfs4_state_owner *owner;
248 struct nfs4_state *state;
249 struct iattr attrs;
250 struct nfs4_layoutget *lgp;
251 unsigned long timestamp;
252 bool rpc_done;
253 bool file_created;
254 bool is_recover;
255 bool cancelled;
256 int rpc_status;
257 };
258
259 struct nfs4_add_xprt_data {
260 struct nfs_client *clp;
261 const struct cred *cred;
262 };
263
264 struct nfs4_sequence_slot_ops {
265 int (*process)(struct rpc_task *, struct nfs4_sequence_res *);
266 int (*done)(struct rpc_task *, struct nfs4_sequence_res *);
267 void (*free_slot)(struct nfs4_sequence_res *);
268 };
269
270 struct nfs4_state_maintenance_ops {
271 int (*sched_state_renewal)(struct nfs_client *, const struct cred *, unsigned);
272 const struct cred * (*get_state_renewal_cred)(struct nfs_client *);
273 int (*renew_lease)(struct nfs_client *, const struct cred *);
274 };
275
276 struct nfs4_mig_recovery_ops {
277 int (*get_locations)(struct nfs_server *, struct nfs_fh *,
278 struct nfs4_fs_locations *, struct page *, const struct cred *);
279 int (*fsid_present)(struct inode *, const struct cred *);
280 };
281
282 extern const struct dentry_operations nfs4_dentry_operations;
283
284 /* dir.c */
285 int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
286 unsigned, umode_t);
287
288 /* fs_context.c */
289 extern struct file_system_type nfs4_fs_type;
290
291 /* nfs4client.c */
292 struct nfs_net;
293 int nfs4_match_client(struct nfs_client *pos, struct nfs_client *new,
294 struct nfs_client **prev, struct nfs_net *nn);
295
296 /* nfs4namespace.c */
297 struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *,
298 const struct qstr *);
299 int nfs4_submount(struct fs_context *, struct nfs_server *);
300 int nfs4_replace_transport(struct nfs_server *server,
301 const struct nfs4_fs_locations *locations);
302 size_t nfs_parse_server_name(char *string, size_t len, struct sockaddr_storage *ss,
303 size_t salen, struct net *net, int port);
304 /* nfs4proc.c */
305 struct nfs4_call_sync_data {
306 const struct nfs_server *seq_server;
307 struct nfs4_sequence_args *seq_args;
308 struct nfs4_sequence_res *seq_res;
309 };
310
311 extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *);
312 extern int nfs4_async_handle_error(struct rpc_task *task,
313 struct nfs_server *server,
314 struct nfs4_state *state, long *timeout);
315 extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
316 struct rpc_message *, struct nfs4_sequence_args *,
317 struct nfs4_sequence_res *, int);
318 extern int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
319 struct nfs_server *server,
320 struct rpc_message *msg,
321 struct nfs4_sequence_args *args,
322 struct nfs4_sequence_res *res);
323 extern void nfs4_init_sequence(struct nfs_client *clp, struct nfs4_sequence_args *,
324 struct nfs4_sequence_res *, int, int);
325 extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
326 extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *);
327 extern void renew_lease(const struct nfs_server *server, unsigned long timestamp);
328 extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *,
329 struct nfs_fattr *, bool);
330 extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
331 extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
332 extern int nfs4_destroy_clientid(struct nfs_client *clp);
333 extern int nfs4_init_clientid(struct nfs_client *, const struct cred *);
334 extern int nfs41_init_clientid(struct nfs_client *, const struct cred *);
335 extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait);
336 extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
337 extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
338 struct nfs4_fs_locations *, struct page *);
339 extern int nfs4_proc_get_locations(struct nfs_server *, struct nfs_fh *,
340 struct nfs4_fs_locations *,
341 struct page *page, const struct cred *);
342 extern int nfs4_proc_fsid_present(struct inode *, const struct cred *);
343 extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *,
344 struct dentry *,
345 struct nfs_fh *,
346 struct nfs_fattr *);
347 extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
348 extern const struct xattr_handler * const nfs4_xattr_handlers[];
349 extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
350 const struct nfs_open_context *ctx,
351 const struct nfs_lock_context *l_ctx,
352 fmode_t fmode);
353 extern void nfs4_bitmask_set(__u32 bitmask[], const __u32 src[],
354 struct inode *inode, unsigned long cache_validity);
355 extern int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
356 struct nfs_fattr *fattr, struct inode *inode);
357 extern int update_open_stateid(struct nfs4_state *state,
358 const nfs4_stateid *open_stateid,
359 const nfs4_stateid *deleg_stateid,
360 fmode_t fmode);
361 extern int nfs4_proc_setlease(struct file *file, int arg,
362 struct file_lease **lease, void **priv);
363 extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
364 struct nfs_fsinfo *fsinfo);
365 extern void nfs4_update_changeattr(struct inode *dir,
366 struct nfs4_change_info *cinfo,
367 unsigned long timestamp,
368 unsigned long cache_validity);
369 extern int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen,
370 struct page **pages);
371 extern int nfs4_open_reclaim(struct nfs4_state_owner *, struct nfs4_state *);
372 extern int nfs4_open_expired(struct nfs4_state_owner *, struct nfs4_state *);
373 extern int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request);
374 extern int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request);
375 extern void nfs_state_clear_delegation(struct nfs4_state *state);
376 extern void nfs_finish_clear_delegation_stateid(struct nfs4_state *state,
377 const nfs4_stateid *stateid);
378 extern void nfs_state_clear_open_state_flags(struct nfs4_state *state);
379 extern void do_renew_lease(struct nfs_client *clp, unsigned long timestamp);
380 extern bool nfs4_match_stateid(const nfs4_stateid *s1, const nfs4_stateid *s2);
381 extern int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
382 struct nfs_fattr *fattr);
383
384 extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *);
385 extern int nfs4_proc_create_session(struct nfs_client *, const struct cred *);
386 extern int nfs4_proc_destroy_session(struct nfs4_session *, const struct cred *);
387 extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
388 bool sync);
389 extern int nfs4_detect_session_trunking(struct nfs_client *clp,
390 struct nfs41_exchange_id_res *res, struct rpc_xprt *xprt);
391
392 static inline bool
is_ds_only_client(struct nfs_client * clp)393 is_ds_only_client(struct nfs_client *clp)
394 {
395 return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) ==
396 EXCHGID4_FLAG_USE_PNFS_DS;
397 }
398
399 static inline bool
is_ds_client(struct nfs_client * clp)400 is_ds_client(struct nfs_client *clp)
401 {
402 return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
403 }
404
405 static inline bool
_nfs4_state_protect(struct nfs_client * clp,unsigned long sp4_mode,struct rpc_clnt ** clntp,struct rpc_message * msg)406 _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
407 struct rpc_clnt **clntp, struct rpc_message *msg)
408 {
409 rpc_authflavor_t flavor;
410
411 if (sp4_mode == NFS_SP4_MACH_CRED_CLEANUP ||
412 sp4_mode == NFS_SP4_MACH_CRED_PNFS_CLEANUP) {
413 /* Using machine creds for cleanup operations
414 * is only relevent if the client credentials
415 * might expire. So don't bother for
416 * RPC_AUTH_UNIX. If file was only exported to
417 * sec=sys, the PUTFH would fail anyway.
418 */
419 if ((*clntp)->cl_auth->au_flavor == RPC_AUTH_UNIX)
420 return false;
421 }
422 if (test_bit(sp4_mode, &clp->cl_sp4_flags)) {
423 msg->rpc_cred = rpc_machine_cred();
424
425 flavor = clp->cl_rpcclient->cl_auth->au_flavor;
426 WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I &&
427 flavor != RPC_AUTH_GSS_KRB5P);
428 *clntp = clp->cl_rpcclient;
429
430 return true;
431 }
432 return false;
433 }
434
435 /*
436 * Function responsible for determining if an rpc_message should use the
437 * machine cred under SP4_MACH_CRED and if so switching the credential and
438 * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p).
439 * Should be called before rpc_call_sync/rpc_call_async.
440 */
441 static inline void
nfs4_state_protect(struct nfs_client * clp,unsigned long sp4_mode,struct rpc_clnt ** clntp,struct rpc_message * msg)442 nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
443 struct rpc_clnt **clntp, struct rpc_message *msg)
444 {
445 _nfs4_state_protect(clp, sp4_mode, clntp, msg);
446 }
447
448 /*
449 * Special wrapper to nfs4_state_protect for write.
450 * If WRITE can use machine cred but COMMIT cannot, make sure all writes
451 * that use machine cred use NFS_FILE_SYNC.
452 */
453 static inline void
nfs4_state_protect_write(struct nfs_client * clp,struct rpc_clnt ** clntp,struct rpc_message * msg,struct nfs_pgio_header * hdr)454 nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
455 struct rpc_message *msg, struct nfs_pgio_header *hdr)
456 {
457 if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) &&
458 !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
459 hdr->args.stable = NFS_FILE_SYNC;
460 }
461
462 extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];
463
464 extern const u32 nfs4_fattr_bitmap[3];
465 extern const u32 nfs4_statfs_bitmap[3];
466 extern const u32 nfs4_pathconf_bitmap[3];
467 extern const u32 nfs4_fsinfo_bitmap[3];
468 extern const u32 nfs4_fs_locations_bitmap[3];
469
470 void nfs41_shutdown_client(struct nfs_client *);
471 int nfs41_init_client(struct nfs_client *);
472 void nfs4_free_client(struct nfs_client *);
473
474 struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *);
475
476 /* nfs4renewd.c */
477 extern void nfs4_schedule_state_renewal(struct nfs_client *);
478 extern void nfs4_kill_renewd(struct nfs_client *);
479 extern void nfs4_renew_state(struct work_struct *);
480 extern void nfs4_set_lease_period(struct nfs_client *clp, u32 period);
481
482 /* nfs4state.c */
483 extern const nfs4_stateid current_stateid;
484
485 const struct cred *nfs4_get_clid_cred(struct nfs_client *clp);
486 const struct cred *nfs4_get_machine_cred(struct nfs_client *clp);
487 const struct cred *nfs4_get_renew_cred(struct nfs_client *clp);
488 int nfs4_discover_server_trunking(struct nfs_client *clp,
489 struct nfs_client **);
490 int nfs40_discover_server_trunking(struct nfs_client *clp,
491 struct nfs_client **, const struct cred *);
492 int nfs41_discover_server_trunking(struct nfs_client *clp,
493 struct nfs_client **, const struct cred *);
494 extern void nfs4_schedule_session_recovery(struct nfs4_session *, int);
495 extern void nfs41_notify_server(struct nfs_client *);
496 bool nfs4_check_serverowner_major_id(struct nfs41_server_owner *o1,
497 struct nfs41_server_owner *o2);
498
499 extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, const struct cred *, gfp_t);
500 extern void nfs4_put_state_owner(struct nfs4_state_owner *);
501 extern void nfs4_purge_state_owners(struct nfs_server *, struct list_head *);
502 extern void nfs4_free_state_owners(struct list_head *head);
503 extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
504 extern void nfs4_put_open_state(struct nfs4_state *);
505 extern void nfs4_close_state(struct nfs4_state *, fmode_t);
506 extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
507 extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
508 extern void nfs_inode_find_state_and_recover(struct inode *inode,
509 const nfs4_stateid *stateid);
510 extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *, struct nfs4_state *);
511 extern void nfs4_schedule_lease_recovery(struct nfs_client *);
512 extern int nfs4_wait_clnt_recover(struct nfs_client *clp);
513 extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
514 extern void nfs4_schedule_state_manager(struct nfs_client *);
515 extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
516 extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
517 extern int nfs4_schedule_migration_recovery(const struct nfs_server *);
518 extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
519 extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags, bool);
520 extern void nfs41_handle_server_scope(struct nfs_client *,
521 struct nfs41_server_scope **);
522 extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
523 extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
524 extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t,
525 const struct nfs_lock_context *, nfs4_stateid *,
526 const struct cred **);
527 extern bool nfs4_copy_open_stateid(nfs4_stateid *dst,
528 struct nfs4_state *state);
529
530 extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
531 extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
532 extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
533 extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
534 extern void nfs_release_seqid(struct nfs_seqid *seqid);
535 extern void nfs_free_seqid(struct nfs_seqid *seqid);
536 extern int nfs4_setup_sequence(struct nfs_client *client,
537 struct nfs4_sequence_args *args,
538 struct nfs4_sequence_res *res,
539 struct rpc_task *task);
540 extern int nfs4_sequence_done(struct rpc_task *task,
541 struct nfs4_sequence_res *res);
542
543 extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
544 extern int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res);
545 extern const nfs4_stateid zero_stateid;
546 extern const nfs4_stateid invalid_stateid;
547
548 /* nfs4super.c */
549 struct nfs_mount_info;
550 extern struct nfs_subversion nfs_v4;
551 extern bool nfs4_disable_idmapping;
552 extern unsigned short max_session_slots;
553 extern unsigned short max_session_cb_slots;
554 extern unsigned short send_implementation_id;
555 extern bool recover_lost_locks;
556 extern short nfs_delay_retrans;
557
558 #define NFS4_CLIENT_ID_UNIQ_LEN (64)
559 extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
560
561 extern int nfs4_try_get_tree(struct fs_context *);
562 extern int nfs4_get_referral_tree(struct fs_context *);
563
564 /* nfs4sysctl.c */
565 #ifdef CONFIG_SYSCTL
566 int nfs4_register_sysctl(void);
567 void nfs4_unregister_sysctl(void);
568 #else
nfs4_register_sysctl(void)569 static inline int nfs4_register_sysctl(void)
570 {
571 return 0;
572 }
573
nfs4_unregister_sysctl(void)574 static inline void nfs4_unregister_sysctl(void)
575 {
576 }
577 #endif
578
579 /* nfs4xdr.c */
580 extern const struct rpc_procinfo nfs4_procedures[];
581
582 #ifdef CONFIG_NFS_V4_2
583 extern const u32 nfs42_maxsetxattr_overhead;
584 extern const u32 nfs42_maxgetxattr_overhead;
585 extern const u32 nfs42_maxlistxattrs_overhead;
586 #endif
587
588 struct nfs4_mount_data;
589
590 /* callback_xdr.c */
591 extern const struct svc_version nfs4_callback_version1;
592 extern const struct svc_version nfs4_callback_version4;
593
nfs4_stateid_copy(nfs4_stateid * dst,const nfs4_stateid * src)594 static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
595 {
596 memcpy(dst->data, src->data, sizeof(dst->data));
597 dst->type = src->type;
598 }
599
nfs4_stateid_match(const nfs4_stateid * dst,const nfs4_stateid * src)600 static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
601 {
602 if (dst->type != src->type)
603 return false;
604 return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
605 }
606
nfs4_stateid_match_other(const nfs4_stateid * dst,const nfs4_stateid * src)607 static inline bool nfs4_stateid_match_other(const nfs4_stateid *dst, const nfs4_stateid *src)
608 {
609 return memcmp(dst->other, src->other, NFS4_STATEID_OTHER_SIZE) == 0;
610 }
611
nfs4_stateid_is_newer(const nfs4_stateid * s1,const nfs4_stateid * s2)612 static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stateid *s2)
613 {
614 return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0;
615 }
616
nfs4_stateid_is_next(const nfs4_stateid * s1,const nfs4_stateid * s2)617 static inline bool nfs4_stateid_is_next(const nfs4_stateid *s1, const nfs4_stateid *s2)
618 {
619 u32 seq1 = be32_to_cpu(s1->seqid);
620 u32 seq2 = be32_to_cpu(s2->seqid);
621
622 return seq2 == seq1 + 1U || (seq2 == 1U && seq1 == 0xffffffffU);
623 }
624
nfs4_stateid_match_or_older(const nfs4_stateid * dst,const nfs4_stateid * src)625 static inline bool nfs4_stateid_match_or_older(const nfs4_stateid *dst, const nfs4_stateid *src)
626 {
627 return nfs4_stateid_match_other(dst, src) &&
628 !(src->seqid && nfs4_stateid_is_newer(dst, src));
629 }
630
nfs4_stateid_seqid_inc(nfs4_stateid * s1)631 static inline void nfs4_stateid_seqid_inc(nfs4_stateid *s1)
632 {
633 u32 seqid = be32_to_cpu(s1->seqid);
634
635 if (++seqid == 0)
636 ++seqid;
637 s1->seqid = cpu_to_be32(seqid);
638 }
639
nfs4_valid_open_stateid(const struct nfs4_state * state)640 static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
641 {
642 return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0;
643 }
644
nfs4_state_match_open_stateid_other(const struct nfs4_state * state,const nfs4_stateid * stateid)645 static inline bool nfs4_state_match_open_stateid_other(const struct nfs4_state *state,
646 const nfs4_stateid *stateid)
647 {
648 return test_bit(NFS_OPEN_STATE, &state->flags) &&
649 nfs4_stateid_match_other(&state->open_stateid, stateid);
650 }
651
652 /* nfs42xattr.c */
653 #ifdef CONFIG_NFS_V4_2
654 extern int __init nfs4_xattr_cache_init(void);
655 extern void nfs4_xattr_cache_exit(void);
656 extern void nfs4_xattr_cache_add(struct inode *inode, const char *name,
657 const char *buf, struct page **pages,
658 ssize_t buflen);
659 extern void nfs4_xattr_cache_remove(struct inode *inode, const char *name);
660 extern ssize_t nfs4_xattr_cache_get(struct inode *inode, const char *name,
661 char *buf, ssize_t buflen);
662 extern void nfs4_xattr_cache_set_list(struct inode *inode, const char *buf,
663 ssize_t buflen);
664 extern ssize_t nfs4_xattr_cache_list(struct inode *inode, char *buf,
665 ssize_t buflen);
666 extern void nfs4_xattr_cache_zap(struct inode *inode);
667 #else
nfs4_xattr_cache_zap(struct inode * inode)668 static inline void nfs4_xattr_cache_zap(struct inode *inode)
669 {
670 }
671 #endif /* CONFIG_NFS_V4_2 */
672
673 #else /* CONFIG_NFS_V4 */
674
675 #define nfs4_close_state(a, b) do { } while (0)
676 #define nfs4_close_sync(a, b) do { } while (0)
677 #define nfs4_state_protect(a, b, c, d) do { } while (0)
678 #define nfs4_state_protect_write(a, b, c, d) do { } while (0)
679
680
681 #endif /* CONFIG_NFS_V4 */
682 #endif /* __LINUX_FS_NFS_NFS4_FS.H */
683