예제 #1
0
        /// <exception cref="System.IO.IOException"/>
        private static void SetDirStoragePolicy(FSDirectory fsd, INodeDirectory inode, byte
                                                policyId, int latestSnapshotId)
        {
            IList <XAttr> existingXAttrs = XAttrStorage.ReadINodeXAttrs(inode);
            XAttr         xAttr          = BlockStoragePolicySuite.BuildXAttr(policyId);
            IList <XAttr> newXAttrs      = FSDirXAttrOp.SetINodeXAttrs(fsd, existingXAttrs, Arrays.
                                                                       AsList(xAttr), EnumSet.Of(XAttrSetFlag.Create, XAttrSetFlag.Replace));

            XAttrStorage.UpdateINodeXAttrs(inode, newXAttrs, latestSnapshotId);
        }
예제 #2
0
 /// <exception cref="System.IO.IOException"/>
 internal static IList <XAttr> GetXAttrs(FSDirectory fsd, INode inode, int snapshotId
                                         )
 {
     fsd.ReadLock();
     try
     {
         return(XAttrStorage.ReadINodeXAttrs(inode, snapshotId));
     }
     finally
     {
         fsd.ReadUnlock();
     }
 }
예제 #3
0
        /// <exception cref="System.IO.IOException"/>
        private static IList <XAttr> GetXAttrs(FSDirectory fsd, string src)
        {
            string srcs = FSDirectory.NormalizePath(src);

            fsd.ReadLock();
            try
            {
                INodesInPath iip        = fsd.GetINodesInPath(srcs, true);
                INode        inode      = FSDirectory.ResolveLastINode(iip);
                int          snapshotId = iip.GetPathSnapshotId();
                return(XAttrStorage.ReadINodeXAttrs(fsd.GetAttributes(src, inode.GetLocalNameBytes
                                                                          (), inode, snapshotId)));
            }
            finally
            {
                fsd.ReadUnlock();
            }
        }
예제 #4
0
        /// <exception cref="System.IO.IOException"/>
        internal static XAttr UnprotectedGetXAttrByName(INode inode, int snapshotId, string
                                                        xAttrName)
        {
            IList <XAttr> xAttrs = XAttrStorage.ReadINodeXAttrs(inode, snapshotId);

            if (xAttrs == null)
            {
                return(null);
            }
            foreach (XAttr x in xAttrs)
            {
                if (XAttrHelper.GetPrefixName(x).Equals(xAttrName))
                {
                    return(x);
                }
            }
            return(null);
        }
예제 #5
0
        /// <exception cref="System.IO.IOException"/>
        internal static IList <XAttr> UnprotectedRemoveXAttrs(FSDirectory fsd, string src,
                                                              IList <XAttr> toRemove)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            INodesInPath iip = fsd.GetINodesInPath4Write(FSDirectory.NormalizePath(src), true
                                                         );
            INode         inode          = FSDirectory.ResolveLastINode(iip);
            int           snapshotId     = iip.GetLatestSnapshotId();
            IList <XAttr> existingXAttrs = XAttrStorage.ReadINodeXAttrs(inode);
            IList <XAttr> removedXAttrs  = Lists.NewArrayListWithCapacity(toRemove.Count);
            IList <XAttr> newXAttrs      = FilterINodeXAttrs(existingXAttrs, toRemove, removedXAttrs
                                                             );

            if (existingXAttrs.Count != newXAttrs.Count)
            {
                XAttrStorage.UpdateINodeXAttrs(inode, newXAttrs, snapshotId);
                return(removedXAttrs);
            }
            return(null);
        }
예제 #6
0
        /// <exception cref="System.IO.IOException"/>
        internal static INode UnprotectedSetXAttrs(FSDirectory fsd, string src, IList <XAttr
                                                                                       > xAttrs, EnumSet <XAttrSetFlag> flag)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            INodesInPath iip = fsd.GetINodesInPath4Write(FSDirectory.NormalizePath(src), true
                                                         );
            INode         inode          = FSDirectory.ResolveLastINode(iip);
            int           snapshotId     = iip.GetLatestSnapshotId();
            IList <XAttr> existingXAttrs = XAttrStorage.ReadINodeXAttrs(inode);
            IList <XAttr> newXAttrs      = SetINodeXAttrs(fsd, existingXAttrs, xAttrs, flag);
            bool          isFile         = inode.IsFile();

            foreach (XAttr xattr in newXAttrs)
            {
                string xaName = XAttrHelper.GetPrefixName(xattr);

                /*
                 * If we're adding the encryption zone xattr, then add src to the list
                 * of encryption zones.
                 */
                if (HdfsServerConstants.CryptoXattrEncryptionZone.Equals(xaName))
                {
                    HdfsProtos.ZoneEncryptionInfoProto ezProto = HdfsProtos.ZoneEncryptionInfoProto.ParseFrom
                                                                     (xattr.GetValue());
                    fsd.ezManager.AddEncryptionZone(inode.GetId(), PBHelper.Convert(ezProto.GetSuite(
                                                                                        )), PBHelper.Convert(ezProto.GetCryptoProtocolVersion()), ezProto.GetKeyName());
                }
                if (!isFile && HdfsServerConstants.SecurityXattrUnreadableBySuperuser.Equals(xaName
                                                                                             ))
                {
                    throw new IOException("Can only set '" + HdfsServerConstants.SecurityXattrUnreadableBySuperuser
                                          + "' on a file.");
                }
            }
            XAttrStorage.UpdateINodeXAttrs(inode, newXAttrs, snapshotId);
            return(inode);
        }