Skip to content

Commit bbbd27e

Browse files
committed
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull ext2, ext3, udf updates from Jan Kara: "Several UDF fixes, a support for UDF extent cache, and couple of ext2 and ext3 cleanups and minor fixes" * 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: Ext2: remove the static function release_blocks to optimize the kernel Ext2: mark inode dirty after the function dquot_free_block_nodirty is called Ext2: remove the overhead check about sb in the function ext2_new_blocks udf: Remove unused s_extLength from udf_bitmap udf: Make s_block_bitmap standard array udf: Fix bitmap overflow on large filesystems with small block size udf: add extent cache support in case of file reading udf: Write LVID to disk after opening / closing Ext3: return ENOMEM rather than EIO if sb_getblk fails Ext2: return ENOMEM rather than EIO if sb_getblk fails Ext3: use unlikely to improve the efficiency of the kernel Ext2: use unlikely to improve the efficiency of the kernel Ext3: add necessary check in case IO error happens Ext2: free memory allocated and forget buffer head when io error happens ext3: Fix memory leak when quota options are specified multiple times ext3, ext4, ocfs2: remove unused macro NAMEI_RA_INDEX
2 parents a6590b9 + 712ddc5 commit bbbd27e

16 files changed

Lines changed: 177 additions & 78 deletions

File tree

‎fs/ext2/balloc.c‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,6 @@ read_block_bitmap(struct super_block *sb, unsigned int block_group)
159159
return bh;
160160
}
161161

162-
static void release_blocks(struct super_block *sb, int count)
163-
{
164-
if (count) {
165-
struct ext2_sb_info *sbi = EXT2_SB(sb);
166-
167-
percpu_counter_add(&sbi->s_freeblocks_counter, count);
168-
}
169-
}
170-
171162
static void group_adjust_blocks(struct super_block *sb, int group_no,
172163
struct ext2_group_desc *desc, struct buffer_head *bh, int count)
173164
{
@@ -568,8 +559,11 @@ void ext2_free_blocks (struct inode * inode, unsigned long block,
568559
}
569560
error_return:
570561
brelse(bitmap_bh);
571-
release_blocks(sb, freed);
572-
dquot_free_block_nodirty(inode, freed);
562+
if (freed) {
563+
percpu_counter_add(&sbi->s_freeblocks_counter, freed);
564+
dquot_free_block_nodirty(inode, freed);
565+
mark_inode_dirty(inode);
566+
}
573567
}
574568

575569
/**
@@ -1239,10 +1233,6 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
12391233

12401234
*errp = -ENOSPC;
12411235
sb = inode->i_sb;
1242-
if (!sb) {
1243-
printk("ext2_new_blocks: nonexistent device");
1244-
return 0;
1245-
}
12461236

12471237
/*
12481238
* Check quota for allocation of this block.
@@ -1416,9 +1406,11 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
14161406

14171407
*errp = 0;
14181408
brelse(bitmap_bh);
1419-
dquot_free_block_nodirty(inode, *count-num);
1420-
mark_inode_dirty(inode);
1421-
*count = num;
1409+
if (num < *count) {
1410+
dquot_free_block_nodirty(inode, *count-num);
1411+
mark_inode_dirty(inode);
1412+
*count = num;
1413+
}
14221414
return ret_block;
14231415

14241416
io_error:

‎fs/ext2/inode.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ static int ext2_alloc_branch(struct inode *inode,
495495
* parent to disk.
496496
*/
497497
bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
498+
if (unlikely(!bh)) {
499+
err = -ENOMEM;
500+
goto failed;
501+
}
498502
branch[n].bh = bh;
499503
lock_buffer(bh);
500504
memset(bh->b_data, 0, blocksize);
@@ -523,6 +527,14 @@ static int ext2_alloc_branch(struct inode *inode,
523527
}
524528
*blks = num;
525529
return err;
530+
531+
failed:
532+
for (i = 1; i < n; i++)
533+
bforget(branch[i].bh);
534+
for (i = 0; i < indirect_blks; i++)
535+
ext2_free_blocks(inode, new_blocks[i], 1);
536+
ext2_free_blocks(inode, new_blocks[i], num);
537+
return err;
526538
}
527539

528540
/**

‎fs/ext2/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type,
15001500
bh = sb_bread(sb, tmp_bh.b_blocknr);
15011501
else
15021502
bh = sb_getblk(sb, tmp_bh.b_blocknr);
1503-
if (!bh) {
1503+
if (unlikely(!bh)) {
15041504
err = -EIO;
15051505
goto out;
15061506
}

‎fs/ext2/xattr.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,10 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
662662
ea_idebug(inode, "creating block %d", block);
663663

664664
new_bh = sb_getblk(sb, block);
665-
if (!new_bh) {
665+
if (unlikely(!new_bh)) {
666666
ext2_free_blocks(inode, block, 1);
667667
mark_inode_dirty(inode);
668-
error = -EIO;
668+
error = -ENOMEM;
669669
goto cleanup;
670670
}
671671
lock_buffer(new_bh);

‎fs/ext3/inode.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
676676
* parent to disk.
677677
*/
678678
bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
679+
if (unlikely(!bh)) {
680+
err = -ENOMEM;
681+
goto failed;
682+
}
679683
branch[n].bh = bh;
680684
lock_buffer(bh);
681685
BUFFER_TRACE(bh, "call get_create_access");
@@ -717,7 +721,7 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
717721
BUFFER_TRACE(branch[i].bh, "call journal_forget");
718722
ext3_journal_forget(handle, branch[i].bh);
719723
}
720-
for (i = 0; i <indirect_blks; i++)
724+
for (i = 0; i < indirect_blks; i++)
721725
ext3_free_blocks(handle, inode, new_blocks[i], 1);
722726

723727
ext3_free_blocks(handle, inode, new_blocks[i], num);
@@ -1078,8 +1082,8 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode,
10781082
if (!err && buffer_mapped(&dummy)) {
10791083
struct buffer_head *bh;
10801084
bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
1081-
if (!bh) {
1082-
*errp = -EIO;
1085+
if (unlikely(!bh)) {
1086+
*errp = -ENOMEM;
10831087
goto err;
10841088
}
10851089
if (buffer_new(&dummy)) {
@@ -2729,12 +2733,12 @@ static int __ext3_get_inode_loc(struct inode *inode,
27292733
return -EIO;
27302734

27312735
bh = sb_getblk(inode->i_sb, block);
2732-
if (!bh) {
2736+
if (unlikely(!bh)) {
27332737
ext3_error (inode->i_sb, "ext3_get_inode_loc",
27342738
"unable to read inode block - "
27352739
"inode=%lu, block="E3FSBLK,
27362740
inode->i_ino, block);
2737-
return -EIO;
2741+
return -ENOMEM;
27382742
}
27392743
if (!buffer_uptodate(bh)) {
27402744
lock_buffer(bh);
@@ -2783,7 +2787,7 @@ static int __ext3_get_inode_loc(struct inode *inode,
27832787

27842788
bitmap_bh = sb_getblk(inode->i_sb,
27852789
le32_to_cpu(desc->bg_inode_bitmap));
2786-
if (!bitmap_bh)
2790+
if (unlikely(!bitmap_bh))
27872791
goto make_io;
27882792

27892793
/*

‎fs/ext3/namei.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#define NAMEI_RA_CHUNKS 2
3737
#define NAMEI_RA_BLOCKS 4
3838
#define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
39-
#define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
4039

4140
static struct buffer_head *ext3_append(handle_t *handle,
4241
struct inode *inode,

‎fs/ext3/resize.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
116116
int err;
117117

118118
bh = sb_getblk(sb, blk);
119-
if (!bh)
120-
return ERR_PTR(-EIO);
119+
if (unlikely(!bh))
120+
return ERR_PTR(-ENOMEM);
121121
if ((err = ext3_journal_get_write_access(handle, bh))) {
122122
brelse(bh);
123123
bh = ERR_PTR(err);
@@ -234,8 +234,8 @@ static int setup_new_group_blocks(struct super_block *sb,
234234
goto exit_bh;
235235

236236
gdb = sb_getblk(sb, block);
237-
if (!gdb) {
238-
err = -EIO;
237+
if (unlikely(!gdb)) {
238+
err = -ENOMEM;
239239
goto exit_bh;
240240
}
241241
if ((err = ext3_journal_get_write_access(handle, gdb))) {
@@ -722,8 +722,8 @@ static void update_backups(struct super_block *sb,
722722
break;
723723

724724
bh = sb_getblk(sb, group * bpg + blk_off);
725-
if (!bh) {
726-
err = -EIO;
725+
if (unlikely(!bh)) {
726+
err = -ENOMEM;
727727
break;
728728
}
729729
ext3_debug("update metadata backup %#04lx\n",

‎fs/ext3/super.c‎

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -916,21 +916,24 @@ static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
916916
"Not enough memory for storing quotafile name");
917917
return 0;
918918
}
919-
if (sbi->s_qf_names[qtype] &&
920-
strcmp(sbi->s_qf_names[qtype], qname)) {
921-
ext3_msg(sb, KERN_ERR,
922-
"%s quota file already specified", QTYPE2NAME(qtype));
919+
if (sbi->s_qf_names[qtype]) {
920+
int same = !strcmp(sbi->s_qf_names[qtype], qname);
921+
923922
kfree(qname);
924-
return 0;
923+
if (!same) {
924+
ext3_msg(sb, KERN_ERR,
925+
"%s quota file already specified",
926+
QTYPE2NAME(qtype));
927+
}
928+
return same;
925929
}
926-
sbi->s_qf_names[qtype] = qname;
927-
if (strchr(sbi->s_qf_names[qtype], '/')) {
930+
if (strchr(qname, '/')) {
928931
ext3_msg(sb, KERN_ERR,
929932
"quotafile must be on filesystem root");
930-
kfree(sbi->s_qf_names[qtype]);
931-
sbi->s_qf_names[qtype] = NULL;
933+
kfree(qname);
932934
return 0;
933935
}
936+
sbi->s_qf_names[qtype] = qname;
934937
set_opt(sbi->s_mount_opt, QUOTA);
935938
return 1;
936939
}
@@ -945,11 +948,10 @@ static int clear_qf_name(struct super_block *sb, int qtype) {
945948
" when quota turned on");
946949
return 0;
947950
}
948-
/*
949-
* The space will be released later when all options are confirmed
950-
* to be correct
951-
*/
952-
sbi->s_qf_names[qtype] = NULL;
951+
if (sbi->s_qf_names[qtype]) {
952+
kfree(sbi->s_qf_names[qtype]);
953+
sbi->s_qf_names[qtype] = NULL;
954+
}
953955
return 1;
954956
}
955957
#endif
@@ -2606,7 +2608,18 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
26062608
#ifdef CONFIG_QUOTA
26072609
old_opts.s_jquota_fmt = sbi->s_jquota_fmt;
26082610
for (i = 0; i < MAXQUOTAS; i++)
2609-
old_opts.s_qf_names[i] = sbi->s_qf_names[i];
2611+
if (sbi->s_qf_names[i]) {
2612+
old_opts.s_qf_names[i] = kstrdup(sbi->s_qf_names[i],
2613+
GFP_KERNEL);
2614+
if (!old_opts.s_qf_names[i]) {
2615+
int j;
2616+
2617+
for (j = 0; j < i; j++)
2618+
kfree(old_opts.s_qf_names[j]);
2619+
return -ENOMEM;
2620+
}
2621+
} else
2622+
old_opts.s_qf_names[i] = NULL;
26102623
#endif
26112624

26122625
/*
@@ -2699,9 +2712,7 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
26992712
#ifdef CONFIG_QUOTA
27002713
/* Release old quota file names */
27012714
for (i = 0; i < MAXQUOTAS; i++)
2702-
if (old_opts.s_qf_names[i] &&
2703-
old_opts.s_qf_names[i] != sbi->s_qf_names[i])
2704-
kfree(old_opts.s_qf_names[i]);
2715+
kfree(old_opts.s_qf_names[i]);
27052716
#endif
27062717
if (enable_quota)
27072718
dquot_resume(sb, -1);
@@ -2715,9 +2726,7 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
27152726
#ifdef CONFIG_QUOTA
27162727
sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
27172728
for (i = 0; i < MAXQUOTAS; i++) {
2718-
if (sbi->s_qf_names[i] &&
2719-
old_opts.s_qf_names[i] != sbi->s_qf_names[i])
2720-
kfree(sbi->s_qf_names[i]);
2729+
kfree(sbi->s_qf_names[i]);
27212730
sbi->s_qf_names[i] = old_opts.s_qf_names[i];
27222731
}
27232732
#endif

‎fs/ext3/xattr.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,10 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
813813
ea_idebug(inode, "creating block %d", block);
814814

815815
new_bh = sb_getblk(sb, block);
816-
if (!new_bh) {
816+
if (unlikely(!new_bh)) {
817817
getblk_failed:
818818
ext3_free_blocks(handle, inode, block, 1);
819-
error = -EIO;
819+
error = -ENOMEM;
820820
goto cleanup;
821821
}
822822
lock_buffer(new_bh);

‎fs/ext4/namei.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#define NAMEI_RA_CHUNKS 2
4848
#define NAMEI_RA_BLOCKS 4
4949
#define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
50-
#define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
5150

5251
static struct buffer_head *ext4_append(handle_t *handle,
5352
struct inode *inode,

0 commit comments

Comments
 (0)