flexfilelayoutxdr.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2016 Tom Haynes <loghyr@primarydata.com>
  3. */
  4. #include <linux/sunrpc/svc.h>
  5. #include <linux/nfs4.h>
  6. #include "nfsd.h"
  7. #include "flexfilelayoutxdr.h"
  8. #define NFSDDBG_FACILITY NFSDDBG_PNFS
  9. struct ff_idmap {
  10. char buf[11];
  11. int len;
  12. };
  13. __be32
  14. nfsd4_ff_encode_layoutget(struct xdr_stream *xdr,
  15. struct nfsd4_layoutget *lgp)
  16. {
  17. struct pnfs_ff_layout *fl = lgp->lg_content;
  18. int len, mirror_len, ds_len, fh_len;
  19. __be32 *p;
  20. /*
  21. * Unlike nfsd4_encode_user, we know these will
  22. * always be stringified.
  23. */
  24. struct ff_idmap uid;
  25. struct ff_idmap gid;
  26. fh_len = 4 + fl->fh.size;
  27. uid.len = sprintf(uid.buf, "%u", from_kuid(&init_user_ns, fl->uid));
  28. gid.len = sprintf(gid.buf, "%u", from_kgid(&init_user_ns, fl->gid));
  29. /* 8 + len for recording the length, name, and padding */
  30. ds_len = 20 + sizeof(stateid_opaque_t) + 4 + fh_len +
  31. 8 + uid.len + 8 + gid.len;
  32. mirror_len = 4 + ds_len;
  33. /* The layout segment */
  34. len = 20 + mirror_len;
  35. p = xdr_reserve_space(xdr, sizeof(__be32) + len);
  36. if (!p)
  37. return nfserr_toosmall;
  38. *p++ = cpu_to_be32(len);
  39. p = xdr_encode_hyper(p, 0); /* stripe unit of 1 */
  40. *p++ = cpu_to_be32(1); /* single mirror */
  41. *p++ = cpu_to_be32(1); /* single data server */
  42. p = xdr_encode_opaque_fixed(p, &fl->deviceid,
  43. sizeof(struct nfsd4_deviceid));
  44. *p++ = cpu_to_be32(1); /* efficiency */
  45. *p++ = cpu_to_be32(fl->stateid.si_generation);
  46. p = xdr_encode_opaque_fixed(p, &fl->stateid.si_opaque,
  47. sizeof(stateid_opaque_t));
  48. *p++ = cpu_to_be32(1); /* single file handle */
  49. p = xdr_encode_opaque(p, fl->fh.data, fl->fh.size);
  50. p = xdr_encode_opaque(p, uid.buf, uid.len);
  51. p = xdr_encode_opaque(p, gid.buf, gid.len);
  52. *p++ = cpu_to_be32(fl->flags);
  53. *p++ = cpu_to_be32(0); /* No stats collect hint */
  54. return 0;
  55. }
  56. __be32
  57. nfsd4_ff_encode_getdeviceinfo(struct xdr_stream *xdr,
  58. struct nfsd4_getdeviceinfo *gdp)
  59. {
  60. struct pnfs_ff_device_addr *da = gdp->gd_device;
  61. int len;
  62. int ver_len;
  63. int addr_len;
  64. __be32 *p;
  65. /* len + padding for two strings */
  66. addr_len = 16 + da->netaddr.netid_len + da->netaddr.addr_len;
  67. ver_len = 20;
  68. len = 4 + ver_len + 4 + addr_len;
  69. p = xdr_reserve_space(xdr, len + sizeof(__be32));
  70. if (!p)
  71. return nfserr_resource;
  72. /*
  73. * Fill in the overall length and number of volumes at the beginning
  74. * of the layout.
  75. */
  76. *p++ = cpu_to_be32(len);
  77. *p++ = cpu_to_be32(1); /* 1 netaddr */
  78. p = xdr_encode_opaque(p, da->netaddr.netid, da->netaddr.netid_len);
  79. p = xdr_encode_opaque(p, da->netaddr.addr, da->netaddr.addr_len);
  80. *p++ = cpu_to_be32(1); /* 1 versions */
  81. *p++ = cpu_to_be32(da->version);
  82. *p++ = cpu_to_be32(da->minor_version);
  83. *p++ = cpu_to_be32(da->rsize);
  84. *p++ = cpu_to_be32(da->wsize);
  85. *p++ = cpu_to_be32(da->tightly_coupled);
  86. return 0;
  87. }