linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] f2fs: backup raw_super in sbi
@ 2015-12-15  9:17 Chao Yu
  0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2015-12-15  9:17 UTC (permalink / raw)
  To: Jaegeuk Kim, Yunlei He; +Cc: linux-kernel, linux-f2fs-devel

From: Yunlei He <heyunlei@huawei.com>

f2fs use fields of f2fs_super_block struct directly in a grabbed buffer.

Once the buffer happen to be destroyed (e.g. through dd), it may bring
in unpredictable effect on f2fs.

This patch fixes to allocate additional buffer to store datas of super
block rather than using grabbed block buffer directly.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Chao Yu <chao2.yu@samsung.com>
---
 fs/f2fs/super.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 694e092..a6eb79a 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -578,6 +578,7 @@ static void f2fs_put_super(struct super_block *sb)
 
 	sb->s_fs_info = NULL;
 	brelse(sbi->raw_super_buf);
+	kfree(sbi->raw_super);
 	kfree(sbi);
 }
 
@@ -1153,6 +1154,9 @@ static int read_raw_super_block(struct super_block *sb,
 	struct f2fs_super_block *super;
 	int err = 0;
 
+	super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL);
+	if (!super)
+		return -ENOMEM;
 retry:
 	buffer = sb_bread(sb, block);
 	if (!buffer) {
@@ -1168,8 +1172,7 @@ retry:
 		}
 	}
 
-	super = (struct f2fs_super_block *)
-		((char *)(buffer)->b_data + F2FS_SUPER_OFFSET);
+	memcpy(super, buffer->b_data + F2FS_SUPER_OFFSET, sizeof(*super));
 
 	/* sanity checking of raw super */
 	if (sanity_check_raw_super(sb, super)) {
@@ -1203,14 +1206,17 @@ retry:
 
 out:
 	/* No valid superblock */
-	if (!*raw_super)
+	if (!*raw_super) {
+		kfree(super);
 		return err;
+	}
 
 	return 0;
 }
 
 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
 {
+	struct f2fs_super_block *super = F2FS_RAW_SUPER(sbi);
 	struct buffer_head *sbh = sbi->raw_super_buf;
 	struct buffer_head *bh;
 	int err;
@@ -1221,7 +1227,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
 		return -EIO;
 
 	lock_buffer(bh);
-	memcpy(bh->b_data, sbh->b_data, sbh->b_size);
+	memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
 	WARN_ON(sbh->b_size != F2FS_BLKSIZE);
 	set_buffer_uptodate(bh);
 	set_buffer_dirty(bh);
@@ -1237,6 +1243,10 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
 
 	/* write current valid superblock */
 	lock_buffer(sbh);
+	if (memcmp(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super))) {
+		f2fs_msg(sbi->sb, KERN_INFO, "Write modified valid superblock");
+		memcpy(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
+	}
 	set_buffer_dirty(sbh);
 	unlock_buffer(sbh);
 
@@ -1513,6 +1523,7 @@ free_options:
 	kfree(options);
 free_sb_buf:
 	brelse(raw_super_buf);
+	kfree(raw_super);
 free_sbi:
 	kfree(sbi);
 
-- 
2.6.3



------------------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/3] f2fs: backup raw_super in sbi
@ 2015-12-15  9:40 Chao Yu
  2015-12-15 22:06 ` Jaegeuk Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2015-12-15  9:40 UTC (permalink / raw)
  To: Jaegeuk Kim, Yunlei He; +Cc: linux-kernel, linux-f2fs-devel

Hi Jaegeuk, Yunlei,

I help do some edits and send it out as my patch's base. :)

But if you want to send patch by yourself, please ignore this patch.

Thanks,

> -----Original Message-----
> From: Chao Yu [mailto:chao2.yu@samsung.com]
> Sent: Tuesday, December 15, 2015 5:17 PM
> To: Jaegeuk Kim (jaegeuk@kernel.org); Yunlei He (heyunlei@huawei.com)
> Cc: linux-f2fs-devel@lists.sourceforge.net; linux-kernel@vger.kernel.org
> Subject: [PATCH 1/3] f2fs: backup raw_super in sbi
> 
> From: Yunlei He <heyunlei@huawei.com>
> 
> f2fs use fields of f2fs_super_block struct directly in a grabbed buffer.
> 
> Once the buffer happen to be destroyed (e.g. through dd), it may bring
> in unpredictable effect on f2fs.
> 
> This patch fixes to allocate additional buffer to store datas of super
> block rather than using grabbed block buffer directly.
> 
> Signed-off-by: Yunlei He <heyunlei@huawei.com>
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> Signed-off-by: Chao Yu <chao2.yu@samsung.com>
> ---
>  fs/f2fs/super.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 694e092..a6eb79a 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -578,6 +578,7 @@ static void f2fs_put_super(struct super_block *sb)
> 
>  	sb->s_fs_info = NULL;
>  	brelse(sbi->raw_super_buf);
> +	kfree(sbi->raw_super);
>  	kfree(sbi);
>  }
> 
> @@ -1153,6 +1154,9 @@ static int read_raw_super_block(struct super_block *sb,
>  	struct f2fs_super_block *super;
>  	int err = 0;
> 
> +	super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL);
> +	if (!super)
> +		return -ENOMEM;
>  retry:
>  	buffer = sb_bread(sb, block);
>  	if (!buffer) {
> @@ -1168,8 +1172,7 @@ retry:
>  		}
>  	}
> 
> -	super = (struct f2fs_super_block *)
> -		((char *)(buffer)->b_data + F2FS_SUPER_OFFSET);
> +	memcpy(super, buffer->b_data + F2FS_SUPER_OFFSET, sizeof(*super));
> 
>  	/* sanity checking of raw super */
>  	if (sanity_check_raw_super(sb, super)) {
> @@ -1203,14 +1206,17 @@ retry:
> 
>  out:
>  	/* No valid superblock */
> -	if (!*raw_super)
> +	if (!*raw_super) {
> +		kfree(super);
>  		return err;
> +	}
> 
>  	return 0;
>  }
> 
>  int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
>  {
> +	struct f2fs_super_block *super = F2FS_RAW_SUPER(sbi);
>  	struct buffer_head *sbh = sbi->raw_super_buf;
>  	struct buffer_head *bh;
>  	int err;
> @@ -1221,7 +1227,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
>  		return -EIO;
> 
>  	lock_buffer(bh);
> -	memcpy(bh->b_data, sbh->b_data, sbh->b_size);
> +	memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
>  	WARN_ON(sbh->b_size != F2FS_BLKSIZE);
>  	set_buffer_uptodate(bh);
>  	set_buffer_dirty(bh);
> @@ -1237,6 +1243,10 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
> 
>  	/* write current valid superblock */
>  	lock_buffer(sbh);
> +	if (memcmp(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super))) {
> +		f2fs_msg(sbi->sb, KERN_INFO, "Write modified valid superblock");
> +		memcpy(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
> +	}
>  	set_buffer_dirty(sbh);
>  	unlock_buffer(sbh);
> 
> @@ -1513,6 +1523,7 @@ free_options:
>  	kfree(options);
>  free_sb_buf:
>  	brelse(raw_super_buf);
> +	kfree(raw_super);
>  free_sbi:
>  	kfree(sbi);
> 
> --
> 2.6.3



------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/3] f2fs: backup raw_super in sbi
  2015-12-15  9:40 [PATCH 1/3] f2fs: backup raw_super in sbi Chao Yu
@ 2015-12-15 22:06 ` Jaegeuk Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Jaegeuk Kim @ 2015-12-15 22:06 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel

On Tue, Dec 15, 2015 at 05:40:51PM +0800, Chao Yu wrote:
> Hi Jaegeuk, Yunlei,
> 
> I help do some edits and send it out as my patch's base. :)
> 
> But if you want to send patch by yourself, please ignore this patch.

No problem to merge this patch.
Thanks Chao.

> 
> Thanks,
> 
> > -----Original Message-----
> > From: Chao Yu [mailto:chao2.yu@samsung.com]
> > Sent: Tuesday, December 15, 2015 5:17 PM
> > To: Jaegeuk Kim (jaegeuk@kernel.org); Yunlei He (heyunlei@huawei.com)
> > Cc: linux-f2fs-devel@lists.sourceforge.net; linux-kernel@vger.kernel.org
> > Subject: [PATCH 1/3] f2fs: backup raw_super in sbi
> > 
> > From: Yunlei He <heyunlei@huawei.com>
> > 
> > f2fs use fields of f2fs_super_block struct directly in a grabbed buffer.
> > 
> > Once the buffer happen to be destroyed (e.g. through dd), it may bring
> > in unpredictable effect on f2fs.
> > 
> > This patch fixes to allocate additional buffer to store datas of super
> > block rather than using grabbed block buffer directly.
> > 
> > Signed-off-by: Yunlei He <heyunlei@huawei.com>
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > Signed-off-by: Chao Yu <chao2.yu@samsung.com>
> > ---
> >  fs/f2fs/super.c | 19 +++++++++++++++----
> >  1 file changed, 15 insertions(+), 4 deletions(-)
> > 
> > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> > index 694e092..a6eb79a 100644
> > --- a/fs/f2fs/super.c
> > +++ b/fs/f2fs/super.c
> > @@ -578,6 +578,7 @@ static void f2fs_put_super(struct super_block *sb)
> > 
> >  	sb->s_fs_info = NULL;
> >  	brelse(sbi->raw_super_buf);
> > +	kfree(sbi->raw_super);
> >  	kfree(sbi);
> >  }
> > 
> > @@ -1153,6 +1154,9 @@ static int read_raw_super_block(struct super_block *sb,
> >  	struct f2fs_super_block *super;
> >  	int err = 0;
> > 
> > +	super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL);
> > +	if (!super)
> > +		return -ENOMEM;
> >  retry:
> >  	buffer = sb_bread(sb, block);
> >  	if (!buffer) {
> > @@ -1168,8 +1172,7 @@ retry:
> >  		}
> >  	}
> > 
> > -	super = (struct f2fs_super_block *)
> > -		((char *)(buffer)->b_data + F2FS_SUPER_OFFSET);
> > +	memcpy(super, buffer->b_data + F2FS_SUPER_OFFSET, sizeof(*super));
> > 
> >  	/* sanity checking of raw super */
> >  	if (sanity_check_raw_super(sb, super)) {
> > @@ -1203,14 +1206,17 @@ retry:
> > 
> >  out:
> >  	/* No valid superblock */
> > -	if (!*raw_super)
> > +	if (!*raw_super) {
> > +		kfree(super);
> >  		return err;
> > +	}
> > 
> >  	return 0;
> >  }
> > 
> >  int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
> >  {
> > +	struct f2fs_super_block *super = F2FS_RAW_SUPER(sbi);
> >  	struct buffer_head *sbh = sbi->raw_super_buf;
> >  	struct buffer_head *bh;
> >  	int err;
> > @@ -1221,7 +1227,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
> >  		return -EIO;
> > 
> >  	lock_buffer(bh);
> > -	memcpy(bh->b_data, sbh->b_data, sbh->b_size);
> > +	memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
> >  	WARN_ON(sbh->b_size != F2FS_BLKSIZE);
> >  	set_buffer_uptodate(bh);
> >  	set_buffer_dirty(bh);
> > @@ -1237,6 +1243,10 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
> > 
> >  	/* write current valid superblock */
> >  	lock_buffer(sbh);
> > +	if (memcmp(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super))) {
> > +		f2fs_msg(sbi->sb, KERN_INFO, "Write modified valid superblock");
> > +		memcpy(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
> > +	}
> >  	set_buffer_dirty(sbh);
> >  	unlock_buffer(sbh);
> > 
> > @@ -1513,6 +1523,7 @@ free_options:
> >  	kfree(options);
> >  free_sb_buf:
> >  	brelse(raw_super_buf);
> > +	kfree(raw_super);
> >  free_sbi:
> >  	kfree(sbi);
> > 
> > --
> > 2.6.3
> 

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-15 22:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-15  9:40 [PATCH 1/3] f2fs: backup raw_super in sbi Chao Yu
2015-12-15 22:06 ` Jaegeuk Kim
  -- strict thread matches above, loose matches on Subject: below --
2015-12-15  9:17 Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).