static boolean setTimes( FSDirectory fsd, INodesInPath iip, long mtime, long atime, boolean force) throws QuotaExceededException { fsd.writeLock(); try { return unprotectedSetTimes(fsd, iip, mtime, atime, force); } finally { fsd.writeUnlock(); } }
void markNameCacheInitialized() { writeLock(); try { nameCache.initialized(); } finally { writeUnlock(); } }
void stopReencryptThread() { if (getProvider() == null || reencryptionHandler == null) { return; } dir.writeLock(); try { reencryptionHandler.stopThreads(); } finally { dir.writeUnlock(); } if (reencryptHandlerExecutor != null) { reencryptHandlerExecutor.shutdownNow(); reencryptHandlerExecutor = null; } }
static void disallowSnapshot( FSDirectory fsd, SnapshotManager snapshotManager, String path) throws IOException { fsd.writeLock(); try { snapshotManager.resetSnapshottable(path); } finally { fsd.writeUnlock(); } fsd.getEditLog().logDisallowSnapshot(path); }
/** Allow snapshot on a directory. */ static void allowSnapshot(FSDirectory fsd, SnapshotManager snapshotManager, String path) throws IOException { fsd.writeLock(); try { snapshotManager.setSnapshottable(path, true); } finally { fsd.writeUnlock(); } fsd.getEditLog().logAllowSnapshot(path); }
/** * Add the given child to the namespace. * @param existing the INodesInPath containing all the ancestral INodes * @param child the new INode to add * @param modes create modes * @return a new INodesInPath instance containing the new child INode. Null * if the adding fails. * @throws QuotaExceededException is thrown if it violates quota limit */ INodesInPath addINode(INodesInPath existing, INode child, FsPermission modes) throws QuotaExceededException, UnresolvedLinkException { cacheName(child); writeLock(); try { return addLastINode(existing, child, modes, true); } finally { writeUnlock(); } }
static void removeSPSXattr(FSDirectory fsd, INode inode, XAttr spsXAttr) throws IOException { try { fsd.writeLock(); List<XAttr> existingXAttrs = XAttrStorage.readINodeXAttrs(inode); existingXAttrs.remove(spsXAttr); XAttrStorage.updateINodeXAttrs(inode, existingXAttrs, INodesInPath .fromINode(inode).getLatestSnapshotId()); List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1); xAttrs.add(spsXAttr); fsd.getEditLog().logRemoveXAttrs(inode.getFullPathName(), xAttrs, false); } finally { fsd.writeUnlock(); } } }
/** Updates namespace, storagespace and typespaces consumed for all * directories until the parent directory of file represented by path. * * @param iip the INodesInPath instance containing all the INodes for * updating quota usage * @param nsDelta the delta change of namespace * @param ssDelta the delta change of storage space consumed without replication * @param replication the replication factor of the block consumption change * @throws QuotaExceededException if the new count violates any quota limit * @throws FileNotFoundException if path does not exist. */ void updateSpaceConsumed(INodesInPath iip, long nsDelta, long ssDelta, short replication) throws QuotaExceededException, FileNotFoundException, UnresolvedLinkException, SnapshotAccessControlException { writeLock(); try { if (iip.getLastINode() == null) { throw new FileNotFoundException("Path not found: " + iip.getPath()); } updateCount(iip, nsDelta, ssDelta, replication, true); } finally { writeUnlock(); } }
static FileStatus setStoragePolicy(FSDirectory fsd, FSPermissionChecker pc, BlockManager bm, String src, final byte policyId, final String operation) throws IOException { if (!fsd.isStoragePolicyEnabled()) { throw new IOException(String.format( "Failed to %s storage policy since %s is set to false.", operation, DFS_STORAGE_POLICY_ENABLED_KEY)); } INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); if (fsd.isPermissionEnabled()) { fsd.checkPathAccess(pc, iip, FsAction.WRITE); } unprotectedSetStoragePolicy(fsd, bm, iip, policyId); fsd.getEditLog().logSetStoragePolicy(iip.getPath(), policyId); } finally { fsd.writeUnlock(); } return fsd.getAuditFileInfo(iip); }
/** * Reset the entire namespace tree. */ void reset() { writeLock(); try { rootDir = createRoot(getFSNamesystem()); inodeMap.clear(); addToInodeMap(rootDir); nameCache.reset(); inodeId.setCurrentValue(INodeId.LAST_RESERVED_ID); } finally { writeUnlock(); } }
static void abandonBlock( FSDirectory fsd, FSPermissionChecker pc, ExtendedBlock b, long fileId, String src, String holder) throws IOException { final INodesInPath iip = fsd.resolvePath(pc, src, fileId); src = iip.getPath(); FSNamesystem fsn = fsd.getFSNamesystem(); final INodeFile file = fsn.checkLease(iip, holder, fileId); Preconditions.checkState(file.isUnderConstruction()); if (file.getBlockType() == BlockType.STRIPED) { return; // do not abandon block for striped file } Block localBlock = ExtendedBlock.getLocalBlock(b); fsd.writeLock(); try { // Remove the block from the pending creates list if (!unprotectedRemoveBlock(fsd, src, iip, file, localBlock)) { return; } } finally { fsd.writeUnlock(); } persistBlocks(fsd, src, file, false); }
static void renameSnapshot(FSDirectory fsd, FSPermissionChecker pc, SnapshotManager snapshotManager, String path, String snapshotOldName, String snapshotNewName, boolean logRetryCache) throws IOException { final INodesInPath iip = fsd.resolvePath(pc, path, DirOp.WRITE); if (fsd.isPermissionEnabled()) { fsd.checkOwner(pc, iip); } verifySnapshotName(fsd, snapshotNewName, path); fsd.writeLock(); try { snapshotManager.renameSnapshot(iip, path, snapshotOldName, snapshotNewName); } finally { fsd.writeUnlock(); } fsd.getEditLog().logRenameSnapshot(path, snapshotOldName, snapshotNewName, logRetryCache); }
static FileStatus setTimes( FSDirectory fsd, FSPermissionChecker pc, String src, long mtime, long atime) throws IOException { INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); // Write access is required to set access and modification times if (fsd.isPermissionEnabled()) { fsd.checkPathAccess(pc, iip, FsAction.WRITE); } final INode inode = iip.getLastINode(); if (inode == null) { throw new FileNotFoundException("File/Directory " + iip.getPath() + " does not exist."); } boolean changed = unprotectedSetTimes(fsd, iip, mtime, atime, true); if (changed) { fsd.getEditLog().logTimes(iip.getPath(), mtime, atime); } } finally { fsd.writeUnlock(); } return fsd.getAuditFileInfo(iip); }
static FileStatus setPermission( FSDirectory fsd, FSPermissionChecker pc, final String src, FsPermission permission) throws IOException { if (FSDirectory.isExactReservedName(src)) { throw new InvalidPathException(src); } INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); fsd.checkOwner(pc, iip); unprotectedSetPermission(fsd, iip, permission); } finally { fsd.writeUnlock(); } fsd.getEditLog().logSetPermissions(iip.getPath(), permission); return fsd.getAuditFileInfo(iip); }
static boolean setReplication( FSDirectory fsd, FSPermissionChecker pc, BlockManager bm, String src, final short replication) throws IOException { bm.verifyReplication(src, replication, null); final boolean isFile; fsd.writeLock(); try { final INodesInPath iip = fsd.resolvePath(pc, src, DirOp.WRITE); if (fsd.isPermissionEnabled()) { fsd.checkPathAccess(pc, iip, FsAction.WRITE); } final BlockInfo[] blocks = unprotectedSetReplication(fsd, iip, replication); isFile = blocks != null; if (isFile) { fsd.getEditLog().logSetReplication(iip.getPath(), replication); } } finally { fsd.writeUnlock(); } return isFile; }
static FileStatus setAcl( FSDirectory fsd, FSPermissionChecker pc, final String srcArg, List<AclEntry> aclSpec) throws IOException { String src = srcArg; checkAclsConfigFlag(fsd); INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); fsd.checkOwner(pc, iip); List<AclEntry> newAcl = unprotectedSetAcl(fsd, iip, aclSpec, false); fsd.getEditLog().logSetAcl(iip.getPath(), newAcl); } catch (AclException e){ throw new AclException(e.getMessage() + " Path: " + src, e); } finally { fsd.writeUnlock(); } return fsd.getAuditFileInfo(iip); }
static FileStatus removeAcl(FSDirectory fsd, FSPermissionChecker pc, final String srcArg) throws IOException { String src = srcArg; checkAclsConfigFlag(fsd); INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); src = iip.getPath(); fsd.checkOwner(pc, iip); unprotectedRemoveAcl(fsd, iip); } catch (AclException e){ throw new AclException(e.getMessage() + " Path: " + src, e); } finally { fsd.writeUnlock(); } fsd.getEditLog().logSetAcl(src, AclFeature.EMPTY_ENTRY_LIST); return fsd.getAuditFileInfo(iip); }
static FileStatus removeAclEntries( FSDirectory fsd, FSPermissionChecker pc, final String srcArg, List<AclEntry> aclSpec) throws IOException { String src = srcArg; checkAclsConfigFlag(fsd); INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); src = iip.getPath(); fsd.checkOwner(pc, iip); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<AclEntry> existingAcl = AclStorage.readINodeLogicalAcl(inode); List<AclEntry> newAcl = AclTransformation.filterAclEntriesByAclSpec( existingAcl, aclSpec); AclStorage.updateINodeAcl(inode, newAcl, snapshotId); fsd.getEditLog().logSetAcl(src, newAcl); } catch (AclException e){ throw new AclException(e.getMessage() + " Path: " + src, e); } finally { fsd.writeUnlock(); } return fsd.getAuditFileInfo(iip); }
static FileStatus modifyAclEntries( FSDirectory fsd, FSPermissionChecker pc, final String srcArg, List<AclEntry> aclSpec) throws IOException { String src = srcArg; checkAclsConfigFlag(fsd); INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); src = iip.getPath(); fsd.checkOwner(pc, iip); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<AclEntry> existingAcl = AclStorage.readINodeLogicalAcl(inode); List<AclEntry> newAcl = AclTransformation.mergeAclEntries( existingAcl, aclSpec); AclStorage.updateINodeAcl(inode, newAcl, snapshotId); fsd.getEditLog().logSetAcl(src, newAcl); } catch (AclException e){ throw new AclException(e.getMessage() + " Path: " + src, e); } finally { fsd.writeUnlock(); } return fsd.getAuditFileInfo(iip); }
static FileStatus removeDefaultAcl(FSDirectory fsd, FSPermissionChecker pc, final String srcArg) throws IOException { String src = srcArg; checkAclsConfigFlag(fsd); INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); src = iip.getPath(); fsd.checkOwner(pc, iip); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<AclEntry> existingAcl = AclStorage.readINodeLogicalAcl(inode); List<AclEntry> newAcl = AclTransformation.filterDefaultAclEntries( existingAcl); AclStorage.updateINodeAcl(inode, newAcl, snapshotId); fsd.getEditLog().logSetAcl(src, newAcl); } catch (AclException e){ throw new AclException(e.getMessage() + " Path: " + src, e); } finally { fsd.writeUnlock(); } return fsd.getAuditFileInfo(iip); }