Skip to content

Commit

Permalink
nfs4: fix removal of derived states
Browse files Browse the repository at this point in the history
Motivation:
when derived state is not released, parent (open) state
disposal should take care and remove them, for instance,
CLOSE must release all locks associated with an opened
file.

Current implementation disposes the derived states, but
doesn't remove them, which leads to a memory leak.

Modification:
remove state if it's not disposed.

Result:
fixes state id leak

Acked-by: Paul Millar
Target: master
  • Loading branch information
kofemann committed Jan 26, 2017
1 parent b809636 commit aeb7544
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/main/java/org/dcache/nfs/v4/NFS4Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,14 @@ public NFS4State createState(StateOwner stateOwner, NFS4State openState) throws

NFS4State state = new NFS4State(openState, stateOwner, _stateHandler.createStateId(this, _stateIdCounter.incrementAndGet()));
if (openState != null) {
openState.addDisposeListener(s -> state.tryDispose());
openState.addDisposeListener(s -> {
// remove and dispose derived states.
NFS4State nfsState = _clientStates.remove(state.stateid());
if (nfsState != null) {
_log.debug("removing derived state {}", nfsState);
nfsState.tryDispose();
}
});
}
_clientStates.put(state.stateid(), state);
return state;
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/org/dcache/nfs/v4/NFS4State.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.dcache.nfs.v4;

import com.google.common.base.MoreObjects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -123,4 +124,15 @@ public StateOwner getStateOwner() {
synchronized public void addDisposeListener(StateDisposeListener disposeListener) {
_disposeListeners.add(disposeListener);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this.getClass().getSimpleName())
.add("stateid", _stateid)
.add("open-stateid", _openState == null? null : _openState.stateid())
.add("owner", _owner.getRawStateOwner())
.add("confirmed", _isConfimed)
.omitNullValues()
.toString();
}
}

0 comments on commit aeb7544

Please sign in to comment.