Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/nfs3proc.c |
| 3 | * |
| 4 | * Client-side NFSv3 procedures stubs. |
| 5 | * |
| 6 | * Copyright (C) 1997, Olaf Kirch |
| 7 | */ |
| 8 | |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/utsname.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/sunrpc/clnt.h> |
| 14 | #include <linux/nfs.h> |
| 15 | #include <linux/nfs3.h> |
| 16 | #include <linux/nfs_fs.h> |
| 17 | #include <linux/nfs_page.h> |
| 18 | #include <linux/lockd/bind.h> |
| 19 | #include <linux/smp_lock.h> |
Andreas Gruenbacher | b7fa055 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 20 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 22 | #include "iostat.h" |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 23 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | /* A wrapper to handle the EJUKEBOX error message */ |
| 28 | static int |
| 29 | nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) |
| 30 | { |
| 31 | sigset_t oldset; |
| 32 | int res; |
| 33 | rpc_clnt_sigmask(clnt, &oldset); |
| 34 | do { |
| 35 | res = rpc_call_sync(clnt, msg, flags); |
| 36 | if (res != -EJUKEBOX) |
| 37 | break; |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 38 | schedule_timeout_interruptible(NFS_JUKEBOX_RETRY_TIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | res = -ERESTARTSYS; |
| 40 | } while (!signalled()); |
| 41 | rpc_clnt_sigunmask(clnt, &oldset); |
| 42 | return res; |
| 43 | } |
| 44 | |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 45 | #define rpc_call_sync(clnt, msg, flags) nfs3_rpc_wrapper(clnt, msg, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | static int |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 48 | nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | if (task->tk_status != -EJUKEBOX) |
| 51 | return 0; |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 52 | nfs_inc_stats(inode, NFSIOS_DELAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | task->tk_status = 0; |
| 54 | rpc_restart_call(task); |
| 55 | rpc_delay(task, NFS_JUKEBOX_RETRY_TIME); |
| 56 | return 1; |
| 57 | } |
| 58 | |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 59 | static int |
| 60 | do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle, |
| 61 | struct nfs_fsinfo *info) |
| 62 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 63 | struct rpc_message msg = { |
| 64 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO], |
| 65 | .rpc_argp = fhandle, |
| 66 | .rpc_resp = info, |
| 67 | }; |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 68 | int status; |
| 69 | |
| 70 | dprintk("%s: call fsinfo\n", __FUNCTION__); |
| 71 | nfs_fattr_init(info->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 72 | status = rpc_call_sync(client, &msg, 0); |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 73 | dprintk("%s: reply fsinfo: %d\n", __FUNCTION__, status); |
| 74 | if (!(info->fattr->valid & NFS_ATTR_FATTR)) { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 75 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; |
| 76 | msg.rpc_resp = info->fattr; |
| 77 | status = rpc_call_sync(client, &msg, 0); |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 78 | dprintk("%s: reply getattr: %d\n", __FUNCTION__, status); |
| 79 | } |
| 80 | return status; |
| 81 | } |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 84 | * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | */ |
| 86 | static int |
| 87 | nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 88 | struct nfs_fsinfo *info) |
| 89 | { |
| 90 | int status; |
| 91 | |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 92 | status = do_proc_get_root(server->client, fhandle, info); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 93 | if (status && server->nfs_client->cl_rpcclient != server->client) |
| 94 | status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | return status; |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * One function for each procedure in the NFS protocol. |
| 100 | */ |
| 101 | static int |
| 102 | nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 103 | struct nfs_fattr *fattr) |
| 104 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 105 | struct rpc_message msg = { |
| 106 | .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR], |
| 107 | .rpc_argp = fhandle, |
| 108 | .rpc_resp = fattr, |
| 109 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | int status; |
| 111 | |
| 112 | dprintk("NFS call getattr\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 113 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 114 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | dprintk("NFS reply getattr: %d\n", status); |
| 116 | return status; |
| 117 | } |
| 118 | |
| 119 | static int |
| 120 | nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 121 | struct iattr *sattr) |
| 122 | { |
| 123 | struct inode *inode = dentry->d_inode; |
| 124 | struct nfs3_sattrargs arg = { |
| 125 | .fh = NFS_FH(inode), |
| 126 | .sattr = sattr, |
| 127 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 128 | struct rpc_message msg = { |
| 129 | .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR], |
| 130 | .rpc_argp = &arg, |
| 131 | .rpc_resp = fattr, |
| 132 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | int status; |
| 134 | |
| 135 | dprintk("NFS call setattr\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 136 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 137 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 138 | if (status == 0) |
| 139 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | dprintk("NFS reply setattr: %d\n", status); |
| 141 | return status; |
| 142 | } |
| 143 | |
| 144 | static int |
| 145 | nfs3_proc_lookup(struct inode *dir, struct qstr *name, |
| 146 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 147 | { |
| 148 | struct nfs_fattr dir_attr; |
| 149 | struct nfs3_diropargs arg = { |
| 150 | .fh = NFS_FH(dir), |
| 151 | .name = name->name, |
| 152 | .len = name->len |
| 153 | }; |
| 154 | struct nfs3_diropres res = { |
| 155 | .dir_attr = &dir_attr, |
| 156 | .fh = fhandle, |
| 157 | .fattr = fattr |
| 158 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 159 | struct rpc_message msg = { |
| 160 | .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP], |
| 161 | .rpc_argp = &arg, |
| 162 | .rpc_resp = &res, |
| 163 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | int status; |
| 165 | |
| 166 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 167 | nfs_fattr_init(&dir_attr); |
| 168 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 169 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 170 | if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) { |
| 171 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; |
| 172 | msg.rpc_argp = fhandle; |
| 173 | msg.rpc_resp = fattr; |
| 174 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | dprintk("NFS reply lookup: %d\n", status); |
| 177 | if (status >= 0) |
| 178 | status = nfs_refresh_inode(dir, &dir_attr); |
| 179 | return status; |
| 180 | } |
| 181 | |
| 182 | static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 183 | { |
| 184 | struct nfs_fattr fattr; |
| 185 | struct nfs3_accessargs arg = { |
| 186 | .fh = NFS_FH(inode), |
| 187 | }; |
| 188 | struct nfs3_accessres res = { |
| 189 | .fattr = &fattr, |
| 190 | }; |
| 191 | struct rpc_message msg = { |
| 192 | .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS], |
| 193 | .rpc_argp = &arg, |
| 194 | .rpc_resp = &res, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 195 | .rpc_cred = entry->cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | }; |
| 197 | int mode = entry->mask; |
| 198 | int status; |
| 199 | |
| 200 | dprintk("NFS call access\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | if (mode & MAY_READ) |
| 203 | arg.access |= NFS3_ACCESS_READ; |
| 204 | if (S_ISDIR(inode->i_mode)) { |
| 205 | if (mode & MAY_WRITE) |
| 206 | arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE; |
| 207 | if (mode & MAY_EXEC) |
| 208 | arg.access |= NFS3_ACCESS_LOOKUP; |
| 209 | } else { |
| 210 | if (mode & MAY_WRITE) |
| 211 | arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND; |
| 212 | if (mode & MAY_EXEC) |
| 213 | arg.access |= NFS3_ACCESS_EXECUTE; |
| 214 | } |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 215 | nfs_fattr_init(&fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
| 217 | nfs_refresh_inode(inode, &fattr); |
| 218 | if (status == 0) { |
| 219 | entry->mask = 0; |
| 220 | if (res.access & NFS3_ACCESS_READ) |
| 221 | entry->mask |= MAY_READ; |
| 222 | if (res.access & (NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE)) |
| 223 | entry->mask |= MAY_WRITE; |
| 224 | if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE)) |
| 225 | entry->mask |= MAY_EXEC; |
| 226 | } |
| 227 | dprintk("NFS reply access: %d\n", status); |
| 228 | return status; |
| 229 | } |
| 230 | |
| 231 | static int nfs3_proc_readlink(struct inode *inode, struct page *page, |
| 232 | unsigned int pgbase, unsigned int pglen) |
| 233 | { |
| 234 | struct nfs_fattr fattr; |
| 235 | struct nfs3_readlinkargs args = { |
| 236 | .fh = NFS_FH(inode), |
| 237 | .pgbase = pgbase, |
| 238 | .pglen = pglen, |
| 239 | .pages = &page |
| 240 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 241 | struct rpc_message msg = { |
| 242 | .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK], |
| 243 | .rpc_argp = &args, |
| 244 | .rpc_resp = &fattr, |
| 245 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | int status; |
| 247 | |
| 248 | dprintk("NFS call readlink\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 249 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 250 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | nfs_refresh_inode(inode, &fattr); |
| 252 | dprintk("NFS reply readlink: %d\n", status); |
| 253 | return status; |
| 254 | } |
| 255 | |
| 256 | static int nfs3_proc_read(struct nfs_read_data *rdata) |
| 257 | { |
| 258 | int flags = rdata->flags; |
| 259 | struct inode * inode = rdata->inode; |
| 260 | struct nfs_fattr * fattr = rdata->res.fattr; |
| 261 | struct rpc_message msg = { |
| 262 | .rpc_proc = &nfs3_procedures[NFS3PROC_READ], |
| 263 | .rpc_argp = &rdata->args, |
| 264 | .rpc_resp = &rdata->res, |
| 265 | .rpc_cred = rdata->cred, |
| 266 | }; |
| 267 | int status; |
| 268 | |
| 269 | dprintk("NFS call read %d @ %Ld\n", rdata->args.count, |
| 270 | (long long) rdata->args.offset); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 271 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags); |
| 273 | if (status >= 0) |
| 274 | nfs_refresh_inode(inode, fattr); |
| 275 | dprintk("NFS reply read: %d\n", status); |
| 276 | return status; |
| 277 | } |
| 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | /* |
| 280 | * Create a regular file. |
| 281 | * For now, we don't implement O_EXCL. |
| 282 | */ |
| 283 | static int |
| 284 | nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 285 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
| 287 | struct nfs_fh fhandle; |
| 288 | struct nfs_fattr fattr; |
| 289 | struct nfs_fattr dir_attr; |
| 290 | struct nfs3_createargs arg = { |
| 291 | .fh = NFS_FH(dir), |
| 292 | .name = dentry->d_name.name, |
| 293 | .len = dentry->d_name.len, |
| 294 | .sattr = sattr, |
| 295 | }; |
| 296 | struct nfs3_diropres res = { |
| 297 | .dir_attr = &dir_attr, |
| 298 | .fh = &fhandle, |
| 299 | .fattr = &fattr |
| 300 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 301 | struct rpc_message msg = { |
| 302 | .rpc_proc = &nfs3_procedures[NFS3PROC_CREATE], |
| 303 | .rpc_argp = &arg, |
| 304 | .rpc_resp = &res, |
| 305 | }; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 306 | mode_t mode = sattr->ia_mode; |
| 307 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | dprintk("NFS call create %s\n", dentry->d_name.name); |
| 310 | arg.createmode = NFS3_CREATE_UNCHECKED; |
| 311 | if (flags & O_EXCL) { |
| 312 | arg.createmode = NFS3_CREATE_EXCLUSIVE; |
| 313 | arg.verifier[0] = jiffies; |
| 314 | arg.verifier[1] = current->pid; |
| 315 | } |
| 316 | |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 317 | sattr->ia_mode &= ~current->fs->umask; |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | again: |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 320 | nfs_fattr_init(&dir_attr); |
| 321 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 322 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 323 | nfs_refresh_inode(dir, &dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | /* If the server doesn't support the exclusive creation semantics, |
| 326 | * try again with simple 'guarded' mode. */ |
Andy Ryan | 46b9f8e | 2006-11-07 14:36:26 -0600 | [diff] [blame] | 327 | if (status == -ENOTSUPP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | switch (arg.createmode) { |
| 329 | case NFS3_CREATE_EXCLUSIVE: |
| 330 | arg.createmode = NFS3_CREATE_GUARDED; |
| 331 | break; |
| 332 | |
| 333 | case NFS3_CREATE_GUARDED: |
| 334 | arg.createmode = NFS3_CREATE_UNCHECKED; |
| 335 | break; |
| 336 | |
| 337 | case NFS3_CREATE_UNCHECKED: |
| 338 | goto out; |
| 339 | } |
| 340 | goto again; |
| 341 | } |
| 342 | |
| 343 | if (status == 0) |
| 344 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 345 | if (status != 0) |
| 346 | goto out; |
| 347 | |
| 348 | /* When we created the file with exclusive semantics, make |
| 349 | * sure we set the attributes afterwards. */ |
| 350 | if (arg.createmode == NFS3_CREATE_EXCLUSIVE) { |
| 351 | dprintk("NFS call setattr (post-create)\n"); |
| 352 | |
| 353 | if (!(sattr->ia_valid & ATTR_ATIME_SET)) |
| 354 | sattr->ia_valid |= ATTR_ATIME; |
| 355 | if (!(sattr->ia_valid & ATTR_MTIME_SET)) |
| 356 | sattr->ia_valid |= ATTR_MTIME; |
| 357 | |
| 358 | /* Note: we could use a guarded setattr here, but I'm |
| 359 | * not sure this buys us anything (and I'd have |
| 360 | * to revamp the NFSv3 XDR code) */ |
| 361 | status = nfs3_proc_setattr(dentry, &fattr, sattr); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 362 | if (status == 0) |
| 363 | nfs_setattr_update_inode(dentry->d_inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | nfs_refresh_inode(dentry->d_inode, &fattr); |
| 365 | dprintk("NFS reply setattr (post-create): %d\n", status); |
| 366 | } |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 367 | if (status != 0) |
| 368 | goto out; |
| 369 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | out: |
| 371 | dprintk("NFS reply create: %d\n", status); |
| 372 | return status; |
| 373 | } |
| 374 | |
| 375 | static int |
| 376 | nfs3_proc_remove(struct inode *dir, struct qstr *name) |
| 377 | { |
| 378 | struct nfs_fattr dir_attr; |
| 379 | struct nfs3_diropargs arg = { |
| 380 | .fh = NFS_FH(dir), |
| 381 | .name = name->name, |
| 382 | .len = name->len |
| 383 | }; |
| 384 | struct rpc_message msg = { |
| 385 | .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE], |
| 386 | .rpc_argp = &arg, |
| 387 | .rpc_resp = &dir_attr, |
| 388 | }; |
| 389 | int status; |
| 390 | |
| 391 | dprintk("NFS call remove %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 392 | nfs_fattr_init(&dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 394 | nfs_post_op_update_inode(dir, &dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | dprintk("NFS reply remove: %d\n", status); |
| 396 | return status; |
| 397 | } |
| 398 | |
| 399 | static int |
| 400 | nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name) |
| 401 | { |
| 402 | struct unlinkxdr { |
| 403 | struct nfs3_diropargs arg; |
| 404 | struct nfs_fattr res; |
| 405 | } *ptr; |
| 406 | |
Panagiotis Issaris | f52720c | 2006-09-27 01:49:39 -0700 | [diff] [blame] | 407 | ptr = kmalloc(sizeof(*ptr), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | if (!ptr) |
| 409 | return -ENOMEM; |
| 410 | ptr->arg.fh = NFS_FH(dir->d_inode); |
| 411 | ptr->arg.name = name->name; |
| 412 | ptr->arg.len = name->len; |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 413 | nfs_fattr_init(&ptr->res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE]; |
| 415 | msg->rpc_argp = &ptr->arg; |
| 416 | msg->rpc_resp = &ptr->res; |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static int |
| 421 | nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task) |
| 422 | { |
| 423 | struct rpc_message *msg = &task->tk_msg; |
| 424 | struct nfs_fattr *dir_attr; |
| 425 | |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 426 | if (nfs3_async_handle_jukebox(task, dir->d_inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | return 1; |
| 428 | if (msg->rpc_argp) { |
| 429 | dir_attr = (struct nfs_fattr*)msg->rpc_resp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 430 | nfs_post_op_update_inode(dir->d_inode, dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | kfree(msg->rpc_argp); |
| 432 | } |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | static int |
| 437 | nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 438 | struct inode *new_dir, struct qstr *new_name) |
| 439 | { |
| 440 | struct nfs_fattr old_dir_attr, new_dir_attr; |
| 441 | struct nfs3_renameargs arg = { |
| 442 | .fromfh = NFS_FH(old_dir), |
| 443 | .fromname = old_name->name, |
| 444 | .fromlen = old_name->len, |
| 445 | .tofh = NFS_FH(new_dir), |
| 446 | .toname = new_name->name, |
| 447 | .tolen = new_name->len |
| 448 | }; |
| 449 | struct nfs3_renameres res = { |
| 450 | .fromattr = &old_dir_attr, |
| 451 | .toattr = &new_dir_attr |
| 452 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 453 | struct rpc_message msg = { |
| 454 | .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME], |
| 455 | .rpc_argp = &arg, |
| 456 | .rpc_resp = &res, |
| 457 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | int status; |
| 459 | |
| 460 | dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 461 | nfs_fattr_init(&old_dir_attr); |
| 462 | nfs_fattr_init(&new_dir_attr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 463 | status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 464 | nfs_post_op_update_inode(old_dir, &old_dir_attr); |
| 465 | nfs_post_op_update_inode(new_dir, &new_dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | dprintk("NFS reply rename: %d\n", status); |
| 467 | return status; |
| 468 | } |
| 469 | |
| 470 | static int |
| 471 | nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 472 | { |
| 473 | struct nfs_fattr dir_attr, fattr; |
| 474 | struct nfs3_linkargs arg = { |
| 475 | .fromfh = NFS_FH(inode), |
| 476 | .tofh = NFS_FH(dir), |
| 477 | .toname = name->name, |
| 478 | .tolen = name->len |
| 479 | }; |
| 480 | struct nfs3_linkres res = { |
| 481 | .dir_attr = &dir_attr, |
| 482 | .fattr = &fattr |
| 483 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 484 | struct rpc_message msg = { |
| 485 | .rpc_proc = &nfs3_procedures[NFS3PROC_LINK], |
| 486 | .rpc_argp = &arg, |
| 487 | .rpc_resp = &res, |
| 488 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | int status; |
| 490 | |
| 491 | dprintk("NFS call link %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 492 | nfs_fattr_init(&dir_attr); |
| 493 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 494 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 495 | nfs_post_op_update_inode(dir, &dir_attr); |
| 496 | nfs_post_op_update_inode(inode, &fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | dprintk("NFS reply link: %d\n", status); |
| 498 | return status; |
| 499 | } |
| 500 | |
| 501 | static int |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 502 | nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, |
| 503 | unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 505 | struct nfs_fh fhandle; |
| 506 | struct nfs_fattr fattr, dir_attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | struct nfs3_symlinkargs arg = { |
| 508 | .fromfh = NFS_FH(dir), |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 509 | .fromname = dentry->d_name.name, |
| 510 | .fromlen = dentry->d_name.len, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 511 | .pages = &page, |
| 512 | .pathlen = len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | .sattr = sattr |
| 514 | }; |
| 515 | struct nfs3_diropres res = { |
| 516 | .dir_attr = &dir_attr, |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 517 | .fh = &fhandle, |
| 518 | .fattr = &fattr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 520 | struct rpc_message msg = { |
| 521 | .rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK], |
| 522 | .rpc_argp = &arg, |
| 523 | .rpc_resp = &res, |
| 524 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | int status; |
| 526 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 527 | if (len > NFS3_MAXPATHLEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | return -ENAMETOOLONG; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 529 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 530 | dprintk("NFS call symlink %s\n", dentry->d_name.name); |
| 531 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 532 | nfs_fattr_init(&dir_attr); |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 533 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 534 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 535 | nfs_post_op_update_inode(dir, &dir_attr); |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 536 | if (status != 0) |
| 537 | goto out; |
| 538 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 539 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | dprintk("NFS reply symlink: %d\n", status); |
| 541 | return status; |
| 542 | } |
| 543 | |
| 544 | static int |
| 545 | nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) |
| 546 | { |
| 547 | struct nfs_fh fhandle; |
| 548 | struct nfs_fattr fattr, dir_attr; |
| 549 | struct nfs3_mkdirargs arg = { |
| 550 | .fh = NFS_FH(dir), |
| 551 | .name = dentry->d_name.name, |
| 552 | .len = dentry->d_name.len, |
| 553 | .sattr = sattr |
| 554 | }; |
| 555 | struct nfs3_diropres res = { |
| 556 | .dir_attr = &dir_attr, |
| 557 | .fh = &fhandle, |
| 558 | .fattr = &fattr |
| 559 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 560 | struct rpc_message msg = { |
| 561 | .rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR], |
| 562 | .rpc_argp = &arg, |
| 563 | .rpc_resp = &res, |
| 564 | }; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 565 | int mode = sattr->ia_mode; |
| 566 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | dprintk("NFS call mkdir %s\n", dentry->d_name.name); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 569 | |
| 570 | sattr->ia_mode &= ~current->fs->umask; |
| 571 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 572 | nfs_fattr_init(&dir_attr); |
| 573 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 574 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 575 | nfs_post_op_update_inode(dir, &dir_attr); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 576 | if (status != 0) |
| 577 | goto out; |
| 578 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 579 | if (status != 0) |
| 580 | goto out; |
| 581 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); |
| 582 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | dprintk("NFS reply mkdir: %d\n", status); |
| 584 | return status; |
| 585 | } |
| 586 | |
| 587 | static int |
| 588 | nfs3_proc_rmdir(struct inode *dir, struct qstr *name) |
| 589 | { |
| 590 | struct nfs_fattr dir_attr; |
| 591 | struct nfs3_diropargs arg = { |
| 592 | .fh = NFS_FH(dir), |
| 593 | .name = name->name, |
| 594 | .len = name->len |
| 595 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 596 | struct rpc_message msg = { |
| 597 | .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR], |
| 598 | .rpc_argp = &arg, |
| 599 | .rpc_resp = &dir_attr, |
| 600 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | int status; |
| 602 | |
| 603 | dprintk("NFS call rmdir %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 604 | nfs_fattr_init(&dir_attr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 605 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 606 | nfs_post_op_update_inode(dir, &dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | dprintk("NFS reply rmdir: %d\n", status); |
| 608 | return status; |
| 609 | } |
| 610 | |
| 611 | /* |
| 612 | * The READDIR implementation is somewhat hackish - we pass the user buffer |
| 613 | * to the encode function, which installs it in the receive iovec. |
| 614 | * The decode function itself doesn't perform any decoding, it just makes |
| 615 | * sure the reply is syntactically correct. |
| 616 | * |
| 617 | * Also note that this implementation handles both plain readdir and |
| 618 | * readdirplus. |
| 619 | */ |
| 620 | static int |
| 621 | nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 622 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 623 | { |
| 624 | struct inode *dir = dentry->d_inode; |
| 625 | struct nfs_fattr dir_attr; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 626 | __be32 *verf = NFS_COOKIEVERF(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | struct nfs3_readdirargs arg = { |
| 628 | .fh = NFS_FH(dir), |
| 629 | .cookie = cookie, |
| 630 | .verf = {verf[0], verf[1]}, |
| 631 | .plus = plus, |
| 632 | .count = count, |
| 633 | .pages = &page |
| 634 | }; |
| 635 | struct nfs3_readdirres res = { |
| 636 | .dir_attr = &dir_attr, |
| 637 | .verf = verf, |
| 638 | .plus = plus |
| 639 | }; |
| 640 | struct rpc_message msg = { |
| 641 | .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR], |
| 642 | .rpc_argp = &arg, |
| 643 | .rpc_resp = &res, |
| 644 | .rpc_cred = cred |
| 645 | }; |
| 646 | int status; |
| 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (plus) |
| 649 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS]; |
| 650 | |
| 651 | dprintk("NFS call readdir%s %d\n", |
| 652 | plus? "plus" : "", (unsigned int) cookie); |
| 653 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 654 | nfs_fattr_init(&dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 656 | nfs_refresh_inode(dir, &dir_attr); |
| 657 | dprintk("NFS reply readdir: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | return status; |
| 659 | } |
| 660 | |
| 661 | static int |
| 662 | nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
| 663 | dev_t rdev) |
| 664 | { |
| 665 | struct nfs_fh fh; |
| 666 | struct nfs_fattr fattr, dir_attr; |
| 667 | struct nfs3_mknodargs arg = { |
| 668 | .fh = NFS_FH(dir), |
| 669 | .name = dentry->d_name.name, |
| 670 | .len = dentry->d_name.len, |
| 671 | .sattr = sattr, |
| 672 | .rdev = rdev |
| 673 | }; |
| 674 | struct nfs3_diropres res = { |
| 675 | .dir_attr = &dir_attr, |
| 676 | .fh = &fh, |
| 677 | .fattr = &fattr |
| 678 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 679 | struct rpc_message msg = { |
| 680 | .rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD], |
| 681 | .rpc_argp = &arg, |
| 682 | .rpc_resp = &res, |
| 683 | }; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 684 | mode_t mode = sattr->ia_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | int status; |
| 686 | |
| 687 | switch (sattr->ia_mode & S_IFMT) { |
| 688 | case S_IFBLK: arg.type = NF3BLK; break; |
| 689 | case S_IFCHR: arg.type = NF3CHR; break; |
| 690 | case S_IFIFO: arg.type = NF3FIFO; break; |
| 691 | case S_IFSOCK: arg.type = NF3SOCK; break; |
| 692 | default: return -EINVAL; |
| 693 | } |
| 694 | |
| 695 | dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name, |
| 696 | MAJOR(rdev), MINOR(rdev)); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 697 | |
| 698 | sattr->ia_mode &= ~current->fs->umask; |
| 699 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 700 | nfs_fattr_init(&dir_attr); |
| 701 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 702 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 703 | nfs_post_op_update_inode(dir, &dir_attr); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 704 | if (status != 0) |
| 705 | goto out; |
| 706 | status = nfs_instantiate(dentry, &fh, &fattr); |
| 707 | if (status != 0) |
| 708 | goto out; |
| 709 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); |
| 710 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | dprintk("NFS reply mknod: %d\n", status); |
| 712 | return status; |
| 713 | } |
| 714 | |
| 715 | static int |
| 716 | nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 717 | struct nfs_fsstat *stat) |
| 718 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 719 | struct rpc_message msg = { |
| 720 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT], |
| 721 | .rpc_argp = fhandle, |
| 722 | .rpc_resp = stat, |
| 723 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | int status; |
| 725 | |
| 726 | dprintk("NFS call fsstat\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 727 | nfs_fattr_init(stat->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 728 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | dprintk("NFS reply statfs: %d\n", status); |
| 730 | return status; |
| 731 | } |
| 732 | |
| 733 | static int |
| 734 | nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 735 | struct nfs_fsinfo *info) |
| 736 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 737 | struct rpc_message msg = { |
| 738 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO], |
| 739 | .rpc_argp = fhandle, |
| 740 | .rpc_resp = info, |
| 741 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | int status; |
| 743 | |
| 744 | dprintk("NFS call fsinfo\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 745 | nfs_fattr_init(info->fattr); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 746 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | dprintk("NFS reply fsinfo: %d\n", status); |
| 748 | return status; |
| 749 | } |
| 750 | |
| 751 | static int |
| 752 | nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 753 | struct nfs_pathconf *info) |
| 754 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 755 | struct rpc_message msg = { |
| 756 | .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF], |
| 757 | .rpc_argp = fhandle, |
| 758 | .rpc_resp = info, |
| 759 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | int status; |
| 761 | |
| 762 | dprintk("NFS call pathconf\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 763 | nfs_fattr_init(info->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 764 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | dprintk("NFS reply pathconf: %d\n", status); |
| 766 | return status; |
| 767 | } |
| 768 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 769 | static int nfs3_read_done(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 771 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 772 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | /* Call back common NFS readpage processing */ |
| 774 | if (task->tk_status >= 0) |
| 775 | nfs_refresh_inode(data->inode, &data->fattr); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 776 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 779 | static void nfs3_proc_read_setup(struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | struct rpc_message msg = { |
| 782 | .rpc_proc = &nfs3_procedures[NFS3PROC_READ], |
| 783 | .rpc_argp = &data->args, |
| 784 | .rpc_resp = &data->res, |
| 785 | .rpc_cred = data->cred, |
| 786 | }; |
| 787 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 788 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 791 | static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 793 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 794 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | if (task->tk_status >= 0) |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 796 | nfs_post_op_update_inode(data->inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 797 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 800 | static void nfs3_proc_write_setup(struct nfs_write_data *data, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | struct rpc_message msg = { |
| 803 | .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE], |
| 804 | .rpc_argp = &data->args, |
| 805 | .rpc_resp = &data->res, |
| 806 | .rpc_cred = data->cred, |
| 807 | }; |
| 808 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 809 | data->args.stable = NFS_UNSTABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | if (how & FLUSH_STABLE) { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 811 | data->args.stable = NFS_FILE_SYNC; |
| 812 | if (NFS_I(data->inode)->ncommit) |
| 813 | data->args.stable = NFS_DATA_SYNC; |
| 814 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
| 816 | /* Finalize the task. */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 817 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 820 | static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 822 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 823 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | if (task->tk_status >= 0) |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 825 | nfs_post_op_update_inode(data->inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 826 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 829 | static void nfs3_proc_commit_setup(struct nfs_write_data *data, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | struct rpc_message msg = { |
| 832 | .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT], |
| 833 | .rpc_argp = &data->args, |
| 834 | .rpc_resp = &data->res, |
| 835 | .rpc_cred = data->cred, |
| 836 | }; |
| 837 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 838 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | static int |
| 842 | nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) |
| 843 | { |
Josef "Jeff" Sipek | 01cce93 | 2006-12-08 02:36:40 -0800 | [diff] [blame] | 844 | return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } |
| 846 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 847 | const struct nfs_rpc_ops nfs_v3_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | .version = 3, /* protocol version */ |
| 849 | .dentry_ops = &nfs_dentry_operations, |
Andreas Gruenbacher | b7fa055 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 850 | .dir_inode_ops = &nfs3_dir_inode_operations, |
| 851 | .file_inode_ops = &nfs3_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | .getroot = nfs3_proc_get_root, |
| 853 | .getattr = nfs3_proc_getattr, |
| 854 | .setattr = nfs3_proc_setattr, |
| 855 | .lookup = nfs3_proc_lookup, |
| 856 | .access = nfs3_proc_access, |
| 857 | .readlink = nfs3_proc_readlink, |
| 858 | .read = nfs3_proc_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | .create = nfs3_proc_create, |
| 860 | .remove = nfs3_proc_remove, |
| 861 | .unlink_setup = nfs3_proc_unlink_setup, |
| 862 | .unlink_done = nfs3_proc_unlink_done, |
| 863 | .rename = nfs3_proc_rename, |
| 864 | .link = nfs3_proc_link, |
| 865 | .symlink = nfs3_proc_symlink, |
| 866 | .mkdir = nfs3_proc_mkdir, |
| 867 | .rmdir = nfs3_proc_rmdir, |
| 868 | .readdir = nfs3_proc_readdir, |
| 869 | .mknod = nfs3_proc_mknod, |
| 870 | .statfs = nfs3_proc_statfs, |
| 871 | .fsinfo = nfs3_proc_fsinfo, |
| 872 | .pathconf = nfs3_proc_pathconf, |
| 873 | .decode_dirent = nfs3_decode_dirent, |
| 874 | .read_setup = nfs3_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 875 | .read_done = nfs3_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | .write_setup = nfs3_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 877 | .write_done = nfs3_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | .commit_setup = nfs3_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 879 | .commit_done = nfs3_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | .file_open = nfs_open, |
| 881 | .file_release = nfs_release, |
| 882 | .lock = nfs3_proc_lock, |
Andreas Gruenbacher | 5c6a9f7 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 883 | .clear_acl_cache = nfs3_forget_cached_acls, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | }; |