Skip to content

Commit 59550a9

Browse files
committed
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
1 parent 3b8d58d commit 59550a9

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

core/src/main/java/org/dcache/nfs/v4/FileTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public stateid4 downgradeOpen(NFS4Client client, stateid4 stateid, Inode inode,
180180
os.shareAccess = shareAccess;
181181
os.shareDeny = shareDeny;
182182

183-
os.stateid.seqid.value++;
183+
os.stateid.seqid++;
184184
return os.stateid;
185185
} finally {
186186
lock.unlock();

core/src/main/java/org/dcache/nfs/v4/NFS4State.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2017 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -74,7 +74,7 @@ public NFS4State(NFS4State openState, StateOwner owner, stateid4 stateid) {
7474
_disposeListeners = new ArrayList<>();
7575
}
7676

77-
public void bumpSeqid() { ++ _stateid.seqid.value; }
77+
public void bumpSeqid() { ++ _stateid.seqid; }
7878

7979
public stateid4 stateid() {
8080
return _stateid;

core/src/main/java/org/dcache/nfs/v4/OperationOPEN.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -271,7 +271,7 @@ public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNF
271271
_args.opopen.share_access.value,
272272
_args.opopen.share_deny.value);
273273

274-
stateid.seqid.value++;
274+
stateid.seqid++;
275275
context.currentStateid(stateid);
276276
res.resok4.stateid = stateid;
277277
res.status = nfsstat.NFS_OK;

core/src/main/java/org/dcache/nfs/v4/OperationTEST_STATEID.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2015 - 2020 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -51,7 +51,7 @@ public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNF
5151
stateid4 statid = _args.optest_stateid.ts_stateids[i];
5252
try {
5353
NFS4State state = client.state(statid);
54-
if (state.stateid().seqid.value < statid.seqid.value) {
54+
if (state.stateid().seqid < statid.seqid) {
5555
res.tsr_resok4.tsr_status_codes[i] = nfsstat.NFSERR_OLD_STATEID;
5656
} else {
5757
res.tsr_resok4.tsr_status_codes[i] = nfsstat.NFS_OK;

core/src/main/java/org/dcache/nfs/v4/Stateids.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2014 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -64,16 +64,16 @@ public static boolean isStateLess(stateid4 stateid) {
6464
}
6565

6666
public static void checkStateId(stateid4 expected, stateid4 stateid) throws ChimeraNFSException {
67-
if (stateid.seqid.value == 0) {
67+
if (stateid.seqid == 0) {
6868
// so called 'most up-to-date seqid', see https://tools.ietf.org/html/rfc5661#section-8.2.2
6969
return;
7070
}
7171

72-
if (expected.seqid.value > stateid.seqid.value) {
72+
if (expected.seqid > stateid.seqid) {
7373
throw new OldStateidException();
7474
}
7575

76-
if (expected.seqid.value < stateid.seqid.value) {
76+
if (expected.seqid < stateid.seqid) {
7777
throw new BadStateidException();
7878
}
7979
}

core/src/main/java/org/dcache/nfs/v4/xdr/stateid4.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -32,15 +32,15 @@ public class stateid4 implements XdrAble, Serializable {
3232

3333
static final long serialVersionUID = -6677150504723505919L;
3434

35-
public uint32_t seqid;
35+
public int seqid;
3636
public byte [] other;
3737

3838
public stateid4() {
3939
}
4040

4141
public stateid4(byte[] other, int seq) {
4242
this.other = other;
43-
seqid = new uint32_t(seq);
43+
seqid = seq;
4444
}
4545

4646
public stateid4(XdrDecodingStream xdr)
@@ -50,13 +50,13 @@ public stateid4(XdrDecodingStream xdr)
5050

5151
public void xdrEncode(XdrEncodingStream xdr)
5252
throws OncRpcException, IOException {
53-
seqid.xdrEncode(xdr);
53+
xdr.xdrEncodeInt(seqid);
5454
xdr.xdrEncodeOpaque(other, 12);
5555
}
5656

5757
public void xdrDecode(XdrDecodingStream xdr)
5858
throws OncRpcException, IOException {
59-
seqid = new uint32_t(xdr);
59+
seqid = xdr.xdrDecodeInt();
6060
other = xdr.xdrDecodeOpaque(12);
6161
}
6262

@@ -83,7 +83,7 @@ public boolean equalsWithSeq(stateid4 otherState) {
8383
return true;
8484
}
8585

86-
return otherState.seqid.value == this.seqid.value && Arrays.equals(this.other, otherState.other);
86+
return otherState.seqid == this.seqid && Arrays.equals(this.other, otherState.other);
8787
}
8888

8989
@Override
@@ -97,7 +97,7 @@ public String toString() {
9797

9898
sb.append("[");
9999
sb.append(BaseEncoding.base16().lowerCase().encode(other));
100-
sb.append(", seq: ").append(seqid.value).append("]");
100+
sb.append(", seq: ").append(seqid).append("]");
101101
return sb.toString();
102102
}
103103

core/src/test/java/org/dcache/nfs/v4/xdr/stateid4Test.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2012 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -31,11 +31,11 @@ public class stateid4Test {
3131
public void testEqualsTrue() {
3232

3333
stateid4 stateidA = new stateid4();
34-
stateidA.seqid = new uint32_t(1);
34+
stateidA.seqid = 1;
3535
stateidA.other = "state".getBytes();
3636

3737
stateid4 stateidB = new stateid4();
38-
stateidB.seqid = new uint32_t(1);
38+
stateidB.seqid = 1;
3939
stateidB.other = "state".getBytes();
4040

4141
assertTrue("equal keys not equal", stateidA.equals(stateidB));
@@ -47,7 +47,7 @@ public void testEqualsTrue() {
4747
public void testEqualsSame() {
4848

4949
stateid4 stateidA = new stateid4();
50-
stateidA.seqid = new uint32_t(1);
50+
stateidA.seqid = 1;
5151
stateidA.other = "state".getBytes();
5252

5353
assertTrue("equal keys not equal", stateidA.equals(stateidA));
@@ -57,11 +57,11 @@ public void testEqualsSame() {
5757
public void testDifferSequence() {
5858

5959
stateid4 stateidA = new stateid4();
60-
stateidA.seqid = new uint32_t(1);
60+
stateidA.seqid = 1;
6161
stateidA.other = "state".getBytes();
6262

6363
stateid4 stateidB = new stateid4();
64-
stateidB.seqid = new uint32_t(2);
64+
stateidB.seqid = 2;
6565
stateidB.other = "state".getBytes();
6666

6767
assertTrue("differ by sequence should still be equal", stateidA.equals(stateidB));
@@ -72,11 +72,11 @@ public void testDifferSequence() {
7272
public void testDifferOther() {
7373

7474
stateid4 stateidA = new stateid4();
75-
stateidA.seqid = new uint32_t(1);
75+
stateidA.seqid = 1;
7676
stateidA.other = "stateA".getBytes();
7777

7878
stateid4 stateidB = new stateid4();
79-
stateidB.seqid = new uint32_t(1);
79+
stateidB.seqid = 1;
8080
stateidB.other = "stateB".getBytes();
8181

8282
assertFalse("differ by other not detected", stateidA.equals(stateidB));

0 commit comments

Comments
 (0)