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. --- libnetfs/netfs.h | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'libnetfs/netfs.h') diff --git a/libnetfs/netfs.h b/libnetfs/netfs.h index 67a6a9a0..6c989a48 100644 --- a/libnetfs/netfs.h +++ b/libnetfs/netfs.h @@ -82,8 +82,8 @@ struct node pthread_mutex_t lock; - /* The number of references to this node. */ - int references; + /* Hard and soft references to this node. */ + refcounts_t refcounts; mach_port_t sockaddr; @@ -397,10 +397,6 @@ netfs_netnode_node (struct netnode *netnode) return (struct node *) ((char *) netnode - _netfs_sizeof_struct_node); } -/* Whenever node->references is to be touched, this lock must be - held. Cf. netfs_nrele, netfs_nput, netfs_nref and netfs_drop_node. */ -extern pthread_spinlock_t netfs_node_refcnt_lock; - /* Normally called in main. This function sets up some of the netfs server's internal state. */ void netfs_init (void); @@ -425,22 +421,38 @@ struct protid *netfs_make_protid (struct peropen *po, struct iouser *user); struct peropen *netfs_make_peropen (struct node *, int, struct peropen *context); -/* Add a reference to node NP. Unless you already hold a reference, +/* Add a hard reference to node NP. Unless you already hold a reference, NP must be locked. */ void netfs_nref (struct node *np); -/* Releases a node. Drops a reference to node NP, which must not be - locked by the caller. If this was the last reference, drops the - node. The node cannot be used again without first obtaining a - reference to it. */ +/* Add a light reference to a node. */ +void netfs_nref_light (struct node *np); + +/* Releases a hard reference on NP. If NP is locked by anyone, then + this cannot be the last hard reference (because you must hold a + hard reference in order to hold the lock). If this is the last + hard reference then request soft references to be dropped. */ void netfs_nrele (struct node *np); -/* Puts a node back. Drops a reference to the node NP, which must be - locked by the caller (this lock will be released by netfs_nput). - If this was the last reference, drops the node. The node cannot be - used again without first obtaining a reference to it. */ +/* Release a soft reference on NP. If NP is locked by anyone, then + this cannot be the last reference (because you must hold a hard + reference in order to hold the lock). */ +void netfs_nrele_light (struct node *np); + +/* Puts a node back by releasing a hard reference on NP, which must + be locked by the caller (this lock will be released by netfs_nput). + If this was the last reference, then request soft references to be + dropped. */ void netfs_nput (struct node *np); +/* The user must define this function in order to drop the soft references + that this node may have. When this function is called, node NP has just + lost its hard references and is now trying to also drop its soft references. + If the node is stored in another data structure (for caching purposes), + this allows the user to remove it so that the node can be safely deleted + from memory. */ +void netfs_try_dropping_softrefs (struct node *np); + /* Called internally when no more references to node NP exist. */ void netfs_drop_node (struct node *np); -- cgit v1.2.3