|
@@ -86,6 +86,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_PERMISSIONS_SUPERUSERGROUP_KEY;
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_DEFAULT;
|
|
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_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.hdfs.server.common.HdfsServerConstants.SECURITY_XATTR_UNREADABLE_BY_SUPERUSER;
|
|
import static org.apache.hadoop.util.Time.now;
|
|
import static org.apache.hadoop.util.Time.now;
|
|
|
|
|
|
@@ -423,6 +425,9 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
private final CacheManager cacheManager;
|
|
private final CacheManager cacheManager;
|
|
private final DatanodeStatistics datanodeStatistics;
|
|
private final DatanodeStatistics datanodeStatistics;
|
|
|
|
|
|
|
|
+ // whether setStoragePolicy is allowed.
|
|
|
|
+ private final boolean isStoragePolicyEnabled;
|
|
|
|
+
|
|
private String nameserviceId;
|
|
private String nameserviceId;
|
|
|
|
|
|
private RollingUpgradeInfo rollingUpgradeInfo = null;
|
|
private RollingUpgradeInfo rollingUpgradeInfo = null;
|
|
@@ -794,6 +799,10 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
this.datanodeStatistics = blockManager.getDatanodeManager().getDatanodeStatistics();
|
|
this.datanodeStatistics = blockManager.getDatanodeManager().getDatanodeStatistics();
|
|
this.blockIdGenerator = new SequentialBlockIdGenerator(this.blockManager);
|
|
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.fsOwner = UserGroupInformation.getCurrentUser();
|
|
this.fsOwnerShortUserName = fsOwner.getShortUserName();
|
|
this.fsOwnerShortUserName = fsOwner.getShortUserName();
|
|
this.supergroup = conf.get(DFS_PERMISSIONS_SUPERUSERGROUP_KEY,
|
|
this.supergroup = conf.get(DFS_PERMISSIONS_SUPERUSERGROUP_KEY,
|
|
@@ -2305,8 +2314,17 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
}
|
|
}
|
|
|
|
|
|
private void setStoragePolicyInt(String src, final String policyName)
|
|
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);
|
|
checkOperation(OperationCategory.WRITE);
|
|
byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
|
|
byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
|
|
waitForLoadingFSImage();
|
|
waitForLoadingFSImage();
|
|
@@ -2315,6 +2333,12 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
try {
|
|
try {
|
|
checkOperation(OperationCategory.WRITE);
|
|
checkOperation(OperationCategory.WRITE);
|
|
checkNameNodeSafeMode("Cannot set storage policy for " + src);
|
|
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);
|
|
src = FSDirectory.resolvePath(src, pathComponents, dir);
|
|
|
|
|
|
// get the corresponding policy and make sure the policy name is valid
|
|
// get the corresponding policy and make sure the policy name is valid
|