summaryrefslogtreecommitdiff
path: root/nfsd
diff options
context:
space:
mode:
Diffstat (limited to 'nfsd')
-rw-r--r--nfsd/Makefile3
-rw-r--r--nfsd/cache.c71
-rw-r--r--nfsd/loop.c5
-rw-r--r--nfsd/main.c23
-rw-r--r--nfsd/nfsd.h6
5 files changed, 63 insertions, 45 deletions
diff --git a/nfsd/Makefile b/nfsd/Makefile
index 5487a946..daaf86e8 100644
--- a/nfsd/Makefile
+++ b/nfsd/Makefile
@@ -24,7 +24,8 @@ SRCS = cache.c loop.c main.c ops.c fsys.c xdr.c
OBJS = $(subst .c,.o,$(SRCS))
target = nfsd
installationdir = $(sbindir)
-HURDLIBS=threads shouldbeinlibc
+HURDLIBS = shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/nfsd/cache.c b/nfsd/cache.c
index 7b96dbc2..060cc738 100644
--- a/nfsd/cache.c
+++ b/nfsd/cache.c
@@ -24,6 +24,7 @@
#include <hurd/fsys.h>
#include <assert.h>
#include <string.h>
+#include <pthread.h>
#include <hurd/io.h>
#include <hurd/auth.h>
#include "nfsd.h"
@@ -42,7 +43,7 @@
static struct idspec *idhashtable[IDHASH_TABLE_SIZE];
-spin_lock_t idhashlock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t idhashlock = PTHREAD_SPINLOCK_INITIALIZER;
static int nfreeids;
static int leastidlastuse;
@@ -90,14 +91,14 @@ idspec_lookup (int nuids, int ngids, int *uids, int *gids)
hash = idspec_hash (nuids, ngids, uids, gids);
- spin_lock (&idhashlock);
+ pthread_spin_lock (&idhashlock);
for (i = idhashtable[hash]; i; i = i->next)
if (idspec_compare (i, nuids, ngids, uids, gids))
{
i->references++;
if (i->references == 1)
nfreeids--;
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
return i;
}
@@ -117,7 +118,7 @@ idspec_lookup (int nuids, int ngids, int *uids, int *gids)
i->prevp = &idhashtable[hash];
idhashtable[hash] = i;
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
return i;
}
@@ -184,7 +185,7 @@ process_cred (int *p, struct idspec **credp)
void
cred_rele (struct idspec *i)
{
- spin_lock (&idhashlock);
+ pthread_spin_lock (&idhashlock);
i->references--;
if (i->references == 0)
{
@@ -193,16 +194,16 @@ cred_rele (struct idspec *i)
leastidlastuse = i->lastuse;
nfreeids++;
}
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
}
void
cred_ref (struct idspec *i)
{
- spin_lock (&idhashlock);
+ pthread_spin_lock (&idhashlock);
assert (i->references);
i->references++;
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
}
void
@@ -211,7 +212,7 @@ scan_creds ()
int n;
int newleast = mapped_time->seconds;
- spin_lock (&idhashlock);
+ pthread_spin_lock (&idhashlock);
if (mapped_time->seconds - leastidlastuse > ID_KEEP_TIMEOUT)
{
@@ -245,13 +246,13 @@ scan_creds ()
if (nfreeids)
leastidlastuse = newleast;
}
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
}
static struct cache_handle *fhhashtable[FHHASH_TABLE_SIZE];
-struct mutex fhhashlock = MUTEX_INITIALIZER;
+pthread_mutex_t fhhashlock = PTHREAD_MUTEX_INITIALIZER;
static int nfreefh;
static int leastfhlastuse;
@@ -275,14 +276,14 @@ lookup_cache_handle (int *p, struct cache_handle **cp, struct idspec *i)
file_t port;
hash = fh_hash ((char *)p, i);
- mutex_lock (&fhhashlock);
+ pthread_mutex_lock (&fhhashlock);
for (c = fhhashtable[hash]; c; c = c->next)
if (c->ids == i && ! bcmp (c->handle, p, NFS2_FHSIZE))
{
if (c->references == 0)
nfreefh--;
c->references++;
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
*cp = c;
return p + NFS2_FHSIZE / sizeof (int);
}
@@ -295,7 +296,7 @@ lookup_cache_handle (int *p, struct cache_handle **cp, struct idspec *i)
|| fsys_getfile (fsys, i->uids, i->nuids, i->gids, i->ngids,
(char *)(p + 1), NFS2_FHSIZE - sizeof (int), &port))
{
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
*cp = 0;
return p + NFS2_FHSIZE / sizeof (int);
}
@@ -313,7 +314,7 @@ lookup_cache_handle (int *p, struct cache_handle **cp, struct idspec *i)
c->prevp = &fhhashtable[hash];
fhhashtable[hash] = c;
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
*cp = c;
return p + NFS2_FHSIZE / sizeof (int);
}
@@ -321,7 +322,7 @@ lookup_cache_handle (int *p, struct cache_handle **cp, struct idspec *i)
void
cache_handle_rele (struct cache_handle *c)
{
- mutex_lock (&fhhashlock);
+ pthread_mutex_lock (&fhhashlock);
c->references--;
if (c->references == 0)
{
@@ -330,7 +331,7 @@ cache_handle_rele (struct cache_handle *c)
leastfhlastuse = c->lastuse;
nfreefh++;
}
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
}
void
@@ -339,7 +340,7 @@ scan_fhs ()
int n;
int newleast = mapped_time->seconds;
- mutex_lock (&fhhashlock);
+ pthread_mutex_lock (&fhhashlock);
if (mapped_time->seconds - leastfhlastuse > FH_KEEP_TIMEOUT)
{
@@ -373,7 +374,7 @@ scan_fhs ()
if (nfreefh)
leastfhlastuse = newleast;
}
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
}
struct cache_handle *
@@ -416,7 +417,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
/* Cache it. */
hash = fh_hash (fhandle, credc->ids);
- mutex_lock (&fhhashlock);
+ pthread_mutex_lock (&fhhashlock);
for (c = fhhashtable[hash]; c; c = c->next)
if (c->ids == credc->ids && ! bcmp (fhandle, c->handle, NFS2_FHSIZE))
{
@@ -424,7 +425,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
if (c->references == 0)
nfreefh--;
c->references++;
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
return c;
}
@@ -438,7 +439,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
&newport);
if (err)
{
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
return 0;
}
@@ -456,7 +457,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
c->next->prevp = &c->next;
c->prevp = &fhhashtable[hash];
fhhashtable[hash] = c;
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
return c;
}
@@ -464,7 +465,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
static struct cached_reply *replyhashtable [REPLYHASH_TABLE_SIZE];
-static spin_lock_t replycachelock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t replycachelock = PTHREAD_SPINLOCK_INITIALIZER;
static int nfreereplies;
static int leastreplylastuse;
@@ -480,7 +481,7 @@ check_cached_replies (int xid,
hash = abs(xid % REPLYHASH_TABLE_SIZE);
- spin_lock (&replycachelock);
+ pthread_spin_lock (&replycachelock);
for (cr = replyhashtable[hash]; cr; cr = cr->next)
if (cr->xid == xid
&& !bcmp (sender, &cr->source, sizeof (struct sockaddr_in)))
@@ -488,14 +489,14 @@ check_cached_replies (int xid,
cr->references++;
if (cr->references == 1)
nfreereplies--;
- spin_unlock (&replycachelock);
- mutex_lock (&cr->lock);
+ pthread_spin_unlock (&replycachelock);
+ pthread_mutex_lock (&cr->lock);
return cr;
}
cr = malloc (sizeof (struct cached_reply));
- mutex_init (&cr->lock);
- mutex_lock (&cr->lock);
+ pthread_mutex_init (&cr->lock, NULL);
+ pthread_mutex_lock (&cr->lock);
memcpy (&cr->source, sender, sizeof (struct sockaddr_in));
cr->xid = xid;
cr->data = 0;
@@ -507,7 +508,7 @@ check_cached_replies (int xid,
cr->prevp = &replyhashtable[hash];
replyhashtable[hash] = cr;
- spin_unlock (&replycachelock);
+ pthread_spin_unlock (&replycachelock);
return cr;
}
@@ -516,8 +517,8 @@ check_cached_replies (int xid,
void
release_cached_reply (struct cached_reply *cr)
{
- mutex_unlock (&cr->lock);
- spin_lock (&replycachelock);
+ pthread_mutex_unlock (&cr->lock);
+ pthread_spin_lock (&replycachelock);
cr->references--;
if (cr->references == 0)
{
@@ -526,7 +527,7 @@ release_cached_reply (struct cached_reply *cr)
leastreplylastuse = cr->lastuse;
nfreereplies++;
}
- spin_unlock (&replycachelock);
+ pthread_spin_unlock (&replycachelock);
}
void
@@ -535,7 +536,7 @@ scan_replies ()
int n;
int newleast = mapped_time->seconds;
- spin_lock (&replycachelock);
+ pthread_spin_lock (&replycachelock);
if (mapped_time->seconds - leastreplylastuse > REPLY_KEEP_TIMEOUT)
{
@@ -569,5 +570,5 @@ scan_replies ()
if (nfreereplies)
leastreplylastuse = newleast;
}
- spin_unlock (&replycachelock);
+ pthread_spin_unlock (&replycachelock);
}
diff --git a/nfsd/loop.c b/nfsd/loop.c
index bfec5e5a..f2d6d546 100644
--- a/nfsd/loop.c
+++ b/nfsd/loop.c
@@ -35,9 +35,10 @@
#include <rpc/rpc_msg.h>
#undef malloc
-void
-server_loop (int fd)
+void *
+server_loop (void *arg)
{
+ int fd = (int) arg;
char buf[MAXIOSIZE];
int xid;
int *p, *r;
diff --git a/nfsd/main.c b/nfsd/main.c
index ee071090..d5607d37 100644
--- a/nfsd/main.c
+++ b/nfsd/main.c
@@ -24,6 +24,7 @@
#include <rpc/pmap_prot.h>
#include <maptime.h>
#include <hurd.h>
+#include <pthread.h>
#include <error.h>
int main_udp_socket, pmap_udp_socket;
@@ -31,6 +32,22 @@ struct sockaddr_in main_address, pmap_address;
static char index_file[] = LOCALSTATEDIR "/state/misc/nfsd.index";
char *index_file_name = index_file;
+/* Launch a server loop thread */
+static void
+create_server_thread (int socket)
+{
+ pthread_t thread;
+ int fail;
+
+ fail = pthread_create (&thread, NULL, server_loop, (void *) socket);
+ if (fail)
+ error (1, fail, "Creating main server thread");
+
+ fail = pthread_detach (thread);
+ if (fail)
+ error (1, fail, "Detaching main server thread");
+}
+
int
main (int argc, char **argv)
{
@@ -73,12 +90,10 @@ main (int argc, char **argv)
init_filesystems ();
- cthread_detach (cthread_fork ((cthread_fn_t) server_loop,
- (any_t)(intptr_t) pmap_udp_socket));
+ create_server_thread (pmap_udp_socket);
while (nthreads--)
- cthread_detach (cthread_fork ((cthread_fn_t) server_loop,
- (any_t)(intptr_t) main_udp_socket));
+ create_server_thread (main_udp_socket);
for (;;)
{
diff --git a/nfsd/nfsd.h b/nfsd/nfsd.h
index e89a411b..4afff061 100644
--- a/nfsd/nfsd.h
+++ b/nfsd/nfsd.h
@@ -22,7 +22,7 @@
#include <sys/socket.h>
#include <errno.h>
#include <netinet/in.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <rpc/types.h>
#include "../nfs/nfs-spec.h" /* XXX */
#include <hurd/fs.h>
@@ -55,7 +55,7 @@ struct cache_handle
struct cached_reply
{
struct cached_reply *next, **prevp;
- struct mutex lock;
+ pthread_mutex_t lock;
struct sockaddr_in source;
int xid;
time_t lastuse;
@@ -109,7 +109,7 @@ void release_cached_reply (struct cached_reply *cr);
void scan_replies (void);
/* loop.c */
-void server_loop (int);
+void * server_loop (void *);
/* ops.c */
extern struct proctable nfs2table, mounttable, pmaptable;