diff options
Diffstat (limited to 'nfs')
-rw-r--r-- | nfs/Makefile | 3 | ||||
-rw-r--r-- | nfs/cache.c | 36 | ||||
-rw-r--r-- | nfs/main.c | 20 | ||||
-rw-r--r-- | nfs/mount.c | 2 | ||||
-rw-r--r-- | nfs/name-cache.c | 30 | ||||
-rw-r--r-- | nfs/nfs.h | 5 | ||||
-rw-r--r-- | nfs/ops.c | 168 | ||||
-rw-r--r-- | nfs/rpc.c | 44 |
8 files changed, 172 insertions, 136 deletions
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 <string.h> +#include <stdio.h> #include <netinet/in.h> /* 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); } @@ -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; } @@ -21,6 +21,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <stdint.h> +#include <pthread.h> #include <sys/mman.h> #include "nfs-spec.h" #include <hurd/netfs.h> @@ -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 **); @@ -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); } @@ -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; } |