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; 022 023import com.google.common.base.Preconditions; 024 025/** 026 * The attributes of an inode. 027 */ 028@InterfaceAudience.Private 029public interface INodeDirectoryAttributes extends INodeAttributes { 030 public long getNsQuota(); 031 032 public long getDsQuota(); 033 034 public boolean metadataEquals(INodeDirectoryAttributes other); 035 036 /** A copy of the inode directory attributes */ 037 public static class SnapshotCopy extends INodeAttributes.SnapshotCopy 038 implements INodeDirectoryAttributes { 039 public SnapshotCopy(byte[] name, PermissionStatus permissions, 040 long modificationTime) { 041 super(name, permissions, modificationTime, 0L); 042 } 043 044 public SnapshotCopy(INodeDirectory dir) { 045 super(dir); 046 } 047 048 @Override 049 public long getNsQuota() { 050 return -1; 051 } 052 053 @Override 054 public long getDsQuota() { 055 return -1; 056 } 057 058 @Override 059 public boolean metadataEquals(INodeDirectoryAttributes other) { 060 return other != null 061 && getNsQuota() == other.getNsQuota() 062 && getDsQuota() == other.getDsQuota() 063 && getPermissionLong() == other.getPermissionLong(); 064 } 065 } 066 067 public static class CopyWithQuota extends INodeDirectoryAttributes.SnapshotCopy { 068 private final long nsQuota; 069 private final long dsQuota; 070 071 public CopyWithQuota(byte[] name, PermissionStatus permissions, 072 long modificationTime, long nsQuota, long dsQuota) { 073 super(name, permissions, modificationTime); 074 this.nsQuota = nsQuota; 075 this.dsQuota = dsQuota; 076 } 077 078 public CopyWithQuota(INodeDirectory dir) { 079 super(dir); 080 Preconditions.checkArgument(dir.isQuotaSet()); 081 this.nsQuota = dir.getNsQuota(); 082 this.dsQuota = dir.getDsQuota(); 083 } 084 085 @Override 086 public final long getNsQuota() { 087 return nsQuota; 088 } 089 090 @Override 091 public final long getDsQuota() { 092 return dsQuota; 093 } 094 } 095}