0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/mm.h>
0011 #include <linux/errno.h>
0012 #include <linux/string.h>
0013 #include <linux/sunrpc/clnt.h>
0014 #include <linux/slab.h>
0015 #include <linux/nfs.h>
0016 #include <linux/nfs3.h>
0017 #include <linux/nfs_fs.h>
0018 #include <linux/nfs_page.h>
0019 #include <linux/lockd/bind.h>
0020 #include <linux/nfs_mount.h>
0021 #include <linux/freezer.h>
0022 #include <linux/xattr.h>
0023
0024 #include "iostat.h"
0025 #include "internal.h"
0026 #include "nfs3_fs.h"
0027
0028 #define NFSDBG_FACILITY NFSDBG_PROC
0029
0030
0031 static int
0032 nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
0033 {
0034 int res;
0035 do {
0036 res = rpc_call_sync(clnt, msg, flags);
0037 if (res != -EJUKEBOX)
0038 break;
0039 freezable_schedule_timeout_killable_unsafe(NFS_JUKEBOX_RETRY_TIME);
0040 res = -ERESTARTSYS;
0041 } while (!fatal_signal_pending(current));
0042 return res;
0043 }
0044
0045 #define rpc_call_sync(clnt, msg, flags) nfs3_rpc_wrapper(clnt, msg, flags)
0046
0047 static int
0048 nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode)
0049 {
0050 if (task->tk_status != -EJUKEBOX)
0051 return 0;
0052 nfs_inc_stats(inode, NFSIOS_DELAY);
0053 task->tk_status = 0;
0054 rpc_restart_call(task);
0055 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
0056 return 1;
0057 }
0058
0059 static int
0060 do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle,
0061 struct nfs_fsinfo *info)
0062 {
0063 struct rpc_message msg = {
0064 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
0065 .rpc_argp = fhandle,
0066 .rpc_resp = info,
0067 };
0068 int status;
0069
0070 dprintk("%s: call fsinfo\n", __func__);
0071 nfs_fattr_init(info->fattr);
0072 status = rpc_call_sync(client, &msg, 0);
0073 dprintk("%s: reply fsinfo: %d\n", __func__, status);
0074 if (status == 0 && !(info->fattr->valid & NFS_ATTR_FATTR)) {
0075 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
0076 msg.rpc_resp = info->fattr;
0077 status = rpc_call_sync(client, &msg, 0);
0078 dprintk("%s: reply getattr: %d\n", __func__, status);
0079 }
0080 return status;
0081 }
0082
0083
0084
0085
0086 static int
0087 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
0088 struct nfs_fsinfo *info)
0089 {
0090 int status;
0091
0092 status = do_proc_get_root(server->client, fhandle, info);
0093 if (status && server->nfs_client->cl_rpcclient != server->client)
0094 status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info);
0095 return status;
0096 }
0097
0098
0099
0100
0101 static int
0102 nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
0103 struct nfs_fattr *fattr, struct inode *inode)
0104 {
0105 struct rpc_message msg = {
0106 .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR],
0107 .rpc_argp = fhandle,
0108 .rpc_resp = fattr,
0109 };
0110 int status;
0111 unsigned short task_flags = 0;
0112
0113
0114 if (inode && (server->flags & NFS_MOUNT_SOFTREVAL))
0115 task_flags |= RPC_TASK_TIMEOUT;
0116
0117 dprintk("NFS call getattr\n");
0118 nfs_fattr_init(fattr);
0119 status = rpc_call_sync(server->client, &msg, task_flags);
0120 dprintk("NFS reply getattr: %d\n", status);
0121 return status;
0122 }
0123
0124 static int
0125 nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
0126 struct iattr *sattr)
0127 {
0128 struct inode *inode = d_inode(dentry);
0129 struct nfs3_sattrargs arg = {
0130 .fh = NFS_FH(inode),
0131 .sattr = sattr,
0132 };
0133 struct rpc_message msg = {
0134 .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR],
0135 .rpc_argp = &arg,
0136 .rpc_resp = fattr,
0137 };
0138 int status;
0139
0140 dprintk("NFS call setattr\n");
0141 if (sattr->ia_valid & ATTR_FILE)
0142 msg.rpc_cred = nfs_file_cred(sattr->ia_file);
0143 nfs_fattr_init(fattr);
0144 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
0145 if (status == 0) {
0146 nfs_setattr_update_inode(inode, sattr, fattr);
0147 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
0148 nfs_zap_acl_cache(inode);
0149 }
0150 dprintk("NFS reply setattr: %d\n", status);
0151 return status;
0152 }
0153
0154 static int
0155 __nfs3_proc_lookup(struct inode *dir, const char *name, size_t len,
0156 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
0157 unsigned short task_flags)
0158 {
0159 struct nfs3_diropargs arg = {
0160 .fh = NFS_FH(dir),
0161 .name = name,
0162 .len = len
0163 };
0164 struct nfs3_diropres res = {
0165 .fh = fhandle,
0166 .fattr = fattr
0167 };
0168 struct rpc_message msg = {
0169 .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP],
0170 .rpc_argp = &arg,
0171 .rpc_resp = &res,
0172 };
0173 int status;
0174
0175 res.dir_attr = nfs_alloc_fattr();
0176 if (res.dir_attr == NULL)
0177 return -ENOMEM;
0178
0179 nfs_fattr_init(fattr);
0180 status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags);
0181 nfs_refresh_inode(dir, res.dir_attr);
0182 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
0183 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
0184 msg.rpc_argp = fhandle;
0185 msg.rpc_resp = fattr;
0186 status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags);
0187 }
0188 nfs_free_fattr(res.dir_attr);
0189 dprintk("NFS reply lookup: %d\n", status);
0190 return status;
0191 }
0192
0193 static int
0194 nfs3_proc_lookup(struct inode *dir, struct dentry *dentry,
0195 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
0196 {
0197 unsigned short task_flags = 0;
0198
0199
0200 if (nfs_lookup_is_soft_revalidate(dentry))
0201 task_flags |= RPC_TASK_TIMEOUT;
0202
0203 dprintk("NFS call lookup %pd2\n", dentry);
0204 return __nfs3_proc_lookup(dir, dentry->d_name.name,
0205 dentry->d_name.len, fhandle, fattr,
0206 task_flags);
0207 }
0208
0209 static int nfs3_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle,
0210 struct nfs_fattr *fattr)
0211 {
0212 const char dotdot[] = "..";
0213 const size_t len = strlen(dotdot);
0214 unsigned short task_flags = 0;
0215
0216 if (NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL)
0217 task_flags |= RPC_TASK_TIMEOUT;
0218
0219 return __nfs3_proc_lookup(inode, dotdot, len, fhandle, fattr,
0220 task_flags);
0221 }
0222
0223 static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry,
0224 const struct cred *cred)
0225 {
0226 struct nfs3_accessargs arg = {
0227 .fh = NFS_FH(inode),
0228 .access = entry->mask,
0229 };
0230 struct nfs3_accessres res;
0231 struct rpc_message msg = {
0232 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
0233 .rpc_argp = &arg,
0234 .rpc_resp = &res,
0235 .rpc_cred = cred,
0236 };
0237 int status = -ENOMEM;
0238
0239 dprintk("NFS call access\n");
0240 res.fattr = nfs_alloc_fattr();
0241 if (res.fattr == NULL)
0242 goto out;
0243
0244 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
0245 nfs_refresh_inode(inode, res.fattr);
0246 if (status == 0)
0247 nfs_access_set_mask(entry, res.access);
0248 nfs_free_fattr(res.fattr);
0249 out:
0250 dprintk("NFS reply access: %d\n", status);
0251 return status;
0252 }
0253
0254 static int nfs3_proc_readlink(struct inode *inode, struct page *page,
0255 unsigned int pgbase, unsigned int pglen)
0256 {
0257 struct nfs_fattr *fattr;
0258 struct nfs3_readlinkargs args = {
0259 .fh = NFS_FH(inode),
0260 .pgbase = pgbase,
0261 .pglen = pglen,
0262 .pages = &page
0263 };
0264 struct rpc_message msg = {
0265 .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK],
0266 .rpc_argp = &args,
0267 };
0268 int status = -ENOMEM;
0269
0270 dprintk("NFS call readlink\n");
0271 fattr = nfs_alloc_fattr();
0272 if (fattr == NULL)
0273 goto out;
0274 msg.rpc_resp = fattr;
0275
0276 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
0277 nfs_refresh_inode(inode, fattr);
0278 nfs_free_fattr(fattr);
0279 out:
0280 dprintk("NFS reply readlink: %d\n", status);
0281 return status;
0282 }
0283
0284 struct nfs3_createdata {
0285 struct rpc_message msg;
0286 union {
0287 struct nfs3_createargs create;
0288 struct nfs3_mkdirargs mkdir;
0289 struct nfs3_symlinkargs symlink;
0290 struct nfs3_mknodargs mknod;
0291 } arg;
0292 struct nfs3_diropres res;
0293 struct nfs_fh fh;
0294 struct nfs_fattr fattr;
0295 struct nfs_fattr dir_attr;
0296 };
0297
0298 static struct nfs3_createdata *nfs3_alloc_createdata(void)
0299 {
0300 struct nfs3_createdata *data;
0301
0302 data = kzalloc(sizeof(*data), GFP_KERNEL);
0303 if (data != NULL) {
0304 data->msg.rpc_argp = &data->arg;
0305 data->msg.rpc_resp = &data->res;
0306 data->res.fh = &data->fh;
0307 data->res.fattr = &data->fattr;
0308 data->res.dir_attr = &data->dir_attr;
0309 nfs_fattr_init(data->res.fattr);
0310 nfs_fattr_init(data->res.dir_attr);
0311 }
0312 return data;
0313 }
0314
0315 static struct dentry *
0316 nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
0317 {
0318 int status;
0319
0320 status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
0321 nfs_post_op_update_inode(dir, data->res.dir_attr);
0322 if (status != 0)
0323 return ERR_PTR(status);
0324
0325 return nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr);
0326 }
0327
0328 static void nfs3_free_createdata(struct nfs3_createdata *data)
0329 {
0330 kfree(data);
0331 }
0332
0333
0334
0335
0336 static int
0337 nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
0338 int flags)
0339 {
0340 struct posix_acl *default_acl, *acl;
0341 struct nfs3_createdata *data;
0342 struct dentry *d_alias;
0343 int status = -ENOMEM;
0344
0345 dprintk("NFS call create %pd\n", dentry);
0346
0347 data = nfs3_alloc_createdata();
0348 if (data == NULL)
0349 goto out;
0350
0351 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
0352 data->arg.create.fh = NFS_FH(dir);
0353 data->arg.create.name = dentry->d_name.name;
0354 data->arg.create.len = dentry->d_name.len;
0355 data->arg.create.sattr = sattr;
0356
0357 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
0358 if (flags & O_EXCL) {
0359 data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
0360 data->arg.create.verifier[0] = cpu_to_be32(jiffies);
0361 data->arg.create.verifier[1] = cpu_to_be32(current->pid);
0362 }
0363
0364 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
0365 if (status)
0366 goto out;
0367
0368 for (;;) {
0369 d_alias = nfs3_do_create(dir, dentry, data);
0370 status = PTR_ERR_OR_ZERO(d_alias);
0371
0372 if (status != -ENOTSUPP)
0373 break;
0374
0375
0376 switch (data->arg.create.createmode) {
0377 case NFS3_CREATE_EXCLUSIVE:
0378 data->arg.create.createmode = NFS3_CREATE_GUARDED;
0379 break;
0380
0381 case NFS3_CREATE_GUARDED:
0382 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
0383 break;
0384
0385 case NFS3_CREATE_UNCHECKED:
0386 goto out_release_acls;
0387 }
0388 nfs_fattr_init(data->res.dir_attr);
0389 nfs_fattr_init(data->res.fattr);
0390 }
0391
0392 if (status != 0)
0393 goto out_release_acls;
0394
0395 if (d_alias)
0396 dentry = d_alias;
0397
0398
0399
0400 if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
0401 dprintk("NFS call setattr (post-create)\n");
0402
0403 if (!(sattr->ia_valid & ATTR_ATIME_SET))
0404 sattr->ia_valid |= ATTR_ATIME;
0405 if (!(sattr->ia_valid & ATTR_MTIME_SET))
0406 sattr->ia_valid |= ATTR_MTIME;
0407
0408
0409
0410
0411 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
0412 nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
0413 dprintk("NFS reply setattr (post-create): %d\n", status);
0414 if (status != 0)
0415 goto out_dput;
0416 }
0417
0418 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
0419
0420 out_dput:
0421 dput(d_alias);
0422 out_release_acls:
0423 posix_acl_release(acl);
0424 posix_acl_release(default_acl);
0425 out:
0426 nfs3_free_createdata(data);
0427 dprintk("NFS reply create: %d\n", status);
0428 return status;
0429 }
0430
0431 static int
0432 nfs3_proc_remove(struct inode *dir, struct dentry *dentry)
0433 {
0434 struct nfs_removeargs arg = {
0435 .fh = NFS_FH(dir),
0436 .name = dentry->d_name,
0437 };
0438 struct nfs_removeres res;
0439 struct rpc_message msg = {
0440 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
0441 .rpc_argp = &arg,
0442 .rpc_resp = &res,
0443 };
0444 int status = -ENOMEM;
0445
0446 dprintk("NFS call remove %pd2\n", dentry);
0447 res.dir_attr = nfs_alloc_fattr();
0448 if (res.dir_attr == NULL)
0449 goto out;
0450
0451 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0452 nfs_post_op_update_inode(dir, res.dir_attr);
0453 nfs_free_fattr(res.dir_attr);
0454 out:
0455 dprintk("NFS reply remove: %d\n", status);
0456 return status;
0457 }
0458
0459 static void
0460 nfs3_proc_unlink_setup(struct rpc_message *msg,
0461 struct dentry *dentry,
0462 struct inode *inode)
0463 {
0464 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
0465 }
0466
0467 static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
0468 {
0469 rpc_call_start(task);
0470 }
0471
0472 static int
0473 nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
0474 {
0475 struct nfs_removeres *res;
0476 if (nfs3_async_handle_jukebox(task, dir))
0477 return 0;
0478 res = task->tk_msg.rpc_resp;
0479 nfs_post_op_update_inode(dir, res->dir_attr);
0480 return 1;
0481 }
0482
0483 static void
0484 nfs3_proc_rename_setup(struct rpc_message *msg,
0485 struct dentry *old_dentry,
0486 struct dentry *new_dentry)
0487 {
0488 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
0489 }
0490
0491 static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
0492 {
0493 rpc_call_start(task);
0494 }
0495
0496 static int
0497 nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
0498 struct inode *new_dir)
0499 {
0500 struct nfs_renameres *res;
0501
0502 if (nfs3_async_handle_jukebox(task, old_dir))
0503 return 0;
0504 res = task->tk_msg.rpc_resp;
0505
0506 nfs_post_op_update_inode(old_dir, res->old_fattr);
0507 nfs_post_op_update_inode(new_dir, res->new_fattr);
0508 return 1;
0509 }
0510
0511 static int
0512 nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
0513 {
0514 struct nfs3_linkargs arg = {
0515 .fromfh = NFS_FH(inode),
0516 .tofh = NFS_FH(dir),
0517 .toname = name->name,
0518 .tolen = name->len
0519 };
0520 struct nfs3_linkres res;
0521 struct rpc_message msg = {
0522 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
0523 .rpc_argp = &arg,
0524 .rpc_resp = &res,
0525 };
0526 int status = -ENOMEM;
0527
0528 dprintk("NFS call link %s\n", name->name);
0529 res.fattr = nfs_alloc_fattr();
0530 res.dir_attr = nfs_alloc_fattr();
0531 if (res.fattr == NULL || res.dir_attr == NULL)
0532 goto out;
0533
0534 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
0535 nfs_post_op_update_inode(dir, res.dir_attr);
0536 nfs_post_op_update_inode(inode, res.fattr);
0537 out:
0538 nfs_free_fattr(res.dir_attr);
0539 nfs_free_fattr(res.fattr);
0540 dprintk("NFS reply link: %d\n", status);
0541 return status;
0542 }
0543
0544 static int
0545 nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
0546 unsigned int len, struct iattr *sattr)
0547 {
0548 struct nfs3_createdata *data;
0549 struct dentry *d_alias;
0550 int status = -ENOMEM;
0551
0552 if (len > NFS3_MAXPATHLEN)
0553 return -ENAMETOOLONG;
0554
0555 dprintk("NFS call symlink %pd\n", dentry);
0556
0557 data = nfs3_alloc_createdata();
0558 if (data == NULL)
0559 goto out;
0560 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
0561 data->arg.symlink.fromfh = NFS_FH(dir);
0562 data->arg.symlink.fromname = dentry->d_name.name;
0563 data->arg.symlink.fromlen = dentry->d_name.len;
0564 data->arg.symlink.pages = &page;
0565 data->arg.symlink.pathlen = len;
0566 data->arg.symlink.sattr = sattr;
0567
0568 d_alias = nfs3_do_create(dir, dentry, data);
0569 status = PTR_ERR_OR_ZERO(d_alias);
0570
0571 if (status == 0)
0572 dput(d_alias);
0573
0574 nfs3_free_createdata(data);
0575 out:
0576 dprintk("NFS reply symlink: %d\n", status);
0577 return status;
0578 }
0579
0580 static int
0581 nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
0582 {
0583 struct posix_acl *default_acl, *acl;
0584 struct nfs3_createdata *data;
0585 struct dentry *d_alias;
0586 int status = -ENOMEM;
0587
0588 dprintk("NFS call mkdir %pd\n", dentry);
0589
0590 data = nfs3_alloc_createdata();
0591 if (data == NULL)
0592 goto out;
0593
0594 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
0595 if (status)
0596 goto out;
0597
0598 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
0599 data->arg.mkdir.fh = NFS_FH(dir);
0600 data->arg.mkdir.name = dentry->d_name.name;
0601 data->arg.mkdir.len = dentry->d_name.len;
0602 data->arg.mkdir.sattr = sattr;
0603
0604 d_alias = nfs3_do_create(dir, dentry, data);
0605 status = PTR_ERR_OR_ZERO(d_alias);
0606
0607 if (status != 0)
0608 goto out_release_acls;
0609
0610 if (d_alias)
0611 dentry = d_alias;
0612
0613 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
0614
0615 dput(d_alias);
0616 out_release_acls:
0617 posix_acl_release(acl);
0618 posix_acl_release(default_acl);
0619 out:
0620 nfs3_free_createdata(data);
0621 dprintk("NFS reply mkdir: %d\n", status);
0622 return status;
0623 }
0624
0625 static int
0626 nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
0627 {
0628 struct nfs_fattr *dir_attr;
0629 struct nfs3_diropargs arg = {
0630 .fh = NFS_FH(dir),
0631 .name = name->name,
0632 .len = name->len
0633 };
0634 struct rpc_message msg = {
0635 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
0636 .rpc_argp = &arg,
0637 };
0638 int status = -ENOMEM;
0639
0640 dprintk("NFS call rmdir %s\n", name->name);
0641 dir_attr = nfs_alloc_fattr();
0642 if (dir_attr == NULL)
0643 goto out;
0644
0645 msg.rpc_resp = dir_attr;
0646 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0647 nfs_post_op_update_inode(dir, dir_attr);
0648 nfs_free_fattr(dir_attr);
0649 out:
0650 dprintk("NFS reply rmdir: %d\n", status);
0651 return status;
0652 }
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663 static int nfs3_proc_readdir(struct nfs_readdir_arg *nr_arg,
0664 struct nfs_readdir_res *nr_res)
0665 {
0666 struct inode *dir = d_inode(nr_arg->dentry);
0667 struct nfs3_readdirargs arg = {
0668 .fh = NFS_FH(dir),
0669 .cookie = nr_arg->cookie,
0670 .plus = nr_arg->plus,
0671 .count = nr_arg->page_len,
0672 .pages = nr_arg->pages
0673 };
0674 struct nfs3_readdirres res = {
0675 .verf = nr_res->verf,
0676 .plus = nr_arg->plus,
0677 };
0678 struct rpc_message msg = {
0679 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
0680 .rpc_argp = &arg,
0681 .rpc_resp = &res,
0682 .rpc_cred = nr_arg->cred,
0683 };
0684 int status = -ENOMEM;
0685
0686 if (nr_arg->plus)
0687 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
0688 if (arg.cookie)
0689 memcpy(arg.verf, nr_arg->verf, sizeof(arg.verf));
0690
0691 dprintk("NFS call readdir%s %llu\n", nr_arg->plus ? "plus" : "",
0692 (unsigned long long)nr_arg->cookie);
0693
0694 res.dir_attr = nfs_alloc_fattr();
0695 if (res.dir_attr == NULL)
0696 goto out;
0697
0698 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0699
0700 nfs_invalidate_atime(dir);
0701 nfs_refresh_inode(dir, res.dir_attr);
0702
0703 nfs_free_fattr(res.dir_attr);
0704 out:
0705 dprintk("NFS reply readdir%s: %d\n", nr_arg->plus ? "plus" : "",
0706 status);
0707 return status;
0708 }
0709
0710 static int
0711 nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
0712 dev_t rdev)
0713 {
0714 struct posix_acl *default_acl, *acl;
0715 struct nfs3_createdata *data;
0716 struct dentry *d_alias;
0717 int status = -ENOMEM;
0718
0719 dprintk("NFS call mknod %pd %u:%u\n", dentry,
0720 MAJOR(rdev), MINOR(rdev));
0721
0722 data = nfs3_alloc_createdata();
0723 if (data == NULL)
0724 goto out;
0725
0726 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
0727 if (status)
0728 goto out;
0729
0730 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
0731 data->arg.mknod.fh = NFS_FH(dir);
0732 data->arg.mknod.name = dentry->d_name.name;
0733 data->arg.mknod.len = dentry->d_name.len;
0734 data->arg.mknod.sattr = sattr;
0735 data->arg.mknod.rdev = rdev;
0736
0737 switch (sattr->ia_mode & S_IFMT) {
0738 case S_IFBLK:
0739 data->arg.mknod.type = NF3BLK;
0740 break;
0741 case S_IFCHR:
0742 data->arg.mknod.type = NF3CHR;
0743 break;
0744 case S_IFIFO:
0745 data->arg.mknod.type = NF3FIFO;
0746 break;
0747 case S_IFSOCK:
0748 data->arg.mknod.type = NF3SOCK;
0749 break;
0750 default:
0751 status = -EINVAL;
0752 goto out_release_acls;
0753 }
0754
0755 d_alias = nfs3_do_create(dir, dentry, data);
0756 status = PTR_ERR_OR_ZERO(d_alias);
0757 if (status != 0)
0758 goto out_release_acls;
0759
0760 if (d_alias)
0761 dentry = d_alias;
0762
0763 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
0764
0765 dput(d_alias);
0766 out_release_acls:
0767 posix_acl_release(acl);
0768 posix_acl_release(default_acl);
0769 out:
0770 nfs3_free_createdata(data);
0771 dprintk("NFS reply mknod: %d\n", status);
0772 return status;
0773 }
0774
0775 static int
0776 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
0777 struct nfs_fsstat *stat)
0778 {
0779 struct rpc_message msg = {
0780 .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
0781 .rpc_argp = fhandle,
0782 .rpc_resp = stat,
0783 };
0784 int status;
0785
0786 dprintk("NFS call fsstat\n");
0787 nfs_fattr_init(stat->fattr);
0788 status = rpc_call_sync(server->client, &msg, 0);
0789 dprintk("NFS reply fsstat: %d\n", status);
0790 return status;
0791 }
0792
0793 static int
0794 do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
0795 struct nfs_fsinfo *info)
0796 {
0797 struct rpc_message msg = {
0798 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
0799 .rpc_argp = fhandle,
0800 .rpc_resp = info,
0801 };
0802 int status;
0803
0804 dprintk("NFS call fsinfo\n");
0805 nfs_fattr_init(info->fattr);
0806 status = rpc_call_sync(client, &msg, 0);
0807 dprintk("NFS reply fsinfo: %d\n", status);
0808 return status;
0809 }
0810
0811
0812
0813
0814
0815 static int
0816 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
0817 struct nfs_fsinfo *info)
0818 {
0819 int status;
0820
0821 status = do_proc_fsinfo(server->client, fhandle, info);
0822 if (status && server->nfs_client->cl_rpcclient != server->client)
0823 status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
0824 return status;
0825 }
0826
0827 static int
0828 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
0829 struct nfs_pathconf *info)
0830 {
0831 struct rpc_message msg = {
0832 .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
0833 .rpc_argp = fhandle,
0834 .rpc_resp = info,
0835 };
0836 int status;
0837
0838 dprintk("NFS call pathconf\n");
0839 nfs_fattr_init(info->fattr);
0840 status = rpc_call_sync(server->client, &msg, 0);
0841 dprintk("NFS reply pathconf: %d\n", status);
0842 return status;
0843 }
0844
0845 static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
0846 {
0847 struct inode *inode = hdr->inode;
0848 struct nfs_server *server = NFS_SERVER(inode);
0849
0850 if (hdr->pgio_done_cb != NULL)
0851 return hdr->pgio_done_cb(task, hdr);
0852
0853 if (nfs3_async_handle_jukebox(task, inode))
0854 return -EAGAIN;
0855
0856 if (task->tk_status >= 0 && !server->read_hdrsize)
0857 cmpxchg(&server->read_hdrsize, 0, hdr->res.replen);
0858
0859 nfs_invalidate_atime(inode);
0860 nfs_refresh_inode(inode, &hdr->fattr);
0861 return 0;
0862 }
0863
0864 static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr,
0865 struct rpc_message *msg)
0866 {
0867 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
0868 hdr->args.replen = NFS_SERVER(hdr->inode)->read_hdrsize;
0869 }
0870
0871 static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
0872 struct nfs_pgio_header *hdr)
0873 {
0874 rpc_call_start(task);
0875 return 0;
0876 }
0877
0878 static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
0879 {
0880 struct inode *inode = hdr->inode;
0881
0882 if (hdr->pgio_done_cb != NULL)
0883 return hdr->pgio_done_cb(task, hdr);
0884
0885 if (nfs3_async_handle_jukebox(task, inode))
0886 return -EAGAIN;
0887 if (task->tk_status >= 0)
0888 nfs_writeback_update_inode(hdr);
0889 return 0;
0890 }
0891
0892 static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr,
0893 struct rpc_message *msg,
0894 struct rpc_clnt **clnt)
0895 {
0896 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
0897 }
0898
0899 static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
0900 {
0901 rpc_call_start(task);
0902 }
0903
0904 static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
0905 {
0906 if (data->commit_done_cb != NULL)
0907 return data->commit_done_cb(task, data);
0908
0909 if (nfs3_async_handle_jukebox(task, data->inode))
0910 return -EAGAIN;
0911 nfs_refresh_inode(data->inode, data->res.fattr);
0912 return 0;
0913 }
0914
0915 static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
0916 struct rpc_clnt **clnt)
0917 {
0918 msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
0919 }
0920
0921 static void nfs3_nlm_alloc_call(void *data)
0922 {
0923 struct nfs_lock_context *l_ctx = data;
0924 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
0925 get_nfs_open_context(l_ctx->open_context);
0926 nfs_get_lock_context(l_ctx->open_context);
0927 }
0928 }
0929
0930 static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data)
0931 {
0932 struct nfs_lock_context *l_ctx = data;
0933 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags))
0934 return nfs_async_iocounter_wait(task, l_ctx);
0935 return false;
0936
0937 }
0938
0939 static void nfs3_nlm_release_call(void *data)
0940 {
0941 struct nfs_lock_context *l_ctx = data;
0942 struct nfs_open_context *ctx;
0943 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
0944 ctx = l_ctx->open_context;
0945 nfs_put_lock_context(l_ctx);
0946 put_nfs_open_context(ctx);
0947 }
0948 }
0949
0950 static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = {
0951 .nlmclnt_alloc_call = nfs3_nlm_alloc_call,
0952 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare,
0953 .nlmclnt_release_call = nfs3_nlm_release_call,
0954 };
0955
0956 static int
0957 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
0958 {
0959 struct inode *inode = file_inode(filp);
0960 struct nfs_lock_context *l_ctx = NULL;
0961 struct nfs_open_context *ctx = nfs_file_open_context(filp);
0962 int status;
0963
0964 if (fl->fl_flags & FL_CLOSE) {
0965 l_ctx = nfs_get_lock_context(ctx);
0966 if (IS_ERR(l_ctx))
0967 l_ctx = NULL;
0968 else
0969 set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags);
0970 }
0971
0972 status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx);
0973
0974 if (l_ctx)
0975 nfs_put_lock_context(l_ctx);
0976
0977 return status;
0978 }
0979
0980 static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
0981 {
0982 return 0;
0983 }
0984
0985 static const struct inode_operations nfs3_dir_inode_operations = {
0986 .create = nfs_create,
0987 .lookup = nfs_lookup,
0988 .link = nfs_link,
0989 .unlink = nfs_unlink,
0990 .symlink = nfs_symlink,
0991 .mkdir = nfs_mkdir,
0992 .rmdir = nfs_rmdir,
0993 .mknod = nfs_mknod,
0994 .rename = nfs_rename,
0995 .permission = nfs_permission,
0996 .getattr = nfs_getattr,
0997 .setattr = nfs_setattr,
0998 #ifdef CONFIG_NFS_V3_ACL
0999 .listxattr = nfs3_listxattr,
1000 .get_acl = nfs3_get_acl,
1001 .set_acl = nfs3_set_acl,
1002 #endif
1003 };
1004
1005 static const struct inode_operations nfs3_file_inode_operations = {
1006 .permission = nfs_permission,
1007 .getattr = nfs_getattr,
1008 .setattr = nfs_setattr,
1009 #ifdef CONFIG_NFS_V3_ACL
1010 .listxattr = nfs3_listxattr,
1011 .get_acl = nfs3_get_acl,
1012 .set_acl = nfs3_set_acl,
1013 #endif
1014 };
1015
1016 const struct nfs_rpc_ops nfs_v3_clientops = {
1017 .version = 3,
1018 .dentry_ops = &nfs_dentry_operations,
1019 .dir_inode_ops = &nfs3_dir_inode_operations,
1020 .file_inode_ops = &nfs3_file_inode_operations,
1021 .file_ops = &nfs_file_operations,
1022 .nlmclnt_ops = &nlmclnt_fl_close_lock_ops,
1023 .getroot = nfs3_proc_get_root,
1024 .submount = nfs_submount,
1025 .try_get_tree = nfs_try_get_tree,
1026 .getattr = nfs3_proc_getattr,
1027 .setattr = nfs3_proc_setattr,
1028 .lookup = nfs3_proc_lookup,
1029 .lookupp = nfs3_proc_lookupp,
1030 .access = nfs3_proc_access,
1031 .readlink = nfs3_proc_readlink,
1032 .create = nfs3_proc_create,
1033 .remove = nfs3_proc_remove,
1034 .unlink_setup = nfs3_proc_unlink_setup,
1035 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
1036 .unlink_done = nfs3_proc_unlink_done,
1037 .rename_setup = nfs3_proc_rename_setup,
1038 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
1039 .rename_done = nfs3_proc_rename_done,
1040 .link = nfs3_proc_link,
1041 .symlink = nfs3_proc_symlink,
1042 .mkdir = nfs3_proc_mkdir,
1043 .rmdir = nfs3_proc_rmdir,
1044 .readdir = nfs3_proc_readdir,
1045 .mknod = nfs3_proc_mknod,
1046 .statfs = nfs3_proc_statfs,
1047 .fsinfo = nfs3_proc_fsinfo,
1048 .pathconf = nfs3_proc_pathconf,
1049 .decode_dirent = nfs3_decode_dirent,
1050 .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare,
1051 .read_setup = nfs3_proc_read_setup,
1052 .read_done = nfs3_read_done,
1053 .write_setup = nfs3_proc_write_setup,
1054 .write_done = nfs3_write_done,
1055 .commit_setup = nfs3_proc_commit_setup,
1056 .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare,
1057 .commit_done = nfs3_commit_done,
1058 .lock = nfs3_proc_lock,
1059 .clear_acl_cache = forget_all_cached_acls,
1060 .close_context = nfs_close_context,
1061 .have_delegation = nfs3_have_delegation,
1062 .alloc_client = nfs_alloc_client,
1063 .init_client = nfs_init_client,
1064 .free_client = nfs_free_client,
1065 .create_server = nfs3_create_server,
1066 .clone_server = nfs3_clone_server,
1067 };