From 2fb7d99d0de3fd8ae869f35ab682581d8455887a Mon Sep 17 00:00:00 2001 From: Namjae Jeon Date: Wed, 10 Oct 2012 00:08:56 +0900 Subject: [PATCH 1/6] udf: fix memory leak while allocating blocks during write Need to brelse the buffer_head stored in cur_epos and next_epos. Signed-off-by: Namjae Jeon Signed-off-by: Ashish Sangwan Signed-off-by: Jan Kara --- fs/udf/inode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index df88b957ccf..2b7759371ff 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -765,6 +765,8 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, goal, err); if (!newblocknum) { brelse(prev_epos.bh); + brelse(cur_epos.bh); + brelse(next_epos.bh); *err = -ENOSPC; return 0; } @@ -795,6 +797,8 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); brelse(prev_epos.bh); + brelse(cur_epos.bh); + brelse(next_epos.bh); newblock = udf_get_pblock(inode->i_sb, newblocknum, iinfo->i_location.partitionReferenceNum, 0); From fb719c59bdb4fca86ee1fd1f42ab3735ca12b6b2 Mon Sep 17 00:00:00 2001 From: Namjae Jeon Date: Wed, 10 Oct 2012 00:09:12 +0900 Subject: [PATCH 2/6] udf: don't increment lenExtents while writing to a hole Incrementing lenExtents even while writing to a hole is bad for performance as calls to udf_discard_prealloc and udf_truncate_tail_extent would not return from start if isize != lenExtents Signed-off-by: Namjae Jeon Signed-off-by: Ashish Sangwan Signed-off-by: Jan Kara --- fs/udf/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 2b7759371ff..8266f2ed7fc 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -601,6 +601,7 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, struct udf_inode_info *iinfo = UDF_I(inode); int goal = 0, pgoal = iinfo->i_location.logicalBlockNum; int lastblock = 0; + bool isBeyondEOF; *err = 0; *new = 0; @@ -680,7 +681,7 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, /* Are we beyond EOF? */ if (etype == -1) { int ret; - + isBeyondEOF = 1; if (count) { if (c) laarr[0] = laarr[1]; @@ -723,6 +724,7 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, endnum = c + 1; lastblock = 1; } else { + isBeyondEOF = 0; endnum = startnum = ((count > 2) ? 2 : count); /* if the current extent is in position 0, @@ -770,7 +772,8 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, *err = -ENOSPC; return 0; } - iinfo->i_lenExtents += inode->i_sb->s_blocksize; + if (isBeyondEOF) + iinfo->i_lenExtents += inode->i_sb->s_blocksize; } /* if the extent the requsted block is located in contains multiple From 6d31d15f21b376ac0d8a2323fd6673683bc82bd6 Mon Sep 17 00:00:00 2001 From: Namjae Jeon Date: Wed, 10 Oct 2012 00:09:44 +0900 Subject: [PATCH 3/6] udf: remove un-needed variable from inode_getblk The variable last_block is not needed. Signed-off-by: Namjae Jeon Signed-off-by: Ashish Sangwan Signed-off-by: Jan Kara --- fs/udf/inode.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 8266f2ed7fc..cbae1ed0b7c 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -587,7 +587,6 @@ out: static sector_t inode_getblk(struct inode *inode, sector_t block, int *err, int *new) { - static sector_t last_block; struct kernel_long_ad laarr[EXTENT_MERGE_SIZE]; struct extent_position prev_epos, cur_epos, next_epos; int count = 0, startnum = 0, endnum = 0; @@ -677,7 +676,6 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, return newblock; } - last_block = block; /* Are we beyond EOF? */ if (etype == -1) { int ret; @@ -719,7 +717,6 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, memset(&laarr[c].extLocation, 0x00, sizeof(struct kernel_lb_addr)); count++; - endnum++; } endnum = c + 1; lastblock = 1; From 195c0f96f0f96da317e22c9851a7ecc1a541f9ad Mon Sep 17 00:00:00 2001 From: Zhao Hongjiang Date: Mon, 29 Oct 2012 15:28:07 +0800 Subject: [PATCH 4/6] ext3: get rid of the duplicate code on ext3_fill_super Setting s_mount_opt to 0 is unnecessary because we use kzalloc() for sb allocation. s_resuid and s_resgid are set again few lines below based on values in on disk superblock. Signed-off-by: Zhao Hongjiang Signed-off-by: Jan Kara --- fs/ext3/super.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/ext3/super.c b/fs/ext3/super.c index 5366393528d..6e50223b329 100644 --- a/fs/ext3/super.c +++ b/fs/ext3/super.c @@ -1661,9 +1661,6 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) return -ENOMEM; } sb->s_fs_info = sbi; - sbi->s_mount_opt = 0; - sbi->s_resuid = make_kuid(&init_user_ns, EXT3_DEF_RESUID); - sbi->s_resgid = make_kgid(&init_user_ns, EXT3_DEF_RESGID); sbi->s_sb_block = sb_block; blocksize = sb_min_blocksize(sb, EXT3_MIN_BLOCK_SIZE); From 4789775477718983b6f8c604a809b950c6a10052 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sat, 3 Nov 2012 21:30:21 +0100 Subject: [PATCH 5/6] ext3: drop if around WARN_ON Just use WARN_ON rather than an if containing only WARN_ON(1). A simplified version of the semantic patch that makes this transformation is as follows: (http://coccinelle.lip6.fr/) // @@ expression e; @@ - if (e) WARN_ON(1); + WARN_ON(e); // Signed-off-by: Julia Lawall Signed-off-by: Jan Kara --- fs/ext3/inode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index 7e87e37a372..b176d425354 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c @@ -1071,8 +1071,7 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode, * mapped. 0 in case of a HOLE. */ if (err > 0) { - if (err > 1) - WARN_ON(1); + WARN_ON(err > 1); err = 0; } *errp = err; From 56df127855b593cc4b2e94ce8df5c609b0109b42 Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Sat, 3 Nov 2012 23:02:28 +0100 Subject: [PATCH 6/6] quota: Use the pre-processor to compile out quotactl_cmd_write when !CONFIG_BLOCK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit quotactl_cmd_write() is only ever invoked when BLOCK is configured. When !CONFIG_BLOCK, the build warning below is displayed. Let's fix that. fs/quota/quota.c:311:12: warning: ‘quotactl_cmd_write’ defined but not used [-Wunused-function] Cc: Jan Kara Signed-off-by: Lee Jones Signed-off-by: Jan Kara --- fs/quota/quota.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/quota/quota.c b/fs/quota/quota.c index af1661f7a54..c7314f1771f 100644 --- a/fs/quota/quota.c +++ b/fs/quota/quota.c @@ -307,6 +307,8 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, } } +#ifdef CONFIG_BLOCK + /* Return 1 if 'cmd' will block on frozen filesystem */ static int quotactl_cmd_write(int cmd) { @@ -322,6 +324,8 @@ static int quotactl_cmd_write(int cmd) return 1; } +#endif /* CONFIG_BLOCK */ + /* * look up a superblock on which quota ops will be performed * - use the name of a block device to find the superblock thereon