Commit 51581f3bf922512880f52a7777923fd6dcfc792b
1 parent
3e4f6290ca
Exists in
master
and in
7 other branches
NFSv4: SETCLIENTID_CONFIRM should handle NFS4ERR_DELAY/NFS4ERR_RESOURCE
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Showing 2 changed files with 20 additions and 2 deletions Inline Diff
fs/nfs/nfs4proc.c
1 | /* | 1 | /* |
2 | * fs/nfs/nfs4proc.c | 2 | * fs/nfs/nfs4proc.c |
3 | * | 3 | * |
4 | * Client-side procedure declarations for NFSv4. | 4 | * Client-side procedure declarations for NFSv4. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 The Regents of the University of Michigan. | 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
7 | * All rights reserved. | 7 | * All rights reserved. |
8 | * | 8 | * |
9 | * Kendrick Smith <kmsmith@umich.edu> | 9 | * Kendrick Smith <kmsmith@umich.edu> |
10 | * Andy Adamson <andros@umich.edu> | 10 | * Andy Adamson <andros@umich.edu> |
11 | * | 11 | * |
12 | * Redistribution and use in source and binary forms, with or without | 12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | 13 | * modification, are permitted provided that the following conditions |
14 | * are met: | 14 | * are met: |
15 | * | 15 | * |
16 | * 1. Redistributions of source code must retain the above copyright | 16 | * 1. Redistributions of source code must retain the above copyright |
17 | * notice, this list of conditions and the following disclaimer. | 17 | * notice, this list of conditions and the following disclaimer. |
18 | * 2. Redistributions in binary form must reproduce the above copyright | 18 | * 2. Redistributions in binary form must reproduce the above copyright |
19 | * notice, this list of conditions and the following disclaimer in the | 19 | * notice, this list of conditions and the following disclaimer in the |
20 | * documentation and/or other materials provided with the distribution. | 20 | * documentation and/or other materials provided with the distribution. |
21 | * 3. Neither the name of the University nor the names of its | 21 | * 3. Neither the name of the University nor the names of its |
22 | * contributors may be used to endorse or promote products derived | 22 | * contributors may be used to endorse or promote products derived |
23 | * from this software without specific prior written permission. | 23 | * from this software without specific prior written permission. |
24 | * | 24 | * |
25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
36 | */ | 36 | */ |
37 | 37 | ||
38 | #include <linux/mm.h> | 38 | #include <linux/mm.h> |
39 | #include <linux/utsname.h> | 39 | #include <linux/utsname.h> |
40 | #include <linux/delay.h> | 40 | #include <linux/delay.h> |
41 | #include <linux/errno.h> | 41 | #include <linux/errno.h> |
42 | #include <linux/string.h> | 42 | #include <linux/string.h> |
43 | #include <linux/sunrpc/clnt.h> | 43 | #include <linux/sunrpc/clnt.h> |
44 | #include <linux/nfs.h> | 44 | #include <linux/nfs.h> |
45 | #include <linux/nfs4.h> | 45 | #include <linux/nfs4.h> |
46 | #include <linux/nfs_fs.h> | 46 | #include <linux/nfs_fs.h> |
47 | #include <linux/nfs_page.h> | 47 | #include <linux/nfs_page.h> |
48 | #include <linux/smp_lock.h> | 48 | #include <linux/smp_lock.h> |
49 | #include <linux/namei.h> | 49 | #include <linux/namei.h> |
50 | #include <linux/mount.h> | 50 | #include <linux/mount.h> |
51 | 51 | ||
52 | #include "nfs4_fs.h" | 52 | #include "nfs4_fs.h" |
53 | #include "delegation.h" | 53 | #include "delegation.h" |
54 | #include "iostat.h" | 54 | #include "iostat.h" |
55 | 55 | ||
56 | #define NFSDBG_FACILITY NFSDBG_PROC | 56 | #define NFSDBG_FACILITY NFSDBG_PROC |
57 | 57 | ||
58 | #define NFS4_POLL_RETRY_MIN (1*HZ) | 58 | #define NFS4_POLL_RETRY_MIN (1*HZ) |
59 | #define NFS4_POLL_RETRY_MAX (15*HZ) | 59 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
60 | 60 | ||
61 | struct nfs4_opendata; | 61 | struct nfs4_opendata; |
62 | static int _nfs4_proc_open(struct nfs4_opendata *data); | 62 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
63 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); | 63 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
64 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *); | 64 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *); |
65 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry); | 65 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry); |
66 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception); | 66 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception); |
67 | static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp); | 67 | static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp); |
68 | extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus); | 68 | extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus); |
69 | extern struct rpc_procinfo nfs4_procedures[]; | 69 | extern struct rpc_procinfo nfs4_procedures[]; |
70 | 70 | ||
71 | /* Prevent leaks of NFSv4 errors into userland */ | 71 | /* Prevent leaks of NFSv4 errors into userland */ |
72 | int nfs4_map_errors(int err) | 72 | int nfs4_map_errors(int err) |
73 | { | 73 | { |
74 | if (err < -1000) { | 74 | if (err < -1000) { |
75 | dprintk("%s could not handle NFSv4 error %d\n", | 75 | dprintk("%s could not handle NFSv4 error %d\n", |
76 | __FUNCTION__, -err); | 76 | __FUNCTION__, -err); |
77 | return -EIO; | 77 | return -EIO; |
78 | } | 78 | } |
79 | return err; | 79 | return err; |
80 | } | 80 | } |
81 | 81 | ||
82 | /* | 82 | /* |
83 | * This is our standard bitmap for GETATTR requests. | 83 | * This is our standard bitmap for GETATTR requests. |
84 | */ | 84 | */ |
85 | const u32 nfs4_fattr_bitmap[2] = { | 85 | const u32 nfs4_fattr_bitmap[2] = { |
86 | FATTR4_WORD0_TYPE | 86 | FATTR4_WORD0_TYPE |
87 | | FATTR4_WORD0_CHANGE | 87 | | FATTR4_WORD0_CHANGE |
88 | | FATTR4_WORD0_SIZE | 88 | | FATTR4_WORD0_SIZE |
89 | | FATTR4_WORD0_FSID | 89 | | FATTR4_WORD0_FSID |
90 | | FATTR4_WORD0_FILEID, | 90 | | FATTR4_WORD0_FILEID, |
91 | FATTR4_WORD1_MODE | 91 | FATTR4_WORD1_MODE |
92 | | FATTR4_WORD1_NUMLINKS | 92 | | FATTR4_WORD1_NUMLINKS |
93 | | FATTR4_WORD1_OWNER | 93 | | FATTR4_WORD1_OWNER |
94 | | FATTR4_WORD1_OWNER_GROUP | 94 | | FATTR4_WORD1_OWNER_GROUP |
95 | | FATTR4_WORD1_RAWDEV | 95 | | FATTR4_WORD1_RAWDEV |
96 | | FATTR4_WORD1_SPACE_USED | 96 | | FATTR4_WORD1_SPACE_USED |
97 | | FATTR4_WORD1_TIME_ACCESS | 97 | | FATTR4_WORD1_TIME_ACCESS |
98 | | FATTR4_WORD1_TIME_METADATA | 98 | | FATTR4_WORD1_TIME_METADATA |
99 | | FATTR4_WORD1_TIME_MODIFY | 99 | | FATTR4_WORD1_TIME_MODIFY |
100 | }; | 100 | }; |
101 | 101 | ||
102 | const u32 nfs4_statfs_bitmap[2] = { | 102 | const u32 nfs4_statfs_bitmap[2] = { |
103 | FATTR4_WORD0_FILES_AVAIL | 103 | FATTR4_WORD0_FILES_AVAIL |
104 | | FATTR4_WORD0_FILES_FREE | 104 | | FATTR4_WORD0_FILES_FREE |
105 | | FATTR4_WORD0_FILES_TOTAL, | 105 | | FATTR4_WORD0_FILES_TOTAL, |
106 | FATTR4_WORD1_SPACE_AVAIL | 106 | FATTR4_WORD1_SPACE_AVAIL |
107 | | FATTR4_WORD1_SPACE_FREE | 107 | | FATTR4_WORD1_SPACE_FREE |
108 | | FATTR4_WORD1_SPACE_TOTAL | 108 | | FATTR4_WORD1_SPACE_TOTAL |
109 | }; | 109 | }; |
110 | 110 | ||
111 | const u32 nfs4_pathconf_bitmap[2] = { | 111 | const u32 nfs4_pathconf_bitmap[2] = { |
112 | FATTR4_WORD0_MAXLINK | 112 | FATTR4_WORD0_MAXLINK |
113 | | FATTR4_WORD0_MAXNAME, | 113 | | FATTR4_WORD0_MAXNAME, |
114 | 0 | 114 | 0 |
115 | }; | 115 | }; |
116 | 116 | ||
117 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE | 117 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
118 | | FATTR4_WORD0_MAXREAD | 118 | | FATTR4_WORD0_MAXREAD |
119 | | FATTR4_WORD0_MAXWRITE | 119 | | FATTR4_WORD0_MAXWRITE |
120 | | FATTR4_WORD0_LEASE_TIME, | 120 | | FATTR4_WORD0_LEASE_TIME, |
121 | 0 | 121 | 0 |
122 | }; | 122 | }; |
123 | 123 | ||
124 | static void nfs4_setup_readdir(u64 cookie, u32 *verifier, struct dentry *dentry, | 124 | static void nfs4_setup_readdir(u64 cookie, u32 *verifier, struct dentry *dentry, |
125 | struct nfs4_readdir_arg *readdir) | 125 | struct nfs4_readdir_arg *readdir) |
126 | { | 126 | { |
127 | u32 *start, *p; | 127 | u32 *start, *p; |
128 | 128 | ||
129 | BUG_ON(readdir->count < 80); | 129 | BUG_ON(readdir->count < 80); |
130 | if (cookie > 2) { | 130 | if (cookie > 2) { |
131 | readdir->cookie = cookie; | 131 | readdir->cookie = cookie; |
132 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); | 132 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
133 | return; | 133 | return; |
134 | } | 134 | } |
135 | 135 | ||
136 | readdir->cookie = 0; | 136 | readdir->cookie = 0; |
137 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); | 137 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
138 | if (cookie == 2) | 138 | if (cookie == 2) |
139 | return; | 139 | return; |
140 | 140 | ||
141 | /* | 141 | /* |
142 | * NFSv4 servers do not return entries for '.' and '..' | 142 | * NFSv4 servers do not return entries for '.' and '..' |
143 | * Therefore, we fake these entries here. We let '.' | 143 | * Therefore, we fake these entries here. We let '.' |
144 | * have cookie 0 and '..' have cookie 1. Note that | 144 | * have cookie 0 and '..' have cookie 1. Note that |
145 | * when talking to the server, we always send cookie 0 | 145 | * when talking to the server, we always send cookie 0 |
146 | * instead of 1 or 2. | 146 | * instead of 1 or 2. |
147 | */ | 147 | */ |
148 | start = p = (u32 *)kmap_atomic(*readdir->pages, KM_USER0); | 148 | start = p = (u32 *)kmap_atomic(*readdir->pages, KM_USER0); |
149 | 149 | ||
150 | if (cookie == 0) { | 150 | if (cookie == 0) { |
151 | *p++ = xdr_one; /* next */ | 151 | *p++ = xdr_one; /* next */ |
152 | *p++ = xdr_zero; /* cookie, first word */ | 152 | *p++ = xdr_zero; /* cookie, first word */ |
153 | *p++ = xdr_one; /* cookie, second word */ | 153 | *p++ = xdr_one; /* cookie, second word */ |
154 | *p++ = xdr_one; /* entry len */ | 154 | *p++ = xdr_one; /* entry len */ |
155 | memcpy(p, ".\0\0\0", 4); /* entry */ | 155 | memcpy(p, ".\0\0\0", 4); /* entry */ |
156 | p++; | 156 | p++; |
157 | *p++ = xdr_one; /* bitmap length */ | 157 | *p++ = xdr_one; /* bitmap length */ |
158 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ | 158 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
159 | *p++ = htonl(8); /* attribute buffer length */ | 159 | *p++ = htonl(8); /* attribute buffer length */ |
160 | p = xdr_encode_hyper(p, dentry->d_inode->i_ino); | 160 | p = xdr_encode_hyper(p, dentry->d_inode->i_ino); |
161 | } | 161 | } |
162 | 162 | ||
163 | *p++ = xdr_one; /* next */ | 163 | *p++ = xdr_one; /* next */ |
164 | *p++ = xdr_zero; /* cookie, first word */ | 164 | *p++ = xdr_zero; /* cookie, first word */ |
165 | *p++ = xdr_two; /* cookie, second word */ | 165 | *p++ = xdr_two; /* cookie, second word */ |
166 | *p++ = xdr_two; /* entry len */ | 166 | *p++ = xdr_two; /* entry len */ |
167 | memcpy(p, "..\0\0", 4); /* entry */ | 167 | memcpy(p, "..\0\0", 4); /* entry */ |
168 | p++; | 168 | p++; |
169 | *p++ = xdr_one; /* bitmap length */ | 169 | *p++ = xdr_one; /* bitmap length */ |
170 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ | 170 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
171 | *p++ = htonl(8); /* attribute buffer length */ | 171 | *p++ = htonl(8); /* attribute buffer length */ |
172 | p = xdr_encode_hyper(p, dentry->d_parent->d_inode->i_ino); | 172 | p = xdr_encode_hyper(p, dentry->d_parent->d_inode->i_ino); |
173 | 173 | ||
174 | readdir->pgbase = (char *)p - (char *)start; | 174 | readdir->pgbase = (char *)p - (char *)start; |
175 | readdir->count -= readdir->pgbase; | 175 | readdir->count -= readdir->pgbase; |
176 | kunmap_atomic(start, KM_USER0); | 176 | kunmap_atomic(start, KM_USER0); |
177 | } | 177 | } |
178 | 178 | ||
179 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) | 179 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
180 | { | 180 | { |
181 | struct nfs4_client *clp = server->nfs4_state; | 181 | struct nfs4_client *clp = server->nfs4_state; |
182 | spin_lock(&clp->cl_lock); | 182 | spin_lock(&clp->cl_lock); |
183 | if (time_before(clp->cl_last_renewal,timestamp)) | 183 | if (time_before(clp->cl_last_renewal,timestamp)) |
184 | clp->cl_last_renewal = timestamp; | 184 | clp->cl_last_renewal = timestamp; |
185 | spin_unlock(&clp->cl_lock); | 185 | spin_unlock(&clp->cl_lock); |
186 | } | 186 | } |
187 | 187 | ||
188 | static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinfo) | 188 | static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinfo) |
189 | { | 189 | { |
190 | struct nfs_inode *nfsi = NFS_I(inode); | 190 | struct nfs_inode *nfsi = NFS_I(inode); |
191 | 191 | ||
192 | spin_lock(&inode->i_lock); | 192 | spin_lock(&inode->i_lock); |
193 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 193 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; |
194 | if (cinfo->before == nfsi->change_attr && cinfo->atomic) | 194 | if (cinfo->before == nfsi->change_attr && cinfo->atomic) |
195 | nfsi->change_attr = cinfo->after; | 195 | nfsi->change_attr = cinfo->after; |
196 | spin_unlock(&inode->i_lock); | 196 | spin_unlock(&inode->i_lock); |
197 | } | 197 | } |
198 | 198 | ||
199 | struct nfs4_opendata { | 199 | struct nfs4_opendata { |
200 | atomic_t count; | 200 | atomic_t count; |
201 | struct nfs_openargs o_arg; | 201 | struct nfs_openargs o_arg; |
202 | struct nfs_openres o_res; | 202 | struct nfs_openres o_res; |
203 | struct nfs_open_confirmargs c_arg; | 203 | struct nfs_open_confirmargs c_arg; |
204 | struct nfs_open_confirmres c_res; | 204 | struct nfs_open_confirmres c_res; |
205 | struct nfs_fattr f_attr; | 205 | struct nfs_fattr f_attr; |
206 | struct nfs_fattr dir_attr; | 206 | struct nfs_fattr dir_attr; |
207 | struct dentry *dentry; | 207 | struct dentry *dentry; |
208 | struct dentry *dir; | 208 | struct dentry *dir; |
209 | struct nfs4_state_owner *owner; | 209 | struct nfs4_state_owner *owner; |
210 | struct iattr attrs; | 210 | struct iattr attrs; |
211 | unsigned long timestamp; | 211 | unsigned long timestamp; |
212 | int rpc_status; | 212 | int rpc_status; |
213 | int cancelled; | 213 | int cancelled; |
214 | }; | 214 | }; |
215 | 215 | ||
216 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, | 216 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
217 | struct nfs4_state_owner *sp, int flags, | 217 | struct nfs4_state_owner *sp, int flags, |
218 | const struct iattr *attrs) | 218 | const struct iattr *attrs) |
219 | { | 219 | { |
220 | struct dentry *parent = dget_parent(dentry); | 220 | struct dentry *parent = dget_parent(dentry); |
221 | struct inode *dir = parent->d_inode; | 221 | struct inode *dir = parent->d_inode; |
222 | struct nfs_server *server = NFS_SERVER(dir); | 222 | struct nfs_server *server = NFS_SERVER(dir); |
223 | struct nfs4_opendata *p; | 223 | struct nfs4_opendata *p; |
224 | 224 | ||
225 | p = kzalloc(sizeof(*p), GFP_KERNEL); | 225 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
226 | if (p == NULL) | 226 | if (p == NULL) |
227 | goto err; | 227 | goto err; |
228 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); | 228 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); |
229 | if (p->o_arg.seqid == NULL) | 229 | if (p->o_arg.seqid == NULL) |
230 | goto err_free; | 230 | goto err_free; |
231 | atomic_set(&p->count, 1); | 231 | atomic_set(&p->count, 1); |
232 | p->dentry = dget(dentry); | 232 | p->dentry = dget(dentry); |
233 | p->dir = parent; | 233 | p->dir = parent; |
234 | p->owner = sp; | 234 | p->owner = sp; |
235 | atomic_inc(&sp->so_count); | 235 | atomic_inc(&sp->so_count); |
236 | p->o_arg.fh = NFS_FH(dir); | 236 | p->o_arg.fh = NFS_FH(dir); |
237 | p->o_arg.open_flags = flags, | 237 | p->o_arg.open_flags = flags, |
238 | p->o_arg.clientid = server->nfs4_state->cl_clientid; | 238 | p->o_arg.clientid = server->nfs4_state->cl_clientid; |
239 | p->o_arg.id = sp->so_id; | 239 | p->o_arg.id = sp->so_id; |
240 | p->o_arg.name = &dentry->d_name; | 240 | p->o_arg.name = &dentry->d_name; |
241 | p->o_arg.server = server; | 241 | p->o_arg.server = server; |
242 | p->o_arg.bitmask = server->attr_bitmask; | 242 | p->o_arg.bitmask = server->attr_bitmask; |
243 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; | 243 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
244 | p->o_res.f_attr = &p->f_attr; | 244 | p->o_res.f_attr = &p->f_attr; |
245 | p->o_res.dir_attr = &p->dir_attr; | 245 | p->o_res.dir_attr = &p->dir_attr; |
246 | p->o_res.server = server; | 246 | p->o_res.server = server; |
247 | nfs_fattr_init(&p->f_attr); | 247 | nfs_fattr_init(&p->f_attr); |
248 | nfs_fattr_init(&p->dir_attr); | 248 | nfs_fattr_init(&p->dir_attr); |
249 | if (flags & O_EXCL) { | 249 | if (flags & O_EXCL) { |
250 | u32 *s = (u32 *) p->o_arg.u.verifier.data; | 250 | u32 *s = (u32 *) p->o_arg.u.verifier.data; |
251 | s[0] = jiffies; | 251 | s[0] = jiffies; |
252 | s[1] = current->pid; | 252 | s[1] = current->pid; |
253 | } else if (flags & O_CREAT) { | 253 | } else if (flags & O_CREAT) { |
254 | p->o_arg.u.attrs = &p->attrs; | 254 | p->o_arg.u.attrs = &p->attrs; |
255 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); | 255 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
256 | } | 256 | } |
257 | p->c_arg.fh = &p->o_res.fh; | 257 | p->c_arg.fh = &p->o_res.fh; |
258 | p->c_arg.stateid = &p->o_res.stateid; | 258 | p->c_arg.stateid = &p->o_res.stateid; |
259 | p->c_arg.seqid = p->o_arg.seqid; | 259 | p->c_arg.seqid = p->o_arg.seqid; |
260 | return p; | 260 | return p; |
261 | err_free: | 261 | err_free: |
262 | kfree(p); | 262 | kfree(p); |
263 | err: | 263 | err: |
264 | dput(parent); | 264 | dput(parent); |
265 | return NULL; | 265 | return NULL; |
266 | } | 266 | } |
267 | 267 | ||
268 | static void nfs4_opendata_free(struct nfs4_opendata *p) | 268 | static void nfs4_opendata_free(struct nfs4_opendata *p) |
269 | { | 269 | { |
270 | if (p != NULL && atomic_dec_and_test(&p->count)) { | 270 | if (p != NULL && atomic_dec_and_test(&p->count)) { |
271 | nfs_free_seqid(p->o_arg.seqid); | 271 | nfs_free_seqid(p->o_arg.seqid); |
272 | nfs4_put_state_owner(p->owner); | 272 | nfs4_put_state_owner(p->owner); |
273 | dput(p->dir); | 273 | dput(p->dir); |
274 | dput(p->dentry); | 274 | dput(p->dentry); |
275 | kfree(p); | 275 | kfree(p); |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | /* Helper for asynchronous RPC calls */ | 279 | /* Helper for asynchronous RPC calls */ |
280 | static int nfs4_call_async(struct rpc_clnt *clnt, | 280 | static int nfs4_call_async(struct rpc_clnt *clnt, |
281 | const struct rpc_call_ops *tk_ops, void *calldata) | 281 | const struct rpc_call_ops *tk_ops, void *calldata) |
282 | { | 282 | { |
283 | struct rpc_task *task; | 283 | struct rpc_task *task; |
284 | 284 | ||
285 | if (!(task = rpc_new_task(clnt, RPC_TASK_ASYNC, tk_ops, calldata))) | 285 | if (!(task = rpc_new_task(clnt, RPC_TASK_ASYNC, tk_ops, calldata))) |
286 | return -ENOMEM; | 286 | return -ENOMEM; |
287 | rpc_execute(task); | 287 | rpc_execute(task); |
288 | return 0; | 288 | return 0; |
289 | } | 289 | } |
290 | 290 | ||
291 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) | 291 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
292 | { | 292 | { |
293 | sigset_t oldset; | 293 | sigset_t oldset; |
294 | int ret; | 294 | int ret; |
295 | 295 | ||
296 | rpc_clnt_sigmask(task->tk_client, &oldset); | 296 | rpc_clnt_sigmask(task->tk_client, &oldset); |
297 | ret = rpc_wait_for_completion_task(task); | 297 | ret = rpc_wait_for_completion_task(task); |
298 | rpc_clnt_sigunmask(task->tk_client, &oldset); | 298 | rpc_clnt_sigunmask(task->tk_client, &oldset); |
299 | return ret; | 299 | return ret; |
300 | } | 300 | } |
301 | 301 | ||
302 | static inline void update_open_stateflags(struct nfs4_state *state, mode_t open_flags) | 302 | static inline void update_open_stateflags(struct nfs4_state *state, mode_t open_flags) |
303 | { | 303 | { |
304 | switch (open_flags) { | 304 | switch (open_flags) { |
305 | case FMODE_WRITE: | 305 | case FMODE_WRITE: |
306 | state->n_wronly++; | 306 | state->n_wronly++; |
307 | break; | 307 | break; |
308 | case FMODE_READ: | 308 | case FMODE_READ: |
309 | state->n_rdonly++; | 309 | state->n_rdonly++; |
310 | break; | 310 | break; |
311 | case FMODE_READ|FMODE_WRITE: | 311 | case FMODE_READ|FMODE_WRITE: |
312 | state->n_rdwr++; | 312 | state->n_rdwr++; |
313 | } | 313 | } |
314 | } | 314 | } |
315 | 315 | ||
316 | static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags) | 316 | static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags) |
317 | { | 317 | { |
318 | struct inode *inode = state->inode; | 318 | struct inode *inode = state->inode; |
319 | 319 | ||
320 | open_flags &= (FMODE_READ|FMODE_WRITE); | 320 | open_flags &= (FMODE_READ|FMODE_WRITE); |
321 | /* Protect against nfs4_find_state_byowner() */ | 321 | /* Protect against nfs4_find_state_byowner() */ |
322 | spin_lock(&state->owner->so_lock); | 322 | spin_lock(&state->owner->so_lock); |
323 | spin_lock(&inode->i_lock); | 323 | spin_lock(&inode->i_lock); |
324 | memcpy(&state->stateid, stateid, sizeof(state->stateid)); | 324 | memcpy(&state->stateid, stateid, sizeof(state->stateid)); |
325 | update_open_stateflags(state, open_flags); | 325 | update_open_stateflags(state, open_flags); |
326 | nfs4_state_set_mode_locked(state, state->state | open_flags); | 326 | nfs4_state_set_mode_locked(state, state->state | open_flags); |
327 | spin_unlock(&inode->i_lock); | 327 | spin_unlock(&inode->i_lock); |
328 | spin_unlock(&state->owner->so_lock); | 328 | spin_unlock(&state->owner->so_lock); |
329 | } | 329 | } |
330 | 330 | ||
331 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) | 331 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
332 | { | 332 | { |
333 | struct inode *inode; | 333 | struct inode *inode; |
334 | struct nfs4_state *state = NULL; | 334 | struct nfs4_state *state = NULL; |
335 | 335 | ||
336 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) | 336 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
337 | goto out; | 337 | goto out; |
338 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr); | 338 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr); |
339 | if (inode == NULL) | 339 | if (inode == NULL) |
340 | goto out; | 340 | goto out; |
341 | state = nfs4_get_open_state(inode, data->owner); | 341 | state = nfs4_get_open_state(inode, data->owner); |
342 | if (state == NULL) | 342 | if (state == NULL) |
343 | goto put_inode; | 343 | goto put_inode; |
344 | update_open_stateid(state, &data->o_res.stateid, data->o_arg.open_flags); | 344 | update_open_stateid(state, &data->o_res.stateid, data->o_arg.open_flags); |
345 | put_inode: | 345 | put_inode: |
346 | iput(inode); | 346 | iput(inode); |
347 | out: | 347 | out: |
348 | return state; | 348 | return state; |
349 | } | 349 | } |
350 | 350 | ||
351 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) | 351 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
352 | { | 352 | { |
353 | struct nfs_inode *nfsi = NFS_I(state->inode); | 353 | struct nfs_inode *nfsi = NFS_I(state->inode); |
354 | struct nfs_open_context *ctx; | 354 | struct nfs_open_context *ctx; |
355 | 355 | ||
356 | spin_lock(&state->inode->i_lock); | 356 | spin_lock(&state->inode->i_lock); |
357 | list_for_each_entry(ctx, &nfsi->open_files, list) { | 357 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
358 | if (ctx->state != state) | 358 | if (ctx->state != state) |
359 | continue; | 359 | continue; |
360 | get_nfs_open_context(ctx); | 360 | get_nfs_open_context(ctx); |
361 | spin_unlock(&state->inode->i_lock); | 361 | spin_unlock(&state->inode->i_lock); |
362 | return ctx; | 362 | return ctx; |
363 | } | 363 | } |
364 | spin_unlock(&state->inode->i_lock); | 364 | spin_unlock(&state->inode->i_lock); |
365 | return ERR_PTR(-ENOENT); | 365 | return ERR_PTR(-ENOENT); |
366 | } | 366 | } |
367 | 367 | ||
368 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, mode_t openflags, nfs4_stateid *stateid) | 368 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, mode_t openflags, nfs4_stateid *stateid) |
369 | { | 369 | { |
370 | int ret; | 370 | int ret; |
371 | 371 | ||
372 | opendata->o_arg.open_flags = openflags; | 372 | opendata->o_arg.open_flags = openflags; |
373 | ret = _nfs4_proc_open(opendata); | 373 | ret = _nfs4_proc_open(opendata); |
374 | if (ret != 0) | 374 | if (ret != 0) |
375 | return ret; | 375 | return ret; |
376 | memcpy(stateid->data, opendata->o_res.stateid.data, | 376 | memcpy(stateid->data, opendata->o_res.stateid.data, |
377 | sizeof(stateid->data)); | 377 | sizeof(stateid->data)); |
378 | return 0; | 378 | return 0; |
379 | } | 379 | } |
380 | 380 | ||
381 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) | 381 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
382 | { | 382 | { |
383 | nfs4_stateid stateid; | 383 | nfs4_stateid stateid; |
384 | struct nfs4_state *newstate; | 384 | struct nfs4_state *newstate; |
385 | int mode = 0; | 385 | int mode = 0; |
386 | int delegation = 0; | 386 | int delegation = 0; |
387 | int ret; | 387 | int ret; |
388 | 388 | ||
389 | /* memory barrier prior to reading state->n_* */ | 389 | /* memory barrier prior to reading state->n_* */ |
390 | smp_rmb(); | 390 | smp_rmb(); |
391 | if (state->n_rdwr != 0) { | 391 | if (state->n_rdwr != 0) { |
392 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &stateid); | 392 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &stateid); |
393 | if (ret != 0) | 393 | if (ret != 0) |
394 | return ret; | 394 | return ret; |
395 | mode |= FMODE_READ|FMODE_WRITE; | 395 | mode |= FMODE_READ|FMODE_WRITE; |
396 | if (opendata->o_res.delegation_type != 0) | 396 | if (opendata->o_res.delegation_type != 0) |
397 | delegation = opendata->o_res.delegation_type; | 397 | delegation = opendata->o_res.delegation_type; |
398 | smp_rmb(); | 398 | smp_rmb(); |
399 | } | 399 | } |
400 | if (state->n_wronly != 0) { | 400 | if (state->n_wronly != 0) { |
401 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &stateid); | 401 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &stateid); |
402 | if (ret != 0) | 402 | if (ret != 0) |
403 | return ret; | 403 | return ret; |
404 | mode |= FMODE_WRITE; | 404 | mode |= FMODE_WRITE; |
405 | if (opendata->o_res.delegation_type != 0) | 405 | if (opendata->o_res.delegation_type != 0) |
406 | delegation = opendata->o_res.delegation_type; | 406 | delegation = opendata->o_res.delegation_type; |
407 | smp_rmb(); | 407 | smp_rmb(); |
408 | } | 408 | } |
409 | if (state->n_rdonly != 0) { | 409 | if (state->n_rdonly != 0) { |
410 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &stateid); | 410 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &stateid); |
411 | if (ret != 0) | 411 | if (ret != 0) |
412 | return ret; | 412 | return ret; |
413 | mode |= FMODE_READ; | 413 | mode |= FMODE_READ; |
414 | } | 414 | } |
415 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | 415 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
416 | if (mode == 0) | 416 | if (mode == 0) |
417 | return 0; | 417 | return 0; |
418 | if (opendata->o_res.delegation_type == 0) | 418 | if (opendata->o_res.delegation_type == 0) |
419 | opendata->o_res.delegation_type = delegation; | 419 | opendata->o_res.delegation_type = delegation; |
420 | opendata->o_arg.open_flags |= mode; | 420 | opendata->o_arg.open_flags |= mode; |
421 | newstate = nfs4_opendata_to_nfs4_state(opendata); | 421 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
422 | if (newstate != NULL) { | 422 | if (newstate != NULL) { |
423 | if (opendata->o_res.delegation_type != 0) { | 423 | if (opendata->o_res.delegation_type != 0) { |
424 | struct nfs_inode *nfsi = NFS_I(newstate->inode); | 424 | struct nfs_inode *nfsi = NFS_I(newstate->inode); |
425 | int delegation_flags = 0; | 425 | int delegation_flags = 0; |
426 | if (nfsi->delegation) | 426 | if (nfsi->delegation) |
427 | delegation_flags = nfsi->delegation->flags; | 427 | delegation_flags = nfsi->delegation->flags; |
428 | if (!(delegation_flags & NFS_DELEGATION_NEED_RECLAIM)) | 428 | if (!(delegation_flags & NFS_DELEGATION_NEED_RECLAIM)) |
429 | nfs_inode_set_delegation(newstate->inode, | 429 | nfs_inode_set_delegation(newstate->inode, |
430 | opendata->owner->so_cred, | 430 | opendata->owner->so_cred, |
431 | &opendata->o_res); | 431 | &opendata->o_res); |
432 | else | 432 | else |
433 | nfs_inode_reclaim_delegation(newstate->inode, | 433 | nfs_inode_reclaim_delegation(newstate->inode, |
434 | opendata->owner->so_cred, | 434 | opendata->owner->so_cred, |
435 | &opendata->o_res); | 435 | &opendata->o_res); |
436 | } | 436 | } |
437 | nfs4_close_state(newstate, opendata->o_arg.open_flags); | 437 | nfs4_close_state(newstate, opendata->o_arg.open_flags); |
438 | } | 438 | } |
439 | if (newstate != state) | 439 | if (newstate != state) |
440 | return -ESTALE; | 440 | return -ESTALE; |
441 | return 0; | 441 | return 0; |
442 | } | 442 | } |
443 | 443 | ||
444 | /* | 444 | /* |
445 | * OPEN_RECLAIM: | 445 | * OPEN_RECLAIM: |
446 | * reclaim state on the server after a reboot. | 446 | * reclaim state on the server after a reboot. |
447 | */ | 447 | */ |
448 | static int _nfs4_do_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry) | 448 | static int _nfs4_do_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry) |
449 | { | 449 | { |
450 | struct nfs_delegation *delegation = NFS_I(state->inode)->delegation; | 450 | struct nfs_delegation *delegation = NFS_I(state->inode)->delegation; |
451 | struct nfs4_opendata *opendata; | 451 | struct nfs4_opendata *opendata; |
452 | int delegation_type = 0; | 452 | int delegation_type = 0; |
453 | int status; | 453 | int status; |
454 | 454 | ||
455 | if (delegation != NULL) { | 455 | if (delegation != NULL) { |
456 | if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) { | 456 | if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) { |
457 | memcpy(&state->stateid, &delegation->stateid, | 457 | memcpy(&state->stateid, &delegation->stateid, |
458 | sizeof(state->stateid)); | 458 | sizeof(state->stateid)); |
459 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 459 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
460 | return 0; | 460 | return 0; |
461 | } | 461 | } |
462 | delegation_type = delegation->type; | 462 | delegation_type = delegation->type; |
463 | } | 463 | } |
464 | opendata = nfs4_opendata_alloc(dentry, sp, 0, NULL); | 464 | opendata = nfs4_opendata_alloc(dentry, sp, 0, NULL); |
465 | if (opendata == NULL) | 465 | if (opendata == NULL) |
466 | return -ENOMEM; | 466 | return -ENOMEM; |
467 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; | 467 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
468 | opendata->o_arg.fh = NFS_FH(state->inode); | 468 | opendata->o_arg.fh = NFS_FH(state->inode); |
469 | nfs_copy_fh(&opendata->o_res.fh, opendata->o_arg.fh); | 469 | nfs_copy_fh(&opendata->o_res.fh, opendata->o_arg.fh); |
470 | opendata->o_arg.u.delegation_type = delegation_type; | 470 | opendata->o_arg.u.delegation_type = delegation_type; |
471 | status = nfs4_open_recover(opendata, state); | 471 | status = nfs4_open_recover(opendata, state); |
472 | nfs4_opendata_free(opendata); | 472 | nfs4_opendata_free(opendata); |
473 | return status; | 473 | return status; |
474 | } | 474 | } |
475 | 475 | ||
476 | static int nfs4_do_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry) | 476 | static int nfs4_do_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry) |
477 | { | 477 | { |
478 | struct nfs_server *server = NFS_SERVER(state->inode); | 478 | struct nfs_server *server = NFS_SERVER(state->inode); |
479 | struct nfs4_exception exception = { }; | 479 | struct nfs4_exception exception = { }; |
480 | int err; | 480 | int err; |
481 | do { | 481 | do { |
482 | err = _nfs4_do_open_reclaim(sp, state, dentry); | 482 | err = _nfs4_do_open_reclaim(sp, state, dentry); |
483 | if (err != -NFS4ERR_DELAY) | 483 | if (err != -NFS4ERR_DELAY) |
484 | break; | 484 | break; |
485 | nfs4_handle_exception(server, err, &exception); | 485 | nfs4_handle_exception(server, err, &exception); |
486 | } while (exception.retry); | 486 | } while (exception.retry); |
487 | return err; | 487 | return err; |
488 | } | 488 | } |
489 | 489 | ||
490 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) | 490 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
491 | { | 491 | { |
492 | struct nfs_open_context *ctx; | 492 | struct nfs_open_context *ctx; |
493 | int ret; | 493 | int ret; |
494 | 494 | ||
495 | ctx = nfs4_state_find_open_context(state); | 495 | ctx = nfs4_state_find_open_context(state); |
496 | if (IS_ERR(ctx)) | 496 | if (IS_ERR(ctx)) |
497 | return PTR_ERR(ctx); | 497 | return PTR_ERR(ctx); |
498 | ret = nfs4_do_open_reclaim(sp, state, ctx->dentry); | 498 | ret = nfs4_do_open_reclaim(sp, state, ctx->dentry); |
499 | put_nfs_open_context(ctx); | 499 | put_nfs_open_context(ctx); |
500 | return ret; | 500 | return ret; |
501 | } | 501 | } |
502 | 502 | ||
503 | static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state) | 503 | static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state) |
504 | { | 504 | { |
505 | struct nfs4_state_owner *sp = state->owner; | 505 | struct nfs4_state_owner *sp = state->owner; |
506 | struct nfs4_opendata *opendata; | 506 | struct nfs4_opendata *opendata; |
507 | int ret; | 507 | int ret; |
508 | 508 | ||
509 | if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) | 509 | if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) |
510 | return 0; | 510 | return 0; |
511 | opendata = nfs4_opendata_alloc(dentry, sp, 0, NULL); | 511 | opendata = nfs4_opendata_alloc(dentry, sp, 0, NULL); |
512 | if (opendata == NULL) | 512 | if (opendata == NULL) |
513 | return -ENOMEM; | 513 | return -ENOMEM; |
514 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; | 514 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
515 | memcpy(opendata->o_arg.u.delegation.data, state->stateid.data, | 515 | memcpy(opendata->o_arg.u.delegation.data, state->stateid.data, |
516 | sizeof(opendata->o_arg.u.delegation.data)); | 516 | sizeof(opendata->o_arg.u.delegation.data)); |
517 | ret = nfs4_open_recover(opendata, state); | 517 | ret = nfs4_open_recover(opendata, state); |
518 | nfs4_opendata_free(opendata); | 518 | nfs4_opendata_free(opendata); |
519 | return ret; | 519 | return ret; |
520 | } | 520 | } |
521 | 521 | ||
522 | int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state) | 522 | int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state) |
523 | { | 523 | { |
524 | struct nfs4_exception exception = { }; | 524 | struct nfs4_exception exception = { }; |
525 | struct nfs_server *server = NFS_SERVER(dentry->d_inode); | 525 | struct nfs_server *server = NFS_SERVER(dentry->d_inode); |
526 | int err; | 526 | int err; |
527 | do { | 527 | do { |
528 | err = _nfs4_open_delegation_recall(dentry, state); | 528 | err = _nfs4_open_delegation_recall(dentry, state); |
529 | switch (err) { | 529 | switch (err) { |
530 | case 0: | 530 | case 0: |
531 | return err; | 531 | return err; |
532 | case -NFS4ERR_STALE_CLIENTID: | 532 | case -NFS4ERR_STALE_CLIENTID: |
533 | case -NFS4ERR_STALE_STATEID: | 533 | case -NFS4ERR_STALE_STATEID: |
534 | case -NFS4ERR_EXPIRED: | 534 | case -NFS4ERR_EXPIRED: |
535 | /* Don't recall a delegation if it was lost */ | 535 | /* Don't recall a delegation if it was lost */ |
536 | nfs4_schedule_state_recovery(server->nfs4_state); | 536 | nfs4_schedule_state_recovery(server->nfs4_state); |
537 | return err; | 537 | return err; |
538 | } | 538 | } |
539 | err = nfs4_handle_exception(server, err, &exception); | 539 | err = nfs4_handle_exception(server, err, &exception); |
540 | } while (exception.retry); | 540 | } while (exception.retry); |
541 | return err; | 541 | return err; |
542 | } | 542 | } |
543 | 543 | ||
544 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) | 544 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
545 | { | 545 | { |
546 | struct nfs4_opendata *data = calldata; | 546 | struct nfs4_opendata *data = calldata; |
547 | struct rpc_message msg = { | 547 | struct rpc_message msg = { |
548 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], | 548 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
549 | .rpc_argp = &data->c_arg, | 549 | .rpc_argp = &data->c_arg, |
550 | .rpc_resp = &data->c_res, | 550 | .rpc_resp = &data->c_res, |
551 | .rpc_cred = data->owner->so_cred, | 551 | .rpc_cred = data->owner->so_cred, |
552 | }; | 552 | }; |
553 | data->timestamp = jiffies; | 553 | data->timestamp = jiffies; |
554 | rpc_call_setup(task, &msg, 0); | 554 | rpc_call_setup(task, &msg, 0); |
555 | } | 555 | } |
556 | 556 | ||
557 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) | 557 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
558 | { | 558 | { |
559 | struct nfs4_opendata *data = calldata; | 559 | struct nfs4_opendata *data = calldata; |
560 | 560 | ||
561 | data->rpc_status = task->tk_status; | 561 | data->rpc_status = task->tk_status; |
562 | if (RPC_ASSASSINATED(task)) | 562 | if (RPC_ASSASSINATED(task)) |
563 | return; | 563 | return; |
564 | if (data->rpc_status == 0) { | 564 | if (data->rpc_status == 0) { |
565 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, | 565 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
566 | sizeof(data->o_res.stateid.data)); | 566 | sizeof(data->o_res.stateid.data)); |
567 | renew_lease(data->o_res.server, data->timestamp); | 567 | renew_lease(data->o_res.server, data->timestamp); |
568 | } | 568 | } |
569 | nfs_increment_open_seqid(data->rpc_status, data->c_arg.seqid); | 569 | nfs_increment_open_seqid(data->rpc_status, data->c_arg.seqid); |
570 | nfs_confirm_seqid(&data->owner->so_seqid, data->rpc_status); | 570 | nfs_confirm_seqid(&data->owner->so_seqid, data->rpc_status); |
571 | } | 571 | } |
572 | 572 | ||
573 | static void nfs4_open_confirm_release(void *calldata) | 573 | static void nfs4_open_confirm_release(void *calldata) |
574 | { | 574 | { |
575 | struct nfs4_opendata *data = calldata; | 575 | struct nfs4_opendata *data = calldata; |
576 | struct nfs4_state *state = NULL; | 576 | struct nfs4_state *state = NULL; |
577 | 577 | ||
578 | /* If this request hasn't been cancelled, do nothing */ | 578 | /* If this request hasn't been cancelled, do nothing */ |
579 | if (data->cancelled == 0) | 579 | if (data->cancelled == 0) |
580 | goto out_free; | 580 | goto out_free; |
581 | /* In case of error, no cleanup! */ | 581 | /* In case of error, no cleanup! */ |
582 | if (data->rpc_status != 0) | 582 | if (data->rpc_status != 0) |
583 | goto out_free; | 583 | goto out_free; |
584 | nfs_confirm_seqid(&data->owner->so_seqid, 0); | 584 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
585 | state = nfs4_opendata_to_nfs4_state(data); | 585 | state = nfs4_opendata_to_nfs4_state(data); |
586 | if (state != NULL) | 586 | if (state != NULL) |
587 | nfs4_close_state(state, data->o_arg.open_flags); | 587 | nfs4_close_state(state, data->o_arg.open_flags); |
588 | out_free: | 588 | out_free: |
589 | nfs4_opendata_free(data); | 589 | nfs4_opendata_free(data); |
590 | } | 590 | } |
591 | 591 | ||
592 | static const struct rpc_call_ops nfs4_open_confirm_ops = { | 592 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
593 | .rpc_call_prepare = nfs4_open_confirm_prepare, | 593 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
594 | .rpc_call_done = nfs4_open_confirm_done, | 594 | .rpc_call_done = nfs4_open_confirm_done, |
595 | .rpc_release = nfs4_open_confirm_release, | 595 | .rpc_release = nfs4_open_confirm_release, |
596 | }; | 596 | }; |
597 | 597 | ||
598 | /* | 598 | /* |
599 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata | 599 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
600 | */ | 600 | */ |
601 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) | 601 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
602 | { | 602 | { |
603 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); | 603 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
604 | struct rpc_task *task; | 604 | struct rpc_task *task; |
605 | int status; | 605 | int status; |
606 | 606 | ||
607 | atomic_inc(&data->count); | 607 | atomic_inc(&data->count); |
608 | task = rpc_run_task(server->client, RPC_TASK_ASYNC, &nfs4_open_confirm_ops, data); | 608 | task = rpc_run_task(server->client, RPC_TASK_ASYNC, &nfs4_open_confirm_ops, data); |
609 | if (IS_ERR(task)) { | 609 | if (IS_ERR(task)) { |
610 | nfs4_opendata_free(data); | 610 | nfs4_opendata_free(data); |
611 | return PTR_ERR(task); | 611 | return PTR_ERR(task); |
612 | } | 612 | } |
613 | status = nfs4_wait_for_completion_rpc_task(task); | 613 | status = nfs4_wait_for_completion_rpc_task(task); |
614 | if (status != 0) { | 614 | if (status != 0) { |
615 | data->cancelled = 1; | 615 | data->cancelled = 1; |
616 | smp_wmb(); | 616 | smp_wmb(); |
617 | } else | 617 | } else |
618 | status = data->rpc_status; | 618 | status = data->rpc_status; |
619 | rpc_release_task(task); | 619 | rpc_release_task(task); |
620 | return status; | 620 | return status; |
621 | } | 621 | } |
622 | 622 | ||
623 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) | 623 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
624 | { | 624 | { |
625 | struct nfs4_opendata *data = calldata; | 625 | struct nfs4_opendata *data = calldata; |
626 | struct nfs4_state_owner *sp = data->owner; | 626 | struct nfs4_state_owner *sp = data->owner; |
627 | struct rpc_message msg = { | 627 | struct rpc_message msg = { |
628 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], | 628 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
629 | .rpc_argp = &data->o_arg, | 629 | .rpc_argp = &data->o_arg, |
630 | .rpc_resp = &data->o_res, | 630 | .rpc_resp = &data->o_res, |
631 | .rpc_cred = sp->so_cred, | 631 | .rpc_cred = sp->so_cred, |
632 | }; | 632 | }; |
633 | 633 | ||
634 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) | 634 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
635 | return; | 635 | return; |
636 | /* Update sequence id. */ | 636 | /* Update sequence id. */ |
637 | data->o_arg.id = sp->so_id; | 637 | data->o_arg.id = sp->so_id; |
638 | data->o_arg.clientid = sp->so_client->cl_clientid; | 638 | data->o_arg.clientid = sp->so_client->cl_clientid; |
639 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) | 639 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
640 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; | 640 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
641 | data->timestamp = jiffies; | 641 | data->timestamp = jiffies; |
642 | rpc_call_setup(task, &msg, 0); | 642 | rpc_call_setup(task, &msg, 0); |
643 | } | 643 | } |
644 | 644 | ||
645 | static void nfs4_open_done(struct rpc_task *task, void *calldata) | 645 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
646 | { | 646 | { |
647 | struct nfs4_opendata *data = calldata; | 647 | struct nfs4_opendata *data = calldata; |
648 | 648 | ||
649 | data->rpc_status = task->tk_status; | 649 | data->rpc_status = task->tk_status; |
650 | if (RPC_ASSASSINATED(task)) | 650 | if (RPC_ASSASSINATED(task)) |
651 | return; | 651 | return; |
652 | if (task->tk_status == 0) { | 652 | if (task->tk_status == 0) { |
653 | switch (data->o_res.f_attr->mode & S_IFMT) { | 653 | switch (data->o_res.f_attr->mode & S_IFMT) { |
654 | case S_IFREG: | 654 | case S_IFREG: |
655 | break; | 655 | break; |
656 | case S_IFLNK: | 656 | case S_IFLNK: |
657 | data->rpc_status = -ELOOP; | 657 | data->rpc_status = -ELOOP; |
658 | break; | 658 | break; |
659 | case S_IFDIR: | 659 | case S_IFDIR: |
660 | data->rpc_status = -EISDIR; | 660 | data->rpc_status = -EISDIR; |
661 | break; | 661 | break; |
662 | default: | 662 | default: |
663 | data->rpc_status = -ENOTDIR; | 663 | data->rpc_status = -ENOTDIR; |
664 | } | 664 | } |
665 | renew_lease(data->o_res.server, data->timestamp); | 665 | renew_lease(data->o_res.server, data->timestamp); |
666 | } | 666 | } |
667 | nfs_increment_open_seqid(data->rpc_status, data->o_arg.seqid); | 667 | nfs_increment_open_seqid(data->rpc_status, data->o_arg.seqid); |
668 | } | 668 | } |
669 | 669 | ||
670 | static void nfs4_open_release(void *calldata) | 670 | static void nfs4_open_release(void *calldata) |
671 | { | 671 | { |
672 | struct nfs4_opendata *data = calldata; | 672 | struct nfs4_opendata *data = calldata; |
673 | struct nfs4_state *state = NULL; | 673 | struct nfs4_state *state = NULL; |
674 | 674 | ||
675 | /* If this request hasn't been cancelled, do nothing */ | 675 | /* If this request hasn't been cancelled, do nothing */ |
676 | if (data->cancelled == 0) | 676 | if (data->cancelled == 0) |
677 | goto out_free; | 677 | goto out_free; |
678 | /* In case of error, no cleanup! */ | 678 | /* In case of error, no cleanup! */ |
679 | if (data->rpc_status != 0) | 679 | if (data->rpc_status != 0) |
680 | goto out_free; | 680 | goto out_free; |
681 | /* In case we need an open_confirm, no cleanup! */ | 681 | /* In case we need an open_confirm, no cleanup! */ |
682 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) | 682 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
683 | goto out_free; | 683 | goto out_free; |
684 | nfs_confirm_seqid(&data->owner->so_seqid, 0); | 684 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
685 | state = nfs4_opendata_to_nfs4_state(data); | 685 | state = nfs4_opendata_to_nfs4_state(data); |
686 | if (state != NULL) | 686 | if (state != NULL) |
687 | nfs4_close_state(state, data->o_arg.open_flags); | 687 | nfs4_close_state(state, data->o_arg.open_flags); |
688 | out_free: | 688 | out_free: |
689 | nfs4_opendata_free(data); | 689 | nfs4_opendata_free(data); |
690 | } | 690 | } |
691 | 691 | ||
692 | static const struct rpc_call_ops nfs4_open_ops = { | 692 | static const struct rpc_call_ops nfs4_open_ops = { |
693 | .rpc_call_prepare = nfs4_open_prepare, | 693 | .rpc_call_prepare = nfs4_open_prepare, |
694 | .rpc_call_done = nfs4_open_done, | 694 | .rpc_call_done = nfs4_open_done, |
695 | .rpc_release = nfs4_open_release, | 695 | .rpc_release = nfs4_open_release, |
696 | }; | 696 | }; |
697 | 697 | ||
698 | /* | 698 | /* |
699 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata | 699 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
700 | */ | 700 | */ |
701 | static int _nfs4_proc_open(struct nfs4_opendata *data) | 701 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
702 | { | 702 | { |
703 | struct inode *dir = data->dir->d_inode; | 703 | struct inode *dir = data->dir->d_inode; |
704 | struct nfs_server *server = NFS_SERVER(dir); | 704 | struct nfs_server *server = NFS_SERVER(dir); |
705 | struct nfs_openargs *o_arg = &data->o_arg; | 705 | struct nfs_openargs *o_arg = &data->o_arg; |
706 | struct nfs_openres *o_res = &data->o_res; | 706 | struct nfs_openres *o_res = &data->o_res; |
707 | struct rpc_task *task; | 707 | struct rpc_task *task; |
708 | int status; | 708 | int status; |
709 | 709 | ||
710 | atomic_inc(&data->count); | 710 | atomic_inc(&data->count); |
711 | task = rpc_run_task(server->client, RPC_TASK_ASYNC, &nfs4_open_ops, data); | 711 | task = rpc_run_task(server->client, RPC_TASK_ASYNC, &nfs4_open_ops, data); |
712 | if (IS_ERR(task)) { | 712 | if (IS_ERR(task)) { |
713 | nfs4_opendata_free(data); | 713 | nfs4_opendata_free(data); |
714 | return PTR_ERR(task); | 714 | return PTR_ERR(task); |
715 | } | 715 | } |
716 | status = nfs4_wait_for_completion_rpc_task(task); | 716 | status = nfs4_wait_for_completion_rpc_task(task); |
717 | if (status != 0) { | 717 | if (status != 0) { |
718 | data->cancelled = 1; | 718 | data->cancelled = 1; |
719 | smp_wmb(); | 719 | smp_wmb(); |
720 | } else | 720 | } else |
721 | status = data->rpc_status; | 721 | status = data->rpc_status; |
722 | rpc_release_task(task); | 722 | rpc_release_task(task); |
723 | if (status != 0) | 723 | if (status != 0) |
724 | return status; | 724 | return status; |
725 | 725 | ||
726 | if (o_arg->open_flags & O_CREAT) { | 726 | if (o_arg->open_flags & O_CREAT) { |
727 | update_changeattr(dir, &o_res->cinfo); | 727 | update_changeattr(dir, &o_res->cinfo); |
728 | nfs_post_op_update_inode(dir, o_res->dir_attr); | 728 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
729 | } else | 729 | } else |
730 | nfs_refresh_inode(dir, o_res->dir_attr); | 730 | nfs_refresh_inode(dir, o_res->dir_attr); |
731 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { | 731 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
732 | status = _nfs4_proc_open_confirm(data); | 732 | status = _nfs4_proc_open_confirm(data); |
733 | if (status != 0) | 733 | if (status != 0) |
734 | return status; | 734 | return status; |
735 | } | 735 | } |
736 | nfs_confirm_seqid(&data->owner->so_seqid, 0); | 736 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
737 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) | 737 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
738 | return server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr); | 738 | return server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr); |
739 | return 0; | 739 | return 0; |
740 | } | 740 | } |
741 | 741 | ||
742 | static int _nfs4_do_access(struct inode *inode, struct rpc_cred *cred, int openflags) | 742 | static int _nfs4_do_access(struct inode *inode, struct rpc_cred *cred, int openflags) |
743 | { | 743 | { |
744 | struct nfs_access_entry cache; | 744 | struct nfs_access_entry cache; |
745 | int mask = 0; | 745 | int mask = 0; |
746 | int status; | 746 | int status; |
747 | 747 | ||
748 | if (openflags & FMODE_READ) | 748 | if (openflags & FMODE_READ) |
749 | mask |= MAY_READ; | 749 | mask |= MAY_READ; |
750 | if (openflags & FMODE_WRITE) | 750 | if (openflags & FMODE_WRITE) |
751 | mask |= MAY_WRITE; | 751 | mask |= MAY_WRITE; |
752 | status = nfs_access_get_cached(inode, cred, &cache); | 752 | status = nfs_access_get_cached(inode, cred, &cache); |
753 | if (status == 0) | 753 | if (status == 0) |
754 | goto out; | 754 | goto out; |
755 | 755 | ||
756 | /* Be clever: ask server to check for all possible rights */ | 756 | /* Be clever: ask server to check for all possible rights */ |
757 | cache.mask = MAY_EXEC | MAY_WRITE | MAY_READ; | 757 | cache.mask = MAY_EXEC | MAY_WRITE | MAY_READ; |
758 | cache.cred = cred; | 758 | cache.cred = cred; |
759 | cache.jiffies = jiffies; | 759 | cache.jiffies = jiffies; |
760 | status = _nfs4_proc_access(inode, &cache); | 760 | status = _nfs4_proc_access(inode, &cache); |
761 | if (status != 0) | 761 | if (status != 0) |
762 | return status; | 762 | return status; |
763 | nfs_access_add_cache(inode, &cache); | 763 | nfs_access_add_cache(inode, &cache); |
764 | out: | 764 | out: |
765 | if ((cache.mask & mask) == mask) | 765 | if ((cache.mask & mask) == mask) |
766 | return 0; | 766 | return 0; |
767 | return -EACCES; | 767 | return -EACCES; |
768 | } | 768 | } |
769 | 769 | ||
770 | int nfs4_recover_expired_lease(struct nfs_server *server) | 770 | int nfs4_recover_expired_lease(struct nfs_server *server) |
771 | { | 771 | { |
772 | struct nfs4_client *clp = server->nfs4_state; | 772 | struct nfs4_client *clp = server->nfs4_state; |
773 | 773 | ||
774 | if (test_and_clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) | 774 | if (test_and_clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) |
775 | nfs4_schedule_state_recovery(clp); | 775 | nfs4_schedule_state_recovery(clp); |
776 | return nfs4_wait_clnt_recover(server->client, clp); | 776 | return nfs4_wait_clnt_recover(server->client, clp); |
777 | } | 777 | } |
778 | 778 | ||
779 | /* | 779 | /* |
780 | * OPEN_EXPIRED: | 780 | * OPEN_EXPIRED: |
781 | * reclaim state on the server after a network partition. | 781 | * reclaim state on the server after a network partition. |
782 | * Assumes caller holds the appropriate lock | 782 | * Assumes caller holds the appropriate lock |
783 | */ | 783 | */ |
784 | static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry) | 784 | static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry) |
785 | { | 785 | { |
786 | struct inode *inode = state->inode; | 786 | struct inode *inode = state->inode; |
787 | struct nfs_delegation *delegation = NFS_I(inode)->delegation; | 787 | struct nfs_delegation *delegation = NFS_I(inode)->delegation; |
788 | struct nfs4_opendata *opendata; | 788 | struct nfs4_opendata *opendata; |
789 | int openflags = state->state & (FMODE_READ|FMODE_WRITE); | 789 | int openflags = state->state & (FMODE_READ|FMODE_WRITE); |
790 | int ret; | 790 | int ret; |
791 | 791 | ||
792 | if (delegation != NULL && !(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) { | 792 | if (delegation != NULL && !(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) { |
793 | ret = _nfs4_do_access(inode, sp->so_cred, openflags); | 793 | ret = _nfs4_do_access(inode, sp->so_cred, openflags); |
794 | if (ret < 0) | 794 | if (ret < 0) |
795 | return ret; | 795 | return ret; |
796 | memcpy(&state->stateid, &delegation->stateid, sizeof(state->stateid)); | 796 | memcpy(&state->stateid, &delegation->stateid, sizeof(state->stateid)); |
797 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 797 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
798 | return 0; | 798 | return 0; |
799 | } | 799 | } |
800 | opendata = nfs4_opendata_alloc(dentry, sp, openflags, NULL); | 800 | opendata = nfs4_opendata_alloc(dentry, sp, openflags, NULL); |
801 | if (opendata == NULL) | 801 | if (opendata == NULL) |
802 | return -ENOMEM; | 802 | return -ENOMEM; |
803 | ret = nfs4_open_recover(opendata, state); | 803 | ret = nfs4_open_recover(opendata, state); |
804 | if (ret == -ESTALE) { | 804 | if (ret == -ESTALE) { |
805 | /* Invalidate the state owner so we don't ever use it again */ | 805 | /* Invalidate the state owner so we don't ever use it again */ |
806 | nfs4_drop_state_owner(sp); | 806 | nfs4_drop_state_owner(sp); |
807 | d_drop(dentry); | 807 | d_drop(dentry); |
808 | } | 808 | } |
809 | nfs4_opendata_free(opendata); | 809 | nfs4_opendata_free(opendata); |
810 | return ret; | 810 | return ret; |
811 | } | 811 | } |
812 | 812 | ||
813 | static inline int nfs4_do_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry) | 813 | static inline int nfs4_do_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry) |
814 | { | 814 | { |
815 | struct nfs_server *server = NFS_SERVER(dentry->d_inode); | 815 | struct nfs_server *server = NFS_SERVER(dentry->d_inode); |
816 | struct nfs4_exception exception = { }; | 816 | struct nfs4_exception exception = { }; |
817 | int err; | 817 | int err; |
818 | 818 | ||
819 | do { | 819 | do { |
820 | err = _nfs4_open_expired(sp, state, dentry); | 820 | err = _nfs4_open_expired(sp, state, dentry); |
821 | if (err == -NFS4ERR_DELAY) | 821 | if (err == -NFS4ERR_DELAY) |
822 | nfs4_handle_exception(server, err, &exception); | 822 | nfs4_handle_exception(server, err, &exception); |
823 | } while (exception.retry); | 823 | } while (exception.retry); |
824 | return err; | 824 | return err; |
825 | } | 825 | } |
826 | 826 | ||
827 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) | 827 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
828 | { | 828 | { |
829 | struct nfs_open_context *ctx; | 829 | struct nfs_open_context *ctx; |
830 | int ret; | 830 | int ret; |
831 | 831 | ||
832 | ctx = nfs4_state_find_open_context(state); | 832 | ctx = nfs4_state_find_open_context(state); |
833 | if (IS_ERR(ctx)) | 833 | if (IS_ERR(ctx)) |
834 | return PTR_ERR(ctx); | 834 | return PTR_ERR(ctx); |
835 | ret = nfs4_do_open_expired(sp, state, ctx->dentry); | 835 | ret = nfs4_do_open_expired(sp, state, ctx->dentry); |
836 | put_nfs_open_context(ctx); | 836 | put_nfs_open_context(ctx); |
837 | return ret; | 837 | return ret; |
838 | } | 838 | } |
839 | 839 | ||
840 | /* | 840 | /* |
841 | * Returns a referenced nfs4_state if there is an open delegation on the file | 841 | * Returns a referenced nfs4_state if there is an open delegation on the file |
842 | */ | 842 | */ |
843 | static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred, struct nfs4_state **res) | 843 | static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred, struct nfs4_state **res) |
844 | { | 844 | { |
845 | struct nfs_delegation *delegation; | 845 | struct nfs_delegation *delegation; |
846 | struct nfs_server *server = NFS_SERVER(inode); | 846 | struct nfs_server *server = NFS_SERVER(inode); |
847 | struct nfs4_client *clp = server->nfs4_state; | 847 | struct nfs4_client *clp = server->nfs4_state; |
848 | struct nfs_inode *nfsi = NFS_I(inode); | 848 | struct nfs_inode *nfsi = NFS_I(inode); |
849 | struct nfs4_state_owner *sp = NULL; | 849 | struct nfs4_state_owner *sp = NULL; |
850 | struct nfs4_state *state = NULL; | 850 | struct nfs4_state *state = NULL; |
851 | int open_flags = flags & (FMODE_READ|FMODE_WRITE); | 851 | int open_flags = flags & (FMODE_READ|FMODE_WRITE); |
852 | int err; | 852 | int err; |
853 | 853 | ||
854 | err = -ENOMEM; | 854 | err = -ENOMEM; |
855 | if (!(sp = nfs4_get_state_owner(server, cred))) { | 855 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
856 | dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__); | 856 | dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__); |
857 | return err; | 857 | return err; |
858 | } | 858 | } |
859 | err = nfs4_recover_expired_lease(server); | 859 | err = nfs4_recover_expired_lease(server); |
860 | if (err != 0) | 860 | if (err != 0) |
861 | goto out_put_state_owner; | 861 | goto out_put_state_owner; |
862 | /* Protect against reboot recovery - NOTE ORDER! */ | 862 | /* Protect against reboot recovery - NOTE ORDER! */ |
863 | down_read(&clp->cl_sem); | 863 | down_read(&clp->cl_sem); |
864 | /* Protect against delegation recall */ | 864 | /* Protect against delegation recall */ |
865 | down_read(&nfsi->rwsem); | 865 | down_read(&nfsi->rwsem); |
866 | delegation = NFS_I(inode)->delegation; | 866 | delegation = NFS_I(inode)->delegation; |
867 | err = -ENOENT; | 867 | err = -ENOENT; |
868 | if (delegation == NULL || (delegation->type & open_flags) != open_flags) | 868 | if (delegation == NULL || (delegation->type & open_flags) != open_flags) |
869 | goto out_err; | 869 | goto out_err; |
870 | err = -ENOMEM; | 870 | err = -ENOMEM; |
871 | state = nfs4_get_open_state(inode, sp); | 871 | state = nfs4_get_open_state(inode, sp); |
872 | if (state == NULL) | 872 | if (state == NULL) |
873 | goto out_err; | 873 | goto out_err; |
874 | 874 | ||
875 | err = -ENOENT; | 875 | err = -ENOENT; |
876 | if ((state->state & open_flags) == open_flags) { | 876 | if ((state->state & open_flags) == open_flags) { |
877 | spin_lock(&inode->i_lock); | 877 | spin_lock(&inode->i_lock); |
878 | update_open_stateflags(state, open_flags); | 878 | update_open_stateflags(state, open_flags); |
879 | spin_unlock(&inode->i_lock); | 879 | spin_unlock(&inode->i_lock); |
880 | goto out_ok; | 880 | goto out_ok; |
881 | } else if (state->state != 0) | 881 | } else if (state->state != 0) |
882 | goto out_put_open_state; | 882 | goto out_put_open_state; |
883 | 883 | ||
884 | lock_kernel(); | 884 | lock_kernel(); |
885 | err = _nfs4_do_access(inode, cred, open_flags); | 885 | err = _nfs4_do_access(inode, cred, open_flags); |
886 | unlock_kernel(); | 886 | unlock_kernel(); |
887 | if (err != 0) | 887 | if (err != 0) |
888 | goto out_put_open_state; | 888 | goto out_put_open_state; |
889 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 889 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
890 | update_open_stateid(state, &delegation->stateid, open_flags); | 890 | update_open_stateid(state, &delegation->stateid, open_flags); |
891 | out_ok: | 891 | out_ok: |
892 | nfs4_put_state_owner(sp); | 892 | nfs4_put_state_owner(sp); |
893 | up_read(&nfsi->rwsem); | 893 | up_read(&nfsi->rwsem); |
894 | up_read(&clp->cl_sem); | 894 | up_read(&clp->cl_sem); |
895 | *res = state; | 895 | *res = state; |
896 | return 0; | 896 | return 0; |
897 | out_put_open_state: | 897 | out_put_open_state: |
898 | nfs4_put_open_state(state); | 898 | nfs4_put_open_state(state); |
899 | out_err: | 899 | out_err: |
900 | up_read(&nfsi->rwsem); | 900 | up_read(&nfsi->rwsem); |
901 | up_read(&clp->cl_sem); | 901 | up_read(&clp->cl_sem); |
902 | if (err != -EACCES) | 902 | if (err != -EACCES) |
903 | nfs_inode_return_delegation(inode); | 903 | nfs_inode_return_delegation(inode); |
904 | out_put_state_owner: | 904 | out_put_state_owner: |
905 | nfs4_put_state_owner(sp); | 905 | nfs4_put_state_owner(sp); |
906 | return err; | 906 | return err; |
907 | } | 907 | } |
908 | 908 | ||
909 | static struct nfs4_state *nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred) | 909 | static struct nfs4_state *nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred) |
910 | { | 910 | { |
911 | struct nfs4_exception exception = { }; | 911 | struct nfs4_exception exception = { }; |
912 | struct nfs4_state *res = ERR_PTR(-EIO); | 912 | struct nfs4_state *res = ERR_PTR(-EIO); |
913 | int err; | 913 | int err; |
914 | 914 | ||
915 | do { | 915 | do { |
916 | err = _nfs4_open_delegated(inode, flags, cred, &res); | 916 | err = _nfs4_open_delegated(inode, flags, cred, &res); |
917 | if (err == 0) | 917 | if (err == 0) |
918 | break; | 918 | break; |
919 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(inode), | 919 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(inode), |
920 | err, &exception)); | 920 | err, &exception)); |
921 | } while (exception.retry); | 921 | } while (exception.retry); |
922 | return res; | 922 | return res; |
923 | } | 923 | } |
924 | 924 | ||
925 | /* | 925 | /* |
926 | * Returns a referenced nfs4_state | 926 | * Returns a referenced nfs4_state |
927 | */ | 927 | */ |
928 | static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res) | 928 | static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res) |
929 | { | 929 | { |
930 | struct nfs4_state_owner *sp; | 930 | struct nfs4_state_owner *sp; |
931 | struct nfs4_state *state = NULL; | 931 | struct nfs4_state *state = NULL; |
932 | struct nfs_server *server = NFS_SERVER(dir); | 932 | struct nfs_server *server = NFS_SERVER(dir); |
933 | struct nfs4_client *clp = server->nfs4_state; | 933 | struct nfs4_client *clp = server->nfs4_state; |
934 | struct nfs4_opendata *opendata; | 934 | struct nfs4_opendata *opendata; |
935 | int status; | 935 | int status; |
936 | 936 | ||
937 | /* Protect against reboot recovery conflicts */ | 937 | /* Protect against reboot recovery conflicts */ |
938 | status = -ENOMEM; | 938 | status = -ENOMEM; |
939 | if (!(sp = nfs4_get_state_owner(server, cred))) { | 939 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
940 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); | 940 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
941 | goto out_err; | 941 | goto out_err; |
942 | } | 942 | } |
943 | status = nfs4_recover_expired_lease(server); | 943 | status = nfs4_recover_expired_lease(server); |
944 | if (status != 0) | 944 | if (status != 0) |
945 | goto err_put_state_owner; | 945 | goto err_put_state_owner; |
946 | down_read(&clp->cl_sem); | 946 | down_read(&clp->cl_sem); |
947 | status = -ENOMEM; | 947 | status = -ENOMEM; |
948 | opendata = nfs4_opendata_alloc(dentry, sp, flags, sattr); | 948 | opendata = nfs4_opendata_alloc(dentry, sp, flags, sattr); |
949 | if (opendata == NULL) | 949 | if (opendata == NULL) |
950 | goto err_put_state_owner; | 950 | goto err_put_state_owner; |
951 | 951 | ||
952 | status = _nfs4_proc_open(opendata); | 952 | status = _nfs4_proc_open(opendata); |
953 | if (status != 0) | 953 | if (status != 0) |
954 | goto err_opendata_free; | 954 | goto err_opendata_free; |
955 | 955 | ||
956 | status = -ENOMEM; | 956 | status = -ENOMEM; |
957 | state = nfs4_opendata_to_nfs4_state(opendata); | 957 | state = nfs4_opendata_to_nfs4_state(opendata); |
958 | if (state == NULL) | 958 | if (state == NULL) |
959 | goto err_opendata_free; | 959 | goto err_opendata_free; |
960 | if (opendata->o_res.delegation_type != 0) | 960 | if (opendata->o_res.delegation_type != 0) |
961 | nfs_inode_set_delegation(state->inode, cred, &opendata->o_res); | 961 | nfs_inode_set_delegation(state->inode, cred, &opendata->o_res); |
962 | nfs4_opendata_free(opendata); | 962 | nfs4_opendata_free(opendata); |
963 | nfs4_put_state_owner(sp); | 963 | nfs4_put_state_owner(sp); |
964 | up_read(&clp->cl_sem); | 964 | up_read(&clp->cl_sem); |
965 | *res = state; | 965 | *res = state; |
966 | return 0; | 966 | return 0; |
967 | err_opendata_free: | 967 | err_opendata_free: |
968 | nfs4_opendata_free(opendata); | 968 | nfs4_opendata_free(opendata); |
969 | err_put_state_owner: | 969 | err_put_state_owner: |
970 | nfs4_put_state_owner(sp); | 970 | nfs4_put_state_owner(sp); |
971 | out_err: | 971 | out_err: |
972 | /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */ | 972 | /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */ |
973 | up_read(&clp->cl_sem); | 973 | up_read(&clp->cl_sem); |
974 | *res = NULL; | 974 | *res = NULL; |
975 | return status; | 975 | return status; |
976 | } | 976 | } |
977 | 977 | ||
978 | 978 | ||
979 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred) | 979 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred) |
980 | { | 980 | { |
981 | struct nfs4_exception exception = { }; | 981 | struct nfs4_exception exception = { }; |
982 | struct nfs4_state *res; | 982 | struct nfs4_state *res; |
983 | int status; | 983 | int status; |
984 | 984 | ||
985 | do { | 985 | do { |
986 | status = _nfs4_do_open(dir, dentry, flags, sattr, cred, &res); | 986 | status = _nfs4_do_open(dir, dentry, flags, sattr, cred, &res); |
987 | if (status == 0) | 987 | if (status == 0) |
988 | break; | 988 | break; |
989 | /* NOTE: BAD_SEQID means the server and client disagree about the | 989 | /* NOTE: BAD_SEQID means the server and client disagree about the |
990 | * book-keeping w.r.t. state-changing operations | 990 | * book-keeping w.r.t. state-changing operations |
991 | * (OPEN/CLOSE/LOCK/LOCKU...) | 991 | * (OPEN/CLOSE/LOCK/LOCKU...) |
992 | * It is actually a sign of a bug on the client or on the server. | 992 | * It is actually a sign of a bug on the client or on the server. |
993 | * | 993 | * |
994 | * If we receive a BAD_SEQID error in the particular case of | 994 | * If we receive a BAD_SEQID error in the particular case of |
995 | * doing an OPEN, we assume that nfs_increment_open_seqid() will | 995 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
996 | * have unhashed the old state_owner for us, and that we can | 996 | * have unhashed the old state_owner for us, and that we can |
997 | * therefore safely retry using a new one. We should still warn | 997 | * therefore safely retry using a new one. We should still warn |
998 | * the user though... | 998 | * the user though... |
999 | */ | 999 | */ |
1000 | if (status == -NFS4ERR_BAD_SEQID) { | 1000 | if (status == -NFS4ERR_BAD_SEQID) { |
1001 | printk(KERN_WARNING "NFS: v4 server returned a bad sequence-id error!\n"); | 1001 | printk(KERN_WARNING "NFS: v4 server returned a bad sequence-id error!\n"); |
1002 | exception.retry = 1; | 1002 | exception.retry = 1; |
1003 | continue; | 1003 | continue; |
1004 | } | 1004 | } |
1005 | /* | 1005 | /* |
1006 | * BAD_STATEID on OPEN means that the server cancelled our | 1006 | * BAD_STATEID on OPEN means that the server cancelled our |
1007 | * state before it received the OPEN_CONFIRM. | 1007 | * state before it received the OPEN_CONFIRM. |
1008 | * Recover by retrying the request as per the discussion | 1008 | * Recover by retrying the request as per the discussion |
1009 | * on Page 181 of RFC3530. | 1009 | * on Page 181 of RFC3530. |
1010 | */ | 1010 | */ |
1011 | if (status == -NFS4ERR_BAD_STATEID) { | 1011 | if (status == -NFS4ERR_BAD_STATEID) { |
1012 | exception.retry = 1; | 1012 | exception.retry = 1; |
1013 | continue; | 1013 | continue; |
1014 | } | 1014 | } |
1015 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), | 1015 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
1016 | status, &exception)); | 1016 | status, &exception)); |
1017 | } while (exception.retry); | 1017 | } while (exception.retry); |
1018 | return res; | 1018 | return res; |
1019 | } | 1019 | } |
1020 | 1020 | ||
1021 | static int _nfs4_do_setattr(struct inode *inode, struct nfs_fattr *fattr, | 1021 | static int _nfs4_do_setattr(struct inode *inode, struct nfs_fattr *fattr, |
1022 | struct iattr *sattr, struct nfs4_state *state) | 1022 | struct iattr *sattr, struct nfs4_state *state) |
1023 | { | 1023 | { |
1024 | struct nfs_server *server = NFS_SERVER(inode); | 1024 | struct nfs_server *server = NFS_SERVER(inode); |
1025 | struct nfs_setattrargs arg = { | 1025 | struct nfs_setattrargs arg = { |
1026 | .fh = NFS_FH(inode), | 1026 | .fh = NFS_FH(inode), |
1027 | .iap = sattr, | 1027 | .iap = sattr, |
1028 | .server = server, | 1028 | .server = server, |
1029 | .bitmask = server->attr_bitmask, | 1029 | .bitmask = server->attr_bitmask, |
1030 | }; | 1030 | }; |
1031 | struct nfs_setattrres res = { | 1031 | struct nfs_setattrres res = { |
1032 | .fattr = fattr, | 1032 | .fattr = fattr, |
1033 | .server = server, | 1033 | .server = server, |
1034 | }; | 1034 | }; |
1035 | struct rpc_message msg = { | 1035 | struct rpc_message msg = { |
1036 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], | 1036 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
1037 | .rpc_argp = &arg, | 1037 | .rpc_argp = &arg, |
1038 | .rpc_resp = &res, | 1038 | .rpc_resp = &res, |
1039 | }; | 1039 | }; |
1040 | unsigned long timestamp = jiffies; | 1040 | unsigned long timestamp = jiffies; |
1041 | int status; | 1041 | int status; |
1042 | 1042 | ||
1043 | nfs_fattr_init(fattr); | 1043 | nfs_fattr_init(fattr); |
1044 | 1044 | ||
1045 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { | 1045 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
1046 | /* Use that stateid */ | 1046 | /* Use that stateid */ |
1047 | } else if (state != NULL) { | 1047 | } else if (state != NULL) { |
1048 | msg.rpc_cred = state->owner->so_cred; | 1048 | msg.rpc_cred = state->owner->so_cred; |
1049 | nfs4_copy_stateid(&arg.stateid, state, current->files); | 1049 | nfs4_copy_stateid(&arg.stateid, state, current->files); |
1050 | } else | 1050 | } else |
1051 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); | 1051 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
1052 | 1052 | ||
1053 | status = rpc_call_sync(server->client, &msg, 0); | 1053 | status = rpc_call_sync(server->client, &msg, 0); |
1054 | if (status == 0 && state != NULL) | 1054 | if (status == 0 && state != NULL) |
1055 | renew_lease(server, timestamp); | 1055 | renew_lease(server, timestamp); |
1056 | return status; | 1056 | return status; |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | static int nfs4_do_setattr(struct inode *inode, struct nfs_fattr *fattr, | 1059 | static int nfs4_do_setattr(struct inode *inode, struct nfs_fattr *fattr, |
1060 | struct iattr *sattr, struct nfs4_state *state) | 1060 | struct iattr *sattr, struct nfs4_state *state) |
1061 | { | 1061 | { |
1062 | struct nfs_server *server = NFS_SERVER(inode); | 1062 | struct nfs_server *server = NFS_SERVER(inode); |
1063 | struct nfs4_exception exception = { }; | 1063 | struct nfs4_exception exception = { }; |
1064 | int err; | 1064 | int err; |
1065 | do { | 1065 | do { |
1066 | err = nfs4_handle_exception(server, | 1066 | err = nfs4_handle_exception(server, |
1067 | _nfs4_do_setattr(inode, fattr, sattr, state), | 1067 | _nfs4_do_setattr(inode, fattr, sattr, state), |
1068 | &exception); | 1068 | &exception); |
1069 | } while (exception.retry); | 1069 | } while (exception.retry); |
1070 | return err; | 1070 | return err; |
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | struct nfs4_closedata { | 1073 | struct nfs4_closedata { |
1074 | struct inode *inode; | 1074 | struct inode *inode; |
1075 | struct nfs4_state *state; | 1075 | struct nfs4_state *state; |
1076 | struct nfs_closeargs arg; | 1076 | struct nfs_closeargs arg; |
1077 | struct nfs_closeres res; | 1077 | struct nfs_closeres res; |
1078 | struct nfs_fattr fattr; | 1078 | struct nfs_fattr fattr; |
1079 | unsigned long timestamp; | 1079 | unsigned long timestamp; |
1080 | }; | 1080 | }; |
1081 | 1081 | ||
1082 | static void nfs4_free_closedata(void *data) | 1082 | static void nfs4_free_closedata(void *data) |
1083 | { | 1083 | { |
1084 | struct nfs4_closedata *calldata = data; | 1084 | struct nfs4_closedata *calldata = data; |
1085 | struct nfs4_state_owner *sp = calldata->state->owner; | 1085 | struct nfs4_state_owner *sp = calldata->state->owner; |
1086 | 1086 | ||
1087 | nfs4_put_open_state(calldata->state); | 1087 | nfs4_put_open_state(calldata->state); |
1088 | nfs_free_seqid(calldata->arg.seqid); | 1088 | nfs_free_seqid(calldata->arg.seqid); |
1089 | nfs4_put_state_owner(sp); | 1089 | nfs4_put_state_owner(sp); |
1090 | kfree(calldata); | 1090 | kfree(calldata); |
1091 | } | 1091 | } |
1092 | 1092 | ||
1093 | static void nfs4_close_done(struct rpc_task *task, void *data) | 1093 | static void nfs4_close_done(struct rpc_task *task, void *data) |
1094 | { | 1094 | { |
1095 | struct nfs4_closedata *calldata = data; | 1095 | struct nfs4_closedata *calldata = data; |
1096 | struct nfs4_state *state = calldata->state; | 1096 | struct nfs4_state *state = calldata->state; |
1097 | struct nfs_server *server = NFS_SERVER(calldata->inode); | 1097 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
1098 | 1098 | ||
1099 | if (RPC_ASSASSINATED(task)) | 1099 | if (RPC_ASSASSINATED(task)) |
1100 | return; | 1100 | return; |
1101 | /* hmm. we are done with the inode, and in the process of freeing | 1101 | /* hmm. we are done with the inode, and in the process of freeing |
1102 | * the state_owner. we keep this around to process errors | 1102 | * the state_owner. we keep this around to process errors |
1103 | */ | 1103 | */ |
1104 | nfs_increment_open_seqid(task->tk_status, calldata->arg.seqid); | 1104 | nfs_increment_open_seqid(task->tk_status, calldata->arg.seqid); |
1105 | switch (task->tk_status) { | 1105 | switch (task->tk_status) { |
1106 | case 0: | 1106 | case 0: |
1107 | memcpy(&state->stateid, &calldata->res.stateid, | 1107 | memcpy(&state->stateid, &calldata->res.stateid, |
1108 | sizeof(state->stateid)); | 1108 | sizeof(state->stateid)); |
1109 | renew_lease(server, calldata->timestamp); | 1109 | renew_lease(server, calldata->timestamp); |
1110 | break; | 1110 | break; |
1111 | case -NFS4ERR_STALE_STATEID: | 1111 | case -NFS4ERR_STALE_STATEID: |
1112 | case -NFS4ERR_EXPIRED: | 1112 | case -NFS4ERR_EXPIRED: |
1113 | nfs4_schedule_state_recovery(server->nfs4_state); | 1113 | nfs4_schedule_state_recovery(server->nfs4_state); |
1114 | break; | 1114 | break; |
1115 | default: | 1115 | default: |
1116 | if (nfs4_async_handle_error(task, server) == -EAGAIN) { | 1116 | if (nfs4_async_handle_error(task, server) == -EAGAIN) { |
1117 | rpc_restart_call(task); | 1117 | rpc_restart_call(task); |
1118 | return; | 1118 | return; |
1119 | } | 1119 | } |
1120 | } | 1120 | } |
1121 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); | 1121 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | static void nfs4_close_prepare(struct rpc_task *task, void *data) | 1124 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
1125 | { | 1125 | { |
1126 | struct nfs4_closedata *calldata = data; | 1126 | struct nfs4_closedata *calldata = data; |
1127 | struct nfs4_state *state = calldata->state; | 1127 | struct nfs4_state *state = calldata->state; |
1128 | struct rpc_message msg = { | 1128 | struct rpc_message msg = { |
1129 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], | 1129 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
1130 | .rpc_argp = &calldata->arg, | 1130 | .rpc_argp = &calldata->arg, |
1131 | .rpc_resp = &calldata->res, | 1131 | .rpc_resp = &calldata->res, |
1132 | .rpc_cred = state->owner->so_cred, | 1132 | .rpc_cred = state->owner->so_cred, |
1133 | }; | 1133 | }; |
1134 | int mode = 0, old_mode; | 1134 | int mode = 0, old_mode; |
1135 | 1135 | ||
1136 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) | 1136 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
1137 | return; | 1137 | return; |
1138 | /* Recalculate the new open mode in case someone reopened the file | 1138 | /* Recalculate the new open mode in case someone reopened the file |
1139 | * while we were waiting in line to be scheduled. | 1139 | * while we were waiting in line to be scheduled. |
1140 | */ | 1140 | */ |
1141 | spin_lock(&state->owner->so_lock); | 1141 | spin_lock(&state->owner->so_lock); |
1142 | spin_lock(&calldata->inode->i_lock); | 1142 | spin_lock(&calldata->inode->i_lock); |
1143 | mode = old_mode = state->state; | 1143 | mode = old_mode = state->state; |
1144 | if (state->n_rdwr == 0) { | 1144 | if (state->n_rdwr == 0) { |
1145 | if (state->n_rdonly == 0) | 1145 | if (state->n_rdonly == 0) |
1146 | mode &= ~FMODE_READ; | 1146 | mode &= ~FMODE_READ; |
1147 | if (state->n_wronly == 0) | 1147 | if (state->n_wronly == 0) |
1148 | mode &= ~FMODE_WRITE; | 1148 | mode &= ~FMODE_WRITE; |
1149 | } | 1149 | } |
1150 | nfs4_state_set_mode_locked(state, mode); | 1150 | nfs4_state_set_mode_locked(state, mode); |
1151 | spin_unlock(&calldata->inode->i_lock); | 1151 | spin_unlock(&calldata->inode->i_lock); |
1152 | spin_unlock(&state->owner->so_lock); | 1152 | spin_unlock(&state->owner->so_lock); |
1153 | if (mode == old_mode || test_bit(NFS_DELEGATED_STATE, &state->flags)) { | 1153 | if (mode == old_mode || test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
1154 | /* Note: exit _without_ calling nfs4_close_done */ | 1154 | /* Note: exit _without_ calling nfs4_close_done */ |
1155 | task->tk_action = NULL; | 1155 | task->tk_action = NULL; |
1156 | return; | 1156 | return; |
1157 | } | 1157 | } |
1158 | nfs_fattr_init(calldata->res.fattr); | 1158 | nfs_fattr_init(calldata->res.fattr); |
1159 | if (mode != 0) | 1159 | if (mode != 0) |
1160 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; | 1160 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
1161 | calldata->arg.open_flags = mode; | 1161 | calldata->arg.open_flags = mode; |
1162 | calldata->timestamp = jiffies; | 1162 | calldata->timestamp = jiffies; |
1163 | rpc_call_setup(task, &msg, 0); | 1163 | rpc_call_setup(task, &msg, 0); |
1164 | } | 1164 | } |
1165 | 1165 | ||
1166 | static const struct rpc_call_ops nfs4_close_ops = { | 1166 | static const struct rpc_call_ops nfs4_close_ops = { |
1167 | .rpc_call_prepare = nfs4_close_prepare, | 1167 | .rpc_call_prepare = nfs4_close_prepare, |
1168 | .rpc_call_done = nfs4_close_done, | 1168 | .rpc_call_done = nfs4_close_done, |
1169 | .rpc_release = nfs4_free_closedata, | 1169 | .rpc_release = nfs4_free_closedata, |
1170 | }; | 1170 | }; |
1171 | 1171 | ||
1172 | /* | 1172 | /* |
1173 | * It is possible for data to be read/written from a mem-mapped file | 1173 | * It is possible for data to be read/written from a mem-mapped file |
1174 | * after the sys_close call (which hits the vfs layer as a flush). | 1174 | * after the sys_close call (which hits the vfs layer as a flush). |
1175 | * This means that we can't safely call nfsv4 close on a file until | 1175 | * This means that we can't safely call nfsv4 close on a file until |
1176 | * the inode is cleared. This in turn means that we are not good | 1176 | * the inode is cleared. This in turn means that we are not good |
1177 | * NFSv4 citizens - we do not indicate to the server to update the file's | 1177 | * NFSv4 citizens - we do not indicate to the server to update the file's |
1178 | * share state even when we are done with one of the three share | 1178 | * share state even when we are done with one of the three share |
1179 | * stateid's in the inode. | 1179 | * stateid's in the inode. |
1180 | * | 1180 | * |
1181 | * NOTE: Caller must be holding the sp->so_owner semaphore! | 1181 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
1182 | */ | 1182 | */ |
1183 | int nfs4_do_close(struct inode *inode, struct nfs4_state *state) | 1183 | int nfs4_do_close(struct inode *inode, struct nfs4_state *state) |
1184 | { | 1184 | { |
1185 | struct nfs_server *server = NFS_SERVER(inode); | 1185 | struct nfs_server *server = NFS_SERVER(inode); |
1186 | struct nfs4_closedata *calldata; | 1186 | struct nfs4_closedata *calldata; |
1187 | int status = -ENOMEM; | 1187 | int status = -ENOMEM; |
1188 | 1188 | ||
1189 | calldata = kmalloc(sizeof(*calldata), GFP_KERNEL); | 1189 | calldata = kmalloc(sizeof(*calldata), GFP_KERNEL); |
1190 | if (calldata == NULL) | 1190 | if (calldata == NULL) |
1191 | goto out; | 1191 | goto out; |
1192 | calldata->inode = inode; | 1192 | calldata->inode = inode; |
1193 | calldata->state = state; | 1193 | calldata->state = state; |
1194 | calldata->arg.fh = NFS_FH(inode); | 1194 | calldata->arg.fh = NFS_FH(inode); |
1195 | calldata->arg.stateid = &state->stateid; | 1195 | calldata->arg.stateid = &state->stateid; |
1196 | /* Serialization for the sequence id */ | 1196 | /* Serialization for the sequence id */ |
1197 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid); | 1197 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid); |
1198 | if (calldata->arg.seqid == NULL) | 1198 | if (calldata->arg.seqid == NULL) |
1199 | goto out_free_calldata; | 1199 | goto out_free_calldata; |
1200 | calldata->arg.bitmask = server->attr_bitmask; | 1200 | calldata->arg.bitmask = server->attr_bitmask; |
1201 | calldata->res.fattr = &calldata->fattr; | 1201 | calldata->res.fattr = &calldata->fattr; |
1202 | calldata->res.server = server; | 1202 | calldata->res.server = server; |
1203 | 1203 | ||
1204 | status = nfs4_call_async(server->client, &nfs4_close_ops, calldata); | 1204 | status = nfs4_call_async(server->client, &nfs4_close_ops, calldata); |
1205 | if (status == 0) | 1205 | if (status == 0) |
1206 | goto out; | 1206 | goto out; |
1207 | 1207 | ||
1208 | nfs_free_seqid(calldata->arg.seqid); | 1208 | nfs_free_seqid(calldata->arg.seqid); |
1209 | out_free_calldata: | 1209 | out_free_calldata: |
1210 | kfree(calldata); | 1210 | kfree(calldata); |
1211 | out: | 1211 | out: |
1212 | return status; | 1212 | return status; |
1213 | } | 1213 | } |
1214 | 1214 | ||
1215 | static void nfs4_intent_set_file(struct nameidata *nd, struct dentry *dentry, struct nfs4_state *state) | 1215 | static void nfs4_intent_set_file(struct nameidata *nd, struct dentry *dentry, struct nfs4_state *state) |
1216 | { | 1216 | { |
1217 | struct file *filp; | 1217 | struct file *filp; |
1218 | 1218 | ||
1219 | filp = lookup_instantiate_filp(nd, dentry, NULL); | 1219 | filp = lookup_instantiate_filp(nd, dentry, NULL); |
1220 | if (!IS_ERR(filp)) { | 1220 | if (!IS_ERR(filp)) { |
1221 | struct nfs_open_context *ctx; | 1221 | struct nfs_open_context *ctx; |
1222 | ctx = (struct nfs_open_context *)filp->private_data; | 1222 | ctx = (struct nfs_open_context *)filp->private_data; |
1223 | ctx->state = state; | 1223 | ctx->state = state; |
1224 | } else | 1224 | } else |
1225 | nfs4_close_state(state, nd->intent.open.flags); | 1225 | nfs4_close_state(state, nd->intent.open.flags); |
1226 | } | 1226 | } |
1227 | 1227 | ||
1228 | struct dentry * | 1228 | struct dentry * |
1229 | nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | 1229 | nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
1230 | { | 1230 | { |
1231 | struct iattr attr; | 1231 | struct iattr attr; |
1232 | struct rpc_cred *cred; | 1232 | struct rpc_cred *cred; |
1233 | struct nfs4_state *state; | 1233 | struct nfs4_state *state; |
1234 | struct dentry *res; | 1234 | struct dentry *res; |
1235 | 1235 | ||
1236 | if (nd->flags & LOOKUP_CREATE) { | 1236 | if (nd->flags & LOOKUP_CREATE) { |
1237 | attr.ia_mode = nd->intent.open.create_mode; | 1237 | attr.ia_mode = nd->intent.open.create_mode; |
1238 | attr.ia_valid = ATTR_MODE; | 1238 | attr.ia_valid = ATTR_MODE; |
1239 | if (!IS_POSIXACL(dir)) | 1239 | if (!IS_POSIXACL(dir)) |
1240 | attr.ia_mode &= ~current->fs->umask; | 1240 | attr.ia_mode &= ~current->fs->umask; |
1241 | } else { | 1241 | } else { |
1242 | attr.ia_valid = 0; | 1242 | attr.ia_valid = 0; |
1243 | BUG_ON(nd->intent.open.flags & O_CREAT); | 1243 | BUG_ON(nd->intent.open.flags & O_CREAT); |
1244 | } | 1244 | } |
1245 | 1245 | ||
1246 | cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0); | 1246 | cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0); |
1247 | if (IS_ERR(cred)) | 1247 | if (IS_ERR(cred)) |
1248 | return (struct dentry *)cred; | 1248 | return (struct dentry *)cred; |
1249 | state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred); | 1249 | state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred); |
1250 | put_rpccred(cred); | 1250 | put_rpccred(cred); |
1251 | if (IS_ERR(state)) { | 1251 | if (IS_ERR(state)) { |
1252 | if (PTR_ERR(state) == -ENOENT) | 1252 | if (PTR_ERR(state) == -ENOENT) |
1253 | d_add(dentry, NULL); | 1253 | d_add(dentry, NULL); |
1254 | return (struct dentry *)state; | 1254 | return (struct dentry *)state; |
1255 | } | 1255 | } |
1256 | res = d_add_unique(dentry, igrab(state->inode)); | 1256 | res = d_add_unique(dentry, igrab(state->inode)); |
1257 | if (res != NULL) | 1257 | if (res != NULL) |
1258 | dentry = res; | 1258 | dentry = res; |
1259 | nfs4_intent_set_file(nd, dentry, state); | 1259 | nfs4_intent_set_file(nd, dentry, state); |
1260 | return res; | 1260 | return res; |
1261 | } | 1261 | } |
1262 | 1262 | ||
1263 | int | 1263 | int |
1264 | nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd) | 1264 | nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd) |
1265 | { | 1265 | { |
1266 | struct rpc_cred *cred; | 1266 | struct rpc_cred *cred; |
1267 | struct nfs4_state *state; | 1267 | struct nfs4_state *state; |
1268 | 1268 | ||
1269 | cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0); | 1269 | cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0); |
1270 | if (IS_ERR(cred)) | 1270 | if (IS_ERR(cred)) |
1271 | return PTR_ERR(cred); | 1271 | return PTR_ERR(cred); |
1272 | state = nfs4_open_delegated(dentry->d_inode, openflags, cred); | 1272 | state = nfs4_open_delegated(dentry->d_inode, openflags, cred); |
1273 | if (IS_ERR(state)) | 1273 | if (IS_ERR(state)) |
1274 | state = nfs4_do_open(dir, dentry, openflags, NULL, cred); | 1274 | state = nfs4_do_open(dir, dentry, openflags, NULL, cred); |
1275 | put_rpccred(cred); | 1275 | put_rpccred(cred); |
1276 | if (IS_ERR(state)) { | 1276 | if (IS_ERR(state)) { |
1277 | switch (PTR_ERR(state)) { | 1277 | switch (PTR_ERR(state)) { |
1278 | case -EPERM: | 1278 | case -EPERM: |
1279 | case -EACCES: | 1279 | case -EACCES: |
1280 | case -EDQUOT: | 1280 | case -EDQUOT: |
1281 | case -ENOSPC: | 1281 | case -ENOSPC: |
1282 | case -EROFS: | 1282 | case -EROFS: |
1283 | lookup_instantiate_filp(nd, (struct dentry *)state, NULL); | 1283 | lookup_instantiate_filp(nd, (struct dentry *)state, NULL); |
1284 | return 1; | 1284 | return 1; |
1285 | case -ENOENT: | 1285 | case -ENOENT: |
1286 | if (dentry->d_inode == NULL) | 1286 | if (dentry->d_inode == NULL) |
1287 | return 1; | 1287 | return 1; |
1288 | } | 1288 | } |
1289 | goto out_drop; | 1289 | goto out_drop; |
1290 | } | 1290 | } |
1291 | if (state->inode == dentry->d_inode) { | 1291 | if (state->inode == dentry->d_inode) { |
1292 | nfs4_intent_set_file(nd, dentry, state); | 1292 | nfs4_intent_set_file(nd, dentry, state); |
1293 | return 1; | 1293 | return 1; |
1294 | } | 1294 | } |
1295 | nfs4_close_state(state, openflags); | 1295 | nfs4_close_state(state, openflags); |
1296 | out_drop: | 1296 | out_drop: |
1297 | d_drop(dentry); | 1297 | d_drop(dentry); |
1298 | return 0; | 1298 | return 0; |
1299 | } | 1299 | } |
1300 | 1300 | ||
1301 | 1301 | ||
1302 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) | 1302 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
1303 | { | 1303 | { |
1304 | struct nfs4_server_caps_res res = {}; | 1304 | struct nfs4_server_caps_res res = {}; |
1305 | struct rpc_message msg = { | 1305 | struct rpc_message msg = { |
1306 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], | 1306 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
1307 | .rpc_argp = fhandle, | 1307 | .rpc_argp = fhandle, |
1308 | .rpc_resp = &res, | 1308 | .rpc_resp = &res, |
1309 | }; | 1309 | }; |
1310 | int status; | 1310 | int status; |
1311 | 1311 | ||
1312 | status = rpc_call_sync(server->client, &msg, 0); | 1312 | status = rpc_call_sync(server->client, &msg, 0); |
1313 | if (status == 0) { | 1313 | if (status == 0) { |
1314 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); | 1314 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
1315 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) | 1315 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
1316 | server->caps |= NFS_CAP_ACLS; | 1316 | server->caps |= NFS_CAP_ACLS; |
1317 | if (res.has_links != 0) | 1317 | if (res.has_links != 0) |
1318 | server->caps |= NFS_CAP_HARDLINKS; | 1318 | server->caps |= NFS_CAP_HARDLINKS; |
1319 | if (res.has_symlinks != 0) | 1319 | if (res.has_symlinks != 0) |
1320 | server->caps |= NFS_CAP_SYMLINKS; | 1320 | server->caps |= NFS_CAP_SYMLINKS; |
1321 | server->acl_bitmask = res.acl_bitmask; | 1321 | server->acl_bitmask = res.acl_bitmask; |
1322 | } | 1322 | } |
1323 | return status; | 1323 | return status; |
1324 | } | 1324 | } |
1325 | 1325 | ||
1326 | static int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) | 1326 | static int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
1327 | { | 1327 | { |
1328 | struct nfs4_exception exception = { }; | 1328 | struct nfs4_exception exception = { }; |
1329 | int err; | 1329 | int err; |
1330 | do { | 1330 | do { |
1331 | err = nfs4_handle_exception(server, | 1331 | err = nfs4_handle_exception(server, |
1332 | _nfs4_server_capabilities(server, fhandle), | 1332 | _nfs4_server_capabilities(server, fhandle), |
1333 | &exception); | 1333 | &exception); |
1334 | } while (exception.retry); | 1334 | } while (exception.retry); |
1335 | return err; | 1335 | return err; |
1336 | } | 1336 | } |
1337 | 1337 | ||
1338 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, | 1338 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
1339 | struct nfs_fsinfo *info) | 1339 | struct nfs_fsinfo *info) |
1340 | { | 1340 | { |
1341 | struct nfs4_lookup_root_arg args = { | 1341 | struct nfs4_lookup_root_arg args = { |
1342 | .bitmask = nfs4_fattr_bitmap, | 1342 | .bitmask = nfs4_fattr_bitmap, |
1343 | }; | 1343 | }; |
1344 | struct nfs4_lookup_res res = { | 1344 | struct nfs4_lookup_res res = { |
1345 | .server = server, | 1345 | .server = server, |
1346 | .fattr = info->fattr, | 1346 | .fattr = info->fattr, |
1347 | .fh = fhandle, | 1347 | .fh = fhandle, |
1348 | }; | 1348 | }; |
1349 | struct rpc_message msg = { | 1349 | struct rpc_message msg = { |
1350 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], | 1350 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
1351 | .rpc_argp = &args, | 1351 | .rpc_argp = &args, |
1352 | .rpc_resp = &res, | 1352 | .rpc_resp = &res, |
1353 | }; | 1353 | }; |
1354 | nfs_fattr_init(info->fattr); | 1354 | nfs_fattr_init(info->fattr); |
1355 | return rpc_call_sync(server->client, &msg, 0); | 1355 | return rpc_call_sync(server->client, &msg, 0); |
1356 | } | 1356 | } |
1357 | 1357 | ||
1358 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, | 1358 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
1359 | struct nfs_fsinfo *info) | 1359 | struct nfs_fsinfo *info) |
1360 | { | 1360 | { |
1361 | struct nfs4_exception exception = { }; | 1361 | struct nfs4_exception exception = { }; |
1362 | int err; | 1362 | int err; |
1363 | do { | 1363 | do { |
1364 | err = nfs4_handle_exception(server, | 1364 | err = nfs4_handle_exception(server, |
1365 | _nfs4_lookup_root(server, fhandle, info), | 1365 | _nfs4_lookup_root(server, fhandle, info), |
1366 | &exception); | 1366 | &exception); |
1367 | } while (exception.retry); | 1367 | } while (exception.retry); |
1368 | return err; | 1368 | return err; |
1369 | } | 1369 | } |
1370 | 1370 | ||
1371 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, | 1371 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
1372 | struct nfs_fsinfo *info) | 1372 | struct nfs_fsinfo *info) |
1373 | { | 1373 | { |
1374 | struct nfs_fattr * fattr = info->fattr; | 1374 | struct nfs_fattr * fattr = info->fattr; |
1375 | unsigned char * p; | 1375 | unsigned char * p; |
1376 | struct qstr q; | 1376 | struct qstr q; |
1377 | struct nfs4_lookup_arg args = { | 1377 | struct nfs4_lookup_arg args = { |
1378 | .dir_fh = fhandle, | 1378 | .dir_fh = fhandle, |
1379 | .name = &q, | 1379 | .name = &q, |
1380 | .bitmask = nfs4_fattr_bitmap, | 1380 | .bitmask = nfs4_fattr_bitmap, |
1381 | }; | 1381 | }; |
1382 | struct nfs4_lookup_res res = { | 1382 | struct nfs4_lookup_res res = { |
1383 | .server = server, | 1383 | .server = server, |
1384 | .fattr = fattr, | 1384 | .fattr = fattr, |
1385 | .fh = fhandle, | 1385 | .fh = fhandle, |
1386 | }; | 1386 | }; |
1387 | struct rpc_message msg = { | 1387 | struct rpc_message msg = { |
1388 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], | 1388 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
1389 | .rpc_argp = &args, | 1389 | .rpc_argp = &args, |
1390 | .rpc_resp = &res, | 1390 | .rpc_resp = &res, |
1391 | }; | 1391 | }; |
1392 | int status; | 1392 | int status; |
1393 | 1393 | ||
1394 | /* | 1394 | /* |
1395 | * Now we do a separate LOOKUP for each component of the mount path. | 1395 | * Now we do a separate LOOKUP for each component of the mount path. |
1396 | * The LOOKUPs are done separately so that we can conveniently | 1396 | * The LOOKUPs are done separately so that we can conveniently |
1397 | * catch an ERR_WRONGSEC if it occurs along the way... | 1397 | * catch an ERR_WRONGSEC if it occurs along the way... |
1398 | */ | 1398 | */ |
1399 | status = nfs4_lookup_root(server, fhandle, info); | 1399 | status = nfs4_lookup_root(server, fhandle, info); |
1400 | if (status) | 1400 | if (status) |
1401 | goto out; | 1401 | goto out; |
1402 | 1402 | ||
1403 | p = server->mnt_path; | 1403 | p = server->mnt_path; |
1404 | for (;;) { | 1404 | for (;;) { |
1405 | struct nfs4_exception exception = { }; | 1405 | struct nfs4_exception exception = { }; |
1406 | 1406 | ||
1407 | while (*p == '/') | 1407 | while (*p == '/') |
1408 | p++; | 1408 | p++; |
1409 | if (!*p) | 1409 | if (!*p) |
1410 | break; | 1410 | break; |
1411 | q.name = p; | 1411 | q.name = p; |
1412 | while (*p && (*p != '/')) | 1412 | while (*p && (*p != '/')) |
1413 | p++; | 1413 | p++; |
1414 | q.len = p - q.name; | 1414 | q.len = p - q.name; |
1415 | 1415 | ||
1416 | do { | 1416 | do { |
1417 | nfs_fattr_init(fattr); | 1417 | nfs_fattr_init(fattr); |
1418 | status = nfs4_handle_exception(server, | 1418 | status = nfs4_handle_exception(server, |
1419 | rpc_call_sync(server->client, &msg, 0), | 1419 | rpc_call_sync(server->client, &msg, 0), |
1420 | &exception); | 1420 | &exception); |
1421 | } while (exception.retry); | 1421 | } while (exception.retry); |
1422 | if (status == 0) | 1422 | if (status == 0) |
1423 | continue; | 1423 | continue; |
1424 | if (status == -ENOENT) { | 1424 | if (status == -ENOENT) { |
1425 | printk(KERN_NOTICE "NFS: mount path %s does not exist!\n", server->mnt_path); | 1425 | printk(KERN_NOTICE "NFS: mount path %s does not exist!\n", server->mnt_path); |
1426 | printk(KERN_NOTICE "NFS: suggestion: try mounting '/' instead.\n"); | 1426 | printk(KERN_NOTICE "NFS: suggestion: try mounting '/' instead.\n"); |
1427 | } | 1427 | } |
1428 | break; | 1428 | break; |
1429 | } | 1429 | } |
1430 | if (status == 0) | 1430 | if (status == 0) |
1431 | status = nfs4_server_capabilities(server, fhandle); | 1431 | status = nfs4_server_capabilities(server, fhandle); |
1432 | if (status == 0) | 1432 | if (status == 0) |
1433 | status = nfs4_do_fsinfo(server, fhandle, info); | 1433 | status = nfs4_do_fsinfo(server, fhandle, info); |
1434 | out: | 1434 | out: |
1435 | return nfs4_map_errors(status); | 1435 | return nfs4_map_errors(status); |
1436 | } | 1436 | } |
1437 | 1437 | ||
1438 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 1438 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
1439 | { | 1439 | { |
1440 | struct nfs4_getattr_arg args = { | 1440 | struct nfs4_getattr_arg args = { |
1441 | .fh = fhandle, | 1441 | .fh = fhandle, |
1442 | .bitmask = server->attr_bitmask, | 1442 | .bitmask = server->attr_bitmask, |
1443 | }; | 1443 | }; |
1444 | struct nfs4_getattr_res res = { | 1444 | struct nfs4_getattr_res res = { |
1445 | .fattr = fattr, | 1445 | .fattr = fattr, |
1446 | .server = server, | 1446 | .server = server, |
1447 | }; | 1447 | }; |
1448 | struct rpc_message msg = { | 1448 | struct rpc_message msg = { |
1449 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], | 1449 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
1450 | .rpc_argp = &args, | 1450 | .rpc_argp = &args, |
1451 | .rpc_resp = &res, | 1451 | .rpc_resp = &res, |
1452 | }; | 1452 | }; |
1453 | 1453 | ||
1454 | nfs_fattr_init(fattr); | 1454 | nfs_fattr_init(fattr); |
1455 | return rpc_call_sync(server->client, &msg, 0); | 1455 | return rpc_call_sync(server->client, &msg, 0); |
1456 | } | 1456 | } |
1457 | 1457 | ||
1458 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 1458 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
1459 | { | 1459 | { |
1460 | struct nfs4_exception exception = { }; | 1460 | struct nfs4_exception exception = { }; |
1461 | int err; | 1461 | int err; |
1462 | do { | 1462 | do { |
1463 | err = nfs4_handle_exception(server, | 1463 | err = nfs4_handle_exception(server, |
1464 | _nfs4_proc_getattr(server, fhandle, fattr), | 1464 | _nfs4_proc_getattr(server, fhandle, fattr), |
1465 | &exception); | 1465 | &exception); |
1466 | } while (exception.retry); | 1466 | } while (exception.retry); |
1467 | return err; | 1467 | return err; |
1468 | } | 1468 | } |
1469 | 1469 | ||
1470 | /* | 1470 | /* |
1471 | * The file is not closed if it is opened due to the a request to change | 1471 | * The file is not closed if it is opened due to the a request to change |
1472 | * the size of the file. The open call will not be needed once the | 1472 | * the size of the file. The open call will not be needed once the |
1473 | * VFS layer lookup-intents are implemented. | 1473 | * VFS layer lookup-intents are implemented. |
1474 | * | 1474 | * |
1475 | * Close is called when the inode is destroyed. | 1475 | * Close is called when the inode is destroyed. |
1476 | * If we haven't opened the file for O_WRONLY, we | 1476 | * If we haven't opened the file for O_WRONLY, we |
1477 | * need to in the size_change case to obtain a stateid. | 1477 | * need to in the size_change case to obtain a stateid. |
1478 | * | 1478 | * |
1479 | * Got race? | 1479 | * Got race? |
1480 | * Because OPEN is always done by name in nfsv4, it is | 1480 | * Because OPEN is always done by name in nfsv4, it is |
1481 | * possible that we opened a different file by the same | 1481 | * possible that we opened a different file by the same |
1482 | * name. We can recognize this race condition, but we | 1482 | * name. We can recognize this race condition, but we |
1483 | * can't do anything about it besides returning an error. | 1483 | * can't do anything about it besides returning an error. |
1484 | * | 1484 | * |
1485 | * This will be fixed with VFS changes (lookup-intent). | 1485 | * This will be fixed with VFS changes (lookup-intent). |
1486 | */ | 1486 | */ |
1487 | static int | 1487 | static int |
1488 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, | 1488 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
1489 | struct iattr *sattr) | 1489 | struct iattr *sattr) |
1490 | { | 1490 | { |
1491 | struct rpc_cred *cred; | 1491 | struct rpc_cred *cred; |
1492 | struct inode *inode = dentry->d_inode; | 1492 | struct inode *inode = dentry->d_inode; |
1493 | struct nfs_open_context *ctx; | 1493 | struct nfs_open_context *ctx; |
1494 | struct nfs4_state *state = NULL; | 1494 | struct nfs4_state *state = NULL; |
1495 | int status; | 1495 | int status; |
1496 | 1496 | ||
1497 | nfs_fattr_init(fattr); | 1497 | nfs_fattr_init(fattr); |
1498 | 1498 | ||
1499 | cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0); | 1499 | cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0); |
1500 | if (IS_ERR(cred)) | 1500 | if (IS_ERR(cred)) |
1501 | return PTR_ERR(cred); | 1501 | return PTR_ERR(cred); |
1502 | 1502 | ||
1503 | /* Search for an existing open(O_WRITE) file */ | 1503 | /* Search for an existing open(O_WRITE) file */ |
1504 | ctx = nfs_find_open_context(inode, cred, FMODE_WRITE); | 1504 | ctx = nfs_find_open_context(inode, cred, FMODE_WRITE); |
1505 | if (ctx != NULL) | 1505 | if (ctx != NULL) |
1506 | state = ctx->state; | 1506 | state = ctx->state; |
1507 | 1507 | ||
1508 | status = nfs4_do_setattr(inode, fattr, sattr, state); | 1508 | status = nfs4_do_setattr(inode, fattr, sattr, state); |
1509 | if (status == 0) | 1509 | if (status == 0) |
1510 | nfs_setattr_update_inode(inode, sattr); | 1510 | nfs_setattr_update_inode(inode, sattr); |
1511 | if (ctx != NULL) | 1511 | if (ctx != NULL) |
1512 | put_nfs_open_context(ctx); | 1512 | put_nfs_open_context(ctx); |
1513 | put_rpccred(cred); | 1513 | put_rpccred(cred); |
1514 | return status; | 1514 | return status; |
1515 | } | 1515 | } |
1516 | 1516 | ||
1517 | static int _nfs4_proc_lookup(struct inode *dir, struct qstr *name, | 1517 | static int _nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
1518 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 1518 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
1519 | { | 1519 | { |
1520 | int status; | 1520 | int status; |
1521 | struct nfs_server *server = NFS_SERVER(dir); | 1521 | struct nfs_server *server = NFS_SERVER(dir); |
1522 | struct nfs4_lookup_arg args = { | 1522 | struct nfs4_lookup_arg args = { |
1523 | .bitmask = server->attr_bitmask, | 1523 | .bitmask = server->attr_bitmask, |
1524 | .dir_fh = NFS_FH(dir), | 1524 | .dir_fh = NFS_FH(dir), |
1525 | .name = name, | 1525 | .name = name, |
1526 | }; | 1526 | }; |
1527 | struct nfs4_lookup_res res = { | 1527 | struct nfs4_lookup_res res = { |
1528 | .server = server, | 1528 | .server = server, |
1529 | .fattr = fattr, | 1529 | .fattr = fattr, |
1530 | .fh = fhandle, | 1530 | .fh = fhandle, |
1531 | }; | 1531 | }; |
1532 | struct rpc_message msg = { | 1532 | struct rpc_message msg = { |
1533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], | 1533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
1534 | .rpc_argp = &args, | 1534 | .rpc_argp = &args, |
1535 | .rpc_resp = &res, | 1535 | .rpc_resp = &res, |
1536 | }; | 1536 | }; |
1537 | 1537 | ||
1538 | nfs_fattr_init(fattr); | 1538 | nfs_fattr_init(fattr); |
1539 | 1539 | ||
1540 | dprintk("NFS call lookup %s\n", name->name); | 1540 | dprintk("NFS call lookup %s\n", name->name); |
1541 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 1541 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
1542 | dprintk("NFS reply lookup: %d\n", status); | 1542 | dprintk("NFS reply lookup: %d\n", status); |
1543 | return status; | 1543 | return status; |
1544 | } | 1544 | } |
1545 | 1545 | ||
1546 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 1546 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
1547 | { | 1547 | { |
1548 | struct nfs4_exception exception = { }; | 1548 | struct nfs4_exception exception = { }; |
1549 | int err; | 1549 | int err; |
1550 | do { | 1550 | do { |
1551 | err = nfs4_handle_exception(NFS_SERVER(dir), | 1551 | err = nfs4_handle_exception(NFS_SERVER(dir), |
1552 | _nfs4_proc_lookup(dir, name, fhandle, fattr), | 1552 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
1553 | &exception); | 1553 | &exception); |
1554 | } while (exception.retry); | 1554 | } while (exception.retry); |
1555 | return err; | 1555 | return err; |
1556 | } | 1556 | } |
1557 | 1557 | ||
1558 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) | 1558 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
1559 | { | 1559 | { |
1560 | struct nfs4_accessargs args = { | 1560 | struct nfs4_accessargs args = { |
1561 | .fh = NFS_FH(inode), | 1561 | .fh = NFS_FH(inode), |
1562 | }; | 1562 | }; |
1563 | struct nfs4_accessres res = { 0 }; | 1563 | struct nfs4_accessres res = { 0 }; |
1564 | struct rpc_message msg = { | 1564 | struct rpc_message msg = { |
1565 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], | 1565 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
1566 | .rpc_argp = &args, | 1566 | .rpc_argp = &args, |
1567 | .rpc_resp = &res, | 1567 | .rpc_resp = &res, |
1568 | .rpc_cred = entry->cred, | 1568 | .rpc_cred = entry->cred, |
1569 | }; | 1569 | }; |
1570 | int mode = entry->mask; | 1570 | int mode = entry->mask; |
1571 | int status; | 1571 | int status; |
1572 | 1572 | ||
1573 | /* | 1573 | /* |
1574 | * Determine which access bits we want to ask for... | 1574 | * Determine which access bits we want to ask for... |
1575 | */ | 1575 | */ |
1576 | if (mode & MAY_READ) | 1576 | if (mode & MAY_READ) |
1577 | args.access |= NFS4_ACCESS_READ; | 1577 | args.access |= NFS4_ACCESS_READ; |
1578 | if (S_ISDIR(inode->i_mode)) { | 1578 | if (S_ISDIR(inode->i_mode)) { |
1579 | if (mode & MAY_WRITE) | 1579 | if (mode & MAY_WRITE) |
1580 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; | 1580 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
1581 | if (mode & MAY_EXEC) | 1581 | if (mode & MAY_EXEC) |
1582 | args.access |= NFS4_ACCESS_LOOKUP; | 1582 | args.access |= NFS4_ACCESS_LOOKUP; |
1583 | } else { | 1583 | } else { |
1584 | if (mode & MAY_WRITE) | 1584 | if (mode & MAY_WRITE) |
1585 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; | 1585 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
1586 | if (mode & MAY_EXEC) | 1586 | if (mode & MAY_EXEC) |
1587 | args.access |= NFS4_ACCESS_EXECUTE; | 1587 | args.access |= NFS4_ACCESS_EXECUTE; |
1588 | } | 1588 | } |
1589 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); | 1589 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
1590 | if (!status) { | 1590 | if (!status) { |
1591 | entry->mask = 0; | 1591 | entry->mask = 0; |
1592 | if (res.access & NFS4_ACCESS_READ) | 1592 | if (res.access & NFS4_ACCESS_READ) |
1593 | entry->mask |= MAY_READ; | 1593 | entry->mask |= MAY_READ; |
1594 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) | 1594 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
1595 | entry->mask |= MAY_WRITE; | 1595 | entry->mask |= MAY_WRITE; |
1596 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) | 1596 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
1597 | entry->mask |= MAY_EXEC; | 1597 | entry->mask |= MAY_EXEC; |
1598 | } | 1598 | } |
1599 | return status; | 1599 | return status; |
1600 | } | 1600 | } |
1601 | 1601 | ||
1602 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) | 1602 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
1603 | { | 1603 | { |
1604 | struct nfs4_exception exception = { }; | 1604 | struct nfs4_exception exception = { }; |
1605 | int err; | 1605 | int err; |
1606 | do { | 1606 | do { |
1607 | err = nfs4_handle_exception(NFS_SERVER(inode), | 1607 | err = nfs4_handle_exception(NFS_SERVER(inode), |
1608 | _nfs4_proc_access(inode, entry), | 1608 | _nfs4_proc_access(inode, entry), |
1609 | &exception); | 1609 | &exception); |
1610 | } while (exception.retry); | 1610 | } while (exception.retry); |
1611 | return err; | 1611 | return err; |
1612 | } | 1612 | } |
1613 | 1613 | ||
1614 | /* | 1614 | /* |
1615 | * TODO: For the time being, we don't try to get any attributes | 1615 | * TODO: For the time being, we don't try to get any attributes |
1616 | * along with any of the zero-copy operations READ, READDIR, | 1616 | * along with any of the zero-copy operations READ, READDIR, |
1617 | * READLINK, WRITE. | 1617 | * READLINK, WRITE. |
1618 | * | 1618 | * |
1619 | * In the case of the first three, we want to put the GETATTR | 1619 | * In the case of the first three, we want to put the GETATTR |
1620 | * after the read-type operation -- this is because it is hard | 1620 | * after the read-type operation -- this is because it is hard |
1621 | * to predict the length of a GETATTR response in v4, and thus | 1621 | * to predict the length of a GETATTR response in v4, and thus |
1622 | * align the READ data correctly. This means that the GETATTR | 1622 | * align the READ data correctly. This means that the GETATTR |
1623 | * may end up partially falling into the page cache, and we should | 1623 | * may end up partially falling into the page cache, and we should |
1624 | * shift it into the 'tail' of the xdr_buf before processing. | 1624 | * shift it into the 'tail' of the xdr_buf before processing. |
1625 | * To do this efficiently, we need to know the total length | 1625 | * To do this efficiently, we need to know the total length |
1626 | * of data received, which doesn't seem to be available outside | 1626 | * of data received, which doesn't seem to be available outside |
1627 | * of the RPC layer. | 1627 | * of the RPC layer. |
1628 | * | 1628 | * |
1629 | * In the case of WRITE, we also want to put the GETATTR after | 1629 | * In the case of WRITE, we also want to put the GETATTR after |
1630 | * the operation -- in this case because we want to make sure | 1630 | * the operation -- in this case because we want to make sure |
1631 | * we get the post-operation mtime and size. This means that | 1631 | * we get the post-operation mtime and size. This means that |
1632 | * we can't use xdr_encode_pages() as written: we need a variant | 1632 | * we can't use xdr_encode_pages() as written: we need a variant |
1633 | * of it which would leave room in the 'tail' iovec. | 1633 | * of it which would leave room in the 'tail' iovec. |
1634 | * | 1634 | * |
1635 | * Both of these changes to the XDR layer would in fact be quite | 1635 | * Both of these changes to the XDR layer would in fact be quite |
1636 | * minor, but I decided to leave them for a subsequent patch. | 1636 | * minor, but I decided to leave them for a subsequent patch. |
1637 | */ | 1637 | */ |
1638 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, | 1638 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
1639 | unsigned int pgbase, unsigned int pglen) | 1639 | unsigned int pgbase, unsigned int pglen) |
1640 | { | 1640 | { |
1641 | struct nfs4_readlink args = { | 1641 | struct nfs4_readlink args = { |
1642 | .fh = NFS_FH(inode), | 1642 | .fh = NFS_FH(inode), |
1643 | .pgbase = pgbase, | 1643 | .pgbase = pgbase, |
1644 | .pglen = pglen, | 1644 | .pglen = pglen, |
1645 | .pages = &page, | 1645 | .pages = &page, |
1646 | }; | 1646 | }; |
1647 | struct rpc_message msg = { | 1647 | struct rpc_message msg = { |
1648 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], | 1648 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
1649 | .rpc_argp = &args, | 1649 | .rpc_argp = &args, |
1650 | .rpc_resp = NULL, | 1650 | .rpc_resp = NULL, |
1651 | }; | 1651 | }; |
1652 | 1652 | ||
1653 | return rpc_call_sync(NFS_CLIENT(inode), &msg, 0); | 1653 | return rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
1654 | } | 1654 | } |
1655 | 1655 | ||
1656 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, | 1656 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
1657 | unsigned int pgbase, unsigned int pglen) | 1657 | unsigned int pgbase, unsigned int pglen) |
1658 | { | 1658 | { |
1659 | struct nfs4_exception exception = { }; | 1659 | struct nfs4_exception exception = { }; |
1660 | int err; | 1660 | int err; |
1661 | do { | 1661 | do { |
1662 | err = nfs4_handle_exception(NFS_SERVER(inode), | 1662 | err = nfs4_handle_exception(NFS_SERVER(inode), |
1663 | _nfs4_proc_readlink(inode, page, pgbase, pglen), | 1663 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
1664 | &exception); | 1664 | &exception); |
1665 | } while (exception.retry); | 1665 | } while (exception.retry); |
1666 | return err; | 1666 | return err; |
1667 | } | 1667 | } |
1668 | 1668 | ||
1669 | static int _nfs4_proc_read(struct nfs_read_data *rdata) | 1669 | static int _nfs4_proc_read(struct nfs_read_data *rdata) |
1670 | { | 1670 | { |
1671 | int flags = rdata->flags; | 1671 | int flags = rdata->flags; |
1672 | struct inode *inode = rdata->inode; | 1672 | struct inode *inode = rdata->inode; |
1673 | struct nfs_fattr *fattr = rdata->res.fattr; | 1673 | struct nfs_fattr *fattr = rdata->res.fattr; |
1674 | struct nfs_server *server = NFS_SERVER(inode); | 1674 | struct nfs_server *server = NFS_SERVER(inode); |
1675 | struct rpc_message msg = { | 1675 | struct rpc_message msg = { |
1676 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ], | 1676 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ], |
1677 | .rpc_argp = &rdata->args, | 1677 | .rpc_argp = &rdata->args, |
1678 | .rpc_resp = &rdata->res, | 1678 | .rpc_resp = &rdata->res, |
1679 | .rpc_cred = rdata->cred, | 1679 | .rpc_cred = rdata->cred, |
1680 | }; | 1680 | }; |
1681 | unsigned long timestamp = jiffies; | 1681 | unsigned long timestamp = jiffies; |
1682 | int status; | 1682 | int status; |
1683 | 1683 | ||
1684 | dprintk("NFS call read %d @ %Ld\n", rdata->args.count, | 1684 | dprintk("NFS call read %d @ %Ld\n", rdata->args.count, |
1685 | (long long) rdata->args.offset); | 1685 | (long long) rdata->args.offset); |
1686 | 1686 | ||
1687 | nfs_fattr_init(fattr); | 1687 | nfs_fattr_init(fattr); |
1688 | status = rpc_call_sync(server->client, &msg, flags); | 1688 | status = rpc_call_sync(server->client, &msg, flags); |
1689 | if (!status) | 1689 | if (!status) |
1690 | renew_lease(server, timestamp); | 1690 | renew_lease(server, timestamp); |
1691 | dprintk("NFS reply read: %d\n", status); | 1691 | dprintk("NFS reply read: %d\n", status); |
1692 | return status; | 1692 | return status; |
1693 | } | 1693 | } |
1694 | 1694 | ||
1695 | static int nfs4_proc_read(struct nfs_read_data *rdata) | 1695 | static int nfs4_proc_read(struct nfs_read_data *rdata) |
1696 | { | 1696 | { |
1697 | struct nfs4_exception exception = { }; | 1697 | struct nfs4_exception exception = { }; |
1698 | int err; | 1698 | int err; |
1699 | do { | 1699 | do { |
1700 | err = nfs4_handle_exception(NFS_SERVER(rdata->inode), | 1700 | err = nfs4_handle_exception(NFS_SERVER(rdata->inode), |
1701 | _nfs4_proc_read(rdata), | 1701 | _nfs4_proc_read(rdata), |
1702 | &exception); | 1702 | &exception); |
1703 | } while (exception.retry); | 1703 | } while (exception.retry); |
1704 | return err; | 1704 | return err; |
1705 | } | 1705 | } |
1706 | 1706 | ||
1707 | static int _nfs4_proc_write(struct nfs_write_data *wdata) | 1707 | static int _nfs4_proc_write(struct nfs_write_data *wdata) |
1708 | { | 1708 | { |
1709 | int rpcflags = wdata->flags; | 1709 | int rpcflags = wdata->flags; |
1710 | struct inode *inode = wdata->inode; | 1710 | struct inode *inode = wdata->inode; |
1711 | struct nfs_fattr *fattr = wdata->res.fattr; | 1711 | struct nfs_fattr *fattr = wdata->res.fattr; |
1712 | struct nfs_server *server = NFS_SERVER(inode); | 1712 | struct nfs_server *server = NFS_SERVER(inode); |
1713 | struct rpc_message msg = { | 1713 | struct rpc_message msg = { |
1714 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE], | 1714 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE], |
1715 | .rpc_argp = &wdata->args, | 1715 | .rpc_argp = &wdata->args, |
1716 | .rpc_resp = &wdata->res, | 1716 | .rpc_resp = &wdata->res, |
1717 | .rpc_cred = wdata->cred, | 1717 | .rpc_cred = wdata->cred, |
1718 | }; | 1718 | }; |
1719 | int status; | 1719 | int status; |
1720 | 1720 | ||
1721 | dprintk("NFS call write %d @ %Ld\n", wdata->args.count, | 1721 | dprintk("NFS call write %d @ %Ld\n", wdata->args.count, |
1722 | (long long) wdata->args.offset); | 1722 | (long long) wdata->args.offset); |
1723 | 1723 | ||
1724 | wdata->args.bitmask = server->attr_bitmask; | 1724 | wdata->args.bitmask = server->attr_bitmask; |
1725 | wdata->res.server = server; | 1725 | wdata->res.server = server; |
1726 | wdata->timestamp = jiffies; | 1726 | wdata->timestamp = jiffies; |
1727 | nfs_fattr_init(fattr); | 1727 | nfs_fattr_init(fattr); |
1728 | status = rpc_call_sync(server->client, &msg, rpcflags); | 1728 | status = rpc_call_sync(server->client, &msg, rpcflags); |
1729 | dprintk("NFS reply write: %d\n", status); | 1729 | dprintk("NFS reply write: %d\n", status); |
1730 | if (status < 0) | 1730 | if (status < 0) |
1731 | return status; | 1731 | return status; |
1732 | renew_lease(server, wdata->timestamp); | 1732 | renew_lease(server, wdata->timestamp); |
1733 | nfs_post_op_update_inode(inode, fattr); | 1733 | nfs_post_op_update_inode(inode, fattr); |
1734 | return wdata->res.count; | 1734 | return wdata->res.count; |
1735 | } | 1735 | } |
1736 | 1736 | ||
1737 | static int nfs4_proc_write(struct nfs_write_data *wdata) | 1737 | static int nfs4_proc_write(struct nfs_write_data *wdata) |
1738 | { | 1738 | { |
1739 | struct nfs4_exception exception = { }; | 1739 | struct nfs4_exception exception = { }; |
1740 | int err; | 1740 | int err; |
1741 | do { | 1741 | do { |
1742 | err = nfs4_handle_exception(NFS_SERVER(wdata->inode), | 1742 | err = nfs4_handle_exception(NFS_SERVER(wdata->inode), |
1743 | _nfs4_proc_write(wdata), | 1743 | _nfs4_proc_write(wdata), |
1744 | &exception); | 1744 | &exception); |
1745 | } while (exception.retry); | 1745 | } while (exception.retry); |
1746 | return err; | 1746 | return err; |
1747 | } | 1747 | } |
1748 | 1748 | ||
1749 | static int _nfs4_proc_commit(struct nfs_write_data *cdata) | 1749 | static int _nfs4_proc_commit(struct nfs_write_data *cdata) |
1750 | { | 1750 | { |
1751 | struct inode *inode = cdata->inode; | 1751 | struct inode *inode = cdata->inode; |
1752 | struct nfs_fattr *fattr = cdata->res.fattr; | 1752 | struct nfs_fattr *fattr = cdata->res.fattr; |
1753 | struct nfs_server *server = NFS_SERVER(inode); | 1753 | struct nfs_server *server = NFS_SERVER(inode); |
1754 | struct rpc_message msg = { | 1754 | struct rpc_message msg = { |
1755 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], | 1755 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
1756 | .rpc_argp = &cdata->args, | 1756 | .rpc_argp = &cdata->args, |
1757 | .rpc_resp = &cdata->res, | 1757 | .rpc_resp = &cdata->res, |
1758 | .rpc_cred = cdata->cred, | 1758 | .rpc_cred = cdata->cred, |
1759 | }; | 1759 | }; |
1760 | int status; | 1760 | int status; |
1761 | 1761 | ||
1762 | dprintk("NFS call commit %d @ %Ld\n", cdata->args.count, | 1762 | dprintk("NFS call commit %d @ %Ld\n", cdata->args.count, |
1763 | (long long) cdata->args.offset); | 1763 | (long long) cdata->args.offset); |
1764 | 1764 | ||
1765 | cdata->args.bitmask = server->attr_bitmask; | 1765 | cdata->args.bitmask = server->attr_bitmask; |
1766 | cdata->res.server = server; | 1766 | cdata->res.server = server; |
1767 | cdata->timestamp = jiffies; | 1767 | cdata->timestamp = jiffies; |
1768 | nfs_fattr_init(fattr); | 1768 | nfs_fattr_init(fattr); |
1769 | status = rpc_call_sync(server->client, &msg, 0); | 1769 | status = rpc_call_sync(server->client, &msg, 0); |
1770 | if (status >= 0) | 1770 | if (status >= 0) |
1771 | renew_lease(server, cdata->timestamp); | 1771 | renew_lease(server, cdata->timestamp); |
1772 | dprintk("NFS reply commit: %d\n", status); | 1772 | dprintk("NFS reply commit: %d\n", status); |
1773 | if (status >= 0) | 1773 | if (status >= 0) |
1774 | nfs_post_op_update_inode(inode, fattr); | 1774 | nfs_post_op_update_inode(inode, fattr); |
1775 | return status; | 1775 | return status; |
1776 | } | 1776 | } |
1777 | 1777 | ||
1778 | static int nfs4_proc_commit(struct nfs_write_data *cdata) | 1778 | static int nfs4_proc_commit(struct nfs_write_data *cdata) |
1779 | { | 1779 | { |
1780 | struct nfs4_exception exception = { }; | 1780 | struct nfs4_exception exception = { }; |
1781 | int err; | 1781 | int err; |
1782 | do { | 1782 | do { |
1783 | err = nfs4_handle_exception(NFS_SERVER(cdata->inode), | 1783 | err = nfs4_handle_exception(NFS_SERVER(cdata->inode), |
1784 | _nfs4_proc_commit(cdata), | 1784 | _nfs4_proc_commit(cdata), |
1785 | &exception); | 1785 | &exception); |
1786 | } while (exception.retry); | 1786 | } while (exception.retry); |
1787 | return err; | 1787 | return err; |
1788 | } | 1788 | } |
1789 | 1789 | ||
1790 | /* | 1790 | /* |
1791 | * Got race? | 1791 | * Got race? |
1792 | * We will need to arrange for the VFS layer to provide an atomic open. | 1792 | * We will need to arrange for the VFS layer to provide an atomic open. |
1793 | * Until then, this create/open method is prone to inefficiency and race | 1793 | * Until then, this create/open method is prone to inefficiency and race |
1794 | * conditions due to the lookup, create, and open VFS calls from sys_open() | 1794 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
1795 | * placed on the wire. | 1795 | * placed on the wire. |
1796 | * | 1796 | * |
1797 | * Given the above sorry state of affairs, I'm simply sending an OPEN. | 1797 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
1798 | * The file will be opened again in the subsequent VFS open call | 1798 | * The file will be opened again in the subsequent VFS open call |
1799 | * (nfs4_proc_file_open). | 1799 | * (nfs4_proc_file_open). |
1800 | * | 1800 | * |
1801 | * The open for read will just hang around to be used by any process that | 1801 | * The open for read will just hang around to be used by any process that |
1802 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. | 1802 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
1803 | */ | 1803 | */ |
1804 | 1804 | ||
1805 | static int | 1805 | static int |
1806 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | 1806 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
1807 | int flags, struct nameidata *nd) | 1807 | int flags, struct nameidata *nd) |
1808 | { | 1808 | { |
1809 | struct nfs4_state *state; | 1809 | struct nfs4_state *state; |
1810 | struct rpc_cred *cred; | 1810 | struct rpc_cred *cred; |
1811 | int status = 0; | 1811 | int status = 0; |
1812 | 1812 | ||
1813 | cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0); | 1813 | cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0); |
1814 | if (IS_ERR(cred)) { | 1814 | if (IS_ERR(cred)) { |
1815 | status = PTR_ERR(cred); | 1815 | status = PTR_ERR(cred); |
1816 | goto out; | 1816 | goto out; |
1817 | } | 1817 | } |
1818 | state = nfs4_do_open(dir, dentry, flags, sattr, cred); | 1818 | state = nfs4_do_open(dir, dentry, flags, sattr, cred); |
1819 | put_rpccred(cred); | 1819 | put_rpccred(cred); |
1820 | if (IS_ERR(state)) { | 1820 | if (IS_ERR(state)) { |
1821 | status = PTR_ERR(state); | 1821 | status = PTR_ERR(state); |
1822 | goto out; | 1822 | goto out; |
1823 | } | 1823 | } |
1824 | d_instantiate(dentry, igrab(state->inode)); | 1824 | d_instantiate(dentry, igrab(state->inode)); |
1825 | if (flags & O_EXCL) { | 1825 | if (flags & O_EXCL) { |
1826 | struct nfs_fattr fattr; | 1826 | struct nfs_fattr fattr; |
1827 | status = nfs4_do_setattr(state->inode, &fattr, sattr, state); | 1827 | status = nfs4_do_setattr(state->inode, &fattr, sattr, state); |
1828 | if (status == 0) | 1828 | if (status == 0) |
1829 | nfs_setattr_update_inode(state->inode, sattr); | 1829 | nfs_setattr_update_inode(state->inode, sattr); |
1830 | } | 1830 | } |
1831 | if (status == 0 && nd != NULL && (nd->flags & LOOKUP_OPEN)) | 1831 | if (status == 0 && nd != NULL && (nd->flags & LOOKUP_OPEN)) |
1832 | nfs4_intent_set_file(nd, dentry, state); | 1832 | nfs4_intent_set_file(nd, dentry, state); |
1833 | else | 1833 | else |
1834 | nfs4_close_state(state, flags); | 1834 | nfs4_close_state(state, flags); |
1835 | out: | 1835 | out: |
1836 | return status; | 1836 | return status; |
1837 | } | 1837 | } |
1838 | 1838 | ||
1839 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) | 1839 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
1840 | { | 1840 | { |
1841 | struct nfs_server *server = NFS_SERVER(dir); | 1841 | struct nfs_server *server = NFS_SERVER(dir); |
1842 | struct nfs4_remove_arg args = { | 1842 | struct nfs4_remove_arg args = { |
1843 | .fh = NFS_FH(dir), | 1843 | .fh = NFS_FH(dir), |
1844 | .name = name, | 1844 | .name = name, |
1845 | .bitmask = server->attr_bitmask, | 1845 | .bitmask = server->attr_bitmask, |
1846 | }; | 1846 | }; |
1847 | struct nfs_fattr dir_attr; | 1847 | struct nfs_fattr dir_attr; |
1848 | struct nfs4_remove_res res = { | 1848 | struct nfs4_remove_res res = { |
1849 | .server = server, | 1849 | .server = server, |
1850 | .dir_attr = &dir_attr, | 1850 | .dir_attr = &dir_attr, |
1851 | }; | 1851 | }; |
1852 | struct rpc_message msg = { | 1852 | struct rpc_message msg = { |
1853 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], | 1853 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
1854 | .rpc_argp = &args, | 1854 | .rpc_argp = &args, |
1855 | .rpc_resp = &res, | 1855 | .rpc_resp = &res, |
1856 | }; | 1856 | }; |
1857 | int status; | 1857 | int status; |
1858 | 1858 | ||
1859 | nfs_fattr_init(res.dir_attr); | 1859 | nfs_fattr_init(res.dir_attr); |
1860 | status = rpc_call_sync(server->client, &msg, 0); | 1860 | status = rpc_call_sync(server->client, &msg, 0); |
1861 | if (status == 0) { | 1861 | if (status == 0) { |
1862 | update_changeattr(dir, &res.cinfo); | 1862 | update_changeattr(dir, &res.cinfo); |
1863 | nfs_post_op_update_inode(dir, res.dir_attr); | 1863 | nfs_post_op_update_inode(dir, res.dir_attr); |
1864 | } | 1864 | } |
1865 | return status; | 1865 | return status; |
1866 | } | 1866 | } |
1867 | 1867 | ||
1868 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) | 1868 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
1869 | { | 1869 | { |
1870 | struct nfs4_exception exception = { }; | 1870 | struct nfs4_exception exception = { }; |
1871 | int err; | 1871 | int err; |
1872 | do { | 1872 | do { |
1873 | err = nfs4_handle_exception(NFS_SERVER(dir), | 1873 | err = nfs4_handle_exception(NFS_SERVER(dir), |
1874 | _nfs4_proc_remove(dir, name), | 1874 | _nfs4_proc_remove(dir, name), |
1875 | &exception); | 1875 | &exception); |
1876 | } while (exception.retry); | 1876 | } while (exception.retry); |
1877 | return err; | 1877 | return err; |
1878 | } | 1878 | } |
1879 | 1879 | ||
1880 | struct unlink_desc { | 1880 | struct unlink_desc { |
1881 | struct nfs4_remove_arg args; | 1881 | struct nfs4_remove_arg args; |
1882 | struct nfs4_remove_res res; | 1882 | struct nfs4_remove_res res; |
1883 | struct nfs_fattr dir_attr; | 1883 | struct nfs_fattr dir_attr; |
1884 | }; | 1884 | }; |
1885 | 1885 | ||
1886 | static int nfs4_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, | 1886 | static int nfs4_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, |
1887 | struct qstr *name) | 1887 | struct qstr *name) |
1888 | { | 1888 | { |
1889 | struct nfs_server *server = NFS_SERVER(dir->d_inode); | 1889 | struct nfs_server *server = NFS_SERVER(dir->d_inode); |
1890 | struct unlink_desc *up; | 1890 | struct unlink_desc *up; |
1891 | 1891 | ||
1892 | up = (struct unlink_desc *) kmalloc(sizeof(*up), GFP_KERNEL); | 1892 | up = (struct unlink_desc *) kmalloc(sizeof(*up), GFP_KERNEL); |
1893 | if (!up) | 1893 | if (!up) |
1894 | return -ENOMEM; | 1894 | return -ENOMEM; |
1895 | 1895 | ||
1896 | up->args.fh = NFS_FH(dir->d_inode); | 1896 | up->args.fh = NFS_FH(dir->d_inode); |
1897 | up->args.name = name; | 1897 | up->args.name = name; |
1898 | up->args.bitmask = server->attr_bitmask; | 1898 | up->args.bitmask = server->attr_bitmask; |
1899 | up->res.server = server; | 1899 | up->res.server = server; |
1900 | up->res.dir_attr = &up->dir_attr; | 1900 | up->res.dir_attr = &up->dir_attr; |
1901 | 1901 | ||
1902 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; | 1902 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
1903 | msg->rpc_argp = &up->args; | 1903 | msg->rpc_argp = &up->args; |
1904 | msg->rpc_resp = &up->res; | 1904 | msg->rpc_resp = &up->res; |
1905 | return 0; | 1905 | return 0; |
1906 | } | 1906 | } |
1907 | 1907 | ||
1908 | static int nfs4_proc_unlink_done(struct dentry *dir, struct rpc_task *task) | 1908 | static int nfs4_proc_unlink_done(struct dentry *dir, struct rpc_task *task) |
1909 | { | 1909 | { |
1910 | struct rpc_message *msg = &task->tk_msg; | 1910 | struct rpc_message *msg = &task->tk_msg; |
1911 | struct unlink_desc *up; | 1911 | struct unlink_desc *up; |
1912 | 1912 | ||
1913 | if (msg->rpc_resp != NULL) { | 1913 | if (msg->rpc_resp != NULL) { |
1914 | up = container_of(msg->rpc_resp, struct unlink_desc, res); | 1914 | up = container_of(msg->rpc_resp, struct unlink_desc, res); |
1915 | update_changeattr(dir->d_inode, &up->res.cinfo); | 1915 | update_changeattr(dir->d_inode, &up->res.cinfo); |
1916 | nfs_post_op_update_inode(dir->d_inode, up->res.dir_attr); | 1916 | nfs_post_op_update_inode(dir->d_inode, up->res.dir_attr); |
1917 | kfree(up); | 1917 | kfree(up); |
1918 | msg->rpc_resp = NULL; | 1918 | msg->rpc_resp = NULL; |
1919 | msg->rpc_argp = NULL; | 1919 | msg->rpc_argp = NULL; |
1920 | } | 1920 | } |
1921 | return 0; | 1921 | return 0; |
1922 | } | 1922 | } |
1923 | 1923 | ||
1924 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, | 1924 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
1925 | struct inode *new_dir, struct qstr *new_name) | 1925 | struct inode *new_dir, struct qstr *new_name) |
1926 | { | 1926 | { |
1927 | struct nfs_server *server = NFS_SERVER(old_dir); | 1927 | struct nfs_server *server = NFS_SERVER(old_dir); |
1928 | struct nfs4_rename_arg arg = { | 1928 | struct nfs4_rename_arg arg = { |
1929 | .old_dir = NFS_FH(old_dir), | 1929 | .old_dir = NFS_FH(old_dir), |
1930 | .new_dir = NFS_FH(new_dir), | 1930 | .new_dir = NFS_FH(new_dir), |
1931 | .old_name = old_name, | 1931 | .old_name = old_name, |
1932 | .new_name = new_name, | 1932 | .new_name = new_name, |
1933 | .bitmask = server->attr_bitmask, | 1933 | .bitmask = server->attr_bitmask, |
1934 | }; | 1934 | }; |
1935 | struct nfs_fattr old_fattr, new_fattr; | 1935 | struct nfs_fattr old_fattr, new_fattr; |
1936 | struct nfs4_rename_res res = { | 1936 | struct nfs4_rename_res res = { |
1937 | .server = server, | 1937 | .server = server, |
1938 | .old_fattr = &old_fattr, | 1938 | .old_fattr = &old_fattr, |
1939 | .new_fattr = &new_fattr, | 1939 | .new_fattr = &new_fattr, |
1940 | }; | 1940 | }; |
1941 | struct rpc_message msg = { | 1941 | struct rpc_message msg = { |
1942 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], | 1942 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
1943 | .rpc_argp = &arg, | 1943 | .rpc_argp = &arg, |
1944 | .rpc_resp = &res, | 1944 | .rpc_resp = &res, |
1945 | }; | 1945 | }; |
1946 | int status; | 1946 | int status; |
1947 | 1947 | ||
1948 | nfs_fattr_init(res.old_fattr); | 1948 | nfs_fattr_init(res.old_fattr); |
1949 | nfs_fattr_init(res.new_fattr); | 1949 | nfs_fattr_init(res.new_fattr); |
1950 | status = rpc_call_sync(server->client, &msg, 0); | 1950 | status = rpc_call_sync(server->client, &msg, 0); |
1951 | 1951 | ||
1952 | if (!status) { | 1952 | if (!status) { |
1953 | update_changeattr(old_dir, &res.old_cinfo); | 1953 | update_changeattr(old_dir, &res.old_cinfo); |
1954 | nfs_post_op_update_inode(old_dir, res.old_fattr); | 1954 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
1955 | update_changeattr(new_dir, &res.new_cinfo); | 1955 | update_changeattr(new_dir, &res.new_cinfo); |
1956 | nfs_post_op_update_inode(new_dir, res.new_fattr); | 1956 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
1957 | } | 1957 | } |
1958 | return status; | 1958 | return status; |
1959 | } | 1959 | } |
1960 | 1960 | ||
1961 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, | 1961 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
1962 | struct inode *new_dir, struct qstr *new_name) | 1962 | struct inode *new_dir, struct qstr *new_name) |
1963 | { | 1963 | { |
1964 | struct nfs4_exception exception = { }; | 1964 | struct nfs4_exception exception = { }; |
1965 | int err; | 1965 | int err; |
1966 | do { | 1966 | do { |
1967 | err = nfs4_handle_exception(NFS_SERVER(old_dir), | 1967 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
1968 | _nfs4_proc_rename(old_dir, old_name, | 1968 | _nfs4_proc_rename(old_dir, old_name, |
1969 | new_dir, new_name), | 1969 | new_dir, new_name), |
1970 | &exception); | 1970 | &exception); |
1971 | } while (exception.retry); | 1971 | } while (exception.retry); |
1972 | return err; | 1972 | return err; |
1973 | } | 1973 | } |
1974 | 1974 | ||
1975 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) | 1975 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
1976 | { | 1976 | { |
1977 | struct nfs_server *server = NFS_SERVER(inode); | 1977 | struct nfs_server *server = NFS_SERVER(inode); |
1978 | struct nfs4_link_arg arg = { | 1978 | struct nfs4_link_arg arg = { |
1979 | .fh = NFS_FH(inode), | 1979 | .fh = NFS_FH(inode), |
1980 | .dir_fh = NFS_FH(dir), | 1980 | .dir_fh = NFS_FH(dir), |
1981 | .name = name, | 1981 | .name = name, |
1982 | .bitmask = server->attr_bitmask, | 1982 | .bitmask = server->attr_bitmask, |
1983 | }; | 1983 | }; |
1984 | struct nfs_fattr fattr, dir_attr; | 1984 | struct nfs_fattr fattr, dir_attr; |
1985 | struct nfs4_link_res res = { | 1985 | struct nfs4_link_res res = { |
1986 | .server = server, | 1986 | .server = server, |
1987 | .fattr = &fattr, | 1987 | .fattr = &fattr, |
1988 | .dir_attr = &dir_attr, | 1988 | .dir_attr = &dir_attr, |
1989 | }; | 1989 | }; |
1990 | struct rpc_message msg = { | 1990 | struct rpc_message msg = { |
1991 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], | 1991 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
1992 | .rpc_argp = &arg, | 1992 | .rpc_argp = &arg, |
1993 | .rpc_resp = &res, | 1993 | .rpc_resp = &res, |
1994 | }; | 1994 | }; |
1995 | int status; | 1995 | int status; |
1996 | 1996 | ||
1997 | nfs_fattr_init(res.fattr); | 1997 | nfs_fattr_init(res.fattr); |
1998 | nfs_fattr_init(res.dir_attr); | 1998 | nfs_fattr_init(res.dir_attr); |
1999 | status = rpc_call_sync(server->client, &msg, 0); | 1999 | status = rpc_call_sync(server->client, &msg, 0); |
2000 | if (!status) { | 2000 | if (!status) { |
2001 | update_changeattr(dir, &res.cinfo); | 2001 | update_changeattr(dir, &res.cinfo); |
2002 | nfs_post_op_update_inode(dir, res.dir_attr); | 2002 | nfs_post_op_update_inode(dir, res.dir_attr); |
2003 | nfs_refresh_inode(inode, res.fattr); | 2003 | nfs_refresh_inode(inode, res.fattr); |
2004 | } | 2004 | } |
2005 | 2005 | ||
2006 | return status; | 2006 | return status; |
2007 | } | 2007 | } |
2008 | 2008 | ||
2009 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) | 2009 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
2010 | { | 2010 | { |
2011 | struct nfs4_exception exception = { }; | 2011 | struct nfs4_exception exception = { }; |
2012 | int err; | 2012 | int err; |
2013 | do { | 2013 | do { |
2014 | err = nfs4_handle_exception(NFS_SERVER(inode), | 2014 | err = nfs4_handle_exception(NFS_SERVER(inode), |
2015 | _nfs4_proc_link(inode, dir, name), | 2015 | _nfs4_proc_link(inode, dir, name), |
2016 | &exception); | 2016 | &exception); |
2017 | } while (exception.retry); | 2017 | } while (exception.retry); |
2018 | return err; | 2018 | return err; |
2019 | } | 2019 | } |
2020 | 2020 | ||
2021 | static int _nfs4_proc_symlink(struct inode *dir, struct qstr *name, | 2021 | static int _nfs4_proc_symlink(struct inode *dir, struct qstr *name, |
2022 | struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle, | 2022 | struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle, |
2023 | struct nfs_fattr *fattr) | 2023 | struct nfs_fattr *fattr) |
2024 | { | 2024 | { |
2025 | struct nfs_server *server = NFS_SERVER(dir); | 2025 | struct nfs_server *server = NFS_SERVER(dir); |
2026 | struct nfs_fattr dir_fattr; | 2026 | struct nfs_fattr dir_fattr; |
2027 | struct nfs4_create_arg arg = { | 2027 | struct nfs4_create_arg arg = { |
2028 | .dir_fh = NFS_FH(dir), | 2028 | .dir_fh = NFS_FH(dir), |
2029 | .server = server, | 2029 | .server = server, |
2030 | .name = name, | 2030 | .name = name, |
2031 | .attrs = sattr, | 2031 | .attrs = sattr, |
2032 | .ftype = NF4LNK, | 2032 | .ftype = NF4LNK, |
2033 | .bitmask = server->attr_bitmask, | 2033 | .bitmask = server->attr_bitmask, |
2034 | }; | 2034 | }; |
2035 | struct nfs4_create_res res = { | 2035 | struct nfs4_create_res res = { |
2036 | .server = server, | 2036 | .server = server, |
2037 | .fh = fhandle, | 2037 | .fh = fhandle, |
2038 | .fattr = fattr, | 2038 | .fattr = fattr, |
2039 | .dir_fattr = &dir_fattr, | 2039 | .dir_fattr = &dir_fattr, |
2040 | }; | 2040 | }; |
2041 | struct rpc_message msg = { | 2041 | struct rpc_message msg = { |
2042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK], | 2042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK], |
2043 | .rpc_argp = &arg, | 2043 | .rpc_argp = &arg, |
2044 | .rpc_resp = &res, | 2044 | .rpc_resp = &res, |
2045 | }; | 2045 | }; |
2046 | int status; | 2046 | int status; |
2047 | 2047 | ||
2048 | if (path->len > NFS4_MAXPATHLEN) | 2048 | if (path->len > NFS4_MAXPATHLEN) |
2049 | return -ENAMETOOLONG; | 2049 | return -ENAMETOOLONG; |
2050 | arg.u.symlink = path; | 2050 | arg.u.symlink = path; |
2051 | nfs_fattr_init(fattr); | 2051 | nfs_fattr_init(fattr); |
2052 | nfs_fattr_init(&dir_fattr); | 2052 | nfs_fattr_init(&dir_fattr); |
2053 | 2053 | ||
2054 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 2054 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
2055 | if (!status) | 2055 | if (!status) |
2056 | update_changeattr(dir, &res.dir_cinfo); | 2056 | update_changeattr(dir, &res.dir_cinfo); |
2057 | nfs_post_op_update_inode(dir, res.dir_fattr); | 2057 | nfs_post_op_update_inode(dir, res.dir_fattr); |
2058 | return status; | 2058 | return status; |
2059 | } | 2059 | } |
2060 | 2060 | ||
2061 | static int nfs4_proc_symlink(struct inode *dir, struct qstr *name, | 2061 | static int nfs4_proc_symlink(struct inode *dir, struct qstr *name, |
2062 | struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle, | 2062 | struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle, |
2063 | struct nfs_fattr *fattr) | 2063 | struct nfs_fattr *fattr) |
2064 | { | 2064 | { |
2065 | struct nfs4_exception exception = { }; | 2065 | struct nfs4_exception exception = { }; |
2066 | int err; | 2066 | int err; |
2067 | do { | 2067 | do { |
2068 | err = nfs4_handle_exception(NFS_SERVER(dir), | 2068 | err = nfs4_handle_exception(NFS_SERVER(dir), |
2069 | _nfs4_proc_symlink(dir, name, path, sattr, | 2069 | _nfs4_proc_symlink(dir, name, path, sattr, |
2070 | fhandle, fattr), | 2070 | fhandle, fattr), |
2071 | &exception); | 2071 | &exception); |
2072 | } while (exception.retry); | 2072 | } while (exception.retry); |
2073 | return err; | 2073 | return err; |
2074 | } | 2074 | } |
2075 | 2075 | ||
2076 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | 2076 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
2077 | struct iattr *sattr) | 2077 | struct iattr *sattr) |
2078 | { | 2078 | { |
2079 | struct nfs_server *server = NFS_SERVER(dir); | 2079 | struct nfs_server *server = NFS_SERVER(dir); |
2080 | struct nfs_fh fhandle; | 2080 | struct nfs_fh fhandle; |
2081 | struct nfs_fattr fattr, dir_fattr; | 2081 | struct nfs_fattr fattr, dir_fattr; |
2082 | struct nfs4_create_arg arg = { | 2082 | struct nfs4_create_arg arg = { |
2083 | .dir_fh = NFS_FH(dir), | 2083 | .dir_fh = NFS_FH(dir), |
2084 | .server = server, | 2084 | .server = server, |
2085 | .name = &dentry->d_name, | 2085 | .name = &dentry->d_name, |
2086 | .attrs = sattr, | 2086 | .attrs = sattr, |
2087 | .ftype = NF4DIR, | 2087 | .ftype = NF4DIR, |
2088 | .bitmask = server->attr_bitmask, | 2088 | .bitmask = server->attr_bitmask, |
2089 | }; | 2089 | }; |
2090 | struct nfs4_create_res res = { | 2090 | struct nfs4_create_res res = { |
2091 | .server = server, | 2091 | .server = server, |
2092 | .fh = &fhandle, | 2092 | .fh = &fhandle, |
2093 | .fattr = &fattr, | 2093 | .fattr = &fattr, |
2094 | .dir_fattr = &dir_fattr, | 2094 | .dir_fattr = &dir_fattr, |
2095 | }; | 2095 | }; |
2096 | struct rpc_message msg = { | 2096 | struct rpc_message msg = { |
2097 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE], | 2097 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE], |
2098 | .rpc_argp = &arg, | 2098 | .rpc_argp = &arg, |
2099 | .rpc_resp = &res, | 2099 | .rpc_resp = &res, |
2100 | }; | 2100 | }; |
2101 | int status; | 2101 | int status; |
2102 | 2102 | ||
2103 | nfs_fattr_init(&fattr); | 2103 | nfs_fattr_init(&fattr); |
2104 | nfs_fattr_init(&dir_fattr); | 2104 | nfs_fattr_init(&dir_fattr); |
2105 | 2105 | ||
2106 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 2106 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
2107 | if (!status) { | 2107 | if (!status) { |
2108 | update_changeattr(dir, &res.dir_cinfo); | 2108 | update_changeattr(dir, &res.dir_cinfo); |
2109 | nfs_post_op_update_inode(dir, res.dir_fattr); | 2109 | nfs_post_op_update_inode(dir, res.dir_fattr); |
2110 | status = nfs_instantiate(dentry, &fhandle, &fattr); | 2110 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
2111 | } | 2111 | } |
2112 | return status; | 2112 | return status; |
2113 | } | 2113 | } |
2114 | 2114 | ||
2115 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | 2115 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
2116 | struct iattr *sattr) | 2116 | struct iattr *sattr) |
2117 | { | 2117 | { |
2118 | struct nfs4_exception exception = { }; | 2118 | struct nfs4_exception exception = { }; |
2119 | int err; | 2119 | int err; |
2120 | do { | 2120 | do { |
2121 | err = nfs4_handle_exception(NFS_SERVER(dir), | 2121 | err = nfs4_handle_exception(NFS_SERVER(dir), |
2122 | _nfs4_proc_mkdir(dir, dentry, sattr), | 2122 | _nfs4_proc_mkdir(dir, dentry, sattr), |
2123 | &exception); | 2123 | &exception); |
2124 | } while (exception.retry); | 2124 | } while (exception.retry); |
2125 | return err; | 2125 | return err; |
2126 | } | 2126 | } |
2127 | 2127 | ||
2128 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | 2128 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
2129 | u64 cookie, struct page *page, unsigned int count, int plus) | 2129 | u64 cookie, struct page *page, unsigned int count, int plus) |
2130 | { | 2130 | { |
2131 | struct inode *dir = dentry->d_inode; | 2131 | struct inode *dir = dentry->d_inode; |
2132 | struct nfs4_readdir_arg args = { | 2132 | struct nfs4_readdir_arg args = { |
2133 | .fh = NFS_FH(dir), | 2133 | .fh = NFS_FH(dir), |
2134 | .pages = &page, | 2134 | .pages = &page, |
2135 | .pgbase = 0, | 2135 | .pgbase = 0, |
2136 | .count = count, | 2136 | .count = count, |
2137 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, | 2137 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
2138 | }; | 2138 | }; |
2139 | struct nfs4_readdir_res res; | 2139 | struct nfs4_readdir_res res; |
2140 | struct rpc_message msg = { | 2140 | struct rpc_message msg = { |
2141 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], | 2141 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
2142 | .rpc_argp = &args, | 2142 | .rpc_argp = &args, |
2143 | .rpc_resp = &res, | 2143 | .rpc_resp = &res, |
2144 | .rpc_cred = cred, | 2144 | .rpc_cred = cred, |
2145 | }; | 2145 | }; |
2146 | int status; | 2146 | int status; |
2147 | 2147 | ||
2148 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __FUNCTION__, | 2148 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __FUNCTION__, |
2149 | dentry->d_parent->d_name.name, | 2149 | dentry->d_parent->d_name.name, |
2150 | dentry->d_name.name, | 2150 | dentry->d_name.name, |
2151 | (unsigned long long)cookie); | 2151 | (unsigned long long)cookie); |
2152 | lock_kernel(); | 2152 | lock_kernel(); |
2153 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); | 2153 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
2154 | res.pgbase = args.pgbase; | 2154 | res.pgbase = args.pgbase; |
2155 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 2155 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
2156 | if (status == 0) | 2156 | if (status == 0) |
2157 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); | 2157 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
2158 | unlock_kernel(); | 2158 | unlock_kernel(); |
2159 | dprintk("%s: returns %d\n", __FUNCTION__, status); | 2159 | dprintk("%s: returns %d\n", __FUNCTION__, status); |
2160 | return status; | 2160 | return status; |
2161 | } | 2161 | } |
2162 | 2162 | ||
2163 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | 2163 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
2164 | u64 cookie, struct page *page, unsigned int count, int plus) | 2164 | u64 cookie, struct page *page, unsigned int count, int plus) |
2165 | { | 2165 | { |
2166 | struct nfs4_exception exception = { }; | 2166 | struct nfs4_exception exception = { }; |
2167 | int err; | 2167 | int err; |
2168 | do { | 2168 | do { |
2169 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), | 2169 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
2170 | _nfs4_proc_readdir(dentry, cred, cookie, | 2170 | _nfs4_proc_readdir(dentry, cred, cookie, |
2171 | page, count, plus), | 2171 | page, count, plus), |
2172 | &exception); | 2172 | &exception); |
2173 | } while (exception.retry); | 2173 | } while (exception.retry); |
2174 | return err; | 2174 | return err; |
2175 | } | 2175 | } |
2176 | 2176 | ||
2177 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | 2177 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
2178 | struct iattr *sattr, dev_t rdev) | 2178 | struct iattr *sattr, dev_t rdev) |
2179 | { | 2179 | { |
2180 | struct nfs_server *server = NFS_SERVER(dir); | 2180 | struct nfs_server *server = NFS_SERVER(dir); |
2181 | struct nfs_fh fh; | 2181 | struct nfs_fh fh; |
2182 | struct nfs_fattr fattr, dir_fattr; | 2182 | struct nfs_fattr fattr, dir_fattr; |
2183 | struct nfs4_create_arg arg = { | 2183 | struct nfs4_create_arg arg = { |
2184 | .dir_fh = NFS_FH(dir), | 2184 | .dir_fh = NFS_FH(dir), |
2185 | .server = server, | 2185 | .server = server, |
2186 | .name = &dentry->d_name, | 2186 | .name = &dentry->d_name, |
2187 | .attrs = sattr, | 2187 | .attrs = sattr, |
2188 | .bitmask = server->attr_bitmask, | 2188 | .bitmask = server->attr_bitmask, |
2189 | }; | 2189 | }; |
2190 | struct nfs4_create_res res = { | 2190 | struct nfs4_create_res res = { |
2191 | .server = server, | 2191 | .server = server, |
2192 | .fh = &fh, | 2192 | .fh = &fh, |
2193 | .fattr = &fattr, | 2193 | .fattr = &fattr, |
2194 | .dir_fattr = &dir_fattr, | 2194 | .dir_fattr = &dir_fattr, |
2195 | }; | 2195 | }; |
2196 | struct rpc_message msg = { | 2196 | struct rpc_message msg = { |
2197 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE], | 2197 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE], |
2198 | .rpc_argp = &arg, | 2198 | .rpc_argp = &arg, |
2199 | .rpc_resp = &res, | 2199 | .rpc_resp = &res, |
2200 | }; | 2200 | }; |
2201 | int status; | 2201 | int status; |
2202 | int mode = sattr->ia_mode; | 2202 | int mode = sattr->ia_mode; |
2203 | 2203 | ||
2204 | nfs_fattr_init(&fattr); | 2204 | nfs_fattr_init(&fattr); |
2205 | nfs_fattr_init(&dir_fattr); | 2205 | nfs_fattr_init(&dir_fattr); |
2206 | 2206 | ||
2207 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); | 2207 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
2208 | BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode)); | 2208 | BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode)); |
2209 | if (S_ISFIFO(mode)) | 2209 | if (S_ISFIFO(mode)) |
2210 | arg.ftype = NF4FIFO; | 2210 | arg.ftype = NF4FIFO; |
2211 | else if (S_ISBLK(mode)) { | 2211 | else if (S_ISBLK(mode)) { |
2212 | arg.ftype = NF4BLK; | 2212 | arg.ftype = NF4BLK; |
2213 | arg.u.device.specdata1 = MAJOR(rdev); | 2213 | arg.u.device.specdata1 = MAJOR(rdev); |
2214 | arg.u.device.specdata2 = MINOR(rdev); | 2214 | arg.u.device.specdata2 = MINOR(rdev); |
2215 | } | 2215 | } |
2216 | else if (S_ISCHR(mode)) { | 2216 | else if (S_ISCHR(mode)) { |
2217 | arg.ftype = NF4CHR; | 2217 | arg.ftype = NF4CHR; |
2218 | arg.u.device.specdata1 = MAJOR(rdev); | 2218 | arg.u.device.specdata1 = MAJOR(rdev); |
2219 | arg.u.device.specdata2 = MINOR(rdev); | 2219 | arg.u.device.specdata2 = MINOR(rdev); |
2220 | } | 2220 | } |
2221 | else | 2221 | else |
2222 | arg.ftype = NF4SOCK; | 2222 | arg.ftype = NF4SOCK; |
2223 | 2223 | ||
2224 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 2224 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
2225 | if (status == 0) { | 2225 | if (status == 0) { |
2226 | update_changeattr(dir, &res.dir_cinfo); | 2226 | update_changeattr(dir, &res.dir_cinfo); |
2227 | nfs_post_op_update_inode(dir, res.dir_fattr); | 2227 | nfs_post_op_update_inode(dir, res.dir_fattr); |
2228 | status = nfs_instantiate(dentry, &fh, &fattr); | 2228 | status = nfs_instantiate(dentry, &fh, &fattr); |
2229 | } | 2229 | } |
2230 | return status; | 2230 | return status; |
2231 | } | 2231 | } |
2232 | 2232 | ||
2233 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | 2233 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
2234 | struct iattr *sattr, dev_t rdev) | 2234 | struct iattr *sattr, dev_t rdev) |
2235 | { | 2235 | { |
2236 | struct nfs4_exception exception = { }; | 2236 | struct nfs4_exception exception = { }; |
2237 | int err; | 2237 | int err; |
2238 | do { | 2238 | do { |
2239 | err = nfs4_handle_exception(NFS_SERVER(dir), | 2239 | err = nfs4_handle_exception(NFS_SERVER(dir), |
2240 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), | 2240 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
2241 | &exception); | 2241 | &exception); |
2242 | } while (exception.retry); | 2242 | } while (exception.retry); |
2243 | return err; | 2243 | return err; |
2244 | } | 2244 | } |
2245 | 2245 | ||
2246 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, | 2246 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
2247 | struct nfs_fsstat *fsstat) | 2247 | struct nfs_fsstat *fsstat) |
2248 | { | 2248 | { |
2249 | struct nfs4_statfs_arg args = { | 2249 | struct nfs4_statfs_arg args = { |
2250 | .fh = fhandle, | 2250 | .fh = fhandle, |
2251 | .bitmask = server->attr_bitmask, | 2251 | .bitmask = server->attr_bitmask, |
2252 | }; | 2252 | }; |
2253 | struct rpc_message msg = { | 2253 | struct rpc_message msg = { |
2254 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], | 2254 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
2255 | .rpc_argp = &args, | 2255 | .rpc_argp = &args, |
2256 | .rpc_resp = fsstat, | 2256 | .rpc_resp = fsstat, |
2257 | }; | 2257 | }; |
2258 | 2258 | ||
2259 | nfs_fattr_init(fsstat->fattr); | 2259 | nfs_fattr_init(fsstat->fattr); |
2260 | return rpc_call_sync(server->client, &msg, 0); | 2260 | return rpc_call_sync(server->client, &msg, 0); |
2261 | } | 2261 | } |
2262 | 2262 | ||
2263 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) | 2263 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
2264 | { | 2264 | { |
2265 | struct nfs4_exception exception = { }; | 2265 | struct nfs4_exception exception = { }; |
2266 | int err; | 2266 | int err; |
2267 | do { | 2267 | do { |
2268 | err = nfs4_handle_exception(server, | 2268 | err = nfs4_handle_exception(server, |
2269 | _nfs4_proc_statfs(server, fhandle, fsstat), | 2269 | _nfs4_proc_statfs(server, fhandle, fsstat), |
2270 | &exception); | 2270 | &exception); |
2271 | } while (exception.retry); | 2271 | } while (exception.retry); |
2272 | return err; | 2272 | return err; |
2273 | } | 2273 | } |
2274 | 2274 | ||
2275 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, | 2275 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
2276 | struct nfs_fsinfo *fsinfo) | 2276 | struct nfs_fsinfo *fsinfo) |
2277 | { | 2277 | { |
2278 | struct nfs4_fsinfo_arg args = { | 2278 | struct nfs4_fsinfo_arg args = { |
2279 | .fh = fhandle, | 2279 | .fh = fhandle, |
2280 | .bitmask = server->attr_bitmask, | 2280 | .bitmask = server->attr_bitmask, |
2281 | }; | 2281 | }; |
2282 | struct rpc_message msg = { | 2282 | struct rpc_message msg = { |
2283 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], | 2283 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
2284 | .rpc_argp = &args, | 2284 | .rpc_argp = &args, |
2285 | .rpc_resp = fsinfo, | 2285 | .rpc_resp = fsinfo, |
2286 | }; | 2286 | }; |
2287 | 2287 | ||
2288 | return rpc_call_sync(server->client, &msg, 0); | 2288 | return rpc_call_sync(server->client, &msg, 0); |
2289 | } | 2289 | } |
2290 | 2290 | ||
2291 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) | 2291 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
2292 | { | 2292 | { |
2293 | struct nfs4_exception exception = { }; | 2293 | struct nfs4_exception exception = { }; |
2294 | int err; | 2294 | int err; |
2295 | 2295 | ||
2296 | do { | 2296 | do { |
2297 | err = nfs4_handle_exception(server, | 2297 | err = nfs4_handle_exception(server, |
2298 | _nfs4_do_fsinfo(server, fhandle, fsinfo), | 2298 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
2299 | &exception); | 2299 | &exception); |
2300 | } while (exception.retry); | 2300 | } while (exception.retry); |
2301 | return err; | 2301 | return err; |
2302 | } | 2302 | } |
2303 | 2303 | ||
2304 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) | 2304 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
2305 | { | 2305 | { |
2306 | nfs_fattr_init(fsinfo->fattr); | 2306 | nfs_fattr_init(fsinfo->fattr); |
2307 | return nfs4_do_fsinfo(server, fhandle, fsinfo); | 2307 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
2308 | } | 2308 | } |
2309 | 2309 | ||
2310 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | 2310 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
2311 | struct nfs_pathconf *pathconf) | 2311 | struct nfs_pathconf *pathconf) |
2312 | { | 2312 | { |
2313 | struct nfs4_pathconf_arg args = { | 2313 | struct nfs4_pathconf_arg args = { |
2314 | .fh = fhandle, | 2314 | .fh = fhandle, |
2315 | .bitmask = server->attr_bitmask, | 2315 | .bitmask = server->attr_bitmask, |
2316 | }; | 2316 | }; |
2317 | struct rpc_message msg = { | 2317 | struct rpc_message msg = { |
2318 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], | 2318 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
2319 | .rpc_argp = &args, | 2319 | .rpc_argp = &args, |
2320 | .rpc_resp = pathconf, | 2320 | .rpc_resp = pathconf, |
2321 | }; | 2321 | }; |
2322 | 2322 | ||
2323 | /* None of the pathconf attributes are mandatory to implement */ | 2323 | /* None of the pathconf attributes are mandatory to implement */ |
2324 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { | 2324 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
2325 | memset(pathconf, 0, sizeof(*pathconf)); | 2325 | memset(pathconf, 0, sizeof(*pathconf)); |
2326 | return 0; | 2326 | return 0; |
2327 | } | 2327 | } |
2328 | 2328 | ||
2329 | nfs_fattr_init(pathconf->fattr); | 2329 | nfs_fattr_init(pathconf->fattr); |
2330 | return rpc_call_sync(server->client, &msg, 0); | 2330 | return rpc_call_sync(server->client, &msg, 0); |
2331 | } | 2331 | } |
2332 | 2332 | ||
2333 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | 2333 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
2334 | struct nfs_pathconf *pathconf) | 2334 | struct nfs_pathconf *pathconf) |
2335 | { | 2335 | { |
2336 | struct nfs4_exception exception = { }; | 2336 | struct nfs4_exception exception = { }; |
2337 | int err; | 2337 | int err; |
2338 | 2338 | ||
2339 | do { | 2339 | do { |
2340 | err = nfs4_handle_exception(server, | 2340 | err = nfs4_handle_exception(server, |
2341 | _nfs4_proc_pathconf(server, fhandle, pathconf), | 2341 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
2342 | &exception); | 2342 | &exception); |
2343 | } while (exception.retry); | 2343 | } while (exception.retry); |
2344 | return err; | 2344 | return err; |
2345 | } | 2345 | } |
2346 | 2346 | ||
2347 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) | 2347 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
2348 | { | 2348 | { |
2349 | struct nfs_server *server = NFS_SERVER(data->inode); | 2349 | struct nfs_server *server = NFS_SERVER(data->inode); |
2350 | 2350 | ||
2351 | if (nfs4_async_handle_error(task, server) == -EAGAIN) { | 2351 | if (nfs4_async_handle_error(task, server) == -EAGAIN) { |
2352 | rpc_restart_call(task); | 2352 | rpc_restart_call(task); |
2353 | return -EAGAIN; | 2353 | return -EAGAIN; |
2354 | } | 2354 | } |
2355 | if (task->tk_status > 0) | 2355 | if (task->tk_status > 0) |
2356 | renew_lease(server, data->timestamp); | 2356 | renew_lease(server, data->timestamp); |
2357 | return 0; | 2357 | return 0; |
2358 | } | 2358 | } |
2359 | 2359 | ||
2360 | static void nfs4_proc_read_setup(struct nfs_read_data *data) | 2360 | static void nfs4_proc_read_setup(struct nfs_read_data *data) |
2361 | { | 2361 | { |
2362 | struct rpc_message msg = { | 2362 | struct rpc_message msg = { |
2363 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ], | 2363 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ], |
2364 | .rpc_argp = &data->args, | 2364 | .rpc_argp = &data->args, |
2365 | .rpc_resp = &data->res, | 2365 | .rpc_resp = &data->res, |
2366 | .rpc_cred = data->cred, | 2366 | .rpc_cred = data->cred, |
2367 | }; | 2367 | }; |
2368 | 2368 | ||
2369 | data->timestamp = jiffies; | 2369 | data->timestamp = jiffies; |
2370 | 2370 | ||
2371 | rpc_call_setup(&data->task, &msg, 0); | 2371 | rpc_call_setup(&data->task, &msg, 0); |
2372 | } | 2372 | } |
2373 | 2373 | ||
2374 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) | 2374 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
2375 | { | 2375 | { |
2376 | struct inode *inode = data->inode; | 2376 | struct inode *inode = data->inode; |
2377 | 2377 | ||
2378 | if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) { | 2378 | if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) { |
2379 | rpc_restart_call(task); | 2379 | rpc_restart_call(task); |
2380 | return -EAGAIN; | 2380 | return -EAGAIN; |
2381 | } | 2381 | } |
2382 | if (task->tk_status >= 0) { | 2382 | if (task->tk_status >= 0) { |
2383 | renew_lease(NFS_SERVER(inode), data->timestamp); | 2383 | renew_lease(NFS_SERVER(inode), data->timestamp); |
2384 | nfs_post_op_update_inode(inode, data->res.fattr); | 2384 | nfs_post_op_update_inode(inode, data->res.fattr); |
2385 | } | 2385 | } |
2386 | return 0; | 2386 | return 0; |
2387 | } | 2387 | } |
2388 | 2388 | ||
2389 | static void nfs4_proc_write_setup(struct nfs_write_data *data, int how) | 2389 | static void nfs4_proc_write_setup(struct nfs_write_data *data, int how) |
2390 | { | 2390 | { |
2391 | struct rpc_message msg = { | 2391 | struct rpc_message msg = { |
2392 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE], | 2392 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE], |
2393 | .rpc_argp = &data->args, | 2393 | .rpc_argp = &data->args, |
2394 | .rpc_resp = &data->res, | 2394 | .rpc_resp = &data->res, |
2395 | .rpc_cred = data->cred, | 2395 | .rpc_cred = data->cred, |
2396 | }; | 2396 | }; |
2397 | struct inode *inode = data->inode; | 2397 | struct inode *inode = data->inode; |
2398 | struct nfs_server *server = NFS_SERVER(inode); | 2398 | struct nfs_server *server = NFS_SERVER(inode); |
2399 | int stable; | 2399 | int stable; |
2400 | 2400 | ||
2401 | if (how & FLUSH_STABLE) { | 2401 | if (how & FLUSH_STABLE) { |
2402 | if (!NFS_I(inode)->ncommit) | 2402 | if (!NFS_I(inode)->ncommit) |
2403 | stable = NFS_FILE_SYNC; | 2403 | stable = NFS_FILE_SYNC; |
2404 | else | 2404 | else |
2405 | stable = NFS_DATA_SYNC; | 2405 | stable = NFS_DATA_SYNC; |
2406 | } else | 2406 | } else |
2407 | stable = NFS_UNSTABLE; | 2407 | stable = NFS_UNSTABLE; |
2408 | data->args.stable = stable; | 2408 | data->args.stable = stable; |
2409 | data->args.bitmask = server->attr_bitmask; | 2409 | data->args.bitmask = server->attr_bitmask; |
2410 | data->res.server = server; | 2410 | data->res.server = server; |
2411 | 2411 | ||
2412 | data->timestamp = jiffies; | 2412 | data->timestamp = jiffies; |
2413 | 2413 | ||
2414 | /* Finalize the task. */ | 2414 | /* Finalize the task. */ |
2415 | rpc_call_setup(&data->task, &msg, 0); | 2415 | rpc_call_setup(&data->task, &msg, 0); |
2416 | } | 2416 | } |
2417 | 2417 | ||
2418 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) | 2418 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
2419 | { | 2419 | { |
2420 | struct inode *inode = data->inode; | 2420 | struct inode *inode = data->inode; |
2421 | 2421 | ||
2422 | if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) { | 2422 | if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) { |
2423 | rpc_restart_call(task); | 2423 | rpc_restart_call(task); |
2424 | return -EAGAIN; | 2424 | return -EAGAIN; |
2425 | } | 2425 | } |
2426 | if (task->tk_status >= 0) | 2426 | if (task->tk_status >= 0) |
2427 | nfs_post_op_update_inode(inode, data->res.fattr); | 2427 | nfs_post_op_update_inode(inode, data->res.fattr); |
2428 | return 0; | 2428 | return 0; |
2429 | } | 2429 | } |
2430 | 2430 | ||
2431 | static void nfs4_proc_commit_setup(struct nfs_write_data *data, int how) | 2431 | static void nfs4_proc_commit_setup(struct nfs_write_data *data, int how) |
2432 | { | 2432 | { |
2433 | struct rpc_message msg = { | 2433 | struct rpc_message msg = { |
2434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], | 2434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
2435 | .rpc_argp = &data->args, | 2435 | .rpc_argp = &data->args, |
2436 | .rpc_resp = &data->res, | 2436 | .rpc_resp = &data->res, |
2437 | .rpc_cred = data->cred, | 2437 | .rpc_cred = data->cred, |
2438 | }; | 2438 | }; |
2439 | struct nfs_server *server = NFS_SERVER(data->inode); | 2439 | struct nfs_server *server = NFS_SERVER(data->inode); |
2440 | 2440 | ||
2441 | data->args.bitmask = server->attr_bitmask; | 2441 | data->args.bitmask = server->attr_bitmask; |
2442 | data->res.server = server; | 2442 | data->res.server = server; |
2443 | 2443 | ||
2444 | rpc_call_setup(&data->task, &msg, 0); | 2444 | rpc_call_setup(&data->task, &msg, 0); |
2445 | } | 2445 | } |
2446 | 2446 | ||
2447 | /* | 2447 | /* |
2448 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special | 2448 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
2449 | * standalone procedure for queueing an asynchronous RENEW. | 2449 | * standalone procedure for queueing an asynchronous RENEW. |
2450 | */ | 2450 | */ |
2451 | static void nfs4_renew_done(struct rpc_task *task, void *data) | 2451 | static void nfs4_renew_done(struct rpc_task *task, void *data) |
2452 | { | 2452 | { |
2453 | struct nfs4_client *clp = (struct nfs4_client *)task->tk_msg.rpc_argp; | 2453 | struct nfs4_client *clp = (struct nfs4_client *)task->tk_msg.rpc_argp; |
2454 | unsigned long timestamp = (unsigned long)data; | 2454 | unsigned long timestamp = (unsigned long)data; |
2455 | 2455 | ||
2456 | if (task->tk_status < 0) { | 2456 | if (task->tk_status < 0) { |
2457 | switch (task->tk_status) { | 2457 | switch (task->tk_status) { |
2458 | case -NFS4ERR_STALE_CLIENTID: | 2458 | case -NFS4ERR_STALE_CLIENTID: |
2459 | case -NFS4ERR_EXPIRED: | 2459 | case -NFS4ERR_EXPIRED: |
2460 | case -NFS4ERR_CB_PATH_DOWN: | 2460 | case -NFS4ERR_CB_PATH_DOWN: |
2461 | nfs4_schedule_state_recovery(clp); | 2461 | nfs4_schedule_state_recovery(clp); |
2462 | } | 2462 | } |
2463 | return; | 2463 | return; |
2464 | } | 2464 | } |
2465 | spin_lock(&clp->cl_lock); | 2465 | spin_lock(&clp->cl_lock); |
2466 | if (time_before(clp->cl_last_renewal,timestamp)) | 2466 | if (time_before(clp->cl_last_renewal,timestamp)) |
2467 | clp->cl_last_renewal = timestamp; | 2467 | clp->cl_last_renewal = timestamp; |
2468 | spin_unlock(&clp->cl_lock); | 2468 | spin_unlock(&clp->cl_lock); |
2469 | } | 2469 | } |
2470 | 2470 | ||
2471 | static const struct rpc_call_ops nfs4_renew_ops = { | 2471 | static const struct rpc_call_ops nfs4_renew_ops = { |
2472 | .rpc_call_done = nfs4_renew_done, | 2472 | .rpc_call_done = nfs4_renew_done, |
2473 | }; | 2473 | }; |
2474 | 2474 | ||
2475 | int nfs4_proc_async_renew(struct nfs4_client *clp, struct rpc_cred *cred) | 2475 | int nfs4_proc_async_renew(struct nfs4_client *clp, struct rpc_cred *cred) |
2476 | { | 2476 | { |
2477 | struct rpc_message msg = { | 2477 | struct rpc_message msg = { |
2478 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], | 2478 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
2479 | .rpc_argp = clp, | 2479 | .rpc_argp = clp, |
2480 | .rpc_cred = cred, | 2480 | .rpc_cred = cred, |
2481 | }; | 2481 | }; |
2482 | 2482 | ||
2483 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, | 2483 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
2484 | &nfs4_renew_ops, (void *)jiffies); | 2484 | &nfs4_renew_ops, (void *)jiffies); |
2485 | } | 2485 | } |
2486 | 2486 | ||
2487 | int nfs4_proc_renew(struct nfs4_client *clp, struct rpc_cred *cred) | 2487 | int nfs4_proc_renew(struct nfs4_client *clp, struct rpc_cred *cred) |
2488 | { | 2488 | { |
2489 | struct rpc_message msg = { | 2489 | struct rpc_message msg = { |
2490 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], | 2490 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
2491 | .rpc_argp = clp, | 2491 | .rpc_argp = clp, |
2492 | .rpc_cred = cred, | 2492 | .rpc_cred = cred, |
2493 | }; | 2493 | }; |
2494 | unsigned long now = jiffies; | 2494 | unsigned long now = jiffies; |
2495 | int status; | 2495 | int status; |
2496 | 2496 | ||
2497 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); | 2497 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
2498 | if (status < 0) | 2498 | if (status < 0) |
2499 | return status; | 2499 | return status; |
2500 | spin_lock(&clp->cl_lock); | 2500 | spin_lock(&clp->cl_lock); |
2501 | if (time_before(clp->cl_last_renewal,now)) | 2501 | if (time_before(clp->cl_last_renewal,now)) |
2502 | clp->cl_last_renewal = now; | 2502 | clp->cl_last_renewal = now; |
2503 | spin_unlock(&clp->cl_lock); | 2503 | spin_unlock(&clp->cl_lock); |
2504 | return 0; | 2504 | return 0; |
2505 | } | 2505 | } |
2506 | 2506 | ||
2507 | static inline int nfs4_server_supports_acls(struct nfs_server *server) | 2507 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
2508 | { | 2508 | { |
2509 | return (server->caps & NFS_CAP_ACLS) | 2509 | return (server->caps & NFS_CAP_ACLS) |
2510 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) | 2510 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
2511 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); | 2511 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
2512 | } | 2512 | } |
2513 | 2513 | ||
2514 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that | 2514 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
2515 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on | 2515 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
2516 | * the stack. | 2516 | * the stack. |
2517 | */ | 2517 | */ |
2518 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) | 2518 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
2519 | 2519 | ||
2520 | static void buf_to_pages(const void *buf, size_t buflen, | 2520 | static void buf_to_pages(const void *buf, size_t buflen, |
2521 | struct page **pages, unsigned int *pgbase) | 2521 | struct page **pages, unsigned int *pgbase) |
2522 | { | 2522 | { |
2523 | const void *p = buf; | 2523 | const void *p = buf; |
2524 | 2524 | ||
2525 | *pgbase = offset_in_page(buf); | 2525 | *pgbase = offset_in_page(buf); |
2526 | p -= *pgbase; | 2526 | p -= *pgbase; |
2527 | while (p < buf + buflen) { | 2527 | while (p < buf + buflen) { |
2528 | *(pages++) = virt_to_page(p); | 2528 | *(pages++) = virt_to_page(p); |
2529 | p += PAGE_CACHE_SIZE; | 2529 | p += PAGE_CACHE_SIZE; |
2530 | } | 2530 | } |
2531 | } | 2531 | } |
2532 | 2532 | ||
2533 | struct nfs4_cached_acl { | 2533 | struct nfs4_cached_acl { |
2534 | int cached; | 2534 | int cached; |
2535 | size_t len; | 2535 | size_t len; |
2536 | char data[0]; | 2536 | char data[0]; |
2537 | }; | 2537 | }; |
2538 | 2538 | ||
2539 | static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl) | 2539 | static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl) |
2540 | { | 2540 | { |
2541 | struct nfs_inode *nfsi = NFS_I(inode); | 2541 | struct nfs_inode *nfsi = NFS_I(inode); |
2542 | 2542 | ||
2543 | spin_lock(&inode->i_lock); | 2543 | spin_lock(&inode->i_lock); |
2544 | kfree(nfsi->nfs4_acl); | 2544 | kfree(nfsi->nfs4_acl); |
2545 | nfsi->nfs4_acl = acl; | 2545 | nfsi->nfs4_acl = acl; |
2546 | spin_unlock(&inode->i_lock); | 2546 | spin_unlock(&inode->i_lock); |
2547 | } | 2547 | } |
2548 | 2548 | ||
2549 | static void nfs4_zap_acl_attr(struct inode *inode) | 2549 | static void nfs4_zap_acl_attr(struct inode *inode) |
2550 | { | 2550 | { |
2551 | nfs4_set_cached_acl(inode, NULL); | 2551 | nfs4_set_cached_acl(inode, NULL); |
2552 | } | 2552 | } |
2553 | 2553 | ||
2554 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) | 2554 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
2555 | { | 2555 | { |
2556 | struct nfs_inode *nfsi = NFS_I(inode); | 2556 | struct nfs_inode *nfsi = NFS_I(inode); |
2557 | struct nfs4_cached_acl *acl; | 2557 | struct nfs4_cached_acl *acl; |
2558 | int ret = -ENOENT; | 2558 | int ret = -ENOENT; |
2559 | 2559 | ||
2560 | spin_lock(&inode->i_lock); | 2560 | spin_lock(&inode->i_lock); |
2561 | acl = nfsi->nfs4_acl; | 2561 | acl = nfsi->nfs4_acl; |
2562 | if (acl == NULL) | 2562 | if (acl == NULL) |
2563 | goto out; | 2563 | goto out; |
2564 | if (buf == NULL) /* user is just asking for length */ | 2564 | if (buf == NULL) /* user is just asking for length */ |
2565 | goto out_len; | 2565 | goto out_len; |
2566 | if (acl->cached == 0) | 2566 | if (acl->cached == 0) |
2567 | goto out; | 2567 | goto out; |
2568 | ret = -ERANGE; /* see getxattr(2) man page */ | 2568 | ret = -ERANGE; /* see getxattr(2) man page */ |
2569 | if (acl->len > buflen) | 2569 | if (acl->len > buflen) |
2570 | goto out; | 2570 | goto out; |
2571 | memcpy(buf, acl->data, acl->len); | 2571 | memcpy(buf, acl->data, acl->len); |
2572 | out_len: | 2572 | out_len: |
2573 | ret = acl->len; | 2573 | ret = acl->len; |
2574 | out: | 2574 | out: |
2575 | spin_unlock(&inode->i_lock); | 2575 | spin_unlock(&inode->i_lock); |
2576 | return ret; | 2576 | return ret; |
2577 | } | 2577 | } |
2578 | 2578 | ||
2579 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) | 2579 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
2580 | { | 2580 | { |
2581 | struct nfs4_cached_acl *acl; | 2581 | struct nfs4_cached_acl *acl; |
2582 | 2582 | ||
2583 | if (buf && acl_len <= PAGE_SIZE) { | 2583 | if (buf && acl_len <= PAGE_SIZE) { |
2584 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); | 2584 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
2585 | if (acl == NULL) | 2585 | if (acl == NULL) |
2586 | goto out; | 2586 | goto out; |
2587 | acl->cached = 1; | 2587 | acl->cached = 1; |
2588 | memcpy(acl->data, buf, acl_len); | 2588 | memcpy(acl->data, buf, acl_len); |
2589 | } else { | 2589 | } else { |
2590 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); | 2590 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
2591 | if (acl == NULL) | 2591 | if (acl == NULL) |
2592 | goto out; | 2592 | goto out; |
2593 | acl->cached = 0; | 2593 | acl->cached = 0; |
2594 | } | 2594 | } |
2595 | acl->len = acl_len; | 2595 | acl->len = acl_len; |
2596 | out: | 2596 | out: |
2597 | nfs4_set_cached_acl(inode, acl); | 2597 | nfs4_set_cached_acl(inode, acl); |
2598 | } | 2598 | } |
2599 | 2599 | ||
2600 | static inline ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) | 2600 | static inline ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
2601 | { | 2601 | { |
2602 | struct page *pages[NFS4ACL_MAXPAGES]; | 2602 | struct page *pages[NFS4ACL_MAXPAGES]; |
2603 | struct nfs_getaclargs args = { | 2603 | struct nfs_getaclargs args = { |
2604 | .fh = NFS_FH(inode), | 2604 | .fh = NFS_FH(inode), |
2605 | .acl_pages = pages, | 2605 | .acl_pages = pages, |
2606 | .acl_len = buflen, | 2606 | .acl_len = buflen, |
2607 | }; | 2607 | }; |
2608 | size_t resp_len = buflen; | 2608 | size_t resp_len = buflen; |
2609 | void *resp_buf; | 2609 | void *resp_buf; |
2610 | struct rpc_message msg = { | 2610 | struct rpc_message msg = { |
2611 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], | 2611 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
2612 | .rpc_argp = &args, | 2612 | .rpc_argp = &args, |
2613 | .rpc_resp = &resp_len, | 2613 | .rpc_resp = &resp_len, |
2614 | }; | 2614 | }; |
2615 | struct page *localpage = NULL; | 2615 | struct page *localpage = NULL; |
2616 | int ret; | 2616 | int ret; |
2617 | 2617 | ||
2618 | if (buflen < PAGE_SIZE) { | 2618 | if (buflen < PAGE_SIZE) { |
2619 | /* As long as we're doing a round trip to the server anyway, | 2619 | /* As long as we're doing a round trip to the server anyway, |
2620 | * let's be prepared for a page of acl data. */ | 2620 | * let's be prepared for a page of acl data. */ |
2621 | localpage = alloc_page(GFP_KERNEL); | 2621 | localpage = alloc_page(GFP_KERNEL); |
2622 | resp_buf = page_address(localpage); | 2622 | resp_buf = page_address(localpage); |
2623 | if (localpage == NULL) | 2623 | if (localpage == NULL) |
2624 | return -ENOMEM; | 2624 | return -ENOMEM; |
2625 | args.acl_pages[0] = localpage; | 2625 | args.acl_pages[0] = localpage; |
2626 | args.acl_pgbase = 0; | 2626 | args.acl_pgbase = 0; |
2627 | resp_len = args.acl_len = PAGE_SIZE; | 2627 | resp_len = args.acl_len = PAGE_SIZE; |
2628 | } else { | 2628 | } else { |
2629 | resp_buf = buf; | 2629 | resp_buf = buf; |
2630 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); | 2630 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
2631 | } | 2631 | } |
2632 | ret = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); | 2632 | ret = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
2633 | if (ret) | 2633 | if (ret) |
2634 | goto out_free; | 2634 | goto out_free; |
2635 | if (resp_len > args.acl_len) | 2635 | if (resp_len > args.acl_len) |
2636 | nfs4_write_cached_acl(inode, NULL, resp_len); | 2636 | nfs4_write_cached_acl(inode, NULL, resp_len); |
2637 | else | 2637 | else |
2638 | nfs4_write_cached_acl(inode, resp_buf, resp_len); | 2638 | nfs4_write_cached_acl(inode, resp_buf, resp_len); |
2639 | if (buf) { | 2639 | if (buf) { |
2640 | ret = -ERANGE; | 2640 | ret = -ERANGE; |
2641 | if (resp_len > buflen) | 2641 | if (resp_len > buflen) |
2642 | goto out_free; | 2642 | goto out_free; |
2643 | if (localpage) | 2643 | if (localpage) |
2644 | memcpy(buf, resp_buf, resp_len); | 2644 | memcpy(buf, resp_buf, resp_len); |
2645 | } | 2645 | } |
2646 | ret = resp_len; | 2646 | ret = resp_len; |
2647 | out_free: | 2647 | out_free: |
2648 | if (localpage) | 2648 | if (localpage) |
2649 | __free_page(localpage); | 2649 | __free_page(localpage); |
2650 | return ret; | 2650 | return ret; |
2651 | } | 2651 | } |
2652 | 2652 | ||
2653 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) | 2653 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
2654 | { | 2654 | { |
2655 | struct nfs_server *server = NFS_SERVER(inode); | 2655 | struct nfs_server *server = NFS_SERVER(inode); |
2656 | int ret; | 2656 | int ret; |
2657 | 2657 | ||
2658 | if (!nfs4_server_supports_acls(server)) | 2658 | if (!nfs4_server_supports_acls(server)) |
2659 | return -EOPNOTSUPP; | 2659 | return -EOPNOTSUPP; |
2660 | ret = nfs_revalidate_inode(server, inode); | 2660 | ret = nfs_revalidate_inode(server, inode); |
2661 | if (ret < 0) | 2661 | if (ret < 0) |
2662 | return ret; | 2662 | return ret; |
2663 | ret = nfs4_read_cached_acl(inode, buf, buflen); | 2663 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
2664 | if (ret != -ENOENT) | 2664 | if (ret != -ENOENT) |
2665 | return ret; | 2665 | return ret; |
2666 | return nfs4_get_acl_uncached(inode, buf, buflen); | 2666 | return nfs4_get_acl_uncached(inode, buf, buflen); |
2667 | } | 2667 | } |
2668 | 2668 | ||
2669 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) | 2669 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
2670 | { | 2670 | { |
2671 | struct nfs_server *server = NFS_SERVER(inode); | 2671 | struct nfs_server *server = NFS_SERVER(inode); |
2672 | struct page *pages[NFS4ACL_MAXPAGES]; | 2672 | struct page *pages[NFS4ACL_MAXPAGES]; |
2673 | struct nfs_setaclargs arg = { | 2673 | struct nfs_setaclargs arg = { |
2674 | .fh = NFS_FH(inode), | 2674 | .fh = NFS_FH(inode), |
2675 | .acl_pages = pages, | 2675 | .acl_pages = pages, |
2676 | .acl_len = buflen, | 2676 | .acl_len = buflen, |
2677 | }; | 2677 | }; |
2678 | struct rpc_message msg = { | 2678 | struct rpc_message msg = { |
2679 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], | 2679 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
2680 | .rpc_argp = &arg, | 2680 | .rpc_argp = &arg, |
2681 | .rpc_resp = NULL, | 2681 | .rpc_resp = NULL, |
2682 | }; | 2682 | }; |
2683 | int ret; | 2683 | int ret; |
2684 | 2684 | ||
2685 | if (!nfs4_server_supports_acls(server)) | 2685 | if (!nfs4_server_supports_acls(server)) |
2686 | return -EOPNOTSUPP; | 2686 | return -EOPNOTSUPP; |
2687 | nfs_inode_return_delegation(inode); | 2687 | nfs_inode_return_delegation(inode); |
2688 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); | 2688 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
2689 | ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0); | 2689 | ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0); |
2690 | if (ret == 0) | 2690 | if (ret == 0) |
2691 | nfs4_write_cached_acl(inode, buf, buflen); | 2691 | nfs4_write_cached_acl(inode, buf, buflen); |
2692 | return ret; | 2692 | return ret; |
2693 | } | 2693 | } |
2694 | 2694 | ||
2695 | static int | 2695 | static int |
2696 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server) | 2696 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server) |
2697 | { | 2697 | { |
2698 | struct nfs4_client *clp = server->nfs4_state; | 2698 | struct nfs4_client *clp = server->nfs4_state; |
2699 | 2699 | ||
2700 | if (!clp || task->tk_status >= 0) | 2700 | if (!clp || task->tk_status >= 0) |
2701 | return 0; | 2701 | return 0; |
2702 | switch(task->tk_status) { | 2702 | switch(task->tk_status) { |
2703 | case -NFS4ERR_STALE_CLIENTID: | 2703 | case -NFS4ERR_STALE_CLIENTID: |
2704 | case -NFS4ERR_STALE_STATEID: | 2704 | case -NFS4ERR_STALE_STATEID: |
2705 | case -NFS4ERR_EXPIRED: | 2705 | case -NFS4ERR_EXPIRED: |
2706 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL, NULL); | 2706 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL, NULL); |
2707 | nfs4_schedule_state_recovery(clp); | 2707 | nfs4_schedule_state_recovery(clp); |
2708 | if (test_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state) == 0) | 2708 | if (test_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state) == 0) |
2709 | rpc_wake_up_task(task); | 2709 | rpc_wake_up_task(task); |
2710 | task->tk_status = 0; | 2710 | task->tk_status = 0; |
2711 | return -EAGAIN; | 2711 | return -EAGAIN; |
2712 | case -NFS4ERR_DELAY: | 2712 | case -NFS4ERR_DELAY: |
2713 | nfs_inc_server_stats((struct nfs_server *) server, | 2713 | nfs_inc_server_stats((struct nfs_server *) server, |
2714 | NFSIOS_DELAY); | 2714 | NFSIOS_DELAY); |
2715 | case -NFS4ERR_GRACE: | 2715 | case -NFS4ERR_GRACE: |
2716 | rpc_delay(task, NFS4_POLL_RETRY_MAX); | 2716 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
2717 | task->tk_status = 0; | 2717 | task->tk_status = 0; |
2718 | return -EAGAIN; | 2718 | return -EAGAIN; |
2719 | case -NFS4ERR_OLD_STATEID: | 2719 | case -NFS4ERR_OLD_STATEID: |
2720 | task->tk_status = 0; | 2720 | task->tk_status = 0; |
2721 | return -EAGAIN; | 2721 | return -EAGAIN; |
2722 | } | 2722 | } |
2723 | task->tk_status = nfs4_map_errors(task->tk_status); | 2723 | task->tk_status = nfs4_map_errors(task->tk_status); |
2724 | return 0; | 2724 | return 0; |
2725 | } | 2725 | } |
2726 | 2726 | ||
2727 | static int nfs4_wait_bit_interruptible(void *word) | 2727 | static int nfs4_wait_bit_interruptible(void *word) |
2728 | { | 2728 | { |
2729 | if (signal_pending(current)) | 2729 | if (signal_pending(current)) |
2730 | return -ERESTARTSYS; | 2730 | return -ERESTARTSYS; |
2731 | schedule(); | 2731 | schedule(); |
2732 | return 0; | 2732 | return 0; |
2733 | } | 2733 | } |
2734 | 2734 | ||
2735 | static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp) | 2735 | static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp) |
2736 | { | 2736 | { |
2737 | sigset_t oldset; | 2737 | sigset_t oldset; |
2738 | int res; | 2738 | int res; |
2739 | 2739 | ||
2740 | might_sleep(); | 2740 | might_sleep(); |
2741 | 2741 | ||
2742 | rpc_clnt_sigmask(clnt, &oldset); | 2742 | rpc_clnt_sigmask(clnt, &oldset); |
2743 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_STATE_RECOVER, | 2743 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_STATE_RECOVER, |
2744 | nfs4_wait_bit_interruptible, | 2744 | nfs4_wait_bit_interruptible, |
2745 | TASK_INTERRUPTIBLE); | 2745 | TASK_INTERRUPTIBLE); |
2746 | rpc_clnt_sigunmask(clnt, &oldset); | 2746 | rpc_clnt_sigunmask(clnt, &oldset); |
2747 | return res; | 2747 | return res; |
2748 | } | 2748 | } |
2749 | 2749 | ||
2750 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) | 2750 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
2751 | { | 2751 | { |
2752 | sigset_t oldset; | 2752 | sigset_t oldset; |
2753 | int res = 0; | 2753 | int res = 0; |
2754 | 2754 | ||
2755 | might_sleep(); | 2755 | might_sleep(); |
2756 | 2756 | ||
2757 | if (*timeout <= 0) | 2757 | if (*timeout <= 0) |
2758 | *timeout = NFS4_POLL_RETRY_MIN; | 2758 | *timeout = NFS4_POLL_RETRY_MIN; |
2759 | if (*timeout > NFS4_POLL_RETRY_MAX) | 2759 | if (*timeout > NFS4_POLL_RETRY_MAX) |
2760 | *timeout = NFS4_POLL_RETRY_MAX; | 2760 | *timeout = NFS4_POLL_RETRY_MAX; |
2761 | rpc_clnt_sigmask(clnt, &oldset); | 2761 | rpc_clnt_sigmask(clnt, &oldset); |
2762 | if (clnt->cl_intr) { | 2762 | if (clnt->cl_intr) { |
2763 | schedule_timeout_interruptible(*timeout); | 2763 | schedule_timeout_interruptible(*timeout); |
2764 | if (signalled()) | 2764 | if (signalled()) |
2765 | res = -ERESTARTSYS; | 2765 | res = -ERESTARTSYS; |
2766 | } else | 2766 | } else |
2767 | schedule_timeout_uninterruptible(*timeout); | 2767 | schedule_timeout_uninterruptible(*timeout); |
2768 | rpc_clnt_sigunmask(clnt, &oldset); | 2768 | rpc_clnt_sigunmask(clnt, &oldset); |
2769 | *timeout <<= 1; | 2769 | *timeout <<= 1; |
2770 | return res; | 2770 | return res; |
2771 | } | 2771 | } |
2772 | 2772 | ||
2773 | /* This is the error handling routine for processes that are allowed | 2773 | /* This is the error handling routine for processes that are allowed |
2774 | * to sleep. | 2774 | * to sleep. |
2775 | */ | 2775 | */ |
2776 | int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) | 2776 | int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
2777 | { | 2777 | { |
2778 | struct nfs4_client *clp = server->nfs4_state; | 2778 | struct nfs4_client *clp = server->nfs4_state; |
2779 | int ret = errorcode; | 2779 | int ret = errorcode; |
2780 | 2780 | ||
2781 | exception->retry = 0; | 2781 | exception->retry = 0; |
2782 | switch(errorcode) { | 2782 | switch(errorcode) { |
2783 | case 0: | 2783 | case 0: |
2784 | return 0; | 2784 | return 0; |
2785 | case -NFS4ERR_STALE_CLIENTID: | 2785 | case -NFS4ERR_STALE_CLIENTID: |
2786 | case -NFS4ERR_STALE_STATEID: | 2786 | case -NFS4ERR_STALE_STATEID: |
2787 | case -NFS4ERR_EXPIRED: | 2787 | case -NFS4ERR_EXPIRED: |
2788 | nfs4_schedule_state_recovery(clp); | 2788 | nfs4_schedule_state_recovery(clp); |
2789 | ret = nfs4_wait_clnt_recover(server->client, clp); | 2789 | ret = nfs4_wait_clnt_recover(server->client, clp); |
2790 | if (ret == 0) | 2790 | if (ret == 0) |
2791 | exception->retry = 1; | 2791 | exception->retry = 1; |
2792 | break; | 2792 | break; |
2793 | case -NFS4ERR_GRACE: | 2793 | case -NFS4ERR_GRACE: |
2794 | case -NFS4ERR_DELAY: | 2794 | case -NFS4ERR_DELAY: |
2795 | ret = nfs4_delay(server->client, &exception->timeout); | 2795 | ret = nfs4_delay(server->client, &exception->timeout); |
2796 | if (ret != 0) | 2796 | if (ret != 0) |
2797 | break; | 2797 | break; |
2798 | case -NFS4ERR_OLD_STATEID: | 2798 | case -NFS4ERR_OLD_STATEID: |
2799 | exception->retry = 1; | 2799 | exception->retry = 1; |
2800 | } | 2800 | } |
2801 | /* We failed to handle the error */ | 2801 | /* We failed to handle the error */ |
2802 | return nfs4_map_errors(ret); | 2802 | return nfs4_map_errors(ret); |
2803 | } | 2803 | } |
2804 | 2804 | ||
2805 | int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port, struct rpc_cred *cred) | 2805 | int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port, struct rpc_cred *cred) |
2806 | { | 2806 | { |
2807 | nfs4_verifier sc_verifier; | 2807 | nfs4_verifier sc_verifier; |
2808 | struct nfs4_setclientid setclientid = { | 2808 | struct nfs4_setclientid setclientid = { |
2809 | .sc_verifier = &sc_verifier, | 2809 | .sc_verifier = &sc_verifier, |
2810 | .sc_prog = program, | 2810 | .sc_prog = program, |
2811 | }; | 2811 | }; |
2812 | struct rpc_message msg = { | 2812 | struct rpc_message msg = { |
2813 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], | 2813 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
2814 | .rpc_argp = &setclientid, | 2814 | .rpc_argp = &setclientid, |
2815 | .rpc_resp = clp, | 2815 | .rpc_resp = clp, |
2816 | .rpc_cred = cred, | 2816 | .rpc_cred = cred, |
2817 | }; | 2817 | }; |
2818 | u32 *p; | 2818 | u32 *p; |
2819 | int loop = 0; | 2819 | int loop = 0; |
2820 | int status; | 2820 | int status; |
2821 | 2821 | ||
2822 | p = (u32*)sc_verifier.data; | 2822 | p = (u32*)sc_verifier.data; |
2823 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); | 2823 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
2824 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); | 2824 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
2825 | 2825 | ||
2826 | for(;;) { | 2826 | for(;;) { |
2827 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, | 2827 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
2828 | sizeof(setclientid.sc_name), "%s/%u.%u.%u.%u %s %u", | 2828 | sizeof(setclientid.sc_name), "%s/%u.%u.%u.%u %s %u", |
2829 | clp->cl_ipaddr, NIPQUAD(clp->cl_addr.s_addr), | 2829 | clp->cl_ipaddr, NIPQUAD(clp->cl_addr.s_addr), |
2830 | cred->cr_ops->cr_name, | 2830 | cred->cr_ops->cr_name, |
2831 | clp->cl_id_uniquifier); | 2831 | clp->cl_id_uniquifier); |
2832 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, | 2832 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
2833 | sizeof(setclientid.sc_netid), "tcp"); | 2833 | sizeof(setclientid.sc_netid), "tcp"); |
2834 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, | 2834 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
2835 | sizeof(setclientid.sc_uaddr), "%s.%d.%d", | 2835 | sizeof(setclientid.sc_uaddr), "%s.%d.%d", |
2836 | clp->cl_ipaddr, port >> 8, port & 255); | 2836 | clp->cl_ipaddr, port >> 8, port & 255); |
2837 | 2837 | ||
2838 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); | 2838 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
2839 | if (status != -NFS4ERR_CLID_INUSE) | 2839 | if (status != -NFS4ERR_CLID_INUSE) |
2840 | break; | 2840 | break; |
2841 | if (signalled()) | 2841 | if (signalled()) |
2842 | break; | 2842 | break; |
2843 | if (loop++ & 1) | 2843 | if (loop++ & 1) |
2844 | ssleep(clp->cl_lease_time + 1); | 2844 | ssleep(clp->cl_lease_time + 1); |
2845 | else | 2845 | else |
2846 | if (++clp->cl_id_uniquifier == 0) | 2846 | if (++clp->cl_id_uniquifier == 0) |
2847 | break; | 2847 | break; |
2848 | } | 2848 | } |
2849 | return status; | 2849 | return status; |
2850 | } | 2850 | } |
2851 | 2851 | ||
2852 | int | 2852 | static int _nfs4_proc_setclientid_confirm(struct nfs4_client *clp, struct rpc_cred *cred) |
2853 | nfs4_proc_setclientid_confirm(struct nfs4_client *clp, struct rpc_cred *cred) | ||
2854 | { | 2853 | { |
2855 | struct nfs_fsinfo fsinfo; | 2854 | struct nfs_fsinfo fsinfo; |
2856 | struct rpc_message msg = { | 2855 | struct rpc_message msg = { |
2857 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], | 2856 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
2858 | .rpc_argp = clp, | 2857 | .rpc_argp = clp, |
2859 | .rpc_resp = &fsinfo, | 2858 | .rpc_resp = &fsinfo, |
2860 | .rpc_cred = cred, | 2859 | .rpc_cred = cred, |
2861 | }; | 2860 | }; |
2862 | unsigned long now; | 2861 | unsigned long now; |
2863 | int status; | 2862 | int status; |
2864 | 2863 | ||
2865 | now = jiffies; | 2864 | now = jiffies; |
2866 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); | 2865 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
2867 | if (status == 0) { | 2866 | if (status == 0) { |
2868 | spin_lock(&clp->cl_lock); | 2867 | spin_lock(&clp->cl_lock); |
2869 | clp->cl_lease_time = fsinfo.lease_time * HZ; | 2868 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
2870 | clp->cl_last_renewal = now; | 2869 | clp->cl_last_renewal = now; |
2871 | clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); | 2870 | clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); |
2872 | spin_unlock(&clp->cl_lock); | 2871 | spin_unlock(&clp->cl_lock); |
2873 | } | 2872 | } |
2874 | return status; | 2873 | return status; |
2874 | } | ||
2875 | |||
2876 | int nfs4_proc_setclientid_confirm(struct nfs4_client *clp, struct rpc_cred *cred) | ||
2877 | { | ||
2878 | long timeout; | ||
2879 | int err; | ||
2880 | do { | ||
2881 | err = _nfs4_proc_setclientid_confirm(clp, cred); | ||
2882 | switch (err) { | ||
2883 | case 0: | ||
2884 | return err; | ||
2885 | case -NFS4ERR_RESOURCE: | ||
2886 | /* The IBM lawyers misread another document! */ | ||
2887 | case -NFS4ERR_DELAY: | ||
2888 | err = nfs4_delay(clp->cl_rpcclient, &timeout); | ||
2889 | } | ||
2890 | } while (err == 0); | ||
2891 | return err; | ||
2875 | } | 2892 | } |
2876 | 2893 | ||
2877 | struct nfs4_delegreturndata { | 2894 | struct nfs4_delegreturndata { |
2878 | struct nfs4_delegreturnargs args; | 2895 | struct nfs4_delegreturnargs args; |
2879 | struct nfs4_delegreturnres res; | 2896 | struct nfs4_delegreturnres res; |
2880 | struct nfs_fh fh; | 2897 | struct nfs_fh fh; |
2881 | nfs4_stateid stateid; | 2898 | nfs4_stateid stateid; |
2882 | struct rpc_cred *cred; | 2899 | struct rpc_cred *cred; |
2883 | unsigned long timestamp; | 2900 | unsigned long timestamp; |
2884 | struct nfs_fattr fattr; | 2901 | struct nfs_fattr fattr; |
2885 | int rpc_status; | 2902 | int rpc_status; |
2886 | }; | 2903 | }; |
2887 | 2904 | ||
2888 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *calldata) | 2905 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *calldata) |
2889 | { | 2906 | { |
2890 | struct nfs4_delegreturndata *data = calldata; | 2907 | struct nfs4_delegreturndata *data = calldata; |
2891 | struct rpc_message msg = { | 2908 | struct rpc_message msg = { |
2892 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], | 2909 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
2893 | .rpc_argp = &data->args, | 2910 | .rpc_argp = &data->args, |
2894 | .rpc_resp = &data->res, | 2911 | .rpc_resp = &data->res, |
2895 | .rpc_cred = data->cred, | 2912 | .rpc_cred = data->cred, |
2896 | }; | 2913 | }; |
2897 | nfs_fattr_init(data->res.fattr); | 2914 | nfs_fattr_init(data->res.fattr); |
2898 | rpc_call_setup(task, &msg, 0); | 2915 | rpc_call_setup(task, &msg, 0); |
2899 | } | 2916 | } |
2900 | 2917 | ||
2901 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) | 2918 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
2902 | { | 2919 | { |
2903 | struct nfs4_delegreturndata *data = calldata; | 2920 | struct nfs4_delegreturndata *data = calldata; |
2904 | data->rpc_status = task->tk_status; | 2921 | data->rpc_status = task->tk_status; |
2905 | if (data->rpc_status == 0) | 2922 | if (data->rpc_status == 0) |
2906 | renew_lease(data->res.server, data->timestamp); | 2923 | renew_lease(data->res.server, data->timestamp); |
2907 | } | 2924 | } |
2908 | 2925 | ||
2909 | static void nfs4_delegreturn_release(void *calldata) | 2926 | static void nfs4_delegreturn_release(void *calldata) |
2910 | { | 2927 | { |
2911 | struct nfs4_delegreturndata *data = calldata; | 2928 | struct nfs4_delegreturndata *data = calldata; |
2912 | 2929 | ||
2913 | put_rpccred(data->cred); | 2930 | put_rpccred(data->cred); |
2914 | kfree(calldata); | 2931 | kfree(calldata); |
2915 | } | 2932 | } |
2916 | 2933 | ||
2917 | static const struct rpc_call_ops nfs4_delegreturn_ops = { | 2934 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
2918 | .rpc_call_prepare = nfs4_delegreturn_prepare, | 2935 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
2919 | .rpc_call_done = nfs4_delegreturn_done, | 2936 | .rpc_call_done = nfs4_delegreturn_done, |
2920 | .rpc_release = nfs4_delegreturn_release, | 2937 | .rpc_release = nfs4_delegreturn_release, |
2921 | }; | 2938 | }; |
2922 | 2939 | ||
2923 | static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid) | 2940 | static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid) |
2924 | { | 2941 | { |
2925 | struct nfs4_delegreturndata *data; | 2942 | struct nfs4_delegreturndata *data; |
2926 | struct nfs_server *server = NFS_SERVER(inode); | 2943 | struct nfs_server *server = NFS_SERVER(inode); |
2927 | struct rpc_task *task; | 2944 | struct rpc_task *task; |
2928 | int status; | 2945 | int status; |
2929 | 2946 | ||
2930 | data = kmalloc(sizeof(*data), GFP_KERNEL); | 2947 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
2931 | if (data == NULL) | 2948 | if (data == NULL) |
2932 | return -ENOMEM; | 2949 | return -ENOMEM; |
2933 | data->args.fhandle = &data->fh; | 2950 | data->args.fhandle = &data->fh; |
2934 | data->args.stateid = &data->stateid; | 2951 | data->args.stateid = &data->stateid; |
2935 | data->args.bitmask = server->attr_bitmask; | 2952 | data->args.bitmask = server->attr_bitmask; |
2936 | nfs_copy_fh(&data->fh, NFS_FH(inode)); | 2953 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
2937 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); | 2954 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
2938 | data->res.fattr = &data->fattr; | 2955 | data->res.fattr = &data->fattr; |
2939 | data->res.server = server; | 2956 | data->res.server = server; |
2940 | data->cred = get_rpccred(cred); | 2957 | data->cred = get_rpccred(cred); |
2941 | data->timestamp = jiffies; | 2958 | data->timestamp = jiffies; |
2942 | data->rpc_status = 0; | 2959 | data->rpc_status = 0; |
2943 | 2960 | ||
2944 | task = rpc_run_task(NFS_CLIENT(inode), RPC_TASK_ASYNC, &nfs4_delegreturn_ops, data); | 2961 | task = rpc_run_task(NFS_CLIENT(inode), RPC_TASK_ASYNC, &nfs4_delegreturn_ops, data); |
2945 | if (IS_ERR(task)) { | 2962 | if (IS_ERR(task)) { |
2946 | nfs4_delegreturn_release(data); | 2963 | nfs4_delegreturn_release(data); |
2947 | return PTR_ERR(task); | 2964 | return PTR_ERR(task); |
2948 | } | 2965 | } |
2949 | status = nfs4_wait_for_completion_rpc_task(task); | 2966 | status = nfs4_wait_for_completion_rpc_task(task); |
2950 | if (status == 0) { | 2967 | if (status == 0) { |
2951 | status = data->rpc_status; | 2968 | status = data->rpc_status; |
2952 | if (status == 0) | 2969 | if (status == 0) |
2953 | nfs_post_op_update_inode(inode, &data->fattr); | 2970 | nfs_post_op_update_inode(inode, &data->fattr); |
2954 | } | 2971 | } |
2955 | rpc_release_task(task); | 2972 | rpc_release_task(task); |
2956 | return status; | 2973 | return status; |
2957 | } | 2974 | } |
2958 | 2975 | ||
2959 | int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid) | 2976 | int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid) |
2960 | { | 2977 | { |
2961 | struct nfs_server *server = NFS_SERVER(inode); | 2978 | struct nfs_server *server = NFS_SERVER(inode); |
2962 | struct nfs4_exception exception = { }; | 2979 | struct nfs4_exception exception = { }; |
2963 | int err; | 2980 | int err; |
2964 | do { | 2981 | do { |
2965 | err = _nfs4_proc_delegreturn(inode, cred, stateid); | 2982 | err = _nfs4_proc_delegreturn(inode, cred, stateid); |
2966 | switch (err) { | 2983 | switch (err) { |
2967 | case -NFS4ERR_STALE_STATEID: | 2984 | case -NFS4ERR_STALE_STATEID: |
2968 | case -NFS4ERR_EXPIRED: | 2985 | case -NFS4ERR_EXPIRED: |
2969 | nfs4_schedule_state_recovery(server->nfs4_state); | 2986 | nfs4_schedule_state_recovery(server->nfs4_state); |
2970 | case 0: | 2987 | case 0: |
2971 | return 0; | 2988 | return 0; |
2972 | } | 2989 | } |
2973 | err = nfs4_handle_exception(server, err, &exception); | 2990 | err = nfs4_handle_exception(server, err, &exception); |
2974 | } while (exception.retry); | 2991 | } while (exception.retry); |
2975 | return err; | 2992 | return err; |
2976 | } | 2993 | } |
2977 | 2994 | ||
2978 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) | 2995 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
2979 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) | 2996 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
2980 | 2997 | ||
2981 | /* | 2998 | /* |
2982 | * sleep, with exponential backoff, and retry the LOCK operation. | 2999 | * sleep, with exponential backoff, and retry the LOCK operation. |
2983 | */ | 3000 | */ |
2984 | static unsigned long | 3001 | static unsigned long |
2985 | nfs4_set_lock_task_retry(unsigned long timeout) | 3002 | nfs4_set_lock_task_retry(unsigned long timeout) |
2986 | { | 3003 | { |
2987 | schedule_timeout_interruptible(timeout); | 3004 | schedule_timeout_interruptible(timeout); |
2988 | timeout <<= 1; | 3005 | timeout <<= 1; |
2989 | if (timeout > NFS4_LOCK_MAXTIMEOUT) | 3006 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
2990 | return NFS4_LOCK_MAXTIMEOUT; | 3007 | return NFS4_LOCK_MAXTIMEOUT; |
2991 | return timeout; | 3008 | return timeout; |
2992 | } | 3009 | } |
2993 | 3010 | ||
2994 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 3011 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
2995 | { | 3012 | { |
2996 | struct inode *inode = state->inode; | 3013 | struct inode *inode = state->inode; |
2997 | struct nfs_server *server = NFS_SERVER(inode); | 3014 | struct nfs_server *server = NFS_SERVER(inode); |
2998 | struct nfs4_client *clp = server->nfs4_state; | 3015 | struct nfs4_client *clp = server->nfs4_state; |
2999 | struct nfs_lockt_args arg = { | 3016 | struct nfs_lockt_args arg = { |
3000 | .fh = NFS_FH(inode), | 3017 | .fh = NFS_FH(inode), |
3001 | .fl = request, | 3018 | .fl = request, |
3002 | }; | 3019 | }; |
3003 | struct nfs_lockt_res res = { | 3020 | struct nfs_lockt_res res = { |
3004 | .denied = request, | 3021 | .denied = request, |
3005 | }; | 3022 | }; |
3006 | struct rpc_message msg = { | 3023 | struct rpc_message msg = { |
3007 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], | 3024 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
3008 | .rpc_argp = &arg, | 3025 | .rpc_argp = &arg, |
3009 | .rpc_resp = &res, | 3026 | .rpc_resp = &res, |
3010 | .rpc_cred = state->owner->so_cred, | 3027 | .rpc_cred = state->owner->so_cred, |
3011 | }; | 3028 | }; |
3012 | struct nfs4_lock_state *lsp; | 3029 | struct nfs4_lock_state *lsp; |
3013 | int status; | 3030 | int status; |
3014 | 3031 | ||
3015 | down_read(&clp->cl_sem); | 3032 | down_read(&clp->cl_sem); |
3016 | arg.lock_owner.clientid = clp->cl_clientid; | 3033 | arg.lock_owner.clientid = clp->cl_clientid; |
3017 | status = nfs4_set_lock_state(state, request); | 3034 | status = nfs4_set_lock_state(state, request); |
3018 | if (status != 0) | 3035 | if (status != 0) |
3019 | goto out; | 3036 | goto out; |
3020 | lsp = request->fl_u.nfs4_fl.owner; | 3037 | lsp = request->fl_u.nfs4_fl.owner; |
3021 | arg.lock_owner.id = lsp->ls_id; | 3038 | arg.lock_owner.id = lsp->ls_id; |
3022 | status = rpc_call_sync(server->client, &msg, 0); | 3039 | status = rpc_call_sync(server->client, &msg, 0); |
3023 | switch (status) { | 3040 | switch (status) { |
3024 | case 0: | 3041 | case 0: |
3025 | request->fl_type = F_UNLCK; | 3042 | request->fl_type = F_UNLCK; |
3026 | break; | 3043 | break; |
3027 | case -NFS4ERR_DENIED: | 3044 | case -NFS4ERR_DENIED: |
3028 | status = 0; | 3045 | status = 0; |
3029 | } | 3046 | } |
3030 | out: | 3047 | out: |
3031 | up_read(&clp->cl_sem); | 3048 | up_read(&clp->cl_sem); |
3032 | return status; | 3049 | return status; |
3033 | } | 3050 | } |
3034 | 3051 | ||
3035 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 3052 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
3036 | { | 3053 | { |
3037 | struct nfs4_exception exception = { }; | 3054 | struct nfs4_exception exception = { }; |
3038 | int err; | 3055 | int err; |
3039 | 3056 | ||
3040 | do { | 3057 | do { |
3041 | err = nfs4_handle_exception(NFS_SERVER(state->inode), | 3058 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
3042 | _nfs4_proc_getlk(state, cmd, request), | 3059 | _nfs4_proc_getlk(state, cmd, request), |
3043 | &exception); | 3060 | &exception); |
3044 | } while (exception.retry); | 3061 | } while (exception.retry); |
3045 | return err; | 3062 | return err; |
3046 | } | 3063 | } |
3047 | 3064 | ||
3048 | static int do_vfs_lock(struct file *file, struct file_lock *fl) | 3065 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
3049 | { | 3066 | { |
3050 | int res = 0; | 3067 | int res = 0; |
3051 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { | 3068 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
3052 | case FL_POSIX: | 3069 | case FL_POSIX: |
3053 | res = posix_lock_file_wait(file, fl); | 3070 | res = posix_lock_file_wait(file, fl); |
3054 | break; | 3071 | break; |
3055 | case FL_FLOCK: | 3072 | case FL_FLOCK: |
3056 | res = flock_lock_file_wait(file, fl); | 3073 | res = flock_lock_file_wait(file, fl); |
3057 | break; | 3074 | break; |
3058 | default: | 3075 | default: |
3059 | BUG(); | 3076 | BUG(); |
3060 | } | 3077 | } |
3061 | if (res < 0) | 3078 | if (res < 0) |
3062 | printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", | 3079 | printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", |
3063 | __FUNCTION__); | 3080 | __FUNCTION__); |
3064 | return res; | 3081 | return res; |
3065 | } | 3082 | } |
3066 | 3083 | ||
3067 | struct nfs4_unlockdata { | 3084 | struct nfs4_unlockdata { |
3068 | struct nfs_locku_args arg; | 3085 | struct nfs_locku_args arg; |
3069 | struct nfs_locku_res res; | 3086 | struct nfs_locku_res res; |
3070 | struct nfs4_lock_state *lsp; | 3087 | struct nfs4_lock_state *lsp; |
3071 | struct nfs_open_context *ctx; | 3088 | struct nfs_open_context *ctx; |
3072 | struct file_lock fl; | 3089 | struct file_lock fl; |
3073 | const struct nfs_server *server; | 3090 | const struct nfs_server *server; |
3074 | unsigned long timestamp; | 3091 | unsigned long timestamp; |
3075 | }; | 3092 | }; |
3076 | 3093 | ||
3077 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, | 3094 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
3078 | struct nfs_open_context *ctx, | 3095 | struct nfs_open_context *ctx, |
3079 | struct nfs4_lock_state *lsp, | 3096 | struct nfs4_lock_state *lsp, |
3080 | struct nfs_seqid *seqid) | 3097 | struct nfs_seqid *seqid) |
3081 | { | 3098 | { |
3082 | struct nfs4_unlockdata *p; | 3099 | struct nfs4_unlockdata *p; |
3083 | struct inode *inode = lsp->ls_state->inode; | 3100 | struct inode *inode = lsp->ls_state->inode; |
3084 | 3101 | ||
3085 | p = kmalloc(sizeof(*p), GFP_KERNEL); | 3102 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
3086 | if (p == NULL) | 3103 | if (p == NULL) |
3087 | return NULL; | 3104 | return NULL; |
3088 | p->arg.fh = NFS_FH(inode); | 3105 | p->arg.fh = NFS_FH(inode); |
3089 | p->arg.fl = &p->fl; | 3106 | p->arg.fl = &p->fl; |
3090 | p->arg.seqid = seqid; | 3107 | p->arg.seqid = seqid; |
3091 | p->arg.stateid = &lsp->ls_stateid; | 3108 | p->arg.stateid = &lsp->ls_stateid; |
3092 | p->lsp = lsp; | 3109 | p->lsp = lsp; |
3093 | atomic_inc(&lsp->ls_count); | 3110 | atomic_inc(&lsp->ls_count); |
3094 | /* Ensure we don't close file until we're done freeing locks! */ | 3111 | /* Ensure we don't close file until we're done freeing locks! */ |
3095 | p->ctx = get_nfs_open_context(ctx); | 3112 | p->ctx = get_nfs_open_context(ctx); |
3096 | memcpy(&p->fl, fl, sizeof(p->fl)); | 3113 | memcpy(&p->fl, fl, sizeof(p->fl)); |
3097 | p->server = NFS_SERVER(inode); | 3114 | p->server = NFS_SERVER(inode); |
3098 | return p; | 3115 | return p; |
3099 | } | 3116 | } |
3100 | 3117 | ||
3101 | static void nfs4_locku_release_calldata(void *data) | 3118 | static void nfs4_locku_release_calldata(void *data) |
3102 | { | 3119 | { |
3103 | struct nfs4_unlockdata *calldata = data; | 3120 | struct nfs4_unlockdata *calldata = data; |
3104 | nfs_free_seqid(calldata->arg.seqid); | 3121 | nfs_free_seqid(calldata->arg.seqid); |
3105 | nfs4_put_lock_state(calldata->lsp); | 3122 | nfs4_put_lock_state(calldata->lsp); |
3106 | put_nfs_open_context(calldata->ctx); | 3123 | put_nfs_open_context(calldata->ctx); |
3107 | kfree(calldata); | 3124 | kfree(calldata); |
3108 | } | 3125 | } |
3109 | 3126 | ||
3110 | static void nfs4_locku_done(struct rpc_task *task, void *data) | 3127 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
3111 | { | 3128 | { |
3112 | struct nfs4_unlockdata *calldata = data; | 3129 | struct nfs4_unlockdata *calldata = data; |
3113 | 3130 | ||
3114 | if (RPC_ASSASSINATED(task)) | 3131 | if (RPC_ASSASSINATED(task)) |
3115 | return; | 3132 | return; |
3116 | nfs_increment_lock_seqid(task->tk_status, calldata->arg.seqid); | 3133 | nfs_increment_lock_seqid(task->tk_status, calldata->arg.seqid); |
3117 | switch (task->tk_status) { | 3134 | switch (task->tk_status) { |
3118 | case 0: | 3135 | case 0: |
3119 | memcpy(calldata->lsp->ls_stateid.data, | 3136 | memcpy(calldata->lsp->ls_stateid.data, |
3120 | calldata->res.stateid.data, | 3137 | calldata->res.stateid.data, |
3121 | sizeof(calldata->lsp->ls_stateid.data)); | 3138 | sizeof(calldata->lsp->ls_stateid.data)); |
3122 | renew_lease(calldata->server, calldata->timestamp); | 3139 | renew_lease(calldata->server, calldata->timestamp); |
3123 | break; | 3140 | break; |
3124 | case -NFS4ERR_STALE_STATEID: | 3141 | case -NFS4ERR_STALE_STATEID: |
3125 | case -NFS4ERR_EXPIRED: | 3142 | case -NFS4ERR_EXPIRED: |
3126 | nfs4_schedule_state_recovery(calldata->server->nfs4_state); | 3143 | nfs4_schedule_state_recovery(calldata->server->nfs4_state); |
3127 | break; | 3144 | break; |
3128 | default: | 3145 | default: |
3129 | if (nfs4_async_handle_error(task, calldata->server) == -EAGAIN) { | 3146 | if (nfs4_async_handle_error(task, calldata->server) == -EAGAIN) { |
3130 | rpc_restart_call(task); | 3147 | rpc_restart_call(task); |
3131 | } | 3148 | } |
3132 | } | 3149 | } |
3133 | } | 3150 | } |
3134 | 3151 | ||
3135 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) | 3152 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
3136 | { | 3153 | { |
3137 | struct nfs4_unlockdata *calldata = data; | 3154 | struct nfs4_unlockdata *calldata = data; |
3138 | struct rpc_message msg = { | 3155 | struct rpc_message msg = { |
3139 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], | 3156 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
3140 | .rpc_argp = &calldata->arg, | 3157 | .rpc_argp = &calldata->arg, |
3141 | .rpc_resp = &calldata->res, | 3158 | .rpc_resp = &calldata->res, |
3142 | .rpc_cred = calldata->lsp->ls_state->owner->so_cred, | 3159 | .rpc_cred = calldata->lsp->ls_state->owner->so_cred, |
3143 | }; | 3160 | }; |
3144 | 3161 | ||
3145 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) | 3162 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
3146 | return; | 3163 | return; |
3147 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { | 3164 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
3148 | /* Note: exit _without_ running nfs4_locku_done */ | 3165 | /* Note: exit _without_ running nfs4_locku_done */ |
3149 | task->tk_action = NULL; | 3166 | task->tk_action = NULL; |
3150 | return; | 3167 | return; |
3151 | } | 3168 | } |
3152 | calldata->timestamp = jiffies; | 3169 | calldata->timestamp = jiffies; |
3153 | rpc_call_setup(task, &msg, 0); | 3170 | rpc_call_setup(task, &msg, 0); |
3154 | } | 3171 | } |
3155 | 3172 | ||
3156 | static const struct rpc_call_ops nfs4_locku_ops = { | 3173 | static const struct rpc_call_ops nfs4_locku_ops = { |
3157 | .rpc_call_prepare = nfs4_locku_prepare, | 3174 | .rpc_call_prepare = nfs4_locku_prepare, |
3158 | .rpc_call_done = nfs4_locku_done, | 3175 | .rpc_call_done = nfs4_locku_done, |
3159 | .rpc_release = nfs4_locku_release_calldata, | 3176 | .rpc_release = nfs4_locku_release_calldata, |
3160 | }; | 3177 | }; |
3161 | 3178 | ||
3162 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, | 3179 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
3163 | struct nfs_open_context *ctx, | 3180 | struct nfs_open_context *ctx, |
3164 | struct nfs4_lock_state *lsp, | 3181 | struct nfs4_lock_state *lsp, |
3165 | struct nfs_seqid *seqid) | 3182 | struct nfs_seqid *seqid) |
3166 | { | 3183 | { |
3167 | struct nfs4_unlockdata *data; | 3184 | struct nfs4_unlockdata *data; |
3168 | struct rpc_task *task; | 3185 | struct rpc_task *task; |
3169 | 3186 | ||
3170 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); | 3187 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
3171 | if (data == NULL) { | 3188 | if (data == NULL) { |
3172 | nfs_free_seqid(seqid); | 3189 | nfs_free_seqid(seqid); |
3173 | return ERR_PTR(-ENOMEM); | 3190 | return ERR_PTR(-ENOMEM); |
3174 | } | 3191 | } |
3175 | 3192 | ||
3176 | /* Unlock _before_ we do the RPC call */ | 3193 | /* Unlock _before_ we do the RPC call */ |
3177 | do_vfs_lock(fl->fl_file, fl); | 3194 | do_vfs_lock(fl->fl_file, fl); |
3178 | task = rpc_run_task(NFS_CLIENT(lsp->ls_state->inode), RPC_TASK_ASYNC, &nfs4_locku_ops, data); | 3195 | task = rpc_run_task(NFS_CLIENT(lsp->ls_state->inode), RPC_TASK_ASYNC, &nfs4_locku_ops, data); |
3179 | if (IS_ERR(task)) | 3196 | if (IS_ERR(task)) |
3180 | nfs4_locku_release_calldata(data); | 3197 | nfs4_locku_release_calldata(data); |
3181 | return task; | 3198 | return task; |
3182 | } | 3199 | } |
3183 | 3200 | ||
3184 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) | 3201 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
3185 | { | 3202 | { |
3186 | struct nfs_seqid *seqid; | 3203 | struct nfs_seqid *seqid; |
3187 | struct nfs4_lock_state *lsp; | 3204 | struct nfs4_lock_state *lsp; |
3188 | struct rpc_task *task; | 3205 | struct rpc_task *task; |
3189 | int status = 0; | 3206 | int status = 0; |
3190 | 3207 | ||
3191 | /* Is this a delegated lock? */ | 3208 | /* Is this a delegated lock? */ |
3192 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) | 3209 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
3193 | goto out_unlock; | 3210 | goto out_unlock; |
3194 | /* Is this open_owner holding any locks on the server? */ | 3211 | /* Is this open_owner holding any locks on the server? */ |
3195 | if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) | 3212 | if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) |
3196 | goto out_unlock; | 3213 | goto out_unlock; |
3197 | 3214 | ||
3198 | status = nfs4_set_lock_state(state, request); | 3215 | status = nfs4_set_lock_state(state, request); |
3199 | if (status != 0) | 3216 | if (status != 0) |
3200 | goto out_unlock; | 3217 | goto out_unlock; |
3201 | lsp = request->fl_u.nfs4_fl.owner; | 3218 | lsp = request->fl_u.nfs4_fl.owner; |
3202 | status = -ENOMEM; | 3219 | status = -ENOMEM; |
3203 | seqid = nfs_alloc_seqid(&lsp->ls_seqid); | 3220 | seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
3204 | if (seqid == NULL) | 3221 | if (seqid == NULL) |
3205 | goto out_unlock; | 3222 | goto out_unlock; |
3206 | task = nfs4_do_unlck(request, request->fl_file->private_data, lsp, seqid); | 3223 | task = nfs4_do_unlck(request, request->fl_file->private_data, lsp, seqid); |
3207 | status = PTR_ERR(task); | 3224 | status = PTR_ERR(task); |
3208 | if (IS_ERR(task)) | 3225 | if (IS_ERR(task)) |
3209 | goto out_unlock; | 3226 | goto out_unlock; |
3210 | status = nfs4_wait_for_completion_rpc_task(task); | 3227 | status = nfs4_wait_for_completion_rpc_task(task); |
3211 | rpc_release_task(task); | 3228 | rpc_release_task(task); |
3212 | return status; | 3229 | return status; |
3213 | out_unlock: | 3230 | out_unlock: |
3214 | do_vfs_lock(request->fl_file, request); | 3231 | do_vfs_lock(request->fl_file, request); |
3215 | return status; | 3232 | return status; |
3216 | } | 3233 | } |
3217 | 3234 | ||
3218 | struct nfs4_lockdata { | 3235 | struct nfs4_lockdata { |
3219 | struct nfs_lock_args arg; | 3236 | struct nfs_lock_args arg; |
3220 | struct nfs_lock_res res; | 3237 | struct nfs_lock_res res; |
3221 | struct nfs4_lock_state *lsp; | 3238 | struct nfs4_lock_state *lsp; |
3222 | struct nfs_open_context *ctx; | 3239 | struct nfs_open_context *ctx; |
3223 | struct file_lock fl; | 3240 | struct file_lock fl; |
3224 | unsigned long timestamp; | 3241 | unsigned long timestamp; |
3225 | int rpc_status; | 3242 | int rpc_status; |
3226 | int cancelled; | 3243 | int cancelled; |
3227 | }; | 3244 | }; |
3228 | 3245 | ||
3229 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, | 3246 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
3230 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp) | 3247 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp) |
3231 | { | 3248 | { |
3232 | struct nfs4_lockdata *p; | 3249 | struct nfs4_lockdata *p; |
3233 | struct inode *inode = lsp->ls_state->inode; | 3250 | struct inode *inode = lsp->ls_state->inode; |
3234 | struct nfs_server *server = NFS_SERVER(inode); | 3251 | struct nfs_server *server = NFS_SERVER(inode); |
3235 | 3252 | ||
3236 | p = kzalloc(sizeof(*p), GFP_KERNEL); | 3253 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
3237 | if (p == NULL) | 3254 | if (p == NULL) |
3238 | return NULL; | 3255 | return NULL; |
3239 | 3256 | ||
3240 | p->arg.fh = NFS_FH(inode); | 3257 | p->arg.fh = NFS_FH(inode); |
3241 | p->arg.fl = &p->fl; | 3258 | p->arg.fl = &p->fl; |
3242 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); | 3259 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
3243 | if (p->arg.lock_seqid == NULL) | 3260 | if (p->arg.lock_seqid == NULL) |
3244 | goto out_free; | 3261 | goto out_free; |
3245 | p->arg.lock_stateid = &lsp->ls_stateid; | 3262 | p->arg.lock_stateid = &lsp->ls_stateid; |
3246 | p->arg.lock_owner.clientid = server->nfs4_state->cl_clientid; | 3263 | p->arg.lock_owner.clientid = server->nfs4_state->cl_clientid; |
3247 | p->arg.lock_owner.id = lsp->ls_id; | 3264 | p->arg.lock_owner.id = lsp->ls_id; |
3248 | p->lsp = lsp; | 3265 | p->lsp = lsp; |
3249 | atomic_inc(&lsp->ls_count); | 3266 | atomic_inc(&lsp->ls_count); |
3250 | p->ctx = get_nfs_open_context(ctx); | 3267 | p->ctx = get_nfs_open_context(ctx); |
3251 | memcpy(&p->fl, fl, sizeof(p->fl)); | 3268 | memcpy(&p->fl, fl, sizeof(p->fl)); |
3252 | return p; | 3269 | return p; |
3253 | out_free: | 3270 | out_free: |
3254 | kfree(p); | 3271 | kfree(p); |
3255 | return NULL; | 3272 | return NULL; |
3256 | } | 3273 | } |
3257 | 3274 | ||
3258 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) | 3275 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
3259 | { | 3276 | { |
3260 | struct nfs4_lockdata *data = calldata; | 3277 | struct nfs4_lockdata *data = calldata; |
3261 | struct nfs4_state *state = data->lsp->ls_state; | 3278 | struct nfs4_state *state = data->lsp->ls_state; |
3262 | struct nfs4_state_owner *sp = state->owner; | 3279 | struct nfs4_state_owner *sp = state->owner; |
3263 | struct rpc_message msg = { | 3280 | struct rpc_message msg = { |
3264 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], | 3281 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
3265 | .rpc_argp = &data->arg, | 3282 | .rpc_argp = &data->arg, |
3266 | .rpc_resp = &data->res, | 3283 | .rpc_resp = &data->res, |
3267 | .rpc_cred = sp->so_cred, | 3284 | .rpc_cred = sp->so_cred, |
3268 | }; | 3285 | }; |
3269 | 3286 | ||
3270 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) | 3287 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
3271 | return; | 3288 | return; |
3272 | dprintk("%s: begin!\n", __FUNCTION__); | 3289 | dprintk("%s: begin!\n", __FUNCTION__); |
3273 | /* Do we need to do an open_to_lock_owner? */ | 3290 | /* Do we need to do an open_to_lock_owner? */ |
3274 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { | 3291 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
3275 | data->arg.open_seqid = nfs_alloc_seqid(&sp->so_seqid); | 3292 | data->arg.open_seqid = nfs_alloc_seqid(&sp->so_seqid); |
3276 | if (data->arg.open_seqid == NULL) { | 3293 | if (data->arg.open_seqid == NULL) { |
3277 | data->rpc_status = -ENOMEM; | 3294 | data->rpc_status = -ENOMEM; |
3278 | task->tk_action = NULL; | 3295 | task->tk_action = NULL; |
3279 | goto out; | 3296 | goto out; |
3280 | } | 3297 | } |
3281 | data->arg.open_stateid = &state->stateid; | 3298 | data->arg.open_stateid = &state->stateid; |
3282 | data->arg.new_lock_owner = 1; | 3299 | data->arg.new_lock_owner = 1; |
3283 | } | 3300 | } |
3284 | data->timestamp = jiffies; | 3301 | data->timestamp = jiffies; |
3285 | rpc_call_setup(task, &msg, 0); | 3302 | rpc_call_setup(task, &msg, 0); |
3286 | out: | 3303 | out: |
3287 | dprintk("%s: done!, ret = %d\n", __FUNCTION__, data->rpc_status); | 3304 | dprintk("%s: done!, ret = %d\n", __FUNCTION__, data->rpc_status); |
3288 | } | 3305 | } |
3289 | 3306 | ||
3290 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) | 3307 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
3291 | { | 3308 | { |
3292 | struct nfs4_lockdata *data = calldata; | 3309 | struct nfs4_lockdata *data = calldata; |
3293 | 3310 | ||
3294 | dprintk("%s: begin!\n", __FUNCTION__); | 3311 | dprintk("%s: begin!\n", __FUNCTION__); |
3295 | 3312 | ||
3296 | data->rpc_status = task->tk_status; | 3313 | data->rpc_status = task->tk_status; |
3297 | if (RPC_ASSASSINATED(task)) | 3314 | if (RPC_ASSASSINATED(task)) |
3298 | goto out; | 3315 | goto out; |
3299 | if (data->arg.new_lock_owner != 0) { | 3316 | if (data->arg.new_lock_owner != 0) { |
3300 | nfs_increment_open_seqid(data->rpc_status, data->arg.open_seqid); | 3317 | nfs_increment_open_seqid(data->rpc_status, data->arg.open_seqid); |
3301 | if (data->rpc_status == 0) | 3318 | if (data->rpc_status == 0) |
3302 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); | 3319 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
3303 | else | 3320 | else |
3304 | goto out; | 3321 | goto out; |
3305 | } | 3322 | } |
3306 | if (data->rpc_status == 0) { | 3323 | if (data->rpc_status == 0) { |
3307 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, | 3324 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
3308 | sizeof(data->lsp->ls_stateid.data)); | 3325 | sizeof(data->lsp->ls_stateid.data)); |
3309 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; | 3326 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
3310 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); | 3327 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
3311 | } | 3328 | } |
3312 | nfs_increment_lock_seqid(data->rpc_status, data->arg.lock_seqid); | 3329 | nfs_increment_lock_seqid(data->rpc_status, data->arg.lock_seqid); |
3313 | out: | 3330 | out: |
3314 | dprintk("%s: done, ret = %d!\n", __FUNCTION__, data->rpc_status); | 3331 | dprintk("%s: done, ret = %d!\n", __FUNCTION__, data->rpc_status); |
3315 | } | 3332 | } |
3316 | 3333 | ||
3317 | static void nfs4_lock_release(void *calldata) | 3334 | static void nfs4_lock_release(void *calldata) |
3318 | { | 3335 | { |
3319 | struct nfs4_lockdata *data = calldata; | 3336 | struct nfs4_lockdata *data = calldata; |
3320 | 3337 | ||
3321 | dprintk("%s: begin!\n", __FUNCTION__); | 3338 | dprintk("%s: begin!\n", __FUNCTION__); |
3322 | if (data->arg.open_seqid != NULL) | 3339 | if (data->arg.open_seqid != NULL) |
3323 | nfs_free_seqid(data->arg.open_seqid); | 3340 | nfs_free_seqid(data->arg.open_seqid); |
3324 | if (data->cancelled != 0) { | 3341 | if (data->cancelled != 0) { |
3325 | struct rpc_task *task; | 3342 | struct rpc_task *task; |
3326 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, | 3343 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
3327 | data->arg.lock_seqid); | 3344 | data->arg.lock_seqid); |
3328 | if (!IS_ERR(task)) | 3345 | if (!IS_ERR(task)) |
3329 | rpc_release_task(task); | 3346 | rpc_release_task(task); |
3330 | dprintk("%s: cancelling lock!\n", __FUNCTION__); | 3347 | dprintk("%s: cancelling lock!\n", __FUNCTION__); |
3331 | } else | 3348 | } else |
3332 | nfs_free_seqid(data->arg.lock_seqid); | 3349 | nfs_free_seqid(data->arg.lock_seqid); |
3333 | nfs4_put_lock_state(data->lsp); | 3350 | nfs4_put_lock_state(data->lsp); |
3334 | put_nfs_open_context(data->ctx); | 3351 | put_nfs_open_context(data->ctx); |
3335 | kfree(data); | 3352 | kfree(data); |
3336 | dprintk("%s: done!\n", __FUNCTION__); | 3353 | dprintk("%s: done!\n", __FUNCTION__); |
3337 | } | 3354 | } |
3338 | 3355 | ||
3339 | static const struct rpc_call_ops nfs4_lock_ops = { | 3356 | static const struct rpc_call_ops nfs4_lock_ops = { |
3340 | .rpc_call_prepare = nfs4_lock_prepare, | 3357 | .rpc_call_prepare = nfs4_lock_prepare, |
3341 | .rpc_call_done = nfs4_lock_done, | 3358 | .rpc_call_done = nfs4_lock_done, |
3342 | .rpc_release = nfs4_lock_release, | 3359 | .rpc_release = nfs4_lock_release, |
3343 | }; | 3360 | }; |
3344 | 3361 | ||
3345 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int reclaim) | 3362 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int reclaim) |
3346 | { | 3363 | { |
3347 | struct nfs4_lockdata *data; | 3364 | struct nfs4_lockdata *data; |
3348 | struct rpc_task *task; | 3365 | struct rpc_task *task; |
3349 | int ret; | 3366 | int ret; |
3350 | 3367 | ||
3351 | dprintk("%s: begin!\n", __FUNCTION__); | 3368 | dprintk("%s: begin!\n", __FUNCTION__); |
3352 | data = nfs4_alloc_lockdata(fl, fl->fl_file->private_data, | 3369 | data = nfs4_alloc_lockdata(fl, fl->fl_file->private_data, |
3353 | fl->fl_u.nfs4_fl.owner); | 3370 | fl->fl_u.nfs4_fl.owner); |
3354 | if (data == NULL) | 3371 | if (data == NULL) |
3355 | return -ENOMEM; | 3372 | return -ENOMEM; |
3356 | if (IS_SETLKW(cmd)) | 3373 | if (IS_SETLKW(cmd)) |
3357 | data->arg.block = 1; | 3374 | data->arg.block = 1; |
3358 | if (reclaim != 0) | 3375 | if (reclaim != 0) |
3359 | data->arg.reclaim = 1; | 3376 | data->arg.reclaim = 1; |
3360 | task = rpc_run_task(NFS_CLIENT(state->inode), RPC_TASK_ASYNC, | 3377 | task = rpc_run_task(NFS_CLIENT(state->inode), RPC_TASK_ASYNC, |
3361 | &nfs4_lock_ops, data); | 3378 | &nfs4_lock_ops, data); |
3362 | if (IS_ERR(task)) { | 3379 | if (IS_ERR(task)) { |
3363 | nfs4_lock_release(data); | 3380 | nfs4_lock_release(data); |
3364 | return PTR_ERR(task); | 3381 | return PTR_ERR(task); |
3365 | } | 3382 | } |
3366 | ret = nfs4_wait_for_completion_rpc_task(task); | 3383 | ret = nfs4_wait_for_completion_rpc_task(task); |
3367 | if (ret == 0) { | 3384 | if (ret == 0) { |
3368 | ret = data->rpc_status; | 3385 | ret = data->rpc_status; |
3369 | if (ret == -NFS4ERR_DENIED) | 3386 | if (ret == -NFS4ERR_DENIED) |
3370 | ret = -EAGAIN; | 3387 | ret = -EAGAIN; |
3371 | } else | 3388 | } else |
3372 | data->cancelled = 1; | 3389 | data->cancelled = 1; |
3373 | rpc_release_task(task); | 3390 | rpc_release_task(task); |
3374 | dprintk("%s: done, ret = %d!\n", __FUNCTION__, ret); | 3391 | dprintk("%s: done, ret = %d!\n", __FUNCTION__, ret); |
3375 | return ret; | 3392 | return ret; |
3376 | } | 3393 | } |
3377 | 3394 | ||
3378 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) | 3395 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
3379 | { | 3396 | { |
3380 | struct nfs_server *server = NFS_SERVER(state->inode); | 3397 | struct nfs_server *server = NFS_SERVER(state->inode); |
3381 | struct nfs4_exception exception = { }; | 3398 | struct nfs4_exception exception = { }; |
3382 | int err; | 3399 | int err; |
3383 | 3400 | ||
3384 | /* Cache the lock if possible... */ | 3401 | /* Cache the lock if possible... */ |
3385 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) | 3402 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
3386 | return 0; | 3403 | return 0; |
3387 | do { | 3404 | do { |
3388 | err = _nfs4_do_setlk(state, F_SETLK, request, 1); | 3405 | err = _nfs4_do_setlk(state, F_SETLK, request, 1); |
3389 | if (err != -NFS4ERR_DELAY) | 3406 | if (err != -NFS4ERR_DELAY) |
3390 | break; | 3407 | break; |
3391 | nfs4_handle_exception(server, err, &exception); | 3408 | nfs4_handle_exception(server, err, &exception); |
3392 | } while (exception.retry); | 3409 | } while (exception.retry); |
3393 | return err; | 3410 | return err; |
3394 | } | 3411 | } |
3395 | 3412 | ||
3396 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) | 3413 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
3397 | { | 3414 | { |
3398 | struct nfs_server *server = NFS_SERVER(state->inode); | 3415 | struct nfs_server *server = NFS_SERVER(state->inode); |
3399 | struct nfs4_exception exception = { }; | 3416 | struct nfs4_exception exception = { }; |
3400 | int err; | 3417 | int err; |
3401 | 3418 | ||
3402 | err = nfs4_set_lock_state(state, request); | 3419 | err = nfs4_set_lock_state(state, request); |
3403 | if (err != 0) | 3420 | if (err != 0) |
3404 | return err; | 3421 | return err; |
3405 | do { | 3422 | do { |
3406 | err = _nfs4_do_setlk(state, F_SETLK, request, 0); | 3423 | err = _nfs4_do_setlk(state, F_SETLK, request, 0); |
3407 | if (err != -NFS4ERR_DELAY) | 3424 | if (err != -NFS4ERR_DELAY) |
3408 | break; | 3425 | break; |
3409 | nfs4_handle_exception(server, err, &exception); | 3426 | nfs4_handle_exception(server, err, &exception); |
3410 | } while (exception.retry); | 3427 | } while (exception.retry); |
3411 | return err; | 3428 | return err; |
3412 | } | 3429 | } |
3413 | 3430 | ||
3414 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 3431 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
3415 | { | 3432 | { |
3416 | struct nfs4_client *clp = state->owner->so_client; | 3433 | struct nfs4_client *clp = state->owner->so_client; |
3417 | int status; | 3434 | int status; |
3418 | 3435 | ||
3419 | /* Is this a delegated open? */ | 3436 | /* Is this a delegated open? */ |
3420 | if (NFS_I(state->inode)->delegation_state != 0) { | 3437 | if (NFS_I(state->inode)->delegation_state != 0) { |
3421 | /* Yes: cache locks! */ | 3438 | /* Yes: cache locks! */ |
3422 | status = do_vfs_lock(request->fl_file, request); | 3439 | status = do_vfs_lock(request->fl_file, request); |
3423 | /* ...but avoid races with delegation recall... */ | 3440 | /* ...but avoid races with delegation recall... */ |
3424 | if (status < 0 || test_bit(NFS_DELEGATED_STATE, &state->flags)) | 3441 | if (status < 0 || test_bit(NFS_DELEGATED_STATE, &state->flags)) |
3425 | return status; | 3442 | return status; |
3426 | } | 3443 | } |
3427 | down_read(&clp->cl_sem); | 3444 | down_read(&clp->cl_sem); |
3428 | status = nfs4_set_lock_state(state, request); | 3445 | status = nfs4_set_lock_state(state, request); |
3429 | if (status != 0) | 3446 | if (status != 0) |
3430 | goto out; | 3447 | goto out; |
3431 | status = _nfs4_do_setlk(state, cmd, request, 0); | 3448 | status = _nfs4_do_setlk(state, cmd, request, 0); |
3432 | if (status != 0) | 3449 | if (status != 0) |
3433 | goto out; | 3450 | goto out; |
3434 | /* Note: we always want to sleep here! */ | 3451 | /* Note: we always want to sleep here! */ |
3435 | request->fl_flags |= FL_SLEEP; | 3452 | request->fl_flags |= FL_SLEEP; |
3436 | if (do_vfs_lock(request->fl_file, request) < 0) | 3453 | if (do_vfs_lock(request->fl_file, request) < 0) |
3437 | printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__); | 3454 | printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__); |
3438 | out: | 3455 | out: |
3439 | up_read(&clp->cl_sem); | 3456 | up_read(&clp->cl_sem); |
3440 | return status; | 3457 | return status; |
3441 | } | 3458 | } |
3442 | 3459 | ||
3443 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 3460 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
3444 | { | 3461 | { |
3445 | struct nfs4_exception exception = { }; | 3462 | struct nfs4_exception exception = { }; |
3446 | int err; | 3463 | int err; |
3447 | 3464 | ||
3448 | do { | 3465 | do { |
3449 | err = nfs4_handle_exception(NFS_SERVER(state->inode), | 3466 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
3450 | _nfs4_proc_setlk(state, cmd, request), | 3467 | _nfs4_proc_setlk(state, cmd, request), |
3451 | &exception); | 3468 | &exception); |
3452 | } while (exception.retry); | 3469 | } while (exception.retry); |
3453 | return err; | 3470 | return err; |
3454 | } | 3471 | } |
3455 | 3472 | ||
3456 | static int | 3473 | static int |
3457 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) | 3474 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
3458 | { | 3475 | { |
3459 | struct nfs_open_context *ctx; | 3476 | struct nfs_open_context *ctx; |
3460 | struct nfs4_state *state; | 3477 | struct nfs4_state *state; |
3461 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; | 3478 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
3462 | int status; | 3479 | int status; |
3463 | 3480 | ||
3464 | /* verify open state */ | 3481 | /* verify open state */ |
3465 | ctx = (struct nfs_open_context *)filp->private_data; | 3482 | ctx = (struct nfs_open_context *)filp->private_data; |
3466 | state = ctx->state; | 3483 | state = ctx->state; |
3467 | 3484 | ||
3468 | if (request->fl_start < 0 || request->fl_end < 0) | 3485 | if (request->fl_start < 0 || request->fl_end < 0) |
3469 | return -EINVAL; | 3486 | return -EINVAL; |
3470 | 3487 | ||
3471 | if (IS_GETLK(cmd)) | 3488 | if (IS_GETLK(cmd)) |
3472 | return nfs4_proc_getlk(state, F_GETLK, request); | 3489 | return nfs4_proc_getlk(state, F_GETLK, request); |
3473 | 3490 | ||
3474 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) | 3491 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
3475 | return -EINVAL; | 3492 | return -EINVAL; |
3476 | 3493 | ||
3477 | if (request->fl_type == F_UNLCK) | 3494 | if (request->fl_type == F_UNLCK) |
3478 | return nfs4_proc_unlck(state, cmd, request); | 3495 | return nfs4_proc_unlck(state, cmd, request); |
3479 | 3496 | ||
3480 | do { | 3497 | do { |
3481 | status = nfs4_proc_setlk(state, cmd, request); | 3498 | status = nfs4_proc_setlk(state, cmd, request); |
3482 | if ((status != -EAGAIN) || IS_SETLK(cmd)) | 3499 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
3483 | break; | 3500 | break; |
3484 | timeout = nfs4_set_lock_task_retry(timeout); | 3501 | timeout = nfs4_set_lock_task_retry(timeout); |
3485 | status = -ERESTARTSYS; | 3502 | status = -ERESTARTSYS; |
3486 | if (signalled()) | 3503 | if (signalled()) |
3487 | break; | 3504 | break; |
3488 | } while(status < 0); | 3505 | } while(status < 0); |
3489 | return status; | 3506 | return status; |
3490 | } | 3507 | } |
3491 | 3508 | ||
3492 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) | 3509 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
3493 | { | 3510 | { |
3494 | struct nfs_server *server = NFS_SERVER(state->inode); | 3511 | struct nfs_server *server = NFS_SERVER(state->inode); |
3495 | struct nfs4_exception exception = { }; | 3512 | struct nfs4_exception exception = { }; |
3496 | int err; | 3513 | int err; |
3497 | 3514 | ||
3498 | err = nfs4_set_lock_state(state, fl); | 3515 | err = nfs4_set_lock_state(state, fl); |
3499 | if (err != 0) | 3516 | if (err != 0) |
3500 | goto out; | 3517 | goto out; |
3501 | do { | 3518 | do { |
3502 | err = _nfs4_do_setlk(state, F_SETLK, fl, 0); | 3519 | err = _nfs4_do_setlk(state, F_SETLK, fl, 0); |
3503 | if (err != -NFS4ERR_DELAY) | 3520 | if (err != -NFS4ERR_DELAY) |
3504 | break; | 3521 | break; |
3505 | err = nfs4_handle_exception(server, err, &exception); | 3522 | err = nfs4_handle_exception(server, err, &exception); |
3506 | } while (exception.retry); | 3523 | } while (exception.retry); |
3507 | out: | 3524 | out: |
3508 | return err; | 3525 | return err; |
3509 | } | 3526 | } |
3510 | 3527 | ||
3511 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" | 3528 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
3512 | 3529 | ||
3513 | int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf, | 3530 | int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf, |
3514 | size_t buflen, int flags) | 3531 | size_t buflen, int flags) |
3515 | { | 3532 | { |
3516 | struct inode *inode = dentry->d_inode; | 3533 | struct inode *inode = dentry->d_inode; |
3517 | 3534 | ||
3518 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) | 3535 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
3519 | return -EOPNOTSUPP; | 3536 | return -EOPNOTSUPP; |
3520 | 3537 | ||
3521 | if (!S_ISREG(inode->i_mode) && | 3538 | if (!S_ISREG(inode->i_mode) && |
3522 | (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX)) | 3539 | (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX)) |
3523 | return -EPERM; | 3540 | return -EPERM; |
3524 | 3541 | ||
3525 | return nfs4_proc_set_acl(inode, buf, buflen); | 3542 | return nfs4_proc_set_acl(inode, buf, buflen); |
3526 | } | 3543 | } |
3527 | 3544 | ||
3528 | /* The getxattr man page suggests returning -ENODATA for unknown attributes, | 3545 | /* The getxattr man page suggests returning -ENODATA for unknown attributes, |
3529 | * and that's what we'll do for e.g. user attributes that haven't been set. | 3546 | * and that's what we'll do for e.g. user attributes that haven't been set. |
3530 | * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported | 3547 | * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported |
3531 | * attributes in kernel-managed attribute namespaces. */ | 3548 | * attributes in kernel-managed attribute namespaces. */ |
3532 | ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf, | 3549 | ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf, |
3533 | size_t buflen) | 3550 | size_t buflen) |
3534 | { | 3551 | { |
3535 | struct inode *inode = dentry->d_inode; | 3552 | struct inode *inode = dentry->d_inode; |
3536 | 3553 | ||
3537 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) | 3554 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
3538 | return -EOPNOTSUPP; | 3555 | return -EOPNOTSUPP; |
3539 | 3556 | ||
3540 | return nfs4_proc_get_acl(inode, buf, buflen); | 3557 | return nfs4_proc_get_acl(inode, buf, buflen); |
3541 | } | 3558 | } |
3542 | 3559 | ||
3543 | ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen) | 3560 | ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen) |
3544 | { | 3561 | { |
3545 | size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1; | 3562 | size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1; |
3546 | 3563 | ||
3547 | if (buf && buflen < len) | 3564 | if (buf && buflen < len) |
3548 | return -ERANGE; | 3565 | return -ERANGE; |
3549 | if (buf) | 3566 | if (buf) |
3550 | memcpy(buf, XATTR_NAME_NFSV4_ACL, len); | 3567 | memcpy(buf, XATTR_NAME_NFSV4_ACL, len); |
3551 | return len; | 3568 | return len; |
3552 | } | 3569 | } |
3553 | 3570 | ||
3554 | struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = { | 3571 | struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = { |
3555 | .recover_open = nfs4_open_reclaim, | 3572 | .recover_open = nfs4_open_reclaim, |
3556 | .recover_lock = nfs4_lock_reclaim, | 3573 | .recover_lock = nfs4_lock_reclaim, |
3557 | }; | 3574 | }; |
3558 | 3575 | ||
3559 | struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops = { | 3576 | struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops = { |
3560 | .recover_open = nfs4_open_expired, | 3577 | .recover_open = nfs4_open_expired, |
3561 | .recover_lock = nfs4_lock_expired, | 3578 | .recover_lock = nfs4_lock_expired, |
3562 | }; | 3579 | }; |
3563 | 3580 | ||
3564 | static struct inode_operations nfs4_file_inode_operations = { | 3581 | static struct inode_operations nfs4_file_inode_operations = { |
3565 | .permission = nfs_permission, | 3582 | .permission = nfs_permission, |
3566 | .getattr = nfs_getattr, | 3583 | .getattr = nfs_getattr, |
3567 | .setattr = nfs_setattr, | 3584 | .setattr = nfs_setattr, |
3568 | .getxattr = nfs4_getxattr, | 3585 | .getxattr = nfs4_getxattr, |
3569 | .setxattr = nfs4_setxattr, | 3586 | .setxattr = nfs4_setxattr, |
3570 | .listxattr = nfs4_listxattr, | 3587 | .listxattr = nfs4_listxattr, |
3571 | }; | 3588 | }; |
3572 | 3589 | ||
3573 | struct nfs_rpc_ops nfs_v4_clientops = { | 3590 | struct nfs_rpc_ops nfs_v4_clientops = { |
3574 | .version = 4, /* protocol version */ | 3591 | .version = 4, /* protocol version */ |
3575 | .dentry_ops = &nfs4_dentry_operations, | 3592 | .dentry_ops = &nfs4_dentry_operations, |
3576 | .dir_inode_ops = &nfs4_dir_inode_operations, | 3593 | .dir_inode_ops = &nfs4_dir_inode_operations, |
3577 | .file_inode_ops = &nfs4_file_inode_operations, | 3594 | .file_inode_ops = &nfs4_file_inode_operations, |
3578 | .getroot = nfs4_proc_get_root, | 3595 | .getroot = nfs4_proc_get_root, |
3579 | .getattr = nfs4_proc_getattr, | 3596 | .getattr = nfs4_proc_getattr, |
3580 | .setattr = nfs4_proc_setattr, | 3597 | .setattr = nfs4_proc_setattr, |
3581 | .lookup = nfs4_proc_lookup, | 3598 | .lookup = nfs4_proc_lookup, |
3582 | .access = nfs4_proc_access, | 3599 | .access = nfs4_proc_access, |
3583 | .readlink = nfs4_proc_readlink, | 3600 | .readlink = nfs4_proc_readlink, |
3584 | .read = nfs4_proc_read, | 3601 | .read = nfs4_proc_read, |
3585 | .write = nfs4_proc_write, | 3602 | .write = nfs4_proc_write, |
3586 | .commit = nfs4_proc_commit, | 3603 | .commit = nfs4_proc_commit, |
3587 | .create = nfs4_proc_create, | 3604 | .create = nfs4_proc_create, |
3588 | .remove = nfs4_proc_remove, | 3605 | .remove = nfs4_proc_remove, |
3589 | .unlink_setup = nfs4_proc_unlink_setup, | 3606 | .unlink_setup = nfs4_proc_unlink_setup, |
3590 | .unlink_done = nfs4_proc_unlink_done, | 3607 | .unlink_done = nfs4_proc_unlink_done, |
3591 | .rename = nfs4_proc_rename, | 3608 | .rename = nfs4_proc_rename, |
3592 | .link = nfs4_proc_link, | 3609 | .link = nfs4_proc_link, |
3593 | .symlink = nfs4_proc_symlink, | 3610 | .symlink = nfs4_proc_symlink, |
3594 | .mkdir = nfs4_proc_mkdir, | 3611 | .mkdir = nfs4_proc_mkdir, |
3595 | .rmdir = nfs4_proc_remove, | 3612 | .rmdir = nfs4_proc_remove, |
3596 | .readdir = nfs4_proc_readdir, | 3613 | .readdir = nfs4_proc_readdir, |
3597 | .mknod = nfs4_proc_mknod, | 3614 | .mknod = nfs4_proc_mknod, |
3598 | .statfs = nfs4_proc_statfs, | 3615 | .statfs = nfs4_proc_statfs, |
3599 | .fsinfo = nfs4_proc_fsinfo, | 3616 | .fsinfo = nfs4_proc_fsinfo, |
3600 | .pathconf = nfs4_proc_pathconf, | 3617 | .pathconf = nfs4_proc_pathconf, |
3601 | .decode_dirent = nfs4_decode_dirent, | 3618 | .decode_dirent = nfs4_decode_dirent, |
3602 | .read_setup = nfs4_proc_read_setup, | 3619 | .read_setup = nfs4_proc_read_setup, |
3603 | .read_done = nfs4_read_done, | 3620 | .read_done = nfs4_read_done, |
3604 | .write_setup = nfs4_proc_write_setup, | 3621 | .write_setup = nfs4_proc_write_setup, |
3605 | .write_done = nfs4_write_done, | 3622 | .write_done = nfs4_write_done, |
3606 | .commit_setup = nfs4_proc_commit_setup, | 3623 | .commit_setup = nfs4_proc_commit_setup, |
3607 | .commit_done = nfs4_commit_done, | 3624 | .commit_done = nfs4_commit_done, |
3608 | .file_open = nfs_open, | 3625 | .file_open = nfs_open, |
3609 | .file_release = nfs_release, | 3626 | .file_release = nfs_release, |
3610 | .lock = nfs4_proc_lock, | 3627 | .lock = nfs4_proc_lock, |
3611 | .clear_acl_cache = nfs4_zap_acl_attr, | 3628 | .clear_acl_cache = nfs4_zap_acl_attr, |
3612 | }; | 3629 | }; |
3613 | 3630 | ||
3614 | /* | 3631 | /* |
3615 | * Local variables: | 3632 | * Local variables: |
3616 | * c-basic-offset: 8 | 3633 | * c-basic-offset: 8 |
3617 | * End: | 3634 | * End: |
3618 | */ | 3635 | */ |
fs/nfs/nfs4state.c
1 | /* | 1 | /* |
2 | * fs/nfs/nfs4state.c | 2 | * fs/nfs/nfs4state.c |
3 | * | 3 | * |
4 | * Client-side XDR for NFSv4. | 4 | * Client-side XDR for NFSv4. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 The Regents of the University of Michigan. | 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
7 | * All rights reserved. | 7 | * All rights reserved. |
8 | * | 8 | * |
9 | * Kendrick Smith <kmsmith@umich.edu> | 9 | * Kendrick Smith <kmsmith@umich.edu> |
10 | * | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | 13 | * are met: |
14 | * | 14 | * |
15 | * 1. Redistributions of source code must retain the above copyright | 15 | * 1. Redistributions of source code must retain the above copyright |
16 | * notice, this list of conditions and the following disclaimer. | 16 | * notice, this list of conditions and the following disclaimer. |
17 | * 2. Redistributions in binary form must reproduce the above copyright | 17 | * 2. Redistributions in binary form must reproduce the above copyright |
18 | * notice, this list of conditions and the following disclaimer in the | 18 | * notice, this list of conditions and the following disclaimer in the |
19 | * documentation and/or other materials provided with the distribution. | 19 | * documentation and/or other materials provided with the distribution. |
20 | * 3. Neither the name of the University nor the names of its | 20 | * 3. Neither the name of the University nor the names of its |
21 | * contributors may be used to endorse or promote products derived | 21 | * contributors may be used to endorse or promote products derived |
22 | * from this software without specific prior written permission. | 22 | * from this software without specific prior written permission. |
23 | * | 23 | * |
24 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | 24 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
25 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 25 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
27 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 27 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
31 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 31 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
35 | * | 35 | * |
36 | * Implementation of the NFSv4 state model. For the time being, | 36 | * Implementation of the NFSv4 state model. For the time being, |
37 | * this is minimal, but will be made much more complex in a | 37 | * this is minimal, but will be made much more complex in a |
38 | * subsequent patch. | 38 | * subsequent patch. |
39 | */ | 39 | */ |
40 | 40 | ||
41 | #include <linux/config.h> | 41 | #include <linux/config.h> |
42 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
43 | #include <linux/smp_lock.h> | 43 | #include <linux/smp_lock.h> |
44 | #include <linux/nfs_fs.h> | 44 | #include <linux/nfs_fs.h> |
45 | #include <linux/nfs_idmap.h> | 45 | #include <linux/nfs_idmap.h> |
46 | #include <linux/kthread.h> | 46 | #include <linux/kthread.h> |
47 | #include <linux/module.h> | 47 | #include <linux/module.h> |
48 | #include <linux/workqueue.h> | 48 | #include <linux/workqueue.h> |
49 | #include <linux/bitops.h> | 49 | #include <linux/bitops.h> |
50 | 50 | ||
51 | #include "nfs4_fs.h" | 51 | #include "nfs4_fs.h" |
52 | #include "callback.h" | 52 | #include "callback.h" |
53 | #include "delegation.h" | 53 | #include "delegation.h" |
54 | 54 | ||
55 | #define OPENOWNER_POOL_SIZE 8 | 55 | #define OPENOWNER_POOL_SIZE 8 |
56 | 56 | ||
57 | const nfs4_stateid zero_stateid; | 57 | const nfs4_stateid zero_stateid; |
58 | 58 | ||
59 | static DEFINE_SPINLOCK(state_spinlock); | 59 | static DEFINE_SPINLOCK(state_spinlock); |
60 | static LIST_HEAD(nfs4_clientid_list); | 60 | static LIST_HEAD(nfs4_clientid_list); |
61 | 61 | ||
62 | void | 62 | void |
63 | init_nfsv4_state(struct nfs_server *server) | 63 | init_nfsv4_state(struct nfs_server *server) |
64 | { | 64 | { |
65 | server->nfs4_state = NULL; | 65 | server->nfs4_state = NULL; |
66 | INIT_LIST_HEAD(&server->nfs4_siblings); | 66 | INIT_LIST_HEAD(&server->nfs4_siblings); |
67 | } | 67 | } |
68 | 68 | ||
69 | void | 69 | void |
70 | destroy_nfsv4_state(struct nfs_server *server) | 70 | destroy_nfsv4_state(struct nfs_server *server) |
71 | { | 71 | { |
72 | kfree(server->mnt_path); | 72 | kfree(server->mnt_path); |
73 | server->mnt_path = NULL; | 73 | server->mnt_path = NULL; |
74 | if (server->nfs4_state) { | 74 | if (server->nfs4_state) { |
75 | nfs4_put_client(server->nfs4_state); | 75 | nfs4_put_client(server->nfs4_state); |
76 | server->nfs4_state = NULL; | 76 | server->nfs4_state = NULL; |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | /* | 80 | /* |
81 | * nfs4_get_client(): returns an empty client structure | 81 | * nfs4_get_client(): returns an empty client structure |
82 | * nfs4_put_client(): drops reference to client structure | 82 | * nfs4_put_client(): drops reference to client structure |
83 | * | 83 | * |
84 | * Since these are allocated/deallocated very rarely, we don't | 84 | * Since these are allocated/deallocated very rarely, we don't |
85 | * bother putting them in a slab cache... | 85 | * bother putting them in a slab cache... |
86 | */ | 86 | */ |
87 | static struct nfs4_client * | 87 | static struct nfs4_client * |
88 | nfs4_alloc_client(struct in_addr *addr) | 88 | nfs4_alloc_client(struct in_addr *addr) |
89 | { | 89 | { |
90 | struct nfs4_client *clp; | 90 | struct nfs4_client *clp; |
91 | 91 | ||
92 | if (nfs_callback_up() < 0) | 92 | if (nfs_callback_up() < 0) |
93 | return NULL; | 93 | return NULL; |
94 | if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) { | 94 | if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) { |
95 | nfs_callback_down(); | 95 | nfs_callback_down(); |
96 | return NULL; | 96 | return NULL; |
97 | } | 97 | } |
98 | memcpy(&clp->cl_addr, addr, sizeof(clp->cl_addr)); | 98 | memcpy(&clp->cl_addr, addr, sizeof(clp->cl_addr)); |
99 | init_rwsem(&clp->cl_sem); | 99 | init_rwsem(&clp->cl_sem); |
100 | INIT_LIST_HEAD(&clp->cl_delegations); | 100 | INIT_LIST_HEAD(&clp->cl_delegations); |
101 | INIT_LIST_HEAD(&clp->cl_state_owners); | 101 | INIT_LIST_HEAD(&clp->cl_state_owners); |
102 | INIT_LIST_HEAD(&clp->cl_unused); | 102 | INIT_LIST_HEAD(&clp->cl_unused); |
103 | spin_lock_init(&clp->cl_lock); | 103 | spin_lock_init(&clp->cl_lock); |
104 | atomic_set(&clp->cl_count, 1); | 104 | atomic_set(&clp->cl_count, 1); |
105 | INIT_WORK(&clp->cl_renewd, nfs4_renew_state, clp); | 105 | INIT_WORK(&clp->cl_renewd, nfs4_renew_state, clp); |
106 | INIT_LIST_HEAD(&clp->cl_superblocks); | 106 | INIT_LIST_HEAD(&clp->cl_superblocks); |
107 | rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS4 client"); | 107 | rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS4 client"); |
108 | clp->cl_rpcclient = ERR_PTR(-EINVAL); | 108 | clp->cl_rpcclient = ERR_PTR(-EINVAL); |
109 | clp->cl_boot_time = CURRENT_TIME; | 109 | clp->cl_boot_time = CURRENT_TIME; |
110 | clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED; | 110 | clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED; |
111 | return clp; | 111 | return clp; |
112 | } | 112 | } |
113 | 113 | ||
114 | static void | 114 | static void |
115 | nfs4_free_client(struct nfs4_client *clp) | 115 | nfs4_free_client(struct nfs4_client *clp) |
116 | { | 116 | { |
117 | struct nfs4_state_owner *sp; | 117 | struct nfs4_state_owner *sp; |
118 | 118 | ||
119 | while (!list_empty(&clp->cl_unused)) { | 119 | while (!list_empty(&clp->cl_unused)) { |
120 | sp = list_entry(clp->cl_unused.next, | 120 | sp = list_entry(clp->cl_unused.next, |
121 | struct nfs4_state_owner, | 121 | struct nfs4_state_owner, |
122 | so_list); | 122 | so_list); |
123 | list_del(&sp->so_list); | 123 | list_del(&sp->so_list); |
124 | kfree(sp); | 124 | kfree(sp); |
125 | } | 125 | } |
126 | BUG_ON(!list_empty(&clp->cl_state_owners)); | 126 | BUG_ON(!list_empty(&clp->cl_state_owners)); |
127 | nfs_idmap_delete(clp); | 127 | nfs_idmap_delete(clp); |
128 | if (!IS_ERR(clp->cl_rpcclient)) | 128 | if (!IS_ERR(clp->cl_rpcclient)) |
129 | rpc_shutdown_client(clp->cl_rpcclient); | 129 | rpc_shutdown_client(clp->cl_rpcclient); |
130 | kfree(clp); | 130 | kfree(clp); |
131 | nfs_callback_down(); | 131 | nfs_callback_down(); |
132 | } | 132 | } |
133 | 133 | ||
134 | static struct nfs4_client *__nfs4_find_client(struct in_addr *addr) | 134 | static struct nfs4_client *__nfs4_find_client(struct in_addr *addr) |
135 | { | 135 | { |
136 | struct nfs4_client *clp; | 136 | struct nfs4_client *clp; |
137 | list_for_each_entry(clp, &nfs4_clientid_list, cl_servers) { | 137 | list_for_each_entry(clp, &nfs4_clientid_list, cl_servers) { |
138 | if (memcmp(&clp->cl_addr, addr, sizeof(clp->cl_addr)) == 0) { | 138 | if (memcmp(&clp->cl_addr, addr, sizeof(clp->cl_addr)) == 0) { |
139 | atomic_inc(&clp->cl_count); | 139 | atomic_inc(&clp->cl_count); |
140 | return clp; | 140 | return clp; |
141 | } | 141 | } |
142 | } | 142 | } |
143 | return NULL; | 143 | return NULL; |
144 | } | 144 | } |
145 | 145 | ||
146 | struct nfs4_client *nfs4_find_client(struct in_addr *addr) | 146 | struct nfs4_client *nfs4_find_client(struct in_addr *addr) |
147 | { | 147 | { |
148 | struct nfs4_client *clp; | 148 | struct nfs4_client *clp; |
149 | spin_lock(&state_spinlock); | 149 | spin_lock(&state_spinlock); |
150 | clp = __nfs4_find_client(addr); | 150 | clp = __nfs4_find_client(addr); |
151 | spin_unlock(&state_spinlock); | 151 | spin_unlock(&state_spinlock); |
152 | return clp; | 152 | return clp; |
153 | } | 153 | } |
154 | 154 | ||
155 | struct nfs4_client * | 155 | struct nfs4_client * |
156 | nfs4_get_client(struct in_addr *addr) | 156 | nfs4_get_client(struct in_addr *addr) |
157 | { | 157 | { |
158 | struct nfs4_client *clp, *new = NULL; | 158 | struct nfs4_client *clp, *new = NULL; |
159 | 159 | ||
160 | spin_lock(&state_spinlock); | 160 | spin_lock(&state_spinlock); |
161 | for (;;) { | 161 | for (;;) { |
162 | clp = __nfs4_find_client(addr); | 162 | clp = __nfs4_find_client(addr); |
163 | if (clp != NULL) | 163 | if (clp != NULL) |
164 | break; | 164 | break; |
165 | clp = new; | 165 | clp = new; |
166 | if (clp != NULL) { | 166 | if (clp != NULL) { |
167 | list_add(&clp->cl_servers, &nfs4_clientid_list); | 167 | list_add(&clp->cl_servers, &nfs4_clientid_list); |
168 | new = NULL; | 168 | new = NULL; |
169 | break; | 169 | break; |
170 | } | 170 | } |
171 | spin_unlock(&state_spinlock); | 171 | spin_unlock(&state_spinlock); |
172 | new = nfs4_alloc_client(addr); | 172 | new = nfs4_alloc_client(addr); |
173 | spin_lock(&state_spinlock); | 173 | spin_lock(&state_spinlock); |
174 | if (new == NULL) | 174 | if (new == NULL) |
175 | break; | 175 | break; |
176 | } | 176 | } |
177 | spin_unlock(&state_spinlock); | 177 | spin_unlock(&state_spinlock); |
178 | if (new) | 178 | if (new) |
179 | nfs4_free_client(new); | 179 | nfs4_free_client(new); |
180 | return clp; | 180 | return clp; |
181 | } | 181 | } |
182 | 182 | ||
183 | void | 183 | void |
184 | nfs4_put_client(struct nfs4_client *clp) | 184 | nfs4_put_client(struct nfs4_client *clp) |
185 | { | 185 | { |
186 | if (!atomic_dec_and_lock(&clp->cl_count, &state_spinlock)) | 186 | if (!atomic_dec_and_lock(&clp->cl_count, &state_spinlock)) |
187 | return; | 187 | return; |
188 | list_del(&clp->cl_servers); | 188 | list_del(&clp->cl_servers); |
189 | spin_unlock(&state_spinlock); | 189 | spin_unlock(&state_spinlock); |
190 | BUG_ON(!list_empty(&clp->cl_superblocks)); | 190 | BUG_ON(!list_empty(&clp->cl_superblocks)); |
191 | rpc_wake_up(&clp->cl_rpcwaitq); | 191 | rpc_wake_up(&clp->cl_rpcwaitq); |
192 | nfs4_kill_renewd(clp); | 192 | nfs4_kill_renewd(clp); |
193 | nfs4_free_client(clp); | 193 | nfs4_free_client(clp); |
194 | } | 194 | } |
195 | 195 | ||
196 | static int nfs4_init_client(struct nfs4_client *clp, struct rpc_cred *cred) | 196 | static int nfs4_init_client(struct nfs4_client *clp, struct rpc_cred *cred) |
197 | { | 197 | { |
198 | int status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, | 198 | int status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, |
199 | nfs_callback_tcpport, cred); | 199 | nfs_callback_tcpport, cred); |
200 | if (status == 0) | 200 | if (status == 0) |
201 | status = nfs4_proc_setclientid_confirm(clp, cred); | 201 | status = nfs4_proc_setclientid_confirm(clp, cred); |
202 | if (status == 0) | 202 | if (status == 0) |
203 | nfs4_schedule_state_renewal(clp); | 203 | nfs4_schedule_state_renewal(clp); |
204 | return status; | 204 | return status; |
205 | } | 205 | } |
206 | 206 | ||
207 | u32 | 207 | u32 |
208 | nfs4_alloc_lockowner_id(struct nfs4_client *clp) | 208 | nfs4_alloc_lockowner_id(struct nfs4_client *clp) |
209 | { | 209 | { |
210 | return clp->cl_lockowner_id ++; | 210 | return clp->cl_lockowner_id ++; |
211 | } | 211 | } |
212 | 212 | ||
213 | static struct nfs4_state_owner * | 213 | static struct nfs4_state_owner * |
214 | nfs4_client_grab_unused(struct nfs4_client *clp, struct rpc_cred *cred) | 214 | nfs4_client_grab_unused(struct nfs4_client *clp, struct rpc_cred *cred) |
215 | { | 215 | { |
216 | struct nfs4_state_owner *sp = NULL; | 216 | struct nfs4_state_owner *sp = NULL; |
217 | 217 | ||
218 | if (!list_empty(&clp->cl_unused)) { | 218 | if (!list_empty(&clp->cl_unused)) { |
219 | sp = list_entry(clp->cl_unused.next, struct nfs4_state_owner, so_list); | 219 | sp = list_entry(clp->cl_unused.next, struct nfs4_state_owner, so_list); |
220 | atomic_inc(&sp->so_count); | 220 | atomic_inc(&sp->so_count); |
221 | sp->so_cred = cred; | 221 | sp->so_cred = cred; |
222 | list_move(&sp->so_list, &clp->cl_state_owners); | 222 | list_move(&sp->so_list, &clp->cl_state_owners); |
223 | clp->cl_nunused--; | 223 | clp->cl_nunused--; |
224 | } | 224 | } |
225 | return sp; | 225 | return sp; |
226 | } | 226 | } |
227 | 227 | ||
228 | struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp) | 228 | struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp) |
229 | { | 229 | { |
230 | struct nfs4_state_owner *sp; | 230 | struct nfs4_state_owner *sp; |
231 | struct rpc_cred *cred = NULL; | 231 | struct rpc_cred *cred = NULL; |
232 | 232 | ||
233 | list_for_each_entry(sp, &clp->cl_state_owners, so_list) { | 233 | list_for_each_entry(sp, &clp->cl_state_owners, so_list) { |
234 | if (list_empty(&sp->so_states)) | 234 | if (list_empty(&sp->so_states)) |
235 | continue; | 235 | continue; |
236 | cred = get_rpccred(sp->so_cred); | 236 | cred = get_rpccred(sp->so_cred); |
237 | break; | 237 | break; |
238 | } | 238 | } |
239 | return cred; | 239 | return cred; |
240 | } | 240 | } |
241 | 241 | ||
242 | struct rpc_cred *nfs4_get_setclientid_cred(struct nfs4_client *clp) | 242 | struct rpc_cred *nfs4_get_setclientid_cred(struct nfs4_client *clp) |
243 | { | 243 | { |
244 | struct nfs4_state_owner *sp; | 244 | struct nfs4_state_owner *sp; |
245 | 245 | ||
246 | if (!list_empty(&clp->cl_state_owners)) { | 246 | if (!list_empty(&clp->cl_state_owners)) { |
247 | sp = list_entry(clp->cl_state_owners.next, | 247 | sp = list_entry(clp->cl_state_owners.next, |
248 | struct nfs4_state_owner, so_list); | 248 | struct nfs4_state_owner, so_list); |
249 | return get_rpccred(sp->so_cred); | 249 | return get_rpccred(sp->so_cred); |
250 | } | 250 | } |
251 | return NULL; | 251 | return NULL; |
252 | } | 252 | } |
253 | 253 | ||
254 | static struct nfs4_state_owner * | 254 | static struct nfs4_state_owner * |
255 | nfs4_find_state_owner(struct nfs4_client *clp, struct rpc_cred *cred) | 255 | nfs4_find_state_owner(struct nfs4_client *clp, struct rpc_cred *cred) |
256 | { | 256 | { |
257 | struct nfs4_state_owner *sp, *res = NULL; | 257 | struct nfs4_state_owner *sp, *res = NULL; |
258 | 258 | ||
259 | list_for_each_entry(sp, &clp->cl_state_owners, so_list) { | 259 | list_for_each_entry(sp, &clp->cl_state_owners, so_list) { |
260 | if (sp->so_cred != cred) | 260 | if (sp->so_cred != cred) |
261 | continue; | 261 | continue; |
262 | atomic_inc(&sp->so_count); | 262 | atomic_inc(&sp->so_count); |
263 | /* Move to the head of the list */ | 263 | /* Move to the head of the list */ |
264 | list_move(&sp->so_list, &clp->cl_state_owners); | 264 | list_move(&sp->so_list, &clp->cl_state_owners); |
265 | res = sp; | 265 | res = sp; |
266 | break; | 266 | break; |
267 | } | 267 | } |
268 | return res; | 268 | return res; |
269 | } | 269 | } |
270 | 270 | ||
271 | /* | 271 | /* |
272 | * nfs4_alloc_state_owner(): this is called on the OPEN or CREATE path to | 272 | * nfs4_alloc_state_owner(): this is called on the OPEN or CREATE path to |
273 | * create a new state_owner. | 273 | * create a new state_owner. |
274 | * | 274 | * |
275 | */ | 275 | */ |
276 | static struct nfs4_state_owner * | 276 | static struct nfs4_state_owner * |
277 | nfs4_alloc_state_owner(void) | 277 | nfs4_alloc_state_owner(void) |
278 | { | 278 | { |
279 | struct nfs4_state_owner *sp; | 279 | struct nfs4_state_owner *sp; |
280 | 280 | ||
281 | sp = kzalloc(sizeof(*sp),GFP_KERNEL); | 281 | sp = kzalloc(sizeof(*sp),GFP_KERNEL); |
282 | if (!sp) | 282 | if (!sp) |
283 | return NULL; | 283 | return NULL; |
284 | spin_lock_init(&sp->so_lock); | 284 | spin_lock_init(&sp->so_lock); |
285 | INIT_LIST_HEAD(&sp->so_states); | 285 | INIT_LIST_HEAD(&sp->so_states); |
286 | INIT_LIST_HEAD(&sp->so_delegations); | 286 | INIT_LIST_HEAD(&sp->so_delegations); |
287 | rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue"); | 287 | rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue"); |
288 | sp->so_seqid.sequence = &sp->so_sequence; | 288 | sp->so_seqid.sequence = &sp->so_sequence; |
289 | spin_lock_init(&sp->so_sequence.lock); | 289 | spin_lock_init(&sp->so_sequence.lock); |
290 | INIT_LIST_HEAD(&sp->so_sequence.list); | 290 | INIT_LIST_HEAD(&sp->so_sequence.list); |
291 | atomic_set(&sp->so_count, 1); | 291 | atomic_set(&sp->so_count, 1); |
292 | return sp; | 292 | return sp; |
293 | } | 293 | } |
294 | 294 | ||
295 | void | 295 | void |
296 | nfs4_drop_state_owner(struct nfs4_state_owner *sp) | 296 | nfs4_drop_state_owner(struct nfs4_state_owner *sp) |
297 | { | 297 | { |
298 | struct nfs4_client *clp = sp->so_client; | 298 | struct nfs4_client *clp = sp->so_client; |
299 | spin_lock(&clp->cl_lock); | 299 | spin_lock(&clp->cl_lock); |
300 | list_del_init(&sp->so_list); | 300 | list_del_init(&sp->so_list); |
301 | spin_unlock(&clp->cl_lock); | 301 | spin_unlock(&clp->cl_lock); |
302 | } | 302 | } |
303 | 303 | ||
304 | /* | 304 | /* |
305 | * Note: must be called with clp->cl_sem held in order to prevent races | 305 | * Note: must be called with clp->cl_sem held in order to prevent races |
306 | * with reboot recovery! | 306 | * with reboot recovery! |
307 | */ | 307 | */ |
308 | struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct rpc_cred *cred) | 308 | struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct rpc_cred *cred) |
309 | { | 309 | { |
310 | struct nfs4_client *clp = server->nfs4_state; | 310 | struct nfs4_client *clp = server->nfs4_state; |
311 | struct nfs4_state_owner *sp, *new; | 311 | struct nfs4_state_owner *sp, *new; |
312 | 312 | ||
313 | get_rpccred(cred); | 313 | get_rpccred(cred); |
314 | new = nfs4_alloc_state_owner(); | 314 | new = nfs4_alloc_state_owner(); |
315 | spin_lock(&clp->cl_lock); | 315 | spin_lock(&clp->cl_lock); |
316 | sp = nfs4_find_state_owner(clp, cred); | 316 | sp = nfs4_find_state_owner(clp, cred); |
317 | if (sp == NULL) | 317 | if (sp == NULL) |
318 | sp = nfs4_client_grab_unused(clp, cred); | 318 | sp = nfs4_client_grab_unused(clp, cred); |
319 | if (sp == NULL && new != NULL) { | 319 | if (sp == NULL && new != NULL) { |
320 | list_add(&new->so_list, &clp->cl_state_owners); | 320 | list_add(&new->so_list, &clp->cl_state_owners); |
321 | new->so_client = clp; | 321 | new->so_client = clp; |
322 | new->so_id = nfs4_alloc_lockowner_id(clp); | 322 | new->so_id = nfs4_alloc_lockowner_id(clp); |
323 | new->so_cred = cred; | 323 | new->so_cred = cred; |
324 | sp = new; | 324 | sp = new; |
325 | new = NULL; | 325 | new = NULL; |
326 | } | 326 | } |
327 | spin_unlock(&clp->cl_lock); | 327 | spin_unlock(&clp->cl_lock); |
328 | kfree(new); | 328 | kfree(new); |
329 | if (sp != NULL) | 329 | if (sp != NULL) |
330 | return sp; | 330 | return sp; |
331 | put_rpccred(cred); | 331 | put_rpccred(cred); |
332 | return NULL; | 332 | return NULL; |
333 | } | 333 | } |
334 | 334 | ||
335 | /* | 335 | /* |
336 | * Must be called with clp->cl_sem held in order to avoid races | 336 | * Must be called with clp->cl_sem held in order to avoid races |
337 | * with state recovery... | 337 | * with state recovery... |
338 | */ | 338 | */ |
339 | void nfs4_put_state_owner(struct nfs4_state_owner *sp) | 339 | void nfs4_put_state_owner(struct nfs4_state_owner *sp) |
340 | { | 340 | { |
341 | struct nfs4_client *clp = sp->so_client; | 341 | struct nfs4_client *clp = sp->so_client; |
342 | struct rpc_cred *cred = sp->so_cred; | 342 | struct rpc_cred *cred = sp->so_cred; |
343 | 343 | ||
344 | if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock)) | 344 | if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock)) |
345 | return; | 345 | return; |
346 | if (clp->cl_nunused >= OPENOWNER_POOL_SIZE) | 346 | if (clp->cl_nunused >= OPENOWNER_POOL_SIZE) |
347 | goto out_free; | 347 | goto out_free; |
348 | if (list_empty(&sp->so_list)) | 348 | if (list_empty(&sp->so_list)) |
349 | goto out_free; | 349 | goto out_free; |
350 | list_move(&sp->so_list, &clp->cl_unused); | 350 | list_move(&sp->so_list, &clp->cl_unused); |
351 | clp->cl_nunused++; | 351 | clp->cl_nunused++; |
352 | spin_unlock(&clp->cl_lock); | 352 | spin_unlock(&clp->cl_lock); |
353 | put_rpccred(cred); | 353 | put_rpccred(cred); |
354 | cred = NULL; | 354 | cred = NULL; |
355 | return; | 355 | return; |
356 | out_free: | 356 | out_free: |
357 | list_del(&sp->so_list); | 357 | list_del(&sp->so_list); |
358 | spin_unlock(&clp->cl_lock); | 358 | spin_unlock(&clp->cl_lock); |
359 | put_rpccred(cred); | 359 | put_rpccred(cred); |
360 | kfree(sp); | 360 | kfree(sp); |
361 | } | 361 | } |
362 | 362 | ||
363 | static struct nfs4_state * | 363 | static struct nfs4_state * |
364 | nfs4_alloc_open_state(void) | 364 | nfs4_alloc_open_state(void) |
365 | { | 365 | { |
366 | struct nfs4_state *state; | 366 | struct nfs4_state *state; |
367 | 367 | ||
368 | state = kzalloc(sizeof(*state), GFP_KERNEL); | 368 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
369 | if (!state) | 369 | if (!state) |
370 | return NULL; | 370 | return NULL; |
371 | atomic_set(&state->count, 1); | 371 | atomic_set(&state->count, 1); |
372 | INIT_LIST_HEAD(&state->lock_states); | 372 | INIT_LIST_HEAD(&state->lock_states); |
373 | spin_lock_init(&state->state_lock); | 373 | spin_lock_init(&state->state_lock); |
374 | return state; | 374 | return state; |
375 | } | 375 | } |
376 | 376 | ||
377 | void | 377 | void |
378 | nfs4_state_set_mode_locked(struct nfs4_state *state, mode_t mode) | 378 | nfs4_state_set_mode_locked(struct nfs4_state *state, mode_t mode) |
379 | { | 379 | { |
380 | if (state->state == mode) | 380 | if (state->state == mode) |
381 | return; | 381 | return; |
382 | /* NB! List reordering - see the reclaim code for why. */ | 382 | /* NB! List reordering - see the reclaim code for why. */ |
383 | if ((mode & FMODE_WRITE) != (state->state & FMODE_WRITE)) { | 383 | if ((mode & FMODE_WRITE) != (state->state & FMODE_WRITE)) { |
384 | if (mode & FMODE_WRITE) | 384 | if (mode & FMODE_WRITE) |
385 | list_move(&state->open_states, &state->owner->so_states); | 385 | list_move(&state->open_states, &state->owner->so_states); |
386 | else | 386 | else |
387 | list_move_tail(&state->open_states, &state->owner->so_states); | 387 | list_move_tail(&state->open_states, &state->owner->so_states); |
388 | } | 388 | } |
389 | if (mode == 0) | 389 | if (mode == 0) |
390 | list_del_init(&state->inode_states); | 390 | list_del_init(&state->inode_states); |
391 | state->state = mode; | 391 | state->state = mode; |
392 | } | 392 | } |
393 | 393 | ||
394 | static struct nfs4_state * | 394 | static struct nfs4_state * |
395 | __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner) | 395 | __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner) |
396 | { | 396 | { |
397 | struct nfs_inode *nfsi = NFS_I(inode); | 397 | struct nfs_inode *nfsi = NFS_I(inode); |
398 | struct nfs4_state *state; | 398 | struct nfs4_state *state; |
399 | 399 | ||
400 | list_for_each_entry(state, &nfsi->open_states, inode_states) { | 400 | list_for_each_entry(state, &nfsi->open_states, inode_states) { |
401 | /* Is this in the process of being freed? */ | 401 | /* Is this in the process of being freed? */ |
402 | if (state->state == 0) | 402 | if (state->state == 0) |
403 | continue; | 403 | continue; |
404 | if (state->owner == owner) { | 404 | if (state->owner == owner) { |
405 | atomic_inc(&state->count); | 405 | atomic_inc(&state->count); |
406 | return state; | 406 | return state; |
407 | } | 407 | } |
408 | } | 408 | } |
409 | return NULL; | 409 | return NULL; |
410 | } | 410 | } |
411 | 411 | ||
412 | static void | 412 | static void |
413 | nfs4_free_open_state(struct nfs4_state *state) | 413 | nfs4_free_open_state(struct nfs4_state *state) |
414 | { | 414 | { |
415 | kfree(state); | 415 | kfree(state); |
416 | } | 416 | } |
417 | 417 | ||
418 | struct nfs4_state * | 418 | struct nfs4_state * |
419 | nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner) | 419 | nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner) |
420 | { | 420 | { |
421 | struct nfs4_state *state, *new; | 421 | struct nfs4_state *state, *new; |
422 | struct nfs_inode *nfsi = NFS_I(inode); | 422 | struct nfs_inode *nfsi = NFS_I(inode); |
423 | 423 | ||
424 | spin_lock(&inode->i_lock); | 424 | spin_lock(&inode->i_lock); |
425 | state = __nfs4_find_state_byowner(inode, owner); | 425 | state = __nfs4_find_state_byowner(inode, owner); |
426 | spin_unlock(&inode->i_lock); | 426 | spin_unlock(&inode->i_lock); |
427 | if (state) | 427 | if (state) |
428 | goto out; | 428 | goto out; |
429 | new = nfs4_alloc_open_state(); | 429 | new = nfs4_alloc_open_state(); |
430 | spin_lock(&owner->so_lock); | 430 | spin_lock(&owner->so_lock); |
431 | spin_lock(&inode->i_lock); | 431 | spin_lock(&inode->i_lock); |
432 | state = __nfs4_find_state_byowner(inode, owner); | 432 | state = __nfs4_find_state_byowner(inode, owner); |
433 | if (state == NULL && new != NULL) { | 433 | if (state == NULL && new != NULL) { |
434 | state = new; | 434 | state = new; |
435 | state->owner = owner; | 435 | state->owner = owner; |
436 | atomic_inc(&owner->so_count); | 436 | atomic_inc(&owner->so_count); |
437 | list_add(&state->inode_states, &nfsi->open_states); | 437 | list_add(&state->inode_states, &nfsi->open_states); |
438 | state->inode = igrab(inode); | 438 | state->inode = igrab(inode); |
439 | spin_unlock(&inode->i_lock); | 439 | spin_unlock(&inode->i_lock); |
440 | /* Note: The reclaim code dictates that we add stateless | 440 | /* Note: The reclaim code dictates that we add stateless |
441 | * and read-only stateids to the end of the list */ | 441 | * and read-only stateids to the end of the list */ |
442 | list_add_tail(&state->open_states, &owner->so_states); | 442 | list_add_tail(&state->open_states, &owner->so_states); |
443 | spin_unlock(&owner->so_lock); | 443 | spin_unlock(&owner->so_lock); |
444 | } else { | 444 | } else { |
445 | spin_unlock(&inode->i_lock); | 445 | spin_unlock(&inode->i_lock); |
446 | spin_unlock(&owner->so_lock); | 446 | spin_unlock(&owner->so_lock); |
447 | if (new) | 447 | if (new) |
448 | nfs4_free_open_state(new); | 448 | nfs4_free_open_state(new); |
449 | } | 449 | } |
450 | out: | 450 | out: |
451 | return state; | 451 | return state; |
452 | } | 452 | } |
453 | 453 | ||
454 | /* | 454 | /* |
455 | * Beware! Caller must be holding exactly one | 455 | * Beware! Caller must be holding exactly one |
456 | * reference to clp->cl_sem! | 456 | * reference to clp->cl_sem! |
457 | */ | 457 | */ |
458 | void nfs4_put_open_state(struct nfs4_state *state) | 458 | void nfs4_put_open_state(struct nfs4_state *state) |
459 | { | 459 | { |
460 | struct inode *inode = state->inode; | 460 | struct inode *inode = state->inode; |
461 | struct nfs4_state_owner *owner = state->owner; | 461 | struct nfs4_state_owner *owner = state->owner; |
462 | 462 | ||
463 | if (!atomic_dec_and_lock(&state->count, &owner->so_lock)) | 463 | if (!atomic_dec_and_lock(&state->count, &owner->so_lock)) |
464 | return; | 464 | return; |
465 | spin_lock(&inode->i_lock); | 465 | spin_lock(&inode->i_lock); |
466 | if (!list_empty(&state->inode_states)) | 466 | if (!list_empty(&state->inode_states)) |
467 | list_del(&state->inode_states); | 467 | list_del(&state->inode_states); |
468 | list_del(&state->open_states); | 468 | list_del(&state->open_states); |
469 | spin_unlock(&inode->i_lock); | 469 | spin_unlock(&inode->i_lock); |
470 | spin_unlock(&owner->so_lock); | 470 | spin_unlock(&owner->so_lock); |
471 | iput(inode); | 471 | iput(inode); |
472 | nfs4_free_open_state(state); | 472 | nfs4_free_open_state(state); |
473 | nfs4_put_state_owner(owner); | 473 | nfs4_put_state_owner(owner); |
474 | } | 474 | } |
475 | 475 | ||
476 | /* | 476 | /* |
477 | * Close the current file. | 477 | * Close the current file. |
478 | */ | 478 | */ |
479 | void nfs4_close_state(struct nfs4_state *state, mode_t mode) | 479 | void nfs4_close_state(struct nfs4_state *state, mode_t mode) |
480 | { | 480 | { |
481 | struct inode *inode = state->inode; | 481 | struct inode *inode = state->inode; |
482 | struct nfs4_state_owner *owner = state->owner; | 482 | struct nfs4_state_owner *owner = state->owner; |
483 | int oldstate, newstate = 0; | 483 | int oldstate, newstate = 0; |
484 | 484 | ||
485 | atomic_inc(&owner->so_count); | 485 | atomic_inc(&owner->so_count); |
486 | /* Protect against nfs4_find_state() */ | 486 | /* Protect against nfs4_find_state() */ |
487 | spin_lock(&owner->so_lock); | 487 | spin_lock(&owner->so_lock); |
488 | spin_lock(&inode->i_lock); | 488 | spin_lock(&inode->i_lock); |
489 | switch (mode & (FMODE_READ | FMODE_WRITE)) { | 489 | switch (mode & (FMODE_READ | FMODE_WRITE)) { |
490 | case FMODE_READ: | 490 | case FMODE_READ: |
491 | state->n_rdonly--; | 491 | state->n_rdonly--; |
492 | break; | 492 | break; |
493 | case FMODE_WRITE: | 493 | case FMODE_WRITE: |
494 | state->n_wronly--; | 494 | state->n_wronly--; |
495 | break; | 495 | break; |
496 | case FMODE_READ|FMODE_WRITE: | 496 | case FMODE_READ|FMODE_WRITE: |
497 | state->n_rdwr--; | 497 | state->n_rdwr--; |
498 | } | 498 | } |
499 | oldstate = newstate = state->state; | 499 | oldstate = newstate = state->state; |
500 | if (state->n_rdwr == 0) { | 500 | if (state->n_rdwr == 0) { |
501 | if (state->n_rdonly == 0) | 501 | if (state->n_rdonly == 0) |
502 | newstate &= ~FMODE_READ; | 502 | newstate &= ~FMODE_READ; |
503 | if (state->n_wronly == 0) | 503 | if (state->n_wronly == 0) |
504 | newstate &= ~FMODE_WRITE; | 504 | newstate &= ~FMODE_WRITE; |
505 | } | 505 | } |
506 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { | 506 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
507 | nfs4_state_set_mode_locked(state, newstate); | 507 | nfs4_state_set_mode_locked(state, newstate); |
508 | oldstate = newstate; | 508 | oldstate = newstate; |
509 | } | 509 | } |
510 | spin_unlock(&inode->i_lock); | 510 | spin_unlock(&inode->i_lock); |
511 | spin_unlock(&owner->so_lock); | 511 | spin_unlock(&owner->so_lock); |
512 | 512 | ||
513 | if (oldstate != newstate && nfs4_do_close(inode, state) == 0) | 513 | if (oldstate != newstate && nfs4_do_close(inode, state) == 0) |
514 | return; | 514 | return; |
515 | nfs4_put_open_state(state); | 515 | nfs4_put_open_state(state); |
516 | nfs4_put_state_owner(owner); | 516 | nfs4_put_state_owner(owner); |
517 | } | 517 | } |
518 | 518 | ||
519 | /* | 519 | /* |
520 | * Search the state->lock_states for an existing lock_owner | 520 | * Search the state->lock_states for an existing lock_owner |
521 | * that is compatible with current->files | 521 | * that is compatible with current->files |
522 | */ | 522 | */ |
523 | static struct nfs4_lock_state * | 523 | static struct nfs4_lock_state * |
524 | __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) | 524 | __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) |
525 | { | 525 | { |
526 | struct nfs4_lock_state *pos; | 526 | struct nfs4_lock_state *pos; |
527 | list_for_each_entry(pos, &state->lock_states, ls_locks) { | 527 | list_for_each_entry(pos, &state->lock_states, ls_locks) { |
528 | if (pos->ls_owner != fl_owner) | 528 | if (pos->ls_owner != fl_owner) |
529 | continue; | 529 | continue; |
530 | atomic_inc(&pos->ls_count); | 530 | atomic_inc(&pos->ls_count); |
531 | return pos; | 531 | return pos; |
532 | } | 532 | } |
533 | return NULL; | 533 | return NULL; |
534 | } | 534 | } |
535 | 535 | ||
536 | /* | 536 | /* |
537 | * Return a compatible lock_state. If no initialized lock_state structure | 537 | * Return a compatible lock_state. If no initialized lock_state structure |
538 | * exists, return an uninitialized one. | 538 | * exists, return an uninitialized one. |
539 | * | 539 | * |
540 | */ | 540 | */ |
541 | static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) | 541 | static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) |
542 | { | 542 | { |
543 | struct nfs4_lock_state *lsp; | 543 | struct nfs4_lock_state *lsp; |
544 | struct nfs4_client *clp = state->owner->so_client; | 544 | struct nfs4_client *clp = state->owner->so_client; |
545 | 545 | ||
546 | lsp = kzalloc(sizeof(*lsp), GFP_KERNEL); | 546 | lsp = kzalloc(sizeof(*lsp), GFP_KERNEL); |
547 | if (lsp == NULL) | 547 | if (lsp == NULL) |
548 | return NULL; | 548 | return NULL; |
549 | lsp->ls_seqid.sequence = &state->owner->so_sequence; | 549 | lsp->ls_seqid.sequence = &state->owner->so_sequence; |
550 | atomic_set(&lsp->ls_count, 1); | 550 | atomic_set(&lsp->ls_count, 1); |
551 | lsp->ls_owner = fl_owner; | 551 | lsp->ls_owner = fl_owner; |
552 | spin_lock(&clp->cl_lock); | 552 | spin_lock(&clp->cl_lock); |
553 | lsp->ls_id = nfs4_alloc_lockowner_id(clp); | 553 | lsp->ls_id = nfs4_alloc_lockowner_id(clp); |
554 | spin_unlock(&clp->cl_lock); | 554 | spin_unlock(&clp->cl_lock); |
555 | INIT_LIST_HEAD(&lsp->ls_locks); | 555 | INIT_LIST_HEAD(&lsp->ls_locks); |
556 | return lsp; | 556 | return lsp; |
557 | } | 557 | } |
558 | 558 | ||
559 | /* | 559 | /* |
560 | * Return a compatible lock_state. If no initialized lock_state structure | 560 | * Return a compatible lock_state. If no initialized lock_state structure |
561 | * exists, return an uninitialized one. | 561 | * exists, return an uninitialized one. |
562 | * | 562 | * |
563 | * The caller must be holding clp->cl_sem | 563 | * The caller must be holding clp->cl_sem |
564 | */ | 564 | */ |
565 | static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) | 565 | static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) |
566 | { | 566 | { |
567 | struct nfs4_lock_state *lsp, *new = NULL; | 567 | struct nfs4_lock_state *lsp, *new = NULL; |
568 | 568 | ||
569 | for(;;) { | 569 | for(;;) { |
570 | spin_lock(&state->state_lock); | 570 | spin_lock(&state->state_lock); |
571 | lsp = __nfs4_find_lock_state(state, owner); | 571 | lsp = __nfs4_find_lock_state(state, owner); |
572 | if (lsp != NULL) | 572 | if (lsp != NULL) |
573 | break; | 573 | break; |
574 | if (new != NULL) { | 574 | if (new != NULL) { |
575 | new->ls_state = state; | 575 | new->ls_state = state; |
576 | list_add(&new->ls_locks, &state->lock_states); | 576 | list_add(&new->ls_locks, &state->lock_states); |
577 | set_bit(LK_STATE_IN_USE, &state->flags); | 577 | set_bit(LK_STATE_IN_USE, &state->flags); |
578 | lsp = new; | 578 | lsp = new; |
579 | new = NULL; | 579 | new = NULL; |
580 | break; | 580 | break; |
581 | } | 581 | } |
582 | spin_unlock(&state->state_lock); | 582 | spin_unlock(&state->state_lock); |
583 | new = nfs4_alloc_lock_state(state, owner); | 583 | new = nfs4_alloc_lock_state(state, owner); |
584 | if (new == NULL) | 584 | if (new == NULL) |
585 | return NULL; | 585 | return NULL; |
586 | } | 586 | } |
587 | spin_unlock(&state->state_lock); | 587 | spin_unlock(&state->state_lock); |
588 | kfree(new); | 588 | kfree(new); |
589 | return lsp; | 589 | return lsp; |
590 | } | 590 | } |
591 | 591 | ||
592 | /* | 592 | /* |
593 | * Release reference to lock_state, and free it if we see that | 593 | * Release reference to lock_state, and free it if we see that |
594 | * it is no longer in use | 594 | * it is no longer in use |
595 | */ | 595 | */ |
596 | void nfs4_put_lock_state(struct nfs4_lock_state *lsp) | 596 | void nfs4_put_lock_state(struct nfs4_lock_state *lsp) |
597 | { | 597 | { |
598 | struct nfs4_state *state; | 598 | struct nfs4_state *state; |
599 | 599 | ||
600 | if (lsp == NULL) | 600 | if (lsp == NULL) |
601 | return; | 601 | return; |
602 | state = lsp->ls_state; | 602 | state = lsp->ls_state; |
603 | if (!atomic_dec_and_lock(&lsp->ls_count, &state->state_lock)) | 603 | if (!atomic_dec_and_lock(&lsp->ls_count, &state->state_lock)) |
604 | return; | 604 | return; |
605 | list_del(&lsp->ls_locks); | 605 | list_del(&lsp->ls_locks); |
606 | if (list_empty(&state->lock_states)) | 606 | if (list_empty(&state->lock_states)) |
607 | clear_bit(LK_STATE_IN_USE, &state->flags); | 607 | clear_bit(LK_STATE_IN_USE, &state->flags); |
608 | spin_unlock(&state->state_lock); | 608 | spin_unlock(&state->state_lock); |
609 | kfree(lsp); | 609 | kfree(lsp); |
610 | } | 610 | } |
611 | 611 | ||
612 | static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src) | 612 | static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src) |
613 | { | 613 | { |
614 | struct nfs4_lock_state *lsp = src->fl_u.nfs4_fl.owner; | 614 | struct nfs4_lock_state *lsp = src->fl_u.nfs4_fl.owner; |
615 | 615 | ||
616 | dst->fl_u.nfs4_fl.owner = lsp; | 616 | dst->fl_u.nfs4_fl.owner = lsp; |
617 | atomic_inc(&lsp->ls_count); | 617 | atomic_inc(&lsp->ls_count); |
618 | } | 618 | } |
619 | 619 | ||
620 | static void nfs4_fl_release_lock(struct file_lock *fl) | 620 | static void nfs4_fl_release_lock(struct file_lock *fl) |
621 | { | 621 | { |
622 | nfs4_put_lock_state(fl->fl_u.nfs4_fl.owner); | 622 | nfs4_put_lock_state(fl->fl_u.nfs4_fl.owner); |
623 | } | 623 | } |
624 | 624 | ||
625 | static struct file_lock_operations nfs4_fl_lock_ops = { | 625 | static struct file_lock_operations nfs4_fl_lock_ops = { |
626 | .fl_copy_lock = nfs4_fl_copy_lock, | 626 | .fl_copy_lock = nfs4_fl_copy_lock, |
627 | .fl_release_private = nfs4_fl_release_lock, | 627 | .fl_release_private = nfs4_fl_release_lock, |
628 | }; | 628 | }; |
629 | 629 | ||
630 | int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl) | 630 | int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl) |
631 | { | 631 | { |
632 | struct nfs4_lock_state *lsp; | 632 | struct nfs4_lock_state *lsp; |
633 | 633 | ||
634 | if (fl->fl_ops != NULL) | 634 | if (fl->fl_ops != NULL) |
635 | return 0; | 635 | return 0; |
636 | lsp = nfs4_get_lock_state(state, fl->fl_owner); | 636 | lsp = nfs4_get_lock_state(state, fl->fl_owner); |
637 | if (lsp == NULL) | 637 | if (lsp == NULL) |
638 | return -ENOMEM; | 638 | return -ENOMEM; |
639 | fl->fl_u.nfs4_fl.owner = lsp; | 639 | fl->fl_u.nfs4_fl.owner = lsp; |
640 | fl->fl_ops = &nfs4_fl_lock_ops; | 640 | fl->fl_ops = &nfs4_fl_lock_ops; |
641 | return 0; | 641 | return 0; |
642 | } | 642 | } |
643 | 643 | ||
644 | /* | 644 | /* |
645 | * Byte-range lock aware utility to initialize the stateid of read/write | 645 | * Byte-range lock aware utility to initialize the stateid of read/write |
646 | * requests. | 646 | * requests. |
647 | */ | 647 | */ |
648 | void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner) | 648 | void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner) |
649 | { | 649 | { |
650 | struct nfs4_lock_state *lsp; | 650 | struct nfs4_lock_state *lsp; |
651 | 651 | ||
652 | memcpy(dst, &state->stateid, sizeof(*dst)); | 652 | memcpy(dst, &state->stateid, sizeof(*dst)); |
653 | if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) | 653 | if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) |
654 | return; | 654 | return; |
655 | 655 | ||
656 | spin_lock(&state->state_lock); | 656 | spin_lock(&state->state_lock); |
657 | lsp = __nfs4_find_lock_state(state, fl_owner); | 657 | lsp = __nfs4_find_lock_state(state, fl_owner); |
658 | if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) | 658 | if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
659 | memcpy(dst, &lsp->ls_stateid, sizeof(*dst)); | 659 | memcpy(dst, &lsp->ls_stateid, sizeof(*dst)); |
660 | spin_unlock(&state->state_lock); | 660 | spin_unlock(&state->state_lock); |
661 | nfs4_put_lock_state(lsp); | 661 | nfs4_put_lock_state(lsp); |
662 | } | 662 | } |
663 | 663 | ||
664 | struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter) | 664 | struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter) |
665 | { | 665 | { |
666 | struct rpc_sequence *sequence = counter->sequence; | 666 | struct rpc_sequence *sequence = counter->sequence; |
667 | struct nfs_seqid *new; | 667 | struct nfs_seqid *new; |
668 | 668 | ||
669 | new = kmalloc(sizeof(*new), GFP_KERNEL); | 669 | new = kmalloc(sizeof(*new), GFP_KERNEL); |
670 | if (new != NULL) { | 670 | if (new != NULL) { |
671 | new->sequence = counter; | 671 | new->sequence = counter; |
672 | spin_lock(&sequence->lock); | 672 | spin_lock(&sequence->lock); |
673 | list_add_tail(&new->list, &sequence->list); | 673 | list_add_tail(&new->list, &sequence->list); |
674 | spin_unlock(&sequence->lock); | 674 | spin_unlock(&sequence->lock); |
675 | } | 675 | } |
676 | return new; | 676 | return new; |
677 | } | 677 | } |
678 | 678 | ||
679 | void nfs_free_seqid(struct nfs_seqid *seqid) | 679 | void nfs_free_seqid(struct nfs_seqid *seqid) |
680 | { | 680 | { |
681 | struct rpc_sequence *sequence = seqid->sequence->sequence; | 681 | struct rpc_sequence *sequence = seqid->sequence->sequence; |
682 | 682 | ||
683 | spin_lock(&sequence->lock); | 683 | spin_lock(&sequence->lock); |
684 | list_del(&seqid->list); | 684 | list_del(&seqid->list); |
685 | spin_unlock(&sequence->lock); | 685 | spin_unlock(&sequence->lock); |
686 | rpc_wake_up(&sequence->wait); | 686 | rpc_wake_up(&sequence->wait); |
687 | kfree(seqid); | 687 | kfree(seqid); |
688 | } | 688 | } |
689 | 689 | ||
690 | /* | 690 | /* |
691 | * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or | 691 | * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or |
692 | * failed with a seqid incrementing error - | 692 | * failed with a seqid incrementing error - |
693 | * see comments nfs_fs.h:seqid_mutating_error() | 693 | * see comments nfs_fs.h:seqid_mutating_error() |
694 | */ | 694 | */ |
695 | static inline void nfs_increment_seqid(int status, struct nfs_seqid *seqid) | 695 | static inline void nfs_increment_seqid(int status, struct nfs_seqid *seqid) |
696 | { | 696 | { |
697 | switch (status) { | 697 | switch (status) { |
698 | case 0: | 698 | case 0: |
699 | break; | 699 | break; |
700 | case -NFS4ERR_BAD_SEQID: | 700 | case -NFS4ERR_BAD_SEQID: |
701 | case -NFS4ERR_STALE_CLIENTID: | 701 | case -NFS4ERR_STALE_CLIENTID: |
702 | case -NFS4ERR_STALE_STATEID: | 702 | case -NFS4ERR_STALE_STATEID: |
703 | case -NFS4ERR_BAD_STATEID: | 703 | case -NFS4ERR_BAD_STATEID: |
704 | case -NFS4ERR_BADXDR: | 704 | case -NFS4ERR_BADXDR: |
705 | case -NFS4ERR_RESOURCE: | 705 | case -NFS4ERR_RESOURCE: |
706 | case -NFS4ERR_NOFILEHANDLE: | 706 | case -NFS4ERR_NOFILEHANDLE: |
707 | /* Non-seqid mutating errors */ | 707 | /* Non-seqid mutating errors */ |
708 | return; | 708 | return; |
709 | }; | 709 | }; |
710 | /* | 710 | /* |
711 | * Note: no locking needed as we are guaranteed to be first | 711 | * Note: no locking needed as we are guaranteed to be first |
712 | * on the sequence list | 712 | * on the sequence list |
713 | */ | 713 | */ |
714 | seqid->sequence->counter++; | 714 | seqid->sequence->counter++; |
715 | } | 715 | } |
716 | 716 | ||
717 | void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid) | 717 | void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid) |
718 | { | 718 | { |
719 | if (status == -NFS4ERR_BAD_SEQID) { | 719 | if (status == -NFS4ERR_BAD_SEQID) { |
720 | struct nfs4_state_owner *sp = container_of(seqid->sequence, | 720 | struct nfs4_state_owner *sp = container_of(seqid->sequence, |
721 | struct nfs4_state_owner, so_seqid); | 721 | struct nfs4_state_owner, so_seqid); |
722 | nfs4_drop_state_owner(sp); | 722 | nfs4_drop_state_owner(sp); |
723 | } | 723 | } |
724 | return nfs_increment_seqid(status, seqid); | 724 | return nfs_increment_seqid(status, seqid); |
725 | } | 725 | } |
726 | 726 | ||
727 | /* | 727 | /* |
728 | * Increment the seqid if the LOCK/LOCKU succeeded, or | 728 | * Increment the seqid if the LOCK/LOCKU succeeded, or |
729 | * failed with a seqid incrementing error - | 729 | * failed with a seqid incrementing error - |
730 | * see comments nfs_fs.h:seqid_mutating_error() | 730 | * see comments nfs_fs.h:seqid_mutating_error() |
731 | */ | 731 | */ |
732 | void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid) | 732 | void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid) |
733 | { | 733 | { |
734 | return nfs_increment_seqid(status, seqid); | 734 | return nfs_increment_seqid(status, seqid); |
735 | } | 735 | } |
736 | 736 | ||
737 | int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task) | 737 | int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task) |
738 | { | 738 | { |
739 | struct rpc_sequence *sequence = seqid->sequence->sequence; | 739 | struct rpc_sequence *sequence = seqid->sequence->sequence; |
740 | int status = 0; | 740 | int status = 0; |
741 | 741 | ||
742 | if (sequence->list.next == &seqid->list) | 742 | if (sequence->list.next == &seqid->list) |
743 | goto out; | 743 | goto out; |
744 | spin_lock(&sequence->lock); | 744 | spin_lock(&sequence->lock); |
745 | if (sequence->list.next != &seqid->list) { | 745 | if (sequence->list.next != &seqid->list) { |
746 | rpc_sleep_on(&sequence->wait, task, NULL, NULL); | 746 | rpc_sleep_on(&sequence->wait, task, NULL, NULL); |
747 | status = -EAGAIN; | 747 | status = -EAGAIN; |
748 | } | 748 | } |
749 | spin_unlock(&sequence->lock); | 749 | spin_unlock(&sequence->lock); |
750 | out: | 750 | out: |
751 | return status; | 751 | return status; |
752 | } | 752 | } |
753 | 753 | ||
754 | static int reclaimer(void *); | 754 | static int reclaimer(void *); |
755 | 755 | ||
756 | static inline void nfs4_clear_recover_bit(struct nfs4_client *clp) | 756 | static inline void nfs4_clear_recover_bit(struct nfs4_client *clp) |
757 | { | 757 | { |
758 | smp_mb__before_clear_bit(); | 758 | smp_mb__before_clear_bit(); |
759 | clear_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state); | 759 | clear_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state); |
760 | smp_mb__after_clear_bit(); | 760 | smp_mb__after_clear_bit(); |
761 | wake_up_bit(&clp->cl_state, NFS4CLNT_STATE_RECOVER); | 761 | wake_up_bit(&clp->cl_state, NFS4CLNT_STATE_RECOVER); |
762 | rpc_wake_up(&clp->cl_rpcwaitq); | 762 | rpc_wake_up(&clp->cl_rpcwaitq); |
763 | } | 763 | } |
764 | 764 | ||
765 | /* | 765 | /* |
766 | * State recovery routine | 766 | * State recovery routine |
767 | */ | 767 | */ |
768 | static void nfs4_recover_state(struct nfs4_client *clp) | 768 | static void nfs4_recover_state(struct nfs4_client *clp) |
769 | { | 769 | { |
770 | struct task_struct *task; | 770 | struct task_struct *task; |
771 | 771 | ||
772 | __module_get(THIS_MODULE); | 772 | __module_get(THIS_MODULE); |
773 | atomic_inc(&clp->cl_count); | 773 | atomic_inc(&clp->cl_count); |
774 | task = kthread_run(reclaimer, clp, "%u.%u.%u.%u-reclaim", | 774 | task = kthread_run(reclaimer, clp, "%u.%u.%u.%u-reclaim", |
775 | NIPQUAD(clp->cl_addr)); | 775 | NIPQUAD(clp->cl_addr)); |
776 | if (!IS_ERR(task)) | 776 | if (!IS_ERR(task)) |
777 | return; | 777 | return; |
778 | nfs4_clear_recover_bit(clp); | 778 | nfs4_clear_recover_bit(clp); |
779 | nfs4_put_client(clp); | 779 | nfs4_put_client(clp); |
780 | module_put(THIS_MODULE); | 780 | module_put(THIS_MODULE); |
781 | } | 781 | } |
782 | 782 | ||
783 | /* | 783 | /* |
784 | * Schedule a state recovery attempt | 784 | * Schedule a state recovery attempt |
785 | */ | 785 | */ |
786 | void nfs4_schedule_state_recovery(struct nfs4_client *clp) | 786 | void nfs4_schedule_state_recovery(struct nfs4_client *clp) |
787 | { | 787 | { |
788 | if (!clp) | 788 | if (!clp) |
789 | return; | 789 | return; |
790 | if (test_and_set_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state) == 0) | 790 | if (test_and_set_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state) == 0) |
791 | nfs4_recover_state(clp); | 791 | nfs4_recover_state(clp); |
792 | } | 792 | } |
793 | 793 | ||
794 | static int nfs4_reclaim_locks(struct nfs4_state_recovery_ops *ops, struct nfs4_state *state) | 794 | static int nfs4_reclaim_locks(struct nfs4_state_recovery_ops *ops, struct nfs4_state *state) |
795 | { | 795 | { |
796 | struct inode *inode = state->inode; | 796 | struct inode *inode = state->inode; |
797 | struct file_lock *fl; | 797 | struct file_lock *fl; |
798 | int status = 0; | 798 | int status = 0; |
799 | 799 | ||
800 | for (fl = inode->i_flock; fl != 0; fl = fl->fl_next) { | 800 | for (fl = inode->i_flock; fl != 0; fl = fl->fl_next) { |
801 | if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) | 801 | if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) |
802 | continue; | 802 | continue; |
803 | if (((struct nfs_open_context *)fl->fl_file->private_data)->state != state) | 803 | if (((struct nfs_open_context *)fl->fl_file->private_data)->state != state) |
804 | continue; | 804 | continue; |
805 | status = ops->recover_lock(state, fl); | 805 | status = ops->recover_lock(state, fl); |
806 | if (status >= 0) | 806 | if (status >= 0) |
807 | continue; | 807 | continue; |
808 | switch (status) { | 808 | switch (status) { |
809 | default: | 809 | default: |
810 | printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", | 810 | printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", |
811 | __FUNCTION__, status); | 811 | __FUNCTION__, status); |
812 | case -NFS4ERR_EXPIRED: | 812 | case -NFS4ERR_EXPIRED: |
813 | case -NFS4ERR_NO_GRACE: | 813 | case -NFS4ERR_NO_GRACE: |
814 | case -NFS4ERR_RECLAIM_BAD: | 814 | case -NFS4ERR_RECLAIM_BAD: |
815 | case -NFS4ERR_RECLAIM_CONFLICT: | 815 | case -NFS4ERR_RECLAIM_CONFLICT: |
816 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ | 816 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
817 | break; | 817 | break; |
818 | case -NFS4ERR_STALE_CLIENTID: | 818 | case -NFS4ERR_STALE_CLIENTID: |
819 | goto out_err; | 819 | goto out_err; |
820 | } | 820 | } |
821 | } | 821 | } |
822 | return 0; | 822 | return 0; |
823 | out_err: | 823 | out_err: |
824 | return status; | 824 | return status; |
825 | } | 825 | } |
826 | 826 | ||
827 | static int nfs4_reclaim_open_state(struct nfs4_state_recovery_ops *ops, struct nfs4_state_owner *sp) | 827 | static int nfs4_reclaim_open_state(struct nfs4_state_recovery_ops *ops, struct nfs4_state_owner *sp) |
828 | { | 828 | { |
829 | struct nfs4_state *state; | 829 | struct nfs4_state *state; |
830 | struct nfs4_lock_state *lock; | 830 | struct nfs4_lock_state *lock; |
831 | int status = 0; | 831 | int status = 0; |
832 | 832 | ||
833 | /* Note: we rely on the sp->so_states list being ordered | 833 | /* Note: we rely on the sp->so_states list being ordered |
834 | * so that we always reclaim open(O_RDWR) and/or open(O_WRITE) | 834 | * so that we always reclaim open(O_RDWR) and/or open(O_WRITE) |
835 | * states first. | 835 | * states first. |
836 | * This is needed to ensure that the server won't give us any | 836 | * This is needed to ensure that the server won't give us any |
837 | * read delegations that we have to return if, say, we are | 837 | * read delegations that we have to return if, say, we are |
838 | * recovering after a network partition or a reboot from a | 838 | * recovering after a network partition or a reboot from a |
839 | * server that doesn't support a grace period. | 839 | * server that doesn't support a grace period. |
840 | */ | 840 | */ |
841 | list_for_each_entry(state, &sp->so_states, open_states) { | 841 | list_for_each_entry(state, &sp->so_states, open_states) { |
842 | if (state->state == 0) | 842 | if (state->state == 0) |
843 | continue; | 843 | continue; |
844 | status = ops->recover_open(sp, state); | 844 | status = ops->recover_open(sp, state); |
845 | if (status >= 0) { | 845 | if (status >= 0) { |
846 | status = nfs4_reclaim_locks(ops, state); | 846 | status = nfs4_reclaim_locks(ops, state); |
847 | if (status < 0) | 847 | if (status < 0) |
848 | goto out_err; | 848 | goto out_err; |
849 | list_for_each_entry(lock, &state->lock_states, ls_locks) { | 849 | list_for_each_entry(lock, &state->lock_states, ls_locks) { |
850 | if (!(lock->ls_flags & NFS_LOCK_INITIALIZED)) | 850 | if (!(lock->ls_flags & NFS_LOCK_INITIALIZED)) |
851 | printk("%s: Lock reclaim failed!\n", | 851 | printk("%s: Lock reclaim failed!\n", |
852 | __FUNCTION__); | 852 | __FUNCTION__); |
853 | } | 853 | } |
854 | continue; | 854 | continue; |
855 | } | 855 | } |
856 | switch (status) { | 856 | switch (status) { |
857 | default: | 857 | default: |
858 | printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", | 858 | printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", |
859 | __FUNCTION__, status); | 859 | __FUNCTION__, status); |
860 | case -ENOENT: | 860 | case -ENOENT: |
861 | case -NFS4ERR_RECLAIM_BAD: | 861 | case -NFS4ERR_RECLAIM_BAD: |
862 | case -NFS4ERR_RECLAIM_CONFLICT: | 862 | case -NFS4ERR_RECLAIM_CONFLICT: |
863 | /* | 863 | /* |
864 | * Open state on this file cannot be recovered | 864 | * Open state on this file cannot be recovered |
865 | * All we can do is revert to using the zero stateid. | 865 | * All we can do is revert to using the zero stateid. |
866 | */ | 866 | */ |
867 | memset(state->stateid.data, 0, | 867 | memset(state->stateid.data, 0, |
868 | sizeof(state->stateid.data)); | 868 | sizeof(state->stateid.data)); |
869 | /* Mark the file as being 'closed' */ | 869 | /* Mark the file as being 'closed' */ |
870 | state->state = 0; | 870 | state->state = 0; |
871 | break; | 871 | break; |
872 | case -NFS4ERR_EXPIRED: | 872 | case -NFS4ERR_EXPIRED: |
873 | case -NFS4ERR_NO_GRACE: | 873 | case -NFS4ERR_NO_GRACE: |
874 | case -NFS4ERR_STALE_CLIENTID: | 874 | case -NFS4ERR_STALE_CLIENTID: |
875 | goto out_err; | 875 | goto out_err; |
876 | } | 876 | } |
877 | } | 877 | } |
878 | return 0; | 878 | return 0; |
879 | out_err: | 879 | out_err: |
880 | return status; | 880 | return status; |
881 | } | 881 | } |
882 | 882 | ||
883 | static void nfs4_state_mark_reclaim(struct nfs4_client *clp) | 883 | static void nfs4_state_mark_reclaim(struct nfs4_client *clp) |
884 | { | 884 | { |
885 | struct nfs4_state_owner *sp; | 885 | struct nfs4_state_owner *sp; |
886 | struct nfs4_state *state; | 886 | struct nfs4_state *state; |
887 | struct nfs4_lock_state *lock; | 887 | struct nfs4_lock_state *lock; |
888 | 888 | ||
889 | /* Reset all sequence ids to zero */ | 889 | /* Reset all sequence ids to zero */ |
890 | list_for_each_entry(sp, &clp->cl_state_owners, so_list) { | 890 | list_for_each_entry(sp, &clp->cl_state_owners, so_list) { |
891 | sp->so_seqid.counter = 0; | 891 | sp->so_seqid.counter = 0; |
892 | sp->so_seqid.flags = 0; | 892 | sp->so_seqid.flags = 0; |
893 | spin_lock(&sp->so_lock); | 893 | spin_lock(&sp->so_lock); |
894 | list_for_each_entry(state, &sp->so_states, open_states) { | 894 | list_for_each_entry(state, &sp->so_states, open_states) { |
895 | list_for_each_entry(lock, &state->lock_states, ls_locks) { | 895 | list_for_each_entry(lock, &state->lock_states, ls_locks) { |
896 | lock->ls_seqid.counter = 0; | 896 | lock->ls_seqid.counter = 0; |
897 | lock->ls_seqid.flags = 0; | 897 | lock->ls_seqid.flags = 0; |
898 | lock->ls_flags &= ~NFS_LOCK_INITIALIZED; | 898 | lock->ls_flags &= ~NFS_LOCK_INITIALIZED; |
899 | } | 899 | } |
900 | } | 900 | } |
901 | spin_unlock(&sp->so_lock); | 901 | spin_unlock(&sp->so_lock); |
902 | } | 902 | } |
903 | } | 903 | } |
904 | 904 | ||
905 | static int reclaimer(void *ptr) | 905 | static int reclaimer(void *ptr) |
906 | { | 906 | { |
907 | struct nfs4_client *clp = ptr; | 907 | struct nfs4_client *clp = ptr; |
908 | struct nfs4_state_owner *sp; | 908 | struct nfs4_state_owner *sp; |
909 | struct nfs4_state_recovery_ops *ops; | 909 | struct nfs4_state_recovery_ops *ops; |
910 | struct rpc_cred *cred; | 910 | struct rpc_cred *cred; |
911 | int status = 0; | 911 | int status = 0; |
912 | 912 | ||
913 | allow_signal(SIGKILL); | 913 | allow_signal(SIGKILL); |
914 | 914 | ||
915 | /* Ensure exclusive access to NFSv4 state */ | 915 | /* Ensure exclusive access to NFSv4 state */ |
916 | lock_kernel(); | 916 | lock_kernel(); |
917 | down_write(&clp->cl_sem); | 917 | down_write(&clp->cl_sem); |
918 | /* Are there any NFS mounts out there? */ | 918 | /* Are there any NFS mounts out there? */ |
919 | if (list_empty(&clp->cl_superblocks)) | 919 | if (list_empty(&clp->cl_superblocks)) |
920 | goto out; | 920 | goto out; |
921 | restart_loop: | 921 | restart_loop: |
922 | ops = &nfs4_network_partition_recovery_ops; | 922 | ops = &nfs4_network_partition_recovery_ops; |
923 | /* Are there any open files on this volume? */ | 923 | /* Are there any open files on this volume? */ |
924 | cred = nfs4_get_renew_cred(clp); | 924 | cred = nfs4_get_renew_cred(clp); |
925 | if (cred != NULL) { | 925 | if (cred != NULL) { |
926 | /* Yes there are: try to renew the old lease */ | 926 | /* Yes there are: try to renew the old lease */ |
927 | status = nfs4_proc_renew(clp, cred); | 927 | status = nfs4_proc_renew(clp, cred); |
928 | switch (status) { | 928 | switch (status) { |
929 | case 0: | 929 | case 0: |
930 | case -NFS4ERR_CB_PATH_DOWN: | 930 | case -NFS4ERR_CB_PATH_DOWN: |
931 | put_rpccred(cred); | 931 | put_rpccred(cred); |
932 | goto out; | 932 | goto out; |
933 | case -NFS4ERR_STALE_CLIENTID: | 933 | case -NFS4ERR_STALE_CLIENTID: |
934 | case -NFS4ERR_LEASE_MOVED: | 934 | case -NFS4ERR_LEASE_MOVED: |
935 | ops = &nfs4_reboot_recovery_ops; | 935 | ops = &nfs4_reboot_recovery_ops; |
936 | } | 936 | } |
937 | } else { | 937 | } else { |
938 | /* "reboot" to ensure we clear all state on the server */ | 938 | /* "reboot" to ensure we clear all state on the server */ |
939 | clp->cl_boot_time = CURRENT_TIME; | 939 | clp->cl_boot_time = CURRENT_TIME; |
940 | cred = nfs4_get_setclientid_cred(clp); | 940 | cred = nfs4_get_setclientid_cred(clp); |
941 | } | 941 | } |
942 | /* We're going to have to re-establish a clientid */ | 942 | /* We're going to have to re-establish a clientid */ |
943 | nfs4_state_mark_reclaim(clp); | 943 | nfs4_state_mark_reclaim(clp); |
944 | status = -ENOENT; | 944 | status = -ENOENT; |
945 | if (cred != NULL) { | 945 | if (cred != NULL) { |
946 | status = nfs4_init_client(clp, cred); | 946 | status = nfs4_init_client(clp, cred); |
947 | put_rpccred(cred); | 947 | put_rpccred(cred); |
948 | } | 948 | } |
949 | if (status) | 949 | if (status) |
950 | goto out_error; | 950 | goto out_error; |
951 | /* Mark all delegations for reclaim */ | 951 | /* Mark all delegations for reclaim */ |
952 | nfs_delegation_mark_reclaim(clp); | 952 | nfs_delegation_mark_reclaim(clp); |
953 | /* Note: list is protected by exclusive lock on cl->cl_sem */ | 953 | /* Note: list is protected by exclusive lock on cl->cl_sem */ |
954 | list_for_each_entry(sp, &clp->cl_state_owners, so_list) { | 954 | list_for_each_entry(sp, &clp->cl_state_owners, so_list) { |
955 | status = nfs4_reclaim_open_state(ops, sp); | 955 | status = nfs4_reclaim_open_state(ops, sp); |
956 | if (status < 0) { | 956 | if (status < 0) { |
957 | if (status == -NFS4ERR_NO_GRACE) { | 957 | if (status == -NFS4ERR_NO_GRACE) { |
958 | ops = &nfs4_network_partition_recovery_ops; | 958 | ops = &nfs4_network_partition_recovery_ops; |
959 | status = nfs4_reclaim_open_state(ops, sp); | 959 | status = nfs4_reclaim_open_state(ops, sp); |
960 | } | 960 | } |
961 | if (status == -NFS4ERR_STALE_CLIENTID) | 961 | if (status == -NFS4ERR_STALE_CLIENTID) |
962 | goto restart_loop; | 962 | goto restart_loop; |
963 | if (status == -NFS4ERR_EXPIRED) | 963 | if (status == -NFS4ERR_EXPIRED) |
964 | goto restart_loop; | 964 | goto restart_loop; |
965 | } | 965 | } |
966 | } | 966 | } |
967 | nfs_delegation_reap_unclaimed(clp); | 967 | nfs_delegation_reap_unclaimed(clp); |
968 | out: | 968 | out: |
969 | up_write(&clp->cl_sem); | 969 | up_write(&clp->cl_sem); |
970 | unlock_kernel(); | 970 | unlock_kernel(); |
971 | if (status == -NFS4ERR_CB_PATH_DOWN) | 971 | if (status == -NFS4ERR_CB_PATH_DOWN) |
972 | nfs_handle_cb_pathdown(clp); | 972 | nfs_handle_cb_pathdown(clp); |
973 | nfs4_clear_recover_bit(clp); | 973 | nfs4_clear_recover_bit(clp); |
974 | nfs4_put_client(clp); | 974 | nfs4_put_client(clp); |
975 | module_put_and_exit(0); | 975 | module_put_and_exit(0); |
976 | return 0; | 976 | return 0; |
977 | out_error: | 977 | out_error: |
978 | printk(KERN_WARNING "Error: state recovery failed on NFSv4 server %u.%u.%u.%u with error %d\n", | 978 | printk(KERN_WARNING "Error: state recovery failed on NFSv4 server %u.%u.%u.%u with error %d\n", |
979 | NIPQUAD(clp->cl_addr.s_addr), -status); | 979 | NIPQUAD(clp->cl_addr.s_addr), -status); |
980 | set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); | ||
980 | goto out; | 981 | goto out; |
981 | } | 982 | } |
982 | 983 | ||
983 | /* | 984 | /* |
984 | * Local variables: | 985 | * Local variables: |
985 | * c-basic-offset: 8 | 986 | * c-basic-offset: 8 |
986 | * End: | 987 | * End: |
987 | */ | 988 | */ |
988 | 989 |