Пример #1
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));
        }
Пример #2
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus RemoveAcl(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(src);
                fsd.CheckOwner(pc, iip);
                UnprotectedRemoveAcl(fsd, iip);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogSetAcl(src, AclFeature.EmptyEntryList);
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #3
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus SetAcl(FSDirectory fsd, string srcArg, IList <AclEntry
                                                                                     > aclSpec)
        {
            string src = srcArg;

            CheckAclsConfigFlag(fsd);
            byte[][]            pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            FSPermissionChecker pc             = fsd.GetPermissionChecker();

            src = fsd.ResolvePath(pc, src, pathComponents);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                iip = fsd.GetINodesInPath4Write(src);
                fsd.CheckOwner(pc, iip);
                IList <AclEntry> newAcl = UnprotectedSetAcl(fsd, src, aclSpec, false);
                fsd.GetEditLog().LogSetAcl(src, newAcl);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #4
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus SetOwner(FSDirectory fsd, string src, string username
                                                , string group)
        {
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][]     pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                src = fsd.ResolvePath(pc, src, pathComponents);
                iip = fsd.GetINodesInPath4Write(src);
                fsd.CheckOwner(pc, iip);
                if (!pc.IsSuperUser())
                {
                    if (username != null && !pc.GetUser().Equals(username))
                    {
                        throw new AccessControlException("Non-super user cannot change owner");
                    }
                    if (group != null && !pc.ContainsGroup(group))
                    {
                        throw new AccessControlException("User does not belong to " + group);
                    }
                }
                UnprotectedSetOwner(fsd, src, username, group);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogSetOwner(src, username, group);
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #5
0
        /// <summary>Set xattr for a file or directory.</summary>
        /// <param name="src">- path on which it sets the xattr</param>
        /// <param name="xAttr">- xAttr details to set</param>
        /// <param name="flag">- xAttrs flags</param>
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus SetXAttr(FSDirectory fsd, string src, XAttr xAttr,
                                                EnumSet <XAttrSetFlag> flag, bool logRetryCache)
        {
            CheckXAttrsConfigFlag(fsd);
            CheckXAttrSize(fsd, xAttr);
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            XAttrPermissionFilter.CheckPermissionForApi(pc, xAttr, FSDirectory.IsReservedRawName
                                                            (src));
            byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            src = fsd.ResolvePath(pc, src, pathComponents);
            IList <XAttr> xAttrs = Lists.NewArrayListWithCapacity(1);

            xAttrs.AddItem(xAttr);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                iip = fsd.GetINodesInPath4Write(src);
                CheckXAttrChangeAccess(fsd, iip, xAttr, pc);
                UnprotectedSetXAttrs(fsd, src, xAttrs, flag);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogSetXAttrs(src, xAttrs, logRetryCache);
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #6
0
        /// <summary>The new rename which has the POSIX semantic.</summary>
        /// <exception cref="System.IO.IOException"/>
        internal static KeyValuePair <INode.BlocksMapUpdateInfo, HdfsFileStatus> RenameToInt
            (FSDirectory fsd, string srcArg, string dstArg, bool logRetryCache, params Options.Rename
            [] options)
        {
            string src = srcArg;
            string dst = dstArg;

            if (NameNode.stateChangeLog.IsDebugEnabled())
            {
                NameNode.stateChangeLog.Debug("DIR* NameSystem.renameTo: with options -" + " " +
                                              src + " to " + dst);
            }
            if (!DFSUtil.IsValidName(dst))
            {
                throw new InvalidPathException("Invalid name: " + dst);
            }
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][] srcComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            byte[][] dstComponents = FSDirectory.GetPathComponentsForReservedPath(dst);
            INode.BlocksMapUpdateInfo collectedBlocks = new INode.BlocksMapUpdateInfo();
            src = fsd.ResolvePath(pc, src, srcComponents);
            dst = fsd.ResolvePath(pc, dst, dstComponents);
            RenameTo(fsd, pc, src, dst, collectedBlocks, logRetryCache, options);
            INodesInPath   dstIIP        = fsd.GetINodesInPath(dst, false);
            HdfsFileStatus resultingStat = fsd.GetAuditFileInfo(dstIIP);

            return(new AbstractMap.SimpleImmutableEntry <INode.BlocksMapUpdateInfo, HdfsFileStatus
                                                         >(collectedBlocks, resultingStat));
        }
Пример #7
0
        internal static FSDirRenameOp.RenameOldResult RenameToInt(FSDirectory fsd, string
                                                                  srcArg, string dstArg, bool logRetryCache)
        {
            string src = srcArg;
            string dst = dstArg;

            if (NameNode.stateChangeLog.IsDebugEnabled())
            {
                NameNode.stateChangeLog.Debug("DIR* NameSystem.renameTo: " + src + " to " + dst);
            }
            if (!DFSUtil.IsValidName(dst))
            {
                throw new IOException("Invalid name: " + dst);
            }
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][]       srcComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            byte[][]       dstComponents = FSDirectory.GetPathComponentsForReservedPath(dst);
            HdfsFileStatus resultingStat = null;

            src = fsd.ResolvePath(pc, src, srcComponents);
            dst = fsd.ResolvePath(pc, dst, dstComponents);
            bool status = RenameTo(fsd, pc, src, dst, logRetryCache);

            if (status)
            {
                INodesInPath dstIIP = fsd.GetINodesInPath(dst, false);
                resultingStat = fsd.GetAuditFileInfo(dstIIP);
            }
            return(new FSDirRenameOp.RenameOldResult(status, resultingStat));
        }
Пример #8
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus CreateSymlinkInt(FSNamesystem fsn, string target,
                                                        string linkArg, PermissionStatus dirPerms, bool createParent, bool logRetryCache
                                                        )
        {
            FSDirectory fsd  = fsn.GetFSDirectory();
            string      link = linkArg;

            if (!DFSUtil.IsValidName(link))
            {
                throw new InvalidPathException("Invalid link name: " + link);
            }
            if (FSDirectory.IsReservedName(target) || target.IsEmpty())
            {
                throw new InvalidPathException("Invalid target name: " + target);
            }
            if (NameNode.stateChangeLog.IsDebugEnabled())
            {
                NameNode.stateChangeLog.Debug("DIR* NameSystem.createSymlink: target=" + target +
                                              " link=" + link);
            }
            FSPermissionChecker pc = fsn.GetPermissionChecker();

            byte[][]     pathComponents = FSDirectory.GetPathComponentsForReservedPath(link);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                link = fsd.ResolvePath(pc, link, pathComponents);
                iip  = fsd.GetINodesInPath4Write(link, false);
                if (!createParent)
                {
                    fsd.VerifyParentDir(iip, link);
                }
                if (!fsd.IsValidToCreate(link, iip))
                {
                    throw new IOException("failed to create link " + link + " either because the filename is invalid or the file exists"
                                          );
                }
                if (fsd.IsPermissionEnabled())
                {
                    fsd.CheckAncestorAccess(pc, iip, FsAction.Write);
                }
                // validate that we have enough inodes.
                fsn.CheckFsObjectLimit();
                // add symbolic link to namespace
                AddSymlink(fsd, link, iip, target, dirPerms, createParent, logRetryCache);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            NameNode.GetNameNodeMetrics().IncrCreateSymlinkOps();
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #9
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus SetTimes(FSDirectory fsd, string src, long mtime,
                                                long atime)
        {
            if (!fsd.IsAccessTimeSupported() && atime != -1)
            {
                throw new IOException("Access time for hdfs is not configured. " + " Please set "
                                      + DFSConfigKeys.DfsNamenodeAccesstimePrecisionKey + " configuration parameter."
                                      );
            }
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][]     pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                src = fsd.ResolvePath(pc, src, pathComponents);
                iip = fsd.GetINodesInPath4Write(src);
                // Write access is required to set access and modification times
                if (fsd.IsPermissionEnabled())
                {
                    fsd.CheckPathAccess(pc, iip, FsAction.Write);
                }
                INode inode = iip.GetLastINode();
                if (inode == null)
                {
                    throw new FileNotFoundException("File/Directory " + src + " does not exist.");
                }
                bool changed = UnprotectedSetTimes(fsd, inode, mtime, atime, true, iip.GetLatestSnapshotId
                                                       ());
                if (changed)
                {
                    fsd.GetEditLog().LogTimes(src, mtime, atime);
                }
            }
            finally
            {
                fsd.WriteUnlock();
            }
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #10
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus Concat(FSDirectory fsd, string target, string[] srcs
                                              , bool logRetryCache)
        {
            Preconditions.CheckArgument(!target.IsEmpty(), "Target file name is empty");
            Preconditions.CheckArgument(srcs != null && srcs.Length > 0, "No sources given");
            System.Diagnostics.Debug.Assert(srcs != null);
            if (FSDirectory.Log.IsDebugEnabled())
            {
                FSDirectory.Log.Debug("concat {} to {}", Arrays.ToString(srcs), target);
            }
            INodesInPath targetIIP = fsd.GetINodesInPath4Write(target);
            // write permission for the target
            FSPermissionChecker pc = null;

            if (fsd.IsPermissionEnabled())
            {
                pc = fsd.GetPermissionChecker();
                fsd.CheckPathAccess(pc, targetIIP, FsAction.Write);
            }
            // check the target
            VerifyTargetFile(fsd, target, targetIIP);
            // check the srcs
            INodeFile[] srcFiles = VerifySrcFiles(fsd, srcs, targetIIP, pc);
            if (NameNode.stateChangeLog.IsDebugEnabled())
            {
                NameNode.stateChangeLog.Debug("DIR* NameSystem.concat: " + Arrays.ToString(srcs)
                                              + " to " + target);
            }
            long timestamp = Time.Now();

            fsd.WriteLock();
            try
            {
                UnprotectedConcat(fsd, targetIIP, srcFiles, timestamp);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogConcat(target, srcs, timestamp, logRetryCache);
            return(fsd.GetAuditFileInfo(targetIIP));
        }
Пример #11
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus SetStoragePolicy(FSDirectory fsd, BlockManager bm,
                                                        string src, string policyName)
        {
            if (!fsd.IsStoragePolicyEnabled())
            {
                throw new IOException("Failed to set storage policy since " + DFSConfigKeys.DfsStoragePolicyEnabledKey
                                      + " is set to false.");
            }
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][]     pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                src = FSDirectory.ResolvePath(src, pathComponents, fsd);
                iip = fsd.GetINodesInPath4Write(src);
                if (fsd.IsPermissionEnabled())
                {
                    fsd.CheckPathAccess(pc, iip, FsAction.Write);
                }
                // get the corresponding policy and make sure the policy name is valid
                BlockStoragePolicy policy = bm.GetStoragePolicy(policyName);
                if (policy == null)
                {
                    throw new HadoopIllegalArgumentException("Cannot find a block policy with the name "
                                                             + policyName);
                }
                UnprotectedSetStoragePolicy(fsd, bm, iip, policy.GetId());
                fsd.GetEditLog().LogSetStoragePolicy(src, policy.GetId());
            }
            finally
            {
                fsd.WriteUnlock();
            }
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #12
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus SetPermission(FSDirectory fsd, string srcArg, FsPermission
                                                     permission)
        {
            string src             = srcArg;
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][]     pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                src = fsd.ResolvePath(pc, src, pathComponents);
                iip = fsd.GetINodesInPath4Write(src);
                fsd.CheckOwner(pc, iip);
                UnprotectedSetPermission(fsd, src, permission);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogSetPermissions(src, permission);
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #13
0
        /// <summary>Remove an xattr for a file or directory.</summary>
        /// <param name="src">- path to remove the xattr from</param>
        /// <param name="xAttr">- xAttr to remove</param>
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus RemoveXAttr(FSDirectory fsd, string src, XAttr xAttr
                                                   , bool logRetryCache)
        {
            FSDirXAttrOp.CheckXAttrsConfigFlag(fsd);
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            XAttrPermissionFilter.CheckPermissionForApi(pc, xAttr, FSDirectory.IsReservedRawName
                                                            (src));
            byte[][]      pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            IList <XAttr> xAttrs         = Lists.NewArrayListWithCapacity(1);

            xAttrs.AddItem(xAttr);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                src = fsd.ResolvePath(pc, src, pathComponents);
                iip = fsd.GetINodesInPath4Write(src);
                CheckXAttrChangeAccess(fsd, iip, xAttr, pc);
                IList <XAttr> removedXAttrs = UnprotectedRemoveXAttrs(fsd, src, xAttrs);
                if (removedXAttrs != null && !removedXAttrs.IsEmpty())
                {
                    fsd.GetEditLog().LogRemoveXAttrs(src, removedXAttrs, logRetryCache);
                }
                else
                {
                    throw new IOException("No matching attributes found for remove operation");
                }
            }
            finally
            {
                fsd.WriteUnlock();
            }
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #14
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus Mkdirs(FSNamesystem fsn, string src, PermissionStatus
                                              permissions, bool createParent)
        {
            FSDirectory fsd = fsn.GetFSDirectory();

            if (NameNode.stateChangeLog.IsDebugEnabled())
            {
                NameNode.stateChangeLog.Debug("DIR* NameSystem.mkdirs: " + src);
            }
            if (!DFSUtil.IsValidName(src))
            {
                throw new InvalidPathException(src);
            }
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            fsd.WriteLock();
            try
            {
                src = fsd.ResolvePath(pc, src, pathComponents);
                INodesInPath iip = fsd.GetINodesInPath4Write(src);
                if (fsd.IsPermissionEnabled())
                {
                    fsd.CheckTraverse(pc, iip);
                }
                INode lastINode = iip.GetLastINode();
                if (lastINode != null && lastINode.IsFile())
                {
                    throw new FileAlreadyExistsException("Path is not a directory: " + src);
                }
                INodesInPath existing = lastINode != null ? iip : iip.GetExistingINodes();
                if (lastINode == null)
                {
                    if (fsd.IsPermissionEnabled())
                    {
                        fsd.CheckAncestorAccess(pc, iip, FsAction.Write);
                    }
                    if (!createParent)
                    {
                        fsd.VerifyParentDir(iip, src);
                    }
                    // validate that we have enough inodes. This is, at best, a
                    // heuristic because the mkdirs() operation might need to
                    // create multiple inodes.
                    fsn.CheckFsObjectLimit();
                    IList <string> nonExisting = iip.GetPath(existing.Length(), iip.Length() - existing
                                                             .Length());
                    int length = nonExisting.Count;
                    if (length > 1)
                    {
                        IList <string> ancestors = nonExisting.SubList(0, length - 1);
                        // Ensure that the user can traversal the path by adding implicit
                        // u+wx permission to all ancestor directories
                        existing = CreateChildrenDirectories(fsd, existing, ancestors, AddImplicitUwx(permissions
                                                                                                      , permissions));
                        if (existing == null)
                        {
                            throw new IOException("Failed to create directory: " + src);
                        }
                    }
                    if ((existing = CreateChildrenDirectories(fsd, existing, nonExisting.SubList(length
                                                                                                 - 1, length), permissions)) == null)
                    {
                        throw new IOException("Failed to create directory: " + src);
                    }
                }
                return(fsd.GetAuditFileInfo(existing));
            }
            finally
            {
                fsd.WriteUnlock();
            }
        }