linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miao Xie <miaox@cn.fujitsu.com>
To: Josef Bacik <josef@redhat.com>
Cc: Linux Btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 2/3] Btrfs: make btrfs_truncate_inode_items() more readable
Date: Fri, 06 Jan 2012 09:35:59 +0800	[thread overview]
Message-ID: <4F064FFF.9060404@cn.fujitsu.com> (raw)
In-Reply-To: <20120105151142.GB1843@localhost.localdomain>

On thu, 5 Jan 2012 10:11:43 -0500, Josef Bacik wrote:
>> +	extent_start = btrfs_file_extent_disk_bytenr(leaf, fi);
>> +	if (offset < new_size) {
>> +		/*
>> +		 * If the new size is in the extent:
>> +		 *   +--------------------------+
>> +		 *   |				|
>> +		 *   +--------------------------+
>> +		 *   			^ new size
>> +		 * so this extent should be truncated, not be dropped directly.
>> +		 */
>> +		orig_nbytes = btrfs_file_extent_num_bytes(leaf, fi);
>> +		new_nbytes = round_up(new_size - offset, root->sectorsize);
>> +
>> +		btrfs_set_file_extent_num_bytes(leaf, fi, new_nbytes);
>> +
>> +		if (extent_start != 0 && root->ref_cows)
>> +			inode_sub_bytes(inode, orig_nbytes - new_nbytes);
>> +
>> +		btrfs_mark_buffer_dirty(leaf);
>> +		return 0;
> 
> Use ret = 0 here, and then further down...
> 
>> +	} else {
>> +		/*
>> +		 * If the new size is in the font of the extent:
>> +		 *   +--------------------------+
>> +		 *   |				|
>> +		 *   +--------------------------+
>> +		 *  ^ new size
>> +		 * so this extent should be dropped.
>> +		 */
>> +
>> +		/*
>> +		 * It is a dummy extent, or it is in log tree, we needn't do
>> +		 * anything, just drop it.
>> +		 */
>> +		if (extent_start == 0 ||
>> +		    !(root->ref_cows || root == root->fs_info->tree_root))
>> +			return 1;
>> +
>> +		/* If this file is not a free space management file... */
>> +		/* FIXME blocksize != 4096 */
>> +		if (root != root->fs_info->tree_root) {
>> +			orig_nbytes = btrfs_file_extent_num_bytes(leaf, fi);
>> +			inode_sub_bytes(inode, orig_nbytes);
>> +		}
>> +
>> +		orig_nbytes = btrfs_file_extent_disk_num_bytes(leaf, fi);
>> +		extent_offset = offset - btrfs_file_extent_offset(leaf, fi);
>> +		btrfs_set_path_blocking(path);
>> +		ret = btrfs_free_extent(trans, root, extent_start,
>> +					orig_nbytes, 0,
>> +					btrfs_header_owner(leaf),
>> +					ino, extent_offset);
>> +		BUG_ON(ret);
>> +		btrfs_clear_path_blocking(path, NULL, 0);
>> +
>> +		return 1;
> 
> ret = 1
>> +	}
> 
> return ret;

OK, I'll modify it. Thanks for your review.

Miao

  reply	other threads:[~2012-01-06  1:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-05  8:32 [PATCH 2/3] Btrfs: make btrfs_truncate_inode_items() more readable Miao Xie
2012-01-05 15:11 ` Josef Bacik
2012-01-06  1:35   ` Miao Xie [this message]
2012-01-06  1:14 ` Chris Mason

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=4F064FFF.9060404@cn.fujitsu.com \
    --to=miaox@cn.fujitsu.com \
    --cc=josef@redhat.com \
    --cc=linux-btrfs@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).