Commit 59550a9c authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfs4: simplify stateid4 class

Motivation:
stateid4 is a struct that holds a byte array and int. No need
for extra wrapper around int.

Modification:
use plain int to reduce object creation.

Result:
simpler code.

Acked-by: Paul Millar
Acked-by: Svenja Meyer
Target: master
parent 3b8d58d2
......@@ -180,7 +180,7 @@ public class FileTracker {
os.shareAccess = shareAccess;
os.shareDeny = shareDeny;
os.stateid.seqid.value++;
os.stateid.seqid++;
return os.stateid;
} finally {
lock.unlock();
......
/*
* Copyright (c) 2009 - 2017 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -74,7 +74,7 @@ public class NFS4State {
_disposeListeners = new ArrayList<>();
}
public void bumpSeqid() { ++ _stateid.seqid.value; }
public void bumpSeqid() { ++ _stateid.seqid; }
public stateid4 stateid() {
return _stateid;
......
/*
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -271,7 +271,7 @@ public class OperationOPEN extends AbstractNFSv4Operation {
_args.opopen.share_access.value,
_args.opopen.share_deny.value);
stateid.seqid.value++;
stateid.seqid++;
context.currentStateid(stateid);
res.resok4.stateid = stateid;
res.status = nfsstat.NFS_OK;
......
/*
* Copyright (c) 2015 Deutsches Elektronen-Synchroton,
* Copyright (c) 2015 - 2020 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -51,7 +51,7 @@ public class OperationTEST_STATEID extends AbstractNFSv4Operation {
stateid4 statid = _args.optest_stateid.ts_stateids[i];
try {
NFS4State state = client.state(statid);
if (state.stateid().seqid.value < statid.seqid.value) {
if (state.stateid().seqid < statid.seqid) {
res.tsr_resok4.tsr_status_codes[i] = nfsstat.NFSERR_OLD_STATEID;
} else {
res.tsr_resok4.tsr_status_codes[i] = nfsstat.NFS_OK;
......
/*
* Copyright (c) 2009 - 2014 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -64,16 +64,16 @@ public class Stateids {
}
public static void checkStateId(stateid4 expected, stateid4 stateid) throws ChimeraNFSException {
if (stateid.seqid.value == 0) {
if (stateid.seqid == 0) {
// so called 'most up-to-date seqid', see https://tools.ietf.org/html/rfc5661#section-8.2.2
return;
}
if (expected.seqid.value > stateid.seqid.value) {
if (expected.seqid > stateid.seqid) {
throw new OldStateidException();
}
if (expected.seqid.value < stateid.seqid.value) {
if (expected.seqid < stateid.seqid) {
throw new BadStateidException();
}
}
......
/*
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -32,7 +32,7 @@ public class stateid4 implements XdrAble, Serializable {
static final long serialVersionUID = -6677150504723505919L;
public uint32_t seqid;
public int seqid;
public byte [] other;
public stateid4() {
......@@ -40,7 +40,7 @@ public class stateid4 implements XdrAble, Serializable {
public stateid4(byte[] other, int seq) {
this.other = other;
seqid = new uint32_t(seq);
seqid = seq;
}
public stateid4(XdrDecodingStream xdr)
......@@ -50,13 +50,13 @@ public class stateid4 implements XdrAble, Serializable {
public void xdrEncode(XdrEncodingStream xdr)
throws OncRpcException, IOException {
seqid.xdrEncode(xdr);
xdr.xdrEncodeInt(seqid);
xdr.xdrEncodeOpaque(other, 12);
}
public void xdrDecode(XdrDecodingStream xdr)
throws OncRpcException, IOException {
seqid = new uint32_t(xdr);
seqid = xdr.xdrDecodeInt();
other = xdr.xdrDecodeOpaque(12);
}
......@@ -83,7 +83,7 @@ public class stateid4 implements XdrAble, Serializable {
return true;
}
return otherState.seqid.value == this.seqid.value && Arrays.equals(this.other, otherState.other);
return otherState.seqid == this.seqid && Arrays.equals(this.other, otherState.other);
}
@Override
......@@ -97,7 +97,7 @@ public class stateid4 implements XdrAble, Serializable {
sb.append("[");
sb.append(BaseEncoding.base16().lowerCase().encode(other));
sb.append(", seq: ").append(seqid.value).append("]");
sb.append(", seq: ").append(seqid).append("]");
return sb.toString();
}
......
/*
* Copyright (c) 2009 - 2012 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -31,11 +31,11 @@ public class stateid4Test {
public void testEqualsTrue() {
stateid4 stateidA = new stateid4();
stateidA.seqid = new uint32_t(1);
stateidA.seqid = 1;
stateidA.other = "state".getBytes();
stateid4 stateidB = new stateid4();
stateidB.seqid = new uint32_t(1);
stateidB.seqid = 1;
stateidB.other = "state".getBytes();
assertTrue("equal keys not equal", stateidA.equals(stateidB));
......@@ -47,7 +47,7 @@ public class stateid4Test {
public void testEqualsSame() {
stateid4 stateidA = new stateid4();
stateidA.seqid = new uint32_t(1);
stateidA.seqid = 1;
stateidA.other = "state".getBytes();
assertTrue("equal keys not equal", stateidA.equals(stateidA));
......@@ -57,11 +57,11 @@ public class stateid4Test {
public void testDifferSequence() {
stateid4 stateidA = new stateid4();
stateidA.seqid = new uint32_t(1);
stateidA.seqid = 1;
stateidA.other = "state".getBytes();
stateid4 stateidB = new stateid4();
stateidB.seqid = new uint32_t(2);
stateidB.seqid = 2;
stateidB.other = "state".getBytes();
assertTrue("differ by sequence should still be equal", stateidA.equals(stateidB));
......@@ -72,11 +72,11 @@ public class stateid4Test {
public void testDifferOther() {
stateid4 stateidA = new stateid4();
stateidA.seqid = new uint32_t(1);
stateidA.seqid = 1;
stateidA.other = "stateA".getBytes();
stateid4 stateidB = new stateid4();
stateidB.seqid = new uint32_t(1);
stateidB.seqid = 1;
stateidB.other = "stateB".getBytes();
assertFalse("differ by other not detected", stateidA.equals(stateidB));
......
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