Commit 2f8e43ed authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfsv41: exchange_id refactoring

parent a2335790
...@@ -103,7 +103,7 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation { ...@@ -103,7 +103,7 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
} }
*/ */
byte[] clientOwner = _args.opexchange_id.eia_clientowner.co_ownerid; final byte[] clientOwner = _args.opexchange_id.eia_clientowner.co_ownerid;
/* /*
* check the state * check the state
...@@ -141,49 +141,41 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation { ...@@ -141,49 +141,41 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
throw new ChimeraNFSException(nfsstat.NFSERR_ACCESS, "SSV other than SP4NONE to use"); throw new ChimeraNFSException(nfsstat.NFSERR_ACCESS, "SSV other than SP4NONE to use");
} }
//decision variable for case selection
NFS4Client client = context.getStateHandler().clientByOwner(clientOwner); NFS4Client client = context.getStateHandler().clientByOwner(clientOwner);
String principal = Integer.toString(context.getUser().getUID()); final String principal = Integer.toString(context.getUser().getUID());
verifier4 verifier = _args.opexchange_id.eia_clientowner.co_verifier; final verifier4 verifier = _args.opexchange_id.eia_clientowner.co_verifier;
boolean update = (_args.opexchange_id.eia_flags.value & nfs4_prot.EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) != 0;
InetSocketAddress remoteSocketAddress = context.getRpcCall().getTransport().getRemoteSocketAddress(); final boolean update = (_args.opexchange_id.eia_flags.value & nfs4_prot.EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) != 0;
InetSocketAddress localSocketAddress = context.getRpcCall().getTransport().getLocalSocketAddress();
if (client == null) { final InetSocketAddress remoteSocketAddress = context.getRpcCall().getTransport().getRemoteSocketAddress();
final InetSocketAddress localSocketAddress = context.getRpcCall().getTransport().getLocalSocketAddress();
final NFSv4StateHandler stateHandler = context.getStateHandler();
if (update) { if (update) {
_log.debug("Case 7a: Update but No Confirmed Record"); if (client == null || !client.isConfirmed()) {
_log.debug("Update of no existing/confirmed Record (case 7)");
throw new ChimeraNFSException(nfsstat.NFSERR_NOENT, "no such client"); throw new ChimeraNFSException(nfsstat.NFSERR_NOENT, "no such client");
} }
// create a new client: case 1 if (!client.verifierEquals(verifier)) {
_log.debug("Case 1: New Owner ID"); _log.debug("case 8: Update but Wrong Verifier");
client = context.getStateHandler().createClient( throw new ChimeraNFSException(nfsstat.NFSERR_NOT_SAME, "Update but Wrong Verifier");
remoteSocketAddress, localSocketAddress, }
clientOwner, _args.opexchange_id.eia_clientowner.co_verifier, principal);
} else {
if (update) { if (!principal.equals(client.principal())) {
_log.debug("case 9: Update but Wrong Principal");
throw new ChimeraNFSException(nfsstat.NFSERR_PERM, "Principal Mismatch");
}
if (client.isConfirmed()) { _log.debug("Case 6: Update");
if (client.verifierEquals(verifier) && principal.equals(client.principal())) { client.refreshLeaseTime();
_log.debug("Case 6: Update"); } else {
} else if (!client.verifierEquals(verifier)) { if (client == null) {
_log.debug("case 8: Update but Wrong Verifier"); // create a new client: case 1
throw new ChimeraNFSException(nfsstat.NFSERR_NOT_SAME, "Update but Wrong Verifier"); _log.debug("Case 1: New Owner ID");
} else { client = stateHandler.createClient(
_log.debug("case 9: Update but Wrong Principal"); remoteSocketAddress, localSocketAddress,
throw new ChimeraNFSException(nfsstat.NFSERR_PERM, "Principal Mismatch"); clientOwner, _args.opexchange_id.eia_clientowner.co_verifier, principal);
}
} else {
_log.debug("Case 7b: Update but No Confirmed Record");
throw new ChimeraNFSException(nfsstat.NFSERR_NOENT, "no such client");
}
} else { } else {
...@@ -192,18 +184,18 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation { ...@@ -192,18 +184,18 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
_log.debug("Case 2: Non-Update on Existing Client ID"); _log.debug("Case 2: Non-Update on Existing Client ID");
if (!client.hasState()) { if (!client.hasState()) {
client.refreshLeaseTime(); client.refreshLeaseTime();
} }
} else if (principal.equals(client.principal())) { } else if (principal.equals(client.principal())) {
_log.debug("case 5: Client Restart"); _log.debug("case 5: Client Restart");
context.getStateHandler().removeClient(client); stateHandler.removeClient(client);
client = context.getStateHandler().createClient( client = stateHandler.createClient(
remoteSocketAddress, localSocketAddress, remoteSocketAddress, localSocketAddress,
clientOwner, _args.opexchange_id.eia_clientowner.co_verifier, principal); clientOwner, _args.opexchange_id.eia_clientowner.co_verifier, principal);
} else { } else {
_log.debug("Case 3b: Client Collision"); _log.debug("Case 3b: Client Collision");
if ((!client.hasState()) || !client.isLeaseValid()) { if ((!client.hasState()) || !client.isLeaseValid()) {
context.getStateHandler().removeClient(client); stateHandler.removeClient(client);
client = context.getStateHandler().createClient( client = stateHandler.createClient(
remoteSocketAddress, localSocketAddress, remoteSocketAddress, localSocketAddress,
clientOwner, _args.opexchange_id.eia_clientowner.co_verifier, principal); clientOwner, _args.opexchange_id.eia_clientowner.co_verifier, principal);
} else { } else {
...@@ -212,16 +204,14 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation { ...@@ -212,16 +204,14 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
} }
} else { } else {
_log.debug("case 4: Replacement of Unconfirmed Record"); _log.debug("case 4: Replacement of Unconfirmed Record");
context.getStateHandler().removeClient(client); stateHandler.removeClient(client);
client = context.getStateHandler().createClient( client = stateHandler.createClient(
remoteSocketAddress, localSocketAddress, remoteSocketAddress, localSocketAddress,
_args.opexchange_id.eia_clientowner.co_ownerid, _args.opexchange_id.eia_clientowner.co_ownerid,
_args.opexchange_id.eia_clientowner.co_verifier, _args.opexchange_id.eia_clientowner.co_verifier,
principal); principal);
} }
} }
} }
client.updateLeaseTime(); client.updateLeaseTime();
......
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