Whamcloud - gitweb
LU-15660 statahead: statahead thread doesn't stop 00/52300/2
authorYang Sheng <ys@whamcloud.com>
Fri, 17 Jun 2022 12:30:34 +0000 (20:30 +0800)
committerOleg Drokin <green@whamcloud.com>
Thu, 19 Oct 2023 13:51:03 +0000 (13:51 +0000)
Add a barrier to ensure sai_task changing can be seen
when access it without locking. Else the statahead
thread could sleep forever since wake_up was lost.

Lustre-change: https://review.whamcloud.com/47673
Lustre-commit: b977caa2dc7dddcec9e20d393ee79dfa9fe31c0d

Signed-off-by: Yang Sheng <ys@whamcloud.com>
Change-Id: I211e99f1bdddaaaf028a205658f603fda034d389
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52300
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/statahead.c

index faf2860..9df5137 100644 (file)
@@ -1055,7 +1055,8 @@ static int ll_statahead_thread(void *arg)
        if (!op_data)
                GOTO(out, rc = -ENOMEM);
 
-       while (pos != MDS_DIR_END_OFF && sai->sai_task) {
+       /* matches smp_store_release() in ll_deauthorize_statahead() */
+       while (pos != MDS_DIR_END_OFF && smp_load_acquire(&sai->sai_task)) {
                struct lu_dirpage *dp;
                struct lu_dirent  *ent;
 
@@ -1081,7 +1082,8 @@ static int ll_statahead_thread(void *arg)
 
                dp = page_address(page);
                for (ent = lu_dirent_start(dp);
-                    ent != NULL && sai->sai_task &&
+                    /* matches smp_store_release() in ll_deauthorize_statahead() */
+                    ent != NULL && smp_load_acquire(&sai->sai_task) &&
                     !sa_low_hit(sai);
                     ent = lu_dirent_next(ent)) {
                        __u64 hash;
@@ -1134,7 +1136,9 @@ static int ll_statahead_thread(void *arg)
                        fid_le_to_cpu(&fid, &ent->lde_fid);
 
                        while (({set_current_state(TASK_IDLE);
-                                sai->sai_task; })) {
+                                /* matches smp_store_release() in
+                                 * ll_deauthorize_statahead() */
+                                smp_load_acquire(&sai->sai_task); })) {
                                if (sa_has_callback(sai)) {
                                        __set_current_state(TASK_RUNNING);
                                        sa_handle_callback(sai);
@@ -1217,7 +1221,8 @@ static int ll_statahead_thread(void *arg)
         * for file release to stop me.
         */
        while (({set_current_state(TASK_IDLE);
-                sai->sai_task; })) {
+               /* matches smp_store_release() in ll_deauthorize_statahead() */
+               smp_load_acquire(&sai->sai_task); })) {
                if (sa_has_callback(sai)) {
                        __set_current_state(TASK_RUNNING);
                        sa_handle_callback(sai);
@@ -1304,7 +1309,8 @@ void ll_deauthorize_statahead(struct inode *dir, void *key)
                 */
                struct task_struct *task = sai->sai_task;
 
-               sai->sai_task = NULL;
+               /* matches smp_load_acquire() in ll_statahead_thread() */
+               smp_store_release(&sai->sai_task, NULL);
                wake_up_process(task);
        }
        spin_unlock(&lli->lli_sa_lock);
@@ -1686,11 +1692,10 @@ static int start_statahead_thread(struct inode *dir, struct dentry *dentry,
                GOTO(out, rc);
        }
 
-       if (test_bit(LL_SBI_AGL_ENABLED, ll_i2sbi(parent->d_inode)->ll_flags) &&
-           agl)
+       if (test_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags) && agl)
                ll_start_agl(parent, sai);
 
-       atomic_inc(&ll_i2sbi(parent->d_inode)->ll_sa_total);
+       atomic_inc(&sbi->ll_sa_total);
        sai->sai_task = task;
 
        wake_up_process(task);