[RFC][PATCH 4/5] must hold lock_super() to set initial mount writer

From: Dave Hansen
Date: Tue Apr 29 2008 - 15:00:55 EST



We need lock_mnt_writers() during a remount in order
to keep mnt->__mnt_writers from changing so that we
get a consistent look at if a sb currently has anyone
writing to it.

But, we need to lock writers out for an extended
period, even during the ->remount_fs() operation.
That's because we do conclusively make the fs
r/o until *after* the ->remount_fs().
lock_mnt_writers() is an awfully blunt instrument
for this since it will lock out *ALL* new writers
on the entire system. That's bad because that
remount might take a bit.

So, we introduce a new semantic. Before a new
cpu_writer is established to a mount, it must
lock_super(). This is already a slow path because
the old cpu_writer->count must be coalesced into
mnt->__mnt_writers. The fast path where (mnt ==
cpu_writer->mnt) is unaffected.


Signed-off-by: Dave Hansen <dave@xxxxxxxxxxxxxxxxxx>
---

linux-2.6.git-dave/fs/namespace.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff -puN fs/namespace.c~must-hold-lock_super-to-set-initial-mnt_writer fs/namespace.c
--- linux-2.6.git/fs/namespace.c~must-hold-lock_super-to-set-initial-mnt_writer 2008-04-29 11:56:41.000000000 -0700
+++ linux-2.6.git-dave/fs/namespace.c 2008-04-29 11:56:41.000000000 -0700
@@ -225,8 +225,20 @@ static inline void use_cpu_writer_for_mo
{
if (cpu_writer->mnt == mnt)
return;
+ /*
+ * This is a slow path taken the first time that
+ * a particular cpu_writer is used for a given
+ * mount. It lets someone (like remount) clear
+ * all the cpu_writer->mnts by lock_mnt_writers(),
+ * take lock_super(), and guarantee that no one
+ * else can get through here and acquire a new
+ * mnt_want_write() until after they
+ * unlock_super().
+ */
+ lock_super(mnt->mnt_sb);
__clear_mnt_count(cpu_writer);
cpu_writer->mnt = mnt;
+ unlock_super(mnt->mnt_sb);
}

/*
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/