]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
NFSv4: Add recovery of attribute delegations
authorTrond Myklebust <trond.myklebust@primarydata.com>
Mon, 17 Jun 2024 01:21:26 +0000 (21:21 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Mon, 8 Jul 2024 17:47:25 +0000 (13:47 -0400)
After a reboot of the NFSv4.2 server, the recovery code needs to specify
whether the delegation to be recovered is an attribute delegation or
not.

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/nfs_xdr.h

index f4215dcf36149a36fd0a808bac445f863fcf169a..34182a3c38a78326ad1f2ae7b0644b641620b562 100644 (file)
@@ -2225,7 +2225,7 @@ static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state
 {
        struct nfs_delegation *delegation;
        struct nfs4_opendata *opendata;
-       fmode_t delegation_type = 0;
+       u32 delegation_type = NFS4_OPEN_DELEGATE_NONE;
        int status;
 
        opendata = nfs4_open_recoverdata_alloc(ctx, state,
@@ -2234,8 +2234,20 @@ static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state
                return PTR_ERR(opendata);
        rcu_read_lock();
        delegation = rcu_dereference(NFS_I(state->inode)->delegation);
-       if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
-               delegation_type = delegation->type;
+       if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) {
+               switch(delegation->type) {
+               case FMODE_READ:
+                       delegation_type = NFS4_OPEN_DELEGATE_READ;
+                       if (test_bit(NFS_DELEGATION_DELEGTIME, &delegation->flags))
+                               delegation_type = NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG;
+                       break;
+               case FMODE_WRITE:
+               case FMODE_READ|FMODE_WRITE:
+                       delegation_type = NFS4_OPEN_DELEGATE_WRITE;
+                       if (test_bit(NFS_DELEGATION_DELEGTIME, &delegation->flags))
+                               delegation_type = NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG;
+               }
+       }
        rcu_read_unlock();
        opendata->o_arg.u.delegation_type = delegation_type;
        status = nfs4_open_recover(opendata, state);
index 4c22b865b9c9a9c6fc43ada4c5c3b093d3024fe7..e160a275ad4aa76ffce16b78b40b5f4a2b2c0616 100644 (file)
@@ -1475,20 +1475,18 @@ static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *a
        }
 }
 
-static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
+static inline void encode_delegation_type(struct xdr_stream *xdr, u32 delegation_type)
 {
        __be32 *p;
 
        p = reserve_space(xdr, 4);
        switch (delegation_type) {
-       case 0:
-               *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
-               break;
-       case FMODE_READ:
-               *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
-               break;
-       case FMODE_WRITE|FMODE_READ:
-               *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
+       case NFS4_OPEN_DELEGATE_NONE:
+       case NFS4_OPEN_DELEGATE_READ:
+       case NFS4_OPEN_DELEGATE_WRITE:
+       case NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG:
+       case NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG:
+               *p = cpu_to_be32(delegation_type);
                break;
        default:
                BUG();
@@ -1504,7 +1502,7 @@ static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *
        encode_string(xdr, name->len, name->name);
 }
 
-static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
+static inline void encode_claim_previous(struct xdr_stream *xdr, u32 type)
 {
        __be32 *p;
 
index 51611583af51c5df00bf0221a75d6a10e0a0878e..d8cfa956d24cb5447bf5cddab393f13b425dcb06 100644 (file)
@@ -484,7 +484,7 @@ struct nfs_openargs {
                        nfs4_verifier   verifier; /* EXCLUSIVE */
                };
                nfs4_stateid    delegation;             /* CLAIM_DELEGATE_CUR */
-               fmode_t         delegation_type;        /* CLAIM_PREVIOUS */
+               __u32           delegation_type;        /* CLAIM_PREVIOUS */
        } u;
        const struct qstr *     name;
        const struct nfs_server *server;         /* Needed for ID mapping */