1
2
3
4
5
6
7
8
9#ifndef __LINUX_FS_NFS_NFS4_FS_H
10#define __LINUX_FS_NFS_NFS4_FS_H
11
12#if defined(CONFIG_NFS_V4_2)
13#define NFS4_MAX_MINOR_VERSION 2
14#elif defined(CONFIG_NFS_V4_1)
15#define NFS4_MAX_MINOR_VERSION 1
16#else
17#define NFS4_MAX_MINOR_VERSION 0
18#endif
19
20#if IS_ENABLED(CONFIG_NFS_V4)
21
22#define NFS4_MAX_LOOP_ON_RECOVER (10)
23
24#include <linux/seqlock.h>
25
26struct idmap;
27
28enum nfs4_client_state {
29 NFS4CLNT_MANAGER_RUNNING = 0,
30 NFS4CLNT_CHECK_LEASE,
31 NFS4CLNT_LEASE_EXPIRED,
32 NFS4CLNT_RECLAIM_REBOOT,
33 NFS4CLNT_RECLAIM_NOGRACE,
34 NFS4CLNT_DELEGRETURN,
35 NFS4CLNT_SESSION_RESET,
36 NFS4CLNT_LEASE_CONFIRM,
37 NFS4CLNT_SERVER_SCOPE_MISMATCH,
38 NFS4CLNT_PURGE_STATE,
39 NFS4CLNT_BIND_CONN_TO_SESSION,
40 NFS4CLNT_MOVED,
41 NFS4CLNT_LEASE_MOVED,
42 NFS4CLNT_DELEGATION_EXPIRED,
43};
44
45#define NFS4_RENEW_TIMEOUT 0x01
46#define NFS4_RENEW_DELEGATION_CB 0x02
47
48struct nfs_seqid_counter;
49struct nfs4_minor_version_ops {
50 u32 minor_version;
51 unsigned init_caps;
52
53 int (*init_client)(struct nfs_client *);
54 void (*shutdown_client)(struct nfs_client *);
55 bool (*match_stateid)(const nfs4_stateid *,
56 const nfs4_stateid *);
57 int (*find_root_sec)(struct nfs_server *, struct nfs_fh *,
58 struct nfs_fsinfo *);
59 void (*free_lock_state)(struct nfs_server *,
60 struct nfs4_lock_state *);
61 int (*test_and_free_expired)(struct nfs_server *,
62 nfs4_stateid *, struct rpc_cred *);
63 struct nfs_seqid *
64 (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
65 int (*session_trunk)(struct rpc_clnt *, struct rpc_xprt *, void *);
66 const struct rpc_call_ops *call_sync_ops;
67 const struct nfs4_state_recovery_ops *reboot_recovery_ops;
68 const struct nfs4_state_recovery_ops *nograce_recovery_ops;
69 const struct nfs4_state_maintenance_ops *state_renewal_ops;
70 const struct nfs4_mig_recovery_ops *mig_recovery_ops;
71};
72
73#define NFS_SEQID_CONFIRMED 1
74struct nfs_seqid_counter {
75 ktime_t create_time;
76 int owner_id;
77 int flags;
78 u32 counter;
79 spinlock_t lock;
80 struct list_head list;
81 struct rpc_wait_queue wait;
82};
83
84struct nfs_seqid {
85 struct nfs_seqid_counter *sequence;
86 struct list_head list;
87 struct rpc_task *task;
88};
89
90static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
91{
92 if (seqid_mutating_err(-status))
93 seqid->flags |= NFS_SEQID_CONFIRMED;
94}
95
96
97
98
99
100
101struct nfs4_state_owner {
102 struct nfs_server *so_server;
103 struct list_head so_lru;
104 unsigned long so_expires;
105 struct rb_node so_server_node;
106
107 struct rpc_cred *so_cred;
108
109 spinlock_t so_lock;
110 atomic_t so_count;
111 unsigned long so_flags;
112 struct list_head so_states;
113 struct nfs_seqid_counter so_seqid;
114 seqcount_t so_reclaim_seqcount;
115 struct mutex so_delegreturn_mutex;
116};
117
118enum {
119 NFS_OWNER_RECLAIM_REBOOT,
120 NFS_OWNER_RECLAIM_NOGRACE
121};
122
123#define NFS_LOCK_NEW 0
124#define NFS_LOCK_RECLAIM 1
125#define NFS_LOCK_EXPIRED 2
126
127
128
129
130
131
132
133
134
135
136
137
138
139struct nfs4_lock_state {
140 struct list_head ls_locks;
141 struct nfs4_state * ls_state;
142#define NFS_LOCK_INITIALIZED 0
143#define NFS_LOCK_LOST 1
144 unsigned long ls_flags;
145 struct nfs_seqid_counter ls_seqid;
146 nfs4_stateid ls_stateid;
147 atomic_t ls_count;
148 fl_owner_t ls_owner;
149};
150
151
152enum {
153 LK_STATE_IN_USE,
154 NFS_DELEGATED_STATE,
155 NFS_OPEN_STATE,
156 NFS_O_RDONLY_STATE,
157 NFS_O_WRONLY_STATE,
158 NFS_O_RDWR_STATE,
159 NFS_STATE_RECLAIM_REBOOT,
160 NFS_STATE_RECLAIM_NOGRACE,
161 NFS_STATE_POSIX_LOCKS,
162 NFS_STATE_RECOVERY_FAILED,
163 NFS_STATE_MAY_NOTIFY_LOCK,
164 NFS_STATE_CHANGE_WAIT,
165};
166
167struct nfs4_state {
168 struct list_head open_states;
169 struct list_head inode_states;
170 struct list_head lock_states;
171
172 struct nfs4_state_owner *owner;
173 struct inode *inode;
174
175 unsigned long flags;
176 spinlock_t state_lock;
177
178 seqlock_t seqlock;
179 nfs4_stateid stateid;
180 nfs4_stateid open_stateid;
181
182
183 unsigned int n_rdonly;
184 unsigned int n_wronly;
185 unsigned int n_rdwr;
186 fmode_t state;
187 atomic_t count;
188
189 wait_queue_head_t waitq;
190};
191
192
193struct nfs4_exception {
194 struct nfs4_state *state;
195 struct inode *inode;
196 nfs4_stateid *stateid;
197 long timeout;
198 unsigned char delay : 1,
199 recovering : 1,
200 retry : 1;
201};
202
203struct nfs4_state_recovery_ops {
204 int owner_flag_bit;
205 int state_flag_bit;
206 int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
207 int (*recover_lock)(struct nfs4_state *, struct file_lock *);
208 int (*establish_clid)(struct nfs_client *, struct rpc_cred *);
209 int (*reclaim_complete)(struct nfs_client *, struct rpc_cred *);
210 int (*detect_trunking)(struct nfs_client *, struct nfs_client **,
211 struct rpc_cred *);
212};
213
214struct nfs4_add_xprt_data {
215 struct nfs_client *clp;
216 struct rpc_cred *cred;
217};
218
219struct nfs4_state_maintenance_ops {
220 int (*sched_state_renewal)(struct nfs_client *, struct rpc_cred *, unsigned);
221 struct rpc_cred * (*get_state_renewal_cred_locked)(struct nfs_client *);
222 int (*renew_lease)(struct nfs_client *, struct rpc_cred *);
223};
224
225struct nfs4_mig_recovery_ops {
226 int (*get_locations)(struct inode *, struct nfs4_fs_locations *,
227 struct page *, struct rpc_cred *);
228 int (*fsid_present)(struct inode *, struct rpc_cred *);
229};
230
231extern const struct dentry_operations nfs4_dentry_operations;
232
233
234int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
235 unsigned, umode_t, int *);
236
237
238extern struct file_system_type nfs4_fs_type;
239
240
241struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *, struct qstr *);
242struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *,
243 struct nfs_fh *, struct nfs_fattr *);
244int nfs4_replace_transport(struct nfs_server *server,
245 const struct nfs4_fs_locations *locations);
246
247
248extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *);
249extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
250 struct rpc_message *, struct nfs4_sequence_args *,
251 struct nfs4_sequence_res *, int);
252extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int);
253extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *);
254extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *);
255extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
256extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, struct rpc_cred *cred);
257extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred);
258extern int nfs4_destroy_clientid(struct nfs_client *clp);
259extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
260extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
261extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait);
262extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
263extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
264 struct nfs4_fs_locations *, struct page *);
265extern int nfs4_proc_get_locations(struct inode *, struct nfs4_fs_locations *,
266 struct page *page, struct rpc_cred *);
267extern int nfs4_proc_fsid_present(struct inode *, struct rpc_cred *);
268extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, struct qstr *,
269 struct nfs_fh *, struct nfs_fattr *);
270extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
271extern const struct xattr_handler *nfs4_xattr_handlers[];
272extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
273 const struct nfs_open_context *ctx,
274 const struct nfs_lock_context *l_ctx,
275 fmode_t fmode);
276
277#if defined(CONFIG_NFS_V4_1)
278extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *);
279extern int nfs4_proc_create_session(struct nfs_client *, struct rpc_cred *);
280extern int nfs4_proc_destroy_session(struct nfs4_session *, struct rpc_cred *);
281extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
282 struct nfs_fsinfo *fsinfo);
283extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
284 bool sync);
285extern int nfs4_detect_session_trunking(struct nfs_client *clp,
286 struct nfs41_exchange_id_res *res, struct rpc_xprt *xprt);
287
288static inline bool
289is_ds_only_client(struct nfs_client *clp)
290{
291 return (clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) ==
292 EXCHGID4_FLAG_USE_PNFS_DS;
293}
294
295static inline bool
296is_ds_client(struct nfs_client *clp)
297{
298 return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
299}
300
301static inline bool
302_nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
303 struct rpc_clnt **clntp, struct rpc_message *msg)
304{
305 struct rpc_cred *newcred = NULL;
306 rpc_authflavor_t flavor;
307
308 if (test_bit(sp4_mode, &clp->cl_sp4_flags)) {
309 spin_lock(&clp->cl_lock);
310 if (clp->cl_machine_cred != NULL)
311
312
313 newcred = clp->cl_machine_cred;
314 spin_unlock(&clp->cl_lock);
315 msg->rpc_cred = newcred;
316
317 flavor = clp->cl_rpcclient->cl_auth->au_flavor;
318 WARN_ON_ONCE(flavor != RPC_AUTH_GSS_KRB5I &&
319 flavor != RPC_AUTH_GSS_KRB5P);
320 *clntp = clp->cl_rpcclient;
321
322 return true;
323 }
324 return false;
325}
326
327
328
329
330
331
332
333static inline void
334nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
335 struct rpc_clnt **clntp, struct rpc_message *msg)
336{
337 _nfs4_state_protect(clp, sp4_mode, clntp, msg);
338}
339
340
341
342
343
344
345static inline void
346nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
347 struct rpc_message *msg, struct nfs_pgio_header *hdr)
348{
349 if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) &&
350 !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
351 hdr->args.stable = NFS_FILE_SYNC;
352}
353#else
354static inline bool
355is_ds_only_client(struct nfs_client *clp)
356{
357 return false;
358}
359
360static inline bool
361is_ds_client(struct nfs_client *clp)
362{
363 return false;
364}
365
366static inline void
367nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags,
368 struct rpc_clnt **clntp, struct rpc_message *msg)
369{
370}
371
372static inline void
373nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
374 struct rpc_message *msg, struct nfs_pgio_header *hdr)
375{
376}
377#endif
378
379extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];
380
381extern const u32 nfs4_fattr_bitmap[3];
382extern const u32 nfs4_statfs_bitmap[3];
383extern const u32 nfs4_pathconf_bitmap[3];
384extern const u32 nfs4_fsinfo_bitmap[3];
385extern const u32 nfs4_fs_locations_bitmap[3];
386
387void nfs40_shutdown_client(struct nfs_client *);
388void nfs41_shutdown_client(struct nfs_client *);
389int nfs40_init_client(struct nfs_client *);
390int nfs41_init_client(struct nfs_client *);
391void nfs4_free_client(struct nfs_client *);
392
393struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *);
394
395
396extern void nfs4_schedule_state_renewal(struct nfs_client *);
397extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
398extern void nfs4_kill_renewd(struct nfs_client *);
399extern void nfs4_renew_state(struct work_struct *);
400extern void nfs4_set_lease_period(struct nfs_client *clp,
401 unsigned long lease,
402 unsigned long lastrenewed);
403
404
405
406struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp);
407struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp);
408struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp);
409int nfs4_discover_server_trunking(struct nfs_client *clp,
410 struct nfs_client **);
411int nfs40_discover_server_trunking(struct nfs_client *clp,
412 struct nfs_client **, struct rpc_cred *);
413#if defined(CONFIG_NFS_V4_1)
414int nfs41_discover_server_trunking(struct nfs_client *clp,
415 struct nfs_client **, struct rpc_cred *);
416extern void nfs4_schedule_session_recovery(struct nfs4_session *, int);
417extern void nfs41_notify_server(struct nfs_client *);
418#else
419static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err)
420{
421}
422#endif
423
424extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *, gfp_t);
425extern void nfs4_put_state_owner(struct nfs4_state_owner *);
426extern void nfs4_purge_state_owners(struct nfs_server *);
427extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
428extern void nfs4_put_open_state(struct nfs4_state *);
429extern void nfs4_close_state(struct nfs4_state *, fmode_t);
430extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
431extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
432extern void nfs_inode_find_state_and_recover(struct inode *inode,
433 const nfs4_stateid *stateid);
434extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *, struct nfs4_state *);
435extern void nfs4_schedule_lease_recovery(struct nfs_client *);
436extern int nfs4_wait_clnt_recover(struct nfs_client *clp);
437extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
438extern void nfs4_schedule_state_manager(struct nfs_client *);
439extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
440extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
441extern int nfs4_schedule_migration_recovery(const struct nfs_server *);
442extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
443extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags, bool);
444extern void nfs41_handle_server_scope(struct nfs_client *,
445 struct nfs41_server_scope **);
446extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
447extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
448extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t,
449 const struct nfs_lock_context *, nfs4_stateid *,
450 struct rpc_cred **);
451extern bool nfs4_refresh_open_stateid(nfs4_stateid *dst,
452 struct nfs4_state *state);
453extern bool nfs4_copy_open_stateid(nfs4_stateid *dst,
454 struct nfs4_state *state);
455
456extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
457extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
458extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
459extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
460extern void nfs_release_seqid(struct nfs_seqid *seqid);
461extern void nfs_free_seqid(struct nfs_seqid *seqid);
462extern int nfs4_setup_sequence(struct nfs_client *client,
463 struct nfs4_sequence_args *args,
464 struct nfs4_sequence_res *res,
465 struct rpc_task *task);
466extern int nfs4_sequence_done(struct rpc_task *task,
467 struct nfs4_sequence_res *res);
468
469extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
470
471extern const nfs4_stateid zero_stateid;
472extern const nfs4_stateid invalid_stateid;
473
474
475struct nfs_mount_info;
476extern struct nfs_subversion nfs_v4;
477struct dentry *nfs4_try_mount(int, const char *, struct nfs_mount_info *, struct nfs_subversion *);
478extern bool nfs4_disable_idmapping;
479extern unsigned short max_session_slots;
480extern unsigned short send_implementation_id;
481extern bool recover_lost_locks;
482
483#define NFS4_CLIENT_ID_UNIQ_LEN (64)
484extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
485
486
487#ifdef CONFIG_SYSCTL
488int nfs4_register_sysctl(void);
489void nfs4_unregister_sysctl(void);
490#else
491static inline int nfs4_register_sysctl(void)
492{
493 return 0;
494}
495
496static inline void nfs4_unregister_sysctl(void)
497{
498}
499#endif
500
501
502extern struct rpc_procinfo nfs4_procedures[];
503
504struct nfs4_mount_data;
505
506
507extern struct svc_version nfs4_callback_version1;
508extern struct svc_version nfs4_callback_version4;
509
510static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
511{
512 memcpy(dst->data, src->data, sizeof(dst->data));
513 dst->type = src->type;
514}
515
516static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
517{
518 if (dst->type != src->type)
519 return false;
520 return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
521}
522
523static inline bool nfs4_stateid_match_other(const nfs4_stateid *dst, const nfs4_stateid *src)
524{
525 return memcmp(dst->other, src->other, NFS4_STATEID_OTHER_SIZE) == 0;
526}
527
528static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stateid *s2)
529{
530 return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0;
531}
532
533static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
534{
535 return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0;
536}
537
538static inline bool nfs4_state_match_open_stateid_other(const struct nfs4_state *state,
539 const nfs4_stateid *stateid)
540{
541 return test_bit(NFS_OPEN_STATE, &state->flags) &&
542 nfs4_stateid_match_other(&state->open_stateid, stateid);
543}
544
545#else
546
547#define nfs4_close_state(a, b) do { } while (0)
548#define nfs4_close_sync(a, b) do { } while (0)
549#define nfs4_state_protect(a, b, c, d) do { } while (0)
550#define nfs4_state_protect_write(a, b, c, d) do { } while (0)
551
552#endif
553#endif
554