linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk.kim@samsung.com>
To: Chao Yu <chao2.yu@samsung.com>
Cc: linux-f2fs-devel@lists.sourceforge.net,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [f2fs-dev][PATCH 3/3 v3] f2fs: fix to truncate inline data in inode page when setattr
Date: Tue, 29 Apr 2014 15:16:14 +0900	[thread overview]
Message-ID: <1398752174.13268.4.camel@kjgkr> (raw)
In-Reply-To: <001801cf6370$e0553040$a0ff90c0$@samsung.com>

Hi,

2014-04-29 (화), 14:03 +0800, Chao Yu:
> Previous we do not truncate inline data in inode page when setattr, so following
> case could still read the inline data which has already truncated:
> 
> 1.write inline data
> 2.ftruncate size to 0
> 3.ftruncate size to max inline data size
> 4.read from offset 0
> 
> This patch introduces truncate_inline_data() to fix this problem.
> 
> change log from v1:
>  o fix a bug and do not truncate first page data after truncate inline data.
> change log from v2:
>  o wait to writeback for inode page if it was already submitted.
> 
> Signed-off-by: Chao Yu <chao2.yu@samsung.com>
> ---
>  fs/f2fs/f2fs.h   |    1 +
>  fs/f2fs/file.c   |    3 +++
>  fs/f2fs/inline.c |   19 +++++++++++++++++++
>  3 files changed, 23 insertions(+)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 2b67679..676a2c6 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1410,5 +1410,6 @@ bool f2fs_may_inline(struct inode *);
>  int f2fs_read_inline_data(struct inode *, struct page *);
>  int f2fs_convert_inline_data(struct inode *, pgoff_t);
>  int f2fs_write_inline_data(struct inode *, struct page *, unsigned int);
> +void truncate_inline_data(struct inode *, u64);
>  int recover_inline_data(struct inode *, struct page *);
>  #endif
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index b9f4fbf..d97e5c4 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -369,6 +369,9 @@ static void truncate_partial_data_page(struct inode *inode, u64 from)
>  	unsigned offset = from & (PAGE_CACHE_SIZE - 1);
>  	struct page *page;
>  
> +	if (f2fs_has_inline_data(inode))
> +		return truncate_inline_data(inode, from);
> +
>  	if (!offset)
>  		return;
>  
> diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
> index 3258c7c..6a13997 100644
> --- a/fs/f2fs/inline.c
> +++ b/fs/f2fs/inline.c
> @@ -176,6 +176,25 @@ int f2fs_write_inline_data(struct inode *inode,
>  	return 0;
>  }
>  
> +void truncate_inline_data(struct inode *inode, u64 from)
> +{
> +	struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
> +	struct page *ipage;
> +
> +	if (from >= MAX_INLINE_DATA)
> +		return;
> +
> +	ipage = get_node_page(sbi, inode->i_ino);
> +	if (IS_ERR(ipage))
> +		return;
> +
> +	f2fs_wait_on_page_writeback(ipage, NODE);

The get_node_page() triggers,
 grab_cache_page_write_begin()
  -> wait_for_stable_page()
     -> wait_on_page_writeback().

Any bugs in there?

> +	zero_user_segment(ipage, INLINE_DATA_OFFSET + from,
> +				INLINE_DATA_OFFSET + MAX_INLINE_DATA);
> +	set_page_dirty(ipage);
> +	f2fs_put_page(ipage, 1);
> +}
> +
>  int recover_inline_data(struct inode *inode, struct page *npage)
>  {
>  	struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);

-- 
Jaegeuk Kim
Samsung

  reply	other threads:[~2014-04-29  6:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-29  6:03 [PATCH 3/3 v3] f2fs: fix to truncate inline data in inode page when setattr Chao Yu
2014-04-29  6:16 ` Jaegeuk Kim [this message]
2014-04-29  7:53   ` Chao Yu
2014-04-29  8:02     ` Jaegeuk Kim
2014-04-29  8:12       ` Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398752174.13268.4.camel@kjgkr \
    --to=jaegeuk.kim@samsung.com \
    --cc=chao2.yu@samsung.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).