Author: umamahesh Date: Wed Jun 11 19:25:17 2014 New Revision: 1601992 URL: http://svn.apache.org/r1601992 Log: Merge HDFS-2006 HDFS XAttrs feature from Trunk to Branch-2
Added: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/XAttrCodec.java - copied unchanged from r1596575, hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/XAttrCodec.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/XAttrSetFlag.java - copied unchanged from r1596575, hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/XAttrSetFlag.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/XAttrCommands.java - copied unchanged from r1596575, hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/XAttrCommands.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestXAttrCommands.java - copied unchanged from r1596575, hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestXAttrCommands.java Modified: hadoop/common/branches/branch-2/hadoop-common-project/ (props changed) hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/ (props changed) hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/ (props changed) hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/docs/ (props changed) hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/ (props changed) hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/FsCommand.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/site/apt/FileSystemShell.apt.vm hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/core/ (props changed) hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystem.java Propchange: hadoop/common/branches/branch-2/hadoop-common-project/ ------------------------------------------------------------------------------ Merged /hadoop/common/trunk/hadoop-common-project:r1596575 Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/ ------------------------------------------------------------------------------ Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common:r1596575 Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt Wed Jun 11 19:25:17 2014 @@ -195,6 +195,24 @@ Release 2.5.0 - UNRELEASED HADOOP-10656. The password keystore file is not picked by LDAP group mapping (brandonli) + BREAKDOWN OF HADOOP-10514 SUBTASKS AND RELATED JIRAS + + HADOOP-10520. Extended attributes definition and FileSystem APIs for + extended attributes. (Yi Liu via wang) + + HADOOP-10546. Javadoc and other small fixes for extended attributes in + hadoop-common. (Charles Lamb via wang) + + HADOOP-10521. FsShell commands for extended attributes. (Yi Liu via wang) + + HADOOP-10548. Improve FsShell xattr error handling and other fixes. (Charles Lamb via umamahesh) + + HADOOP-10567. Shift XAttr value encoding code out for reuse. (Yi Liu via umamahesh) + + HADOOP-10621. Remove CRLF for xattr value base64 encoding for better display.(Yi Liu via umamahesh) + + HADOOP-10575. Small fixes for XAttrCommands and test. (Yi Liu via umamahesh) + Release 2.4.1 - UNRELEASED INCOMPATIBLE CHANGES Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/ ------------------------------------------------------------------------------ Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src:r1596575 Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/docs/ ------------------------------------------------------------------------------ Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/docs:r1596575 Merged /hadoop/common/branches/HDFS-2006/hadoop-common-project/hadoop-common/src/main/docs:r1588992-1596568 Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/ ------------------------------------------------------------------------------ Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java:r1596575 Merged /hadoop/common/branches/HDFS-2006/hadoop-common-project/hadoop-common/src/main/java:r1588992-1596568 Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java Wed Jun 11 19:25:17 2014 @@ -17,7 +17,6 @@ */ package org.apache.hadoop.fs; - import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Constructor; @@ -1039,6 +1038,163 @@ public abstract class AbstractFileSystem + " doesn't support getAclStatus"); } + /** + * Set an xattr of a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only set an xattr for the "user" namespace. + * The super user can set an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * The access permissions of an xattr in the "user" namespace are + * defined by the file and directory permission bits. + * An xattr can only be set when the logged-in user has the correct permissions. + * If the xattr exists, it will be replaced. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to modify + * @param name xattr name. + * @param value xattr value. + * @throws IOException + */ + public void setXAttr(Path path, String name, byte[] value) + throws IOException { + setXAttr(path, name, value, EnumSet.of(XAttrSetFlag.CREATE, + XAttrSetFlag.REPLACE)); + } + + /** + * Set an xattr of a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only set an xattr for the "user" namespace. + * The super user can set an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * The access permissions of an xattr in the "user" namespace are + * defined by the file and directory permission bits. + * An xattr can only be set when the logged-in user has the correct permissions. + * If the xattr exists, it will be replaced. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to modify + * @param name xattr name. + * @param value xattr value. + * @param flag xattr set flag + * @throws IOException + */ + public void setXAttr(Path path, String name, byte[] value, + EnumSet<XAttrSetFlag> flag) throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support setXAttr"); + } + + /** + * Get an xattr for a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only get an xattr for the "user" namespace. + * The super user can get an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * An xattr will only be returned when the logged-in user has the correct permissions. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to get extended attribute + * @param name xattr name. + * @return byte[] xattr value. + * @throws IOException + */ + public byte[] getXAttr(Path path, String name) throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support getXAttr"); + } + + /** + * Get all of the xattrs for a file or directory. + * Only those xattrs for which the logged-in user has permissions to view + * are returned. + * <p/> + * A regular user can only get xattrs for the "user" namespace. + * The super user can only get xattrs for "user" and "trusted" namespaces. + * The xattr of "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to get extended attributes + * @return Map<String, byte[]> describing the XAttrs of the file or directory + * @throws IOException + */ + public Map<String, byte[]> getXAttrs(Path path) throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support getXAttrs"); + } + + /** + * Get all of the xattrs for a file or directory. + * Only those xattrs for which the logged-in user has permissions to view + * are returned. + * <p/> + * A regular user can only get xattrs for the "user" namespace. + * The super user can only get xattrs for "user" and "trusted" namespaces. + * The xattr of "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to get extended attributes + * @param names XAttr names. + * @return Map<String, byte[]> describing the XAttrs of the file or directory + * @throws IOException + */ + public Map<String, byte[]> getXAttrs(Path path, List<String> names) + throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support getXAttrs"); + } + + /** + * Remove an xattr of a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only remove an xattr for the "user" namespace. + * The super user can remove an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * The access permissions of an xattr in the "user" namespace are + * defined by the file and directory permission bits. + * An xattr can only be set when the logged-in user has the correct permissions. + * If the xattr exists, it will be replaced. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to remove extended attribute + * @param name xattr name + * @throws IOException + */ + public void removeXAttr(Path path, String name) throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support removeXAttr"); + } + @Override //Object public int hashCode() { return myUri.hashCode(); Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java Wed Jun 11 19:25:17 2014 @@ -2308,4 +2308,194 @@ public final class FileContext { } }.resolve(this, absF); } + + /** + * Set an xattr of a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only set an xattr for the "user" namespace. + * The super user can set an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * The access permissions of an xattr in the "user" namespace are + * defined by the file and directory permission bits. + * An xattr can only be set when the logged-in user has the correct permissions. + * If the xattr exists, it will be replaced. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to modify + * @param name xattr name. + * @param value xattr value. + * @throws IOException + */ + public void setXAttr(Path path, String name, byte[] value) + throws IOException { + setXAttr(path, name, value, EnumSet.of(XAttrSetFlag.CREATE, + XAttrSetFlag.REPLACE)); + } + + /** + * Set an xattr of a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only set an xattr for the "user" namespace. + * The super user can set an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * The access permissions of an xattr in the "user" namespace are + * defined by the file and directory permission bits. + * An xattr can only be set when the logged-in user has the correct permissions. + * If the xattr exists, it will be replaced. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to modify + * @param name xattr name. + * @param value xattr value. + * @param flag xattr set flag + * @throws IOException + */ + public void setXAttr(Path path, final String name, final byte[] value, + final EnumSet<XAttrSetFlag> flag) throws IOException { + final Path absF = fixRelativePart(path); + new FSLinkResolver<Void>() { + @Override + public Void next(final AbstractFileSystem fs, final Path p) + throws IOException { + fs.setXAttr(p, name, value, flag); + return null; + } + }.resolve(this, absF); + } + + /** + * Get an xattr for a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * + * A regular user can only get an xattr for the "user" namespace. + * The super user can get an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * An xattr will only be returned when the logged-in user has the correct permissions. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to get extended attribute + * @param name xattr name. + * @return byte[] xattr value. + * @throws IOException + */ + public byte[] getXAttr(Path path, final String name) throws IOException { + final Path absF = fixRelativePart(path); + return new FSLinkResolver<byte[]>() { + @Override + public byte[] next(final AbstractFileSystem fs, final Path p) + throws IOException { + return fs.getXAttr(p, name); + } + }.resolve(this, absF); + } + + /** + * Get all of the xattrs for a file or directory. + * Only those xattrs for which the logged-in user has permissions to view + * are returned. + * <p/> + * A regular user can only get xattrs for the "user" namespace. + * The super user can only get xattrs for "user" and "trusted" namespaces. + * The xattr of "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to get extended attributes + * @return Map<String, byte[]> describing the XAttrs of the file or directory + * @throws IOException + */ + public Map<String, byte[]> getXAttrs(Path path) throws IOException { + final Path absF = fixRelativePart(path); + return new FSLinkResolver<Map<String, byte[]>>() { + @Override + public Map<String, byte[]> next(final AbstractFileSystem fs, final Path p) + throws IOException { + return fs.getXAttrs(p); + } + }.resolve(this, absF); + } + + /** + * Get all of the xattrs for a file or directory. + * Only those xattrs for which the logged-in user has permissions to view + * are returned. + * <p/> + * A regular user can only get xattrs for the "user" namespace. + * The super user can only get xattrs for "user" and "trusted" namespaces. + * The xattr of "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to get extended attributes + * @param names XAttr names. + * @return Map<String, byte[]> describing the XAttrs of the file or directory + * @throws IOException + */ + public Map<String, byte[]> getXAttrs(Path path, final List<String> names) + throws IOException { + final Path absF = fixRelativePart(path); + return new FSLinkResolver<Map<String, byte[]>>() { + @Override + public Map<String, byte[]> next(final AbstractFileSystem fs, final Path p) + throws IOException { + return fs.getXAttrs(p, names); + } + }.resolve(this, absF); + } + + /** + * Remove an xattr of a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only remove an xattr for the "user" namespace. + * The super user can remove an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * The access permissions of an xattr in the "user" namespace are + * defined by the file and directory permission bits. + * An xattr can only be set when the logged-in user has the correct permissions. + * If the xattr exists, it will be replaced. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to remove extended attribute + * @param name xattr name + * @throws IOException + */ + public void removeXAttr(Path path, final String name) throws IOException { + final Path absF = fixRelativePart(path); + new FSLinkResolver<Void>() { + @Override + public Void next(final AbstractFileSystem fs, final Path p) + throws IOException { + fs.removeXAttr(p, name); + return null; + } + }.resolve(this, absF); + } } Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java Wed Jun 11 19:25:17 2014 @@ -2363,6 +2363,164 @@ public abstract class FileSystem extends + " doesn't support getAclStatus"); } + /** + * Set an xattr of a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only set an xattr for the "user" namespace. + * The super user can set an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * The access permissions of an xattr in the "user" namespace are + * defined by the file and directory permission bits. + * An xattr can only be set when the logged-in user has the correct permissions. + * If the xattr exists, it will be replaced. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to modify + * @param name xattr name. + * @param value xattr value. + * @throws IOException + */ + public void setXAttr(Path path, String name, byte[] value) + throws IOException { + setXAttr(path, name, value, EnumSet.of(XAttrSetFlag.CREATE, + XAttrSetFlag.REPLACE)); + } + + /** + * Set an xattr of a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only set an xattr for the "user" namespace. + * The super user can set an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * The access permissions of an xattr in the "user" namespace are + * defined by the file and directory permission bits. + * An xattr can only be set when the logged-in user has the correct permissions. + * If the xattr exists, it will be replaced. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to modify + * @param name xattr name. + * @param value xattr value. + * @param flag xattr set flag + * @throws IOException + */ + public void setXAttr(Path path, String name, byte[] value, + EnumSet<XAttrSetFlag> flag) throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support setXAttr"); + } + + /** + * Get an xattr for a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * + * A regular user can only get an xattr for the "user" namespace. + * The super user can get an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * An xattr will only be returned when the logged-in user has the correct permissions. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to get extended attribute + * @param name xattr name. + * @return byte[] xattr value. + * @throws IOException + */ + public byte[] getXAttr(Path path, String name) throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support getXAttr"); + } + + /** + * Get all of the xattrs for a file or directory. + * Only those xattrs for which the logged-in user has permissions to view + * are returned. + * <p/> + * A regular user can only get xattrs for the "user" namespace. + * The super user can only get xattrs for "user" and "trusted" namespaces. + * The xattr of "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to get extended attributes + * @return Map<String, byte[]> describing the XAttrs of the file or directory + * @throws IOException + */ + public Map<String, byte[]> getXAttrs(Path path) throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support getXAttrs"); + } + + /** + * Get all of the xattrs for a file or directory. + * Only those xattrs for which the logged-in user has permissions to view + * are returned. + * <p/> + * A regular user can only get xattrs for the "user" namespace. + * The super user can only get xattrs for "user" and "trusted" namespaces. + * The xattr of "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to get extended attributes + * @param names XAttr names. + * @return Map<String, byte[]> describing the XAttrs of the file or directory + * @throws IOException + */ + public Map<String, byte[]> getXAttrs(Path path, List<String> names) + throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support getXAttrs"); + } + + /** + * Remove an xattr of a file or directory. + * The name must be prefixed with user/trusted/security/system and + * followed by ".". For example, "user.attr". + * <p/> + * A regular user can only remove an xattr for the "user" namespace. + * The super user can remove an xattr of either the "user" or "trusted" namespaces. + * The xattrs of the "security" and "system" namespaces are only used/exposed + * internally by/to the FS impl. + * <p/> + * The access permissions of an xattr in the "user" namespace are + * defined by the file and directory permission bits. + * An xattr can only be set when the logged-in user has the correct permissions. + * If the xattr exists, it will be replaced. + * <p/> + * @see <a href="http://en.wikipedia.org/wiki/Extended_file_attributes"> + * http://en.wikipedia.org/wiki/Extended_file_attributes</a> + * + * @param path Path to remove extended attribute + * @param name xattr name + * @throws IOException + */ + public void removeXAttr(Path path, String name) throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support removeXAttr"); + } + // making it volatile to be able to do a double checked locking private volatile static boolean FILE_SYSTEMS_LOADED = false; Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java Wed Jun 11 19:25:17 2014 @@ -23,6 +23,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.EnumSet; import java.util.List; +import java.util.Map; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; @@ -542,4 +543,37 @@ public class FilterFileSystem extends Fi public AclStatus getAclStatus(Path path) throws IOException { return fs.getAclStatus(path); } + + @Override + public void setXAttr(Path path, String name, byte[] value) + throws IOException { + fs.setXAttr(path, name, value); + } + + @Override + public void setXAttr(Path path, String name, byte[] value, + EnumSet<XAttrSetFlag> flag) throws IOException { + fs.setXAttr(path, name, value, flag); + } + + @Override + public byte[] getXAttr(Path path, String name) throws IOException { + return fs.getXAttr(path, name); + } + + @Override + public Map<String, byte[]> getXAttrs(Path path) throws IOException { + return fs.getXAttrs(path); + } + + @Override + public Map<String, byte[]> getXAttrs(Path path, List<String> names) + throws IOException { + return fs.getXAttrs(path, names); + } + + @Override + public void removeXAttr(Path path, String name) throws IOException { + fs.removeXAttr(path, name); + } } Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java Wed Jun 11 19:25:17 2014 @@ -22,6 +22,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.EnumSet; import java.util.List; +import java.util.Map; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; @@ -316,4 +317,37 @@ public abstract class FilterFs extends A public AclStatus getAclStatus(Path path) throws IOException { return myFs.getAclStatus(path); } + + @Override + public void setXAttr(Path path, String name, byte[] value) + throws IOException { + myFs.setXAttr(path, name, value); + } + + @Override + public void setXAttr(Path path, String name, byte[] value, + EnumSet<XAttrSetFlag> flag) throws IOException { + myFs.setXAttr(path, name, value, flag); + } + + @Override + public byte[] getXAttr(Path path, String name) throws IOException { + return myFs.getXAttr(path, name); + } + + @Override + public Map<String, byte[]> getXAttrs(Path path) throws IOException { + return myFs.getXAttrs(path); + } + + @Override + public Map<String, byte[]> getXAttrs(Path path, List<String> names) + throws IOException { + return myFs.getXAttrs(path, names); + } + + @Override + public void removeXAttr(Path path, String name) throws IOException { + myFs.removeXAttr(path, name); + } } Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/FsCommand.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/FsCommand.java?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/FsCommand.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/FsCommand.java Wed Jun 11 19:25:17 2014 @@ -59,6 +59,7 @@ abstract public class FsCommand extends factory.registerCommands(Test.class); factory.registerCommands(Touch.class); factory.registerCommands(SnapshotCommands.class); + factory.registerCommands(XAttrCommands.class); } protected FsCommand() {} Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java Wed Jun 11 19:25:17 2014 @@ -21,6 +21,7 @@ import java.io.IOException; import java.net.URI; import java.util.EnumSet; import java.util.List; +import java.util.Map; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; @@ -37,6 +38,7 @@ import org.apache.hadoop.fs.FilterFileSy import org.apache.hadoop.fs.FsServerDefaults; import org.apache.hadoop.fs.FsStatus; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.XAttrSetFlag; import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.permission.AclStatus; import org.apache.hadoop.fs.permission.FsPermission; @@ -314,6 +316,33 @@ class ChRootedFileSystem extends FilterF } @Override + public void setXAttr(Path path, String name, byte[] value, + EnumSet<XAttrSetFlag> flag) throws IOException { + super.setXAttr(fullPath(path), name, value, flag); + } + + @Override + public byte[] getXAttr(Path path, String name) throws IOException { + return super.getXAttr(fullPath(path), name); + } + + @Override + public Map<String, byte[]> getXAttrs(Path path) throws IOException { + return super.getXAttrs(fullPath(path)); + } + + @Override + public Map<String, byte[]> getXAttrs(Path path, List<String> names) + throws IOException { + return super.getXAttrs(fullPath(path), names); + } + + @Override + public void removeXAttr(Path path, String name) throws IOException { + super.removeXAttr(fullPath(path), name); + } + + @Override public Path resolvePath(final Path p) throws IOException { return super.resolvePath(fullPath(p)); } Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java Wed Jun 11 19:25:17 2014 @@ -27,6 +27,7 @@ import java.util.Arrays; import java.util.EnumSet; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.Map.Entry; @@ -46,6 +47,7 @@ import org.apache.hadoop.fs.FsConstants; import org.apache.hadoop.fs.FsServerDefaults; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.UnsupportedFileSystemException; +import org.apache.hadoop.fs.XAttrSetFlag; import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.permission.AclStatus; import org.apache.hadoop.fs.permission.FsPermission; @@ -520,6 +522,43 @@ public class ViewFileSystem extends File } @Override + public void setXAttr(Path path, String name, byte[] value, + EnumSet<XAttrSetFlag> flag) throws IOException { + InodeTree.ResolveResult<FileSystem> res = + fsState.resolve(getUriPath(path), true); + res.targetFileSystem.setXAttr(res.remainingPath, name, value, flag); + } + + @Override + public byte[] getXAttr(Path path, String name) throws IOException { + InodeTree.ResolveResult<FileSystem> res = + fsState.resolve(getUriPath(path), true); + return res.targetFileSystem.getXAttr(res.remainingPath, name); + } + + @Override + public Map<String, byte[]> getXAttrs(Path path) throws IOException { + InodeTree.ResolveResult<FileSystem> res = + fsState.resolve(getUriPath(path), true); + return res.targetFileSystem.getXAttrs(res.remainingPath); + } + + @Override + public Map<String, byte[]> getXAttrs(Path path, List<String> names) + throws IOException { + InodeTree.ResolveResult<FileSystem> res = + fsState.resolve(getUriPath(path), true); + return res.targetFileSystem.getXAttrs(res.remainingPath, names); + } + + @Override + public void removeXAttr(Path path, String name) throws IOException { + InodeTree.ResolveResult<FileSystem> res = fsState.resolve(getUriPath(path), + true); + res.targetFileSystem.removeXAttr(res.remainingPath, name); + } + + @Override public void setVerifyChecksum(final boolean verifyChecksum) { List<InodeTree.MountPoint<FileSystem>> mountPoints = fsState.getMountPoints(); Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/site/apt/FileSystemShell.apt.vm URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/site/apt/FileSystemShell.apt.vm?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/site/apt/FileSystemShell.apt.vm (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/site/apt/FileSystemShell.apt.vm Wed Jun 11 19:25:17 2014 @@ -254,6 +254,35 @@ getfacl Returns 0 on success and non-zero on error. +getfattr + + Usage: <<<hdfs dfs -getfattr [-R] {-n name | -d} [-e en] <path> >>> + + Displays the extended attribute names and values (if any) for a file or + directory. + + Options: + + * -R: Recursively list the attributes for all files and directories. + + * -n name: Dump the named extended attribute value. + + * -d: Dump all extended attribute values associated with pathname. + + * -e <encoding>: Encode values after retrieving them. Valid encodings are "text", "hex", and "base64". Values encoded as text strings are enclosed in double quotes ("), and values encoded as hexadecimal and base64 are prefixed with 0x and 0s, respectively. + + * <path>: The file or directory. + + Examples: + + * <<<hdfs dfs -getfattr -d /file>>> + + * <<<hdfs dfs -getfattr -R -n user.myAttr /dir>>> + + Exit Code: + + Returns 0 on success and non-zero on error. + getmerge Usage: <<<hdfs dfs -getmerge <src> <localdst> [addnl]>>> @@ -450,6 +479,36 @@ setfacl Returns 0 on success and non-zero on error. +setfattr + + Usage: <<<hdfs dfs -setfattr {-n name [-v value] | -x name} <path> >>> + + Sets an extended attribute name and value for a file or directory. + + Options: + + * -b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits. + + * -n name: The extended attribute name. + + * -v value: The extended attribute value. There are three different encoding methods for the value. If the argument is enclosed in double quotes, then the value is the string inside the quotes. If the argument is prefixed with 0x or 0X, then it is taken as a hexadecimal number. If the argument begins with 0s or 0S, then it is taken as a base64 encoding. + + * -x name: Remove the extended attribute. + + * <path>: The file or directory. + + Examples: + + * <<<hdfs dfs -setfattr -n user.myAttr -v myValue /file>>> + + * <<<hdfs dfs -setfattr -n user.noValue /file>>> + + * <<<hdfs dfs -setfattr -x user.myAttr /file>>> + + Exit Code: + + Returns 0 on success and non-zero on error. + setrep Usage: <<<hdfs dfs -setrep [-R] [-w] <numReplicas> <path> >>> Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/core/ ------------------------------------------------------------------------------ Merged /hadoop/common/branches/HDFS-2006/hadoop-common-project/hadoop-common/src/test/core:r1588992-1596568 Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/core:r1596575 Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystem.java?rev=1601992&r1=1601991&r2=1601992&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystem.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystem.java Wed Jun 11 19:25:17 2014 @@ -36,6 +36,7 @@ import java.lang.reflect.Modifier; import java.util.EnumSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import static org.apache.hadoop.fs.Options.ChecksumOpt; import static org.apache.hadoop.fs.Options.CreateOpts; @@ -182,6 +183,21 @@ public class TestHarFileSystem { public void setAcl(Path path, List<AclEntry> aclSpec) throws IOException; + public void setXAttr(Path path, String name, byte[] value) + throws IOException; + + public void setXAttr(Path path, String name, byte[] value, + EnumSet<XAttrSetFlag> flag) throws IOException; + + public byte[] getXAttr(Path path, String name) throws IOException; + + public Map<String, byte[]> getXAttrs(Path path) throws IOException; + + public Map<String, byte[]> getXAttrs(Path path, List<String> names) + throws IOException; + + public void removeXAttr(Path path, String name) throws IOException; + public AclStatus getAclStatus(Path path) throws IOException; }