nfs42proc.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
  3. */
  4. #include <linux/fs.h>
  5. #include <linux/sunrpc/sched.h>
  6. #include <linux/nfs.h>
  7. #include <linux/nfs3.h>
  8. #include <linux/nfs4.h>
  9. #include <linux/nfs_xdr.h>
  10. #include <linux/nfs_fs.h>
  11. #include "nfs4_fs.h"
  12. #include "nfs42.h"
  13. static int nfs42_set_rw_stateid(nfs4_stateid *dst, struct file *file,
  14. fmode_t fmode)
  15. {
  16. struct nfs_open_context *open;
  17. struct nfs_lock_context *lock;
  18. int ret;
  19. open = get_nfs_open_context(nfs_file_open_context(file));
  20. lock = nfs_get_lock_context(open);
  21. if (IS_ERR(lock)) {
  22. put_nfs_open_context(open);
  23. return PTR_ERR(lock);
  24. }
  25. ret = nfs4_set_rw_stateid(dst, open, lock, fmode);
  26. nfs_put_lock_context(lock);
  27. put_nfs_open_context(open);
  28. return ret;
  29. }
  30. loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
  31. {
  32. struct inode *inode = file_inode(filep);
  33. struct nfs42_seek_args args = {
  34. .sa_fh = NFS_FH(inode),
  35. .sa_offset = offset,
  36. .sa_what = (whence == SEEK_HOLE) ?
  37. NFS4_CONTENT_HOLE : NFS4_CONTENT_DATA,
  38. };
  39. struct nfs42_seek_res res;
  40. struct rpc_message msg = {
  41. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEEK],
  42. .rpc_argp = &args,
  43. .rpc_resp = &res,
  44. };
  45. struct nfs_server *server = NFS_SERVER(inode);
  46. int status;
  47. if (!(server->caps & NFS_CAP_SEEK))
  48. return -ENOTSUPP;
  49. status = nfs42_set_rw_stateid(&args.sa_stateid, filep, FMODE_READ);
  50. if (status)
  51. return status;
  52. nfs_wb_all(inode);
  53. status = nfs4_call_sync(server->client, server, &msg,
  54. &args.seq_args, &res.seq_res, 0);
  55. if (status == -ENOTSUPP)
  56. server->caps &= ~NFS_CAP_SEEK;
  57. if (status)
  58. return status;
  59. return vfs_setpos(filep, res.sr_offset, inode->i_sb->s_maxbytes);
  60. }