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