Skip to content

Commit

Permalink
When mounting SU-enabled mount point, wait until the softdep_flush()
Browse files Browse the repository at this point in the history
thread started and incremented the stat_flush_threads [1].

Unconditionally wakeup softdep_flush threads when needed, do not try
to check wchan, which is racy and breaks abstraction.

Reported by and discussed with:	glebius, neel
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
  • Loading branch information
kostikbel committed Jan 30, 2015
1 parent 798c260 commit 8372341
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 16 additions & 7 deletions sys/ufs/ffs/ffs_softdep.c
Expand Up @@ -1377,6 +1377,10 @@ softdep_flush(addr)
mp = (struct mount *)addr;
ump = VFSTOUFS(mp);
atomic_add_int(&stat_flush_threads, 1);
ACQUIRE_LOCK(ump);
ump->softdep_flags &= ~FLUSH_STARTING;
wakeup(&ump->softdep_flushtd);
FREE_LOCK(ump);
if (print_threads) {
if (stat_flush_threads == 1)
printf("Running %s at pid %d\n", bufdaemonproc->p_comm,
Expand All @@ -1389,7 +1393,7 @@ softdep_flush(addr)
VFSTOUFS(mp)->softdep_jblocks->jb_suspended))
kthread_suspend_check();
ACQUIRE_LOCK(ump);
if ((ump->softdep_flags & FLUSH_CLEANUP) == 0)
while ((ump->softdep_flags & (FLUSH_CLEANUP | FLUSH_EXIT)) == 0)
msleep(&ump->softdep_flushtd, LOCK_PTR(ump), PVM,
"sdflush", hz / 2);
ump->softdep_flags &= ~FLUSH_CLEANUP;
Expand Down Expand Up @@ -1421,8 +1425,7 @@ worklist_speedup(mp)
LOCK_OWNED(ump);
if ((ump->softdep_flags & (FLUSH_CLEANUP | FLUSH_EXIT)) == 0) {
ump->softdep_flags |= FLUSH_CLEANUP;
if (ump->softdep_flushtd->td_wchan == &ump->softdep_flushtd)
wakeup(&ump->softdep_flushtd);
wakeup(&ump->softdep_flushtd);
}
}

Expand Down Expand Up @@ -1471,10 +1474,7 @@ softdep_speedup(ump)
(FLUSH_CLEANUP | FLUSH_EXIT)) == 0) {
altump->softdep_flags |= FLUSH_CLEANUP;
altump->um_softdep->sd_cleanups++;
if (altump->softdep_flushtd->td_wchan ==
&altump->softdep_flushtd) {
wakeup(&altump->softdep_flushtd);
}
wakeup(&altump->softdep_flushtd);
}
FREE_LOCK(altump);
}
Expand Down Expand Up @@ -2491,9 +2491,18 @@ softdep_mount(devvp, mp, fs, cred)
/*
* Start our flushing thread in the bufdaemon process.
*/
ACQUIRE_LOCK(ump);
ump->softdep_flags |= FLUSH_STARTING;
FREE_LOCK(ump);
kproc_kthread_add(&softdep_flush, mp, &bufdaemonproc,
&ump->softdep_flushtd, 0, 0, "softdepflush", "%s worker",
mp->mnt_stat.f_mntonname);
ACQUIRE_LOCK(ump);
while ((ump->softdep_flags & FLUSH_STARTING) != 0) {
msleep(&ump->softdep_flushtd, LOCK_PTR(ump), PVM, "sdstart",
hz / 2);
}
FREE_LOCK(ump);
/*
* When doing soft updates, the counters in the
* superblock may have gotten out of sync. Recomputation
Expand Down
2 changes: 2 additions & 0 deletions sys/ufs/ffs/softdep.h
Expand Up @@ -1063,6 +1063,8 @@ struct mount_softdeps {
*/
#define FLUSH_EXIT 0x0001 /* time to exit */
#define FLUSH_CLEANUP 0x0002 /* need to clear out softdep structures */
#define FLUSH_STARTING 0x0004 /* flush thread not yet started */

/*
* Keep the old names from when these were in the ufsmount structure.
*/
Expand Down

0 comments on commit 8372341

Please sign in to comment.