Skip to content

Commit

Permalink
jbd: check for error returned by kthread_create on creating journal t…
Browse files Browse the repository at this point in the history
…hread

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: <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Pavel Emelianov authored and Linus Torvalds committed May 8, 2007
1 parent ee6f958 commit 97f0678
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions fs/jbd/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,16 @@ static int kjournald(void *arg)
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);
return 0;
}

static void journal_kill_thread(journal_t *journal)
Expand Down Expand Up @@ -839,8 +845,7 @@ static int journal_reset(journal_t *journal)

/* Add the dynamic fields and write it to disk. */
journal_update_superblock(journal, 1);
journal_start_thread(journal);
return 0;
return journal_start_thread(journal);
}

/**
Expand Down
13 changes: 9 additions & 4 deletions fs/jbd2/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,16 @@ static int kjournald2(void *arg)
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);
return 0;
}

static void journal_kill_thread(journal_t *journal)
Expand Down Expand Up @@ -839,8 +845,7 @@ static int journal_reset(journal_t *journal)

/* Add the dynamic fields and write it to disk. */
jbd2_journal_update_superblock(journal, 1);
jbd2_journal_start_thread(journal);
return 0;
return jbd2_journal_start_thread(journal);
}

/**
Expand Down

0 comments on commit 97f0678

Please sign in to comment.