[Ocfs2-tools-devel] [PATCH] libocfs2: Prevent journals from being truncated below their minimum size.

Joel Becker Joel.Becker at oracle.com
Tue Jul 8 16:57:00 PDT 2008


The function ocfs2_make_journal() is the major API for sizing a journal.
It is used both to grow and shrink journals.

When shrinking a journal, it currently truncates the file before calling
ocfs2_format_journal().  Only then is the new size checked against the
miniumum.  If it is too small, ocfs2_make_journal() aborts.  This leaves
the journal with too small an allocation.

The fix is to have ocfs2_make_journal() do a quick size check up front.
This prevents a journal from being left in an invalid state.

Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
 libocfs2/mkjournal.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/libocfs2/mkjournal.c b/libocfs2/mkjournal.c
index 4e8ccf0..94d1a43 100644
--- a/libocfs2/mkjournal.c
+++ b/libocfs2/mkjournal.c
@@ -260,6 +260,12 @@ errcode_t ocfs2_make_journal(ocfs2_filesys *fs, uint64_t blkno,
 	ocfs2_cached_inode *ci = NULL;
 	struct ocfs2_dinode *di;
 
+	if ((clusters << OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits) <
+	    OCFS2_MIN_JOURNAL_SIZE) {
+		ret = OCFS2_ET_JOURNAL_TOO_SMALL;
+		goto out;
+	}
+
 	ret = ocfs2_read_cached_inode(fs, blkno, &ci);
 	if (ret)
 		goto out;
-- 
1.5.6

-- 

"The whole principle is wrong; it's like demanding that grown men 
 live on skim milk because the baby can't eat steak."
        - author Robert A. Heinlein on censorship

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