From d502abe94740b4af9434d678e7e4745aa3f010ba Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Mon, 13 Aug 2018 17:36:13 -0700 Subject: [PATCH] HDFS-13738. fsck -list-corruptfileblocks has infinite loop if user is not privileged. Contributed by Yuen-Kuei Hsueh. (cherry picked from commit 4023eeba05aefe48384e870da3c95bb3af474514) (cherry picked from commit 74d4fd975a1f67ae3e1b67554319e1f5e525ed6f) --- .../org/apache/hadoop/hdfs/tools/DFSck.java | 6 ++++++ .../hadoop/hdfs/server/namenode/TestFsck.java | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSck.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSck.java index 96fca2448eb..97aa360f82e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSck.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSck.java @@ -210,8 +210,14 @@ public class DFSck extends Configured implements Tool { allDone = true; break; } + if (line.startsWith("Access denied for user")) { + out.println("Failed to open path '" + dir + "': Permission denied"); + errCode = -1; + return errCode; + } if ((line.isEmpty()) || (line.startsWith("FSCK started by")) + || (line.startsWith("FSCK ended at")) || (line.startsWith("The filesystem under path"))) continue; numCorrupt++; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java index bb27d048d9a..2b5d7620d5c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java @@ -2488,4 +2488,22 @@ public class TestFsck { runFsck(cluster.getConfiguration(0), 0, true, "/"); } } + + @Test + public void testFsckNonPrivilegedListCorrupt() throws Exception { + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build(); + UserGroupInformation ugi = UserGroupInformation.createUserForTesting("systest", new String[]{""}); + ugi.doAs(new PrivilegedExceptionAction() { + @Override + public Void run() throws Exception { + String path = "/"; + String outStr = runFsck(conf, -1, true, path, "-list-corruptfileblocks"); + + assertFalse(outStr.contains("The list of corrupt files under path '" + path + "' are:")); + assertFalse(outStr.contains("The filesystem under path '" + path + "' has ")); + assertTrue(outStr.contains("Failed to open path '" + path + "': Permission denied")); + return null; + } + }); + } }