Search in sources :

Example 1 with FuseContext

use of ru.serce.jnrfuse.struct.FuseContext in project alluxio by Alluxio.

the class AlluxioFuseFileSystem method mkdirInternal.

private int mkdirInternal(String path, @mode_t long mode) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    if (turi.getName().length() > MAX_NAME_LENGTH) {
        LOG.error("Failed to create directory {}, directory name is longer than {} characters", path, MAX_NAME_LENGTH);
        return -ErrorCodes.ENAMETOOLONG();
    }
    SetAttributePOptions.Builder attributeOptionsBuilder = SetAttributePOptions.newBuilder();
    FuseContext fc = getContext();
    long uid = fc.uid.get();
    long gid = fc.gid.get();
    try {
        if (gid != GID) {
            String groupName = AlluxioFuseUtils.getGroupName(gid);
            if (groupName.isEmpty()) {
                // This should never be reached since input gid is always valid
                LOG.error("Failed to get group name from gid {}.", gid);
                return -ErrorCodes.EFAULT();
            }
            attributeOptionsBuilder.setGroup(groupName);
        }
        if (uid != UID) {
            String userName = AlluxioFuseUtils.getUserName(uid);
            if (userName.isEmpty()) {
                // This should never be reached since input uid is always valid
                LOG.error("Failed to get user name from uid {}", uid);
                return -ErrorCodes.EFAULT();
            }
            attributeOptionsBuilder.setOwner(userName);
        }
        SetAttributePOptions setAttributePOptions = attributeOptionsBuilder.build();
        mFileSystem.createDirectory(turi, CreateDirectoryPOptions.newBuilder().setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build());
        if (gid != GID || uid != UID) {
            LOG.debug("Set attributes of path {} to {}", path, setAttributePOptions);
            mFileSystem.setAttribute(turi, setAttributePOptions);
        }
    } catch (FileAlreadyExistsException e) {
        LOG.debug("Failed to create directory {}, directory already exists", path);
        return -ErrorCodes.EEXIST();
    } catch (InvalidPathException e) {
        LOG.debug("Failed to create directory {}, path is invalid", path);
        return -ErrorCodes.ENOENT();
    } catch (Throwable t) {
        LOG.error("Failed to create directory {}", path, t);
        return AlluxioFuseUtils.getErrorCode(t);
    }
    return 0;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FuseContext(ru.serce.jnrfuse.struct.FuseContext) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) InvalidPathException(java.nio.file.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 2 with FuseContext

use of ru.serce.jnrfuse.struct.FuseContext in project alluxio by Alluxio.

the class AlluxioFuseFileSystem method createInternal.

private int createInternal(String path, @mode_t long mode, FuseFileInfo fi) {
    final AlluxioURI uri = mPathResolverCache.getUnchecked(path);
    if (uri.getName().length() > MAX_NAME_LENGTH) {
        LOG.error("Failed to create {}, file name is longer than {} characters", path, MAX_NAME_LENGTH);
        return -ErrorCodes.ENAMETOOLONG();
    }
    try {
        if (mOpenFiles.size() >= MAX_OPEN_FILES) {
            LOG.error("Cannot create {}: too many open files (MAX_OPEN_FILES: {})", path, MAX_OPEN_FILES);
            return -ErrorCodes.EMFILE();
        }
        SetAttributePOptions.Builder attributeOptionsBuilder = SetAttributePOptions.newBuilder();
        FuseContext fc = getContext();
        long uid = fc.uid.get();
        long gid = fc.gid.get();
        if (gid != GID) {
            String groupName = AlluxioFuseUtils.getGroupName(gid);
            if (groupName.isEmpty()) {
                // This should never be reached since input gid is always valid
                LOG.error("Failed to get group name from gid {}.", gid);
                return -ErrorCodes.EFAULT();
            }
            attributeOptionsBuilder.setGroup(groupName);
        }
        if (uid != UID) {
            String userName = AlluxioFuseUtils.getUserName(uid);
            if (userName.isEmpty()) {
                // This should never be reached since input uid is always valid
                LOG.error("Failed to get user name from uid {}", uid);
                return -ErrorCodes.EFAULT();
            }
            attributeOptionsBuilder.setOwner(userName);
        }
        SetAttributePOptions setAttributePOptions = attributeOptionsBuilder.build();
        FileOutStream os = mFileSystem.createFile(uri, CreateFilePOptions.newBuilder().setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build());
        long fid = mNextOpenFileId.getAndIncrement();
        mOpenFiles.add(new OpenFileEntry(fid, path, null, os));
        fi.fh.set(fid);
        if (gid != GID || uid != UID) {
            LOG.debug("Set attributes of path {} to {}", path, setAttributePOptions);
            mFileSystem.setAttribute(uri, setAttributePOptions);
        }
    } catch (FileAlreadyExistsException e) {
        LOG.debug("Failed to create {}, file already exists", path);
        return -ErrorCodes.EEXIST();
    } catch (InvalidPathException e) {
        LOG.debug("Failed to create {}, path is invalid", path);
        return -ErrorCodes.ENOENT();
    } catch (Throwable t) {
        LOG.error("Failed to create {}", path, t);
        return AlluxioFuseUtils.getErrorCode(t);
    }
    return 0;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FileOutStream(alluxio.client.file.FileOutStream) InvalidPathException(java.nio.file.InvalidPathException) FuseContext(ru.serce.jnrfuse.struct.FuseContext) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) AlluxioURI(alluxio.AlluxioURI)

Aggregations

AlluxioURI (alluxio.AlluxioURI)2 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 InvalidPathException (java.nio.file.InvalidPathException)2 FuseContext (ru.serce.jnrfuse.struct.FuseContext)2 FileOutStream (alluxio.client.file.FileOutStream)1