@@ -1146,14 +1146,23 @@ out:
*/
void __sb_end_write(struct super_block *sb, int level)
{
+ rcu_read_lock();
percpu_counter_dec(&sb->s_writers.counter[level-1]);
/*
- * Make sure s_writers are updated before we wake up waiters in
- * freeze_super().
+ * We are racing here with freeze_super()'s calls to
+ * sb_wait_write(). We want to ensure that we call
+ * wake_up() whenever one of those calls _might_ be
+ * in sb_wait_write().
+ *
+ * Since freeze_super() does a synchronize_rcu() before
+ * each of its sb_wait_write() calls, it can guarantee
+ * that it sees our update to s_writers.counter as well
+ * as that we see its update to s_writers.frozen.
*/
- smp_mb();
- if (waitqueue_active(&sb->s_writers.wait))
+ if (unlikely(sb->s_writers.frozen >= level))
wake_up(&sb->s_writers.wait);
+ rcu_read_unlock();
+
rwsem_release(&sb->s_writers.lock_map[level-1], 1, _RET_IP_);
}
EXPORT_SYMBOL(__sb_end_write);