Exemplo n.º 1
0
        public override XDR Dump(XDR @out, int xid, IPAddress client)
        {
            if (Log.IsDebugEnabled())
            {
                Log.Debug("MOUNT NULLOP : " + " client: " + client);
            }
            IList <MountEntry> copy = new AList <MountEntry>(mounts);

            MountResponse.WriteMountList(@out, xid, copy);
            return(@out);
        }
Exemplo n.º 2
0
        public override XDR Mnt(XDR xdr, XDR @out, int xid, IPAddress client)
        {
            if (hostsMatcher == null)
            {
                return(MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errAcces, @out, xid, null));
            }
            AccessPrivilege accessPrivilege = hostsMatcher.GetAccessPrivilege(client);

            if (accessPrivilege == AccessPrivilege.None)
            {
                return(MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errAcces, @out, xid, null));
            }
            string path = xdr.ReadString();

            if (Log.IsDebugEnabled())
            {
                Log.Debug("MOUNT MNT path: " + path + " client: " + client);
            }
            string host = client.GetHostName();

            if (Log.IsDebugEnabled())
            {
                Log.Debug("Got host: " + host + " path: " + path);
            }
            if (!exports.Contains(path))
            {
                Log.Info("Path " + path + " is not shared.");
                MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errNoent, @out, xid, null);
                return(@out);
            }
            FileHandle handle = null;

            try
            {
                HdfsFileStatus exFileStatus = dfsClient.GetFileInfo(path);
                handle = new FileHandle(exFileStatus.GetFileId());
            }
            catch (IOException e)
            {
                Log.Error("Can't get handle for export:" + path, e);
                MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errNoent, @out, xid, null);
                return(@out);
            }
            System.Diagnostics.Debug.Assert((handle != null));
            Log.Info("Giving handle (fileId:" + handle.GetFileId() + ") to client for export "
                     + path);
            mounts.AddItem(new MountEntry(host, path));
            MountResponse.WriteMNTResponse(Nfs3Status.Nfs3Ok, @out, xid, handle.GetContent());
            return(@out);
        }
Exemplo n.º 3
0
        protected override void HandleInternal(ChannelHandlerContext ctx, RpcInfo info)
        {
            RpcCall rpcCall = (RpcCall)info.Header();

            MountInterface.MNTPROC mntproc = MountInterface.MNTPROC.FromValue(rpcCall.GetProcedure
                                                                                  ());
            int xid = rpcCall.GetXid();

            byte[] data = new byte[info.Data().ReadableBytes()];
            info.Data().ReadBytes(data);
            XDR       xdr    = new XDR(data);
            XDR       @out   = new XDR();
            IPAddress client = ((IPEndPoint)info.RemoteAddress()).Address;

            if (mntproc == MountInterface.MNTPROC.Null)
            {
                @out = NullOp(@out, xid, client);
            }
            else
            {
                if (mntproc == MountInterface.MNTPROC.Mnt)
                {
                    // Only do port monitoring for MNT
                    if (!DoPortMonitoring(info.RemoteAddress()))
                    {
                        @out = MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errAcces, @out, xid, null);
                    }
                    else
                    {
                        @out = Mnt(xdr, @out, xid, client);
                    }
                }
                else
                {
                    if (mntproc == MountInterface.MNTPROC.Dump)
                    {
                        @out = Dump(@out, xid, client);
                    }
                    else
                    {
                        if (mntproc == MountInterface.MNTPROC.Umnt)
                        {
                            @out = Umnt(xdr, @out, xid, client);
                        }
                        else
                        {
                            if (mntproc == MountInterface.MNTPROC.Umntall)
                            {
                                Umntall(@out, xid, client);
                            }
                            else
                            {
                                if (mntproc == MountInterface.MNTPROC.Export)
                                {
                                    // Currently only support one NFS export
                                    IList <NfsExports> hostsMatchers = new AList <NfsExports>();
                                    if (hostsMatcher != null)
                                    {
                                        hostsMatchers.AddItem(hostsMatcher);
                                        @out = MountResponse.WriteExportList(@out, xid, exports, hostsMatchers);
                                    }
                                    else
                                    {
                                        // This means there are no valid exports provided.
                                        RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone
                                                                         ()).Write(@out);
                                    }
                                }
                                else
                                {
                                    // Invalid procedure
                                    RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone
                                                                     ()).Write(@out);
                                }
                            }
                        }
                    }
                }
            }
            ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer());
            RpcResponse   rsp = new RpcResponse(buf, info.RemoteAddress());

            RpcUtil.SendRpcResponse(ctx, rsp);
        }