Fix bug #487: osd: fix hang during mkfs

If the user has turned on journalling, but left osd_journal_size at 0,
normally we would use the existing size of the journal without
modifications. If the journal doesn't exist (i.e., we are running
mkjournal()), we have to check for this condition and return an error.
We can't create a journal if we don't know what size that journal needs
to be.

This fixes a bug where an extremely small journal file was being
created, leading to an infinite loop in FileJournal::wrap_read_bl().

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
This commit is contained in:
Colin Patrick McCabe 2010-10-14 11:51:47 -07:00
parent 17de417fad
commit ad12d5d5be
2 changed files with 12 additions and 5 deletions

View File

@ -157,6 +157,12 @@ int FileJournal::create()
char buf[80];
dout(2) << "create " << fn << dendl;
if (g_conf.osd_journal_size == 0) {
dout(0) << "You must set a non-zero journal size in order to create a journal. "
"Set osd_journal_size." << dendl;
return -EINVAL;
}
int err = _open(true, true);
if (err < 0)
return err;

View File

@ -384,18 +384,19 @@ int FileStore::mkjournal()
::read(fd, &fsid, sizeof(fsid));
::close(fd);
int ret = 0;
open_journal();
if (journal) {
int err = journal->create();
if (err < 0) {
ret = journal->create();
if (ret)
dout(0) << "mkjournal error creating journal on " << journalpath << dendl;
} else {
else
dout(0) << "mkjournal created journal on " << journalpath << dendl;
}
delete journal;
journal = 0;
}
return 0;
return ret;
}