From f31a206648c99179c9df2df81653832d79a088be Mon Sep 17 00:00:00 2001 From: Abhay Kulkarni Date: Sat, 27 Apr 2024 06:03:29 -0700 Subject: [PATCH 1/2] HDFS-17500: Add missing operation name while authorizing create and completeFile operations --- .../org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 e21c24398680d..70fcaf06e1a34 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 @@ -2710,6 +2710,7 @@ HdfsFileStatus startFile(String src, PermissionStatus permissions, HdfsFileStatus status; try { + FSPermissionChecker.setOperationType("create"); status = startFileInt(src, permissions, holder, clientMachine, flag, createParent, replication, blockSize, supportedVersions, ecPolicyName, storagePolicy, logRetryCache); @@ -2764,7 +2765,6 @@ private HdfsFileStatus startFileInt(String src, checkOperation(OperationCategory.WRITE); final FSPermissionChecker pc = getPermissionChecker(); - FSPermissionChecker.setOperationType(null); writeLock(); try { checkOperation(OperationCategory.WRITE); @@ -3224,7 +3224,7 @@ boolean completeFile(final String src, String holder, boolean success = false; checkOperation(OperationCategory.WRITE); final FSPermissionChecker pc = getPermissionChecker(); - FSPermissionChecker.setOperationType(null); + FSPermissionChecker.setOperationType("completeFile"); writeLock(); try { checkOperation(OperationCategory.WRITE); From b81cb631634a25bd6033d51134cfe0a84db8b959 Mon Sep 17 00:00:00 2001 From: Abhay Kulkarni Date: Tue, 30 Apr 2024 15:05:01 -0700 Subject: [PATCH 2/2] HDFS-17500: Set missing operation names: getStoragePolicy, getPreferredBlockSize, recoverLease, getAdditionalDatanode, abandonBlock, fsync operations - in FSPermissionChecker --- .../hdfs/server/namenode/FSNamesystem.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 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 70fcaf06e1a34..2f399cd4c2348 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 @@ -2618,9 +2618,10 @@ void unsetStoragePolicy(String src) throws IOException { * @throws IOException */ BlockStoragePolicy getStoragePolicy(String src) throws IOException { + final String operationName = "getStoragePolicy"; checkOperation(OperationCategory.READ); final FSPermissionChecker pc = getPermissionChecker(); - FSPermissionChecker.setOperationType(null); + FSPermissionChecker.setOperationType(operationName); readLock(); try { checkOperation(OperationCategory.READ); @@ -2646,9 +2647,10 @@ BlockStoragePolicy[] getStoragePolicies() throws IOException { } long getPreferredBlockSize(String src) throws IOException { + final String operationName = "getPreferredBlockSize"; checkOperation(OperationCategory.READ); final FSPermissionChecker pc = getPermissionChecker(); - FSPermissionChecker.setOperationType(null); + FSPermissionChecker.setOperationType(operationName); readLock(); try { checkOperation(OperationCategory.READ); @@ -2709,8 +2711,9 @@ HdfsFileStatus startFile(String src, PermissionStatus permissions, String storagePolicy, boolean logRetryCache) throws IOException { HdfsFileStatus status; + final String operationName = "create"; + FSPermissionChecker.setOperationType(operationName); try { - FSPermissionChecker.setOperationType("create"); status = startFileInt(src, permissions, holder, clientMachine, flag, createParent, replication, blockSize, supportedVersions, ecPolicyName, storagePolicy, logRetryCache); @@ -2857,9 +2860,10 @@ private HdfsFileStatus startFileInt(String src, boolean recoverLease(String src, String holder, String clientMachine) throws IOException { boolean skipSync = false; + final String operationName = "recoverLease"; checkOperation(OperationCategory.WRITE); final FSPermissionChecker pc = getPermissionChecker(); - FSPermissionChecker.setOperationType(null); + FSPermissionChecker.setOperationType(operationName); writeLock(); try { checkOperation(OperationCategory.WRITE); @@ -3105,9 +3109,10 @@ LocatedBlock getAdditionalDatanode(String src, long fileId, final byte storagePolicyID; final List chosen; final BlockType blockType; + final String operationName = "getAdditionalDatanode"; checkOperation(OperationCategory.WRITE); final FSPermissionChecker pc = getPermissionChecker(); - FSPermissionChecker.setOperationType(null); + FSPermissionChecker.setOperationType(operationName); readLock(); try { // Changing this operation category to WRITE instead of making getAdditionalDatanode as a @@ -3155,10 +3160,11 @@ LocatedBlock getAdditionalDatanode(String src, long fileId, */ void abandonBlock(ExtendedBlock b, long fileId, String src, String holder) throws IOException { + final String operationName = "abandonBlock"; NameNode.stateChangeLog.debug("BLOCK* NameSystem.abandonBlock: {} of file {}", b, src); checkOperation(OperationCategory.WRITE); final FSPermissionChecker pc = getPermissionChecker(); - FSPermissionChecker.setOperationType(null); + FSPermissionChecker.setOperationType(operationName); writeLock(); try { checkOperation(OperationCategory.WRITE); @@ -3222,9 +3228,10 @@ boolean completeFile(final String src, String holder, ExtendedBlock last, long fileId) throws IOException { boolean success = false; + final String operationName = "completeFile"; checkOperation(OperationCategory.WRITE); final FSPermissionChecker pc = getPermissionChecker(); - FSPermissionChecker.setOperationType("completeFile"); + FSPermissionChecker.setOperationType(operationName); writeLock(); try { checkOperation(OperationCategory.WRITE); @@ -3666,10 +3673,11 @@ void setQuota(String src, long nsQuota, long ssQuota, StorageType type) */ void fsync(String src, long fileId, String clientName, long lastBlockLength) throws IOException { + final String operationName = "fsync"; NameNode.stateChangeLog.info("BLOCK* fsync: " + src + " for " + clientName); checkOperation(OperationCategory.WRITE); final FSPermissionChecker pc = getPermissionChecker(); - FSPermissionChecker.setOperationType(null); + FSPermissionChecker.setOperationType(operationName); writeLock(); try { checkOperation(OperationCategory.WRITE);