static BatchedListEntries<EncryptionZone> listEncryptionZones( final FSDirectory fsd, final long prevId) throws IOException { fsd.readLock(); try { return fsd.ezManager.listEncryptionZones(prevId); } finally { fsd.readUnlock(); } }
static BatchedListEntries<ZoneReencryptionStatus> listReencryptionStatus( final FSDirectory fsd, final long prevId) throws IOException { fsd.readLock(); try { return fsd.ezManager.listReencryptionStatus(prevId); } finally { fsd.readUnlock(); } }
static EncryptionZone getEZForPath(final FSDirectory fsd, final INodesInPath iip) throws IOException { fsd.readLock(); try { return fsd.ezManager.getEZINodeForPath(iip); } finally { fsd.readUnlock(); } }
protected void readUnlock() { dir.readUnlock(); dir.getFSNamesystem().readUnlock("FSTreeTraverser"); }
/** * Get the inode from inodeMap based on its inode id. * @param id The given id * @return The inode associated with the given id */ public INode getInode(long id) { readLock(); try { return inodeMap.get(id); } finally { readUnlock(); } }
private static List<XAttr> getXAttrs(FSDirectory fsd, INodesInPath iip) throws IOException { fsd.readLock(); try { return XAttrStorage.readINodeXAttrs(fsd.getAttributes(iip)); } finally { fsd.readUnlock(); } }
static boolean isInAnEZ(final FSDirectory fsd, final INodesInPath iip) throws UnresolvedLinkException, SnapshotAccessControlException, IOException { if (!fsd.ezManager.hasCreatedEncryptionZone()) { return false; } fsd.readLock(); try { return fsd.ezManager.isInAnEZ(iip); } finally { fsd.readUnlock(); } }
/** * Proactively warm up the edek cache. We'll get all the edek key names, * then launch up a separate thread to warm them up. */ static void warmUpEdekCache(final ExecutorService executor, final FSDirectory fsd, final int delay, final int interval) { fsd.readLock(); try { String[] edeks = fsd.ezManager.getKeyNames(); executor.execute( new EDEKCacheLoader(edeks, fsd.getProvider(), delay, interval)); } finally { fsd.readUnlock(); } }
/** * Check whether current user have permissions to access the path. For more * details of the parameters, see * {@link FSPermissionChecker#checkPermission}. */ void checkPermission(FSPermissionChecker pc, INodesInPath iip, boolean doCheckOwner, FsAction ancestorAccess, FsAction parentAccess, FsAction access, FsAction subAccess, boolean ignoreEmptyDir) throws AccessControlException { if (!pc.isSuperUser()) { readLock(); try { pc.checkPermission(iip, doCheckOwner, ancestorAccess, parentAccess, access, subAccess, ignoreEmptyDir); } finally { readUnlock(); } } }
static XAttr getXAttrByPrefixedName(FSDirectory fsd, INodesInPath iip, String prefixedName) throws IOException { fsd.readLock(); try { return XAttrStorage.readINodeXAttrByPrefixedName(iip.getLastINode(), iip.getPathSnapshotId(), prefixedName); } finally { fsd.readUnlock(); } }
static SnapshottableDirectoryStatus[] getSnapshottableDirListing( FSDirectory fsd, FSPermissionChecker pc, SnapshotManager snapshotManager) throws IOException { fsd.readLock(); try { final String user = pc.isSuperUser()? null : pc.getUser(); return snapshotManager.getSnapshottableDirListing(user); } finally { fsd.readUnlock(); } }
@VisibleForTesting public void pauseForTestingAfterNthCheckpoint(final String zone, final int count) throws IOException { INodesInPath iip; final FSPermissionChecker pc = dir.getPermissionChecker(); dir.readLock(); try { iip = dir.resolvePath(pc, zone, DirOp.READ); } finally { dir.readUnlock(); } reencryptionHandler .pauseForTestingAfterNthCheckpoint(iip.getLastINode().getId(), count); }
static long getPreferredBlockSize(FSDirectory fsd, FSPermissionChecker pc, String src) throws IOException { fsd.readLock(); try { final INodesInPath iip = fsd.resolvePath(pc, src, DirOp.READ_LINK); return INodeFile.valueOf(iip.getLastINode(), iip.getPath()) .getPreferredBlockSize(); } finally { fsd.readUnlock(); } }
static BlockStoragePolicy getStoragePolicy(FSDirectory fsd, FSPermissionChecker pc, BlockManager bm, String path) throws IOException { fsd.readLock(); try { final INodesInPath iip = fsd.resolvePath(pc, path, DirOp.READ_LINK); if (fsd.isPermissionEnabled()) { fsd.checkPathAccess(pc, iip, FsAction.READ); } INode inode = iip.getLastINode(); if (inode == null) { throw new FileNotFoundException("File/Directory does not exist: " + iip.getPath()); } return bm.getStoragePolicy(inode.getStoragePolicyID()); } finally { fsd.readUnlock(); } }
static SnapshotDiffReport getSnapshotDiffReport(FSDirectory fsd, FSPermissionChecker pc, SnapshotManager snapshotManager, String path, String fromSnapshot, String toSnapshot) throws IOException { SnapshotDiffReport diffs; fsd.readLock(); try { INodesInPath iip = fsd.resolvePath(pc, path, DirOp.READ); if (fsd.isPermissionEnabled()) { checkSubtreeReadPermission(fsd, pc, path, fromSnapshot); checkSubtreeReadPermission(fsd, pc, path, toSnapshot); } diffs = snapshotManager.diff(iip, path, fromSnapshot, toSnapshot); } finally { fsd.readUnlock(); } return diffs; }
/** * Resolve the zone to an inode, find the encryption zone info associated with * that inode, and return the key name. Does not contact the KMS. */ static String getKeyNameForZone(final FSDirectory dir, final FSPermissionChecker pc, final String zone) throws IOException { assert dir.getProvider() != null; final INodesInPath iip; dir.readLock(); try { iip = dir.resolvePath(pc, zone, DirOp.READ); dir.ezManager.checkEncryptionZoneRoot(iip.getLastINode(), zone); return dir.ezManager.getKeyName(iip); } finally { dir.readUnlock(); } } }
static HdfsFileStatus getFileInfo(FSDirectory fsd, INodesInPath iip, boolean needLocation, boolean needBlockToken) throws IOException { fsd.readLock(); try { HdfsFileStatus status = null; if (FSDirectory.isExactReservedName(iip.getPathComponents())) { status = FSDirectory.DOT_RESERVED_STATUS; } else if (iip.isDotSnapshotDir()) { if (fsd.getINode4DotSnapshot(iip) != null) { status = FSDirectory.DOT_SNAPSHOT_DIR_STATUS; } } else { status = getFileInfo(fsd, iip, true, needLocation, needBlockToken); } return status; } finally { fsd.readUnlock(); } }
/** * @return true if the path is a non-empty directory; otherwise, return false. */ boolean isNonEmptyDirectory(INodesInPath inodesInPath) { readLock(); try { final INode inode = inodesInPath.getLastINode(); if (inode == null || !inode.isDirectory()) { //not found or not a directory return false; } final int s = inodesInPath.getPathSnapshotId(); return !inode.asDirectory().getChildrenList(s).isEmpty(); } finally { readUnlock(); } }
@VisibleForTesting public ZoneReencryptionStatus getZoneStatus(final String zone) throws IOException { final FSPermissionChecker pc = dir.getPermissionChecker(); final INode inode; dir.getFSNamesystem().readLock(); dir.readLock(); try { final INodesInPath iip = dir.resolvePath(pc, zone, DirOp.READ); inode = iip.getLastINode(); if (inode == null) { return null; } return getReencryptionStatus().getZoneStatus(inode.getId()); } finally { dir.readUnlock(); dir.getFSNamesystem().readUnlock(); } }
private static void verifyQuotaForTruncate(FSNamesystem fsn, INodesInPath iip, INodeFile file, long newLength, QuotaCounts delta) throws QuotaExceededException { FSDirectory fsd = fsn.getFSDirectory(); if (!fsn.isImageLoaded() || fsd.shouldSkipQuotaChecks()) { // Do not check quota if edit log is still being processed return; } final BlockStoragePolicy policy = fsd.getBlockStoragePolicySuite() .getPolicy(file.getStoragePolicyID()); file.computeQuotaDeltaForTruncate(newLength, policy, delta); fsd.readLock(); try { FSDirectory.verifyQuota(iip, iip.length() - 1, delta, null); } finally { fsd.readUnlock(); } }