Hi,

I have this buggy patch here to get mmap() working on nfs.
Simply apply it, compile nfs and try to mmap a file from it.  For me, the
computer locks solid :) but hey, your mileage may vary.  I don't know how
much time I will have to debug this in the next time, so someone please beat
me to it!  (I did not really wrote any of that code, so it's as hard for you
as it is for me).  The netfs_S_io_map implementation is ripped from
libdiskfs, pager.c was in nfs/ but never used.

Thanks,
Marcus

-- 
`Rhubarb is no Egyptian god.' Debian http://www.debian.org [EMAIL PROTECTED]
Marcus Brinkmann              GNU    http://www.gnu.org    [EMAIL PROTECTED]
[EMAIL PROTECTED]
http://www.marcus-brinkmann.de
diff -Nrup -x CVS /mnt/marcus/gnu/cvs/hurd/nfs/ChangeLog nfs/ChangeLog
--- /mnt/marcus/gnu/cvs/hurd/nfs/ChangeLog      Tue Jan 30 01:36:24 2001
+++ nfs/ChangeLog       Wed Oct 31 01:14:17 2001
@@ -1,3 +1,17 @@
+2001-10-30  Marcus Brinkmann  <[EMAIL PROTECTED]>
+
+       * pager.c (pager_read_page): Add argument to NFSPROC_READ.
+       (pager_write_page): Likewise.
+       (netfs_pager_user): Return 1 on success.
+       (pager_initialize): Add missing closing bracket.
+       * iostubs.c: New file.
+       * Makefile (SRCS): Add iostubs.c and pager.c.
+       (HURDLIBS): Add pager, ihash and shouldbeinlibc.
+       * cache.c (lookup_fhandle): Clear fileinfo member in NN.
+       * main.c (main): Call pager_initialize.
+       * nfs.h: Add prototypes for netfs_get_filemap and pager_initialize.
+       * ops.c (netfs_set_translator): Remove stub.
+
 2000-12-26  Neal H Walfield <[EMAIL PROTECTED]>
 
        * cache.c: Change cache/hash table size to 509, a prime.  Use
diff -Nrup -x CVS /mnt/marcus/gnu/cvs/hurd/nfs/Makefile nfs/Makefile
--- /mnt/marcus/gnu/cvs/hurd/nfs/Makefile       Thu Jul 27 18:50:55 2000
+++ nfs/Makefile        Wed Oct 31 01:10:45 2001
@@ -23,8 +23,8 @@ makemode := server
 
 target = nfs
 LCLHDRS = nfs.h mount.h nfs-spec.h
-SRCS = ops.c rpc.c mount.c nfs.c cache.c consts.c main.c name-cache.c
+SRCS = ops.c rpc.c mount.c nfs.c cache.c consts.c main.c name-cache.c iostubs.c 
+pager.c
 OBJS = $(subst .c,.o,$(SRCS))
-HURDLIBS = netfs fshelp iohelp threads ports
+HURDLIBS = netfs pager iohelp fshelp threads ports ihash shouldbeinlibc
 
 include ../Makeconf
diff -Nrup -x CVS /mnt/marcus/gnu/cvs/hurd/nfs/cache.c nfs/cache.c
--- /mnt/marcus/gnu/cvs/hurd/nfs/cache.c        Tue Jan 30 01:36:24 2001
+++ nfs/cache.c Tue Oct 30 22:07:43 2001
@@ -82,7 +82,8 @@ lookup_fhandle (void *p, size_t len, str
   nn->dtrans = NOT_POSSIBLE;
   nn->dead_dir = 0;
   nn->dead_name = 0;
-  
+  nn->fileinfo = 0;
+
   np = netfs_make_node (nn);
   mutex_lock (&np->lock);
   nn->hnext = nodehash[h];
diff -Nrup -x CVS /mnt/marcus/gnu/cvs/hurd/nfs/iostubs.c nfs/iostubs.c
--- /mnt/marcus/gnu/cvs/hurd/nfs/iostubs.c      Thu Jan  1 01:00:00 1970
+++ nfs/iostubs.c       Tue Oct 30 21:14:54 2001
@@ -0,0 +1,131 @@
+/* 
+   Copyright (C) 1994, 1997, 2001 Free Software Foundation
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <fcntl.h>
+
+#include <hurd/netfs.h>
+#include "io_S.h"
+#include "nfs.h"
+
+/* Implement io_map as described in <hurd/io.defs>. */
+kern_return_t
+netfs_S_io_map (struct protid *cred,
+               memory_object_t *rdobj,
+               mach_msg_type_name_t *rdtype,
+               memory_object_t *wrobj,
+               mach_msg_type_name_t *wrtype)
+{
+  int flags;
+  struct node *node;
+
+  if (!cred)
+    return EOPNOTSUPP;
+
+  *wrobj = *rdobj = MACH_PORT_NULL;
+
+  node = cred->po->np;
+  flags = cred->po->openstat & (O_READ | O_WRITE);
+
+  mutex_lock (&node->lock);
+  switch (flags)
+    {
+    case O_READ | O_WRITE:
+      *wrobj = *rdobj = netfs_get_filemap (node, VM_PROT_READ |VM_PROT_WRITE);
+      if (*wrobj == MACH_PORT_NULL)
+       goto error;
+      mach_port_mod_refs (mach_task_self (), *rdobj, MACH_PORT_RIGHT_SEND, 1);
+      break;
+    case O_READ:
+      *rdobj = netfs_get_filemap (node, VM_PROT_READ);
+      if (*rdobj == MACH_PORT_NULL)
+       goto error;
+      break;
+    case O_WRITE:
+      *wrobj = netfs_get_filemap (node, VM_PROT_WRITE);
+      if (*wrobj == MACH_PORT_NULL)
+       goto error;
+      break;
+    }
+  mutex_unlock (&node->lock);
+
+  *rdtype = MACH_MSG_TYPE_MOVE_SEND;
+  *wrtype = MACH_MSG_TYPE_MOVE_SEND;
+
+  return 0;
+  
+error:
+  mutex_unlock (&node->lock);
+  return errno;
+}
+
+error_t
+netfs_S_io_map_cntl (struct protid *user,
+                    mach_port_t *obj,
+                    mach_msg_type_name_t *objtype)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+netfs_S_io_get_conch (struct protid *user)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+netfs_S_io_release_conch (struct protid *user)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+netfs_S_io_eofnotify (struct protid *user)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+netfs_S_io_prenotify (struct protid *user,
+                     vm_offset_t start, vm_offset_t stop)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+netfs_S_io_postnotify (struct protid *user,
+                      vm_offset_t start, vm_offset_t stop)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+netfs_S_io_readnotify (struct protid *user)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+netfs_S_io_readsleep (struct protid *user)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+netfs_S_io_sigio (struct protid *user)
+{
+  return EOPNOTSUPP;
+}
diff -Nrup -x CVS /mnt/marcus/gnu/cvs/hurd/nfs/main.c nfs/main.c
--- /mnt/marcus/gnu/cvs/hurd/nfs/main.c Tue Jan 30 01:36:24 2001
+++ nfs/main.c  Tue Oct 30 22:13:27 2001
@@ -389,7 +389,9 @@ main (int argc, char **argv)
 
   cthread_detach (cthread_fork ((cthread_fn_t) timeout_service_thread, 0));
   cthread_detach (cthread_fork ((cthread_fn_t) rpc_receive_thread, 0));
-  
+
+  pager_initialize ();
+
   hostname = localhost ();
 
   netfs_root_node = mount_root (remote_fs, host);
diff -Nrup -x CVS /mnt/marcus/gnu/cvs/hurd/nfs/nfs.h nfs/nfs.h
--- /mnt/marcus/gnu/cvs/hurd/nfs/nfs.h  Tue Jan 30 01:36:24 2001
+++ nfs/nfs.h   Tue Oct 30 22:13:40 2001
@@ -197,4 +197,8 @@ void purge_lookup_cache (struct node *, 
 struct node *check_lookup_cache (struct node *, char *);
 void purge_lookup_cache_node (struct node *);
 
+/* pager.c */
+mach_port_t netfs_get_filemap (struct node *np, vm_prot_t prot);
+void pager_initialize (void);
+
 #endif /* NFS_NFS_H */
diff -Nrup -x CVS /mnt/marcus/gnu/cvs/hurd/nfs/ops.c nfs/ops.c
--- /mnt/marcus/gnu/cvs/hurd/nfs/ops.c  Tue Jan 30 01:36:24 2001
+++ nfs/ops.c   Tue Oct 30 21:26:57 2001
@@ -1818,17 +1818,6 @@ netfs_get_dirents (struct iouser *cred, 
 }
 
 
-/* Implement the netfs_set_translator callback as described in
-   <hurd/netfs.h>. */
-error_t
-netfs_set_translator (struct iouser *cred,
-                     struct node *np,
-                     char *argz,
-                     size_t argzlen)
-{
-  return EOPNOTSUPP;
-}
-
 /* Implement the netfs_attempt_mksymlink callback as described in
    <hurd/netfs.h>. */
 error_t
diff -Nrup -x CVS /mnt/marcus/gnu/cvs/hurd/nfs/pager.c nfs/pager.c
--- /mnt/marcus/gnu/cvs/hurd/nfs/pager.c        Sun Jul 11 07:31:15 1999
+++ nfs/pager.c Tue Oct 30 14:50:35 2001
@@ -130,7 +130,8 @@ pager_read_page (struct user_pager_info 
       if (thisamt > read_size)
        thisamt = read_size;
 
-      p = nfs_initialize_rpc (NFSPROC_READ, (struct iouser *)-1, 0, 
+      p = nfs_initialize_rpc (NFSPROC_READ (protocol_version),
+                             (struct iouser *)-1, 0, 
                              &rpcbuf, np, -1);
       p = xdr_encode_fhandle (p, &np->nn->handle);
       *p++ = htonl (offset);
@@ -198,7 +199,8 @@ pager_write_page (struct user_pager_info
       if (amt > write_size)
        amt = write_size;
       
-      p = nfs_initialize_rpc (NFSPROC_WRITE, (struct iouser *) -1, 
+      p = nfs_initialize_rpc (NFSPROC_WRITE (protocol_version),
+                             (struct iouser *) -1, 
                              amt, &rpcbuf, np, -1);
       p = xdr_encode_fhandle (p, &np->nn->handle);
       *p++ = 0;
@@ -396,6 +398,7 @@ netfs_pager_users ()
   enable_caching ();
 
   ports_enable_bucket (pager_bucket);
+  return 1;
 }
 
 vm_prot_t
@@ -453,4 +456,4 @@ pager_initialize (void)
 {
   pager_bucket = ports_create_bucket ();
   cthread_detach (cthread_fork (flush_pager_cache_thread, 0));
-  
+}

Reply via email to