]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging: lustre: osc: fix race issues thanks to oap_lock
authorSebastien Buisson <sbuisson@ddn.com>
Tue, 12 Apr 2016 20:14:01 +0000 (16:14 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 26 Apr 2016 22:13:13 +0000 (15:13 -0700)
Fix 'data race condition' defects found by Coverity version 6.5.0:

Data race condition (MISSING_LOCK)

Accessing variable without holding lock. Elsewhere,
this variable is accessed with lock held.

This patch is dedicated to code fragments involving oap_lock.

Signed-off-by: Sebastien Buisson <sbuisson@ddn.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2744
Reviewed-on: http://review.whamcloud.com/6572
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/osc/osc_cache.c
drivers/staging/lustre/lustre/osc/osc_io.c

index de8c8255ce4fc631273151a97f0be365e3a6b6cf..8263a85495acad9bb6225e33eb7302dfcc6d9743 100644 (file)
@@ -1147,7 +1147,9 @@ static int osc_extent_make_ready(const struct lu_env *env,
                last->oap_count = osc_refresh_count(env, last, OBD_BRW_WRITE);
                LASSERT(last->oap_count > 0);
                LASSERT(last->oap_page_off + last->oap_count <= PAGE_SIZE);
+               spin_lock(&last->oap_lock);
                last->oap_async_flags |= ASYNC_COUNT_STABLE;
+               spin_unlock(&last->oap_lock);
        }
 
        /* for the rest of pages, we don't need to call osf_refresh_count()
@@ -1156,7 +1158,9 @@ static int osc_extent_make_ready(const struct lu_env *env,
        list_for_each_entry(oap, &ext->oe_pages, oap_pending_item) {
                if (!(oap->oap_async_flags & ASYNC_COUNT_STABLE)) {
                        oap->oap_count = PAGE_SIZE - oap->oap_page_off;
+                       spin_lock(&last->oap_lock);
                        oap->oap_async_flags |= ASYNC_COUNT_STABLE;
+                       spin_unlock(&last->oap_lock);
                }
        }
 
@@ -2327,6 +2331,10 @@ int osc_queue_async_io(const struct lu_env *env, struct cl_io *io,
        oap->oap_cmd = cmd;
        oap->oap_page_off = ops->ops_from;
        oap->oap_count = ops->ops_to - ops->ops_from;
+       /*
+        * No need to hold a lock here,
+        * since this page is not in any list yet.
+        */
        oap->oap_async_flags = 0;
        oap->oap_brw_flags = brw_flags;
 
index 9d67fca2bc59488568f440a1c8abdd8f3ea9a6e4..d534b0e0edf69a6c69885b124539def70670e0d4 100644 (file)
@@ -168,8 +168,10 @@ static int osc_io_submit(const struct lu_env *env,
                }
 
                cl_page_list_move(qout, qin, page);
+               spin_lock(&oap->oap_lock);
                oap->oap_async_flags = ASYNC_URGENT|ASYNC_READY;
                oap->oap_async_flags |= ASYNC_COUNT_STABLE;
+               spin_unlock(&oap->oap_lock);
 
                osc_page_submit(env, opg, crt, brw_flags);
                list_add_tail(&oap->oap_pending_item, &list);