From 6834b8a72152be22a7424c4fe76936bd3a242edf Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Tue, 31 Jul 2018 10:03:46 +0200 Subject: [PATCH] nfs: introduce NFS4Client#getOwnerId Motivation: client's long-hand owner id is a client side identifier which is used by server identify client on initial EXCHANGE_ID or SETCLIENT_ID (v4.0). Moreover, during reboot recovery server uses owner id to find records associated with a previous instance of the server. Modification: add NFS4Client#getOwnerId to make it possible to get client's owner id. Remove NFS4Client#isOwner. Result: Client's long-hand owner id is available for later use. Acked-by: Marina Sahakyan Target: master --- .../java/org/dcache/nfs/v4/NFS4Client.java | 19 ++++++++----------- .../org/dcache/nfs/v4/NFSv4StateHandler.java | 9 ++++++++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/dcache/nfs/v4/NFS4Client.java b/core/src/main/java/org/dcache/nfs/v4/NFS4Client.java index 34849391d..94cebb169 100644 --- a/core/src/main/java/org/dcache/nfs/v4/NFS4Client.java +++ b/core/src/main/java/org/dcache/nfs/v4/NFS4Client.java @@ -86,17 +86,15 @@ public class NFS4Client { */ /** - * The client identifier string, from the eia_clientowner structure - * of the EXCHANGE_ID4args structure + * Variable length string that uniquely defines the client. */ private final byte[] _ownerId; /** - * A client-specific value used to indicate reboots, from - * the eia_clientowner structure of the EXCHANGE_ID4args structure + * Verifier that is used to detect client reboots. */ - private final verifier4 _verifier; + /** * The RPCSEC_GSS principal sent via the RPC headers. */ @@ -192,7 +190,7 @@ public NFS4Client(NFSv4StateHandler stateHandler, clientid4 clientId, int minorV byte[] ownerID, verifier4 verifier, Principal principal, long leaseTime, boolean calbackNeeded) { _stateHandler = stateHandler; - _ownerId = ownerID; + _ownerId = Arrays.copyOf(ownerID, ownerID.length); _verifier = verifier; _principal = principal; _clientId = clientId; @@ -222,12 +220,11 @@ public int getMinorVersion() { } /** - * Check whatever client belongs to the provider owner. - * @param other client owner to test. - * @return true iff client belongs to the provider owner. + * Get client's long-hand unique identifier. + * @return client's unique identifier. */ - public boolean isOwner(byte[] other) { - return Arrays.equals(_ownerId, other); + public byte[] getOwnerId() { + return _ownerId; } /** diff --git a/core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java b/core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java index f74b80630..c247560fe 100644 --- a/core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java +++ b/core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java @@ -24,6 +24,7 @@ import java.net.InetSocketAddress; import java.security.Principal; +import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -186,11 +187,17 @@ public synchronized NFS4Client getClient(sessionid4 id) throws ChimeraNFSExcepti return client; } + /** + * Get existing, possibly not valid, client record that matches given client side generated long-hand owner identifier. + * @param ownerid client side generated long-hand owner identifier. + * + * @return an existing client record or null, if not matching record found. + */ public synchronized NFS4Client clientByOwner(byte[] ownerid) { return _clientsByServerId.entries() .stream() .map(CacheElement::getObject) - .filter(c -> c.isOwner(ownerid)) + .filter(c -> Arrays.equals(c.getOwnerId(), ownerid)) .findAny() .orElse(null); }