Commit 3fc3f452 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfsv41: sessions: use directly stateid instead of String representation

parent 8a1f7952
......@@ -60,7 +60,7 @@ public class DeviceManager implements NFSv41DeviceManager {
byte[] data = id2deviceid(id);
_log.log(Level.FINEST, "generating new device: {0} ({1}) for stateid {2}",
new Object[] {Arrays.toString(data), id, Arrays.toString(stateid.other)}
new Object[] {Arrays.toString(data), id, stateid}
);
InetAddress addr = null;
......@@ -143,8 +143,7 @@ public class DeviceManager implements NFSv41DeviceManager {
*/
public void releaseDevice(stateid4 stateid) {
// I'am fine
_log.log(Level.FINEST, "release device for stateid {1}",
Arrays.toString(stateid.other) );
_log.log(Level.FINEST, "release device for stateid {0}", stateid );
}
public static byte[] id2deviceid(int id) {
......
......@@ -17,6 +17,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import org.dcache.chimera.nfs.v4.xdr.stateid4;
public class NFS4Client {
......@@ -77,7 +78,7 @@ public class NFS4Client {
private static final Logger _log = Logger.getLogger(NFS4Client.class.getName());
private Map<String, NFS4State> _clinetStates = new HashMap<String, NFS4State>();
private Map<stateid4, NFS4State> _clinetStates = new HashMap<stateid4, NFS4State>();
/**
* sessions associated with the client
......@@ -234,12 +235,12 @@ public class NFS4Client {
public void addState(NFS4State state) {
_clinetStates.put(new String(state.other()), state);
_clinetStates.put(state.stateid(), state);
}
public NFS4State state( String state) {
return _clinetStates.get(state);
public NFS4State state( stateid4 stateid) {
return _clinetStates.get(stateid);
}
@Override
......
......@@ -3,6 +3,9 @@
*/
package org.dcache.chimera.nfs.v4;
import org.dcache.chimera.nfs.v4.xdr.stateid4;
import org.dcache.chimera.nfs.v4.xdr.uint32_t;
class NFS4State {
......@@ -22,33 +25,28 @@ class NFS4State {
*/
private int _seqid = 0;
private byte[] _other = new byte[12];
private final stateid4 _stateid;
private boolean _isConfimed = false;
public NFS4State(int seqid) {
_stateid = new stateid4();
_stateid.other = new byte[12];
_stateid.seqid = new uint32_t(seqid);
byte[] other_local = Integer.toString( this.hashCode()).getBytes();
int len = other_local.length > 12 ? 12 : other_local.length;
System.arraycopy(other_local, 0, _other, 0, len);
System.arraycopy(other_local, 0, _stateid.other, 0, len);
for( int i = 0; i < 12 - len; i++ ) {
_other[len + i] = '0';
_stateid.other[len + i] = '0';
}
_seqid = seqid;
}
public int seqid() { return _seqid; }
public void bumpSeqid() { ++ _seqid; }
public byte [] other() {
return _other;
}
public void bumpSeqid() { ++ _stateid.seqid.value; }
public stateid4 stateid() {
return _stateid;
}
public void confirm() {
_isConfimed = true;
......
......@@ -29,7 +29,7 @@ public class NFSv4StateHandler {
// mapping between server generated clietid and nfs_client_id, not confirmed yet
private static Map<Long, NFS4Client> _clientsByServerId = new HashMap<Long, NFS4Client>();
private static Map<String, Long> _clientsByStateId = new HashMap<String, Long>();
private static Map<stateid4, Long> _clientsByStateId = new HashMap<stateid4, Long>();
private final Cache<sessionid4, NFSv41Session> _sessionById =
new Cache<sessionid4, NFSv41Session>("NFSv41 sessions", 5000, Long.MAX_VALUE, TimeUnit.SECONDS.toMillis(NFSv4Defaults.NFS4_LEASE_TIME*2));
......@@ -68,7 +68,7 @@ public class NFSv4StateHandler {
}
public Long getClientIdByStateId(String stateId) {
public Long getClientIdByStateId(stateid4 stateId) {
return _clientsByStateId.get(stateId);
}
......@@ -78,7 +78,7 @@ public class NFSv4StateHandler {
}
public void addClinetByStateID(String stateId, Long clientId) {
public void addClinetByStateID(stateid4 stateId, Long clientId) {
_clientsByStateId.put(stateId, clientId);
}
......@@ -106,9 +106,7 @@ public class NFSv4StateHandler {
public void updateClientLeaseTime(stateid4 stateid) throws ChimeraNFSException {
String stateID = new String(stateid.other);
Long clientId = _clientsByStateId.get(stateID);
Long clientId = _clientsByStateId.get(stateid);
if(clientId == null ) {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "No client ID associated with sate." );
}
......@@ -118,7 +116,7 @@ public class NFSv4StateHandler {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "No client associated with client id." );
}
NFS4State state = client.state(stateID);
NFS4State state = client.state(stateid);
if( state == null) {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "State not know to the client." );
}
......@@ -127,11 +125,10 @@ public class NFSv4StateHandler {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "State is not confirmed" );
}
if( state.seqid() != stateid.seqid.value ) {
if( state.stateid().seqid.value != stateid.seqid.value ) {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "Sequence id miss match." );
}
client.updateLeaseTime(NFSv4Defaults.NFS4_LEASE_TIME);
}
......
......@@ -11,7 +11,6 @@ import org.dcache.chimera.nfs.v4.xdr.uint32_t;
import org.dcache.chimera.nfs.v4.xdr.opentype4;
import org.dcache.chimera.nfs.v4.xdr.open_claim_type4;
import org.dcache.chimera.nfs.v4.xdr.fattr4;
import org.dcache.chimera.nfs.v4.xdr.stateid4;
import org.dcache.chimera.nfs.v4.xdr.open_delegation4;
import org.dcache.chimera.nfs.v4.xdr.uint64_t;
import org.dcache.chimera.nfs.v4.xdr.createmode4;
......@@ -83,28 +82,16 @@ public class OperationOPEN extends AbstractNFSv4Operation {
if(context.getSession() == null ){
res.resok4.rflags = new uint32_t( nfs4_prot.OPEN4_RESULT_LOCKTYPE_POSIX | nfs4_prot.OPEN4_RESULT_CONFIRM);
nfs4state = new NFS4State( _args.opopen.seqid.value.value);
res.resok4.stateid = new stateid4();
res.resok4.stateid.seqid = new uint32_t(nfs4state.seqid());
res.resok4.stateid.other = nfs4state.other();
}else {
res.resok4.rflags = new uint32_t(nfs4_prot.OPEN4_RESULT_LOCKTYPE_POSIX);
nfs4state = new NFS4State(context.getSession().getClient().currentSeqID());
res.resok4.stateid = new stateid4();
res.resok4.stateid.seqid = new uint32_t(nfs4state.seqid());
res.resok4.stateid.other = nfs4state.other();
context.getSession().getClient().nextSeqID();
}
res.resok4.stateid = nfs4state.stateid();
client.addState(nfs4state);
String stateID = new String( nfs4state.other() );
NFSv4StateHandler.getInstace().addClinetByStateID(stateID, clientid);
_log.log(Level.FINEST, "New stateID: {0} seqid: {1}",
new Object[] {stateID, nfs4state.seqid()}
);
NFSv4StateHandler.getInstace().addClinetByStateID(nfs4state.stateid(), clientid);
_log.log(Level.FINEST, "New stateID: {0}", nfs4state.stateid());
} catch (ChimeraNFSException he) {
_log.log(Level.FINE, "OPEN: ", he.getMessage());
......
package org.dcache.chimera.nfs.v4;
import org.dcache.chimera.nfs.v4.xdr.nfsstat4;
import org.dcache.chimera.nfs.v4.xdr.uint32_t;
import org.dcache.chimera.nfs.v4.xdr.stateid4;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
......@@ -37,11 +36,11 @@ public class OperationOPEN_CONFIRM extends AbstractNFSv4Operation {
throw new ChimeraNFSException(nfsstat4.NFS4ERR_INVAL, "path is a symlink");
}
String stateID = new String( _args.opopen_confirm.open_stateid.other);
stateid4 stateid = _args.opopen_confirm.open_stateid;
if(_log.isDebugEnabled() ) {
_log.debug("confirmed stateID: " + stateID + " seqid: " + _args.opopen_confirm.seqid.value.value );
_log.debug("confirmed stateID: " + stateid );
}
Long clientId = NFSv4StateHandler.getInstace().getClientIdByStateId(stateID);
Long clientId = NFSv4StateHandler.getInstace().getClientIdByStateId(stateid);
if(clientId == null ) {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "bad client id." );
}
......@@ -51,23 +50,21 @@ public class OperationOPEN_CONFIRM extends AbstractNFSv4Operation {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "bad client id." );
}
NFS4State state = client.state(stateID);
NFS4State state = client.state(stateid);
if( state == null) {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "bad client id." );
}
state.bumpSeqid();
if( state.seqid() != _args.opopen_confirm.seqid.value.value ) {
if( state.stateid().seqid.value != _args.opopen_confirm.seqid.value.value ) {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_SEQID, "bad seqid." );
}
state.confirm();
res.resok4 = new OPEN_CONFIRM4resok();
res.resok4.open_stateid = new stateid4();
res.resok4.open_stateid.seqid = new uint32_t( state.seqid() );
res.resok4.open_stateid.other = state.other();
res.resok4.open_stateid = state.stateid();
res.status = nfsstat4.NFS4_OK;
......
......@@ -4,7 +4,6 @@
* See http://remotetea.sourceforge.net for details
*/
package org.dcache.chimera.nfs.v4.xdr;
import org.dcache.chimera.nfs.v4.*;
import org.dcache.xdr.*;
import java.io.IOException;
......
......@@ -53,5 +53,20 @@ public class stateid4 implements XdrAble, Serializable {
return seqid == null? 17 : seqid.value;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[");
for(byte b : other) {
if(b < 0x10)
sb.append("0");
sb.append(Integer.toHexString(b));
}
sb.append(", seq: ").append(seqid.value).append("]");
return sb.toString();
}
}
// End of stateid4.java
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment