NFSv4: Clean up CB_GETATTR encoding
authorTrond Myklebust <trond.myklebust@primarydata.com>
Tue, 20 Mar 2018 21:03:12 +0000 (17:03 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Tue, 10 Apr 2018 20:06:22 +0000 (16:06 -0400)
Replace the open coded bitmap implementation with a generic one.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/callback_xdr.c

index 123c069429a7ba71fed0d1ed986eb7e764f75706..a813979b5be0c7b6491d3ca0843f6c63945ac959 100644 (file)
@@ -535,35 +535,10 @@ static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char
        return 0;
 }
 
-#define CB_SUPPORTED_ATTR0 (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE)
-#define CB_SUPPORTED_ATTR1 (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY)
-static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, __be32 **savep)
+static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, size_t sz)
 {
-       __be32 bm[2];
-       __be32 *p;
-
-       bm[0] = htonl(bitmap[0] & CB_SUPPORTED_ATTR0);
-       bm[1] = htonl(bitmap[1] & CB_SUPPORTED_ATTR1);
-       if (bm[1] != 0) {
-               p = xdr_reserve_space(xdr, 16);
-               if (unlikely(p == NULL))
-                       return htonl(NFS4ERR_RESOURCE);
-               *p++ = htonl(2);
-               *p++ = bm[0];
-               *p++ = bm[1];
-       } else if (bm[0] != 0) {
-               p = xdr_reserve_space(xdr, 12);
-               if (unlikely(p == NULL))
-                       return htonl(NFS4ERR_RESOURCE);
-               *p++ = htonl(1);
-               *p++ = bm[0];
-       } else {
-               p = xdr_reserve_space(xdr, 8);
-               if (unlikely(p == NULL))
-                       return htonl(NFS4ERR_RESOURCE);
-               *p++ = htonl(0);
-       }
-       *savep = p;
+       if (xdr_stream_encode_uint32_array(xdr, bitmap, sz) < 0)
+               return cpu_to_be32(NFS4ERR_RESOURCE);
        return 0;
 }
 
@@ -656,9 +631,13 @@ static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr,
        
        if (unlikely(status != 0))
                goto out;
-       status = encode_attr_bitmap(xdr, res->bitmap, &savep);
+       status = encode_attr_bitmap(xdr, res->bitmap, ARRAY_SIZE(res->bitmap));
        if (unlikely(status != 0))
                goto out;
+       status = cpu_to_be32(NFS4ERR_RESOURCE);
+       savep = xdr_reserve_space(xdr, sizeof(*savep));
+       if (unlikely(!savep))
+               goto out;
        status = encode_attr_change(xdr, res->bitmap, res->change_attr);
        if (unlikely(status != 0))
                goto out;