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 */
018package org.apache.hadoop.hdfs.server.namenode;
019
020import org.apache.hadoop.classification.InterfaceAudience;
021import org.apache.hadoop.fs.permission.PermissionStatus;
022import org.apache.hadoop.hdfs.server.namenode.XAttrFeature;
023
024import com.google.common.base.Preconditions;
025
026/**
027 * The attributes of an inode.
028 */
029@InterfaceAudience.Private
030public interface INodeDirectoryAttributes extends INodeAttributes {
031  public Quota.Counts getQuotaCounts();
032
033  public boolean metadataEquals(INodeDirectoryAttributes other);
034  
035  /** A copy of the inode directory attributes */
036  public static class SnapshotCopy extends INodeAttributes.SnapshotCopy
037      implements INodeDirectoryAttributes {
038    public SnapshotCopy(byte[] name, PermissionStatus permissions,
039        AclFeature aclFeature, long modificationTime, 
040        XAttrFeature xAttrsFeature) {
041      super(name, permissions, aclFeature, modificationTime, 0L, xAttrsFeature);
042    }
043
044    public SnapshotCopy(INodeDirectory dir) {
045      super(dir);
046    }
047
048    @Override
049    public Quota.Counts getQuotaCounts() {
050      return Quota.Counts.newInstance(-1, -1);
051    }
052
053    @Override
054    public boolean metadataEquals(INodeDirectoryAttributes other) {
055      return other != null
056          && getQuotaCounts().equals(other.getQuotaCounts())
057          && getPermissionLong() == other.getPermissionLong()
058          && getAclFeature() == other.getAclFeature()
059          && getXAttrFeature() == other.getXAttrFeature();
060    }
061  }
062
063  public static class CopyWithQuota extends INodeDirectoryAttributes.SnapshotCopy {
064    private final long nsQuota;
065    private final long dsQuota;
066
067
068    public CopyWithQuota(byte[] name, PermissionStatus permissions,
069        AclFeature aclFeature, long modificationTime, long nsQuota,
070        long dsQuota, XAttrFeature xAttrsFeature) {
071      super(name, permissions, aclFeature, modificationTime, xAttrsFeature);
072      this.nsQuota = nsQuota;
073      this.dsQuota = dsQuota;
074    }
075
076    public CopyWithQuota(INodeDirectory dir) {
077      super(dir);
078      Preconditions.checkArgument(dir.isQuotaSet());
079      final Quota.Counts q = dir.getQuotaCounts();
080      this.nsQuota = q.get(Quota.NAMESPACE);
081      this.dsQuota = q.get(Quota.DISKSPACE);
082    }
083    
084    @Override
085    public Quota.Counts getQuotaCounts() {
086      return Quota.Counts.newInstance(nsQuota, dsQuota);
087    }
088  }
089}