001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.hadoop.hdfs.server.namenode;
019
020 import org.apache.hadoop.classification.InterfaceAudience;
021 import org.apache.hadoop.fs.permission.PermissionStatus;
022
023 import com.google.common.base.Preconditions;
024
025 /**
026 * The attributes of an inode.
027 */
028 @InterfaceAudience.Private
029 public interface INodeDirectoryAttributes extends INodeAttributes {
030 public Quota.Counts getQuotaCounts();
031
032 public boolean metadataEquals(INodeDirectoryAttributes other);
033
034 /** A copy of the inode directory attributes */
035 public static class SnapshotCopy extends INodeAttributes.SnapshotCopy
036 implements INodeDirectoryAttributes {
037 public SnapshotCopy(byte[] name, PermissionStatus permissions,
038 AclFeature aclFeature, long modificationTime) {
039 super(name, permissions, aclFeature, modificationTime, 0L);
040 }
041
042 public SnapshotCopy(INodeDirectory dir) {
043 super(dir);
044 }
045
046 @Override
047 public Quota.Counts getQuotaCounts() {
048 return Quota.Counts.newInstance(-1, -1);
049 }
050
051 @Override
052 public boolean metadataEquals(INodeDirectoryAttributes other) {
053 return other != null
054 && this.getQuotaCounts().equals(other.getQuotaCounts())
055 && getPermissionLong() == other.getPermissionLong();
056 }
057 }
058
059 public static class CopyWithQuota extends INodeDirectoryAttributes.SnapshotCopy {
060 private final long nsQuota;
061 private final long dsQuota;
062
063
064 public CopyWithQuota(byte[] name, PermissionStatus permissions,
065 AclFeature aclFeature, long modificationTime, long nsQuota,
066 long dsQuota) {
067 super(name, permissions, aclFeature, modificationTime);
068 this.nsQuota = nsQuota;
069 this.dsQuota = dsQuota;
070 }
071
072 public CopyWithQuota(INodeDirectory dir) {
073 super(dir);
074 Preconditions.checkArgument(dir.isQuotaSet());
075 final Quota.Counts q = dir.getQuotaCounts();
076 this.nsQuota = q.get(Quota.NAMESPACE);
077 this.dsQuota = q.get(Quota.DISKSPACE);
078 }
079
080 @Override
081 public Quota.Counts getQuotaCounts() {
082 return Quota.Counts.newInstance(nsQuota, dsQuota);
083 }
084 }
085 }