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);
}
}
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());
}
}
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;
}
}
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());
}
}
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());
}
}
Aggregations