NFSv4: Add support for the FATTR4_OPEN_ARGUMENTS attribute
authorTrond Myklebust <trond.myklebust@primarydata.com>
Mon, 17 Jun 2024 01:21:32 +0000 (21:21 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Mon, 8 Jul 2024 17:47:25 +0000 (13:47 -0400)
Query the server for the OPEN arguments that it supports so that
we can figure out which extensions we can use.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Lance Shelton <lance.shelton@hammerspace.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/nfs4proc.c
fs/nfs/nfs4xdr.c
include/linux/nfs4.h
include/linux/nfs_xdr.h

index cbd340cd825e1447196dae4d0e4592a736f9a7de..ae91492e952177a95aa86b5ec84277476523a338 100644 (file)
@@ -3885,11 +3885,14 @@ static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
 
 #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL)
 #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL)
-#define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_TIME_DELEG_MODIFY - 1UL)
+#define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_OPEN_ARGUMENTS - 1UL)
 
 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
 {
-       u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion;
+       u32 minorversion = server->nfs_client->cl_minorversion;
+       u32 bitmask[3] = {
+               [0] = FATTR4_WORD0_SUPPORTED_ATTRS,
+       };
        struct nfs4_server_caps_arg args = {
                .fhandle = fhandle,
                .bitmask = bitmask,
@@ -3915,6 +3918,14 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f
 
        status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
        if (status == 0) {
+               bitmask[0] = (FATTR4_WORD0_SUPPORTED_ATTRS |
+                             FATTR4_WORD0_FH_EXPIRE_TYPE |
+                             FATTR4_WORD0_LINK_SUPPORT |
+                             FATTR4_WORD0_SYMLINK_SUPPORT |
+                             FATTR4_WORD0_ACLSUPPORT |
+                             FATTR4_WORD0_CASE_INSENSITIVE |
+                             FATTR4_WORD0_CASE_PRESERVING) &
+                            res.attr_bitmask[0];
                /* Sanity check the server answers */
                switch (minorversion) {
                case 0:
@@ -3923,9 +3934,14 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f
                        break;
                case 1:
                        res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK;
+                       bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT &
+                                    res.attr_bitmask[2];
                        break;
                case 2:
                        res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK;
+                       bitmask[2] = (FATTR4_WORD2_SUPPATTR_EXCLCREAT |
+                                     FATTR4_WORD2_OPEN_ARGUMENTS) &
+                                    res.attr_bitmask[2];
                }
                memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
                server->caps &= ~(NFS_CAP_ACLS | NFS_CAP_HARDLINKS |
index e160a275ad4aa76ffce16b78b40b5f4a2b2c0616..98aab2c324c91a4ec91bbd5a928e8a76e03f613f 100644 (file)
@@ -4337,6 +4337,28 @@ static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,
        return 0;
 }
 
+static int decode_attr_open_arguments(struct xdr_stream *xdr, uint32_t *bitmap,
+               struct nfs4_open_caps *res)
+{
+       memset(res, 0, sizeof(*res));
+       if (unlikely(bitmap[2] & (FATTR4_WORD2_OPEN_ARGUMENTS - 1U)))
+               return -EIO;
+       if (likely(bitmap[2] & FATTR4_WORD2_OPEN_ARGUMENTS)) {
+               if (decode_bitmap4(xdr, res->oa_share_access, ARRAY_SIZE(res->oa_share_access)) < 0)
+                       return -EIO;
+               if (decode_bitmap4(xdr, res->oa_share_deny, ARRAY_SIZE(res->oa_share_deny)) < 0)
+                       return -EIO;
+               if (decode_bitmap4(xdr, res->oa_share_access_want, ARRAY_SIZE(res->oa_share_access_want)) < 0)
+                       return -EIO;
+               if (decode_bitmap4(xdr, res->oa_open_claim, ARRAY_SIZE(res->oa_open_claim)) < 0)
+                       return -EIO;
+               if (decode_bitmap4(xdr, res->oa_createmode, ARRAY_SIZE(res->oa_createmode)) < 0)
+                       return -EIO;
+               bitmap[2] &= ~FATTR4_WORD2_OPEN_ARGUMENTS;
+       }
+       return 0;
+}
+
 static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
 {
        unsigned int attrwords = XDR_QUADLEN(attrlen);
@@ -4511,6 +4533,8 @@ static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_re
        if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
                                res->exclcreat_bitmask)) != 0)
                goto xdr_error;
+       if ((status = decode_attr_open_arguments(xdr, bitmap, &res->open_caps)) != 0)
+               goto xdr_error;
        status = verify_attr_len(xdr, savep, attrlen);
 xdr_error:
        dprintk("%s: xdr returned %d!\n", __func__, -status);
index c074e0ac390f9f32043572ae4f912e8fe9e3cb5f..f9df88091c6d7077f9cbefeff09cbbe135142e69 100644 (file)
@@ -512,6 +512,7 @@ enum {
 enum {
        FATTR4_TIME_DELEG_ACCESS        = 84,
        FATTR4_TIME_DELEG_MODIFY        = 85,
+       FATTR4_OPEN_ARGUMENTS           = 86,
 };
 
 /*
@@ -595,6 +596,7 @@ enum {
 #define FATTR4_WORD2_XATTR_SUPPORT     BIT(FATTR4_XATTR_SUPPORT - 64)
 #define FATTR4_WORD2_TIME_DELEG_ACCESS BIT(FATTR4_TIME_DELEG_ACCESS - 64)
 #define FATTR4_WORD2_TIME_DELEG_MODIFY BIT(FATTR4_TIME_DELEG_MODIFY - 64)
+#define FATTR4_WORD2_OPEN_ARGUMENTS    BIT(FATTR4_OPEN_ARGUMENTS - 64)
 
 /* MDS threshold bitmap bits */
 #define THRESHOLD_RD                    (1UL << 0)
index d8cfa956d24cb5447bf5cddab393f13b425dcb06..af510a7ec46acc5c8a09451df361e57c632cf0ed 100644 (file)
@@ -1213,6 +1213,14 @@ struct nfs4_statfs_res {
        struct nfs_fsstat              *fsstat;
 };
 
+struct nfs4_open_caps {
+       u32                             oa_share_access[1];
+       u32                             oa_share_deny[1];
+       u32                             oa_share_access_want[1];
+       u32                             oa_open_claim[1];
+       u32                             oa_createmode[1];
+};
+
 struct nfs4_server_caps_arg {
        struct nfs4_sequence_args       seq_args;
        struct nfs_fh                  *fhandle;
@@ -1229,6 +1237,7 @@ struct nfs4_server_caps_res {
        u32                             fh_expire_type;
        u32                             case_insensitive;
        u32                             case_preserving;
+       struct nfs4_open_caps           open_caps;
 };
 
 #define NFS4_PATHNAME_MAXCOMPONENTS 512