Skip to content

Commit

Permalink
nfs4: simplify aceflag4 acemask4 acetype4 classes
Browse files Browse the repository at this point in the history
Motivation:
The values use by aceflag4, acemask4 and acetype4 are wrapped by uint32_t
ints.

Modification:
Simplify aceflag4, acemask4 and acetype4 by dropping extra uint32 wrapper.

Result:
less work for GC.

Acked-by: Paul Millar
Acked-by: Lea Morschel
Target: master
  • Loading branch information
kofemann committed Sep 27, 2021
1 parent fde8701 commit 0d9f5ff
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 50 deletions.
37 changes: 18 additions & 19 deletions core/src/main/java/org/dcache/nfs/v4/acl/Acls.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009 - 2014 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
Expand All @@ -20,7 +20,6 @@
package org.dcache.nfs.v4.acl;

import org.dcache.nfs.v4.xdr.utf8str_mixed;
import org.dcache.nfs.v4.xdr.uint32_t;
import org.dcache.nfs.v4.xdr.nfsace4;
import org.dcache.nfs.v4.xdr.aceflag4;
import org.dcache.nfs.v4.xdr.acetype4;
Expand Down Expand Up @@ -51,9 +50,9 @@ public class Acls {
public final static utf8str_mixed GROUP = new utf8str_mixed("GROUP@");
public final static utf8str_mixed EVERYONE = new utf8str_mixed("EVERYONE@");

private final static aceflag4 NO_FLAGS = new aceflag4(new uint32_t(0));
private final static acetype4 ALLOW = new acetype4(new uint32_t(ACE4_ACCESS_ALLOWED_ACE_TYPE));
private final static acetype4 DENY = new acetype4(new uint32_t(ACE4_ACCESS_DENIED_ACE_TYPE));
private final static aceflag4 NO_FLAGS = new aceflag4(0);
private final static acetype4 ALLOW = new acetype4(ACE4_ACCESS_ALLOWED_ACE_TYPE);
private final static acetype4 DENY = new acetype4(ACE4_ACCESS_DENIED_ACE_TYPE);

private final static int WANT_MODITY = ACE4_WRITE_ACL
| ACE4_WRITE_ATTRIBUTES
Expand Down Expand Up @@ -185,7 +184,7 @@ public static int toAccessMask(int mode, boolean isDir, boolean isOwner) {
private static acemask4 toAceMask(int mode, boolean isDir, boolean isOwner) {

acemask4 acemask = new acemask4();
acemask.value = new uint32_t(toAccessMask(mode, isDir, isOwner));
acemask.value = toAccessMask(mode, isDir, isOwner);

return acemask;
}
Expand Down Expand Up @@ -257,15 +256,15 @@ private static int calculateBits(utf8str_mixed principal, nfsace4[] acl) {
/*
* consider only ALLOWED and DENIED aces
*/
if (ace.type.value.value != ACE4_ACCESS_DENIED_ACE_TYPE
&& ace.type.value.value != ACE4_ACCESS_ALLOWED_ACE_TYPE) {
if (ace.type.value != ACE4_ACCESS_DENIED_ACE_TYPE
&& ace.type.value != ACE4_ACCESS_ALLOWED_ACE_TYPE) {
continue;
}

if( ace.who.equals(EVERYONE) || ace.who.equals(principal)) {
int acemask = ace.access_mask.value.value;
int acemask = ace.access_mask.value;
int rwx = getBitR(acemask) | getBitW(acemask) | getBitX(acemask);
if (ace.type.value.value == ACE4_ACCESS_ALLOWED_ACE_TYPE) {
if (ace.type.value == ACE4_ACCESS_ALLOWED_ACE_TYPE) {
mode |= rwx;
} else {
mode ^= rwx;
Expand Down Expand Up @@ -293,21 +292,21 @@ public static nfsace4[] compact(nfsace4[] acl) {
nfsace4 a = acl[i];
utf8str_mixed pricipal = a.who;

int processedMask = a.access_mask.value.value;
int processedMask = a.access_mask.value;
for(int j = i+1; j < size; j++) {
nfsace4 b = acl[j];
if (a.flag.value.value != b.flag.value.value || !pricipal.equals(b.who)) {
if (a.flag.value != b.flag.value|| !pricipal.equals(b.who)) {
continue;
}

// remove processed bits
b.access_mask.value.value &= ~processedMask;
int maskToProcess = b.access_mask.value.value;
b.access_mask.value &= ~processedMask;
int maskToProcess = b.access_mask.value;

if(maskToProcess != 0) {
if (a.type.value.value == b.type.value.value) {
a.access_mask.value.value |= maskToProcess;
b.access_mask.value.value &= ~maskToProcess;
if (a.type.value == b.type.value) {
a.access_mask.value |= maskToProcess;
b.access_mask.value &= ~maskToProcess;
} else {
//b.access_mask.value.value &= ~maskToProcess;
}
Expand All @@ -317,15 +316,15 @@ public static nfsace4[] compact(nfsace4[] acl) {
}

for (nfsace4 ace : acl) {
if (ace.access_mask.value.value == 0) {
if (ace.access_mask.value == 0) {
size--;
}
}

nfsace4[] compact = new nfsace4[size];
int i = 0;
for (nfsace4 ace : acl) {
if (ace.access_mask.value.value != 0) {
if (ace.access_mask.value != 0) {
compact[i] = ace;
i++;
}
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/org/dcache/nfs/v4/xdr/aceflag4.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009 - 2012 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
Expand All @@ -26,12 +26,12 @@

public class aceflag4 implements XdrAble {

public uint32_t value;
public int value;

public aceflag4() {
}

public aceflag4(uint32_t value) {
public aceflag4(int value) {
this.value = value;
}

Expand All @@ -41,13 +41,13 @@ public aceflag4(XdrDecodingStream xdr)
}

public void xdrEncode(XdrEncodingStream xdr)
throws OncRpcException, IOException {
value.xdrEncode(xdr);
throws OncRpcException, IOException {
xdr.xdrEncodeInt(value);
}

public void xdrDecode(XdrDecodingStream xdr)
throws OncRpcException, IOException {
value = new uint32_t(xdr);
throws OncRpcException, IOException {
value = xdr.xdrDecodeInt();
}

}
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/java/org/dcache/nfs/v4/xdr/acemask4.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

public class acemask4 implements XdrAble {

public uint32_t value;
public int value;

public acemask4() {
}

public acemask4(uint32_t value) {
public acemask4(int value) {
this.value = value;
}

Expand All @@ -42,26 +42,26 @@ public acemask4(XdrDecodingStream xdr)
}

public void xdrEncode(XdrEncodingStream xdr)
throws OncRpcException, IOException {
value.xdrEncode(xdr);
throws OncRpcException, IOException {
xdr.xdrEncodeInt(value);
}

public void xdrDecode(XdrDecodingStream xdr)
throws OncRpcException, IOException {
value = new uint32_t(xdr);
throws OncRpcException, IOException {
value = xdr.xdrDecodeInt();
}

public static acemask4 allOf(acemask4... masks) {
int mask = 0;
for (acemask4 acemask : masks) {
mask |= acemask.value.value;
mask |= acemask.value;
}
return new acemask4(new uint32_t(mask));
return new acemask4(mask);
}

public static acemask4 clear(acemask4 acemask, acemask4 clear) {
int mask = (acemask.value.value | clear.value.value) & ~acemask.value.value;
return new acemask4(new uint32_t(mask));
int mask = (acemask.value | clear.value) & ~acemask.value;
return new acemask4(mask);
}

private static boolean hasBit(int value, int bit) {
Expand Down Expand Up @@ -126,7 +126,7 @@ public static String toString(int mask) {

@Override
public String toString() {
return toString(value.value);
return toString(value);
}
}
// End of acemask4.java
8 changes: 4 additions & 4 deletions core/src/main/java/org/dcache/nfs/v4/xdr/acetype4.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

public class acetype4 implements XdrAble {

public uint32_t value;
public int value;

public acetype4() {
}

public acetype4(uint32_t value) {
public acetype4(int value) {
this.value = value;
}

Expand All @@ -42,12 +42,12 @@ public acetype4(XdrDecodingStream xdr)

public void xdrEncode(XdrEncodingStream xdr)
throws OncRpcException, IOException {
value.xdrEncode(xdr);
xdr.xdrEncodeInt(value);
}

public void xdrDecode(XdrDecodingStream xdr)
throws OncRpcException, IOException {
value = new uint32_t(xdr);
value = xdr.xdrDecodeInt();
}

}
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/org/dcache/nfs/v4/xdr/nfsace4.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void xdrDecode(XdrDecodingStream xdr)
public String toString() {
StringBuilder sb = new StringBuilder();

switch (type.value.value) {
switch (type.value) {
case nfs4_prot.ACE4_ACCESS_ALLOWED_ACE_TYPE:
sb.append('A');
break;
Expand All @@ -77,26 +77,26 @@ public String toString() {

sb.append(':');

if ((flag.value.value & nfs4_prot.ACE4_FILE_INHERIT_ACE) == nfs4_prot.ACE4_FILE_INHERIT_ACE) {
if ((flag.value & nfs4_prot.ACE4_FILE_INHERIT_ACE) == nfs4_prot.ACE4_FILE_INHERIT_ACE) {
sb.append('f');
}

if ((flag.value.value & nfs4_prot.ACE4_DIRECTORY_INHERIT_ACE) == nfs4_prot.ACE4_DIRECTORY_INHERIT_ACE) {
if ((flag.value & nfs4_prot.ACE4_DIRECTORY_INHERIT_ACE) == nfs4_prot.ACE4_DIRECTORY_INHERIT_ACE) {
sb.append('d');
}

if ((flag.value.value & nfs4_prot.ACE4_INHERIT_ONLY_ACE) == nfs4_prot.ACE4_INHERIT_ONLY_ACE) {
if ((flag.value & nfs4_prot.ACE4_INHERIT_ONLY_ACE) == nfs4_prot.ACE4_INHERIT_ONLY_ACE) {
sb.append('i');
}

if ((flag.value.value & nfs4_prot.ACE4_IDENTIFIER_GROUP) == nfs4_prot.ACE4_IDENTIFIER_GROUP) {
if ((flag.value & nfs4_prot.ACE4_IDENTIFIER_GROUP) == nfs4_prot.ACE4_IDENTIFIER_GROUP) {
sb.append('g');
}

sb.append(':');
sb.append(who);
sb.append(':');
sb.append(acemask4.toString(access_mask.value.value));
sb.append(acemask4.toString(access_mask.value));
return sb.toString();
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/org/dcache/nfs/v4/acl/AclsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public void testAllRead() {
private nfsace4 toACE(utf8str_mixed principal, int type, int mask, int flag) {
nfsace4 ace = new nfsace4();
ace.who = principal;
ace.access_mask = new acemask4(new uint32_t(mask));
ace.type = new acetype4(new uint32_t(type));
ace.access_mask = new acemask4(mask);
ace.type = new acetype4(type);
int flags = flag | (principal == Acls.GROUP ? ACE4_IDENTIFIER_GROUP : 0);
ace.flag = new aceflag4(new uint32_t(flags));
ace.flag = new aceflag4(flags);
return ace;
}

Expand Down

0 comments on commit 0d9f5ff

Please sign in to comment.