HDFS-6451. Merging change r1615702 from trunk
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1615708 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e5c5417f10
commit
225febccc1
|
@ -222,6 +222,17 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
writeManager.startAsyncDataSerivce();
|
||||
}
|
||||
|
||||
// Checks the type of IOException and maps it to appropriate Nfs3Status code.
|
||||
private int mapErrorStatus(IOException e) {
|
||||
if (e instanceof FileNotFoundException) {
|
||||
return Nfs3Status.NFS3ERR_STALE;
|
||||
} else if (e instanceof AccessControlException) {
|
||||
return Nfs3Status.NFS3ERR_ACCES;
|
||||
} else {
|
||||
return Nfs3Status.NFS3ERR_IO;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* RPC call handlers
|
||||
******************************************************/
|
||||
|
@ -236,14 +247,19 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
@Override
|
||||
public GETATTR3Response getattr(XDR xdr, RpcInfo info) {
|
||||
return getattr(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
GETATTR3Response getattr(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
GETATTR3Response response = new GETATTR3Response(Nfs3Status.NFS3_OK);
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_ONLY)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_ONLY)) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_ACCES);
|
||||
return response;
|
||||
}
|
||||
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -280,7 +296,8 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
LOG.info("Can't get file attribute, fileId=" + handle.getFileId(), e);
|
||||
response.setStatus(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
response.setStatus(status);
|
||||
return response;
|
||||
}
|
||||
if (attrs == null) {
|
||||
|
@ -328,8 +345,13 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
@Override
|
||||
public SETATTR3Response setattr(XDR xdr, RpcInfo info) {
|
||||
return setattr(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
SETATTR3Response setattr(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
SETATTR3Response response = new SETATTR3Response(Nfs3Status.NFS3_OK);
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -375,7 +397,7 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
}
|
||||
|
||||
// check the write access privilege
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_WRITE)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
|
||||
return new SETATTR3Response(Nfs3Status.NFS3ERR_ACCES, new WccData(
|
||||
preOpWcc, preOpAttr));
|
||||
}
|
||||
|
@ -394,24 +416,27 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
} catch (IOException e1) {
|
||||
LOG.info("Can't get postOpAttr for fileIdPath: " + fileIdPath, e1);
|
||||
}
|
||||
if (e instanceof AccessControlException) {
|
||||
return new SETATTR3Response(Nfs3Status.NFS3ERR_ACCES, wccData);
|
||||
} else {
|
||||
return new SETATTR3Response(Nfs3Status.NFS3ERR_IO, wccData);
|
||||
}
|
||||
|
||||
int status = mapErrorStatus(e);
|
||||
return new SETATTR3Response(status, wccData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LOOKUP3Response lookup(XDR xdr, RpcInfo info) {
|
||||
return lookup(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
LOOKUP3Response lookup(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
LOOKUP3Response response = new LOOKUP3Response(Nfs3Status.NFS3_OK);
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_ONLY)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_ONLY)) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_ACCES);
|
||||
return response;
|
||||
}
|
||||
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -460,20 +485,26 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Exception ", e);
|
||||
return new LOOKUP3Response(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
return new LOOKUP3Response(status);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ACCESS3Response access(XDR xdr, RpcInfo info) {
|
||||
return access(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ACCESS3Response access(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
ACCESS3Response response = new ACCESS3Response(Nfs3Status.NFS3_OK);
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_ONLY)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_ONLY)) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_ACCES);
|
||||
return response;
|
||||
}
|
||||
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -521,20 +552,26 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Exception ", e);
|
||||
return new ACCESS3Response(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
return new ACCESS3Response(status);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public READLINK3Response readlink(XDR xdr, RpcInfo info) {
|
||||
return readlink(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
READLINK3Response readlink(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
READLINK3Response response = new READLINK3Response(Nfs3Status.NFS3_OK);
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_ONLY)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_ONLY)) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_ACCES);
|
||||
return response;
|
||||
}
|
||||
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -588,20 +625,14 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Readlink error: " + e.getClass(), e);
|
||||
if (e instanceof FileNotFoundException) {
|
||||
return new READLINK3Response(Nfs3Status.NFS3ERR_STALE);
|
||||
} else if (e instanceof AccessControlException) {
|
||||
return new READLINK3Response(Nfs3Status.NFS3ERR_ACCES);
|
||||
}
|
||||
return new READLINK3Response(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
return new READLINK3Response(status);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public READ3Response read(XDR xdr, RpcInfo info) {
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
SocketAddress remoteAddress = info.remoteAddress();
|
||||
return read(xdr, securityHandler, remoteAddress);
|
||||
return read(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -725,7 +756,8 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
} catch (IOException e) {
|
||||
LOG.warn("Read error: " + e.getClass() + " offset: " + offset
|
||||
+ " count: " + count, e);
|
||||
return new READ3Response(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
return new READ3Response(status);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -807,8 +839,10 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
}
|
||||
WccAttr attr = preOpAttr == null ? null : Nfs3Utils.getWccAttr(preOpAttr);
|
||||
WccData fileWcc = new WccData(attr, postOpAttr);
|
||||
return new WRITE3Response(Nfs3Status.NFS3ERR_IO, fileWcc, 0,
|
||||
request.getStableHow(), Nfs3Constant.WRITE_COMMIT_VERF);
|
||||
|
||||
int status = mapErrorStatus(e);
|
||||
return new WRITE3Response(status, fileWcc, 0, request.getStableHow(),
|
||||
Nfs3Constant.WRITE_COMMIT_VERF);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -816,9 +850,7 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
@Override
|
||||
public CREATE3Response create(XDR xdr, RpcInfo info) {
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
SocketAddress remoteAddress = info.remoteAddress();
|
||||
return create(xdr, securityHandler, remoteAddress);
|
||||
return create(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -940,13 +972,9 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
+ dirHandle.getFileId(), e1);
|
||||
}
|
||||
}
|
||||
if (e instanceof AccessControlException) {
|
||||
return new CREATE3Response(Nfs3Status.NFS3ERR_ACCES, fileHandle,
|
||||
postOpObjAttr, dirWcc);
|
||||
} else {
|
||||
return new CREATE3Response(Nfs3Status.NFS3ERR_IO, fileHandle,
|
||||
postOpObjAttr, dirWcc);
|
||||
}
|
||||
|
||||
int status = mapErrorStatus(e);
|
||||
return new CREATE3Response(status, fileHandle, postOpObjAttr, dirWcc);
|
||||
}
|
||||
|
||||
return new CREATE3Response(Nfs3Status.NFS3_OK, fileHandle, postOpObjAttr,
|
||||
|
@ -955,8 +983,13 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
@Override
|
||||
public MKDIR3Response mkdir(XDR xdr, RpcInfo info) {
|
||||
return mkdir(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
MKDIR3Response mkdir(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
MKDIR3Response response = new MKDIR3Response(Nfs3Status.NFS3_OK);
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -992,7 +1025,7 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
return new MKDIR3Response(Nfs3Status.NFS3ERR_STALE);
|
||||
}
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_WRITE)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
|
||||
return new MKDIR3Response(Nfs3Status.NFS3ERR_ACCES, null, preOpDirAttr,
|
||||
new WccData(Nfs3Utils.getWccAttr(preOpDirAttr), preOpDirAttr));
|
||||
}
|
||||
|
@ -1032,15 +1065,11 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
LOG.info("Can't get postOpDirAttr for " + dirFileIdPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
WccData dirWcc = new WccData(Nfs3Utils.getWccAttr(preOpDirAttr),
|
||||
postOpDirAttr);
|
||||
if (e instanceof AccessControlException) {
|
||||
return new MKDIR3Response(Nfs3Status.NFS3ERR_PERM, objFileHandle,
|
||||
postOpObjAttr, dirWcc);
|
||||
} else {
|
||||
return new MKDIR3Response(Nfs3Status.NFS3ERR_IO, objFileHandle,
|
||||
postOpObjAttr, dirWcc);
|
||||
}
|
||||
int status = mapErrorStatus(e);
|
||||
return new MKDIR3Response(status, objFileHandle, postOpObjAttr, dirWcc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1055,7 +1084,8 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
REMOVE3Response remove(XDR xdr, SecurityHandler securityHandler, SocketAddress remoteAddress) {
|
||||
REMOVE3Response remove(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
REMOVE3Response response = new REMOVE3Response(Nfs3Status.NFS3_OK);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
|
@ -1120,20 +1150,23 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
LOG.info("Can't get postOpDirAttr for " + dirFileIdPath, e1);
|
||||
}
|
||||
}
|
||||
|
||||
WccData dirWcc = new WccData(Nfs3Utils.getWccAttr(preOpDirAttr),
|
||||
postOpDirAttr);
|
||||
if (e instanceof AccessControlException) {
|
||||
return new REMOVE3Response(Nfs3Status.NFS3ERR_PERM, dirWcc);
|
||||
} else {
|
||||
return new REMOVE3Response(Nfs3Status.NFS3ERR_IO, dirWcc);
|
||||
}
|
||||
int status = mapErrorStatus(e);
|
||||
return new REMOVE3Response(status, dirWcc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RMDIR3Response rmdir(XDR xdr, RpcInfo info) {
|
||||
return rmdir(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
RMDIR3Response rmdir(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
RMDIR3Response response = new RMDIR3Response(Nfs3Status.NFS3_OK);
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -1167,7 +1200,7 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
WccData errWcc = new WccData(Nfs3Utils.getWccAttr(preOpDirAttr),
|
||||
preOpDirAttr);
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_WRITE)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
|
||||
return new RMDIR3Response(Nfs3Status.NFS3ERR_ACCES, errWcc);
|
||||
}
|
||||
|
||||
|
@ -1202,20 +1235,23 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
LOG.info("Can't get postOpDirAttr for " + dirFileIdPath, e1);
|
||||
}
|
||||
}
|
||||
|
||||
WccData dirWcc = new WccData(Nfs3Utils.getWccAttr(preOpDirAttr),
|
||||
postOpDirAttr);
|
||||
if (e instanceof AccessControlException) {
|
||||
return new RMDIR3Response(Nfs3Status.NFS3ERR_PERM, dirWcc);
|
||||
} else {
|
||||
return new RMDIR3Response(Nfs3Status.NFS3ERR_IO, dirWcc);
|
||||
}
|
||||
int status = mapErrorStatus(e);
|
||||
return new RMDIR3Response(status, dirWcc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RENAME3Response rename(XDR xdr, RpcInfo info) {
|
||||
return rename(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
RENAME3Response rename(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
RENAME3Response response = new RENAME3Response(Nfs3Status.NFS3_OK);
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -1259,7 +1295,7 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
return new RENAME3Response(Nfs3Status.NFS3ERR_STALE);
|
||||
}
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_WRITE)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
|
||||
WccData fromWcc = new WccData(Nfs3Utils.getWccAttr(fromPreOpAttr),
|
||||
fromPreOpAttr);
|
||||
WccData toWcc = new WccData(Nfs3Utils.getWccAttr(toPreOpAttr),
|
||||
|
@ -1291,25 +1327,27 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
LOG.info("Can't get postOpDirAttr for " + fromDirFileIdPath + " or"
|
||||
+ toDirFileIdPath, e1);
|
||||
}
|
||||
if (e instanceof AccessControlException) {
|
||||
return new RENAME3Response(Nfs3Status.NFS3ERR_PERM, fromDirWcc,
|
||||
toDirWcc);
|
||||
} else {
|
||||
return new RENAME3Response(Nfs3Status.NFS3ERR_IO, fromDirWcc, toDirWcc);
|
||||
}
|
||||
|
||||
int status = mapErrorStatus(e);
|
||||
return new RENAME3Response(status, fromDirWcc, toDirWcc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SYMLINK3Response symlink(XDR xdr, RpcInfo info) {
|
||||
return symlink(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
SYMLINK3Response symlink(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
SYMLINK3Response response = new SYMLINK3Response(Nfs3Status.NFS3_OK);
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_WRITE)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_ACCES);
|
||||
return response;
|
||||
}
|
||||
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -1355,7 +1393,8 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Exception:" + e);
|
||||
response.setStatus(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
response.setStatus(status);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
@ -1390,10 +1429,9 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
@Override
|
||||
public READDIR3Response readdir(XDR xdr, RpcInfo info) {
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
SocketAddress remoteAddress = info.remoteAddress();
|
||||
return readdir(xdr, securityHandler, remoteAddress);
|
||||
return readdir(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
public READDIR3Response readdir(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
READDIR3Response response = new READDIR3Response(Nfs3Status.NFS3_OK);
|
||||
|
@ -1501,7 +1539,8 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Exception ", e);
|
||||
return new READDIR3Response(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
return new READDIR3Response(status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1551,9 +1590,7 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
@Override
|
||||
public READDIRPLUS3Response readdirplus(XDR xdr, RpcInfo info) {
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
SocketAddress remoteAddress = info.remoteAddress();
|
||||
return readdirplus(xdr, securityHandler, remoteAddress);
|
||||
return readdirplus(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -1664,7 +1701,8 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Exception ", e);
|
||||
return new READDIRPLUS3Response(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
return new READDIRPLUS3Response(status);
|
||||
}
|
||||
|
||||
// Set up the dirents in the response
|
||||
|
@ -1723,14 +1761,19 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
|
||||
@Override
|
||||
public FSSTAT3Response fsstat(XDR xdr, RpcInfo info) {
|
||||
return fsstat(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
FSSTAT3Response fsstat(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
FSSTAT3Response response = new FSSTAT3Response(Nfs3Status.NFS3_OK);
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_ONLY)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_ONLY)) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_ACCES);
|
||||
return response;
|
||||
}
|
||||
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -1785,20 +1828,26 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Exception ", e);
|
||||
return new FSSTAT3Response(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
return new FSSTAT3Response(status);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FSINFO3Response fsinfo(XDR xdr, RpcInfo info) {
|
||||
return fsinfo(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
FSINFO3Response fsinfo(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
FSINFO3Response response = new FSINFO3Response(Nfs3Status.NFS3_OK);
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_ONLY)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_ONLY)) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_ACCES);
|
||||
return response;
|
||||
}
|
||||
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -1843,20 +1892,26 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
wtmax, wtmax, 1, dtperf, Long.MAX_VALUE, new NfsTime(1), fsProperty);
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Exception ", e);
|
||||
return new FSINFO3Response(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
return new FSINFO3Response(status);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PATHCONF3Response pathconf(XDR xdr, RpcInfo info) {
|
||||
return pathconf(xdr, getSecurityHandler(info), info.remoteAddress());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
PATHCONF3Response pathconf(XDR xdr, SecurityHandler securityHandler,
|
||||
SocketAddress remoteAddress) {
|
||||
PATHCONF3Response response = new PATHCONF3Response(Nfs3Status.NFS3_OK);
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_ONLY)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_ONLY)) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_ACCES);
|
||||
return response;
|
||||
}
|
||||
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -1890,16 +1945,24 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
HdfsConstants.MAX_PATH_LENGTH, true, false, false, true);
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Exception ", e);
|
||||
return new PATHCONF3Response(Nfs3Status.NFS3ERR_IO);
|
||||
int status = mapErrorStatus(e);
|
||||
return new PATHCONF3Response(status);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMMIT3Response commit(XDR xdr, RpcInfo info) {
|
||||
//Channel channel, int xid,
|
||||
// SecurityHandler securityHandler, InetAddress client) {
|
||||
COMMIT3Response response = new COMMIT3Response(Nfs3Status.NFS3_OK);
|
||||
SecurityHandler securityHandler = getSecurityHandler(info);
|
||||
RpcCall rpcCall = (RpcCall) info.header();
|
||||
int xid = rpcCall.getXid();
|
||||
SocketAddress remoteAddress = info.remoteAddress();
|
||||
return commit(xdr, info.channel(), xid, securityHandler, remoteAddress);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
COMMIT3Response commit(XDR xdr, Channel channel, int xid,
|
||||
SecurityHandler securityHandler, SocketAddress remoteAddress) {
|
||||
COMMIT3Response response = new COMMIT3Response(Nfs3Status.NFS3_OK);
|
||||
DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
|
||||
if (dfsClient == null) {
|
||||
response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
|
||||
|
@ -1930,7 +1993,7 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
return new COMMIT3Response(Nfs3Status.NFS3ERR_STALE);
|
||||
}
|
||||
|
||||
if (!checkAccessPrivilege(info, AccessPrivilege.READ_WRITE)) {
|
||||
if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
|
||||
return new COMMIT3Response(Nfs3Status.NFS3ERR_ACCES, new WccData(
|
||||
Nfs3Utils.getWccAttr(preOpAttr), preOpAttr),
|
||||
Nfs3Constant.WRITE_COMMIT_VERF);
|
||||
|
@ -1940,10 +2003,8 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
: (request.getOffset() + request.getCount());
|
||||
|
||||
// Insert commit as an async request
|
||||
RpcCall rpcCall = (RpcCall) info.header();
|
||||
int xid = rpcCall.getXid();
|
||||
writeManager.handleCommit(dfsClient, handle, commitOffset,
|
||||
info.channel(), xid, preOpAttr);
|
||||
channel, xid, preOpAttr);
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Exception ", e);
|
||||
|
@ -1953,8 +2014,10 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
} catch (IOException e1) {
|
||||
LOG.info("Can't get postOpAttr for fileId: " + handle.getFileId(), e1);
|
||||
}
|
||||
|
||||
WccData fileWcc = new WccData(Nfs3Utils.getWccAttr(preOpAttr), postOpAttr);
|
||||
return new COMMIT3Response(Nfs3Status.NFS3ERR_IO, fileWcc,
|
||||
int status = mapErrorStatus(e);
|
||||
return new COMMIT3Response(status, fileWcc,
|
||||
Nfs3Constant.WRITE_COMMIT_VERF);
|
||||
}
|
||||
}
|
||||
|
@ -2111,12 +2174,6 @@ public class RpcProgramNfs3 extends RpcProgram implements Nfs3Interface {
|
|||
return nfsproc3 == null || nfsproc3.isIdempotent();
|
||||
}
|
||||
|
||||
private boolean checkAccessPrivilege(RpcInfo info,
|
||||
final AccessPrivilege expected) {
|
||||
SocketAddress remoteAddress = info.remoteAddress();
|
||||
return checkAccessPrivilege(remoteAddress, expected);
|
||||
}
|
||||
|
||||
private boolean checkAccessPrivilege(SocketAddress remoteAddress,
|
||||
final AccessPrivilege expected) {
|
||||
// Port monitoring
|
||||
|
|
|
@ -18,19 +18,603 @@
|
|||
package org.apache.hadoop.hdfs.nfs.nfs3;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
||||
import org.apache.hadoop.hdfs.nfs.conf.NfsConfigKeys;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.hdfs.DFSTestUtil;
|
||||
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
||||
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
||||
import org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration;
|
||||
import org.apache.hadoop.hdfs.nfs.conf.NfsConfigKeys;
|
||||
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
||||
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
||||
import org.apache.hadoop.nfs.nfs3.FileHandle;
|
||||
import org.apache.hadoop.nfs.nfs3.Nfs3Constant;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.apache.hadoop.nfs.nfs3.Nfs3Constant.WriteStableHow;
|
||||
import org.apache.hadoop.nfs.nfs3.Nfs3Status;
|
||||
import org.apache.hadoop.nfs.nfs3.request.LOOKUP3Request;
|
||||
import org.apache.hadoop.nfs.nfs3.request.READ3Request;
|
||||
import org.apache.hadoop.nfs.nfs3.request.WRITE3Request;
|
||||
import org.apache.hadoop.nfs.nfs3.response.ACCESS3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.COMMIT3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.CREATE3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.FSSTAT3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.FSINFO3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.GETATTR3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.LOOKUP3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.PATHCONF3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.READ3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.REMOVE3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.RMDIR3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.RENAME3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.READDIR3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.READDIRPLUS3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.READLINK3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.SETATTR3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.SYMLINK3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.response.WRITE3Response;
|
||||
import org.apache.hadoop.nfs.nfs3.request.SetAttr3;
|
||||
import org.apache.hadoop.oncrpc.XDR;
|
||||
import org.apache.hadoop.oncrpc.security.SecurityHandler;
|
||||
import org.apache.hadoop.security.authorize.DefaultImpersonationProvider;
|
||||
import org.apache.hadoop.security.authorize.ProxyUsers;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link RpcProgramNfs3}
|
||||
*/
|
||||
public class TestRpcProgramNfs3 {
|
||||
static DistributedFileSystem hdfs;
|
||||
static MiniDFSCluster cluster = null;
|
||||
static NfsConfiguration config = new NfsConfiguration();
|
||||
static NameNode nn;
|
||||
static Nfs3 nfs;
|
||||
static RpcProgramNfs3 nfsd;
|
||||
static SecurityHandler securityHandler;
|
||||
static SecurityHandler securityHandlerUnpriviledged;
|
||||
static String testdir = "/tmp";
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
String currentUser = System.getProperty("user.name");
|
||||
|
||||
config.set("fs.permissions.umask-mode", "u=rwx,g=,o=");
|
||||
config.set(DefaultImpersonationProvider.getTestProvider()
|
||||
.getProxySuperuserGroupConfKey(currentUser), "*");
|
||||
config.set(DefaultImpersonationProvider.getTestProvider()
|
||||
.getProxySuperuserIpConfKey(currentUser), "*");
|
||||
ProxyUsers.refreshSuperUserGroupsConfiguration(config);
|
||||
|
||||
cluster = new MiniDFSCluster.Builder(config).numDataNodes(1).build();
|
||||
cluster.waitActive();
|
||||
hdfs = cluster.getFileSystem();
|
||||
nn = cluster.getNameNode();
|
||||
|
||||
// Use ephemeral ports in case tests are running in parallel
|
||||
config.setInt("nfs3.mountd.port", 0);
|
||||
config.setInt("nfs3.server.port", 0);
|
||||
|
||||
// Start NFS with allowed.hosts set to "* rw"
|
||||
config.set("dfs.nfs.exports.allowed.hosts", "* rw");
|
||||
nfs = new Nfs3(config);
|
||||
nfs.startServiceInternal(false);
|
||||
nfsd = (RpcProgramNfs3) nfs.getRpcProgram();
|
||||
|
||||
|
||||
// Mock SecurityHandler which returns system user.name
|
||||
securityHandler = Mockito.mock(SecurityHandler.class);
|
||||
Mockito.when(securityHandler.getUser()).thenReturn(currentUser);
|
||||
|
||||
// Mock SecurityHandler which returns a dummy username "harry"
|
||||
securityHandlerUnpriviledged = Mockito.mock(SecurityHandler.class);
|
||||
Mockito.when(securityHandlerUnpriviledged.getUser()).thenReturn("harry");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdown() throws Exception {
|
||||
if (cluster != null) {
|
||||
cluster.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void createFiles() throws IllegalArgumentException, IOException {
|
||||
hdfs.delete(new Path(testdir), true);
|
||||
hdfs.mkdirs(new Path(testdir));
|
||||
hdfs.mkdirs(new Path(testdir + "/foo"));
|
||||
DFSTestUtil.createFile(hdfs, new Path(testdir + "/bar"), 0, (short) 1, 0);
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testGetattr() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
XDR xdr_req = new XDR();
|
||||
handle.serialize(xdr_req);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
GETATTR3Response response1 = nfsd.getattr(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
GETATTR3Response response2 = nfsd.getattr(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testSetattr() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
XDR xdr_req = new XDR();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeString("bar");
|
||||
SetAttr3 symAttr = new SetAttr3();
|
||||
symAttr.serialize(xdr_req);
|
||||
xdr_req.writeBoolean(false);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
SETATTR3Response response1 = nfsd.setattr(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
SETATTR3Response response2 = nfsd.setattr(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testLookup() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
LOOKUP3Request lookupReq = new LOOKUP3Request(handle, "bar");
|
||||
XDR xdr_req = new XDR();
|
||||
lookupReq.serialize(xdr_req);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
LOOKUP3Response response1 = nfsd.lookup(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
LOOKUP3Response response2 = nfsd.lookup(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testAccess() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
XDR xdr_req = new XDR();
|
||||
handle.serialize(xdr_req);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
ACCESS3Response response1 = nfsd.access(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
ACCESS3Response response2 = nfsd.access(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testReadlink() throws Exception {
|
||||
// Create a symlink first.
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
XDR xdr_req = new XDR();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeString("fubar");
|
||||
SetAttr3 symAttr = new SetAttr3();
|
||||
symAttr.serialize(xdr_req);
|
||||
xdr_req.writeString("bar");
|
||||
|
||||
SYMLINK3Response response = nfsd.symlink(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response.getStatus());
|
||||
|
||||
// Now perform readlink operations.
|
||||
FileHandle handle2 = response.getObjFileHandle();
|
||||
XDR xdr_req2 = new XDR();
|
||||
handle2.serialize(xdr_req2);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
READLINK3Response response1 = nfsd.readlink(xdr_req2.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
READLINK3Response response2 = nfsd.readlink(xdr_req2.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testRead() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
|
||||
READ3Request readReq = new READ3Request(handle, 0, 5);
|
||||
XDR xdr_req = new XDR();
|
||||
readReq.serialize(xdr_req);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
/* Hits HDFS-6582. It needs to be fixed first.
|
||||
READ3Response response1 = nfsd.read(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
*/
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
READ3Response response2 = nfsd.read(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testWrite() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
|
||||
byte[] buffer = new byte[10];
|
||||
for (int i = 0; i < 10; i++) {
|
||||
buffer[i] = (byte) i;
|
||||
}
|
||||
|
||||
WRITE3Request writeReq = new WRITE3Request(handle, 0, 10,
|
||||
WriteStableHow.DATA_SYNC, ByteBuffer.wrap(buffer));
|
||||
XDR xdr_req = new XDR();
|
||||
writeReq.serialize(xdr_req);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
WRITE3Response response1 = nfsd.write(xdr_req.asReadOnlyWrap(),
|
||||
null, 1, securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
WRITE3Response response2 = nfsd.write(xdr_req.asReadOnlyWrap(),
|
||||
null, 1, securityHandler,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect response:", null, response2);
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testCreate() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
XDR xdr_req = new XDR();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeString("fubar");
|
||||
xdr_req.writeInt(Nfs3Constant.CREATE_UNCHECKED);
|
||||
SetAttr3 symAttr = new SetAttr3();
|
||||
symAttr.serialize(xdr_req);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
CREATE3Response response1 = nfsd.create(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
CREATE3Response response2 = nfsd.create(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testMkdir() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
XDR xdr_req = new XDR();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeString("fubar");
|
||||
SetAttr3 symAttr = new SetAttr3();
|
||||
symAttr.serialize(xdr_req);
|
||||
xdr_req.writeString("bar");
|
||||
|
||||
// Attempt to remove by an unpriviledged user should fail.
|
||||
SYMLINK3Response response1 = nfsd.symlink(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt to remove by a priviledged user should pass.
|
||||
SYMLINK3Response response2 = nfsd.symlink(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testSymlink() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
XDR xdr_req = new XDR();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeString("fubar");
|
||||
SetAttr3 symAttr = new SetAttr3();
|
||||
symAttr.serialize(xdr_req);
|
||||
xdr_req.writeString("bar");
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
SYMLINK3Response response1 = nfsd.symlink(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
SYMLINK3Response response2 = nfsd.symlink(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testRemove() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
XDR xdr_req = new XDR();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeString("bar");
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
REMOVE3Response response1 = nfsd.remove(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
REMOVE3Response response2 = nfsd.remove(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testRmdir() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
XDR xdr_req = new XDR();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeString("foo");
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
RMDIR3Response response1 = nfsd.rmdir(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
RMDIR3Response response2 = nfsd.rmdir(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testRename() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
XDR xdr_req = new XDR();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeString("bar");
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeString("fubar");
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
RENAME3Response response1 = nfsd.rename(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
RENAME3Response response2 = nfsd.rename(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testReaddir() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
XDR xdr_req = new XDR();
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeLongAsHyper(0);
|
||||
xdr_req.writeLongAsHyper(0);
|
||||
xdr_req.writeInt(100);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
READDIR3Response response1 = nfsd.readdir(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
READDIR3Response response2 = nfsd.readdir(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testReaddirplus() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
XDR xdr_req = new XDR();
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeLongAsHyper(0);
|
||||
xdr_req.writeLongAsHyper(0);
|
||||
xdr_req.writeInt(3);
|
||||
xdr_req.writeInt(2);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
READDIRPLUS3Response response1 = nfsd.readdirplus(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
READDIRPLUS3Response response2 = nfsd.readdirplus(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testFsstat() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
XDR xdr_req = new XDR();
|
||||
handle.serialize(xdr_req);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
FSSTAT3Response response1 = nfsd.fsstat(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
FSSTAT3Response response2 = nfsd.fsstat(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testFsinfo() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
XDR xdr_req = new XDR();
|
||||
handle.serialize(xdr_req);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
FSINFO3Response response1 = nfsd.fsinfo(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
FSINFO3Response response2 = nfsd.fsinfo(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testPathconf() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
XDR xdr_req = new XDR();
|
||||
handle.serialize(xdr_req);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
PATHCONF3Response response1 = nfsd.pathconf(xdr_req.asReadOnlyWrap(),
|
||||
securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
PATHCONF3Response response2 = nfsd.pathconf(xdr_req.asReadOnlyWrap(),
|
||||
securityHandler, new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK,
|
||||
response2.getStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testCommit() throws Exception {
|
||||
HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
|
||||
long dirId = status.getFileId();
|
||||
FileHandle handle = new FileHandle(dirId);
|
||||
XDR xdr_req = new XDR();
|
||||
handle.serialize(xdr_req);
|
||||
xdr_req.writeLongAsHyper(0);
|
||||
xdr_req.writeInt(5);
|
||||
|
||||
Channel ch = Mockito.mock(Channel.class);
|
||||
|
||||
// Attempt by an unpriviledged user should fail.
|
||||
COMMIT3Response response1 = nfsd.commit(xdr_req.asReadOnlyWrap(),
|
||||
ch, 1, securityHandlerUnpriviledged,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
|
||||
response1.getStatus());
|
||||
|
||||
// Attempt by a priviledged user should pass.
|
||||
COMMIT3Response response2 = nfsd.commit(xdr_req.asReadOnlyWrap(),
|
||||
ch, 1, securityHandler,
|
||||
new InetSocketAddress("localhost", 1234));
|
||||
assertEquals("Incorrect COMMIT3Response:", null, response2);
|
||||
}
|
||||
|
||||
@Test(timeout=1000)
|
||||
public void testIdempotent() {
|
||||
Object[][] procedures = {
|
||||
|
|
|
@ -182,6 +182,9 @@ Release 2.6.0 - UNRELEASED
|
|||
|
||||
HDFS-5185. DN fails to startup if one of the data dir is full. (vinayakumarb)
|
||||
|
||||
HDFS-6451. NFS should not return NFS3ERR_IO for AccessControlException
|
||||
(Abhiraj Butala via brandonli)
|
||||
|
||||
Release 2.5.0 - UNRELEASED
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
|
Loading…
Reference in New Issue