Search in sources :

Example 1 with NoXdataChimeraException

use of org.dcache.chimera.NoXdataChimeraException in project dcache by dCache.

the class ChimeraVfs method getXattr.

@Override
public byte[] getXattr(Inode inode, String attr) throws IOException {
    FsInode fsInode = toFsInode(inode);
    try {
        if (attr.startsWith(XATTR_TAG_PREFIX) && fsInode.isDirectory()) {
            String tagName = attr.substring(XATTR_TAG_PREFIX.length());
            byte[] buf = new byte[1024];
            int n = _fs.getTag(fsInode, tagName, buf, 0, buf.length);
            if (n == 0) {
                throw new NoXattrException("tag doesn't exist or empty");
            }
            return Arrays.copyOf(buf, n);
        }
        // try dcache dot files first
        var dcache_attr = SpecialXattrs.byName(attr);
        if (dcache_attr.isPresent()) {
            return dcache_attr.get().read(fsInode);
        }
        // just a regular extended attribute
        return _fs.getXattr(fsInode, attr);
    } catch (NoXdataChimeraException e) {
        throw new NoXattrException(e.getMessage(), e);
    }
}
Also used : NoXdataChimeraException(org.dcache.chimera.NoXdataChimeraException) FsInode(org.dcache.chimera.FsInode) NoXattrException(org.dcache.nfs.status.NoXattrException)

Example 2 with NoXdataChimeraException

use of org.dcache.chimera.NoXdataChimeraException 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 3 with NoXdataChimeraException

use of org.dcache.chimera.NoXdataChimeraException in project dcache by dCache.

the class ChimeraNameSpaceProvider method writeExtendedAttribute.

public void writeExtendedAttribute(Subject subject, FsPath path, String name, byte[] value, SetExtendedAttributeMode mode) throws CacheException {
    try {
        ExtendedInode target = pathToInode(subject, path.toString());
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(target);
            if (target.isDirectory()) {
                if (_permissionHandler.canCreateFile(subject, attributes) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied");
                }
            } else {
                if (_permissionHandler.canWriteFile(subject, attributes) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied");
                }
            }
        }
        FileSystemProvider.SetXattrMode m;
        switch(mode) {
            case CREATE:
                m = FileSystemProvider.SetXattrMode.CREATE;
                break;
            case REPLACE:
                m = FileSystemProvider.SetXattrMode.REPLACE;
                break;
            case EITHER:
                m = FileSystemProvider.SetXattrMode.EITHER;
                break;
            default:
                throw new RuntimeException();
        }
        _fs.setXattr(target, name, value, m);
    } catch (NoXdataChimeraException e) {
        throw new NoAttributeCacheException(e.getMessage(), e);
    } catch (FileExistsChimeraFsException e) {
        throw new AttributeExistsCacheException(e.getMessage(), e);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file " + path);
    } catch (ChimeraFsException e) {
        throw new CacheException("Failed to list extended attributes: " + Exceptions.messageOrClassName(e), e);
    }
}
Also used : NoXdataChimeraException(org.dcache.chimera.NoXdataChimeraException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SetXattrMode(org.dcache.chimera.FileSystemProvider.SetXattrMode) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileSystemProvider(org.dcache.chimera.FileSystemProvider) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException)

Example 4 with NoXdataChimeraException

use of org.dcache.chimera.NoXdataChimeraException in project dcache by dCache.

the class ChimeraVfs method setXattr.

@Override
public void setXattr(Inode inode, String attr, byte[] value, SetXattrMode mode) throws IOException {
    FsInode fsInode = toFsInode(inode);
    // try dcache dot files first
    var dcache_attr = SpecialXattrs.byName(attr);
    if (dcache_attr.isPresent()) {
        dcache_attr.get().set(fsInode, value);
        return;
    }
    try {
        if (attr.startsWith(XATTR_TAG_PREFIX) && fsInode.isDirectory()) {
            String tagName = attr.substring(XATTR_TAG_PREFIX.length());
            if (mode == SetXattrMode.CREATE) {
                _fs.createTag(fsInode, tagName);
            }
            if (mode == SetXattrMode.EITHER) {
                try {
                    _fs.statTag(fsInode, tagName);
                } catch (FileNotFoundChimeraFsException e) {
                    _fs.createTag(fsInode, tagName);
                }
            }
            _fs.setTag(fsInode, tagName, value, 0, value.length);
        } else {
            FileSystemProvider.SetXattrMode m;
            switch(mode) {
                case CREATE:
                    m = FileSystemProvider.SetXattrMode.CREATE;
                    break;
                case REPLACE:
                    m = FileSystemProvider.SetXattrMode.REPLACE;
                    break;
                case EITHER:
                    m = FileSystemProvider.SetXattrMode.EITHER;
                    break;
                default:
                    throw new RuntimeException();
            }
            _fs.setXattr(fsInode, attr, value, m);
        }
    } catch (NoXdataChimeraException e) {
        throw new NoXattrException(e.getMessage(), e);
    } catch (FileExistsChimeraFsException e) {
        throw new ExistException(e.getMessage(), e);
    }
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) NoXdataChimeraException(org.dcache.chimera.NoXdataChimeraException) FileSystemProvider(org.dcache.chimera.FileSystemProvider) FsInode(org.dcache.chimera.FsInode) NoXattrException(org.dcache.nfs.status.NoXattrException) ExistException(org.dcache.nfs.status.ExistException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException)

Example 5 with NoXdataChimeraException

use of org.dcache.chimera.NoXdataChimeraException in project dcache by dCache.

the class ChimeraNameSpaceProvider method removeExtendedAttribute.

public void removeExtendedAttribute(Subject subject, FsPath path, String name) throws CacheException {
    try {
        ExtendedInode target = pathToInode(subject, path.toString());
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(target);
            if (target.isDirectory()) {
                if (_permissionHandler.canCreateFile(subject, attributes) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied");
                }
            } else {
                if (_permissionHandler.canWriteFile(subject, attributes) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied");
                }
            }
        }
        _fs.removeXattr(target, name);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file " + path);
    } catch (NoXdataChimeraException e) {
        throw new NoAttributeCacheException("No attribute " + name + " for file " + path, e);
    } catch (ChimeraFsException e) {
        throw new CacheException("Failed to list extended attributes: " + Exceptions.messageOrClassName(e), e);
    }
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) NoXdataChimeraException(org.dcache.chimera.NoXdataChimeraException) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileAttributes(org.dcache.vehicles.FileAttributes)

Aggregations

NoXdataChimeraException (org.dcache.chimera.NoXdataChimeraException)5 FileExistsChimeraFsException (org.dcache.chimera.FileExistsChimeraFsException)3 FileNotFoundChimeraFsException (org.dcache.chimera.FileNotFoundChimeraFsException)3 FsInode (org.dcache.chimera.FsInode)3 NoXattrException (org.dcache.nfs.status.NoXattrException)3 AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)2 CacheException (diskCacheV111.util.CacheException)2 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)2 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)2 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)2 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)2 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)2 LockedCacheException (diskCacheV111.util.LockedCacheException)2 NoAttributeCacheException (diskCacheV111.util.NoAttributeCacheException)2 NotDirCacheException (diskCacheV111.util.NotDirCacheException)2 NotFileCacheException (diskCacheV111.util.NotFileCacheException)2 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)2 ChimeraFsException (org.dcache.chimera.ChimeraFsException)2 DirNotEmptyChimeraFsException (org.dcache.chimera.DirNotEmptyChimeraFsException)2 FileSystemProvider (org.dcache.chimera.FileSystemProvider)2