Commit f237170b authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfsv41: include client's and server's socket accesses into NFSv4Client

In some cases we need to know where from client comes
and to which servers interface it's connected.

Acked-By; Paul
Patch: http://rb.dcache.org/r/1736/
parent fbb6b56d
......@@ -7,17 +7,18 @@ package org.dcache.chimera.nfs.v4;
* with great help of William A.(Andy) Adamson
*/
import org.dcache.chimera.nfs.v4.xdr.nfsstat4;
import org.dcache.chimera.nfs.ChimeraNFSException;
import org.apache.log4j.Logger;
import java.net.InetAddress;
import org.dcache.chimera.nfs.ChimeraNFSException;
import org.dcache.chimera.nfs.v4.xdr.nfsstat4;
import org.dcache.chimera.nfs.v4.xdr.stateid4;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Arrays;
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 {
......@@ -110,11 +111,22 @@ public class NFS4Client {
private long _srv_id = 0; // generated by server
private byte[] _srv_verifier = null; // generated by server
private InetAddress _clIp = null; // client ip address
/**
* Client's {@link InetSocketAddress} seen by server.
*/
private final InetSocketAddress _clientAddress;
/**
* Server's {@link InetSocketAddress} seen by client;
*/
private final InetSocketAddress _localAddress;
private ClientCB _cl_cb = null; /* callback info */
public NFS4Client(String ownerID, byte[] verifier, String principal) {
public NFS4Client(InetSocketAddress clientAddress, InetSocketAddress localAddress,
String ownerID, byte[] verifier, String principal) {
_clientAddress = clientAddress;
_localAddress = localAddress;
_ownerID = ownerID;
_verifier = verifier;
_principal = principal;
......@@ -217,12 +229,20 @@ public class NFS4Client {
_cl_time = System.currentTimeMillis();
}
public InetAddress inetAddress() {
return _clIp;
/**
* Get the client's {@link InetSocketAddress} seen by server.
* @return client's address
*/
public InetSocketAddress getRemoteAddress() {
return _clientAddress;
}
public void inetAddress(InetAddress ip) {
_clIp = ip;
/**
* Get server's {@link InetSocketAddress} seen by the client.
* @return server's address
*/
public InetSocketAddress getLocalAddress() {
return _localAddress;
}
public int nextSeqID() {
......@@ -246,7 +266,8 @@ public class NFS4Client {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(_ownerID).append("@").append(_srv_id);
sb.append(_clientAddress).append(":").
append(_ownerID).append("@").append(_srv_id);
return sb.toString();
}
......
......@@ -118,9 +118,6 @@ public class OperationCREATE_SESSION extends AbstractNFSv4Operation {
NFSv4StateHandler.getInstace().sessionById(session.id(), session);
client.confirmed();
client.nextSeqID();
client.inetAddress( context.getRpcCall().getTransport().getRemoteSocketAddress().getAddress() );
}
client.refreshLeaseTime();
......
......@@ -19,6 +19,7 @@ import org.dcache.chimera.nfs.v4.xdr.EXCHANGE_ID4resok;
import org.dcache.chimera.nfs.ChimeraNFSException;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
......@@ -43,6 +44,7 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
* compile time
*/
private static String COMPILTE_TIME = "<UNKNOWN>";
static {
/*
* get 'Build-Time' attribute from jar file manifest ( if available )
......@@ -164,6 +166,8 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
boolean update = (_args.opexchange_id.eia_flags.value & nfs4_prot.EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) != 0;
InetSocketAddress remoteSocketAddress = context.getRpcCall().getTransport().getRemoteSocketAddress();
InetSocketAddress localSocketAddress = context.getRpcCall().getTransport().getLocalSocketAddress();
if(client == null){
......@@ -174,7 +178,8 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
// create a new client: case 1
_log.log(Level.FINEST, "Case 1: New Owner ID");
client = new NFS4Client(clientOwner, _args.opexchange_id.eia_clientowner.co_verifier.value , principal);
client = new NFS4Client(remoteSocketAddress, localSocketAddress,
clientOwner, _args.opexchange_id.eia_clientowner.co_verifier.value , principal);
NFSv4StateHandler.getInstace().addClient(client);
}else{
......@@ -206,7 +211,8 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
_log.log(Level.FINEST, "case 5: Client Restart");
NFSv4StateHandler.getInstace().removeClient(client);
client = new NFS4Client(new String(_args.opexchange_id.eia_clientowner.co_ownerid), _args.opexchange_id.eia_clientowner.co_verifier.value , principal);
client = new NFS4Client(remoteSocketAddress, localSocketAddress,
new String(_args.opexchange_id.eia_clientowner.co_ownerid), _args.opexchange_id.eia_clientowner.co_verifier.value , principal);
NFSv4StateHandler.getInstace().addClient(client);
}else {
_log.log(Level.FINEST, "Case 3: Client Collision");
......@@ -215,7 +221,8 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
}else{
_log.log(Level.FINEST, "case 4: Replacement of Unconfirmed Record");
NFSv4StateHandler.getInstace().removeClient(client);
client = new NFS4Client(new String(_args.opexchange_id.eia_clientowner.co_ownerid), _args.opexchange_id.eia_clientowner.co_verifier.value , principal);
client = new NFS4Client(remoteSocketAddress, localSocketAddress,
new String(_args.opexchange_id.eia_clientowner.co_ownerid), _args.opexchange_id.eia_clientowner.co_verifier.value , principal);
NFSv4StateHandler.getInstace().addClient(client);
}
......
......@@ -39,8 +39,9 @@ public class OperationSETCLIENTID extends AbstractNFSv4Operation {
String r_netid = _args.opsetclientid.callback.cb_location.na_r_netid;
int program = _args.opsetclientid.callback.cb_program.value;
NFS4Client client = new NFS4Client(new String(_args.opsetclientid.client.id),_args.opsetclientid.client.verifier.value, null );
client.inetAddress( context.getRpcCall().getTransport().getRemoteSocketAddress().getAddress() );
NFS4Client client = new NFS4Client(context.getRpcCall().getTransport().getRemoteSocketAddress(),
context.getRpcCall().getTransport().getLocalSocketAddress(),
new String(_args.opsetclientid.client.id),_args.opsetclientid.client.verifier.value, null );
try {
ClientCB cb = new ClientCB(r_addr, r_netid, program);
......
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