Whamcloud - gitweb
LU-9679 osc: use assert_spin_locked() 96/37596/2
authorNeilBrown <neilb@suse.com>
Wed, 12 Dec 2018 03:25:30 +0000 (14:25 +1100)
committerOleg Drokin <green@whamcloud.com>
Sun, 1 Mar 2020 05:34:54 +0000 (05:34 +0000)
assert_spin_locked() is preferred to spin_is_locked() for affirming
that a spinlock is locked.

__osc_extent_sanity_check() is only ever called with obj already
locked, so change the check into an assertion.

Linux-Commit: a12d8284b574 ("lustre: osc_cache: use
assert_spin_locked()")

Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Mr NeilBrown <neilb@suse.com>
Change-Id: Iaae6deb5af4dec4d31893749924f211ba0489c47
Reviewed-on: https://review.whamcloud.com/37596
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_osc.h
lustre/osc/osc_cache.c

index 902a82f..6c30b61 100644 (file)
@@ -342,19 +342,8 @@ static inline void osc_object_unlock(struct osc_object *obj)
        spin_unlock(&obj->oo_lock);
 }
 
-static inline int osc_object_is_locked(struct osc_object *obj)
-{
-#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
-       return spin_is_locked(&obj->oo_lock);
-#else
-       /*
-        * It is not perfect to return true all the time.
-        * But since this function is only used for assertion
-        * and checking, it seems OK.
-        */
-       return 1;
-#endif
-}
+#define assert_osc_object_is_locked(obj)       \
+       assert_spin_locked(&obj->oo_lock)
 
 static inline void osc_object_set_contended(struct osc_object *obj)
 {
index be0a875..f043f89 100644 (file)
@@ -184,8 +184,7 @@ static int osc_extent_sanity_check0(struct osc_extent *ext,
        size_t page_count;
        int rc = 0;
 
-       if (!osc_object_is_locked(obj))
-               GOTO(out, rc = 9);
+       assert_osc_object_is_locked(obj);
 
        if (ext->oe_state >= OES_STATE_MAX)
                GOTO(out, rc = 10);
@@ -290,7 +289,7 @@ static int osc_extent_is_overlapped(struct osc_object *obj,
 {
        struct osc_extent *tmp;
 
-       LASSERT(osc_object_is_locked(obj));
+       assert_osc_object_is_locked(obj);
 
        if (!extent_debug)
                return 0;
@@ -307,7 +306,7 @@ static int osc_extent_is_overlapped(struct osc_object *obj,
 
 static void osc_extent_state_set(struct osc_extent *ext, int state)
 {
-       LASSERT(osc_object_is_locked(ext->oe_obj));
+       assert_osc_object_is_locked(ext->oe_obj);
        LASSERT(state >= OES_INV && state < OES_STATE_MAX);
 
        /* Never try to sanity check a state changing extent :-) */
@@ -380,7 +379,7 @@ static void osc_extent_put(const struct lu_env *env, struct osc_extent *ext)
 static void osc_extent_put_trust(struct osc_extent *ext)
 {
        LASSERT(atomic_read(&ext->oe_refc) > 1);
-       LASSERT(osc_object_is_locked(ext->oe_obj));
+       assert_osc_object_is_locked(ext->oe_obj);
        atomic_dec(&ext->oe_refc);
 }
 
@@ -394,7 +393,7 @@ static struct osc_extent *osc_extent_search(struct osc_object *obj,
        struct rb_node    *n = obj->oo_root.rb_node;
        struct osc_extent *tmp, *p = NULL;
 
-       LASSERT(osc_object_is_locked(obj));
+       assert_osc_object_is_locked(obj);
        while (n != NULL) {
                tmp = rb_extent(n);
                if (index < tmp->oe_start) {
@@ -433,7 +432,7 @@ static void osc_extent_insert(struct osc_object *obj, struct osc_extent *ext)
 
        LASSERT(ext->oe_intree == 0);
        LASSERT(ext->oe_obj == obj);
-       LASSERT(osc_object_is_locked(obj));
+       assert_osc_object_is_locked(obj);
        while (*n != NULL) {
                tmp = rb_extent(*n);
                parent = *n;
@@ -455,7 +454,7 @@ static void osc_extent_insert(struct osc_object *obj, struct osc_extent *ext)
 static void osc_extent_erase(struct osc_extent *ext)
 {
        struct osc_object *obj = ext->oe_obj;
-       LASSERT(osc_object_is_locked(obj));
+       assert_osc_object_is_locked(obj);
        if (ext->oe_intree) {
                rb_erase(&ext->oe_node, &obj->oo_root);
                ext->oe_intree = 0;
@@ -468,7 +467,7 @@ static struct osc_extent *osc_extent_hold(struct osc_extent *ext)
 {
        struct osc_object *obj = ext->oe_obj;
 
-       LASSERT(osc_object_is_locked(obj));
+       assert_osc_object_is_locked(obj);
        LASSERT(ext->oe_state == OES_ACTIVE || ext->oe_state == OES_CACHE);
        if (ext->oe_state == OES_CACHE) {
                osc_extent_state_set(ext, OES_ACTIVE);
@@ -481,7 +480,7 @@ static struct osc_extent *osc_extent_hold(struct osc_extent *ext)
 
 static void __osc_extent_remove(struct osc_extent *ext)
 {
-       LASSERT(osc_object_is_locked(ext->oe_obj));
+       assert_osc_object_is_locked(ext->oe_obj);
        LASSERT(list_empty(&ext->oe_pages));
        osc_extent_erase(ext);
        list_del_init(&ext->oe_link);
@@ -512,7 +511,7 @@ static int osc_extent_merge(const struct lu_env *env, struct osc_extent *cur,
        int                      ppc_bits;
 
        LASSERT(cur->oe_state == OES_CACHE);
-       LASSERT(osc_object_is_locked(obj));
+       assert_osc_object_is_locked(obj);
        if (victim == NULL)
                return -EINVAL;
 
@@ -2018,7 +2017,7 @@ static unsigned int get_write_extents(struct osc_object *obj,
                .erd_max_extents = 256,
        };
 
-       LASSERT(osc_object_is_locked(obj));
+       assert_osc_object_is_locked(obj);
        while (!list_empty(&obj->oo_hp_exts)) {
                ext = list_entry(obj->oo_hp_exts.next, struct osc_extent,
                                 oe_link);
@@ -2084,7 +2083,7 @@ __must_hold(osc)
        int rc = 0;
        ENTRY;
 
-       LASSERT(osc_object_is_locked(osc));
+       assert_osc_object_is_locked(osc);
 
        page_count = get_write_extents(osc, &rpclist);
        LASSERT(equi(page_count == 0, list_empty(&rpclist)));
@@ -2162,7 +2161,7 @@ __must_hold(osc)
        int rc = 0;
        ENTRY;
 
-       LASSERT(osc_object_is_locked(osc));
+       assert_osc_object_is_locked(osc);
        list_for_each_entry_safe(ext, next, &osc->oo_reading_exts, oe_link) {
                EASSERT(ext->oe_state == OES_LOCK_DONE, ext);
                if (!try_to_add_extent_for_io(cli, ext, &data))