]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
rhashtable: replace rht_ptr_locked() with rht_assign_locked()
authorNeilBrown <neilb@suse.com>
Fri, 12 Apr 2019 01:52:08 +0000 (11:52 +1000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 13 Apr 2019 00:34:45 +0000 (17:34 -0700)
The only times rht_ptr_locked() is used, it is to store a new
value in a bucket-head.  This is the only time it makes sense
to use it too.  So replace it by a function which does the
whole task:  Sets the lock bit and assigns to a bucket head.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/rhashtable.h
lib/rhashtable.c

index b54e6436547e281c65d0c5bd0e84df08cd6dfaad..882bc0fcea4be62d3e4a213b6a5cb74f2787622f 100644 (file)
@@ -316,6 +316,7 @@ static inline struct rhash_lock_head __rcu **rht_bucket_insert(
  * local_bh. For that we have rht_assign_unlock().  As rcu_assign_pointer()
  * provides the same release semantics that bit_spin_unlock() provides,
  * this is safe.
+ * When we write to a bucket without unlocking, we use rht_assign_locked().
  */
 
 static inline void rht_lock(struct bucket_table *tbl,
@@ -369,10 +370,12 @@ static inline struct rhash_head *rht_ptr_exclusive(
        return (void *)(((unsigned long)p) & ~BIT(1));
 }
 
-static inline struct rhash_lock_head __rcu *rht_ptr_locked(const
-                                                          struct rhash_head *p)
+static inline void rht_assign_locked(struct rhash_lock_head __rcu **bkt,
+                                    struct rhash_head *obj)
 {
-       return (void *)(((unsigned long)p) | BIT(1));
+       struct rhash_head __rcu **p = (struct rhash_head __rcu **)bkt;
+
+       rcu_assign_pointer(*p, (void *)((unsigned long)obj | BIT(1)));
 }
 
 static inline void rht_assign_unlock(struct bucket_table *tbl,
index 237368ea98c5a18fe6065e61e1b65ed8cd8d20b3..ef5378efdef34f391d327b04bf2c815c475e7be4 100644 (file)
@@ -259,7 +259,7 @@ static int rhashtable_rehash_one(struct rhashtable *ht,
                rcu_assign_pointer(*pprev, next);
        else
                /* Need to preserved the bit lock. */
-               rcu_assign_pointer(*bkt, rht_ptr_locked(next));
+               rht_assign_locked(bkt, next);
 
 out:
        return err;
@@ -517,7 +517,7 @@ static void *rhashtable_lookup_one(struct rhashtable *ht,
                        rcu_assign_pointer(*pprev, obj);
                else
                        /* Need to preserve the bit lock */
-                       rcu_assign_pointer(*bkt, rht_ptr_locked(obj));
+                       rht_assign_locked(bkt, obj);
 
                return NULL;
        }
@@ -570,7 +570,7 @@ static struct bucket_table *rhashtable_insert_one(struct rhashtable *ht,
        /* bkt is always the head of the list, so it holds
         * the lock, which we need to preserve
         */
-       rcu_assign_pointer(*bkt, rht_ptr_locked(obj));
+       rht_assign_locked(bkt, obj);
 
        atomic_inc(&ht->nelems);
        if (rht_grow_above_75(ht, tbl))