linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] Btrfs: fix btrfsck error 400 when truncating a compressed file extent
@ 2012-01-05  8:32 Miao Xie
  2012-01-09  4:45 ` Mitch Harder
  0 siblings, 1 reply; 3+ messages in thread
From: Miao Xie @ 2012-01-05  8:32 UTC (permalink / raw)
  To: Linux Btrfs

Reproduce steps:
 # mkfs.btrfs /dev/sdb5
 # mount /dev/sdb5 -o compress=lzo /mnt
 # dd if=/dev/zero of=/mnt/tmpfile bs=128K count=1
 # sync
 # truncate -s 64K /mnt/tmpfile
 root 5 inode 257 errors 400

This is because of the wrong if condition, which is used to check if we should
subtract the bytes of the dropped range from i_blocks/i_bytes of i-node or not.
When we truncate a compressed extent, btrfs substracts the bytes of the whole
extent, it's wrong. We should substract the real size that we truncate, no
matter it is a compressed extent or not. Fix it.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
 fs/btrfs/inode.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 13b0542..85e2312 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3009,7 +3009,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
 	int pending_del_nr = 0;
 	int pending_del_slot = 0;
 	int extent_type = -1;
-	int encoding;
 	int ret;
 	int err = 0;
 	u64 ino = btrfs_ino(inode);
@@ -3059,7 +3058,6 @@ search_again:
 		leaf = path->nodes[0];
 		btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
 		found_type = btrfs_key_type(&found_key);
-		encoding = 0;
 
 		if (found_key.objectid != ino)
 			break;
@@ -3072,10 +3070,6 @@ search_again:
 			fi = btrfs_item_ptr(leaf, path->slots[0],
 					    struct btrfs_file_extent_item);
 			extent_type = btrfs_file_extent_type(leaf, fi);
-			encoding = btrfs_file_extent_compression(leaf, fi);
-			encoding |= btrfs_file_extent_encryption(leaf, fi);
-			encoding |= btrfs_file_extent_other_encoding(leaf, fi);
-
 			if (extent_type != BTRFS_FILE_EXTENT_INLINE) {
 				item_end +=
 				    btrfs_file_extent_num_bytes(leaf, fi);
@@ -3103,7 +3097,7 @@ search_again:
 		if (extent_type != BTRFS_FILE_EXTENT_INLINE) {
 			u64 num_dec;
 			extent_start = btrfs_file_extent_disk_bytenr(leaf, fi);
-			if (!del_item && !encoding) {
+			if (!del_item) {
 				u64 orig_num_bytes =
 					btrfs_file_extent_num_bytes(leaf, fi);
 				extent_num_bytes = new_size -
-- 
1.7.6.4

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

* Re: [PATCH 1/3] Btrfs: fix btrfsck error 400 when truncating a compressed file extent
  2012-01-05  8:32 [PATCH 1/3] Btrfs: fix btrfsck error 400 when truncating a compressed file extent Miao Xie
@ 2012-01-09  4:45 ` Mitch Harder
  2012-01-09  5:49   ` Miao Xie
  0 siblings, 1 reply; 3+ messages in thread
From: Mitch Harder @ 2012-01-09  4:45 UTC (permalink / raw)
  To: miaox; +Cc: Linux Btrfs

2012/1/5 Miao Xie <miaox@cn.fujitsu.com>:
> Reproduce steps:
> =A0# mkfs.btrfs /dev/sdb5
> =A0# mount /dev/sdb5 -o compress=3Dlzo /mnt
> =A0# dd if=3D/dev/zero of=3D/mnt/tmpfile bs=3D128K count=3D1
> =A0# sync
> =A0# truncate -s 64K /mnt/tmpfile
> =A0root 5 inode 257 errors 400

Is this patch set intended to address the general case of btrfsck
inode 400 errors, or is it intended for this specific case.

I've been picking up btrfsck inode 400 errors all over the place
recently on unclean shutdowns, and I was wondering if this patch set
might address the issue of unclean shutdowns, or if there is a more
general COW regression out there (or if I'm just extremely unlucky).
--
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

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

* Re: [PATCH 1/3] Btrfs: fix btrfsck error 400 when truncating a compressed file extent
  2012-01-09  4:45 ` Mitch Harder
@ 2012-01-09  5:49   ` Miao Xie
  0 siblings, 0 replies; 3+ messages in thread
From: Miao Xie @ 2012-01-09  5:49 UTC (permalink / raw)
  To: Mitch Harder; +Cc: Linux Btrfs

On Sun, 8 Jan 2012 22:45:14 -0600, Mitch Harder wrote:
> 2012/1/5 Miao Xie <miaox@cn.fujitsu.com>:
>> Reproduce steps:
>>  # mkfs.btrfs /dev/sdb5
>>  # mount /dev/sdb5 -o compress=lzo /mnt
>>  # dd if=/dev/zero of=/mnt/tmpfile bs=128K count=1
>>  # sync
>>  # truncate -s 64K /mnt/tmpfile
>>  root 5 inode 257 errors 400
> 
> Is this patch set intended to address the general case of btrfsck
> inode 400 errors, or is it intended for this specific case.
> 
> I've been picking up btrfsck inode 400 errors all over the place
> recently on unclean shutdowns, and I was wondering if this patch set
> might address the issue of unclean shutdowns, or if there is a more
> general COW regression out there (or if I'm just extremely unlucky).

The purpose of this patch set is to fix the bug of the left orphan items which
is caused by the truncation, not the general case of btrfsck 400 errors.

Thanks
Miao

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

end of thread, other threads:[~2012-01-09  5:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-05  8:32 [PATCH 1/3] Btrfs: fix btrfsck error 400 when truncating a compressed file extent Miao Xie
2012-01-09  4:45 ` Mitch Harder
2012-01-09  5:49   ` Miao Xie

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).