Subject: [nfsv4] protocol question about delegation stateid

From: Olga Kornievskaia <[email-masked]>
Date: Wed, 28 Jan 2015 18:44:10 -0500

Hi folks,

Can somebody clarify if the server is *required* to update the sequence
number of the delegation stateid when it receives an OPEN for which it has
already gave out a delegation before? Client sends one OPEN and server
gives out a delegation, then client sends another OPEN and server is
choosing returning a delegation again.

If the server is not required to update the delegation stateid sequence,
there is a problem with a racing DELEGRETURN and another OPEN from the same
file. Client is in the process of returning a delegation (due to resource
constraints) and a different thread on the client is opening the same file
it (had) the delegation for (at this point the client doesn't see the
delegation and thus sends the open request to the server). The server can
get the OPEN before the DELEGRETURN and from server's perspective it knows
the client has a delegation. If it does not increment the seqnumber when it
returns a delegation in OPEN, when the server receives a DELEGRETURN, the
server assumes the client is returning the delegation. However, the client
finishes processing the reply from the OPEN and stores the delegation. The
use of this delegation later results in BAD_STATEID error.

Let me state that server does have an option of not returning a delegation
to the client in this case. However, then the new open would lack the
benefits of a delegation and perhaps this should be acceptable solution to
deal with the race.

There is a general wording from the definition of the stateid that implies
that seqnumber should be incremented since delegation stateid is a stateid.
Handling of open stateids and need for incrementing is more clearly
specified in the spec.

from rfc 3530 (same wording in rfc 5661)
stateid4

                  struct stateid4 {
                    uint32_t        seqid;
                    opaque          other[12];
                  };

   This structure is used for the various state sharing mechanisms
   between the client and server.  For the client, this data structure
   is read-only.  The starting value of the seqid field is undefined.

*The server is required to increment the seqid field monotonically at
 each transition of the stateid.*

What should the server behavior be when it receives an OPEN for which it
already gave out a delegation?

Thank you.