|
@@ -84,6 +84,8 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_PERMISSIONS_SUPERUSERGROU
|
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_PERMISSIONS_SUPERUSERGROUP_KEY;
|
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_DEFAULT;
|
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_KEY;
|
|
|
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_KEY;
|
|
|
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_DEFAULT;
|
|
|
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.SECURITY_XATTR_UNREADABLE_BY_SUPERUSER;
|
|
|
import static org.apache.hadoop.util.Time.now;
|
|
|
|
|
@@ -420,6 +422,9 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
private final CacheManager cacheManager;
|
|
|
private final DatanodeStatistics datanodeStatistics;
|
|
|
|
|
|
+ // whether setStoragePolicy is allowed.
|
|
|
+ private final boolean isStoragePolicyEnabled;
|
|
|
+
|
|
|
private String nameserviceId;
|
|
|
|
|
|
private RollingUpgradeInfo rollingUpgradeInfo = null;
|
|
@@ -781,6 +786,10 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
this.datanodeStatistics = blockManager.getDatanodeManager().getDatanodeStatistics();
|
|
|
this.blockIdGenerator = new SequentialBlockIdGenerator(this.blockManager);
|
|
|
|
|
|
+ this.isStoragePolicyEnabled =
|
|
|
+ conf.getBoolean(DFS_STORAGE_POLICY_ENABLED_KEY,
|
|
|
+ DFS_STORAGE_POLICY_ENABLED_DEFAULT);
|
|
|
+
|
|
|
this.fsOwner = UserGroupInformation.getCurrentUser();
|
|
|
this.fsOwnerShortUserName = fsOwner.getShortUserName();
|
|
|
this.supergroup = conf.get(DFS_PERMISSIONS_SUPERUSERGROUP_KEY,
|
|
@@ -2273,8 +2282,17 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
|
|
|
private void setStoragePolicyInt(String src, final String policyName)
|
|
|
- throws IOException {
|
|
|
- checkSuperuserPrivilege();
|
|
|
+ throws IOException, UnresolvedLinkException, AccessControlException {
|
|
|
+
|
|
|
+ if (!isStoragePolicyEnabled) {
|
|
|
+ throw new IOException("Failed to set storage policy since "
|
|
|
+ + DFS_STORAGE_POLICY_ENABLED_KEY + " is set to false.");
|
|
|
+ }
|
|
|
+ FSPermissionChecker pc = null;
|
|
|
+ if (isPermissionEnabled) {
|
|
|
+ pc = getPermissionChecker();
|
|
|
+ }
|
|
|
+
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
|
|
|
waitForLoadingFSImage();
|
|
@@ -2283,6 +2301,12 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot set storage policy for " + src);
|
|
|
+
|
|
|
+ if (pc != null) {
|
|
|
+ checkPermission(pc, src, false, null, null, FsAction.WRITE, null,
|
|
|
+ false, true);
|
|
|
+ }
|
|
|
+
|
|
|
src = FSDirectory.resolvePath(src, pathComponents, dir);
|
|
|
|
|
|
// get the corresponding policy and make sure the policy name is valid
|