From 3cbe3f486f60cb0f6d55d72c52aec6bf6e8755b5 Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Fri, 6 Oct 2023 17:36:02 +0200 Subject: [PATCH] nfs: prepare code for removal of redundant stateid4 class Motivation: During split and refactoring of nfs4j code for backwar compatibility with older dCache version (2.6!) we have kept the org.dcache.chimera.nfs.v4.xdr.stateid class. Sommehot it have survived 10 years :). Modification: Update code to: - prepare pools to accept both stateid classes. - pools always sent stateid from nfs4j - doors send legacy stateid, but accept both. With with dcache 11.0 the legacy classes can be dropped. Result: prepare code for legacy class removal. Acked-by: Paul Millar Target: master Require-book: no Require-notes: no --- .../dcache/chimera/nfs/v4/xdr/stateid4.java | 1 + .../dcache/chimera/nfs/v4/xdr/uint32_t.java | 1 + .../chimera/nfsv41/common/LegacyUtils.java | 26 +++++++++++++++++++ .../chimera/nfsv41/door/NFSv41Door.java | 24 ++++++++++------- .../dcache/chimera/nfsv41/mover/NfsMover.java | 10 +++++-- .../nfsv41/mover/NfsTransferService.java | 12 ++++++--- 6 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/common/LegacyUtils.java diff --git a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfs/v4/xdr/stateid4.java b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfs/v4/xdr/stateid4.java index c5dfd909b9b..f6fd916302e 100644 --- a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfs/v4/xdr/stateid4.java +++ b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfs/v4/xdr/stateid4.java @@ -23,6 +23,7 @@ import java.io.Serializable; import java.util.Arrays; +@Deprecated(forRemoval = true) public class stateid4 implements Serializable { static final long serialVersionUID = -6677150504723505919L; diff --git a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfs/v4/xdr/uint32_t.java b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfs/v4/xdr/uint32_t.java index 97590396bd9..d666339bf2a 100644 --- a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfs/v4/xdr/uint32_t.java +++ b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfs/v4/xdr/uint32_t.java @@ -21,6 +21,7 @@ import java.io.Serializable; +@Deprecated(forRemoval = true) public class uint32_t implements Serializable { static final long serialVersionUID = -6603937444681096490L; diff --git a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/common/LegacyUtils.java b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/common/LegacyUtils.java new file mode 100644 index 00000000000..b831e00ca11 --- /dev/null +++ b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/common/LegacyUtils.java @@ -0,0 +1,26 @@ +package org.dcache.chimera.nfsv41.common; + +import org.dcache.nfs.v4.xdr.stateid4; + +/** + * Utility class to support removal of legacy stateid class. + */ +@Deprecated(forRemoval = true) +public class LegacyUtils { + + private LegacyUtils() { + // no instance allowed + } + + public static stateid4 toStateid(Object stateObject) { + stateid4 stateid; + if (stateObject instanceof stateid4) { + stateid = (stateid4) stateObject; + } else { + org.dcache.chimera.nfs.v4.xdr.stateid4 legacyStateid + = (org.dcache.chimera.nfs.v4.xdr.stateid4) stateObject; + stateid = new stateid4(legacyStateid.other, legacyStateid.seqid.value); + } + return stateid; + } +} diff --git a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/door/NFSv41Door.java b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/door/NFSv41Door.java index 789bfcc3835..3c7e9e11699 100644 --- a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/door/NFSv41Door.java +++ b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/door/NFSv41Door.java @@ -89,6 +89,7 @@ import org.dcache.chimera.FsInode; import org.dcache.chimera.FsInodeType; import org.dcache.chimera.JdbcFs; +import org.dcache.chimera.nfsv41.common.LegacyUtils; import org.dcache.chimera.nfsv41.common.StatsDecoratedOperationExecutor; import org.dcache.chimera.nfsv41.door.proxy.NfsProxyIoFactory; import org.dcache.chimera.nfsv41.door.proxy.ProxyIoFactory; @@ -528,8 +529,7 @@ public void destroy() throws IOException { * and NFSv4.1 device id. Finally, notify waiting request that we have got * the reply for LAYOUTGET */ - public void messageArrived( - PoolPassiveIoFileMessage message) { + public void messageArrived(PoolPassiveIoFileMessage message) { String poolName = message.getPoolName(); long verifier = message.getVerifier(); @@ -539,9 +539,13 @@ public void messageArrived( PoolDS device = _poolDeviceMap.getOrCreateDS(poolName, verifier, poolAddresses); - org.dcache.chimera.nfs.v4.xdr.stateid4 legacyStateid = message.challange(); - NfsTransfer transfer = _transfers.get( - new stateid4(legacyStateid.other, legacyStateid.seqid.value)); + + // REVISIT 11.0: remove drop legacy support. Old polls will send legacy stateid. + // stateid4 stateid = message.challange(); + Object stateObject = message.challange(); + stateid4 stateid = LegacyUtils.toStateid(stateObject); + NfsTransfer transfer = _transfers.get(stateid); + /* * We got a notification for a transfer which was not * started by us. @@ -591,10 +595,12 @@ public void messageArrived(DoorTransferFinishedMessage transferFinishedMessage) } } - public DoorValidateMoverMessage messageArrived( - DoorValidateMoverMessage message) { - org.dcache.chimera.nfs.v4.xdr.stateid4 legacyStateid = message.getChallenge(); - stateid4 stateid = new stateid4(legacyStateid.other, legacyStateid.seqid.value); + public DoorValidateMoverMessage messageArrived(DoorValidateMoverMessage message) { + + // REVISIT 11.0: remove drop legacy support. Old polls will send legacy stateid. + // stateid4 stateid = message.getChallenge(); + Object stateObject = message.getChallenge(); + stateid4 stateid = LegacyUtils.toStateid(stateObject); boolean isValid = false; try { diff --git a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/mover/NfsMover.java b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/mover/NfsMover.java index 6cdd56af9ea..ce6f7e5133e 100644 --- a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/mover/NfsMover.java +++ b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/mover/NfsMover.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.nio.channels.CompletionHandler; +import org.dcache.chimera.nfsv41.common.LegacyUtils; import org.dcache.nfs.ChimeraNFSException; import org.dcache.nfs.status.NfsIoException; import org.dcache.nfs.v4.NFS4State; @@ -51,8 +52,13 @@ public NfsMover(ReplicaDescriptor handle, PoolIoFileMessage message, CellPath pa NfsTransferService nfsTransferService, PnfsHandler pnfsHandler) { super(handle, message, pathToDoor, nfsTransferService); _nfsTransferService = nfsTransferService; - org.dcache.chimera.nfs.v4.xdr.stateid4 legacyStateid = getProtocolInfo().stateId(); - _state = new MoverState(null, new stateid4(legacyStateid.other, legacyStateid.seqid.value)); + + // REVISIT 11.0: remove drop legacy support + // stateid4 stateid = getProtocolInfo().stateId(); + Object stateObject = getProtocolInfo().stateId(); + stateid4 stateid = LegacyUtils.toStateid(stateObject); + + _state = new MoverState(null, stateid); _namespace = pnfsHandler; } diff --git a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/mover/NfsTransferService.java b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/mover/NfsTransferService.java index 63064c86794..f222ab1e4f4 100644 --- a/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/mover/NfsTransferService.java +++ b/modules/dcache-nfs/src/main/java/org/dcache/chimera/nfsv41/mover/NfsTransferService.java @@ -44,6 +44,7 @@ import javax.annotation.Nullable; import org.dcache.auth.Subjects; import org.dcache.cells.CellStub; +import org.dcache.chimera.nfsv41.common.LegacyUtils; import org.dcache.chimera.nfsv41.common.StatsDecoratedOperationExecutor; import org.dcache.commons.stats.RequestExecutionTimeGauges; import org.dcache.nfs.ChimeraNFSException; @@ -342,11 +343,16 @@ public Cancellable executeMover(final NfsMover mover, public void notifyDoorWithRedirect(NfsMover mover) { CellPath directDoorPath = new CellPath(mover.getPathToDoor().getDestinationAddress()); - final org.dcache.chimera.nfs.v4.xdr.stateid4 legacyStateId = mover.getProtocolInfo() - .stateId(); + + // REVISIT 11.0: remove drop legacy support + // stateid4 stateid = mover.getProtocolInfo().stateId(); + Object stateObject = mover.getProtocolInfo().stateId(); + stateid4 stateid = LegacyUtils.toStateid(stateObject); + + // never send legacy stateid. _door.notify(directDoorPath, new PoolPassiveIoFileMessage<>(_cellAddress.getCellName(), _localSocketAddresses, - legacyStateId, + stateid, _bootVerifier)); }