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