blob: 2215cdee43ae7da13542955bb14f84a430c531d9 [file] [log] [blame]
Trond Myklebust4ce79712005-06-22 17:16:21 +00001/*
2 * linux/fs/nfs/nfs4_fs.h
3 *
4 * Copyright (C) 2005 Trond Myklebust
5 *
6 * NFSv4-specific filesystem definitions and declarations
7 */
8
9#ifndef __LINUX_FS_NFS_NFS4_FS_H
10#define __LINUX_FS_NFS_NFS4_FS_H
11
12#ifdef CONFIG_NFS_V4
13
14struct idmap;
15
16/*
17 * In a seqid-mutating op, this macro controls which error return
18 * values trigger incrementation of the seqid.
19 *
20 * from rfc 3010:
21 * The client MUST monotonically increment the sequence number for the
22 * CLOSE, LOCK, LOCKU, OPEN, OPEN_CONFIRM, and OPEN_DOWNGRADE
23 * operations. This is true even in the event that the previous
24 * operation that used the sequence number received an error. The only
25 * exception to this rule is if the previous operation received one of
26 * the following errors: NFSERR_STALE_CLIENTID, NFSERR_STALE_STATEID,
27 * NFSERR_BAD_STATEID, NFSERR_BAD_SEQID, NFSERR_BADXDR,
28 * NFSERR_RESOURCE, NFSERR_NOFILEHANDLE.
29 *
30 */
31#define seqid_mutating_err(err) \
32(((err) != NFSERR_STALE_CLIENTID) && \
33 ((err) != NFSERR_STALE_STATEID) && \
34 ((err) != NFSERR_BAD_STATEID) && \
35 ((err) != NFSERR_BAD_SEQID) && \
36 ((err) != NFSERR_BAD_XDR) && \
37 ((err) != NFSERR_RESOURCE) && \
38 ((err) != NFSERR_NOFILEHANDLE))
39
40enum nfs4_client_state {
41 NFS4CLNT_OK = 0,
42};
43
44/*
45 * The nfs4_client identifies our client state to the server.
46 */
47struct nfs4_client {
48 struct list_head cl_servers; /* Global list of servers */
49 struct in_addr cl_addr; /* Server identifier */
50 u64 cl_clientid; /* constant */
51 nfs4_verifier cl_confirm;
52 unsigned long cl_state;
53
54 u32 cl_lockowner_id;
55
56 /*
57 * The following rwsem ensures exclusive access to the server
58 * while we recover the state following a lease expiration.
59 */
60 struct rw_semaphore cl_sem;
61
62 struct list_head cl_delegations;
63 struct list_head cl_state_owners;
64 struct list_head cl_unused;
65 int cl_nunused;
66 spinlock_t cl_lock;
67 atomic_t cl_count;
68
69 struct rpc_clnt * cl_rpcclient;
70 struct rpc_cred * cl_cred;
71
72 struct list_head cl_superblocks; /* List of nfs_server structs */
73
74 unsigned long cl_lease_time;
75 unsigned long cl_last_renewal;
76 struct work_struct cl_renewd;
77 struct work_struct cl_recoverd;
78
79 wait_queue_head_t cl_waitq;
80 struct rpc_wait_queue cl_rpcwaitq;
81
82 /* used for the setclientid verifier */
83 struct timespec cl_boot_time;
84
85 /* idmapper */
86 struct idmap * cl_idmap;
87
88 /* Our own IP address, as a null-terminated string.
89 * This is used to generate the clientid, and the callback address.
90 */
91 char cl_ipaddr[16];
92 unsigned char cl_id_uniquifier;
93};
94
95/*
Trond Myklebustcee54fc2005-10-18 14:20:12 -070096 * struct rpc_sequence ensures that RPC calls are sent in the exact
97 * order that they appear on the list.
98 */
99struct rpc_sequence {
100 struct rpc_wait_queue wait; /* RPC call delay queue */
101 spinlock_t lock; /* Protects the list */
102 struct list_head list; /* Defines sequence of RPC calls */
103};
104
105#define NFS_SEQID_CONFIRMED 1
106struct nfs_seqid_counter {
107 struct rpc_sequence *sequence;
108 int flags;
109 u32 counter;
110};
111
112struct nfs_seqid {
113 struct list_head list;
114 struct nfs_seqid_counter *sequence;
115 struct rpc_task *task;
116};
117
118static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
119{
120 if (seqid_mutating_err(-status))
121 seqid->flags |= NFS_SEQID_CONFIRMED;
122}
123
124/*
Trond Myklebust4ce79712005-06-22 17:16:21 +0000125 * NFS4 state_owners and lock_owners are simply labels for ordered
126 * sequences of RPC calls. Their sole purpose is to provide once-only
127 * semantics by allowing the server to identify replayed requests.
Trond Myklebust4ce79712005-06-22 17:16:21 +0000128 */
129struct nfs4_state_owner {
130 struct list_head so_list; /* per-clientid list of state_owners */
131 struct nfs4_client *so_client;
132 u32 so_id; /* 32-bit identifier, unique */
Trond Myklebust4ce79712005-06-22 17:16:21 +0000133 atomic_t so_count;
134
135 struct rpc_cred *so_cred; /* Associated cred */
136 struct list_head so_states;
137 struct list_head so_delegations;
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700138 struct nfs_seqid_counter so_seqid;
139 struct rpc_sequence so_sequence;
Trond Myklebust4ce79712005-06-22 17:16:21 +0000140};
141
142/*
143 * struct nfs4_state maintains the client-side state for a given
144 * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
145 *
146 * OPEN:
147 * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
148 * we need to know how many files are open for reading or writing on a
149 * given inode. This information too is stored here.
150 *
151 * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
152 */
153
154struct nfs4_lock_state {
155 struct list_head ls_locks; /* Other lock stateids */
Trond Myklebust8d0a8a92005-06-22 17:16:32 +0000156 struct nfs4_state * ls_state; /* Pointer to open state */
Trond Myklebust4ce79712005-06-22 17:16:21 +0000157 fl_owner_t ls_owner; /* POSIX lock owner */
158#define NFS_LOCK_INITIALIZED 1
159 int ls_flags;
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700160 struct nfs_seqid_counter ls_seqid;
Trond Myklebust4ce79712005-06-22 17:16:21 +0000161 u32 ls_id;
162 nfs4_stateid ls_stateid;
163 atomic_t ls_count;
164};
165
166/* bits for nfs4_state->flags */
167enum {
168 LK_STATE_IN_USE,
169 NFS_DELEGATED_STATE,
170};
171
172struct nfs4_state {
173 struct list_head open_states; /* List of states for the same state_owner */
174 struct list_head inode_states; /* List of states for the same inode */
175 struct list_head lock_states; /* List of subservient lock stateids */
176
177 struct nfs4_state_owner *owner; /* Pointer to the open owner */
178 struct inode *inode; /* Pointer to the inode */
179
180 unsigned long flags; /* Do we hold any locks? */
Trond Myklebust8d0a8a92005-06-22 17:16:32 +0000181 spinlock_t state_lock; /* Protects the lock_states list */
Trond Myklebust4ce79712005-06-22 17:16:21 +0000182
183 nfs4_stateid stateid;
184
185 unsigned int nreaders;
186 unsigned int nwriters;
187 int state; /* State on the server (R,W, or RW) */
188 atomic_t count;
189};
190
191
192struct nfs4_exception {
193 long timeout;
194 int retry;
195};
196
197struct nfs4_state_recovery_ops {
198 int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
199 int (*recover_lock)(struct nfs4_state *, struct file_lock *);
200};
201
202extern struct dentry_operations nfs4_dentry_operations;
203extern struct inode_operations nfs4_dir_inode_operations;
J. Bruce Fields6b3b5492005-06-22 17:16:22 +0000204
205/* inode.c */
206extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t);
207extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int);
208extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
209
Trond Myklebust4ce79712005-06-22 17:16:21 +0000210
211/* nfs4proc.c */
212extern int nfs4_map_errors(int err);
213extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short);
214extern int nfs4_proc_setclientid_confirm(struct nfs4_client *);
215extern int nfs4_proc_async_renew(struct nfs4_client *);
216extern int nfs4_proc_renew(struct nfs4_client *);
217extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode);
218extern struct inode *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
219extern int nfs4_open_revalidate(struct inode *, struct dentry *, int);
220
221extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops;
222extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops;
223
224extern const u32 nfs4_fattr_bitmap[2];
225extern const u32 nfs4_statfs_bitmap[2];
226extern const u32 nfs4_pathconf_bitmap[2];
227extern const u32 nfs4_fsinfo_bitmap[2];
228
229/* nfs4renewd.c */
230extern void nfs4_schedule_state_renewal(struct nfs4_client *);
231extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
232extern void nfs4_kill_renewd(struct nfs4_client *);
233extern void nfs4_renew_state(void *);
234
235/* nfs4state.c */
236extern void init_nfsv4_state(struct nfs_server *);
237extern void destroy_nfsv4_state(struct nfs_server *);
238extern struct nfs4_client *nfs4_get_client(struct in_addr *);
239extern void nfs4_put_client(struct nfs4_client *clp);
240extern int nfs4_init_client(struct nfs4_client *clp);
241extern struct nfs4_client *nfs4_find_client(struct in_addr *);
242extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
243
244extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
245extern void nfs4_put_state_owner(struct nfs4_state_owner *);
246extern void nfs4_drop_state_owner(struct nfs4_state_owner *);
247extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
248extern void nfs4_put_open_state(struct nfs4_state *);
249extern void nfs4_close_state(struct nfs4_state *, mode_t);
250extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode);
Trond Myklebust4ce79712005-06-22 17:16:21 +0000251extern void nfs4_schedule_state_recovery(struct nfs4_client *);
Trond Myklebustfaf5f492005-10-18 14:20:15 -0700252extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
Trond Myklebust8d0a8a92005-06-22 17:16:32 +0000253extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
Trond Myklebust4ce79712005-06-22 17:16:21 +0000254extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
255
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700256extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter);
257extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
258extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
259extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
260extern void nfs_free_seqid(struct nfs_seqid *seqid);
261
Trond Myklebust4ce79712005-06-22 17:16:21 +0000262extern const nfs4_stateid zero_stateid;
263
264/* nfs4xdr.c */
265extern uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus);
266extern struct rpc_procinfo nfs4_procedures[];
267
268struct nfs4_mount_data;
269
270/* callback_xdr.c */
271extern struct svc_version nfs4_callback_version1;
272
273#else
274
275#define init_nfsv4_state(server) do { } while (0)
276#define destroy_nfsv4_state(server) do { } while (0)
277#define nfs4_put_state_owner(inode, owner) do { } while (0)
278#define nfs4_put_open_state(state) do { } while (0)
279#define nfs4_close_state(a, b) do { } while (0)
280
281#endif /* CONFIG_NFS_V4 */
282#endif /* __LINUX_FS_NFS_NFS4_FS.H */