@Override public final int hashCode() { long id = getId(); return (int)(id^(id>>>32)); }
@Override public final long getId() { return referred.getId(); }
/** * Replace the given child from the created list. * @return true if the child is replaced; false if the child is not found. */ private boolean replaceCreated(final INode oldChild, final INode newChild) { final List<INode> list = getCreatedUnmodifiable(); final int i = search(list, oldChild.getLocalNameBytes()); if (i < 0 || list.get(i).getId() != oldChild.getId()) { return false; } final INode removed = setCreated(i, newChild); Preconditions.checkState(removed == oldChild); return true; }
/** * This method is always called with writeLock of FSDirectory held. */ public final void removeFromInodeMap(List<? extends INode> inodes) { if (inodes != null) { for (INode inode : inodes) { if (inode != null && inode instanceof INodeWithAdditionalFields) { inodeMap.remove(inode); ezManager.removeEncryptionZone(inode.getId()); } } } }
@Override public boolean canTraverseDir(INode inode) throws IOException { if (ezManager.isEncryptionZoneRoot(inode, inode.getFullPathName())) { // nested EZ, ignore. LOG.info("{}({}) is a nested EZ, skipping for re-encryption", inode.getFullPathName(), inode.getId()); return false; } return true; }
/** * Return whether an INode is an encryption zone root. */ boolean isEncryptionZoneRoot(final INode inode, final String name) throws FileNotFoundException { assert dir.hasReadLock(); if (inode == null) { throw new FileNotFoundException("INode does not exist for " + name); } if (!inode.isDirectory()) { return false; } if (!hasCreatedEncryptionZone() || !encryptionZones.containsKey(inode.getId())) { return false; } return true; }
private INodeSection.INode.Builder buildINodeCommon(INode n) { return INodeSection.INode.newBuilder() .setId(n.getId()) .setName(ByteString.copyFrom(n.getLocalNameBytes())); }
/** * Re-encrypts the given encryption zone path. If the given path is not the * root of an encryption zone, an exception is thrown. */ List<XAttr> reencryptEncryptionZone(final INodesInPath zoneIIP, final String keyVersionName) throws IOException { assert dir.hasWriteLock(); if (reencryptionHandler == null) { throw new IOException("No key provider configured, re-encryption " + "operation is rejected"); } final List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1); final INode inode = zoneIIP.getLastINode(); final String zoneName = zoneIIP.getPath(); checkEncryptionZoneRoot(inode, zoneName); if (getReencryptionStatus().hasRunningZone(inode.getId())) { throw new IOException("Zone " + zoneName + " is already submitted for re-encryption."); } LOG.info("Zone {}({}) is submitted for re-encryption.", zoneName, inode.getId()); final XAttr xattr = FSDirEncryptionZoneOp .updateReencryptionSubmitted(dir, zoneIIP, keyVersionName); xAttrs.add(xattr); reencryptionHandler.notifyNewSubmission(); return xAttrs; }
/** Add a dir-diff pair */ void addDirDiff(INodeDirectory dir, byte[][] relativePath, ChildrenDiff diff) { dirDiffMap.put(dir, diff); diffMap.put(dir, relativePath); // detect rename for (INode created : diff.getCreatedUnmodifiable()) { if (created.isReference()) { RenameEntry entry = getEntry(created.getId()); if (entry.getTargetPath() == null) { entry.setTarget(created, relativePath); } } } for (INode deleted : diff.getDeletedUnmodifiable()) { if (deleted instanceof INodeReference.WithName) { RenameEntry entry = getEntry(deleted.getId()); entry.setSource(deleted, relativePath); } } }
/** * Log re-encrypt complete (cancel, or 100% re-encrypt) to edits. * Caller should logSync after calling this, outside of the FSN lock. * <p> * Original reencryption status is passed in to get existing information, * this should include whether it is finished due to cancellation. * The reencryption status is updated during SetXAttrs for completion time. */ static List<XAttr> updateReencryptionFinish(final FSDirectory fsd, final INodesInPath zoneIIP, final ZoneReencryptionStatus origStatus) throws IOException { assert origStatus != null; assert fsd.hasWriteLock(); fsd.ezManager.getReencryptionStatus() .markZoneCompleted(zoneIIP.getLastINode().getId()); final XAttr xattr = generateNewXAttrForReencryptionFinish(zoneIIP, origStatus); final List<XAttr> xattrs = Lists.newArrayListWithCapacity(1); xattrs.add(xattr); FSDirXAttrOp.unprotectedSetXAttrs(fsd, zoneIIP, xattrs, EnumSet.of(XAttrSetFlag.REPLACE)); return xattrs; }
@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); }
&& Arrays.equals(pathComponents[4], DOT_DOT)) { INode parent = inode.getParent(); if (parent == null || parent.getId() == INodeId.ROOT_INODE_ID) {
/** * Cancels the currently-running re-encryption of the given encryption zone. * If the given path is not the root of an encryption zone, * * an exception is thrown. */ List<XAttr> cancelReencryptEncryptionZone(final INodesInPath zoneIIP) throws IOException { assert dir.hasWriteLock(); if (reencryptionHandler == null) { throw new IOException("No key provider configured, re-encryption " + "operation is rejected"); } final long zoneId = zoneIIP.getLastINode().getId(); final String zoneName = zoneIIP.getPath(); checkEncryptionZoneRoot(zoneIIP.getLastINode(), zoneName); reencryptionHandler.cancelZone(zoneId, zoneName); LOG.info("Cancelled zone {}({}) for re-encryption.", zoneName, zoneId); return FSDirEncryptionZoneOp.updateReencryptionFinish(dir, zoneIIP, reencryptionStatus.getZoneStatus(zoneId)); }
List<XAttr> completeReencryption(final INode zoneNode) throws IOException { assert dir.hasWriteLock(); assert dir.getFSNamesystem().hasWriteLock(); final Long zoneId = zoneNode.getId(); ZoneReencryptionStatus zs = getReencryptionStatus().getZoneStatus(zoneId); assert zs != null; LOG.info("Re-encryption completed on zone {}. Re-encrypted {} files," + " failures encountered: {}.", zoneNode.getFullPathName(), zs.getFilesReencrypted(), zs.getNumReencryptionFailures()); synchronized (this) { submissions.remove(zoneId); } return FSDirEncryptionZoneOp .updateReencryptionFinish(dir, INodesInPath.fromINode(zoneNode), zs); }
static boolean unprotectedSatisfyStoragePolicy(INode inode, FSDirectory fsd) { if (inode.isFile() && inode.asFile().numBlocks() == 0) { return false; } else { // Adding directory in the pending queue, so FileInodeIdCollector process // directory child in batch and recursively StoragePolicySatisfyManager spsManager = fsd.getBlockManager().getSPSManager(); if (spsManager != null) { spsManager.addPathId(inode.getId()); } return true; } }
/** * Resolves the path to inode id, then check if it's the same as the inode id * passed in. This is necessary to filter out zones in snapshots. * @param zoneId * @param zonePath * @return true if path resolve to the id, false if not. * @throws UnresolvedLinkException */ private boolean pathResolvesToId(final long zoneId, final String zonePath) throws UnresolvedLinkException, AccessControlException, ParentNotDirectoryException { assert dir.hasReadLock(); INode inode = dir.getInode(zoneId); if (inode == null) { return false; } INode lastINode = null; if (INode.isValidAbsolutePath(zonePath)) { INodesInPath iip = dir.getINodesInPath(zonePath, DirOp.READ_LINK); lastINode = iip.getLastINode(); } if (lastINode == null || lastINode.getId() != zoneId) { return false; } return true; }
@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(); } }
Preconditions.checkPositionIndex(groupEntryIndex, featureEntries.size(), "Invalid group entry index after binary-searching inode: " + inode.getFullPathName() + "(" + inode.getId() + ") " + "with featureEntries:" + featureEntries); FsAction groupPerm = featureEntries.get(groupEntryIndex).getPermission();
/** * Add create directory record to edit log */ public void logMkDir(String path, INode newNode) { PermissionStatus permissions = newNode.getPermissionStatus(); MkdirOp op = MkdirOp.getInstance(cache.get()) .setInodeId(newNode.getId()) .setPath(path) .setTimestamp(newNode.getModificationTime()) .setPermissionStatus(permissions); AclFeature f = newNode.getAclFeature(); if (f != null) { op.setAclEntries(AclStorage.readINodeLogicalAcl(newNode)); } XAttrFeature x = newNode.getXAttrFeature(); if (x != null) { op.setXAttrs(x.getXAttrs()); } logEdit(op); }