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            XAttrFeature xAttrsFeature) {
040          super(name, permissions, aclFeature, modificationTime, 0L, xAttrsFeature);
041        }
042    
043        public SnapshotCopy(INodeDirectory dir) {
044          super(dir);
045        }
046    
047        @Override
048        public Quota.Counts getQuotaCounts() {
049          return Quota.Counts.newInstance(-1, -1);
050        }
051    
052        @Override
053        public boolean metadataEquals(INodeDirectoryAttributes other) {
054          return other != null
055              && getQuotaCounts().equals(other.getQuotaCounts())
056              && getPermissionLong() == other.getPermissionLong()
057              && getAclFeature() == other.getAclFeature()
058              && getXAttrFeature() == other.getXAttrFeature();
059        }
060      }
061    
062      public static class CopyWithQuota extends INodeDirectoryAttributes.SnapshotCopy {
063        private final long nsQuota;
064        private final long dsQuota;
065    
066    
067        public CopyWithQuota(byte[] name, PermissionStatus permissions,
068            AclFeature aclFeature, long modificationTime, long nsQuota,
069            long dsQuota, XAttrFeature xAttrsFeature) {
070          super(name, permissions, aclFeature, modificationTime, xAttrsFeature);
071          this.nsQuota = nsQuota;
072          this.dsQuota = dsQuota;
073        }
074    
075        public CopyWithQuota(INodeDirectory dir) {
076          super(dir);
077          Preconditions.checkArgument(dir.isQuotaSet());
078          final Quota.Counts q = dir.getQuotaCounts();
079          this.nsQuota = q.get(Quota.NAMESPACE);
080          this.dsQuota = q.get(Quota.DISKSPACE);
081        }
082        
083        @Override
084        public Quota.Counts getQuotaCounts() {
085          return Quota.Counts.newInstance(nsQuota, dsQuota);
086        }
087      }
088    }