示例#1
0
        /// <exception cref="System.IO.IOException"/>
        private static void UnprotectedRemoveAcl(FSDirectory fsd, INodesInPath iip)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            INode      inode      = FSDirectory.ResolveLastINode(iip);
            int        snapshotId = iip.GetLatestSnapshotId();
            AclFeature f          = inode.GetAclFeature();

            if (f == null)
            {
                return;
            }
            FsPermission     perm           = inode.GetFsPermission();
            IList <AclEntry> featureEntries = AclStorage.GetEntriesFromAclFeature(f);

            if (featureEntries[0].GetScope() == AclEntryScope.Access)
            {
                // Restore group permissions from the feature's entry to permission
                // bits, overwriting the mask, which is not part of a minimal ACL.
                AclEntry groupEntryKey = new AclEntry.Builder().SetScope(AclEntryScope.Access).SetType
                                             (AclEntryType.Group).Build();
                int groupEntryIndex = Sharpen.Collections.BinarySearch(featureEntries, groupEntryKey
                                                                       , AclTransformation.AclEntryComparator);
                System.Diagnostics.Debug.Assert(groupEntryIndex >= 0);
                FsAction     groupPerm = featureEntries[groupEntryIndex].GetPermission();
                FsPermission newPerm   = new FsPermission(perm.GetUserAction(), groupPerm, perm.GetOtherAction
                                                              (), perm.GetStickyBit());
                inode.SetPermission(newPerm, snapshotId);
            }
            inode.RemoveAclFeature(snapshotId);
        }
示例#2
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus RemoveDefaultAcl(FSDirectory fsd, string srcArg)
        {
            string src = srcArg;

            CheckAclsConfigFlag(fsd);
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            src = fsd.ResolvePath(pc, src, pathComponents);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                iip = fsd.GetINodesInPath4Write(FSDirectory.NormalizePath(src), true);
                fsd.CheckOwner(pc, iip);
                INode            inode       = FSDirectory.ResolveLastINode(iip);
                int              snapshotId  = iip.GetLatestSnapshotId();
                IList <AclEntry> existingAcl = AclStorage.ReadINodeLogicalAcl(inode);
                IList <AclEntry> newAcl      = AclTransformation.FilterDefaultAclEntries(existingAcl);
                AclStorage.UpdateINodeAcl(inode, newAcl, snapshotId);
                fsd.GetEditLog().LogSetAcl(src, newAcl);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            return(fsd.GetAuditFileInfo(iip));
        }
示例#3
0
        public override void DestroyAndCollectBlocks(BlockStoragePolicySuite bsps, INode.BlocksMapUpdateInfo
                                                     collectedBlocks, IList <INode> removedINodes)
        {
            if (blocks != null && collectedBlocks != null)
            {
                foreach (BlockInfoContiguous blk in blocks)
                {
                    collectedBlocks.AddDeleteBlock(blk);
                    blk.SetBlockCollection(null);
                }
            }
            SetBlocks(null);
            if (GetAclFeature() != null)
            {
                AclStorage.RemoveAclFeature(GetAclFeature());
            }
            Clear();
            removedINodes.AddItem(this);
            FileWithSnapshotFeature sf = GetFileWithSnapshotFeature();

            if (sf != null)
            {
                sf.GetDiffs().DestroyAndCollectSnapshotBlocks(collectedBlocks);
                sf.ClearDiffs();
            }
        }
示例#4
0
        /// <exception cref="System.IO.IOException"/>
        internal static IList <AclEntry> UnprotectedSetAcl(FSDirectory fsd, string src, IList
                                                           <AclEntry> aclSpec, bool fromEdits)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            INodesInPath iip = fsd.GetINodesInPath4Write(FSDirectory.NormalizePath(src), true
                                                         );

            // ACL removal is logged to edits as OP_SET_ACL with an empty list.
            if (aclSpec.IsEmpty())
            {
                UnprotectedRemoveAcl(fsd, iip);
                return(AclFeature.EmptyEntryList);
            }
            INode            inode      = FSDirectory.ResolveLastINode(iip);
            int              snapshotId = iip.GetLatestSnapshotId();
            IList <AclEntry> newAcl     = aclSpec;

            if (!fromEdits)
            {
                IList <AclEntry> existingAcl = AclStorage.ReadINodeLogicalAcl(inode);
                newAcl = AclTransformation.ReplaceAclEntries(existingAcl, aclSpec);
            }
            AclStorage.UpdateINodeAcl(inode, newAcl, snapshotId);
            return(newAcl);
        }
示例#5
0
        internal override void RemoveAclFeature()
        {
            AclFeature f = GetAclFeature();

            Preconditions.CheckNotNull(f);
            RemoveFeature(f);
            AclStorage.RemoveAclFeature(f);
        }
示例#6
0
        internal override void AddAclFeature(AclFeature f)
        {
            AclFeature f1 = GetAclFeature();

            if (f1 != null)
            {
                throw new InvalidOperationException("Duplicated ACLFeature");
            }
            AddFeature(AclStorage.AddAclFeature(f));
        }
示例#7
0
 internal SnapshotCopy(byte[] name, PermissionStatus permissions, AclFeature aclFeature
                       , long modificationTime, long accessTime, XAttrFeature xAttrFeature)
 {
     this.name       = name;
     this.permission = INodeWithAdditionalFields.PermissionStatusFormat.ToLong(permissions
                                                                               );
     if (aclFeature != null)
     {
         aclFeature = AclStorage.AddAclFeature(aclFeature);
     }
     this.aclFeature       = aclFeature;
     this.modificationTime = modificationTime;
     this.accessTime       = accessTime;
     this.xAttrFeature     = xAttrFeature;
 }
示例#8
0
 internal SnapshotCopy(INode inode)
 {
     this.name       = inode.GetLocalNameBytes();
     this.permission = inode.GetPermissionLong();
     if (inode.GetAclFeature() != null)
     {
         aclFeature = AclStorage.AddAclFeature(inode.GetAclFeature());
     }
     else
     {
         aclFeature = null;
     }
     this.modificationTime = inode.GetModificationTime();
     this.accessTime       = inode.GetAccessTime();
     this.xAttrFeature     = inode.GetXAttrFeature();
 }
示例#9
0
        /// <summary>create a directory at path specified by parent</summary>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.AclException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/>
        private static INodesInPath UnprotectedMkdir(FSDirectory fsd, long inodeId, INodesInPath
                                                     parent, byte[] name, PermissionStatus permission, IList <AclEntry> aclEntries, long
                                                     timestamp)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            System.Diagnostics.Debug.Assert(parent.GetLastINode() != null);
            if (!parent.GetLastINode().IsDirectory())
            {
                throw new FileAlreadyExistsException("Parent path is not a directory: " + parent.
                                                     GetPath() + " " + DFSUtil.Bytes2String(name));
            }
            INodeDirectory dir = new INodeDirectory(inodeId, name, permission, timestamp);
            INodesInPath   iip = fsd.AddLastINode(parent, dir, true);

            if (iip != null && aclEntries != null)
            {
                AclStorage.UpdateINodeAcl(dir, aclEntries, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                          .CurrentStateId);
            }
            return(iip);
        }
示例#10
0
        public override void DestroyAndCollectBlocks(BlockStoragePolicySuite bsps, INode.BlocksMapUpdateInfo
                                                     collectedBlocks, IList <INode> removedINodes)
        {
            DirectoryWithSnapshotFeature sf = GetDirectoryWithSnapshotFeature();

            if (sf != null)
            {
                sf.Clear(bsps, this, collectedBlocks, removedINodes);
            }
            foreach (INode child in GetChildrenList(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                    .CurrentStateId))
            {
                child.DestroyAndCollectBlocks(bsps, collectedBlocks, removedINodes);
            }
            if (GetAclFeature() != null)
            {
                AclStorage.RemoveAclFeature(GetAclFeature());
            }
            Clear();
            removedINodes.AddItem(this);
        }
示例#11
0
        /// <summary>Copy constructor</summary>
        /// <param name="other">The INodeDirectory to be copied</param>
        /// <param name="adopt">
        /// Indicate whether or not need to set the parent field of child
        /// INodes to the new node
        /// </param>
        /// <param name="featuresToCopy">
        /// any number of features to copy to the new node.
        /// The method will do a reference copy, not a deep copy.
        /// </param>
        public INodeDirectory(Org.Apache.Hadoop.Hdfs.Server.Namenode.INodeDirectory other
                              , bool adopt, params INode.Feature[] featuresToCopy)
            : base(other)
        {
            this.children = other.children;
            if (adopt && this.children != null)
            {
                foreach (INode child in children)
                {
                    child.SetParent(this);
                }
            }
            this.features = featuresToCopy;
            AclFeature aclFeature = GetFeature(typeof(AclFeature));

            if (aclFeature != null)
            {
                // for the de-duplication of AclFeature
                RemoveFeature(aclFeature);
                AddFeature(AclStorage.AddAclFeature(aclFeature));
            }
        }
示例#12
0
        /// <exception cref="System.IO.IOException"/>
        internal static AclStatus GetAclStatus(FSDirectory fsd, string src)
        {
            CheckAclsConfigFlag(fsd);
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            src = fsd.ResolvePath(pc, src, pathComponents);
            string srcs = FSDirectory.NormalizePath(src);

            fsd.ReadLock();
            try
            {
                // There is no real inode for the path ending in ".snapshot", so return a
                // non-null, unpopulated AclStatus.  This is similar to getFileInfo.
                if (srcs.EndsWith(HdfsConstants.SeparatorDotSnapshotDir) && fsd.GetINode4DotSnapshot
                        (srcs) != null)
                {
                    return(new AclStatus.Builder().Owner(string.Empty).Group(string.Empty).Build());
                }
                INodesInPath iip = fsd.GetINodesInPath(srcs, true);
                if (fsd.IsPermissionEnabled())
                {
                    fsd.CheckTraverse(pc, iip);
                }
                INode            inode      = FSDirectory.ResolveLastINode(iip);
                int              snapshotId = iip.GetPathSnapshotId();
                IList <AclEntry> acl        = AclStorage.ReadINodeAcl(fsd.GetAttributes(src, inode.GetLocalNameBytes
                                                                                            (), inode, snapshotId));
                FsPermission fsPermission = inode.GetFsPermission(snapshotId);
                return(new AclStatus.Builder().Owner(inode.GetUserName()).Group(inode.GetGroupName
                                                                                    ()).StickyBit(fsPermission.GetStickyBit()).SetPermission(fsPermission).AddEntries
                           (acl).Build());
            }
            finally
            {
                fsd.ReadUnlock();
            }
        }
示例#13
0
 /// <exception cref="System.IO.IOException"/>
 private void AddAcl(INodeWithAdditionalFields inode, params AclEntry[] acl)
 {
     AclStorage.UpdateINodeAcl(inode, Arrays.AsList(acl), Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                               .CurrentStateId);
 }