From 1de0643c9218db536f5b2e294bbfa653c77438e4 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Tue, 4 Sep 2012 00:33:09 +0200 Subject: Switch from cthreads to pthreads Makefiles, headers, types, macros and function calls are renamed where appropriate. Most of this work was done by Barry deFreese and Thomas DiModica. * auth/Makefile: Switch from cthreads to pthreads. * auth/auth.c: Likewise. * boot/Makefile: Likewise. * boot/boot.c: Likewise. * boot/ux.c: Likewise. * console-client/Makefile: Likewise. * console-client/console.c: Likewise. * console-client/driver.c: Likewise. * console-client/driver.h: Likewise. * console-client/generic-speaker.c: Likewise. * console-client/kbd-repeat.c: Likewise. * console-client/ncursesw.c: Likewise. * console-client/pc-kbd.c: Likewise. * console-client/pc-mouse.c: Likewise. * console-client/timer.c: Likewise. * console-client/trans.c: Likewise. * console-client/vga.c: Likewise. * console/Makefile: Likewise. * console/console.c: Likewise. * console/display.c: Likewise. * console/input.c: Likewise. * console/pager.c: Likewise. * defpager/backing.c: Likewise. * exec/Makefile: Likewise. * exec/exec.c: Likewise. * exec/hashexec.c: Likewise. * exec/priv.h: Likewise. * ext2fs/Makefile: Likewise. * ext2fs/balloc.c: Likewise. * ext2fs/dir.c: Likewise. * ext2fs/ext2fs.c: Likewise. * ext2fs/ext2fs.h: Likewise. * ext2fs/ialloc.c: Likewise. * ext2fs/inode.c: Likewise. * ext2fs/msg.c: Likewise. * ext2fs/pager.c: Likewise. * ext2fs/pokel.c: Likewise. * ext2fs/storeinfo.c: Likewise. * ext2fs/truncate.c: Likewise. * fatfs/Makefile: Likewise. * fatfs/dir.c: Likewise. * fatfs/fat.c: Likewise. * fatfs/fatfs.h: Likewise. * fatfs/inode.c: Likewise. * fatfs/main.c: Likewise. * fatfs/pager.c: Likewise. * fatfs/virt-inode.c: Likewise. * ftpfs/Makefile: Likewise. * ftpfs/ccache.c: Likewise. * ftpfs/ccache.h: Likewise. * ftpfs/conn.c: Likewise. * ftpfs/dir.c: Likewise. * ftpfs/fs.c: Likewise. * ftpfs/ftpfs.c: Likewise. * ftpfs/ftpfs.h: Likewise. * ftpfs/ncache.c: Likewise. * ftpfs/netfs.c: Likewise. * ftpfs/node.c: Likewise. * hostmux/Makefile: Likewise. * hostmux/hostmux.h: Likewise. * hostmux/mux.c: Likewise. * hostmux/node.c: Likewise. * hostmux/stubs.c: Likewise. * hurd/shared.h: Likewise. * isofs/Makefile: Likewise. * isofs/inode.c: Likewise. * isofs/lookup.c: Likewise. * isofs/main.c: Likewise. * isofs/pager.c: Likewise. * libcons/Makefile: Likewise. * libcons/cons-switch.c: Likewise. * libcons/cons.h: Likewise. * libcons/dir-changed.c: Likewise. * libcons/file-changed.c: Likewise. * libcons/init-init.c: Likewise. * libcons/vcons-close.c: Likewise. * libcons/vcons-input.c: Likewise. * libcons/vcons-move-mouse.c: Likewise. * libcons/vcons-open.c: Likewise. * libcons/vcons-scrollback.c: Likewise. * libdiskfs/Makefile: Likewise. * libdiskfs/boot-start.c: Likewise. * libdiskfs/dead-name.c: Likewise. * libdiskfs/dir-chg.c: Likewise. * libdiskfs/dir-link.c: Likewise. * libdiskfs/dir-lookup.c: Likewise. * libdiskfs/dir-mkdir.c: Likewise. * libdiskfs/dir-mkfile.c: Likewise. * libdiskfs/dir-readdir.c: Likewise. * libdiskfs/dir-rename.c: Likewise. * libdiskfs/dir-renamed.c: Likewise. * libdiskfs/dir-rmdir.c: Likewise. * libdiskfs/dir-unlink.c: Likewise. * libdiskfs/disk-pager.c: Likewise. * libdiskfs/diskfs-pager.h: Likewise. * libdiskfs/diskfs.h: Likewise. * libdiskfs/file-access.c: Likewise. * libdiskfs/file-chg.c: Likewise. * libdiskfs/file-exec.c: Likewise. * libdiskfs/file-get-fs-opts.c: Likewise. * libdiskfs/file-get-trans.c: Likewise. * libdiskfs/file-get-transcntl.c: Likewise. * libdiskfs/file-getcontrol.c: Likewise. * libdiskfs/file-getfh.c: Likewise. * libdiskfs/file-lock-stat.c: Likewise. * libdiskfs/file-lock.c: Likewise. * libdiskfs/file-reparent.c: Likewise. * libdiskfs/file-set-trans.c: Likewise. * libdiskfs/file-sync.c: Likewise. * libdiskfs/file-syncfs.c: Likewise. * libdiskfs/fsys-getroot.c: Likewise. * libdiskfs/fsys-options.c: Likewise. * libdiskfs/fsys-syncfs.c: Likewise. * libdiskfs/ifsock.c: Likewise. * libdiskfs/init-first.c: Likewise. * libdiskfs/init-init.c: Likewise. * libdiskfs/init-startup.c: Likewise. * libdiskfs/io-duplicate.c: Likewise. * libdiskfs/io-get-conch.c: Likewise. * libdiskfs/io-identity.c: Likewise. * libdiskfs/io-map-cntl.c: Likewise. * libdiskfs/io-map.c: Likewise. * libdiskfs/io-modes-get.c: Likewise. * libdiskfs/io-modes-off.c: Likewise. * libdiskfs/io-modes-on.c: Likewise. * libdiskfs/io-modes-set.c: Likewise. * libdiskfs/io-owner-get.c: Likewise. * libdiskfs/io-owner-mod.c: Likewise. * libdiskfs/io-prenotify.c: Likewise. * libdiskfs/io-read.c: Likewise. * libdiskfs/io-readable.c: Likewise. * libdiskfs/io-reauthenticate.c: Likewise. * libdiskfs/io-rel-conch.c: Likewise. * libdiskfs/io-restrict-auth.c: Likewise. * libdiskfs/io-revoke.c: Likewise. * libdiskfs/io-seek.c: Likewise. * libdiskfs/io-sigio.c: Likewise. * libdiskfs/io-stat.c: Likewise. * libdiskfs/io-write.c: Likewise. * libdiskfs/lookup.c: Likewise. * libdiskfs/name-cache.c: Likewise. * libdiskfs/node-drop.c: Likewise. * libdiskfs/node-make.c: Likewise. * libdiskfs/node-nput.c: Likewise. * libdiskfs/node-nputl.c: Likewise. * libdiskfs/node-nref.c: Likewise. * libdiskfs/node-nrefl.c: Likewise. * libdiskfs/node-nrele.c: Likewise. * libdiskfs/node-nrelel.c: Likewise. * libdiskfs/peropen-rele.c: Likewise. * libdiskfs/priv.h: Likewise. * libdiskfs/shutdown.c: Likewise. * libdiskfs/sync-interval.c: Likewise. * libfshelp/Makefile: Likewise. * libfshelp/fetch-root.c: Likewise. * libfshelp/fshelp.h: Likewise. * libfshelp/get-identity.c: Likewise. * libfshelp/lock-acquire.c: Likewise. * libfshelp/lock-init.c: Likewise. * libfshelp/locks.h: Likewise. * libfshelp/set-active.c: Likewise. * libfshelp/trans.h: Likewise. * libfshelp/transbox-init.c: Likewise. * libiohelp/Makefile: Likewise. * libiohelp/get_conch.c: Likewise. * libiohelp/handle_io_release_conch.c: Likewise. * libiohelp/initialize_conch.c: Likewise. * libiohelp/iohelp.h: Likewise. * libiohelp/verify_user_conch.c: Likewise. * libnetfs/Makefile: Likewise. * libnetfs/dir-lookup.c: Likewise. * libnetfs/dir-mkdir.c: Likewise. * libnetfs/dir-mkfile.c: Likewise. * libnetfs/dir-readdir.c: Likewise. * libnetfs/dir-rmdir.c: Likewise. * libnetfs/dir-unlink.c: Likewise. * libnetfs/drop-node.c: Likewise. * libnetfs/file-chauthor.c: Likewise. * libnetfs/file-check-access.c: Likewise. * libnetfs/file-chflags.c: Likewise. * libnetfs/file-chmod.c: Likewise. * libnetfs/file-chown.c: Likewise. * libnetfs/file-exec.c: Likewise. * libnetfs/file-get-storage-info.c: Likewise. * libnetfs/file-get-translator.c: Likewise. * libnetfs/file-lock-stat.c: Likewise. * libnetfs/file-lock.c: Likewise. * libnetfs/file-reparent.c: Likewise. * libnetfs/file-set-size.c: Likewise. * libnetfs/file-set-translator.c: Likewise. * libnetfs/file-statfs.c: Likewise. * libnetfs/file-sync.c: Likewise. * libnetfs/file-syncfs.c: Likewise. * libnetfs/file-utimes.c: Likewise. * libnetfs/fsys-getroot.c: Likewise. * libnetfs/fsys-set-options.c: Likewise. * libnetfs/init-init.c: Likewise. * libnetfs/io-clear-some-openmodes.c: Likewise. * libnetfs/io-duplicate.c: Likewise. * libnetfs/io-get-openmodes.c: Likewise. * libnetfs/io-get-owner.c: Likewise. * libnetfs/io-identity.c: Likewise. * libnetfs/io-mod-owner.c: Likewise. * libnetfs/io-read.c: Likewise. * libnetfs/io-readable.c: Likewise. * libnetfs/io-reauthenticate.c: Likewise. * libnetfs/io-restrict-auth.c: Likewise. * libnetfs/io-revoke.c: Likewise. * libnetfs/io-seek.c: Likewise. * libnetfs/io-set-all-openmodes.c: Likewise. * libnetfs/io-set-some-openmodes.c: Likewise. * libnetfs/io-stat.c: Likewise. * libnetfs/io-write.c: Likewise. * libnetfs/make-node.c: Likewise. * libnetfs/netfs.h: Likewise. * libnetfs/nput.c: Likewise. * libnetfs/nref.c: Likewise. * libnetfs/nrele.c: Likewise. * libnetfs/release-peropen.c: Likewise. * libnetfs/shutdown.c: Likewise. * libpager/Makefile: Likewise. * libpager/chg-compl.c: Likewise. * libpager/clean.c: Likewise. * libpager/data-request.c: Likewise. * libpager/data-return.c: Likewise. * libpager/data-unlock.c: Likewise. * libpager/inhibit-term.c: Likewise. * libpager/lock-completed.c: Likewise. * libpager/lock-object.c: Likewise. * libpager/mark-error.c: Likewise. * libpager/no-senders.c: Likewise. * libpager/object-init.c: Likewise. * libpager/object-terminate.c: Likewise. * libpager/offer-page.c: Likewise. * libpager/pager-attr.c: Likewise. * libpager/pager-create.c: Likewise. * libpager/pager-shutdown.c: Likewise. * libpager/priv.h: Likewise. * libpager/seqnos.c: Likewise. * libpipe/Makefile: Likewise. * libpipe/pipe.c: Likewise. * libpipe/pipe.h: Likewise. * libports/Makefile: Likewise. * libports/begin-rpc.c: Likewise. * libports/bucket-iterate.c: Likewise. * libports/claim-right.c: Likewise. * libports/class-iterate.c: Likewise. * libports/complete-deallocate.c: Likewise. * libports/count-bucket.c: Likewise. * libports/count-class.c: Likewise. * libports/create-bucket.c: Likewise. * libports/create-internal.c: Likewise. * libports/destroy-right.c: Likewise. * libports/enable-bucket.c: Likewise. * libports/enable-class.c: Likewise. * libports/end-rpc.c: Likewise. * libports/get-right.c: Likewise. * libports/import-port.c: Likewise. * libports/inhibit-all-rpcs.c: Likewise. * libports/inhibit-bucket-rpcs.c: Likewise. * libports/inhibit-class-rpcs.c: Likewise. * libports/inhibit-port-rpcs.c: Likewise. * libports/init.c: Likewise. * libports/interrupt-notified-rpcs.c: Likewise. * libports/interrupt-on-notify.c: Likewise. * libports/interrupt-operation.c: Likewise. * libports/interrupt-rpcs.c: Likewise. * libports/interrupted.c: Likewise. * libports/lookup-port.c: Likewise. * libports/manage-multithread.c: Likewise. * libports/no-senders.c: Likewise. * libports/port-deref-weak.c: Likewise. * libports/port-deref.c: Likewise. * libports/port-ref-weak.c: Likewise. * libports/port-ref.c: Likewise. * libports/ports.h: Likewise. * libports/reallocate-from-external.c: Likewise. * libports/reallocate-port.c: Likewise. * libports/resume-all-rpcs.c: Likewise. * libports/resume-bucket-rpcs.c: Likewise. * libports/resume-class-rpcs.c: Likewise. * libports/resume-port-rpcs.c: Likewise. * libports/stubs.c: Likewise. * libports/transfer-right.c: Likewise. * libstore/Makefile: Likewise. * libstore/gunzip.c: Likewise. * libstore/part.c: Likewise. * libstore/unzipstore.c: Likewise. * libthreads/Makefile: Likewise. * libtreefs/dir-lookup.c: Likewise. * libtreefs/fsys-getroot.c: Likewise. * libtreefs/fsys-hooks.c: Likewise. * libtreefs/fsys.c: Likewise. * libtreefs/trans-help.c: Likewise. * libtreefs/trans-start.c: Likewise. * libtreefs/treefs.h: Likewise. * libtrivfs/cntl-create.c: Likewise. * libtrivfs/dyn-classes.c: Likewise. * libtrivfs/io-reauthenticate.c: Likewise. * libtrivfs/io-restrict-auth.c: Likewise. * libtrivfs/protid-clean.c: Likewise. * libtrivfs/protid-dup.c: Likewise. * libtrivfs/trivfs.h: Likewise. * mach-defpager/Makefile: Likewise. * mach-defpager/default_pager.c: Likewise. * mach-defpager/kalloc.c: Likewise. * mach-defpager/main.c: Likewise. * nfs/Makefile: Likewise. * nfs/cache.c: Likewise. * nfs/main.c: Likewise. * nfs/mount.c: Likewise. * nfs/name-cache.c: Likewise. * nfs/nfs.h: Likewise. * nfs/ops.c: Likewise. * nfs/rpc.c: Likewise. * nfsd/Makefile: Likewise. * nfsd/cache.c: Likewise. * nfsd/loop.c: Likewise. * nfsd/main.c: Likewise. * nfsd/nfsd.h: Likewise. * pfinet/Makefile: Likewise. * pfinet/ethernet.c: Likewise. * pfinet/glue-include/asm/spinlock.h: Likewise. * pfinet/glue-include/linux/interrupt.h: Likewise. * pfinet/glue-include/linux/sched.h: Likewise. * pfinet/glue-include/linux/timer.h: Likewise. * pfinet/glue-include/linux/wait.h: Likewise. * pfinet/iioctl-ops.c: Likewise. * pfinet/io-ops.c: Likewise. * pfinet/kmem_cache.c: Likewise. * pfinet/main.c: Likewise. * pfinet/options.c: Likewise. * pfinet/pfinet-ops.c: Likewise. * pfinet/pfinet.h: Likewise. * pfinet/sched.c: Likewise. * pfinet/socket-ops.c: Likewise. * pfinet/socket.c: Likewise. * pfinet/timer-emul.c: Likewise. * pfinet/tunnel.c: Likewise. * pflocal/Makefile: Likewise. * pflocal/connq.c: Likewise. * pflocal/io.c: Likewise. * pflocal/sock.c: Likewise. * pflocal/sock.h: Likewise. * pflocal/socket.c: Likewise. * pflocal/sserver.c: Likewise. * proc/Makefile: Likewise. * proc/info.c: Likewise. * proc/main.c: Likewise. * proc/mgt.c: Likewise. * proc/msg.c: Likewise. * proc/proc.h: Likewise. * proc/stubs.c: Likewise. * proc/wait.c: Likewise. * storeio/Makefile: Likewise. * storeio/dev.c: Likewise. * storeio/dev.h: Likewise. * storeio/open.c: Likewise. * storeio/open.h: Likewise. * storeio/pager.c: Likewise. * storeio/storeio.c: Likewise. * term/Makefile: Likewise. * term/devio.c: Likewise. * term/hurdio.c: Likewise. * term/main.c: Likewise. * term/munge.c: Likewise. * term/ptyio.c: Likewise. * term/term.h: Likewise. * term/users.c: Likewise. * tmpfs/Makefile: Likewise. * tmpfs/dir.c: Likewise. * tmpfs/node.c: Likewise. * tmpfs/tmpfs.c: Likewise. * tmpfs/tmpfs.h: Likewise. * trans/Makefile: Likewise. * trans/fakeroot.c: Likewise. * trans/fifo.c: Likewise. * trans/hello-mt.c: Likewise. * trans/new-fifo.c: Likewise. * trans/streamio.c: Likewise. * ufs/Makefile: Likewise. * ufs/alloc.c: Likewise. * ufs/dir.c: Likewise. * ufs/hyper.c: Likewise. * ufs/inode.c: Likewise. * ufs/main.c: Likewise. * ufs/pager.c: Likewise. * ufs/pokeloc.c: Likewise. * ufs/sizes.c: Likewise. * ufs/ufs.h: Likewise. * usermux/Makefile: Likewise. * usermux/mux.c: Likewise. * usermux/node.c: Likewise. * usermux/usermux.h: Likewise. * utils/Makefile: Likewise. * utils/fakeauth.c: Likewise. * utils/rpctrace.c: Likewise. --- nfs/Makefile | 3 +- nfs/cache.c | 36 +++++++----- nfs/main.c | 20 ++++++- nfs/mount.c | 2 +- nfs/name-cache.c | 30 +++++----- nfs/nfs.h | 5 +- nfs/ops.c | 168 +++++++++++++++++++++++++++---------------------------- nfs/rpc.c | 44 +++++++++------ 8 files changed, 172 insertions(+), 136 deletions(-) (limited to 'nfs') diff --git a/nfs/Makefile b/nfs/Makefile index 86b10899..d814f67d 100644 --- a/nfs/Makefile +++ b/nfs/Makefile @@ -26,6 +26,7 @@ target = nfs SRCS = ops.c rpc.c mount.c nfs.c cache.c consts.c main.c name-cache.c \ storage-info.c OBJS = $(SRCS:.c=.o) -HURDLIBS = netfs fshelp iohelp threads ports ihash shouldbeinlibc +HURDLIBS = netfs fshelp iohelp ports ihash shouldbeinlibc +OTHERLIBS = -lpthread include ../Makeconf diff --git a/nfs/cache.c b/nfs/cache.c index 8f87f5d0..6e932573 100644 --- a/nfs/cache.c +++ b/nfs/cache.c @@ -21,6 +21,7 @@ #include "nfs.h" #include +#include #include /* Hash table containing all the nodes currently active. XXX Was 512, @@ -59,7 +60,7 @@ lookup_fhandle (void *p, size_t len, struct node **npp) h = hash (p, len); - spin_lock (&netfs_node_refcnt_lock); + pthread_spin_lock (&netfs_node_refcnt_lock); for (np = nodehash[h]; np; np = np->nn->hnext) { if (np->nn->handle.size != len @@ -67,8 +68,8 @@ lookup_fhandle (void *p, size_t len, struct node **npp) continue; np->references++; - spin_unlock (&netfs_node_refcnt_lock); - mutex_lock (&np->lock); + pthread_spin_unlock (&netfs_node_refcnt_lock); + pthread_mutex_lock (&np->lock); *npp = np; return; } @@ -85,14 +86,14 @@ lookup_fhandle (void *p, size_t len, struct node **npp) nn->dead_name = 0; np = netfs_make_node (nn); - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); nn->hnext = nodehash[h]; if (nn->hnext) nn->hnext->nn->hprevp = &nn->hnext; nn->hprevp = &nodehash[h]; nodehash[h] = np; - spin_unlock (&netfs_node_refcnt_lock); + pthread_spin_unlock (&netfs_node_refcnt_lock); *npp = np; } @@ -106,12 +107,12 @@ struct fnd /* Worker function to delete nodes that don't have any more local references or links. */ -any_t -forked_node_delete (any_t arg) +void * +forked_node_delete (void *arg) { struct fnd *args = arg; - mutex_lock (&args->dir->lock); + pthread_mutex_lock (&args->dir->lock); netfs_attempt_unlink ((struct iouser *)-1, args->dir, args->name); netfs_nput (args->dir); free (args->name); @@ -129,12 +130,14 @@ netfs_node_norefs (struct node *np) if (np->nn->dead_dir) { struct fnd *args; + pthread_t thread; + error_t err; args = malloc (sizeof (struct fnd)); assert (args); np->references++; - spin_unlock (&netfs_node_refcnt_lock); + pthread_spin_unlock (&netfs_node_refcnt_lock); args->dir = np->nn->dead_dir; args->name = np->nn->dead_name; @@ -145,10 +148,17 @@ netfs_node_norefs (struct node *np) /* Do this in a separate thread so that we don't wait for it; it acquires a lock on the dir, which we are not allowed to do. */ - cthread_detach (cthread_fork (forked_node_delete, (any_t) args)); + err = pthread_create (&thread, NULL, forked_node_delete, args); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } /* Caller expects us to leave this locked... */ - spin_lock (&netfs_node_refcnt_lock); + pthread_spin_lock (&netfs_node_refcnt_lock); } else { @@ -180,7 +190,7 @@ recache_handle (int *p, struct node *np) } /* Unlink it */ - spin_lock (&netfs_node_refcnt_lock); + pthread_spin_lock (&netfs_node_refcnt_lock); *np->nn->hprevp = np->nn->hnext; if (np->nn->hnext) np->nn->hnext->nn->hprevp = np->nn->hprevp; @@ -196,7 +206,7 @@ recache_handle (int *p, struct node *np) np->nn->hnext->nn->hprevp = &np->nn->hnext; np->nn->hprevp = &nodehash[h]; - spin_unlock (&netfs_node_refcnt_lock); + pthread_spin_unlock (&netfs_node_refcnt_lock); return p + len / sizeof (int); } diff --git a/nfs/main.c b/nfs/main.c index 48852062..bb623514 100644 --- a/nfs/main.c +++ b/nfs/main.c @@ -351,7 +351,9 @@ parse_startup_opt (int key, char *arg, struct argp_state *state) int main (int argc, char **argv) { + pthread_t thread; error_t err; + struct argp common_argp = { common_options, parse_common_opt }; const struct argp_child argp_children[] = { {&common_argp}, {&netfs_std_startup_argp}, {0} }; @@ -391,8 +393,22 @@ main (int argc, char **argv) if (err) error (2, err, "mapping time"); - cthread_detach (cthread_fork ((cthread_fn_t) timeout_service_thread, 0)); - cthread_detach (cthread_fork ((cthread_fn_t) rpc_receive_thread, 0)); + err = pthread_create (&thread, NULL, timeout_service_thread, NULL); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } + err = pthread_create (&thread, NULL, rpc_receive_thread, NULL); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } hostname = localhost (); diff --git a/nfs/mount.c b/nfs/mount.c index 6120f87a..29b203aa 100644 --- a/nfs/mount.c +++ b/nfs/mount.c @@ -216,7 +216,7 @@ mount_root (char *name, char *host) /* Create the node for root */ xdr_decode_fhandle (p, &np); free (rpcbuf); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); if (nfs_port_override) port = nfs_port; diff --git a/nfs/name-cache.c b/nfs/name-cache.c index 845cda30..7553d7c0 100644 --- a/nfs/name-cache.c +++ b/nfs/name-cache.c @@ -61,7 +61,7 @@ struct lookup_cache /* The contents of the cache in no particular order */ static struct cacheq lookup_cache = { sizeof (struct lookup_cache) }; -static spin_lock_t cache_lock = SPIN_LOCK_INITIALIZER; +static pthread_spinlock_t cache_lock = PTHREAD_SPINLOCK_INITIALIZER; /* Buffer to hold statistics */ static struct stats @@ -115,7 +115,7 @@ enter_lookup_cache (char *dir, size_t len, struct node *np, char *name) if (name_len > CACHE_NAME_LEN - 1) return; - spin_lock (&cache_lock); + pthread_spin_lock (&cache_lock); if (lookup_cache.length == 0) /* There should always be an lru_cache; this being zero means that the @@ -141,7 +141,7 @@ enter_lookup_cache (char *dir, size_t len, struct node *np, char *name) /* Now C becomes the MRU entry! */ cacheq_make_mru (&lookup_cache, c); - spin_unlock (&cache_lock); + pthread_spin_unlock (&cache_lock); } /* Purge all references in the cache to NAME within directory DIR. */ @@ -150,7 +150,7 @@ purge_lookup_cache (struct node *dp, char *name, size_t namelen) { struct lookup_cache *c, *next; - spin_lock (&cache_lock); + pthread_spin_lock (&cache_lock); for (c = lookup_cache.mru; c; c = next) { /* Save C->hdr.next, since we may move C from this position. */ @@ -170,7 +170,7 @@ purge_lookup_cache (struct node *dp, char *name, size_t namelen) entry. */ } } - spin_unlock (&cache_lock); + pthread_spin_unlock (&cache_lock); } /* Purge all references in the cache to node NP. */ @@ -179,7 +179,7 @@ purge_lookup_cache_node (struct node *np) { struct lookup_cache *c, *next; - spin_lock (&cache_lock); + pthread_spin_lock (&cache_lock); for (c = lookup_cache.mru; c; c = next) { next = c->hdr.next; @@ -192,7 +192,7 @@ purge_lookup_cache_node (struct node *np) cacheq_make_lru (&lookup_cache, c); } } - spin_unlock (&cache_lock); + pthread_spin_unlock (&cache_lock); } @@ -249,7 +249,7 @@ check_lookup_cache (struct node *dir, char *name) { struct lookup_cache *c; - spin_lock (&cache_lock); + pthread_spin_lock (&cache_lock); c = find_cache (dir->nn->handle.data, dir->nn->handle.size, name, strlen (name)); @@ -268,7 +268,7 @@ check_lookup_cache (struct node *dir, char *name) c->name_len = 0; c->np = 0; cacheq_make_lru (&lookup_cache, c); - spin_unlock (&cache_lock); + pthread_spin_unlock (&cache_lock); return 0; } @@ -278,8 +278,8 @@ check_lookup_cache (struct node *dir, char *name) /* A negative cache entry. */ { register_neg_hit (c->stati); - spin_unlock (&cache_lock); - mutex_unlock (&dir->lock); + pthread_spin_unlock (&cache_lock); + pthread_mutex_unlock (&dir->lock); return (struct node *)-1; } else @@ -289,17 +289,17 @@ check_lookup_cache (struct node *dir, char *name) np = c->np; netfs_nref (np); register_pos_hit (c->stati); - spin_unlock (&cache_lock); + pthread_spin_unlock (&cache_lock); - mutex_unlock (&dir->lock); - mutex_lock (&np->lock); + pthread_mutex_unlock (&dir->lock); + pthread_mutex_lock (&np->lock); return np; } } register_miss (); - spin_unlock (&cache_lock); + pthread_spin_unlock (&cache_lock); return 0; } diff --git a/nfs/nfs.h b/nfs/nfs.h index 147dc900..18dec001 100644 --- a/nfs/nfs.h +++ b/nfs/nfs.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "nfs-spec.h" #include @@ -187,8 +188,8 @@ int *register_fresh_stat (struct node *, int *); /* rpc.c */ int *initialize_rpc (int, int, int, size_t, void **, uid_t, gid_t, gid_t); error_t conduct_rpc (void **, int **); -void timeout_service_thread (void); -void rpc_receive_thread (void); +void *timeout_service_thread (void *); +void *rpc_receive_thread (void *); /* cache.c */ void lookup_fhandle (void *, size_t, struct node **); diff --git a/nfs/ops.c b/nfs/ops.c index 05cfbe9a..a4d6ac77 100644 --- a/nfs/ops.c +++ b/nfs/ops.c @@ -671,7 +671,7 @@ netfs_attempt_lookup (struct iouser *cred, struct node *np, dirlen = np->nn->handle.size; memcpy (dirhandle, np->nn->handle.data, dirlen); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); err = conduct_rpc (&rpcbuf, &p); if (!err) @@ -688,12 +688,12 @@ netfs_attempt_lookup (struct iouser *cred, struct node *np, if (protocol_version == 3) { if (*newnp) - mutex_unlock (&(*newnp)->lock); - mutex_lock (&np->lock); + pthread_mutex_unlock (&(*newnp)->lock); + pthread_mutex_lock (&np->lock); p = process_returned_stat (np, p, 0); /* XXX Do we have to lock np? */ - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); if (*newnp) - mutex_lock (&(*newnp)->lock); + pthread_mutex_lock (&(*newnp)->lock); } } else @@ -815,9 +815,9 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, /* We have no RPC available that will do an atomic replacement, so we settle for second best; just doing an unlink and ignoring any errors. */ - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); netfs_attempt_unlink (cred, dir, name); - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); } /* If we have postponed a translator setting on an unlinked node, @@ -828,22 +828,22 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, { case POSSIBLE: case NOT_POSSIBLE: - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); p = nfs_initialize_rpc (NFSPROC_LINK (protocol_version), cred, 0, &rpcbuf, dir, -1); if (! p) { - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); return errno; } - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); p = xdr_encode_fhandle (p, &np->nn->handle); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); purge_lookup_cache (dir, name, strlen (name)); p = xdr_encode_fhandle (p, &dir->nn->handle); @@ -855,32 +855,32 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, err = nfs_error_trans (ntohl (*p)); p++; } - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); free (rpcbuf); break; case SYMLINK: - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); p = nfs_initialize_rpc (NFSPROC_SYMLINK (protocol_version), cred, 0, &rpcbuf, dir, -1); if (! p) { - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); return errno; } p = xdr_encode_fhandle (p, &dir->nn->handle); - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); p = xdr_encode_string (p, name); - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); err = netfs_validate_stat (np, cred); if (err) { - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); free (rpcbuf); return err; } @@ -895,9 +895,9 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, p = xdr_encode_sattr_stat (p, &np->nn_stat); p = xdr_encode_string (p, np->nn->transarg.name); } - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); purge_lookup_cache (dir, name, strlen (name)); err = conduct_rpc (&rpcbuf, &p); @@ -916,13 +916,13 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, cred, 0, &rpcbuf, dir, -1); if (! p) { - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); return errno; } p = xdr_encode_fhandle (p, &dir->nn->handle); p = xdr_encode_string (p, name); - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); err = conduct_rpc (&rpcbuf, &p); if (!err) @@ -932,10 +932,10 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, } if (!err) { - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); p = recache_handle (p, np); p = process_returned_stat (np, p, 1); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); } if (err) err = EGRATUITOUS; /* damn */ @@ -944,21 +944,21 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, { if (!err) { - mutex_unlock (&dir->lock); - mutex_lock (&np->lock); + pthread_mutex_unlock (&dir->lock); + pthread_mutex_lock (&np->lock); p = recache_handle (p, np); p = process_returned_stat (np, p, 1); - mutex_unlock (&np->lock); - mutex_lock (&dir->lock); + pthread_mutex_unlock (&np->lock); + pthread_mutex_lock (&dir->lock); } p = process_wcc_stat (dir, p, !err); - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); } else - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); } else - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); free (rpcbuf); break; @@ -970,7 +970,7 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, if (protocol_version == 2) { - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); err = verify_nonexistent (cred, dir, name); if (err) return err; @@ -979,29 +979,29 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, cred, 0, &rpcbuf, dir, -1); if (! p) { - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); return errno; } p = xdr_encode_fhandle (p, &dir->nn->handle); p = xdr_encode_string (p, name); - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); err = netfs_validate_stat (np, cred); if (err) { - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); free (rpcbuf); return err; } p = xdr_encode_sattr_stat (p, &np->nn_stat); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); purge_lookup_cache (dir, name, strlen (name)); - mutex_unlock (&dir->lock); /* XXX Should this really be after the + pthread_mutex_unlock (&dir->lock); /* XXX Should this really be after the _lengthy_ (blocking) conduct_rpc? */ err = conduct_rpc (&rpcbuf, &p); if (!err) @@ -1012,32 +1012,32 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, if (!err) { - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); p = recache_handle (p, np); register_fresh_stat (np, p); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); } free (rpcbuf); } else /* protocol_version != 2 */ { - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); p = nfs_initialize_rpc (NFS3PROC_MKNOD, cred, 0, &rpcbuf, dir, -1); if (! p) { - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); return errno; } p = xdr_encode_fhandle (p, &dir->nn->handle); p = xdr_encode_string (p, name); - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); err = netfs_validate_stat (np, cred); if (err) { - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); free (rpcbuf); return err; } @@ -1048,7 +1048,7 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, *(p++) = htonl (major (np->nn_stat.st_rdev)); *(p++) = htonl (minor (np->nn_stat.st_rdev)); } - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); purge_lookup_cache (dir, name, strlen (name)); err = conduct_rpc (&rpcbuf, &p); @@ -1059,14 +1059,14 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, if (!err) { - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); p = recache_handle (p, np); p = process_returned_stat (np, p, 1); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); } - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); p = process_wcc_stat (dir, p, !err); - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); } free (rpcbuf); } @@ -1076,7 +1076,7 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, if (err) return err; - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); if (np->nn->dtrans == SYMLINK) free (np->nn->transarg.name); @@ -1089,14 +1089,14 @@ netfs_attempt_link (struct iouser *cred, struct node *dir, char *name = np->nn->dead_name; np->nn->dead_dir = 0; np->nn->dead_name = 0; - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); netfs_attempt_unlink ((struct iouser *)-1, dir, name); - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); } else - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); return 0; } @@ -1122,7 +1122,7 @@ netfs_attempt_mkfile (struct iouser *cred, struct node *dir, sprintf (name, ".nfstmpgnu.%d", n++); err = netfs_attempt_create_file (cred, dir, name, mode, newnp); if (err == EEXIST) - mutex_lock (&dir->lock); /* XXX is this right? does create need this + pthread_mutex_lock (&dir->lock); /* XXX is this right? does create need this and drop this on error? Doesn't look like it. */ } @@ -1172,7 +1172,7 @@ netfs_attempt_create_file (struct iouser *cred, struct node *np, err = verify_nonexistent (cred, np, name); if (err) { - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); return err; } } @@ -1201,7 +1201,7 @@ netfs_attempt_create_file (struct iouser *cred, struct node *np, err = conduct_rpc (&rpcbuf, &p); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); if (!err) { @@ -1217,12 +1217,12 @@ netfs_attempt_create_file (struct iouser *cred, struct node *np, if (protocol_version == 3) { if (*newnp) - mutex_unlock (&(*newnp)->lock); - mutex_lock (&np->lock); + pthread_mutex_unlock (&(*newnp)->lock); + pthread_mutex_lock (&np->lock); p = process_wcc_stat (np, p, 1); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); if (*newnp) - mutex_lock (&(*newnp)->lock); + pthread_mutex_lock (&(*newnp)->lock); } if (*newnp && !netfs_validate_stat (*newnp, (struct iouser *) -1) @@ -1251,13 +1251,13 @@ netfs_attempt_unlink (struct iouser *cred, struct node *dir, err = netfs_attempt_lookup (cred, dir, name, &np); if (err) { - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); return err; } /* Restore the locks to sanity. */ - mutex_unlock (&np->lock); - mutex_lock (&dir->lock); + pthread_mutex_unlock (&np->lock); + pthread_mutex_lock (&dir->lock); /* Purge the cache of entries for this node, so that we don't regard cache-held references as live. */ @@ -1272,12 +1272,12 @@ netfs_attempt_unlink (struct iouser *cred, struct node *dir, char *newname = 0; int n = 0; - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); newname = malloc (50); if (! newname) { - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); netfs_nrele (np); /* XXX Is this the correct thing to do? */ return ENOMEM; } @@ -1292,14 +1292,14 @@ netfs_attempt_unlink (struct iouser *cred, struct node *dir, if (err) { free (newname); - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); netfs_nrele (np); return err; } /* Write down what name we gave it; we'll delete this when all our uses vanish. */ - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); if (np->nn->dead_dir) netfs_nrele (np->nn->dead_dir); @@ -1312,7 +1312,7 @@ netfs_attempt_unlink (struct iouser *cred, struct node *dir, np->nn->dtrans = POSSIBLE; netfs_nput (np); - mutex_lock (&dir->lock); + pthread_mutex_lock (&dir->lock); } else netfs_nrele (np); @@ -1356,9 +1356,9 @@ netfs_attempt_rename (struct iouser *cred, struct node *fromdir, /* Just do a lookup/link/unlink sequence. */ - mutex_lock (&fromdir->lock); + pthread_mutex_lock (&fromdir->lock); err = netfs_attempt_lookup (cred, fromdir, fromname, &np); - mutex_unlock (&fromdir->lock); + pthread_mutex_unlock (&fromdir->lock); if (err) return err; @@ -1367,41 +1367,41 @@ netfs_attempt_rename (struct iouser *cred, struct node *fromdir, if (err) return err; - mutex_lock (&fromdir->lock); + pthread_mutex_lock (&fromdir->lock); err = netfs_attempt_unlink (cred, fromdir, fromname); - mutex_unlock (&fromdir->lock); + pthread_mutex_unlock (&fromdir->lock); /* If the unlink failed, then back out the link */ if (err) { - mutex_lock (&todir->lock); + pthread_mutex_lock (&todir->lock); netfs_attempt_unlink (cred, todir, toname); - mutex_unlock (&todir->lock); + pthread_mutex_unlock (&todir->lock); return err; } return 0; } - mutex_lock (&fromdir->lock); + pthread_mutex_lock (&fromdir->lock); purge_lookup_cache (fromdir, fromname, strlen (fromname)); p = nfs_initialize_rpc (NFSPROC_RENAME (protocol_version), cred, 0, &rpcbuf, fromdir, -1); if (! p) { - mutex_unlock (&fromdir->lock); + pthread_mutex_unlock (&fromdir->lock); return errno; } p = xdr_encode_fhandle (p, &fromdir->nn->handle); p = xdr_encode_string (p, fromname); - mutex_unlock (&fromdir->lock); + pthread_mutex_unlock (&fromdir->lock); - mutex_lock (&todir->lock); + pthread_mutex_lock (&todir->lock); purge_lookup_cache (todir, toname, strlen (toname)); p = xdr_encode_fhandle (p, &todir->nn->handle); p = xdr_encode_string (p, toname); - mutex_unlock (&todir->lock); + pthread_mutex_unlock (&todir->lock); err = conduct_rpc (&rpcbuf, &p); if (!err) @@ -1410,7 +1410,7 @@ netfs_attempt_rename (struct iouser *cred, struct node *fromdir, p++; if (protocol_version == 3) /* XXX Should we add `&& !err' ? */ { - mutex_lock (&fromdir->lock); + pthread_mutex_lock (&fromdir->lock); p = process_wcc_stat (fromdir, p, !err); p = process_wcc_stat (todir, p, !err); } diff --git a/nfs/rpc.c b/nfs/rpc.c index 0b0444d0..c0d0290e 100644 --- a/nfs/rpc.c +++ b/nfs/rpc.c @@ -49,10 +49,10 @@ static struct rpc_list *outstanding_rpcs; /* Wake up this condition when an outstanding RPC has received a reply or we should check for timeouts. */ -static struct condition rpc_wakeup = CONDITION_INITIALIZER; +static pthread_cond_t rpc_wakeup = PTHREAD_COND_INITIALIZER; /* Lock the global data and the REPLY fields of outstanding RPC's. */ -static struct mutex outstanding_lock = MUTEX_INITIALIZER; +static pthread_mutex_t outstanding_lock = PTHREAD_MUTEX_INITIALIZER; @@ -186,7 +186,7 @@ conduct_rpc (void **rpcbuf, int **pp) int n; int cancel; - mutex_lock (&outstanding_lock); + pthread_mutex_lock (&outstanding_lock); link_rpc (&outstanding_rpcs, hdr); @@ -198,7 +198,7 @@ conduct_rpc (void **rpcbuf, int **pp) if (mounted_soft && ntransmit == soft_retries) { unlink_rpc (hdr); - mutex_unlock (&outstanding_lock); + pthread_mutex_unlock (&outstanding_lock); return ETIMEDOUT; } @@ -210,7 +210,7 @@ conduct_rpc (void **rpcbuf, int **pp) if (cc == -1) { unlink_rpc (hdr); - mutex_unlock (&outstanding_lock); + pthread_mutex_unlock (&outstanding_lock); return errno; } else @@ -221,12 +221,12 @@ conduct_rpc (void **rpcbuf, int **pp) while (!hdr->reply && (mapped_time->seconds - lasttrans < timeout) && !cancel) - cancel = hurd_condition_wait (&rpc_wakeup, &outstanding_lock); + cancel = pthread_hurd_cond_wait_np (&rpc_wakeup, &outstanding_lock); if (cancel) { unlink_rpc (hdr); - mutex_unlock (&outstanding_lock); + pthread_mutex_unlock (&outstanding_lock); return EINTR; } @@ -242,7 +242,7 @@ conduct_rpc (void **rpcbuf, int **pp) } while (!hdr->reply); - mutex_unlock (&outstanding_lock); + pthread_mutex_unlock (&outstanding_lock); /* Switch to the reply buffer. */ *rpcbuf = hdr->reply; @@ -349,25 +349,31 @@ conduct_rpc (void **rpcbuf, int **pp) /* Dedicated thread to signal those waiting on rpc_wakeup once a second. */ -void -timeout_service_thread () +void * +timeout_service_thread (void *arg) { + (void) arg; + while (1) { sleep (1); - mutex_lock (&outstanding_lock); - condition_broadcast (&rpc_wakeup); - mutex_unlock (&outstanding_lock); + pthread_mutex_lock (&outstanding_lock); + pthread_cond_broadcast (&rpc_wakeup); + pthread_mutex_unlock (&outstanding_lock); } + + return NULL; } /* Dedicate thread to receive RPC replies, register them on the queue of pending wakeups, and deal appropriately. */ -void -rpc_receive_thread () +void * +rpc_receive_thread (void *arg) { void *buf; + (void) arg; + /* Allocate a receive buffer. */ buf = malloc (1024 + read_size); assert (buf); @@ -385,7 +391,7 @@ rpc_receive_thread () struct rpc_list *r; int xid = *(int *)buf; - mutex_lock (&outstanding_lock); + pthread_mutex_lock (&outstanding_lock); /* Find the rpc that we just fulfilled. */ for (r = outstanding_rpcs; r; r = r->next) @@ -394,7 +400,7 @@ rpc_receive_thread () { unlink_rpc (r); r->reply = buf; - condition_broadcast (&rpc_wakeup); + pthread_cond_broadcast (&rpc_wakeup); break; } } @@ -402,7 +408,7 @@ rpc_receive_thread () if (! r) fprintf (stderr, "NFS dropping reply xid %d\n", xid); #endif - mutex_unlock (&outstanding_lock); + pthread_mutex_unlock (&outstanding_lock); /* If r is not null then we had a message from a pending (i.e. known) rpc. Thus, it was fulfilled and if we want @@ -414,4 +420,6 @@ rpc_receive_thread () } } } + + return NULL; } -- cgit v1.2.3