提交 eff25028 编写于 作者: L Linus Torvalds

Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
  delay capable() check in ext4_has_free_blocks()
  merge ext4_claim_free_blocks & ext4_has_free_blocks
  jbd2: Call the commit callback before the transaction could get dropped
  ext4: fix a bug accessing freed memory in ext4_abort
  ext3: fix a bug accessing freed memory in ext3_abort
...@@ -281,7 +281,8 @@ void ext3_abort (struct super_block * sb, const char * function, ...@@ -281,7 +281,8 @@ void ext3_abort (struct super_block * sb, const char * function,
EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS;
sb->s_flags |= MS_RDONLY; sb->s_flags |= MS_RDONLY;
EXT3_SB(sb)->s_mount_opt |= EXT3_MOUNT_ABORT; EXT3_SB(sb)->s_mount_opt |= EXT3_MOUNT_ABORT;
journal_abort(EXT3_SB(sb)->s_journal, -EIO); if (EXT3_SB(sb)->s_journal)
journal_abort(EXT3_SB(sb)->s_journal, -EIO);
} }
void ext3_warning (struct super_block * sb, const char * function, void ext3_warning (struct super_block * sb, const char * function,
...@@ -390,11 +391,14 @@ static void ext3_put_super (struct super_block * sb) ...@@ -390,11 +391,14 @@ static void ext3_put_super (struct super_block * sb)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext3_sb_info *sbi = EXT3_SB(sb);
struct ext3_super_block *es = sbi->s_es; struct ext3_super_block *es = sbi->s_es;
int i; int i, err;
ext3_xattr_put_super(sb); ext3_xattr_put_super(sb);
if (journal_destroy(sbi->s_journal) < 0) err = journal_destroy(sbi->s_journal);
sbi->s_journal = NULL;
if (err < 0)
ext3_abort(sb, __func__, "Couldn't clean up the journal"); ext3_abort(sb, __func__, "Couldn't clean up the journal");
if (!(sb->s_flags & MS_RDONLY)) { if (!(sb->s_flags & MS_RDONLY)) {
EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
es->s_state = cpu_to_le16(sbi->s_mount_state); es->s_state = cpu_to_le16(sbi->s_mount_state);
......
...@@ -589,21 +589,23 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, ...@@ -589,21 +589,23 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
return; return;
} }
int ext4_claim_free_blocks(struct ext4_sb_info *sbi, /**
s64 nblocks) * ext4_has_free_blocks()
* @sbi: in-core super block structure.
* @nblocks: number of needed blocks
*
* Check if filesystem has nblocks free & available for allocation.
* On success return 1, return 0 on failure.
*/
int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks)
{ {
s64 free_blocks, dirty_blocks; s64 free_blocks, dirty_blocks, root_blocks;
s64 root_blocks = 0;
struct percpu_counter *fbc = &sbi->s_freeblocks_counter; struct percpu_counter *fbc = &sbi->s_freeblocks_counter;
struct percpu_counter *dbc = &sbi->s_dirtyblocks_counter; struct percpu_counter *dbc = &sbi->s_dirtyblocks_counter;
free_blocks = percpu_counter_read_positive(fbc); free_blocks = percpu_counter_read_positive(fbc);
dirty_blocks = percpu_counter_read_positive(dbc); dirty_blocks = percpu_counter_read_positive(dbc);
root_blocks = ext4_r_blocks_count(sbi->s_es);
if (!capable(CAP_SYS_RESOURCE) &&
sbi->s_resuid != current->fsuid &&
(sbi->s_resgid == 0 || !in_group_p(sbi->s_resgid)))
root_blocks = ext4_r_blocks_count(sbi->s_es);
if (free_blocks - (nblocks + root_blocks + dirty_blocks) < if (free_blocks - (nblocks + root_blocks + dirty_blocks) <
EXT4_FREEBLOCKS_WATERMARK) { EXT4_FREEBLOCKS_WATERMARK) {
...@@ -616,57 +618,32 @@ int ext4_claim_free_blocks(struct ext4_sb_info *sbi, ...@@ -616,57 +618,32 @@ int ext4_claim_free_blocks(struct ext4_sb_info *sbi,
} }
} }
/* Check whether we have space after /* Check whether we have space after
* accounting for current dirty blocks * accounting for current dirty blocks & root reserved blocks.
*/ */
if (free_blocks < ((root_blocks + nblocks) + dirty_blocks)) if (free_blocks >= ((root_blocks + nblocks) + dirty_blocks))
/* we don't have free space */ return 1;
return -ENOSPC;
/* Hm, nope. Are (enough) root reserved blocks available? */
if (sbi->s_resuid == current->fsuid ||
((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
capable(CAP_SYS_RESOURCE)) {
if (free_blocks >= (nblocks + dirty_blocks))
return 1;
}
/* Add the blocks to nblocks */
percpu_counter_add(dbc, nblocks);
return 0; return 0;
} }
/** int ext4_claim_free_blocks(struct ext4_sb_info *sbi,
* ext4_has_free_blocks()
* @sbi: in-core super block structure.
* @nblocks: number of neeed blocks
*
* Check if filesystem has free blocks available for allocation.
* Return the number of blocks avaible for allocation for this request
* On success, return nblocks
*/
ext4_fsblk_t ext4_has_free_blocks(struct ext4_sb_info *sbi,
s64 nblocks) s64 nblocks)
{ {
s64 free_blocks, dirty_blocks; if (ext4_has_free_blocks(sbi, nblocks)) {
s64 root_blocks = 0; percpu_counter_add(&sbi->s_dirtyblocks_counter, nblocks);
struct percpu_counter *fbc = &sbi->s_freeblocks_counter;
struct percpu_counter *dbc = &sbi->s_dirtyblocks_counter;
free_blocks = percpu_counter_read_positive(fbc);
dirty_blocks = percpu_counter_read_positive(dbc);
if (!capable(CAP_SYS_RESOURCE) &&
sbi->s_resuid != current->fsuid &&
(sbi->s_resgid == 0 || !in_group_p(sbi->s_resgid)))
root_blocks = ext4_r_blocks_count(sbi->s_es);
if (free_blocks - (nblocks + root_blocks + dirty_blocks) <
EXT4_FREEBLOCKS_WATERMARK) {
free_blocks = percpu_counter_sum(fbc);
dirty_blocks = percpu_counter_sum(dbc);
}
if (free_blocks <= (root_blocks + dirty_blocks))
/* we don't have free space */
return 0; return 0;
} else
if (free_blocks - (root_blocks + dirty_blocks) < nblocks) return -ENOSPC;
return free_blocks - (root_blocks + dirty_blocks);
return nblocks;
} }
/** /**
* ext4_should_retry_alloc() * ext4_should_retry_alloc()
* @sb: super block * @sb: super block
......
...@@ -1003,8 +1003,7 @@ extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1003,8 +1003,7 @@ extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
ext4_lblk_t iblock, ext4_fsblk_t goal, ext4_lblk_t iblock, ext4_fsblk_t goal,
unsigned long *count, int *errp); unsigned long *count, int *errp);
extern int ext4_claim_free_blocks(struct ext4_sb_info *sbi, s64 nblocks); extern int ext4_claim_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
extern ext4_fsblk_t ext4_has_free_blocks(struct ext4_sb_info *sbi, extern int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
s64 nblocks);
extern void ext4_free_blocks(handle_t *handle, struct inode *inode, extern void ext4_free_blocks(handle_t *handle, struct inode *inode,
ext4_fsblk_t block, unsigned long count, int metadata); ext4_fsblk_t block, unsigned long count, int metadata);
extern void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb, extern void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb,
......
...@@ -333,7 +333,8 @@ void ext4_abort(struct super_block *sb, const char *function, ...@@ -333,7 +333,8 @@ void ext4_abort(struct super_block *sb, const char *function,
EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
sb->s_flags |= MS_RDONLY; sb->s_flags |= MS_RDONLY;
EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO); if (EXT4_SB(sb)->s_journal)
jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
} }
void ext4_warning(struct super_block *sb, const char *function, void ext4_warning(struct super_block *sb, const char *function,
...@@ -442,14 +443,16 @@ static void ext4_put_super(struct super_block *sb) ...@@ -442,14 +443,16 @@ static void ext4_put_super(struct super_block *sb)
{ {
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext4_super_block *es = sbi->s_es; struct ext4_super_block *es = sbi->s_es;
int i; int i, err;
ext4_mb_release(sb); ext4_mb_release(sb);
ext4_ext_release(sb); ext4_ext_release(sb);
ext4_xattr_put_super(sb); ext4_xattr_put_super(sb);
if (jbd2_journal_destroy(sbi->s_journal) < 0) err = jbd2_journal_destroy(sbi->s_journal);
ext4_abort(sb, __func__, "Couldn't clean up the journal");
sbi->s_journal = NULL; sbi->s_journal = NULL;
if (err < 0)
ext4_abort(sb, __func__, "Couldn't clean up the journal");
if (!(sb->s_flags & MS_RDONLY)) { if (!(sb->s_flags & MS_RDONLY)) {
EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
es->s_state = cpu_to_le16(sbi->s_mount_state); es->s_state = cpu_to_le16(sbi->s_mount_state);
......
...@@ -974,6 +974,9 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -974,6 +974,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
journal->j_committing_transaction = NULL; journal->j_committing_transaction = NULL;
spin_unlock(&journal->j_state_lock); spin_unlock(&journal->j_state_lock);
if (journal->j_commit_callback)
journal->j_commit_callback(journal, commit_transaction);
if (commit_transaction->t_checkpoint_list == NULL && if (commit_transaction->t_checkpoint_list == NULL &&
commit_transaction->t_checkpoint_io_list == NULL) { commit_transaction->t_checkpoint_io_list == NULL) {
__jbd2_journal_drop_transaction(journal, commit_transaction); __jbd2_journal_drop_transaction(journal, commit_transaction);
...@@ -995,11 +998,8 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -995,11 +998,8 @@ void jbd2_journal_commit_transaction(journal_t *journal)
} }
spin_unlock(&journal->j_list_lock); spin_unlock(&journal->j_list_lock);
if (journal->j_commit_callback)
journal->j_commit_callback(journal, commit_transaction);
trace_mark(jbd2_end_commit, "dev %s transaction %d head %d", trace_mark(jbd2_end_commit, "dev %s transaction %d head %d",
journal->j_devname, commit_transaction->t_tid, journal->j_devname, journal->j_commit_sequence,
journal->j_tail_sequence); journal->j_tail_sequence);
jbd_debug(1, "JBD: commit %d complete, head %d\n", jbd_debug(1, "JBD: commit %d complete, head %d\n",
journal->j_commit_sequence, journal->j_tail_sequence); journal->j_commit_sequence, journal->j_tail_sequence);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册