private static void checkSimpleTraverse(INodesInPath iip) throws UnresolvedPathException, ParentNotDirectoryException { byte[][] components = iip.getPathComponents(); for (int i=0; i < iip.length() - 1; i++) { INode inode = iip.getINode(i); if (inode == null) { break; } checkIsDirectory(inode, components, i); } }
private static ZoneEncryptionInfoProto getZoneEncryptionInfoProto( final INodesInPath iip) throws IOException { final XAttr fileXAttr = FSDirXAttrOp.unprotectedGetXAttrByPrefixedName( iip.getLastINode(), iip.getPathSnapshotId(), CRYPTO_XATTR_ENCRYPTION_ZONE); if (fileXAttr == null) { throw new IOException( "Could not find reencryption XAttr for file " + iip.getPath()); } try { return ZoneEncryptionInfoProto.parseFrom(fileXAttr.getValue()); } catch (InvalidProtocolBufferException e) { throw new IOException( "Could not parse file encryption info for " + "inode " + iip .getPath(), e); } }
/** * Remove the last inode in the path from the namespace. * Note: the caller needs to update the ancestors' quota count. * * @return -1 for failing to remove; * 0 for removing a reference whose referred inode has other * reference nodes; * 1 otherwise. */ @VisibleForTesting public long removeLastINode(final INodesInPath iip) { final int latestSnapshot = iip.getLatestSnapshotId(); final INode last = iip.getLastINode(); final INodeDirectory parent = iip.getINode(-2).asDirectory(); if (!parent.removeChild(last, latestSnapshot)) { return -1; } return (!last.isInLatestSnapshot(latestSnapshot) && INodeReference.tryRemoveReference(last) > 0) ? 0 : 1; }
/** * Construct {@link INodesInPath} from {@link INode}. * * @param inode to construct from * @return INodesInPath */ static INodesInPath fromINode(INode inode) { INode[] inodes = getINodes(inode); byte[][] paths = getPaths(inodes); return new INodesInPath(inodes, paths); }
private boolean isDescendant(final INodesInPath ancestorDirIIP) { int ancestorDirINodesLength = ancestorDirIIP.length(); int myParentINodesLength = length() - 1; if (myParentINodesLength < ancestorDirINodesLength) { return false; } int index = 0; while (index < ancestorDirINodesLength) { if (inodes[index] != ancestorDirIIP.getINode(index)) { return false; } index++; } return true; }
static INode resolveLastINode(INodesInPath iip) throws FileNotFoundException { INode inode = iip.getLastINode(); if (inode == null) { throw new FileNotFoundException("cannot find " + iip.getPath()); } return inode; }
if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("DIR* FSNamesystem.concat to " + targetIIP.getPath()); final INodeFile trgInode = targetIIP.getLastINode().asFile(); QuotaCounts deltas = computeQuotaDeltas(fsd, trgInode, srcList); verifyQuota(fsd, targetIIP, deltas); trgInode.recordModification(targetIIP.getLatestSnapshotId()); INodeDirectory trgParent = targetIIP.getINode(-2).asDirectory(); trgInode.concatBlocks(srcList, fsd.getBlockManager()); targetIIP.getLatestSnapshotId()); fsd.getINodeMap().remove(nodeToRemove); count++; trgInode.setModificationTime(timestamp, targetIIP.getLatestSnapshotId()); trgParent.updateModificationTime(timestamp, targetIIP.getLatestSnapshotId()); FSDirectory.unprotectedUpdateCount(targetIIP, targetIIP.length() - 1, deltas);
INodesInPath nodesInPath = INodesInPath.resolve(fsdir.rootDir, components, false); assertEquals(nodesInPath.length(), components.length); nodesInPath.getINode(components.length - 1) != null); assertEquals(nodesInPath.getINode(components.length - 1).getFullPathName(), file1.toString()); assertEquals(nodesInPath.getINode(components.length - 2).getFullPathName(), sub1.toString()); assertEquals(nodesInPath.getINode(components.length - 3).getFullPathName(), dir.toString()); assertEquals(Path.SEPARATOR, nodesInPath.getPath(0)); assertEquals(dir.toString(), nodesInPath.getPath(1)); assertEquals(sub1.toString(), nodesInPath.getPath(2)); assertEquals(file1.toString(), nodesInPath.getPath(3)); nodesInPath = INodesInPath.resolve(fsdir.rootDir, components, false); assertEquals(nodesInPath.length(), components.length); assertSnapshot(nodesInPath, false, null, -1); assertEquals(nodesInPath.getLastINode().getFullPathName(), file1.toString());
/** * Extend a given INodesInPath with a child INode. The child INode will be * appended to the end of the new INodesInPath. */ public static INodesInPath append(INodesInPath iip, INode child, byte[] childName) { Preconditions.checkArgument(iip.length() > 0); Preconditions.checkArgument(iip.getLastINode() != null && iip .getLastINode().isDirectory()); INode[] inodes = new INode[iip.length() + 1]; System.arraycopy(iip.inodes, 0, inodes, 0, inodes.length - 1); inodes[inodes.length - 1] = child; byte[][] path = new byte[iip.path.length + 1][]; System.arraycopy(iip.path, 0, path, 0, path.length - 1); path[path.length - 1] = childName; return new INodesInPath(inodes, path, iip.isRaw, iip.isSnapshot, iip.snapshotId); }
private static INodesInPath dstForRenameTo( INodesInPath srcIIP, INodesInPath dstIIP) throws IOException { INode dstINode = dstIIP.getLastINode(); if (dstINode != null && dstINode.isDirectory()) { byte[] childName = srcIIP.getLastLocalName(); // new dest might exist so look it up. INode childINode = dstINode.asDirectory().getChild( childName, dstIIP.getPathSnapshotId()); dstIIP = INodesInPath.append(dstIIP, childINode, childName); } return dstIIP; }
try { final INodesInPath iip = fsd.resolvePath(pc, src, DirOp.READ); src = iip.getPath(); final INodeFile inode = INodeFile.valueOf(iip.getLastINode(), src); if (fsd.isPermissionEnabled()) { fsd.checkPathAccess(pc, iip, FsAction.READ); final long fileSize = iip.isSnapshot() ? inode.computeFileSize(iip.getPathSnapshotId()) : inode.computeFileSizeNotIncludingLastUcBlock(); if (iip.isSnapshot()) { inode.getBlocks(iip.getPathSnapshotId()), fileSize, isUc, offset, length, needBlockToken, iip.isSnapshot(), feInfo, ecPolicy); && !iip.isSnapshot() && now > inode.getAccessTime() + fsd.getAccessTimePrecision(); return new GetBlockLocationsResult(updateAccessTime, blocks);
int snapshotID = iip.getPathSnapshotId(); for (int i = iip.length() - 1; i >= 0; i--) { final INode inode = iip.getINode(i); if (inode == null || !inode.isDirectory()) { } catch (InvalidProtocolBufferException e) { throw new IOException("Could not parse encryption zone for inode " + iip.getPath(), e);
static void assertSnapshot(INodesInPath inodesInPath, boolean isSnapshot, final Snapshot snapshot, int index) { assertEquals(isSnapshot, inodesInPath.isSnapshot()); assertEquals(Snapshot.getSnapshotId(isSnapshot ? snapshot : null), inodesInPath.getPathSnapshotId()); if (!isSnapshot) { assertEquals(Snapshot.getSnapshotId(snapshot), inodesInPath.getLatestSnapshotId()); } if (isSnapshot && index >= 0) { assertEquals(Snapshot.Root.class, inodesInPath.getINode(index).getClass()); } }
final int snapshotId = inodesInPath.getPathSnapshotId(); final INode[] inodes = inodesInPath.getINodesArray(); final INodeAttributes[] inodeAttrs = new INodeAttributes[inodes.length]; final byte[][] components = inodesInPath.getPathComponents(); for (int i = 0; i < inodes.length && inodes[i] != null; i++) { inodeAttrs[i] = getINodeAttrs(components, i, inodes[i], snapshotId); String path = inodesInPath.getPath(); int ancestorIndex = inodes.length - 2;
private static boolean deleteAllowed(final INodesInPath iip) { if (iip.length() < 1 || iip.getLastINode() == null) { if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug( "DIR* FSDirectory.unprotectedDelete: failed to remove " + iip.getPath() + " because it does not exist"); } return false; } else if (iip.length() == 1) { // src is the root NameNode.stateChangeLog.warn( "DIR* FSDirectory.unprotectedDelete: failed to remove " + iip.getPath() + " because the root is not allowed to be deleted"); return false; } return true; }
boolean removeSrc4OldRename() { final long removedSrc = fsd.removeLastINode(srcIIP); if (removedSrc == -1) { NameNode.stateChangeLog.warn("DIR* FSDirRenameOp.unprotectedRenameTo: " + "failed to rename " + srcIIP.getPath() + " to " + dstIIP.getPath() + " because the source can not be removed"); return false; } else { // update the quota count if necessary fsd.updateCountForDelete(srcChild, srcIIP); srcIIP = INodesInPath.replace(srcIIP, srcIIP.length() - 1, null); return true; } }
byte[] startAfter, boolean needLocation, boolean includeStoragePolicy) throws IOException { if (FSDirectory.isExactReservedName(iip.getPathComponents())) { return getReservedListing(fsd); if (iip.isDotSnapshotDir()) { return getSnapshotsListing(fsd, iip, startAfter); final int snapshot = iip.getPathSnapshotId(); final INode targetNode = iip.getLastINode(); if (targetNode == null) { return null;
/** * Replace an inode of the given INodesInPath in the given position. We do a * deep copy of the INode array. * @param pos the position of the replacement * @param inode the new inode * @return a new INodesInPath instance */ public static INodesInPath replace(INodesInPath iip, int pos, INode inode) { Preconditions.checkArgument(iip.length() > 0 && pos > 0 // no for root && pos < iip.length()); if (iip.getINode(pos) == null) { Preconditions.checkState(iip.getINode(pos - 1) != null); } INode[] inodes = new INode[iip.inodes.length]; System.arraycopy(iip.inodes, 0, inodes, 0, inodes.length); inodes[pos] = inode; return new INodesInPath(inodes, iip.path, iip.isRaw, iip.isSnapshot, iip.snapshotId); }
INodesInPath srcIIP, INodesInPath dstIIP, boolean logRetryCache) throws IOException { String src = srcIIP.getPath(); String dst = dstIIP.getPath(); dstIIP = INodesInPath.append(dstIIP, null, srcIIP.getLastLocalName()); final String actualDst = dstIIP.getPath(); if (fsd.isPermissionEnabled()) {
if (iip.isRaw() || !fsd.ezManager.hasCreatedEncryptionZone() || !iip.getLastINode().isFile()) { return null; iip.getLastINode(), iip.getPathSnapshotId(), CRYPTO_XATTR_FILE_ENCRYPTION_INFO); if (fileXAttr == null) { NameNode.LOG.warn("Could not find encryption XAttr for file " + iip.getPath() + " in encryption zone " + encryptionZone.getPath()); return null; } catch (InvalidProtocolBufferException e) { throw new IOException("Could not parse file encryption info for " + "inode " + iip.getPath(), e);