[Ocfs2-tools-devel] [PATCH 3/3] tunefs.ocfs2: Use one I/O cache.
Joel Becker
joel.becker at oracle.com
Fri Jun 12 20:18:44 PDT 2009
We nest ocfs2_filesys structures for each operation. However, this can
mean that the I/O cache on the master filesys is stale when a child
filesys has written to its own cache.
Instead, we'll create an I/O cache on the master filesys and share it in
the children. That way all operations have a consistent view of the
disk.
Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
tunefs.ocfs2/libocfs2ne.c | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/tunefs.ocfs2/libocfs2ne.c b/tunefs.ocfs2/libocfs2ne.c
index f588596..5044f65 100644
--- a/tunefs.ocfs2/libocfs2ne.c
+++ b/tunefs.ocfs2/libocfs2ne.c
@@ -1259,10 +1259,21 @@ static void tunefs_init_cache(ocfs2_filesys *fs)
{
errcode_t err;
struct tunefs_private *tp = to_private(fs);
+ struct tunefs_filesystem_state *state = tunefs_get_state(fs);
uint64_t blocks_wanted;
int scale_down;
/*
+ * We have one I/O cache for all ocfs2_filesys structures. This
+ * guarantees a consistent view of the disk. The master filesys
+ * allocates it, child filesyses just use it.
+ */
+ if (state->ts_master != fs) {
+ fs->fs_io = state->ts_master->fs_io;
+ return;
+ }
+
+ /*
* Operations needing a large cache really want enough to
* hold the whole filesystem in memory. The rest of the
* operations don't need much at all. A cache big enough to
@@ -1314,6 +1325,21 @@ static void tunefs_init_cache(ocfs2_filesys *fs)
}
}
+static void tunefs_drop_cache(ocfs2_filesys *fs)
+{
+ struct tunefs_filesystem_state *state = tunefs_get_state(fs);
+
+ /*
+ * The master filesys created our cache. We don't want
+ * ocfs2_close() to kill it if we're closing a non-master,
+ * so kill the pointer for those.
+ */
+ if (state->ts_master == fs)
+ io_destroy_cache(fs->fs_io);
+ else
+ fs->fs_io = NULL;
+}
+
static errcode_t tunefs_add_fs(ocfs2_filesys *fs, int flags)
{
errcode_t err;
@@ -1470,6 +1496,7 @@ errcode_t tunefs_open(const char *device, int flags,
out:
if (err && !tunefs_special_errorp(err)) {
if (fs) {
+ tunefs_drop_cache(fs);
tunefs_remove_fs(fs);
ocfs2_close(fs);
fs = NULL;
@@ -1499,6 +1526,7 @@ errcode_t tunefs_close(ocfs2_filesys *fs)
if (!err)
err = tmp;
+ tunefs_drop_cache(fs);
tunefs_remove_fs(fs);
tmp = ocfs2_close(fs);
if (!err)
--
1.6.3.1
More information about the Ocfs2-tools-devel
mailing list