From 5eef605eb523e4148ccd22578327492178cfd0c4 Mon Sep 17 00:00:00 2001 From: Flavio Cruz Date: Tue, 15 Mar 2016 04:50:02 -0400 Subject: netfs: Remove global reference count lock. * libnetfs/drop-node.c: Remove use of netfs_node_refcnt_lock. * libnetfs/init-init.c: Remove netfs_node_refcnt_lock. * libnetfs/make-node.c: Initialize refcounts in refcounts_init. * libnetfs/netfs.h: Use refcounts_t for tracking node references. Remove netfs_node_refcnt_lock. Add netfs_nref_light, netfs_nrele_light and handler netfs_try_dropping_softrefs. Adjust comments. * libnetfs/nput.c: Use refcounts_t. Call netfs_try_dropping_softrefs to remove any soft reference that the translator might have acquired during the lifetime of the node. Implement empty netfs_try_dropping_softrefs. * libnetfs/nref.c: Implement netfs_nref_light. * libnetfs/nrele.c: Use refcounts_t and netfs_try_dropping_softrefs. Implement netfs_nrele_light. * ftpfs/dir.c: Use netfs_nref without locking the old netfs_node_refcnt_lock. * ftpfs/node.c: Likewise. * usermux/mux.c: Use netfs_nref to increase hard references of the node. * hostmux/mux.c: Use netfs_nref to increase hard references of the node. * trans/fakeroot.c (new_node): Use a light reference when storing a node in the hash table. * trans/fakeroot.c (netfs_try_dropping_softrefs): Implement netfs_try_dropping_softrefs to remove the node from the hash table. * trans/fakeroot.c (netfs_node_norefs): Remove code to remove the node from the hash table. * trans/fakeroot.c (netfs_S_dir_lookup): Simplify lookup code since we don't need to lock netfs_node_refcnt_lock anymore. * procfs/netfs.c: Remove use of netfs_node_refcnt_lock. * nfs/cache.c: Add mutex to handle exclusive access to nodehash. This replaces the use of netfs_node_refcnt_lock. * nfs/cache.c (lookup_handle): Use nodehash_ihash_lock when accessing nodehash. Use netfs_nref_light to add one soft reference to the node just added to nodehash. * nfs/cache.c (netfs_node_norefs): Use netfs_nref. Don't use netfs_node_refcnt_lock and don't remove the node from nodehash here. * nfs/cache.c (netfs_try_dropping_softrefs): Drop the light reference when the node has no more hard references. * nfs/cache.c (recache_handle): Use nodehash_ihash_lock instead. * nfs/ops.c (netds_attempt_unlink): Use refcounts_references. * console/console.c (netfs_node_norefs): Use a soft reference to store a node in dir_node, cons_node, disp_node, inp_node. * console/console.c (netfs_try_dropping_softrefs): When dropping all soft references remove node pointer from the fields above. --- ftpfs/dir.c | 27 ++++++--------------------- ftpfs/node.c | 8 +------- 2 files changed, 7 insertions(+), 28 deletions(-) (limited to 'ftpfs') diff --git a/ftpfs/dir.c b/ftpfs/dir.c index 733a2dcf..2ea29b53 100644 --- a/ftpfs/dir.c +++ b/ftpfs/dir.c @@ -654,10 +654,8 @@ ftpfs_dir_lookup (struct ftpfs_dir *dir, const char *name, { /* If there's already a node, add a ref so that it doesn't go away. */ - pthread_spin_lock (&netfs_node_refcnt_lock); - if (e->node) - e->node->references++; - pthread_spin_unlock (&netfs_node_refcnt_lock); + if (e->node) + netfs_nref (e->node); if (! e->node) /* No node; make one and install it into E. */ @@ -682,11 +680,7 @@ ftpfs_dir_lookup (struct ftpfs_dir *dir, const char *name, if (!err && dir->num_live_entries++ == 0) /* Keep a reference to dir's node corresponding to children. */ - { - pthread_spin_lock (&netfs_node_refcnt_lock); - dir->node->references++; - pthread_spin_unlock (&netfs_node_refcnt_lock); - } + netfs_nref (dir->node); } } @@ -737,10 +731,8 @@ ftpfs_dir_null_lookup (struct ftpfs_dir *dir, struct node **node) /* We've got a dir entry, get a node for it. */ { /* If there's already a node, add a ref so that it doesn't go away. */ - pthread_spin_lock (&netfs_node_refcnt_lock); if (e->node) - e->node->references++; - pthread_spin_unlock (&netfs_node_refcnt_lock); + netfs_nref (e->node); if (! e->node) /* No node; make one and install it into E. */ @@ -749,11 +741,7 @@ ftpfs_dir_null_lookup (struct ftpfs_dir *dir, struct node **node) if (!err && dir->num_live_entries++ == 0) /* Keep a reference to dir's node corresponding to children. */ - { - pthread_spin_lock (&netfs_node_refcnt_lock); - dir->node->references++; - pthread_spin_unlock (&netfs_node_refcnt_lock); - } + netfs_nref (dir->node); } if (! err) @@ -783,10 +771,7 @@ ftpfs_dir_create (struct ftpfs *fs, struct node *node, const char *rmt_path, return ENOMEM; } - /* Hold a reference to the new dir's node. */ - pthread_spin_lock (&netfs_node_refcnt_lock); - node->references++; - pthread_spin_unlock (&netfs_node_refcnt_lock); + netfs_nref (node); hurd_ihash_init (&new->htable, offsetof (struct ftpfs_dir_entry, dir_locp)); hurd_ihash_set_gki (&new->htable, ihash_hash, ihash_compare); diff --git a/ftpfs/node.c b/ftpfs/node.c index 74cd402e..cc9bf433 100644 --- a/ftpfs/node.c +++ b/ftpfs/node.c @@ -84,10 +84,7 @@ netfs_node_norefs (struct node *node) { struct netnode *nn = node->nn; - /* Ftpfs_detach_node does ref count frobbing (of other nodes), so we have - to unlock NETFS_NODE_REFCNT_LOCK during it. */ - node->references++; - pthread_spin_unlock (&netfs_node_refcnt_lock); + netfs_nref (node); /* Remove NODE from any entry it is attached to. */ ftpfs_detach_node (node); @@ -108,7 +105,4 @@ netfs_node_norefs (struct node *node) free (nn); free (node); - - /* Caller expects us to leave this locked... */ - pthread_spin_lock (&netfs_node_refcnt_lock); } -- cgit v1.2.3