예제 #1
0
        /// <summary>Create a new encryption zone.</summary>
        /// <remarks>
        /// Create a new encryption zone.
        /// <p/>
        /// Called while holding the FSDirectory lock.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        internal virtual XAttr CreateEncryptionZone(string src, CipherSuite suite, CryptoProtocolVersion
                                                    version, string keyName)
        {
            System.Diagnostics.Debug.Assert(dir.HasWriteLock());
            INodesInPath srcIIP = dir.GetINodesInPath4Write(src, false);

            if (dir.IsNonEmptyDirectory(srcIIP))
            {
                throw new IOException("Attempt to create an encryption zone for a non-empty directory."
                                      );
            }
            if (srcIIP != null && srcIIP.GetLastINode() != null && !srcIIP.GetLastINode().IsDirectory
                    ())
            {
                throw new IOException("Attempt to create an encryption zone for a file.");
            }
            EncryptionZoneManager.EncryptionZoneInt ezi = GetEncryptionZoneForPath(srcIIP);
            if (ezi != null)
            {
                throw new IOException("Directory " + src + " is already in an " + "encryption zone. ("
                                      + GetFullPathName(ezi) + ")");
            }
            HdfsProtos.ZoneEncryptionInfoProto proto = PBHelper.Convert(suite, version, keyName
                                                                        );
            XAttr ezXAttr = XAttrHelper.BuildXAttr(HdfsServerConstants.CryptoXattrEncryptionZone
                                                   , proto.ToByteArray());
            IList <XAttr> xattrs = Lists.NewArrayListWithCapacity(1);

            xattrs.AddItem(ezXAttr);
            // updating the xattr will call addEncryptionZone,
            // done this way to handle edit log loading
            FSDirXAttrOp.UnprotectedSetXAttrs(dir, src, xattrs, EnumSet.Of(XAttrSetFlag.Create
                                                                           ));
            return(ezXAttr);
        }
예제 #2
0
        /// <summary>Remove a file/directory from the namespace.</summary>
        /// <remarks>
        /// Remove a file/directory from the namespace.
        /// <p>
        /// For large directories, deletion is incremental. The blocks under
        /// the directory are collected and deleted a small number at a time holding
        /// the
        /// <see cref="FSNamesystem"/>
        /// lock.
        /// <p>
        /// For small directory or file the deletion is done in one shot.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        internal static INode.BlocksMapUpdateInfo Delete(FSNamesystem fsn, string src, bool
                                                         recursive, bool logRetryCache)
        {
            FSDirectory         fsd = fsn.GetFSDirectory();
            FSPermissionChecker pc  = fsd.GetPermissionChecker();

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

            if (!recursive && fsd.IsNonEmptyDirectory(iip))
            {
                throw new PathIsNotEmptyDirectoryException(src + " is non empty");
            }
            if (fsd.IsPermissionEnabled())
            {
                fsd.CheckPermission(pc, iip, false, null, FsAction.Write, null, FsAction.All, true
                                    );
            }
            return(DeleteInternal(fsn, src, iip, logRetryCache));
        }