/** * Resolves the given path into inodes. Reserved paths are not handled and * permissions are not verified. Client supplied paths should be * resolved via {@link #resolvePath(FSPermissionChecker, String, DirOp)}. * This method should only be used by internal methods. * @return the {@link INodesInPath} containing all inodes in the path. * @throws UnresolvedLinkException * @throws ParentNotDirectoryException * @throws AccessControlException */ public INodesInPath getINodesInPath(String src, DirOp dirOp) throws UnresolvedLinkException, AccessControlException, ParentNotDirectoryException { return getINodesInPath(INode.getPathComponents(src), dirOp); }
long blocksize = 0; if (inode.isFile()) { final INodeFile fileNode = inode.asFile(); size = fileNode.computeFileSize(snapshot); replication = fileNode.getFileReplication(snapshot); blocksize = fileNode.getPreferredBlockSize(); } else if (inode.isSymlink()) { symlink = new Path( DFSUtilClient.bytes2String(inode.asSymlink().getSymlink())); inode.isDirectory(), replication, blocksize, inode.getModificationTime(snapshot), inode.getAccessTime(snapshot), inode.getFsPermission(snapshot), inode.getUserName(snapshot), inode.getGroupName(snapshot), symlink, new Path(iip.getPath()));
/** * Dump tree recursively. * @param prefix The prefix string that each line should print. */ @VisibleForTesting public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix, int snapshotId) { out.print(prefix); out.print(" "); final String name = getLocalName(); out.print(name.isEmpty()? "/": name); out.print(" ("); out.print(getObjectString()); out.print("), "); out.print(getParentString()); out.print(", " + getPermissionStatus(snapshotId)); }
public byte[][] getPathComponents() { int n = 0; for (INode inode = this; inode != null; inode = inode.getParent()) { n++; } byte[][] components = new byte[n][]; for (INode inode = this; inode != null; inode = inode.getParent()) { components[--n] = inode.getLocalNameBytes(); } return components; }
SnapshotCopy(INode inode) { this.name = inode.getLocalNameBytes(); this.permission = inode.getPermissionLong(); if (inode.getAclFeature() != null) { aclFeature = AclStorage.addAclFeature(inode.getAclFeature()); } else { aclFeature = null; } this.modificationTime = inode.getModificationTime(); this.accessTime = inode.getAccessTime(); this.xAttrFeature = inode.getXAttrFeature(); }
private void save(OutputStream out, INode n) throws IOException { if (n.isDirectory()) { save(out, n.asDirectory()); } else if (n.isFile()) { save(out, n.asFile()); } else if (n.isSymlink()) { save(out, n.asSymlink()); } }
/** copy constructor * * @param other Other node to be copied */ INode(INode other) { setLocalName(other.getLocalName()); this.parent = other.getParent(); setPermissionStatus(other.getPermissionStatus()); setModificationTime(other.getModificationTime()); setAccessTime(other.getAccessTime()); }
static void saveINode2Image(INode node, DataOutputStream out) throws IOException { byte[] name = node.getLocalNameBytes(); out.writeShort(name.length); out.write(name); FsPermission filePerm = TL_DATA.get().FILE_PERM; if (!node.isDirectory()) { // write file inode INodeFile fileINode = (INodeFile)node; out.writeShort(fileINode.getReplication()); } else { // write directory inode out.writeShort(0); // replication out.writeLong(node.getModificationTime()); out.writeLong(0); // access time out.writeLong(0); // preferred block size out.writeInt(-1); // # of blocks out.writeLong(node.getNsQuota()); out.writeLong(node.getDsQuota()); filePerm.fromShort(node.getFsPermissionShort()); PermissionStatus.write(out, node.getUserName(), node.getGroupName(), filePerm);
name = child.getLocalNameBytes(); if (node.isFile()) { final INodeFile fileNode = node.asFile(); size = fileNode.computeFileSize(snapshot); replication = fileNode.getFileReplication(snapshot); } else if (node.isDirectory()) { isSnapShottable = node.asDirectory().isSnapshottable(); int childrenNum = node.isDirectory() ? node.asDirectory().getChildrenNum(snapshot) : 0; node.isDirectory(), replication, blocksize, node.getModificationTime(snapshot), node.getAccessTime(snapshot), nodeAttrs.getFsPermission(), flags, nodeAttrs.getUserName(), nodeAttrs.getGroupName(), node.isSymlink() ? node.asSymlink().getSymlink() : null, name, node.getId(), childrenNum, feInfo,
int snapshotId) throws AclException, QuotaExceededException { assert newAcl.size() >= 3; FsPermission perm = inode.getFsPermission(); final FsPermission newPerm; if (!AclUtil.isMinimalAcl(newAcl)) { if (!defaultEntries.isEmpty() && !inode.isDirectory()) { throw new AclException( "Invalid ACL: only directories may have a default ACL. " + "Path: " + inode.getFullPathName()); if (inode.getAclFeature() != null) { inode.removeAclFeature(snapshotId); inode.addAclFeature(createAclFeature(accessEntries, defaultEntries), snapshotId); newPerm = createFsPermissionForExtendedAcl(accessEntries, perm); } else { if (inode.getAclFeature() != null) { inode.removeAclFeature(snapshotId); inode.setPermission(newPerm, snapshotId);
FsPermission modes, boolean checkQuota) throws QuotaExceededException { assert existing.getLastINode() != null && existing.getLastINode().isDirectory(); "File name \"" + inode.getLocalName() + "\" is reserved and cannot " + "be created. If this is during upgrade change the name of the " + "existing file or directory to another name before upgrading " + "to the new release."); final INodeDirectory parent = existing.getINode(pos - 1).asDirectory(); verifyMaxComponentLength(inode.getLocalNameBytes(), parentPath); verifyMaxDirItems(parent, parentPath); verifyINodeName(inode.getLocalNameBytes()); final QuotaCounts counts = inode.computeQuotaUsage(getBlockStoragePolicySuite()); updateCount(existing, pos, counts, checkQuota); boolean isRename = (inode.getParent() != null); final boolean added = parent.addChild(inode, true, existing.getLatestSnapshotId()); return INodesInPath.append(existing, inode, inode.getLocalNameBytes());
void testQuotaByStorageTypeWithFileCreateCase( String storagePolicy, StorageType storageType, short replication) throws Exception { final Path foo = new Path(dir, "foo"); Path createdFile1 = new Path(foo, "created_file1.data"); dfs.mkdirs(foo); // set storage policy on directory "foo" to storagePolicy dfs.setStoragePolicy(foo, storagePolicy); // set quota by storage type on directory "foo" dfs.setQuotaByStorageType(foo, storageType, BLOCKSIZE * 10); INode fnode = fsdir.getINode4Write(foo.toString()); assertTrue(fnode.isDirectory()); assertTrue(fnode.isQuotaSet()); // Create file of size 2 * BLOCKSIZE under directory "foo" long file1Len = BLOCKSIZE * 2 + BLOCKSIZE / 2; int bufLen = BLOCKSIZE / 16; DFSTestUtil.createFile(dfs, createdFile1, bufLen, file1Len, BLOCKSIZE, REPLICATION, seed); // Verify space consumed and remaining quota long storageTypeConsumed = fnode.asDirectory().getDirectoryWithQuotaFeature() .getSpaceConsumed().getTypeSpaces().get(storageType); assertEquals(file1Len * replication, storageTypeConsumed); }
INodeDirectory parent = child.getParent(); AclFeature parentAclFeature = parent.getAclFeature(); if (parentAclFeature == null || !(child.isFile() || child.isDirectory())) { return false; parentDefaultEntries.size()); FsPermission childPerm = child.getFsPermission(); List<AclEntry> defaultEntries = child.isDirectory() ? parentDefaultEntries : Collections.<AclEntry>emptyList(); if (!AclUtil.isMinimalAcl(accessEntries) || !defaultEntries.isEmpty()) { child.addAclFeature(createAclFeature(accessEntries, defaultEntries)); newPerm = createFsPermissionForExtendedAcl(accessEntries, childPerm); } else { child.setPermission(newPerm); return true;
INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); AclFeature f = inode.getAclFeature(); if (f == null) { return; FsPermission perm = inode.getFsPermission(); List<AclEntry> featureEntries = AclStorage.getEntriesFromAclFeature(f); if (featureEntries.get(0).getScope() == AclEntryScope.ACCESS) { 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(); FsPermission newPerm = new FsPermission(perm.getUserAction(), groupPerm, perm.getOtherAction(), perm.getStickyBit()); inode.setPermission(newPerm, snapshotId); inode.removeAclFeature(snapshotId);
previousNode.compareTo(d.getLocalNameBytes()); if (result == 0) { FSImage.LOG.error( "Name '" + d.getLocalName() + "' is repeated in the " + "'deleted' difflist of directory " + dir.getFullPathName() + ", INodeId=" + dir.getId()); if (d.isReference()) { refList.add(d.asReference()); db.addDeletedINodeRef(refList.size() - 1); } else { db.addDeletedINode(d.getId());
private int getSelfSnapshot() { INode referred = getReferredINode().asReference().getReferredINode(); int snapshot = Snapshot.NO_SNAPSHOT_ID; if (referred.isFile() && referred.asFile().isWithSnapshot()) { snapshot = referred.asFile().getDiffs().getPrior(lastSnapshotId); } else if (referred.isDirectory()) { DirectoryWithSnapshotFeature sf = referred.asDirectory() .getDirectoryWithSnapshotFeature(); if (sf != null) { snapshot = sf.getDiffs().getPrior(lastSnapshotId); } } return snapshot; } }
/** * 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); }
/** Is this inode in the latest snapshot? */ public final boolean isInLatestSnapshot(final int latestSnapshotId) { if (latestSnapshotId == Snapshot.CURRENT_STATE_ID || latestSnapshotId == Snapshot.NO_SNAPSHOT_ID) { return false; } // if parent is a reference node, parent must be a renamed node. We can // stop the check at the reference node. if (parent != null && parent.isReference()) { return true; } final INodeDirectory parentDir = getParent(); if (parentDir == null) { // root return true; } if (!parentDir.isInLatestSnapshot(latestSnapshotId)) { return false; } final INode child = parentDir.getChild(getLocalNameBytes(), latestSnapshotId); if (this == child) { return true; } return child != null && child.isReference() && this == child.asReference().getReferredINode(); }
inode = ((WithCount) inode).getParentRef(snapshotId); } else { INode parent = inode.getParentReference() != null ? inode .getParentReference() : inode.getParent(); if (parent != null && parent instanceof INodeDirectory) { int sid = parent.asDirectory().searchChild(inode); if (sid < snapshotId) { return null; ancestors.addFirst(inode.getLocalNameBytes());
static AclStatus getAclStatus( FSDirectory fsd, FSPermissionChecker pc, String src) throws IOException { checkAclsConfigFlag(fsd); fsd.readLock(); try { INodesInPath iip = fsd.resolvePath(pc, src, DirOp.READ); // There is no real inode for the path ending in ".snapshot", so return a // non-null, unpopulated AclStatus. This is similar to getFileInfo. if (iip.isDotSnapshotDir() && fsd.getINode4DotSnapshot(iip) != null) { return new AclStatus.Builder().owner("").group("").build(); } INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getPathSnapshotId(); List<AclEntry> acl = AclStorage.readINodeAcl(fsd.getAttributes(iip)); FsPermission fsPermission = inode.getFsPermission(snapshotId); return new AclStatus.Builder() .owner(inode.getUserName()).group(inode.getGroupName()) .stickyBit(fsPermission.getStickyBit()) .setPermission(fsPermission) .addEntries(acl).build(); } catch (AclException e){ throw new AclException(e.getMessage() + " Path: " + src, e); } finally { fsd.readUnlock(); } }