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 | |
| 279 | static int nfs3_proc_write(struct nfs_write_data *wdata) |
| 280 | { |
| 281 | int rpcflags = wdata->flags; |
| 282 | struct inode * inode = wdata->inode; |
| 283 | struct nfs_fattr * fattr = wdata->res.fattr; |
| 284 | struct rpc_message msg = { |
| 285 | .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE], |
| 286 | .rpc_argp = &wdata->args, |
| 287 | .rpc_resp = &wdata->res, |
| 288 | .rpc_cred = wdata->cred, |
| 289 | }; |
| 290 | int status; |
| 291 | |
| 292 | dprintk("NFS call write %d @ %Ld\n", wdata->args.count, |
| 293 | (long long) wdata->args.offset); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 294 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags); |
| 296 | if (status >= 0) |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 297 | nfs_post_op_update_inode(inode, fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | dprintk("NFS reply write: %d\n", status); |
| 299 | return status < 0? status : wdata->res.count; |
| 300 | } |
| 301 | |
| 302 | static int nfs3_proc_commit(struct nfs_write_data *cdata) |
| 303 | { |
| 304 | struct inode * inode = cdata->inode; |
| 305 | struct nfs_fattr * fattr = cdata->res.fattr; |
| 306 | struct rpc_message msg = { |
| 307 | .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT], |
| 308 | .rpc_argp = &cdata->args, |
| 309 | .rpc_resp = &cdata->res, |
| 310 | .rpc_cred = cdata->cred, |
| 311 | }; |
| 312 | int status; |
| 313 | |
| 314 | dprintk("NFS call commit %d @ %Ld\n", cdata->args.count, |
| 315 | (long long) cdata->args.offset); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 316 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
| 318 | if (status >= 0) |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 319 | nfs_post_op_update_inode(inode, fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | dprintk("NFS reply commit: %d\n", status); |
| 321 | return status; |
| 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Create a regular file. |
| 326 | * For now, we don't implement O_EXCL. |
| 327 | */ |
| 328 | static int |
| 329 | nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 330 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
| 332 | struct nfs_fh fhandle; |
| 333 | struct nfs_fattr fattr; |
| 334 | struct nfs_fattr dir_attr; |
| 335 | struct nfs3_createargs arg = { |
| 336 | .fh = NFS_FH(dir), |
| 337 | .name = dentry->d_name.name, |
| 338 | .len = dentry->d_name.len, |
| 339 | .sattr = sattr, |
| 340 | }; |
| 341 | struct nfs3_diropres res = { |
| 342 | .dir_attr = &dir_attr, |
| 343 | .fh = &fhandle, |
| 344 | .fattr = &fattr |
| 345 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 346 | struct rpc_message msg = { |
| 347 | .rpc_proc = &nfs3_procedures[NFS3PROC_CREATE], |
| 348 | .rpc_argp = &arg, |
| 349 | .rpc_resp = &res, |
| 350 | }; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 351 | mode_t mode = sattr->ia_mode; |
| 352 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | dprintk("NFS call create %s\n", dentry->d_name.name); |
| 355 | arg.createmode = NFS3_CREATE_UNCHECKED; |
| 356 | if (flags & O_EXCL) { |
| 357 | arg.createmode = NFS3_CREATE_EXCLUSIVE; |
| 358 | arg.verifier[0] = jiffies; |
| 359 | arg.verifier[1] = current->pid; |
| 360 | } |
| 361 | |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 362 | sattr->ia_mode &= ~current->fs->umask; |
| 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | again: |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 365 | nfs_fattr_init(&dir_attr); |
| 366 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 367 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 368 | nfs_refresh_inode(dir, &dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | /* If the server doesn't support the exclusive creation semantics, |
| 371 | * try again with simple 'guarded' mode. */ |
| 372 | if (status == NFSERR_NOTSUPP) { |
| 373 | switch (arg.createmode) { |
| 374 | case NFS3_CREATE_EXCLUSIVE: |
| 375 | arg.createmode = NFS3_CREATE_GUARDED; |
| 376 | break; |
| 377 | |
| 378 | case NFS3_CREATE_GUARDED: |
| 379 | arg.createmode = NFS3_CREATE_UNCHECKED; |
| 380 | break; |
| 381 | |
| 382 | case NFS3_CREATE_UNCHECKED: |
| 383 | goto out; |
| 384 | } |
| 385 | goto again; |
| 386 | } |
| 387 | |
| 388 | if (status == 0) |
| 389 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 390 | if (status != 0) |
| 391 | goto out; |
| 392 | |
| 393 | /* When we created the file with exclusive semantics, make |
| 394 | * sure we set the attributes afterwards. */ |
| 395 | if (arg.createmode == NFS3_CREATE_EXCLUSIVE) { |
| 396 | dprintk("NFS call setattr (post-create)\n"); |
| 397 | |
| 398 | if (!(sattr->ia_valid & ATTR_ATIME_SET)) |
| 399 | sattr->ia_valid |= ATTR_ATIME; |
| 400 | if (!(sattr->ia_valid & ATTR_MTIME_SET)) |
| 401 | sattr->ia_valid |= ATTR_MTIME; |
| 402 | |
| 403 | /* Note: we could use a guarded setattr here, but I'm |
| 404 | * not sure this buys us anything (and I'd have |
| 405 | * to revamp the NFSv3 XDR code) */ |
| 406 | status = nfs3_proc_setattr(dentry, &fattr, sattr); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 407 | if (status == 0) |
| 408 | nfs_setattr_update_inode(dentry->d_inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | nfs_refresh_inode(dentry->d_inode, &fattr); |
| 410 | dprintk("NFS reply setattr (post-create): %d\n", status); |
| 411 | } |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 412 | if (status != 0) |
| 413 | goto out; |
| 414 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | out: |
| 416 | dprintk("NFS reply create: %d\n", status); |
| 417 | return status; |
| 418 | } |
| 419 | |
| 420 | static int |
| 421 | nfs3_proc_remove(struct inode *dir, struct qstr *name) |
| 422 | { |
| 423 | struct nfs_fattr dir_attr; |
| 424 | struct nfs3_diropargs arg = { |
| 425 | .fh = NFS_FH(dir), |
| 426 | .name = name->name, |
| 427 | .len = name->len |
| 428 | }; |
| 429 | struct rpc_message msg = { |
| 430 | .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE], |
| 431 | .rpc_argp = &arg, |
| 432 | .rpc_resp = &dir_attr, |
| 433 | }; |
| 434 | int status; |
| 435 | |
| 436 | dprintk("NFS call remove %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 437 | nfs_fattr_init(&dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 439 | nfs_post_op_update_inode(dir, &dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | dprintk("NFS reply remove: %d\n", status); |
| 441 | return status; |
| 442 | } |
| 443 | |
| 444 | static int |
| 445 | nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name) |
| 446 | { |
| 447 | struct unlinkxdr { |
| 448 | struct nfs3_diropargs arg; |
| 449 | struct nfs_fattr res; |
| 450 | } *ptr; |
| 451 | |
Panagiotis Issaris | f52720c | 2006-09-27 01:49:39 -0700 | [diff] [blame] | 452 | ptr = kmalloc(sizeof(*ptr), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if (!ptr) |
| 454 | return -ENOMEM; |
| 455 | ptr->arg.fh = NFS_FH(dir->d_inode); |
| 456 | ptr->arg.name = name->name; |
| 457 | ptr->arg.len = name->len; |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 458 | nfs_fattr_init(&ptr->res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE]; |
| 460 | msg->rpc_argp = &ptr->arg; |
| 461 | msg->rpc_resp = &ptr->res; |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | static int |
| 466 | nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task) |
| 467 | { |
| 468 | struct rpc_message *msg = &task->tk_msg; |
| 469 | struct nfs_fattr *dir_attr; |
| 470 | |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 471 | if (nfs3_async_handle_jukebox(task, dir->d_inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | return 1; |
| 473 | if (msg->rpc_argp) { |
| 474 | dir_attr = (struct nfs_fattr*)msg->rpc_resp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 475 | nfs_post_op_update_inode(dir->d_inode, dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | kfree(msg->rpc_argp); |
| 477 | } |
| 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | static int |
| 482 | nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 483 | struct inode *new_dir, struct qstr *new_name) |
| 484 | { |
| 485 | struct nfs_fattr old_dir_attr, new_dir_attr; |
| 486 | struct nfs3_renameargs arg = { |
| 487 | .fromfh = NFS_FH(old_dir), |
| 488 | .fromname = old_name->name, |
| 489 | .fromlen = old_name->len, |
| 490 | .tofh = NFS_FH(new_dir), |
| 491 | .toname = new_name->name, |
| 492 | .tolen = new_name->len |
| 493 | }; |
| 494 | struct nfs3_renameres res = { |
| 495 | .fromattr = &old_dir_attr, |
| 496 | .toattr = &new_dir_attr |
| 497 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 498 | struct rpc_message msg = { |
| 499 | .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME], |
| 500 | .rpc_argp = &arg, |
| 501 | .rpc_resp = &res, |
| 502 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | int status; |
| 504 | |
| 505 | 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] | 506 | nfs_fattr_init(&old_dir_attr); |
| 507 | nfs_fattr_init(&new_dir_attr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 508 | status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 509 | nfs_post_op_update_inode(old_dir, &old_dir_attr); |
| 510 | nfs_post_op_update_inode(new_dir, &new_dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | dprintk("NFS reply rename: %d\n", status); |
| 512 | return status; |
| 513 | } |
| 514 | |
| 515 | static int |
| 516 | nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 517 | { |
| 518 | struct nfs_fattr dir_attr, fattr; |
| 519 | struct nfs3_linkargs arg = { |
| 520 | .fromfh = NFS_FH(inode), |
| 521 | .tofh = NFS_FH(dir), |
| 522 | .toname = name->name, |
| 523 | .tolen = name->len |
| 524 | }; |
| 525 | struct nfs3_linkres res = { |
| 526 | .dir_attr = &dir_attr, |
| 527 | .fattr = &fattr |
| 528 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 529 | struct rpc_message msg = { |
| 530 | .rpc_proc = &nfs3_procedures[NFS3PROC_LINK], |
| 531 | .rpc_argp = &arg, |
| 532 | .rpc_resp = &res, |
| 533 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | int status; |
| 535 | |
| 536 | dprintk("NFS call link %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 537 | nfs_fattr_init(&dir_attr); |
| 538 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 539 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 540 | nfs_post_op_update_inode(dir, &dir_attr); |
| 541 | nfs_post_op_update_inode(inode, &fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | dprintk("NFS reply link: %d\n", status); |
| 543 | return status; |
| 544 | } |
| 545 | |
| 546 | static int |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 547 | nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, |
| 548 | unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 550 | struct nfs_fh fhandle; |
| 551 | struct nfs_fattr fattr, dir_attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | struct nfs3_symlinkargs arg = { |
| 553 | .fromfh = NFS_FH(dir), |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 554 | .fromname = dentry->d_name.name, |
| 555 | .fromlen = dentry->d_name.len, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 556 | .pages = &page, |
| 557 | .pathlen = len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | .sattr = sattr |
| 559 | }; |
| 560 | struct nfs3_diropres res = { |
| 561 | .dir_attr = &dir_attr, |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 562 | .fh = &fhandle, |
| 563 | .fattr = &fattr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 565 | struct rpc_message msg = { |
| 566 | .rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK], |
| 567 | .rpc_argp = &arg, |
| 568 | .rpc_resp = &res, |
| 569 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | int status; |
| 571 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 572 | if (len > NFS3_MAXPATHLEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | return -ENAMETOOLONG; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 574 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 575 | dprintk("NFS call symlink %s\n", dentry->d_name.name); |
| 576 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 577 | nfs_fattr_init(&dir_attr); |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 578 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 579 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 580 | nfs_post_op_update_inode(dir, &dir_attr); |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 581 | if (status != 0) |
| 582 | goto out; |
| 583 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 584 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | dprintk("NFS reply symlink: %d\n", status); |
| 586 | return status; |
| 587 | } |
| 588 | |
| 589 | static int |
| 590 | nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) |
| 591 | { |
| 592 | struct nfs_fh fhandle; |
| 593 | struct nfs_fattr fattr, dir_attr; |
| 594 | struct nfs3_mkdirargs arg = { |
| 595 | .fh = NFS_FH(dir), |
| 596 | .name = dentry->d_name.name, |
| 597 | .len = dentry->d_name.len, |
| 598 | .sattr = sattr |
| 599 | }; |
| 600 | struct nfs3_diropres res = { |
| 601 | .dir_attr = &dir_attr, |
| 602 | .fh = &fhandle, |
| 603 | .fattr = &fattr |
| 604 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 605 | struct rpc_message msg = { |
| 606 | .rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR], |
| 607 | .rpc_argp = &arg, |
| 608 | .rpc_resp = &res, |
| 609 | }; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 610 | int mode = sattr->ia_mode; |
| 611 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
| 613 | dprintk("NFS call mkdir %s\n", dentry->d_name.name); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 614 | |
| 615 | sattr->ia_mode &= ~current->fs->umask; |
| 616 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 617 | nfs_fattr_init(&dir_attr); |
| 618 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 619 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 620 | nfs_post_op_update_inode(dir, &dir_attr); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 621 | if (status != 0) |
| 622 | goto out; |
| 623 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 624 | if (status != 0) |
| 625 | goto out; |
| 626 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); |
| 627 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | dprintk("NFS reply mkdir: %d\n", status); |
| 629 | return status; |
| 630 | } |
| 631 | |
| 632 | static int |
| 633 | nfs3_proc_rmdir(struct inode *dir, struct qstr *name) |
| 634 | { |
| 635 | struct nfs_fattr dir_attr; |
| 636 | struct nfs3_diropargs arg = { |
| 637 | .fh = NFS_FH(dir), |
| 638 | .name = name->name, |
| 639 | .len = name->len |
| 640 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 641 | struct rpc_message msg = { |
| 642 | .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR], |
| 643 | .rpc_argp = &arg, |
| 644 | .rpc_resp = &dir_attr, |
| 645 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | int status; |
| 647 | |
| 648 | dprintk("NFS call rmdir %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 649 | nfs_fattr_init(&dir_attr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 650 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 651 | nfs_post_op_update_inode(dir, &dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | dprintk("NFS reply rmdir: %d\n", status); |
| 653 | return status; |
| 654 | } |
| 655 | |
| 656 | /* |
| 657 | * The READDIR implementation is somewhat hackish - we pass the user buffer |
| 658 | * to the encode function, which installs it in the receive iovec. |
| 659 | * The decode function itself doesn't perform any decoding, it just makes |
| 660 | * sure the reply is syntactically correct. |
| 661 | * |
| 662 | * Also note that this implementation handles both plain readdir and |
| 663 | * readdirplus. |
| 664 | */ |
| 665 | static int |
| 666 | nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 667 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 668 | { |
| 669 | struct inode *dir = dentry->d_inode; |
| 670 | struct nfs_fattr dir_attr; |
| 671 | u32 *verf = NFS_COOKIEVERF(dir); |
| 672 | struct nfs3_readdirargs arg = { |
| 673 | .fh = NFS_FH(dir), |
| 674 | .cookie = cookie, |
| 675 | .verf = {verf[0], verf[1]}, |
| 676 | .plus = plus, |
| 677 | .count = count, |
| 678 | .pages = &page |
| 679 | }; |
| 680 | struct nfs3_readdirres res = { |
| 681 | .dir_attr = &dir_attr, |
| 682 | .verf = verf, |
| 683 | .plus = plus |
| 684 | }; |
| 685 | struct rpc_message msg = { |
| 686 | .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR], |
| 687 | .rpc_argp = &arg, |
| 688 | .rpc_resp = &res, |
| 689 | .rpc_cred = cred |
| 690 | }; |
| 691 | int status; |
| 692 | |
| 693 | lock_kernel(); |
| 694 | |
| 695 | if (plus) |
| 696 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS]; |
| 697 | |
| 698 | dprintk("NFS call readdir%s %d\n", |
| 699 | plus? "plus" : "", (unsigned int) cookie); |
| 700 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 701 | nfs_fattr_init(&dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 703 | nfs_refresh_inode(dir, &dir_attr); |
| 704 | dprintk("NFS reply readdir: %d\n", status); |
| 705 | unlock_kernel(); |
| 706 | return status; |
| 707 | } |
| 708 | |
| 709 | static int |
| 710 | nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
| 711 | dev_t rdev) |
| 712 | { |
| 713 | struct nfs_fh fh; |
| 714 | struct nfs_fattr fattr, dir_attr; |
| 715 | struct nfs3_mknodargs arg = { |
| 716 | .fh = NFS_FH(dir), |
| 717 | .name = dentry->d_name.name, |
| 718 | .len = dentry->d_name.len, |
| 719 | .sattr = sattr, |
| 720 | .rdev = rdev |
| 721 | }; |
| 722 | struct nfs3_diropres res = { |
| 723 | .dir_attr = &dir_attr, |
| 724 | .fh = &fh, |
| 725 | .fattr = &fattr |
| 726 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 727 | struct rpc_message msg = { |
| 728 | .rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD], |
| 729 | .rpc_argp = &arg, |
| 730 | .rpc_resp = &res, |
| 731 | }; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 732 | mode_t mode = sattr->ia_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | int status; |
| 734 | |
| 735 | switch (sattr->ia_mode & S_IFMT) { |
| 736 | case S_IFBLK: arg.type = NF3BLK; break; |
| 737 | case S_IFCHR: arg.type = NF3CHR; break; |
| 738 | case S_IFIFO: arg.type = NF3FIFO; break; |
| 739 | case S_IFSOCK: arg.type = NF3SOCK; break; |
| 740 | default: return -EINVAL; |
| 741 | } |
| 742 | |
| 743 | dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name, |
| 744 | MAJOR(rdev), MINOR(rdev)); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 745 | |
| 746 | sattr->ia_mode &= ~current->fs->umask; |
| 747 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 748 | nfs_fattr_init(&dir_attr); |
| 749 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 750 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 751 | nfs_post_op_update_inode(dir, &dir_attr); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 752 | if (status != 0) |
| 753 | goto out; |
| 754 | status = nfs_instantiate(dentry, &fh, &fattr); |
| 755 | if (status != 0) |
| 756 | goto out; |
| 757 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); |
| 758 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | dprintk("NFS reply mknod: %d\n", status); |
| 760 | return status; |
| 761 | } |
| 762 | |
| 763 | static int |
| 764 | nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 765 | struct nfs_fsstat *stat) |
| 766 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 767 | struct rpc_message msg = { |
| 768 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT], |
| 769 | .rpc_argp = fhandle, |
| 770 | .rpc_resp = stat, |
| 771 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | int status; |
| 773 | |
| 774 | dprintk("NFS call fsstat\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 775 | nfs_fattr_init(stat->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 776 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | dprintk("NFS reply statfs: %d\n", status); |
| 778 | return status; |
| 779 | } |
| 780 | |
| 781 | static int |
| 782 | nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 783 | struct nfs_fsinfo *info) |
| 784 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 785 | struct rpc_message msg = { |
| 786 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO], |
| 787 | .rpc_argp = fhandle, |
| 788 | .rpc_resp = info, |
| 789 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | int status; |
| 791 | |
| 792 | dprintk("NFS call fsinfo\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 793 | nfs_fattr_init(info->fattr); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 794 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | dprintk("NFS reply fsinfo: %d\n", status); |
| 796 | return status; |
| 797 | } |
| 798 | |
| 799 | static int |
| 800 | nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 801 | struct nfs_pathconf *info) |
| 802 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 803 | struct rpc_message msg = { |
| 804 | .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF], |
| 805 | .rpc_argp = fhandle, |
| 806 | .rpc_resp = info, |
| 807 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | int status; |
| 809 | |
| 810 | dprintk("NFS call pathconf\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 811 | nfs_fattr_init(info->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 812 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | dprintk("NFS reply pathconf: %d\n", status); |
| 814 | return status; |
| 815 | } |
| 816 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 817 | 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] | 818 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 819 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 820 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | /* Call back common NFS readpage processing */ |
| 822 | if (task->tk_status >= 0) |
| 823 | nfs_refresh_inode(data->inode, &data->fattr); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 824 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 827 | static void nfs3_proc_read_setup(struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | struct rpc_message msg = { |
| 830 | .rpc_proc = &nfs3_procedures[NFS3PROC_READ], |
| 831 | .rpc_argp = &data->args, |
| 832 | .rpc_resp = &data->res, |
| 833 | .rpc_cred = data->cred, |
| 834 | }; |
| 835 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 836 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 839 | 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] | 840 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 841 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 842 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | if (task->tk_status >= 0) |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 844 | nfs_post_op_update_inode(data->inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 845 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 848 | 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] | 849 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | struct rpc_message msg = { |
| 851 | .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE], |
| 852 | .rpc_argp = &data->args, |
| 853 | .rpc_resp = &data->res, |
| 854 | .rpc_cred = data->cred, |
| 855 | }; |
| 856 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 857 | data->args.stable = NFS_UNSTABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | if (how & FLUSH_STABLE) { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 859 | data->args.stable = NFS_FILE_SYNC; |
| 860 | if (NFS_I(data->inode)->ncommit) |
| 861 | data->args.stable = NFS_DATA_SYNC; |
| 862 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | /* Finalize the task. */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 865 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 868 | 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] | 869 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 870 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 871 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | if (task->tk_status >= 0) |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 873 | nfs_post_op_update_inode(data->inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 874 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 877 | 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] | 878 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | struct rpc_message msg = { |
| 880 | .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT], |
| 881 | .rpc_argp = &data->args, |
| 882 | .rpc_resp = &data->res, |
| 883 | .rpc_cred = data->cred, |
| 884 | }; |
| 885 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 886 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | static int |
| 890 | nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) |
| 891 | { |
| 892 | return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl); |
| 893 | } |
| 894 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 895 | const struct nfs_rpc_ops nfs_v3_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | .version = 3, /* protocol version */ |
| 897 | .dentry_ops = &nfs_dentry_operations, |
Andreas Gruenbacher | b7fa055 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 898 | .dir_inode_ops = &nfs3_dir_inode_operations, |
| 899 | .file_inode_ops = &nfs3_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | .getroot = nfs3_proc_get_root, |
| 901 | .getattr = nfs3_proc_getattr, |
| 902 | .setattr = nfs3_proc_setattr, |
| 903 | .lookup = nfs3_proc_lookup, |
| 904 | .access = nfs3_proc_access, |
| 905 | .readlink = nfs3_proc_readlink, |
| 906 | .read = nfs3_proc_read, |
| 907 | .write = nfs3_proc_write, |
| 908 | .commit = nfs3_proc_commit, |
| 909 | .create = nfs3_proc_create, |
| 910 | .remove = nfs3_proc_remove, |
| 911 | .unlink_setup = nfs3_proc_unlink_setup, |
| 912 | .unlink_done = nfs3_proc_unlink_done, |
| 913 | .rename = nfs3_proc_rename, |
| 914 | .link = nfs3_proc_link, |
| 915 | .symlink = nfs3_proc_symlink, |
| 916 | .mkdir = nfs3_proc_mkdir, |
| 917 | .rmdir = nfs3_proc_rmdir, |
| 918 | .readdir = nfs3_proc_readdir, |
| 919 | .mknod = nfs3_proc_mknod, |
| 920 | .statfs = nfs3_proc_statfs, |
| 921 | .fsinfo = nfs3_proc_fsinfo, |
| 922 | .pathconf = nfs3_proc_pathconf, |
| 923 | .decode_dirent = nfs3_decode_dirent, |
| 924 | .read_setup = nfs3_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 925 | .read_done = nfs3_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | .write_setup = nfs3_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 927 | .write_done = nfs3_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | .commit_setup = nfs3_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 929 | .commit_done = nfs3_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | .file_open = nfs_open, |
| 931 | .file_release = nfs_release, |
| 932 | .lock = nfs3_proc_lock, |
Andreas Gruenbacher | 5c6a9f7 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 933 | .clear_acl_cache = nfs3_forget_cached_acls, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | }; |