Search in sources :

Example 1 with PermException

use of org.dcache.nfs.status.PermException in project dcache by dCache.

the class ChimeraVfs method removeXattr.

@Override
public void removeXattr(Inode inode, String attr) throws IOException {
    FsInode fsInode = toFsInode(inode);
    // try dcache dot files first
    var dcache_attr = SpecialXattrs.byName(attr);
    if (dcache_attr.isPresent()) {
        throw new PermException("Can't remove dCache attribute");
    }
    try {
        if (attr.startsWith(XATTR_TAG_PREFIX) && fsInode.isDirectory()) {
            String tagName = attr.substring(XATTR_TAG_PREFIX.length());
            _fs.removeTag(fsInode, tagName);
        } else {
            _fs.removeXattr(fsInode, attr);
        }
    } catch (NoXdataChimeraException e) {
        throw new NoXattrException(e.getMessage(), e);
    }
}
Also used : NoXdataChimeraException(org.dcache.chimera.NoXdataChimeraException) FsInode(org.dcache.chimera.FsInode) PermException(org.dcache.nfs.status.PermException) NoXattrException(org.dcache.nfs.status.NoXattrException)

Example 2 with PermException

use of org.dcache.nfs.status.PermException in project dcache by dCache.

the class ChimeraVfs method setattr.

@Override
public void setattr(Inode inode, Stat stat) throws IOException {
    FsInode fsInode = toFsInode(inode);
    try {
        if (shouldRejectAttributeUpdates(fsInode, _fs)) {
            throw new PermException("setStat not allowed.");
        }
        // OperationSETATTR have already checked for a valid open stateid
        if (stat.isDefined(Stat.StatAttribute.SIZE)) {
            var chimeraStat = fsInode.stat();
            int type = chimeraStat.getMode() & UnixPermission.F_TYPE;
            switch(type) {
                case UnixPermission.S_IFREG:
                    // ok
                    break;
                case UnixPermission.S_IFDIR:
                    throw new IsDirException("Can't update size of a directory");
                default:
                    throw new InvalException("Can't update size of a non file object");
            }
            // allow set size only for newly created files
            if (fsInode.type() == FsInodeType.INODE && chimeraStat.getState() != FileState.CREATED) {
                throw new PermException("Can't change size of existing file");
            }
        }
        org.dcache.chimera.posix.Stat chimeraStat = toChimeraStat(stat);
        // convert empty setattr to noop
        if (!chimeraStat.getDefinedAttributeses().isEmpty()) {
            fsInode.setStat(chimeraStat);
        }
    } catch (InvalidArgumentChimeraException e) {
        throw new InvalException(e.getMessage());
    } catch (IsDirChimeraException e) {
        throw new IsDirException(e.getMessage());
    } catch (FileNotFoundChimeraFsException e) {
        throw new StaleException(e.getMessage());
    } catch (PermissionDeniedChimeraFsException e) {
        throw new PermException(e.getMessage());
    }
}
Also used : IsDirException(org.dcache.nfs.status.IsDirException) InvalException(org.dcache.nfs.status.InvalException) IsDirChimeraException(org.dcache.chimera.IsDirChimeraException) InvalidArgumentChimeraException(org.dcache.chimera.InvalidArgumentChimeraException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedChimeraFsException(org.dcache.chimera.PermissionDeniedChimeraFsException) FsInode(org.dcache.chimera.FsInode) PermException(org.dcache.nfs.status.PermException) StaleException(org.dcache.nfs.status.StaleException)

Example 3 with PermException

use of org.dcache.nfs.status.PermException in project dcache by dCache.

the class EDSOperationWRITE method process.

@Override
public void process(CompoundContext context, nfs_resop4 result) {
    final WRITE4res res = result.opwrite;
    try {
        NfsMover mover = nfsTransferService.getMoverByStateId(context, _args.opwrite.stateid);
        if (!mover.getIoMode().contains(StandardOpenOption.WRITE)) {
            throw new PermException("an attempt to write without IO mode enabled");
        }
        long offset = _args.opwrite.offset.value;
        RepositoryChannel fc = mover.getMoverChannel();
        _args.opwrite.data.rewind();
        int bytesWritten = fc.write(_args.opwrite.data, offset);
        res.status = nfsstat.NFS_OK;
        res.resok4 = new WRITE4resok();
        res.resok4.count = new count4(bytesWritten);
        res.resok4.writeverf = context.getRebootVerifier();
        /*
             * The pool holds only the data. If client wants to sync metadata
             * as well (FILE_SYNC-like behavior), the it must send an explicit
             * LAYOUT_COMMIT to the door.
             */
        res.resok4.committed = stable_how4.DATA_SYNC4;
        _log.debug("MOVER: {}@{} written, {} requested.", bytesWritten, offset, bytesWritten);
    } catch (ChimeraNFSException he) {
        _log.debug(he.getMessage());
        res.status = he.getStatus();
    } catch (OutOfDiskException e) {
        _log.error("DSWRITE: no allocatable space left on the pool");
        res.status = nfsstat.NFSERR_NOSPC;
    } catch (IOException ioe) {
        _log.error("DSWRITE: ", ioe);
        res.status = nfsstat.NFSERR_IO;
    } catch (Exception e) {
        _log.error("DSWRITE: ", e);
        res.status = nfsstat.NFSERR_SERVERFAULT;
    }
}
Also used : WRITE4resok(org.dcache.nfs.v4.xdr.WRITE4resok) OutOfDiskException(org.dcache.pool.repository.OutOfDiskException) RepositoryChannel(org.dcache.pool.repository.RepositoryChannel) org.dcache.nfs.v4.xdr.count4(org.dcache.nfs.v4.xdr.count4) ChimeraNFSException(org.dcache.nfs.ChimeraNFSException) PermException(org.dcache.nfs.status.PermException) IOException(java.io.IOException) WRITE4res(org.dcache.nfs.v4.xdr.WRITE4res) IOException(java.io.IOException) OutOfDiskException(org.dcache.pool.repository.OutOfDiskException) ChimeraNFSException(org.dcache.nfs.ChimeraNFSException) PermException(org.dcache.nfs.status.PermException)

Example 4 with PermException

use of org.dcache.nfs.status.PermException in project dcache by dCache.

the class ChimeraVfs method write.

@Override
public WriteResult write(Inode inode, byte[] data, long offset, int count, StabilityLevel stabilityLevel) throws IOException {
    try {
        FsInode fsInode = toFsInode(inode);
        int bytesWritten = fsInode.write(offset, data, 0, count);
        return new WriteResult(StabilityLevel.FILE_SYNC, bytesWritten);
    } catch (PermissionDeniedChimeraFsException exception) {
        throw new PermException(exception.getMessage());
    }
}
Also used : PermissionDeniedChimeraFsException(org.dcache.chimera.PermissionDeniedChimeraFsException) FsInode(org.dcache.chimera.FsInode) PermException(org.dcache.nfs.status.PermException)

Example 5 with PermException

use of org.dcache.nfs.status.PermException in project dcache by dCache.

the class ChimeraVfs method move.

@Override
public boolean move(Inode src, String oldName, Inode dest, String newName) throws IOException {
    FsInode from = toFsInode(src);
    FsInode to = toFsInode(dest);
    try {
        return _fs.rename(_fs.inodeOf(from, oldName, NO_STAT), from, oldName, to, newName);
    } catch (NotDirChimeraException e) {
        throw new NotDirException("not a directory");
    } catch (FileExistsChimeraFsException e) {
        throw new ExistException("destination exists");
    } catch (DirNotEmptyChimeraFsException e) {
        throw new NotEmptyException("directory exist and not empty");
    } catch (FileNotFoundChimeraFsException e) {
        throw new NoEntException("file not found");
    } catch (PermissionDeniedChimeraFsException e) {
        throw new PermException(e.getMessage());
    }
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) NotDirException(org.dcache.nfs.status.NotDirException) PermissionDeniedChimeraFsException(org.dcache.chimera.PermissionDeniedChimeraFsException) NotDirChimeraException(org.dcache.chimera.NotDirChimeraException) FsInode(org.dcache.chimera.FsInode) NoEntException(org.dcache.nfs.status.NoEntException) PermException(org.dcache.nfs.status.PermException) NotEmptyException(org.dcache.nfs.status.NotEmptyException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) ExistException(org.dcache.nfs.status.ExistException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException)

Aggregations

PermException (org.dcache.nfs.status.PermException)5 FsInode (org.dcache.chimera.FsInode)4 PermissionDeniedChimeraFsException (org.dcache.chimera.PermissionDeniedChimeraFsException)3 FileNotFoundChimeraFsException (org.dcache.chimera.FileNotFoundChimeraFsException)2 IOException (java.io.IOException)1 DirNotEmptyChimeraFsException (org.dcache.chimera.DirNotEmptyChimeraFsException)1 FileExistsChimeraFsException (org.dcache.chimera.FileExistsChimeraFsException)1 InvalidArgumentChimeraException (org.dcache.chimera.InvalidArgumentChimeraException)1 IsDirChimeraException (org.dcache.chimera.IsDirChimeraException)1 NoXdataChimeraException (org.dcache.chimera.NoXdataChimeraException)1 NotDirChimeraException (org.dcache.chimera.NotDirChimeraException)1 ChimeraNFSException (org.dcache.nfs.ChimeraNFSException)1 ExistException (org.dcache.nfs.status.ExistException)1 InvalException (org.dcache.nfs.status.InvalException)1 IsDirException (org.dcache.nfs.status.IsDirException)1 NoEntException (org.dcache.nfs.status.NoEntException)1 NoXattrException (org.dcache.nfs.status.NoXattrException)1 NotDirException (org.dcache.nfs.status.NotDirException)1 NotEmptyException (org.dcache.nfs.status.NotEmptyException)1 StaleException (org.dcache.nfs.status.StaleException)1