Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E55A56BE9 for ; Tue, 19 Jul 2011 23:02:13 +0000 (UTC) Received: (qmail 84202 invoked by uid 500); 19 Jul 2011 23:02:13 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 84173 invoked by uid 500); 19 Jul 2011 23:02:13 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 84166 invoked by uid 99); 19 Jul 2011 23:02:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jul 2011 23:02:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jul 2011 23:02:07 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CB79C2388897 for ; Tue, 19 Jul 2011 23:01:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1148579 - in /hadoop/common/branches/branch-0.20-security: ./ src/core/org/apache/hadoop/fs/ src/core/org/apache/hadoop/io/nativeio/ src/native/ src/native/src/org/apache/hadoop/io/nativeio/ src/test/org/apache/hadoop/io/nativeio/ Date: Tue, 19 Jul 2011 23:01:46 -0000 To: common-commits@hadoop.apache.org From: mattf@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110719230146.CB79C2388897@eris.apache.org> Author: mattf Date: Tue Jul 19 23:01:45 2011 New Revision: 1148579 URL: http://svn.apache.org/viewvc?rev=1148579&view=rev Log: HADOOP-7432. Back-port HADOOP-7110 to 0.20-security: Implement chmod in NativeIO library. Contributed by Sherry Chen. Modified: hadoop/common/branches/branch-0.20-security/CHANGES.txt hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/io/nativeio/NativeIO.java hadoop/common/branches/branch-0.20-security/src/native/config.h.in hadoop/common/branches/branch-0.20-security/src/native/src/org/apache/hadoop/io/nativeio/NativeIO.c hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/io/nativeio/TestNativeIO.java Modified: hadoop/common/branches/branch-0.20-security/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/CHANGES.txt?rev=1148579&r1=1148578&r2=1148579&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20-security/CHANGES.txt (original) +++ hadoop/common/branches/branch-0.20-security/CHANGES.txt Tue Jul 19 23:01:45 2011 @@ -20,6 +20,9 @@ Release 0.20.205.0 - unreleased HDFS-1836. Thousand of CLOSE_WAIT socket. Contributed by Todd Lipcon, ported to security branch by Bharath Mundlapudi. (via mattf) + HADOOP-7432. Back-port HADOOP-7110 to 0.20-security: Implement chmod + in NativeIO library. (Sherry Chen via mattf) + Release 0.20.204.0 - unreleased NEW FEATURES Modified: hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java?rev=1148579&r1=1148578&r2=1148579&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java (original) +++ hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java Tue Jul 19 23:01:45 2011 @@ -26,6 +26,7 @@ import java.util.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.permission.*; +import org.apache.hadoop.io.nativeio.NativeIO; import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.Shell; @@ -529,8 +530,13 @@ public class RawLocalFileSystem extends private void execSetPermission(File f, FsPermission permission) throws IOException { - execCommand(f, Shell.SET_PERMISSION_COMMAND, - String.format("%04o", permission.toShort())); + if (NativeIO.isAvailable()) { + NativeIO.chmod(f.getCanonicalPath(), + permission.toShort()); + } else { + execCommand(f, Shell.SET_PERMISSION_COMMAND, + String.format("%04o", permission.toShort())); + } } private static String execCommand(File f, String... cmd) throws IOException { Modified: hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/io/nativeio/NativeIO.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/io/nativeio/NativeIO.java?rev=1148579&r1=1148578&r2=1148579&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/io/nativeio/NativeIO.java (original) +++ hadoop/common/branches/branch-0.20-security/src/core/org/apache/hadoop/io/nativeio/NativeIO.java Tue Jul 19 23:01:45 2011 @@ -79,11 +79,13 @@ public class NativeIO { //TODO: fstat is an old implementation. Doesn't use the cache. This should be //changed to use the cache. public static native Stat fstat(FileDescriptor fd) throws IOException; + private static native long getUIDforFDOwnerforOwner(FileDescriptor fd) throws IOException; private static native String getUserName(long uid) throws IOException; /** Initialize the JNI method ID and class ID cache */ private static native void initNative(); - + /** Wrapper around chmod(2) */ + public static native void chmod(String path, int mode) throws IOException; private static class CachedUid { final long timestamp; final String username; Modified: hadoop/common/branches/branch-0.20-security/src/native/config.h.in URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/native/config.h.in?rev=1148579&r1=1148578&r2=1148579&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20-security/src/native/config.h.in (original) +++ hadoop/common/branches/branch-0.20-security/src/native/config.h.in Tue Jul 19 23:01:45 2011 @@ -82,6 +82,9 @@ /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME +/* Define to the home page for this package. */ +#undef PACKAGE_URL + /* Define to the version of this package. */ #undef PACKAGE_VERSION Modified: hadoop/common/branches/branch-0.20-security/src/native/src/org/apache/hadoop/io/nativeio/NativeIO.c URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/native/src/org/apache/hadoop/io/nativeio/NativeIO.c?rev=1148579&r1=1148578&r2=1148579&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20-security/src/native/src/org/apache/hadoop/io/nativeio/NativeIO.c (original) +++ hadoop/common/branches/branch-0.20-security/src/native/src/org/apache/hadoop/io/nativeio/NativeIO.c Tue Jul 19 23:01:45 2011 @@ -266,6 +266,24 @@ cleanup: return jstr_username; } +/** + * public static native void chmod(String path, int mode) throws IOException; + */ +JNIEXPORT void JNICALL +Java_org_apache_hadoop_io_nativeio_NativeIO_chmod( + JNIEnv *env, jclass clazz, jstring j_path, + jint mode) +{ + const char *path = (*env)->GetStringUTFChars(env, j_path, NULL); + if (path == NULL) return; // JVM throws Exception for us + + if (chmod(path, mode) != 0) { + throw_ioe(env, errno); + } + + (*env)->ReleaseStringUTFChars(env, j_path, path); +} + /* * Throw a java.IO.IOException, generating the message from errno. */ Modified: hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/io/nativeio/TestNativeIO.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/io/nativeio/TestNativeIO.java?rev=1148579&r1=1148578&r2=1148579&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/io/nativeio/TestNativeIO.java (original) +++ hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/io/nativeio/TestNativeIO.java Tue Jul 19 23:01:45 2011 @@ -28,7 +28,11 @@ import static org.junit.Assert.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.util.NativeCodeLoader; public class TestNativeIO { @@ -136,4 +140,34 @@ public class TestNativeIO { } } + /** + * Test basic chmod operation + */ + @Test + public void testChmod() throws Exception { + try { + NativeIO.chmod("/this/file/doesnt/exist", 777); + fail("Chmod of non-existent file didn't fail"); + } catch (NativeIOException nioe) { + assertEquals(Errno.ENOENT, nioe.getErrno()); + } + + File toChmod = new File(TEST_DIR, "testChmod"); + assertTrue("Create test subject", + toChmod.exists() || toChmod.mkdir()); + NativeIO.chmod(toChmod.getAbsolutePath(), 0777); + assertPermissions(toChmod, 0777); + NativeIO.chmod(toChmod.getAbsolutePath(), 0000); + assertPermissions(toChmod, 0000); + NativeIO.chmod(toChmod.getAbsolutePath(), 0644); + assertPermissions(toChmod, 0644); + } + + private void assertPermissions(File f, int expected) throws IOException { + FileSystem localfs = FileSystem.getLocal(new Configuration()); + FsPermission perms = localfs.getFileStatus( + new Path(f.getAbsolutePath())).getPermission(); + assertEquals(expected, perms.toShort()); + } + }