blob: 9a102860df374676ce0b1ae5b304fcf43cf6bb5c [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 {
Trond Myklebust433fbe42006-01-03 09:55:22 +010041 NFS4CLNT_STATE_RECOVER = 0,
Trond Myklebust58d97142006-01-03 09:55:24 +010042 NFS4CLNT_LEASE_EXPIRED,
Trond Myklebust4ce79712005-06-22 17:16:21 +000043};
44
45/*
46 * The nfs4_client identifies our client state to the server.
47 */
48struct nfs4_client {
49 struct list_head cl_servers; /* Global list of servers */
50 struct in_addr cl_addr; /* Server identifier */
51 u64 cl_clientid; /* constant */
52 nfs4_verifier cl_confirm;
53 unsigned long cl_state;
54
55 u32 cl_lockowner_id;
56
57 /*
58 * The following rwsem ensures exclusive access to the server
59 * while we recover the state following a lease expiration.
60 */
61 struct rw_semaphore cl_sem;
62
63 struct list_head cl_delegations;
64 struct list_head cl_state_owners;
65 struct list_head cl_unused;
66 int cl_nunused;
67 spinlock_t cl_lock;
68 atomic_t cl_count;
69
70 struct rpc_clnt * cl_rpcclient;
Trond Myklebust4ce79712005-06-22 17:16:21 +000071
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
Trond Myklebust4ce79712005-06-22 17:16:21 +000079 struct rpc_wait_queue cl_rpcwaitq;
80
81 /* used for the setclientid verifier */
82 struct timespec cl_boot_time;
83
84 /* idmapper */
85 struct idmap * cl_idmap;
86
87 /* Our own IP address, as a null-terminated string.
88 * This is used to generate the clientid, and the callback address.
89 */
90 char cl_ipaddr[16];
91 unsigned char cl_id_uniquifier;
92};
93
94/*
Trond Myklebustcee54fc2005-10-18 14:20:12 -070095 * struct rpc_sequence ensures that RPC calls are sent in the exact
96 * order that they appear on the list.
97 */
98struct rpc_sequence {
99 struct rpc_wait_queue wait; /* RPC call delay queue */
100 spinlock_t lock; /* Protects the list */
101 struct list_head list; /* Defines sequence of RPC calls */
102};
103
104#define NFS_SEQID_CONFIRMED 1
105struct nfs_seqid_counter {
106 struct rpc_sequence *sequence;
107 int flags;
108 u32 counter;
109};
110
111struct nfs_seqid {
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700112 struct nfs_seqid_counter *sequence;
Trond Myklebust4e513362005-10-20 14:22:41 -0700113 struct list_head list;
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700114};
115
116static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
117{
118 if (seqid_mutating_err(-status))
119 seqid->flags |= NFS_SEQID_CONFIRMED;
120}
121
122/*
Trond Myklebust4ce79712005-06-22 17:16:21 +0000123 * NFS4 state_owners and lock_owners are simply labels for ordered
124 * sequences of RPC calls. Their sole purpose is to provide once-only
125 * semantics by allowing the server to identify replayed requests.
Trond Myklebust4ce79712005-06-22 17:16:21 +0000126 */
127struct nfs4_state_owner {
Trond Myklebustec073422005-10-20 14:22:47 -0700128 spinlock_t so_lock;
Trond Myklebust4ce79712005-06-22 17:16:21 +0000129 struct list_head so_list; /* per-clientid list of state_owners */
130 struct nfs4_client *so_client;
131 u32 so_id; /* 32-bit identifier, unique */
Trond Myklebust4ce79712005-06-22 17:16:21 +0000132 atomic_t so_count;
133
134 struct rpc_cred *so_cred; /* Associated cred */
135 struct list_head so_states;
136 struct list_head so_delegations;
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700137 struct nfs_seqid_counter so_seqid;
138 struct rpc_sequence so_sequence;
Trond Myklebust4ce79712005-06-22 17:16:21 +0000139};
140
141/*
142 * struct nfs4_state maintains the client-side state for a given
143 * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
144 *
145 * OPEN:
146 * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
147 * we need to know how many files are open for reading or writing on a
148 * given inode. This information too is stored here.
149 *
150 * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
151 */
152
153struct nfs4_lock_state {
154 struct list_head ls_locks; /* Other lock stateids */
Trond Myklebust8d0a8a92005-06-22 17:16:32 +0000155 struct nfs4_state * ls_state; /* Pointer to open state */
Trond Myklebust4ce79712005-06-22 17:16:21 +0000156 fl_owner_t ls_owner; /* POSIX lock owner */
157#define NFS_LOCK_INITIALIZED 1
158 int ls_flags;
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700159 struct nfs_seqid_counter ls_seqid;
Trond Myklebust4ce79712005-06-22 17:16:21 +0000160 u32 ls_id;
161 nfs4_stateid ls_stateid;
162 atomic_t ls_count;
163};
164
165/* bits for nfs4_state->flags */
166enum {
167 LK_STATE_IN_USE,
168 NFS_DELEGATED_STATE,
169};
170
171struct nfs4_state {
172 struct list_head open_states; /* List of states for the same state_owner */
173 struct list_head inode_states; /* List of states for the same inode */
174 struct list_head lock_states; /* List of subservient lock stateids */
175
176 struct nfs4_state_owner *owner; /* Pointer to the open owner */
177 struct inode *inode; /* Pointer to the inode */
178
179 unsigned long flags; /* Do we hold any locks? */
Trond Myklebust8d0a8a92005-06-22 17:16:32 +0000180 spinlock_t state_lock; /* Protects the lock_states list */
Trond Myklebust4ce79712005-06-22 17:16:21 +0000181
182 nfs4_stateid stateid;
183
Trond Myklebuste7616922006-01-03 09:55:13 +0100184 unsigned int n_rdonly;
185 unsigned int n_wronly;
186 unsigned int n_rdwr;
Trond Myklebust4ce79712005-06-22 17:16:21 +0000187 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);
Trond Myklebust286d7d62006-01-03 09:55:26 +0100213extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short, struct rpc_cred *);
214extern int nfs4_proc_setclientid_confirm(struct nfs4_client *, struct rpc_cred *);
Trond Myklebustb4454fe2006-01-03 09:55:25 +0100215extern int nfs4_proc_async_renew(struct nfs4_client *, struct rpc_cred *);
216extern int nfs4_proc_renew(struct nfs4_client *, struct rpc_cred *);
Trond Myklebust4cecb762005-11-04 15:32:58 -0500217extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state);
Trond Myklebust02a913a2005-10-18 14:20:17 -0700218extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
219extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
Trond Myklebust55a97592006-06-09 09:34:19 -0400220extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
Trond Myklebust683b57b2006-06-09 09:34:22 -0400221extern int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry,
Manoj Naik7aaa0b32006-06-09 09:34:23 -0400222 struct nfs4_fs_locations *fs_locations, struct page *page);
Trond Myklebust4ce79712005-06-22 17:16:21 +0000223
224extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops;
225extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops;
226
227extern const u32 nfs4_fattr_bitmap[2];
228extern const u32 nfs4_statfs_bitmap[2];
229extern const u32 nfs4_pathconf_bitmap[2];
230extern const u32 nfs4_fsinfo_bitmap[2];
Manoj Naik830b8e32006-06-09 09:34:25 -0400231extern const u32 nfs4_fs_locations_bitmap[2];
Trond Myklebust4ce79712005-06-22 17:16:21 +0000232
233/* nfs4renewd.c */
234extern void nfs4_schedule_state_renewal(struct nfs4_client *);
235extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
236extern void nfs4_kill_renewd(struct nfs4_client *);
237extern void nfs4_renew_state(void *);
238
239/* nfs4state.c */
240extern void init_nfsv4_state(struct nfs_server *);
241extern void destroy_nfsv4_state(struct nfs_server *);
242extern struct nfs4_client *nfs4_get_client(struct in_addr *);
243extern void nfs4_put_client(struct nfs4_client *clp);
Trond Myklebust4ce79712005-06-22 17:16:21 +0000244extern struct nfs4_client *nfs4_find_client(struct in_addr *);
Trond Myklebustb4454fe2006-01-03 09:55:25 +0100245struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp);
Trond Myklebust4ce79712005-06-22 17:16:21 +0000246extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
247
248extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
249extern void nfs4_put_state_owner(struct nfs4_state_owner *);
250extern void nfs4_drop_state_owner(struct nfs4_state_owner *);
251extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
252extern void nfs4_put_open_state(struct nfs4_state *);
253extern void nfs4_close_state(struct nfs4_state *, mode_t);
Trond Myklebust4cecb762005-11-04 15:32:58 -0500254extern void nfs4_state_set_mode_locked(struct nfs4_state *, mode_t);
Trond Myklebust4ce79712005-06-22 17:16:21 +0000255extern void nfs4_schedule_state_recovery(struct nfs4_client *);
Trond Myklebustfaf5f492005-10-18 14:20:15 -0700256extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
Trond Myklebust8d0a8a92005-06-22 17:16:32 +0000257extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
Trond Myklebust4ce79712005-06-22 17:16:21 +0000258extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
259
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700260extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter);
261extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
262extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
263extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
264extern void nfs_free_seqid(struct nfs_seqid *seqid);
265
Trond Myklebust4ce79712005-06-22 17:16:21 +0000266extern const nfs4_stateid zero_stateid;
267
268/* nfs4xdr.c */
269extern uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus);
270extern struct rpc_procinfo nfs4_procedures[];
271
272struct nfs4_mount_data;
273
274/* callback_xdr.c */
275extern struct svc_version nfs4_callback_version1;
276
277#else
278
279#define init_nfsv4_state(server) do { } while (0)
280#define destroy_nfsv4_state(server) do { } while (0)
281#define nfs4_put_state_owner(inode, owner) do { } while (0)
282#define nfs4_put_open_state(state) do { } while (0)
283#define nfs4_close_state(a, b) do { } while (0)
284
285#endif /* CONFIG_NFS_V4 */
286#endif /* __LINUX_FS_NFS_NFS4_FS.H */