Commit 0d9f5ff4 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfs4: simplify aceflag4 acemask4 acetype4 classes

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
parent fde87013
Pipeline #10816 passed with stage
in 1 minute and 27 seconds
/* /*
* Copyright (c) 2009 - 2014 Deutsches Elektronen-Synchroton, * Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
* *
* This library is free software; you can redistribute it and/or modify * This library is free software; you can redistribute it and/or modify
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
package org.dcache.nfs.v4.acl; package org.dcache.nfs.v4.acl;
import org.dcache.nfs.v4.xdr.utf8str_mixed; 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.nfsace4;
import org.dcache.nfs.v4.xdr.aceflag4; import org.dcache.nfs.v4.xdr.aceflag4;
import org.dcache.nfs.v4.xdr.acetype4; import org.dcache.nfs.v4.xdr.acetype4;
...@@ -51,9 +50,9 @@ public class Acls { ...@@ -51,9 +50,9 @@ public class Acls {
public final static utf8str_mixed GROUP = new utf8str_mixed("GROUP@"); public final static utf8str_mixed GROUP = new utf8str_mixed("GROUP@");
public final static utf8str_mixed EVERYONE = new utf8str_mixed("EVERYONE@"); 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 aceflag4 NO_FLAGS = new aceflag4(0);
private final static acetype4 ALLOW = new acetype4(new uint32_t(ACE4_ACCESS_ALLOWED_ACE_TYPE)); private final static acetype4 ALLOW = new acetype4(ACE4_ACCESS_ALLOWED_ACE_TYPE);
private final static acetype4 DENY = new acetype4(new uint32_t(ACE4_ACCESS_DENIED_ACE_TYPE)); private final static acetype4 DENY = new acetype4(ACE4_ACCESS_DENIED_ACE_TYPE);
private final static int WANT_MODITY = ACE4_WRITE_ACL private final static int WANT_MODITY = ACE4_WRITE_ACL
| ACE4_WRITE_ATTRIBUTES | ACE4_WRITE_ATTRIBUTES
...@@ -185,7 +184,7 @@ public class Acls { ...@@ -185,7 +184,7 @@ public class Acls {
private static acemask4 toAceMask(int mode, boolean isDir, boolean isOwner) { private static acemask4 toAceMask(int mode, boolean isDir, boolean isOwner) {
acemask4 acemask = new acemask4(); acemask4 acemask = new acemask4();
acemask.value = new uint32_t(toAccessMask(mode, isDir, isOwner)); acemask.value = toAccessMask(mode, isDir, isOwner);
return acemask; return acemask;
} }
...@@ -257,15 +256,15 @@ public class Acls { ...@@ -257,15 +256,15 @@ public class Acls {
/* /*
* consider only ALLOWED and DENIED aces * consider only ALLOWED and DENIED aces
*/ */
if (ace.type.value.value != ACE4_ACCESS_DENIED_ACE_TYPE if (ace.type.value != ACE4_ACCESS_DENIED_ACE_TYPE
&& ace.type.value.value != ACE4_ACCESS_ALLOWED_ACE_TYPE) { && ace.type.value != ACE4_ACCESS_ALLOWED_ACE_TYPE) {
continue; continue;
} }
if( ace.who.equals(EVERYONE) || ace.who.equals(principal)) { 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); 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; mode |= rwx;
} else { } else {
mode ^= rwx; mode ^= rwx;
...@@ -293,21 +292,21 @@ public class Acls { ...@@ -293,21 +292,21 @@ public class Acls {
nfsace4 a = acl[i]; nfsace4 a = acl[i];
utf8str_mixed pricipal = a.who; 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++) { for(int j = i+1; j < size; j++) {
nfsace4 b = acl[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; continue;
} }
// remove processed bits // remove processed bits
b.access_mask.value.value &= ~processedMask; b.access_mask.value &= ~processedMask;
int maskToProcess = b.access_mask.value.value; int maskToProcess = b.access_mask.value;
if(maskToProcess != 0) { if(maskToProcess != 0) {
if (a.type.value.value == b.type.value.value) { if (a.type.value == b.type.value) {
a.access_mask.value.value |= maskToProcess; a.access_mask.value |= maskToProcess;
b.access_mask.value.value &= ~maskToProcess; b.access_mask.value &= ~maskToProcess;
} else { } else {
//b.access_mask.value.value &= ~maskToProcess; //b.access_mask.value.value &= ~maskToProcess;
} }
...@@ -317,7 +316,7 @@ public class Acls { ...@@ -317,7 +316,7 @@ public class Acls {
} }
for (nfsace4 ace : acl) { for (nfsace4 ace : acl) {
if (ace.access_mask.value.value == 0) { if (ace.access_mask.value == 0) {
size--; size--;
} }
} }
...@@ -325,7 +324,7 @@ public class Acls { ...@@ -325,7 +324,7 @@ public class Acls {
nfsace4[] compact = new nfsace4[size]; nfsace4[] compact = new nfsace4[size];
int i = 0; int i = 0;
for (nfsace4 ace : acl) { for (nfsace4 ace : acl) {
if (ace.access_mask.value.value != 0) { if (ace.access_mask.value != 0) {
compact[i] = ace; compact[i] = ace;
i++; i++;
} }
......
/* /*
* Copyright (c) 2009 - 2012 Deutsches Elektronen-Synchroton, * Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
* *
* This library is free software; you can redistribute it and/or modify * This library is free software; you can redistribute it and/or modify
...@@ -26,12 +26,12 @@ import java.io.IOException; ...@@ -26,12 +26,12 @@ import java.io.IOException;
public class aceflag4 implements XdrAble { public class aceflag4 implements XdrAble {
public uint32_t value; public int value;
public aceflag4() { public aceflag4() {
} }
public aceflag4(uint32_t value) { public aceflag4(int value) {
this.value = value; this.value = value;
} }
...@@ -41,13 +41,13 @@ public class aceflag4 implements XdrAble { ...@@ -41,13 +41,13 @@ public class aceflag4 implements XdrAble {
} }
public void xdrEncode(XdrEncodingStream xdr) public void xdrEncode(XdrEncodingStream xdr)
throws OncRpcException, IOException { throws OncRpcException, IOException {
value.xdrEncode(xdr); xdr.xdrEncodeInt(value);
} }
public void xdrDecode(XdrDecodingStream xdr) public void xdrDecode(XdrDecodingStream xdr)
throws OncRpcException, IOException { throws OncRpcException, IOException {
value = new uint32_t(xdr); value = xdr.xdrDecodeInt();
} }
} }
......
...@@ -27,12 +27,12 @@ import java.io.IOException; ...@@ -27,12 +27,12 @@ import java.io.IOException;
public class acemask4 implements XdrAble { public class acemask4 implements XdrAble {
public uint32_t value; public int value;
public acemask4() { public acemask4() {
} }
public acemask4(uint32_t value) { public acemask4(int value) {
this.value = value; this.value = value;
} }
...@@ -42,26 +42,26 @@ public class acemask4 implements XdrAble { ...@@ -42,26 +42,26 @@ public class acemask4 implements XdrAble {
} }
public void xdrEncode(XdrEncodingStream xdr) public void xdrEncode(XdrEncodingStream xdr)
throws OncRpcException, IOException { throws OncRpcException, IOException {
value.xdrEncode(xdr); xdr.xdrEncodeInt(value);
} }
public void xdrDecode(XdrDecodingStream xdr) public void xdrDecode(XdrDecodingStream xdr)
throws OncRpcException, IOException { throws OncRpcException, IOException {
value = new uint32_t(xdr); value = xdr.xdrDecodeInt();
} }
public static acemask4 allOf(acemask4... masks) { public static acemask4 allOf(acemask4... masks) {
int mask = 0; int mask = 0;
for (acemask4 acemask : masks) { 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) { public static acemask4 clear(acemask4 acemask, acemask4 clear) {
int mask = (acemask.value.value | clear.value.value) & ~acemask.value.value; int mask = (acemask.value | clear.value) & ~acemask.value;
return new acemask4(new uint32_t(mask)); return new acemask4(mask);
} }
private static boolean hasBit(int value, int bit) { private static boolean hasBit(int value, int bit) {
...@@ -126,7 +126,7 @@ public class acemask4 implements XdrAble { ...@@ -126,7 +126,7 @@ public class acemask4 implements XdrAble {
@Override @Override
public String toString() { public String toString() {
return toString(value.value); return toString(value);
} }
} }
// End of acemask4.java // End of acemask4.java
...@@ -26,12 +26,12 @@ import java.io.IOException; ...@@ -26,12 +26,12 @@ import java.io.IOException;
public class acetype4 implements XdrAble { public class acetype4 implements XdrAble {
public uint32_t value; public int value;
public acetype4() { public acetype4() {
} }
public acetype4(uint32_t value) { public acetype4(int value) {
this.value = value; this.value = value;
} }
...@@ -42,12 +42,12 @@ public class acetype4 implements XdrAble { ...@@ -42,12 +42,12 @@ public class acetype4 implements XdrAble {
public void xdrEncode(XdrEncodingStream xdr) public void xdrEncode(XdrEncodingStream xdr)
throws OncRpcException, IOException { throws OncRpcException, IOException {
value.xdrEncode(xdr); xdr.xdrEncodeInt(value);
} }
public void xdrDecode(XdrDecodingStream xdr) public void xdrDecode(XdrDecodingStream xdr)
throws OncRpcException, IOException { throws OncRpcException, IOException {
value = new uint32_t(xdr); value = xdr.xdrDecodeInt();
} }
} }
......
...@@ -58,7 +58,7 @@ public class nfsace4 implements XdrAble { ...@@ -58,7 +58,7 @@ public class nfsace4 implements XdrAble {
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
switch (type.value.value) { switch (type.value) {
case nfs4_prot.ACE4_ACCESS_ALLOWED_ACE_TYPE: case nfs4_prot.ACE4_ACCESS_ALLOWED_ACE_TYPE:
sb.append('A'); sb.append('A');
break; break;
...@@ -77,26 +77,26 @@ public class nfsace4 implements XdrAble { ...@@ -77,26 +77,26 @@ public class nfsace4 implements XdrAble {
sb.append(':'); 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'); 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'); 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'); 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('g');
} }
sb.append(':'); sb.append(':');
sb.append(who); sb.append(who);
sb.append(':'); sb.append(':');
sb.append(acemask4.toString(access_mask.value.value)); sb.append(acemask4.toString(access_mask.value));
return sb.toString(); return sb.toString();
} }
} }
......
...@@ -87,10 +87,10 @@ public class AclsTest { ...@@ -87,10 +87,10 @@ public class AclsTest {
private nfsace4 toACE(utf8str_mixed principal, int type, int mask, int flag) { private nfsace4 toACE(utf8str_mixed principal, int type, int mask, int flag) {
nfsace4 ace = new nfsace4(); nfsace4 ace = new nfsace4();
ace.who = principal; ace.who = principal;
ace.access_mask = new acemask4(new uint32_t(mask)); ace.access_mask = new acemask4(mask);
ace.type = new acetype4(new uint32_t(type)); ace.type = new acetype4(type);
int flags = flag | (principal == Acls.GROUP ? ACE4_IDENTIFIER_GROUP : 0); 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; return ace;
} }
......
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