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