Whamcloud - gitweb
LU-12780 scrub: all update to bitfields must be protected.
[fs/lustre-release.git] / lustre / osd-zfs / osd_scrub.c
index 97cfb2d..9df6f74 100644 (file)
@@ -196,7 +196,10 @@ zget:
                        GOTO(out, rc);
                }
 
+               spin_lock(&scrub->os_lock);
                scrub->os_full_speed = 1;
+               spin_unlock(&scrub->os_lock);
+
                sf->sf_flags |= SF_INCONSISTENT;
        } else if (oid == oid2) {
                GOTO(out, rc = 0);
@@ -227,7 +230,9 @@ zget:
                }
 
 update:
+               spin_lock(&scrub->os_lock);
                scrub->os_full_speed = 1;
+               spin_unlock(&scrub->os_lock);
                sf->sf_flags |= SF_INCONSISTENT;
        }
 
@@ -304,6 +309,7 @@ static int osd_scrub_prep(const struct lu_env *env, struct osd_device *dev)
        if (flags & SS_RESET)
                scrub_file_reset(scrub, dev->od_uuid, 0);
 
+       spin_lock(&scrub->os_lock);
        scrub->os_partial_scan = 0;
        if (flags & SS_AUTO_FULL) {
                scrub->os_full_speed = 1;
@@ -315,7 +321,6 @@ static int osd_scrub_prep(const struct lu_env *env, struct osd_device *dev)
                scrub->os_full_speed = 0;
        }
 
-       spin_lock(&scrub->os_lock);
        scrub->os_in_prior = 0;
        scrub->os_waiting = 0;
        scrub->os_paused = 0;
@@ -538,7 +543,9 @@ static int osd_scrub_exec(const struct lu_env *env, struct osd_device *dev,
                        spin_unlock(&scrub->os_lock);
                }
        } else {
+               spin_lock(&scrub->os_lock);
                scrub->os_in_prior = 0;
+               spin_unlock(&scrub->os_lock);
        }
 
        if (rc)
@@ -1268,8 +1275,7 @@ static int osd_ios_ROOT_sd(const struct lu_env *env, struct osd_device *dev,
                                    sizeof(*zde) / 8, (void *)zde);
                if (rc) {
                        if (rc != -ENOENT)
-                               CWARN("%s: initial OI scrub failed to find"
-                                     "the entry %s under .lustre: rc = %d\n",
+                               CWARN("%s: initial OI scrub failed to find the entry %s under .lustre: rc = %d\n",
                                      osd_name(dev), map->olm_name, rc);
                        else if (!fid_is_zero(&map->olm_fid))
                                /* Try to remove the stale OI mapping. */
@@ -1389,7 +1395,9 @@ void osd_scrub_stop(struct osd_device *dev)
 
        /* od_otable_sem: prevent concurrent start/stop */
        down(&dev->od_otable_sem);
+       spin_lock(&scrub->os_lock);
        scrub->os_paused = 1;
+       spin_unlock(&scrub->os_lock);
        scrub_stop(scrub);
        up(&dev->od_otable_sem);
 
@@ -1679,8 +1687,8 @@ static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
        struct ptlrpc_thread *thread = &scrub->os_thread;
        struct lustre_mdt_attrs *lma = NULL;
        nvlist_t *nvbuf = NULL;
-       int size = 0;
-       int rc;
+       int rc, size = 0;
+       bool locked;
        ENTRY;
 
        LASSERT(it->ooi_user_ready);
@@ -1716,16 +1724,20 @@ again:
 
        rc = __osd_xattr_load_by_oid(dev, it->ooi_pos, &nvbuf);
 
-       if (!scrub->os_full_speed)
+       locked = false;
+       if (!scrub->os_full_speed) {
                spin_lock(&scrub->os_lock);
+               locked = true;
+       }
        it->ooi_prefetched--;
        if (!scrub->os_full_speed) {
                if (scrub->os_waiting) {
                        scrub->os_waiting = 0;
                        wake_up_all(&thread->t_ctl_waitq);
                }
-               spin_unlock(&scrub->os_lock);
        }
+       if (locked)
+               spin_unlock(&scrub->os_lock);
 
        if (rc == -ENOENT || rc == -EEXIST || rc == -ENODATA)
                goto again;