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