From 4d4f5325bde5d789916bd481f2a7763e0f41fce7 Mon Sep 17 00:00:00 2001 From: Ayush Saxena Date: Tue, 22 Oct 2019 18:44:22 +0530 Subject: [PATCH] HDFS-14915. Move Superuser Check Before Taking Lock For Encryption API. Contributed by Ayush Saxena. --- .../apache/hadoop/hdfs/server/namenode/FSNamesystem.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index a091d194d0e..0c6ad221a10 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -7311,11 +7311,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, Metadata metadata = FSDirEncryptionZoneOp.ensureKeyIsInitialized(dir, keyName, src); final FSPermissionChecker pc = getPermissionChecker(); + checkSuperuserPrivilege(pc); checkOperation(OperationCategory.WRITE); final FileStatus resultingStat; writeLock(); try { - checkSuperuserPrivilege(pc); checkOperation(OperationCategory.WRITE); checkNameNodeSafeMode("Cannot create encryption zone on " + src); resultingStat = FSDirEncryptionZoneOp.createEncryptionZone(dir, src, @@ -7372,10 +7372,10 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, boolean success = false; checkOperation(OperationCategory.READ); final FSPermissionChecker pc = getPermissionChecker(); + checkSuperuserPrivilege(pc); readLock(); try { checkOperation(OperationCategory.READ); - checkSuperuserPrivilege(pc); final BatchedListEntries ret = FSDirEncryptionZoneOp.listEncryptionZones(dir, prevId); success = true; @@ -7409,10 +7409,10 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, boolean success = false; checkOperation(OperationCategory.READ); final FSPermissionChecker pc = getPermissionChecker(); + checkSuperuserPrivilege(pc); readLock(); try { checkOperation(OperationCategory.READ); - checkSuperuserPrivilege(pc); final BatchedListEntries ret = FSDirEncryptionZoneOp.listReencryptionStatus(dir, prevId); success = true; @@ -7443,7 +7443,6 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, } writeLock(); try { - checkSuperuserPrivilege(pc); checkOperation(OperationCategory.WRITE); checkNameNodeSafeMode("NameNode in safemode, cannot " + action + " re-encryption on zone " + zone);