Commit 97f06784 authored by Pavel Emelianov's avatar Pavel Emelianov Committed by Linus Torvalds

jbd: check for error returned by kthread_create on creating journal thread

If the thread failed to create the subsequent wait_event will hang forever.

This is likely to happen if kernel hits max_threads limit.

Will be critical for virtualization systems that limit the number of tasks
and kernel memory usage within the container.

(akpm: JBD should be converted fully to the kthread API: kthread_should_stop()
and kthread_stop()).

Cc: <linux-ext4@vger.kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ee6f9582
...@@ -210,10 +210,16 @@ end_loop: ...@@ -210,10 +210,16 @@ end_loop:
return 0; return 0;
} }
static void journal_start_thread(journal_t *journal) static int journal_start_thread(journal_t *journal)
{ {
kthread_run(kjournald, journal, "kjournald"); struct task_struct *t;
t = kthread_run(kjournald, journal, "kjournald");
if (IS_ERR(t))
return PTR_ERR(t);
wait_event(journal->j_wait_done_commit, journal->j_task != 0); wait_event(journal->j_wait_done_commit, journal->j_task != 0);
return 0;
} }
static void journal_kill_thread(journal_t *journal) static void journal_kill_thread(journal_t *journal)
...@@ -839,8 +845,7 @@ static int journal_reset(journal_t *journal) ...@@ -839,8 +845,7 @@ static int journal_reset(journal_t *journal)
/* Add the dynamic fields and write it to disk. */ /* Add the dynamic fields and write it to disk. */
journal_update_superblock(journal, 1); journal_update_superblock(journal, 1);
journal_start_thread(journal); return journal_start_thread(journal);
return 0;
} }
/** /**
......
...@@ -210,10 +210,16 @@ end_loop: ...@@ -210,10 +210,16 @@ end_loop:
return 0; return 0;
} }
static void jbd2_journal_start_thread(journal_t *journal) static int jbd2_journal_start_thread(journal_t *journal)
{ {
kthread_run(kjournald2, journal, "kjournald2"); struct task_struct *t;
t = kthread_run(kjournald2, journal, "kjournald2");
if (IS_ERR(t))
return PTR_ERR(t);
wait_event(journal->j_wait_done_commit, journal->j_task != 0); wait_event(journal->j_wait_done_commit, journal->j_task != 0);
return 0;
} }
static void journal_kill_thread(journal_t *journal) static void journal_kill_thread(journal_t *journal)
...@@ -839,8 +845,7 @@ static int journal_reset(journal_t *journal) ...@@ -839,8 +845,7 @@ static int journal_reset(journal_t *journal)
/* Add the dynamic fields and write it to disk. */ /* Add the dynamic fields and write it to disk. */
jbd2_journal_update_superblock(journal, 1); jbd2_journal_update_superblock(journal, 1);
jbd2_journal_start_thread(journal); return jbd2_journal_start_thread(journal);
return 0;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment