Whamcloud - gitweb
LU-2744 build: fix race issues thanks to oap_lock 72/6572/6
authorSebastien Buisson <sebastien.buisson@bull.net>
Thu, 6 Jun 2013 12:39:13 +0000 (14:39 +0200)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 5 Sep 2013 20:37:58 +0000 (20:37 +0000)
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 <sebastien.buisson@bull.net>
Change-Id: Ibfd5fe6338c624a1ab98b83ec621bcd88d736491
Reviewed-on: http://review.whamcloud.com/6572
Tested-by: Hudson
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/osc/osc_cache.c
lustre/osc/osc_io.c

index 8d9888f..11a5e0e 100644 (file)
@@ -1079,7 +1079,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_CACHE_SIZE);
                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_CACHE_SIZE);
+               spin_lock(&last->oap_lock);
                last->oap_async_flags |= ASYNC_COUNT_STABLE;
                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()
        }
 
        /* for the rest of pages, we don't need to call osf_refresh_count()
@@ -1087,7 +1089,9 @@ static int osc_extent_make_ready(const struct lu_env *env,
        cfs_list_for_each_entry(oap, &ext->oe_pages, oap_pending_item) {
                if (!(oap->oap_async_flags & ASYNC_COUNT_STABLE)) {
                        oap->oap_count = PAGE_CACHE_SIZE - oap->oap_page_off;
        cfs_list_for_each_entry(oap, &ext->oe_pages, oap_pending_item) {
                if (!(oap->oap_async_flags & ASYNC_COUNT_STABLE)) {
                        oap->oap_count = PAGE_CACHE_SIZE - oap->oap_page_off;
+                       spin_lock(&oap->oap_lock);
                        oap->oap_async_flags |= ASYNC_COUNT_STABLE;
                        oap->oap_async_flags |= ASYNC_COUNT_STABLE;
+                       spin_unlock(&oap->oap_lock);
                }
        }
 
                }
        }
 
@@ -2273,6 +2277,8 @@ 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;
        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;
 
        oap->oap_async_flags = 0;
        oap->oap_brw_flags = brw_flags;
 
index 110704c..bf93df5 100644 (file)
@@ -164,8 +164,10 @@ static int osc_io_submit(const struct lu_env *env,
                 }
 
                cl_page_list_move(qout, qin, page);
                 }
 
                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;
                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);
                cfs_list_add_tail(&oap->oap_pending_item, &list);
 
                osc_page_submit(env, opg, crt, brw_flags);
                cfs_list_add_tail(&oap->oap_pending_item, &list);