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 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 66 | dprintk("%s: call fsinfo\n", __func__); |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 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); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 69 | dprintk("%s: reply fsinfo: %d\n", __func__, status); |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 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); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 74 | dprintk("%s: reply getattr: %d\n", __func__, status); |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 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 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 251 | struct nfs3_createdata { |
| 252 | struct rpc_message msg; |
| 253 | union { |
| 254 | struct nfs3_createargs create; |
| 255 | struct nfs3_mkdirargs mkdir; |
| 256 | struct nfs3_symlinkargs symlink; |
| 257 | struct nfs3_mknodargs mknod; |
| 258 | } arg; |
| 259 | struct nfs3_diropres res; |
| 260 | struct nfs_fh fh; |
| 261 | struct nfs_fattr fattr; |
| 262 | struct nfs_fattr dir_attr; |
| 263 | }; |
| 264 | |
| 265 | static struct nfs3_createdata *nfs3_alloc_createdata(void) |
| 266 | { |
| 267 | struct nfs3_createdata *data; |
| 268 | |
| 269 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 270 | if (data != NULL) { |
| 271 | data->msg.rpc_argp = &data->arg; |
| 272 | data->msg.rpc_resp = &data->res; |
| 273 | data->res.fh = &data->fh; |
| 274 | data->res.fattr = &data->fattr; |
| 275 | data->res.dir_attr = &data->dir_attr; |
| 276 | nfs_fattr_init(data->res.fattr); |
| 277 | nfs_fattr_init(data->res.dir_attr); |
| 278 | } |
| 279 | return data; |
| 280 | } |
| 281 | |
| 282 | static int nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data) |
| 283 | { |
| 284 | int status; |
| 285 | |
| 286 | status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0); |
| 287 | nfs_post_op_update_inode(dir, data->res.dir_attr); |
| 288 | if (status == 0) |
| 289 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 290 | return status; |
| 291 | } |
| 292 | |
| 293 | static void nfs3_free_createdata(struct nfs3_createdata *data) |
| 294 | { |
| 295 | kfree(data); |
| 296 | } |
| 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /* |
| 299 | * Create a regular file. |
| 300 | * For now, we don't implement O_EXCL. |
| 301 | */ |
| 302 | static int |
| 303 | nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 304 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 306 | struct nfs3_createdata *data; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 307 | mode_t mode = sattr->ia_mode; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 308 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | dprintk("NFS call create %s\n", dentry->d_name.name); |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 311 | |
| 312 | data = nfs3_alloc_createdata(); |
| 313 | if (data == NULL) |
| 314 | goto out; |
| 315 | |
| 316 | data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE]; |
| 317 | data->arg.create.fh = NFS_FH(dir); |
| 318 | data->arg.create.name = dentry->d_name.name; |
| 319 | data->arg.create.len = dentry->d_name.len; |
| 320 | data->arg.create.sattr = sattr; |
| 321 | |
| 322 | data->arg.create.createmode = NFS3_CREATE_UNCHECKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | if (flags & O_EXCL) { |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 324 | data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE; |
| 325 | data->arg.create.verifier[0] = jiffies; |
| 326 | data->arg.create.verifier[1] = current->pid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 329 | sattr->ia_mode &= ~current->fs->umask; |
| 330 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 331 | for (;;) { |
| 332 | status = nfs3_do_create(dir, dentry, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 334 | if (status != -ENOTSUPP) |
| 335 | break; |
| 336 | /* If the server doesn't support the exclusive creation |
| 337 | * semantics, try again with simple 'guarded' mode. */ |
| 338 | switch (data->arg.create.createmode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | case NFS3_CREATE_EXCLUSIVE: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 340 | data->arg.create.createmode = NFS3_CREATE_GUARDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | break; |
| 342 | |
| 343 | case NFS3_CREATE_GUARDED: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 344 | data->arg.create.createmode = NFS3_CREATE_UNCHECKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | break; |
| 346 | |
| 347 | case NFS3_CREATE_UNCHECKED: |
| 348 | goto out; |
| 349 | } |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 350 | nfs_fattr_init(data->res.dir_attr); |
| 351 | nfs_fattr_init(data->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | if (status != 0) |
| 355 | goto out; |
| 356 | |
| 357 | /* When we created the file with exclusive semantics, make |
| 358 | * sure we set the attributes afterwards. */ |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 359 | if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | dprintk("NFS call setattr (post-create)\n"); |
| 361 | |
| 362 | if (!(sattr->ia_valid & ATTR_ATIME_SET)) |
| 363 | sattr->ia_valid |= ATTR_ATIME; |
| 364 | if (!(sattr->ia_valid & ATTR_MTIME_SET)) |
| 365 | sattr->ia_valid |= ATTR_MTIME; |
| 366 | |
| 367 | /* Note: we could use a guarded setattr here, but I'm |
| 368 | * not sure this buys us anything (and I'd have |
| 369 | * to revamp the NFSv3 XDR code) */ |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 370 | status = nfs3_proc_setattr(dentry, data->res.fattr, sattr); |
| 371 | nfs_post_op_update_inode(dentry->d_inode, data->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | dprintk("NFS reply setattr (post-create): %d\n", status); |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 373 | if (status != 0) |
| 374 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 376 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | out: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 378 | nfs3_free_createdata(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | dprintk("NFS reply create: %d\n", status); |
| 380 | return status; |
| 381 | } |
| 382 | |
| 383 | static int |
| 384 | nfs3_proc_remove(struct inode *dir, struct qstr *name) |
| 385 | { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 386 | struct nfs_removeargs arg = { |
| 387 | .fh = NFS_FH(dir), |
| 388 | .name.len = name->len, |
| 389 | .name.name = name->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 391 | struct nfs_removeres res; |
| 392 | struct rpc_message msg = { |
| 393 | .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE], |
| 394 | .rpc_argp = &arg, |
| 395 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | }; |
| 397 | int status; |
| 398 | |
| 399 | dprintk("NFS call remove %s\n", name->name); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 400 | nfs_fattr_init(&res.dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 402 | nfs_post_op_update_inode(dir, &res.dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | dprintk("NFS reply remove: %d\n", status); |
| 404 | return status; |
| 405 | } |
| 406 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 407 | static void |
| 408 | nfs3_proc_unlink_setup(struct rpc_message *msg, struct inode *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static int |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 414 | nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 416 | struct nfs_removeres *res; |
| 417 | if (nfs3_async_handle_jukebox(task, dir)) |
| 418 | return 0; |
| 419 | res = task->tk_msg.rpc_resp; |
| 420 | nfs_post_op_update_inode(dir, &res->dir_attr); |
| 421 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static int |
| 425 | nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 426 | struct inode *new_dir, struct qstr *new_name) |
| 427 | { |
| 428 | struct nfs_fattr old_dir_attr, new_dir_attr; |
| 429 | struct nfs3_renameargs arg = { |
| 430 | .fromfh = NFS_FH(old_dir), |
| 431 | .fromname = old_name->name, |
| 432 | .fromlen = old_name->len, |
| 433 | .tofh = NFS_FH(new_dir), |
| 434 | .toname = new_name->name, |
| 435 | .tolen = new_name->len |
| 436 | }; |
| 437 | struct nfs3_renameres res = { |
| 438 | .fromattr = &old_dir_attr, |
| 439 | .toattr = &new_dir_attr |
| 440 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 441 | struct rpc_message msg = { |
| 442 | .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME], |
| 443 | .rpc_argp = &arg, |
| 444 | .rpc_resp = &res, |
| 445 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | int status; |
| 447 | |
| 448 | 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] | 449 | nfs_fattr_init(&old_dir_attr); |
| 450 | nfs_fattr_init(&new_dir_attr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 451 | status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 452 | nfs_post_op_update_inode(old_dir, &old_dir_attr); |
| 453 | nfs_post_op_update_inode(new_dir, &new_dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | dprintk("NFS reply rename: %d\n", status); |
| 455 | return status; |
| 456 | } |
| 457 | |
| 458 | static int |
| 459 | nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 460 | { |
| 461 | struct nfs_fattr dir_attr, fattr; |
| 462 | struct nfs3_linkargs arg = { |
| 463 | .fromfh = NFS_FH(inode), |
| 464 | .tofh = NFS_FH(dir), |
| 465 | .toname = name->name, |
| 466 | .tolen = name->len |
| 467 | }; |
| 468 | struct nfs3_linkres res = { |
| 469 | .dir_attr = &dir_attr, |
| 470 | .fattr = &fattr |
| 471 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 472 | struct rpc_message msg = { |
| 473 | .rpc_proc = &nfs3_procedures[NFS3PROC_LINK], |
| 474 | .rpc_argp = &arg, |
| 475 | .rpc_resp = &res, |
| 476 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | int status; |
| 478 | |
| 479 | dprintk("NFS call link %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 480 | nfs_fattr_init(&dir_attr); |
| 481 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 482 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 483 | nfs_post_op_update_inode(dir, &dir_attr); |
| 484 | nfs_post_op_update_inode(inode, &fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | dprintk("NFS reply link: %d\n", status); |
| 486 | return status; |
| 487 | } |
| 488 | |
| 489 | static int |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 490 | nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, |
| 491 | unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 493 | struct nfs3_createdata *data; |
| 494 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 496 | if (len > NFS3_MAXPATHLEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return -ENAMETOOLONG; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 498 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 499 | dprintk("NFS call symlink %s\n", dentry->d_name.name); |
| 500 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 501 | data = nfs3_alloc_createdata(); |
| 502 | if (data == NULL) |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 503 | goto out; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 504 | data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK]; |
| 505 | data->arg.symlink.fromfh = NFS_FH(dir); |
| 506 | data->arg.symlink.fromname = dentry->d_name.name; |
| 507 | data->arg.symlink.fromlen = dentry->d_name.len; |
| 508 | data->arg.symlink.pages = &page; |
| 509 | data->arg.symlink.pathlen = len; |
| 510 | data->arg.symlink.sattr = sattr; |
| 511 | |
| 512 | status = nfs3_do_create(dir, dentry, data); |
| 513 | |
| 514 | nfs3_free_createdata(data); |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 515 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | dprintk("NFS reply symlink: %d\n", status); |
| 517 | return status; |
| 518 | } |
| 519 | |
| 520 | static int |
| 521 | nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) |
| 522 | { |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 523 | struct nfs3_createdata *data; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 524 | int mode = sattr->ia_mode; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 525 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | dprintk("NFS call mkdir %s\n", dentry->d_name.name); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 528 | |
| 529 | sattr->ia_mode &= ~current->fs->umask; |
| 530 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 531 | data = nfs3_alloc_createdata(); |
| 532 | if (data == NULL) |
| 533 | goto out; |
| 534 | |
| 535 | data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR]; |
| 536 | data->arg.mkdir.fh = NFS_FH(dir); |
| 537 | data->arg.mkdir.name = dentry->d_name.name; |
| 538 | data->arg.mkdir.len = dentry->d_name.len; |
| 539 | data->arg.mkdir.sattr = sattr; |
| 540 | |
| 541 | status = nfs3_do_create(dir, dentry, data); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 542 | if (status != 0) |
| 543 | goto out; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 544 | |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 545 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); |
| 546 | out: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 547 | nfs3_free_createdata(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | dprintk("NFS reply mkdir: %d\n", status); |
| 549 | return status; |
| 550 | } |
| 551 | |
| 552 | static int |
| 553 | nfs3_proc_rmdir(struct inode *dir, struct qstr *name) |
| 554 | { |
| 555 | struct nfs_fattr dir_attr; |
| 556 | struct nfs3_diropargs arg = { |
| 557 | .fh = NFS_FH(dir), |
| 558 | .name = name->name, |
| 559 | .len = name->len |
| 560 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 561 | struct rpc_message msg = { |
| 562 | .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR], |
| 563 | .rpc_argp = &arg, |
| 564 | .rpc_resp = &dir_attr, |
| 565 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | int status; |
| 567 | |
| 568 | dprintk("NFS call rmdir %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 569 | nfs_fattr_init(&dir_attr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 570 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 571 | nfs_post_op_update_inode(dir, &dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | dprintk("NFS reply rmdir: %d\n", status); |
| 573 | return status; |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * The READDIR implementation is somewhat hackish - we pass the user buffer |
| 578 | * to the encode function, which installs it in the receive iovec. |
| 579 | * The decode function itself doesn't perform any decoding, it just makes |
| 580 | * sure the reply is syntactically correct. |
| 581 | * |
| 582 | * Also note that this implementation handles both plain readdir and |
| 583 | * readdirplus. |
| 584 | */ |
| 585 | static int |
| 586 | nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 587 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 588 | { |
| 589 | struct inode *dir = dentry->d_inode; |
| 590 | struct nfs_fattr dir_attr; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 591 | __be32 *verf = NFS_COOKIEVERF(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | struct nfs3_readdirargs arg = { |
| 593 | .fh = NFS_FH(dir), |
| 594 | .cookie = cookie, |
| 595 | .verf = {verf[0], verf[1]}, |
| 596 | .plus = plus, |
| 597 | .count = count, |
| 598 | .pages = &page |
| 599 | }; |
| 600 | struct nfs3_readdirres res = { |
| 601 | .dir_attr = &dir_attr, |
| 602 | .verf = verf, |
| 603 | .plus = plus |
| 604 | }; |
| 605 | struct rpc_message msg = { |
| 606 | .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR], |
| 607 | .rpc_argp = &arg, |
| 608 | .rpc_resp = &res, |
| 609 | .rpc_cred = cred |
| 610 | }; |
| 611 | int status; |
| 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | if (plus) |
| 614 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS]; |
| 615 | |
| 616 | dprintk("NFS call readdir%s %d\n", |
| 617 | plus? "plus" : "", (unsigned int) cookie); |
| 618 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 619 | nfs_fattr_init(&dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 621 | |
| 622 | nfs_invalidate_atime(dir); |
| 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | nfs_refresh_inode(dir, &dir_attr); |
| 625 | dprintk("NFS reply readdir: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | return status; |
| 627 | } |
| 628 | |
| 629 | static int |
| 630 | nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
| 631 | dev_t rdev) |
| 632 | { |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 633 | struct nfs3_createdata *data; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 634 | mode_t mode = sattr->ia_mode; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 635 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
| 637 | dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name, |
| 638 | MAJOR(rdev), MINOR(rdev)); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 639 | |
| 640 | sattr->ia_mode &= ~current->fs->umask; |
| 641 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 642 | data = nfs3_alloc_createdata(); |
| 643 | if (data == NULL) |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 644 | goto out; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 645 | |
| 646 | data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD]; |
| 647 | data->arg.mknod.fh = NFS_FH(dir); |
| 648 | data->arg.mknod.name = dentry->d_name.name; |
| 649 | data->arg.mknod.len = dentry->d_name.len; |
| 650 | data->arg.mknod.sattr = sattr; |
| 651 | data->arg.mknod.rdev = rdev; |
| 652 | |
| 653 | switch (sattr->ia_mode & S_IFMT) { |
| 654 | case S_IFBLK: |
| 655 | data->arg.mknod.type = NF3BLK; |
| 656 | break; |
| 657 | case S_IFCHR: |
| 658 | data->arg.mknod.type = NF3CHR; |
| 659 | break; |
| 660 | case S_IFIFO: |
| 661 | data->arg.mknod.type = NF3FIFO; |
| 662 | break; |
| 663 | case S_IFSOCK: |
| 664 | data->arg.mknod.type = NF3SOCK; |
| 665 | break; |
| 666 | default: |
| 667 | status = -EINVAL; |
| 668 | goto out; |
| 669 | } |
| 670 | |
| 671 | status = nfs3_do_create(dir, dentry, data); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 672 | if (status != 0) |
| 673 | goto out; |
| 674 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); |
| 675 | out: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame^] | 676 | nfs3_free_createdata(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | dprintk("NFS reply mknod: %d\n", status); |
| 678 | return status; |
| 679 | } |
| 680 | |
| 681 | static int |
| 682 | nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 683 | struct nfs_fsstat *stat) |
| 684 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 685 | struct rpc_message msg = { |
| 686 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT], |
| 687 | .rpc_argp = fhandle, |
| 688 | .rpc_resp = stat, |
| 689 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | int status; |
| 691 | |
| 692 | dprintk("NFS call fsstat\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 693 | nfs_fattr_init(stat->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 694 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | dprintk("NFS reply statfs: %d\n", status); |
| 696 | return status; |
| 697 | } |
| 698 | |
| 699 | static int |
| 700 | nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 701 | struct nfs_fsinfo *info) |
| 702 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 703 | struct rpc_message msg = { |
| 704 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO], |
| 705 | .rpc_argp = fhandle, |
| 706 | .rpc_resp = info, |
| 707 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | int status; |
| 709 | |
| 710 | dprintk("NFS call fsinfo\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 711 | nfs_fattr_init(info->fattr); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 712 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | dprintk("NFS reply fsinfo: %d\n", status); |
| 714 | return status; |
| 715 | } |
| 716 | |
| 717 | static int |
| 718 | nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 719 | struct nfs_pathconf *info) |
| 720 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 721 | struct rpc_message msg = { |
| 722 | .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF], |
| 723 | .rpc_argp = fhandle, |
| 724 | .rpc_resp = info, |
| 725 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | int status; |
| 727 | |
| 728 | dprintk("NFS call pathconf\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 729 | nfs_fattr_init(info->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 730 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | dprintk("NFS reply pathconf: %d\n", status); |
| 732 | return status; |
| 733 | } |
| 734 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 735 | 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] | 736 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 737 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 738 | return -EAGAIN; |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 739 | |
| 740 | nfs_invalidate_atime(data->inode); |
| 741 | nfs_refresh_inode(data->inode, &data->fattr); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 742 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 745 | 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] | 746 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 747 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 750 | 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] | 751 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 752 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 753 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | if (task->tk_status >= 0) |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 755 | nfs_post_op_update_inode_force_wcc(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_write_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_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 764 | 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] | 765 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 766 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 767 | return -EAGAIN; |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 768 | nfs_refresh_inode(data->inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 769 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 772 | 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] | 773 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 774 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | static int |
| 778 | nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) |
| 779 | { |
Chuck Lever | 1093a60 | 2008-01-11 17:09:59 -0500 | [diff] [blame] | 780 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 781 | |
| 782 | return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 785 | const struct nfs_rpc_ops nfs_v3_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | .version = 3, /* protocol version */ |
| 787 | .dentry_ops = &nfs_dentry_operations, |
Andreas Gruenbacher | b7fa055 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 788 | .dir_inode_ops = &nfs3_dir_inode_operations, |
| 789 | .file_inode_ops = &nfs3_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | .getroot = nfs3_proc_get_root, |
| 791 | .getattr = nfs3_proc_getattr, |
| 792 | .setattr = nfs3_proc_setattr, |
| 793 | .lookup = nfs3_proc_lookup, |
| 794 | .access = nfs3_proc_access, |
| 795 | .readlink = nfs3_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | .create = nfs3_proc_create, |
| 797 | .remove = nfs3_proc_remove, |
| 798 | .unlink_setup = nfs3_proc_unlink_setup, |
| 799 | .unlink_done = nfs3_proc_unlink_done, |
| 800 | .rename = nfs3_proc_rename, |
| 801 | .link = nfs3_proc_link, |
| 802 | .symlink = nfs3_proc_symlink, |
| 803 | .mkdir = nfs3_proc_mkdir, |
| 804 | .rmdir = nfs3_proc_rmdir, |
| 805 | .readdir = nfs3_proc_readdir, |
| 806 | .mknod = nfs3_proc_mknod, |
| 807 | .statfs = nfs3_proc_statfs, |
| 808 | .fsinfo = nfs3_proc_fsinfo, |
| 809 | .pathconf = nfs3_proc_pathconf, |
| 810 | .decode_dirent = nfs3_decode_dirent, |
| 811 | .read_setup = nfs3_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 812 | .read_done = nfs3_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | .write_setup = nfs3_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 814 | .write_done = nfs3_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | .commit_setup = nfs3_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 816 | .commit_done = nfs3_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | .file_open = nfs_open, |
| 818 | .file_release = nfs_release, |
| 819 | .lock = nfs3_proc_lock, |
Andreas Gruenbacher | 5c6a9f7 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 820 | .clear_acl_cache = nfs3_forget_cached_acls, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | }; |