[Ocfs2-tools-devel] [PATCH] tunefs.ocfs2: Check the bitmap with the correct cluster count.
Joel Becker
Joel.Becker at oracle.com
Fri Jun 12 20:20:06 PDT 2009
When tunefs resizes a filesystem, the lowest-level ocfs2_filesys has its
fs_clusters updated, but the master ocfs2_filesys does not. When tunefs
exits, the bitmap check uses the master ocfs2_filesys.
This adds tunefs_update_fs_clusters(), which stores off any changes to
fs_clusters. When exiting, this value is used for the bitmap check.
Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
tunefs.ocfs2/libocfs2ne.c | 39 ++++++++++++++++++++++++++++++++++++++-
tunefs.ocfs2/libocfs2ne.h | 3 +++
tunefs.ocfs2/op_resize_volume.c | 4 ++++
3 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/tunefs.ocfs2/libocfs2ne.c b/tunefs.ocfs2/libocfs2ne.c
index c5362db..84f44a8 100644
--- a/tunefs.ocfs2/libocfs2ne.c
+++ b/tunefs.ocfs2/libocfs2ne.c
@@ -75,6 +75,13 @@ struct tunefs_filesystem_state {
/* Non-zero if we've ever mucked with the allocator */
int ts_allocation;
+ /*
+ * Number of clusters in the filesystem. If changed by a
+ * resized filesystem, it is tracked here and used at final
+ * close.
+ */
+ uint32_t ts_fs_clusters;
+
/* Size of the largest journal seen in tunefs_journal_check() */
uint32_t ts_journal_clusters;
@@ -146,6 +153,7 @@ static errcode_t tunefs_set_state(ocfs2_filesys *fs)
s->ts_local_fd = -1;
s->ts_online_fd = -1;
s->ts_master = fs;
+ s->ts_fs_clusters = fs->fs_clusters;
} else
s = NULL;
}
@@ -1087,8 +1095,25 @@ static errcode_t tunefs_open_bitmap_check(ocfs2_filesys *fs)
return tunefs_global_bitmap_check(fs);
}
+void tunefs_update_fs_clusters(ocfs2_filesys *fs)
+{
+ struct tunefs_private *tp = to_private(fs);
+ struct tunefs_filesystem_state *state = tunefs_get_state(fs);
+
+ if (!(tp->tp_open_flags & TUNEFS_FLAG_ALLOCATION)) {
+ verbosef(VL_LIB,
+ "Operation that claimed it would do no allocation "
+ "just attempted to update the filesystem size\n");
+ return;
+ }
+
+ state->ts_fs_clusters = fs->fs_clusters;
+}
+
static errcode_t tunefs_close_bitmap_check(ocfs2_filesys *fs)
{
+ errcode_t ret;
+ uint32_t old_clusters;
struct tunefs_filesystem_state *state = tunefs_get_state(fs);
if (!state->ts_allocation)
@@ -1097,7 +1122,19 @@ static errcode_t tunefs_close_bitmap_check(ocfs2_filesys *fs)
if (state->ts_master != fs)
return 0;
- return tunefs_global_bitmap_check(fs);
+ /*
+ * An operation that resized the filesystem will have called
+ * tunefs_update_fs_clusters(). The bitmap check needs this
+ * new value, so we swap it in for the call.
+ */
+ old_clusters = fs->fs_clusters;
+ fs->fs_clusters = state->ts_fs_clusters;
+ fs->fs_blocks = ocfs2_clusters_to_blocks(fs, fs->fs_clusters);
+ ret = tunefs_global_bitmap_check(fs);
+ fs->fs_clusters = old_clusters;
+ fs->fs_blocks = ocfs2_clusters_to_blocks(fs, fs->fs_clusters);
+
+ return ret;
}
static errcode_t tunefs_journal_check(ocfs2_filesys *fs)
diff --git a/tunefs.ocfs2/libocfs2ne.h b/tunefs.ocfs2/libocfs2ne.h
index 6138724..9ddb05f 100644
--- a/tunefs.ocfs2/libocfs2ne.h
+++ b/tunefs.ocfs2/libocfs2ne.h
@@ -227,6 +227,9 @@ errcode_t tunefs_get_free_clusters(ocfs2_filesys *fs, uint32_t *clusters);
errcode_t tunefs_empty_clusters(ocfs2_filesys *fs, uint64_t start_blk,
uint32_t num_clusters);
+/* Tell tunefs that you updated the filesystem size */
+void tunefs_update_fs_clusters(ocfs2_filesys *fs);
+
/*
* Send an ioctl() to a live filesystem for online operation. If the
* filesystem is mounted and an operation needs to be performed online,
diff --git a/tunefs.ocfs2/op_resize_volume.c b/tunefs.ocfs2/op_resize_volume.c
index 11552ff..0d0679c 100644
--- a/tunefs.ocfs2/op_resize_volume.c
+++ b/tunefs.ocfs2/op_resize_volume.c
@@ -274,6 +274,7 @@ static errcode_t init_new_gd(ocfs2_filesys *fs,
gd_blkno);
goto bail;
}
+ tunefs_update_fs_clusters(fs);
} else {
/* write a new group descriptor */
ret = ocfs2_write_group_desc(fs, gd_blkno, gd_buf);
@@ -322,6 +323,8 @@ static errcode_t update_global_bitmap(ocfs2_filesys *fs,
"while writing the global bitmap inode to block "
"%"PRIu64,
(uint64_t)di->i_blkno);
+ else
+ tunefs_update_fs_clusters(fs);
bail:
tunefs_unblock_signals();
@@ -452,6 +455,7 @@ static errcode_t run_resize(ocfs2_filesys *fs, uint32_t total_clusters,
cluster_chunk);
goto bail;
}
+ tunefs_update_fs_clusters(fs);
}
}
--
1.6.3.1
--
"And yet I fight,
And yet I fight this battle all alone.
No one to cry to;
No place to call home."
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
More information about the Ocfs2-tools-devel
mailing list