All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dave@jikos.cz>
To: Li Zefan <lizf@cn.fujitsu.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 2/4] Btrfs: use i_size_read() in btrfs_defrag_file()
Date: Thu, 22 Sep 2011 12:58:17 +0200	[thread overview]
Message-ID: <20110922105817.GW22205@twin.jikos.cz> (raw)
In-Reply-To: <4E608C37.90908@cn.fujitsu.com>

On Fri, Sep 02, 2011 at 03:56:39PM +0800, Li Zefan wrote:
> Don't use inode->i_size directly, since we're not holding i_mutex.
> 
> This also fixes another bug, that i_size can change after it's checked
> against 0 and then (i_size - 1) can be negative.
> 
> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Reviewed-by: David Sterba <dsterba@suse.cz>

> ---
>  fs/btrfs/ioctl.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 31fe6d4..6f2b257 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -972,6 +972,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
>  	struct btrfs_super_block *disk_super;
>  	struct file_ra_state *ra = NULL;
>  	unsigned long last_index;
> +	u64 isize = i_size_read(inode);
>  	u64 features;
>  	u64 last_len = 0;
>  	u64 skip = 0;
> @@ -997,7 +998,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
>  			compress_type = range->compress_type;
>  	}
>  
> -	if (inode->i_size == 0)
> +	if (isize == 0)
>  		return 0;
>  
>  	/*
> @@ -1022,10 +1023,10 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
>  
>  	/* find the last page to defrag */
>  	if (range->start + range->len > range->start) {
> -		last_index = min_t(u64, inode->i_size - 1,
> +		last_index = min_t(u64, isize - 1,
>  			 range->start + range->len - 1) >> PAGE_CACHE_SHIFT;
>  	} else {
> -		last_index = (inode->i_size - 1) >> PAGE_CACHE_SHIFT;
> +		last_index = (isize - 1) >> PAGE_CACHE_SHIFT;
>  	}
>  
>  	if (newer_than) {
> -- 
> 1.7.3.1
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2011-09-22 10:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-02  7:56 [PATCH 1/4] Btrfs: fix defragmentation regression Li Zefan
2011-09-02  7:56 ` [PATCH 2/4] Btrfs: use i_size_read() in btrfs_defrag_file() Li Zefan
2011-09-22 10:58   ` David Sterba [this message]
2011-09-02  7:56 ` [PATCH 3/4] Btrfs: fix wrong max_to_defrag " Li Zefan
2011-09-22 10:42   ` David Sterba
2011-09-02  7:57 ` [PATCH 4/4] Btrfs: honor extent thresh during defragmentation Li Zefan
2011-09-02  8:42 ` [PATCH 1/4] Btrfs: fix defragmentation regression Christoph Hellwig
2011-10-18  8:48   ` Dan Merillat
2011-10-18  8:52     ` Li Zefan

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=20110922105817.GW22205@twin.jikos.cz \
    --to=dave@jikos.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.