Ejemplo n.º 1
0
                public override AclFeature GetAclFeature()
                {
                    AclFeature f;

                    if (useDefault)
                    {
                        f = inode.GetAclFeature();
                    }
                    else
                    {
                        AclEntry acl = new AclEntry.Builder().SetType(AclEntryType.Group).SetPermission(FsAction
                                                                                                        .All).SetName("xxx").Build();
                        f = new AclFeature(AclEntryStatusFormat.ToInt(Lists.NewArrayList(acl)));
                    }
                    return(f);
                }
Ejemplo n.º 2
0
            private INodeFile LoadINodeFile(FsImageProto.INodeSection.INode n)
            {
                System.Diagnostics.Debug.Assert(n.GetType() == FsImageProto.INodeSection.INode.Type
                                                .File);
                FsImageProto.INodeSection.INodeFile f  = n.GetFile();
                IList <HdfsProtos.BlockProto>       bp = f.GetBlocksList();
                short replication = (short)f.GetReplication();

                FSImageFormatProtobuf.LoaderContext state = parent.GetLoaderContext();
                BlockInfoContiguous[] blocks = new BlockInfoContiguous[bp.Count];
                for (int i = 0; i < e; ++i)
                {
                    blocks[i] = new BlockInfoContiguous(PBHelper.Convert(bp[i]), replication);
                }
                PermissionStatus permissions = LoadPermission(f.GetPermission(), parent.GetLoaderContext
                                                                  ().GetStringTable());
                INodeFile file = new INodeFile(n.GetId(), n.GetName().ToByteArray(), permissions,
                                               f.GetModificationTime(), f.GetAccessTime(), blocks, replication, f.GetPreferredBlockSize
                                                   (), unchecked ((byte)f.GetStoragePolicyID()));

                if (f.HasAcl())
                {
                    int[] entries = AclEntryStatusFormat.ToInt(LoadAclEntries(f.GetAcl(), state.GetStringTable
                                                                                  ()));
                    file.AddAclFeature(new AclFeature(entries));
                }
                if (f.HasXAttrs())
                {
                    file.AddXAttrFeature(new XAttrFeature(LoadXAttrs(f.GetXAttrs(), state.GetStringTable
                                                                         ())));
                }
                // under-construction information
                if (f.HasFileUC())
                {
                    FsImageProto.INodeSection.FileUnderConstructionFeature uc = f.GetFileUC();
                    file.ToUnderConstruction(uc.GetClientName(), uc.GetClientMachine());
                    if (blocks.Length > 0)
                    {
                        BlockInfoContiguous lastBlk = file.GetLastBlock();
                        // replace the last block of file
                        file.SetBlock(file.NumBlocks() - 1, new BlockInfoContiguousUnderConstruction(lastBlk
                                                                                                     , replication));
                    }
                }
                return(file);
            }
Ejemplo n.º 3
0
        /// <summary>Creates an AclFeature from the given ACL entries.</summary>
        /// <param name="accessEntries">List<AclEntry> access ACL entries</param>
        /// <param name="defaultEntries">List<AclEntry> default ACL entries</param>
        /// <returns>AclFeature containing the required ACL entries</returns>
        private static AclFeature CreateAclFeature(IList <AclEntry> accessEntries, IList <AclEntry
                                                                                          > defaultEntries)
        {
            // Pre-allocate list size for the explicit entries stored in the feature,
            // which is all entries minus the 3 entries implicitly stored in the
            // permission bits.
            IList <AclEntry> featureEntries = Lists.NewArrayListWithCapacity((accessEntries.Count
                                                                              - 3) + defaultEntries.Count);

            // For the access ACL, the feature only needs to hold the named user and
            // group entries.  For a correctly sorted ACL, these will be in a
            // predictable range.
            if (!AclUtil.IsMinimalAcl(accessEntries))
            {
                Sharpen.Collections.AddAll(featureEntries, accessEntries.SubList(1, accessEntries
                                                                                 .Count - 2));
            }
            // Add all default entries to the feature.
            Sharpen.Collections.AddAll(featureEntries, defaultEntries);
            return(new AclFeature(AclEntryStatusFormat.ToInt(featureEntries)));
        }
Ejemplo n.º 4
0
            public static INodeDirectory LoadINodeDirectory(FsImageProto.INodeSection.INode n
                                                            , FSImageFormatProtobuf.LoaderContext state)
            {
                System.Diagnostics.Debug.Assert(n.GetType() == FsImageProto.INodeSection.INode.Type
                                                .Directory);
                FsImageProto.INodeSection.INodeDirectory d = n.GetDirectory();
                PermissionStatus permissions = LoadPermission(d.GetPermission(), state.GetStringTable
                                                                  ());
                INodeDirectory dir = new INodeDirectory(n.GetId(), n.GetName().ToByteArray(), permissions
                                                        , d.GetModificationTime());
                long nsQuota = d.GetNsQuota();
                long dsQuota = d.GetDsQuota();

                if (nsQuota >= 0 || dsQuota >= 0)
                {
                    dir.AddDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder().NameSpaceQuota
                                                         (nsQuota).StorageSpaceQuota(dsQuota).Build());
                }
                EnumCounters <StorageType> typeQuotas = null;

                if (d.HasTypeQuotas())
                {
                    ImmutableList <QuotaByStorageTypeEntry> qes = LoadQuotaByStorageTypeEntries(d.GetTypeQuotas
                                                                                                    ());
                    typeQuotas = new EnumCounters <StorageType>(typeof(StorageType), HdfsConstants.QuotaReset
                                                                );
                    foreach (QuotaByStorageTypeEntry qe in qes)
                    {
                        if (qe.GetQuota() >= 0 && qe.GetStorageType() != null && qe.GetStorageType().SupportTypeQuota
                                ())
                        {
                            typeQuotas.Set(qe.GetStorageType(), qe.GetQuota());
                        }
                    }
                    if (typeQuotas.AnyGreaterOrEqual(0))
                    {
                        DirectoryWithQuotaFeature q = dir.GetDirectoryWithQuotaFeature();
                        if (q == null)
                        {
                            dir.AddDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder().TypeQuotas
                                                                 (typeQuotas).Build());
                        }
                        else
                        {
                            q.SetQuota(typeQuotas);
                        }
                    }
                }
                if (d.HasAcl())
                {
                    int[] entries = AclEntryStatusFormat.ToInt(LoadAclEntries(d.GetAcl(), state.GetStringTable
                                                                                  ()));
                    dir.AddAclFeature(new AclFeature(entries));
                }
                if (d.HasXAttrs())
                {
                    dir.AddXAttrFeature(new XAttrFeature(LoadXAttrs(d.GetXAttrs(), state.GetStringTable
                                                                        ())));
                }
                return(dir);
            }