Search in sources :

Example 1 with AccessPrivilege

use of org.apache.hadoop.nfs.AccessPrivilege in project hadoop by apache.

the class RpcProgramNfs3 method checkAccessPrivilege.

private boolean checkAccessPrivilege(SocketAddress remoteAddress, final AccessPrivilege expected) {
    // Port monitoring
    if (!doPortMonitoring(remoteAddress)) {
        return false;
    }
    // Check export table
    if (exports == null) {
        return false;
    }
    InetAddress client = ((InetSocketAddress) remoteAddress).getAddress();
    AccessPrivilege access = exports.getAccessPrivilege(client);
    if (access == AccessPrivilege.NONE) {
        return false;
    }
    if (access == AccessPrivilege.READ_ONLY && expected == AccessPrivilege.READ_WRITE) {
        return false;
    }
    return true;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) AccessPrivilege(org.apache.hadoop.nfs.AccessPrivilege)

Example 2 with AccessPrivilege

use of org.apache.hadoop.nfs.AccessPrivilege in project hadoop by apache.

the class RpcProgramMountd method mnt.

@Override
public XDR mnt(XDR xdr, XDR out, int xid, InetAddress client) {
    if (hostsMatcher == null) {
        return MountResponse.writeMNTResponse(Nfs3Status.NFS3ERR_ACCES, out, xid, null);
    }
    AccessPrivilege accessPrivilege = hostsMatcher.getAccessPrivilege(client);
    if (accessPrivilege == AccessPrivilege.NONE) {
        return MountResponse.writeMNTResponse(Nfs3Status.NFS3ERR_ACCES, out, xid, null);
    }
    String path = xdr.readString();
    if (LOG.isDebugEnabled()) {
        LOG.debug("MOUNT MNT path: " + path + " client: " + client);
    }
    String host = client.getHostName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Got host: " + host + " path: " + path);
    }
    if (!exports.contains(path)) {
        LOG.info("Path " + path + " is not shared.");
        MountResponse.writeMNTResponse(Nfs3Status.NFS3ERR_NOENT, out, xid, null);
        return out;
    }
    FileHandle handle = null;
    try {
        HdfsFileStatus exFileStatus = dfsClient.getFileInfo(path);
        handle = new FileHandle(exFileStatus.getFileId());
    } catch (IOException e) {
        LOG.error("Can't get handle for export:" + path, e);
        MountResponse.writeMNTResponse(Nfs3Status.NFS3ERR_NOENT, out, xid, null);
        return out;
    }
    assert (handle != null);
    LOG.info("Giving handle (fileId:" + handle.getFileId() + ") to client for export " + path);
    mounts.add(new MountEntry(host, path));
    MountResponse.writeMNTResponse(Nfs3Status.NFS3_OK, out, xid, handle.getContent());
    return out;
}
Also used : MountEntry(org.apache.hadoop.mount.MountEntry) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) IOException(java.io.IOException) AccessPrivilege(org.apache.hadoop.nfs.AccessPrivilege)

Aggregations

AccessPrivilege (org.apache.hadoop.nfs.AccessPrivilege)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)1 MountEntry (org.apache.hadoop.mount.MountEntry)1 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)1