HDFS-8091: ACLStatus and XAttributes should be presented to INodeAttributesProvider before returning to client (asuresh)

This commit is contained in:
Arun Suresh 2015-04-09 12:28:44 -07:00
parent 61dc2ea3fe
commit 922b7ed21d
6 changed files with 50 additions and 12 deletions

View File

@ -153,6 +153,9 @@ Trunk (Unreleased)
BUG FIXES BUG FIXES
HDFS-8091: ACLStatus and XAttributes should be presented to INodeAttributesProvider
before returning to client (asuresh)
HADOOP-9635 Fix potential Stack Overflow in DomainSocket.c (V. Karthik Kumar HADOOP-9635 Fix potential Stack Overflow in DomainSocket.c (V. Karthik Kumar
via cmccabe) via cmccabe)

View File

@ -162,6 +162,17 @@ public final class AclStorage {
return getEntriesFromAclFeature(f); return getEntriesFromAclFeature(f);
} }
/**
* Reads the existing extended ACL entries of an INodeAttribute object.
*
* @param inodeAttr INode to read
* @return List<AclEntry> containing extended inode ACL entries
*/
public static List<AclEntry> readINodeAcl(INodeAttributes inodeAttr) {
AclFeature f = inodeAttr.getAclFeature();
return getEntriesFromAclFeature(f);
}
/** /**
* Build list of AclEntries from the AclFeature * Build list of AclEntries from the AclFeature
* @param aclFeature AclFeature * @param aclFeature AclFeature

View File

@ -172,7 +172,8 @@ class FSDirAclOp {
} }
INode inode = FSDirectory.resolveLastINode(iip); INode inode = FSDirectory.resolveLastINode(iip);
int snapshotId = iip.getPathSnapshotId(); int snapshotId = iip.getPathSnapshotId();
List<AclEntry> acl = AclStorage.readINodeAcl(inode, snapshotId); List<AclEntry> acl = AclStorage.readINodeAcl(fsd.getAttributes(src,
inode.getLocalNameBytes(), inode, snapshotId));
FsPermission fsPermission = inode.getFsPermission(snapshotId); FsPermission fsPermission = inode.getFsPermission(snapshotId);
return new AclStatus.Builder() return new AclStatus.Builder()
.owner(inode.getUserName()).group(inode.getGroupName()) .owner(inode.getUserName()).group(inode.getGroupName())

View File

@ -451,7 +451,8 @@ class FSDirXAttrOp {
INodesInPath iip = fsd.getINodesInPath(srcs, true); INodesInPath iip = fsd.getINodesInPath(srcs, true);
INode inode = FSDirectory.resolveLastINode(iip); INode inode = FSDirectory.resolveLastINode(iip);
int snapshotId = iip.getPathSnapshotId(); int snapshotId = iip.getPathSnapshotId();
return XAttrStorage.readINodeXAttrs(inode, snapshotId); return XAttrStorage.readINodeXAttrs(fsd.getAttributes(src,
inode.getLocalNameBytes(), inode, snapshotId));
} finally { } finally {
fsd.readUnlock(); fsd.readUnlock();
} }

View File

@ -57,11 +57,11 @@ public class XAttrStorage {
* <p/> * <p/>
* Must be called while holding the FSDirectory read lock. * Must be called while holding the FSDirectory read lock.
* *
* @param inode INode to read. * @param inodeAttr INodeAttributes to read.
* @return List<XAttr> <code>XAttr</code> list. * @return List<XAttr> <code>XAttr</code> list.
*/ */
public static List<XAttr> readINodeXAttrs(INode inode) { public static List<XAttr> readINodeXAttrs(INodeAttributes inodeAttr) {
XAttrFeature f = inode.getXAttrFeature(); XAttrFeature f = inodeAttr.getXAttrFeature();
return f == null ? ImmutableList.<XAttr> of() : f.getXAttrs(); return f == null ? ImmutableList.<XAttr> of() : f.getXAttrs();
} }

View File

@ -20,16 +20,16 @@ package org.apache.hadoop.hdfs.server.namenode;
import java.io.IOException; import java.io.IOException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import com.google.common.collect.ImmutableList;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.XAttr;
import org.apache.hadoop.fs.permission.AclEntryType; import org.apache.hadoop.fs.permission.*;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
@ -131,7 +131,17 @@ public class TestINodeAttributeProvider {
@Override @Override
public XAttrFeature getXAttrFeature() { public XAttrFeature getXAttrFeature() {
return (useDefault) ? inode.getXAttrFeature() : null; XAttrFeature x;
if (useDefault) {
x = inode.getXAttrFeature();
} else {
x = new XAttrFeature(ImmutableList.copyOf(
Lists.newArrayList(
new XAttr.Builder().setName("test")
.setValue(new byte[] {1, 2})
.build())));
}
return x;
} }
@Override @Override
@ -218,12 +228,24 @@ public class TestINodeAttributeProvider {
FileStatus status = fs.getFileStatus(new Path("/user/xxx")); FileStatus status = fs.getFileStatus(new Path("/user/xxx"));
Assert.assertEquals(System.getProperty("user.name"), status.getOwner()); Assert.assertEquals(System.getProperty("user.name"), status.getOwner());
Assert.assertEquals("supergroup", status.getGroup()); Assert.assertEquals("supergroup", status.getGroup());
Assert.assertEquals(new FsPermission((short)0755), status.getPermission()); Assert.assertEquals(new FsPermission((short) 0755), status.getPermission());
fs.mkdirs(new Path("/user/authz")); fs.mkdirs(new Path("/user/authz"));
status = fs.getFileStatus(new Path("/user/authz")); Path p = new Path("/user/authz");
status = fs.getFileStatus(p);
Assert.assertEquals("foo", status.getOwner()); Assert.assertEquals("foo", status.getOwner());
Assert.assertEquals("bar", status.getGroup()); Assert.assertEquals("bar", status.getGroup());
Assert.assertEquals(new FsPermission((short) 0770), status.getPermission()); Assert.assertEquals(new FsPermission((short) 0770), status.getPermission());
AclStatus aclStatus = fs.getAclStatus(p);
Assert.assertEquals(1, aclStatus.getEntries().size());
Assert.assertEquals(AclEntryType.GROUP, aclStatus.getEntries().get(0)
.getType());
Assert.assertEquals("xxx", aclStatus.getEntries().get(0)
.getName());
Assert.assertEquals(FsAction.ALL, aclStatus.getEntries().get(0)
.getPermission());
Map<String, byte[]> xAttrs = fs.getXAttrs(p);
Assert.assertTrue(xAttrs.containsKey("user.test"));
Assert.assertEquals(2, xAttrs.get("user.test").length);
} }
} }