linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liu Bo <bo.li.liu@oracle.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: update timestamps on truncate()
Date: Sun, 13 Jan 2013 20:32:10 +0800	[thread overview]
Message-ID: <20130113123208.GB2784@liubo> (raw)
In-Reply-To: <50F0D112.3020407@redhat.com>

On Fri, Jan 11, 2013 at 08:57:22PM -0600, Eric Sandeen wrote:
> truncate() vs. ftruncate() differ in the VFS; truncate()
> doesn't set (ATTR_CTIME | ATTR_MTIME), and it's up to the
> fs to do the timestamp updates if the size changes.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> Hm, am I breaking the rules by updating the vfs inode fields
> before the transaction starts?

IMO it is ok since we'll modify these info in btree during a
transaction.

thanks,
liubo

> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 16d9e8e..af1ab2d 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -88,7 +88,7 @@ static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
>  	[S_IFLNK >> S_SHIFT]	= BTRFS_FT_SYMLINK,
>  };
>  
> -static int btrfs_setsize(struct inode *inode, loff_t newsize);
> +static int btrfs_setsize(struct inode *inode, struct iattr *attr);
>  static int btrfs_truncate(struct inode *inode);
>  static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
>  static noinline int cow_file_range(struct inode *inode,
> @@ -3748,16 +3748,27 @@ next:
>  	return err;
>  }
>  
> -static int btrfs_setsize(struct inode *inode, loff_t newsize)
> +static int btrfs_setsize(struct inode *inode, struct iattr *attr)
>  {
>  	struct btrfs_root *root = BTRFS_I(inode)->root;
>  	struct btrfs_trans_handle *trans;
>  	loff_t oldsize = i_size_read(inode);
> +	loff_t newsize = attr->ia_size;
> +	int mask = attr->ia_valid;
>  	int ret;
>  
>  	if (newsize == oldsize)
>  		return 0;
>  
> +	/*
> +	 * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
> +	 * special case where we need to update the times despite not having
> +	 * these flags set.  For all other operations the VFS set these flags
> +	 * explicitly if it wants a timestamp update.
> +	 */
> +	if (newsize != oldsize && (!(mask & (ATTR_CTIME | ATTR_MTIME))))
> +		inode->i_ctime = inode->i_mtime = current_fs_time(inode->i_sb);
> +
>  	if (newsize > oldsize) {
>  		truncate_pagecache(inode, oldsize, newsize);
>  		ret = btrfs_cont_expand(inode, oldsize, newsize);
> @@ -3805,7 +3816,7 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
>  		return err;
>  
>  	if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) {
> -		err = btrfs_setsize(inode, attr->ia_size);
> +		err = btrfs_setsize(inode, attr);
>  		if (err)
>  			return err;
>  	}
> 
> --
> 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:[~2013-01-13 12:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-12  2:57 [PATCH] btrfs: update timestamps on truncate() Eric Sandeen
2013-01-13 12:32 ` Liu Bo [this message]

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=20130113123208.GB2784@liubo \
    --to=bo.li.liu@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=sandeen@redhat.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 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).