[PATCH V5 07/12] Btrfs: fix corrupted metadata in the snapshot

2012-09-07 Thread Miao Xie
When we delete a inode, we will remove all the delayed items including delayed
inode update, and then truncate all the relative metadata. If there is lots of
metadata, we will end the current transaction, and start a new transaction to
truncate the left metadata. In this way, we will leave a inode item that its
link counter is  0, and also may leave some directory index items in fs/file 
tree
after the current transaction ends. In other words, the metadata in this 
fs/file tree
is inconsistent. If we create a snapshot for this tree now, we will find a 
inode with
corrupted metadata in the new snapshot, and we won't continue to drop the left 
metadata,
because its link counter is not 0.

We fix this problem by updating the inode item before the current transaction 
ends.

Signed-off-by: Miao Xie mi...@cn.fujitsu.com
---
Changelog v4 - v5:
- change the method which is used to fix enospc problem of the inode update

Changelog v1 - v4:
- Update the comment of the truncation in the btrfs_evict_inode()
- Fix enospc problem of the inode update
---
 fs/btrfs/inode.c   |   20 ++--
 fs/btrfs/transaction.c |   29 +
 fs/btrfs/transaction.h |2 ++
 3 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d494c11..b69779d 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3772,21 +3772,17 @@ void btrfs_evict_inode(struct inode *inode)
btrfs_orphan_del(NULL, inode);
goto no_delete;
}
+
rsv-size = min_size;
global_rsv = root-fs_info-global_block_rsv;
 
btrfs_i_size_write(inode, 0);
 
/*
-* This is a bit simpler than btrfs_truncate since
-*
-* 1) We've already reserved our space for our orphan item in the
-*unlink.
-* 2) We're going to delete the inode item, so we don't need to update
-*it at all.
-*
-* So we just need to reserve some slack space in case we add bytes when
-* doing the truncate.
+* This is a bit simpler than btrfs_truncate since we've already
+* reserved our space for our orphan item in the unlink, so we just
+* need to reserve some slack space in case we add bytes and update
+* inode item when doing the truncate.
 */
while (1) {
ret = btrfs_block_rsv_refill_noflush(root, rsv, min_size);
@@ -3807,7 +3803,7 @@ void btrfs_evict_inode(struct inode *inode)
goto no_delete;
}
 
-   trans = btrfs_start_transaction(root, 0);
+   trans = btrfs_start_transaction_noflush(root, 1);
if (IS_ERR(trans)) {
btrfs_orphan_del(NULL, inode);
btrfs_free_block_rsv(root, rsv);
@@ -3820,6 +3816,10 @@ void btrfs_evict_inode(struct inode *inode)
if (ret != -EAGAIN)
break;
 
+   trans-block_rsv = root-fs_info-trans_block_rsv;
+   ret = btrfs_update_inode(trans, root, inode);
+   BUG_ON(ret);
+
nr = trans-blocks_used;
btrfs_end_transaction(trans, root);
trans = NULL;
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 8bd2511..6ea5d2d 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -290,7 +290,8 @@ static int may_wait_transaction(struct btrfs_root *root, 
int type)
 }
 
 static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
-   u64 num_items, int type)
+   u64 num_items, int type,
+   int noflush)
 {
struct btrfs_trans_handle *h;
struct btrfs_transaction *cur_trans;
@@ -324,9 +325,14 @@ static struct btrfs_trans_handle *start_transaction(struct 
btrfs_root *root,
}
 
num_bytes = btrfs_calc_trans_metadata_size(root, num_items);
-   ret = btrfs_block_rsv_add(root,
- root-fs_info-trans_block_rsv,
- num_bytes);
+   if (noflush)
+   ret = btrfs_block_rsv_add_noflush(root,
+   root-fs_info-trans_block_rsv,
+   num_bytes);
+   else
+   ret = btrfs_block_rsv_add(root,
+   root-fs_info-trans_block_rsv,
+   num_bytes);
if (ret)
return ERR_PTR(ret);
}
@@ -390,21 +396,28 @@ got_it:
 struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
   int num_items)
 {
-   return start_transaction(root, 

[PATCH] btrfs: polish names of kmem caches

2012-09-07 Thread David Sterba
Usecase:

  watch 'grep btrfs  /proc/slabinfo'

easy to watch all caches in one go.

Signed-off-by: David Sterba dste...@suse.cz
---
 fs/btrfs/delayed-inode.c |2 +-
 fs/btrfs/extent_io.c |4 ++--
 fs/btrfs/extent_map.c|2 +-
 fs/btrfs/inode.c |   10 +-
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index eb768c4..b26d2f9 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -29,7 +29,7 @@ static struct kmem_cache *delayed_node_cache;
 
 int __init btrfs_delayed_inode_init(void)
 {
-   delayed_node_cache = kmem_cache_create(delayed_node,
+   delayed_node_cache = kmem_cache_create(btrfs_delayed_node,
sizeof(struct btrfs_delayed_node),
0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 604e404..fc8f156 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -64,13 +64,13 @@ tree_fs_info(struct extent_io_tree *tree)
 
 int __init extent_io_init(void)
 {
-   extent_state_cache = kmem_cache_create(extent_state,
+   extent_state_cache = kmem_cache_create(btrfs_extent_state,
sizeof(struct extent_state), 0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
if (!extent_state_cache)
return -ENOMEM;
 
-   extent_buffer_cache = kmem_cache_create(extent_buffers,
+   extent_buffer_cache = kmem_cache_create(btrfs_extent_buffer,
sizeof(struct extent_buffer), 0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
if (!extent_buffer_cache)
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index ac606f0..8d1364d 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -11,7 +11,7 @@ static struct kmem_cache *extent_map_cache;
 
 int __init extent_map_init(void)
 {
-   extent_map_cache = kmem_cache_create(extent_map,
+   extent_map_cache = kmem_cache_create(btrfs_extent_map,
sizeof(struct extent_map), 0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
if (!extent_map_cache)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 02ad1c6..5ce2a10 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7154,31 +7154,31 @@ void btrfs_destroy_cachep(void)
 
 int btrfs_init_cachep(void)
 {
-   btrfs_inode_cachep = kmem_cache_create(btrfs_inode_cache,
+   btrfs_inode_cachep = kmem_cache_create(btrfs_inode,
sizeof(struct btrfs_inode), 0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, init_once);
if (!btrfs_inode_cachep)
goto fail;
 
-   btrfs_trans_handle_cachep = 
kmem_cache_create(btrfs_trans_handle_cache,
+   btrfs_trans_handle_cachep = kmem_cache_create(btrfs_trans_handle,
sizeof(struct btrfs_trans_handle), 0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
if (!btrfs_trans_handle_cachep)
goto fail;
 
-   btrfs_transaction_cachep = kmem_cache_create(btrfs_transaction_cache,
+   btrfs_transaction_cachep = kmem_cache_create(btrfs_transaction,
sizeof(struct btrfs_transaction), 0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
if (!btrfs_transaction_cachep)
goto fail;
 
-   btrfs_path_cachep = kmem_cache_create(btrfs_path_cache,
+   btrfs_path_cachep = kmem_cache_create(btrfs_path,
sizeof(struct btrfs_path), 0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
if (!btrfs_path_cachep)
goto fail;
 
-   btrfs_free_space_cachep = kmem_cache_create(btrfs_free_space_cache,
+   btrfs_free_space_cachep = kmem_cache_create(btrfs_free_space,
sizeof(struct btrfs_free_space), 0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
if (!btrfs_free_space_cachep)
-- 
1.7.9

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC inside][PATCH] btrfs: allow setting NOCOW for a zero sized file via ioctl

2012-09-07 Thread David Sterba
Hi,

the patch si simple, but it has user visible impact and I'm not quite sure how
to resolve it.

In short, $subj says it, chattr -C supports it and we want to use it.

The conditions that acutally allow to change the NOCOW flag are clear. What if
I try to set the flag on a file that is not empty? Options:

1) whole ioctl will fail, EINVAL
2.1) ioctl will succeed, the NOCOW flag will be silently removed, but the file
 will stay COW-ed and checksummed
2.2) ioctl will succeed, flag will not be removed and a syslog message will
 warn that the COW flag has not been changed
2.2.1) dtto, no syslog message

Man page of chattr states that

 If it is set on a file which already has data blocks, it is undefined when
 the blocks assigned to the file will be fully stable.

Yes, it's undefined and with current implementation it'll never happen. So from
this end, the user cannot expect anything. I'm trying to find a reasonable
behaviour, so that a command like 'chattr -R -aijS +C' to tweak a broad set of
flags in a deep directory does not fail unnecessarily and does not pollute the
log.

My personal preference is 2.2.1, but my dev's oppinion is skewed, not counting
the fact that I know the code and otherwise would look there before consulting
the documentation.

The patch implements 2.2.1.


david

-8---
From: David Sterba dste...@suse.cz

It's safe to turn off checksums for a zero sized file.

http://thread.gmane.org/gmane.comp.file-systems.btrfs/18030

We cannot switch on NODATASUM for a file that already has extents that
are checksummed. The invariant here is that either all the extents or
none are checksummed.

Theoretically it's possible to add/remove all checksums from a given
file, but it's a potentially longtime operation, the file has to be in
some intermediate state where the checksums partially exist but have to
be ignored (for the csum-nocsum) until the file is fully converted,
this brings more special cases to extent handling, it has to survive
power failure and remain consistent, and probably needs to be restarted
after next mount.

Signed-off-by: David Sterba dste...@suse.cz
---
 fs/btrfs/ioctl.c |   31 +++
 1 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 00ff333..a6005d5 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -182,6 +182,7 @@ static int btrfs_ioctl_setflags(struct file *file, void 
__user *arg)
int ret;
u64 ip_oldflags;
unsigned int i_oldflags;
+   umode_t mode;
 
if (btrfs_root_readonly(root))
return -EROFS;
@@ -204,6 +205,7 @@ static int btrfs_ioctl_setflags(struct file *file, void 
__user *arg)
 
ip_oldflags = ip-flags;
i_oldflags = inode-i_flags;
+   mode = inode-i_mode;
 
flags = btrfs_mask_flags(inode-i_mode, flags);
oldflags = btrfs_flags_to_ioctl(ip-flags);
@@ -238,10 +240,31 @@ static int btrfs_ioctl_setflags(struct file *file, void 
__user *arg)
ip-flags |= BTRFS_INODE_DIRSYNC;
else
ip-flags = ~BTRFS_INODE_DIRSYNC;
-   if (flags  FS_NOCOW_FL)
-   ip-flags |= BTRFS_INODE_NODATACOW;
-   else
-   ip-flags = ~BTRFS_INODE_NODATACOW;
+   if (flags  FS_NOCOW_FL) {
+   if (S_ISREG(mode)) {
+   /*
+* It's safe to turn csums off here, no extents exist.
+* Otherwise we want the flag to reflect the real COW
+* status of the file and will not set it.
+*/
+   if (inode-i_size == 0)
+   ip-flags |= BTRFS_INODE_NODATACOW
+  | BTRFS_INODE_NODATASUM;
+   } else {
+   ip-flags |= BTRFS_INODE_NODATACOW;
+   }
+   } else {
+   /*
+* Revert back under same assuptions as above
+*/
+   if (S_ISREG(mode)) {
+   if (inode-i_size == 0)
+   ip-flags = ~(BTRFS_INODE_NODATACOW
+| BTRFS_INODE_NODATASUM);
+   } else {
+   ip-flags = ~BTRFS_INODE_NODATACOW;
+   }
+   }
 
/*
 * The COMPRESS flag can only be changed by users, while the NOCOMPRESS
-- 
1.7.9

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] btrfs-progs: pretty print key in extent_item

2012-09-07 Thread David Sterba
Signed-off-by: David Sterba dste...@suse.cz
---
 print-tree.c |8 +++-
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/print-tree.c b/print-tree.c
index 89fc5b4..7c615dd 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -205,11 +205,9 @@ static void print_extent_item(struct extent_buffer *eb, 
int slot)
struct btrfs_tree_block_info *info;
info = (struct btrfs_tree_block_info *)(ei + 1);
btrfs_tree_block_key(eb, info, key);
-   printf(\t\ttree block key (%llu %x %llu) level %d\n,
-  (unsigned long long)btrfs_disk_key_objectid(key),
-  key.type,
-  (unsigned long long)btrfs_disk_key_offset(key),
-  btrfs_tree_block_level(eb, info));
+   printf(\t\ttree block );
+   btrfs_print_key(key);
+   printf( level %d\n, btrfs_tree_block_level(eb, info));
iref = (struct btrfs_extent_inline_ref *)(info + 1);
} else {
iref = (struct btrfs_extent_inline_ref *)(ei + 1);
-- 
1.7.6.233.gd79bc

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Cannot create subvolume with quota enabled

2012-09-07 Thread Andreas Philipp
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

The following steps reproduce the error. My kernel is 3.6-rc4 and
btrfs-progs are at commit 89fe5b5f666c247aa3173745fb87c710f3a71a4a from
git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git
master.

thor ~ # mkfs.btrfs -L test /dev/vg1/test

WARNING! - Btrfs Btrfs v0.19 IS EXPERIMENTAL
WARNING! - see http://btrfs.wiki.kernel.org before using

fs created label test on /dev/vg1/test
nodesize 4096 leafsize 4096 sectorsize 4096 size 20.00GB
Btrfs Btrfs v0.19
thor ~ # mount /dev/vg1/test /mnt/tmp
thor ~ # btrfs quota enable /mnt/tmp
thor ~ # btrfs subvolume create /mnt/tmp/test
Create subvolume '/mnt/tmp/test'
ERROR: cannot create subvolume - Invalid argument

Please, do not hesitate to contact me for any further information etc.

Thanks,
Andreas
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQEcBAEBAgAGBQJQSky/AAoJEIW3W1BiBxU7/AIH/0K+FRSFl619SKnSrpiib+wk
5Rf+R9mjMn9yateRbhtblBF5KuWfGELO8w7okf6Mg6L/wCD7fYFuwo8Gwm7RvG/T
lBrOCRPvrdkT78+elX/Jaj1QKWcYkTz7bkpcXf57zdzLruO1VwF0aCQZOFDR/qD2
d3oI5OCc/3Qw9G0ZnqV/z+bT3oqJRPJBV4ihB1SSI+5YpCAtHBW1jFGfwWRuA+ZV
Q+iPPjMKZALG6wQYu+4WG5M1l9pC9y/aRetBfWplQTVgfT4Hh3eZjvq6OnDv9ZiO
rWLSTqG0uBRCW2Sws0uFpPKMod0RFWm0sJNfkzGAM6O3a15CGTPnA9Hq0SgMRL4=
=pr3t
-END PGP SIGNATURE-
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Btrfs: btrfs_qgroup_inherit wrongly returns an error

2012-09-07 Thread Arne Jansen
When using the V1-version of the snap/subvol creation ioctl
btrfs_qgroup_inherit wrongly returns an error because no inherit parameter
is given. Fix the return value.

Signed-off-by: Arne Jansen sensi...@gmx.net
---
 fs/btrfs/qgroup.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 38b42e7..090405d 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1383,10 +1383,8 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle 
*trans,
qgroup_dirty(fs_info, srcgroup);
}
 
-   if (!inherit) {
-   ret = -EINVAL;
+   if (!inherit)
goto unlock;
-   }
 
i_qgroups = (u64 *)(inherit + 1);
for (i = 0; i  inherit-num_qgroups; ++i) {
-- 
1.7.3.4

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Cannot create subvolume with quota enabled

2012-09-07 Thread Arne Jansen
Hi Andreas,

On 09/07/2012 09:36 PM, Andreas Philipp wrote:
 Hi,
 
 The following steps reproduce the error. My kernel is 3.6-rc4 and 
 btrfs-progs are at commit 89fe5b5f666c247aa3173745fb87c710f3a71a4a
 from 
 git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git

 
master.
 
 thor ~ # mkfs.btrfs -L test /dev/vg1/test
 
 WARNING! - Btrfs Btrfs v0.19 IS EXPERIMENTAL WARNING! - see
 http://btrfs.wiki.kernel.org before using
 
 fs created label test on /dev/vg1/test nodesize 4096 leafsize 4096
 sectorsize 4096 size 20.00GB Btrfs Btrfs v0.19 thor ~ # mount
 /dev/vg1/test /mnt/tmp thor ~ # btrfs quota enable /mnt/tmp thor ~
 # btrfs subvolume create /mnt/tmp/test Create subvolume
 '/mnt/tmp/test' ERROR: cannot create subvolume - Invalid argument

Thanks for giving quota a try. I sent a fix separately with
the subject

[PATCH] Btrfs: btrfs_qgroup_inherit wrongly returns an error

Could you please see if it fixes the problem?

Thanks,
Arne
 
 Please, do not hesitate to contact me for any further information
 etc.
 
 Thanks, Andreas -- To unsubscribe from this list: send the line
 unsubscribe linux-btrfs in the body of a message to
 majord...@vger.kernel.org More majordomo info at
 http://vger.kernel.org/majordomo-info.html
 

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/6] Btrfs: fix a bug of per-file nocow

2012-09-07 Thread Liu Bo
Users report a bug, the reproducer is:
$ mkfs.btrfs /dev/loop0
$ mount /dev/loop0 /mnt/btrfs/
$ mkdir /mnt/btrfs/dir
$ chattr +C /mnt/btrfs/dir/
$ dd if=/dev/zero of=/mnt/btrfs/dir/foo bs=4K count=10;
$ lsattr /mnt/btrfs/dir/foo
---C- /mnt/btrfs/dir/foo
$ filefrag /mnt/btrfs/dir/foo
/mnt/btrfs/dir/foo: 1 extent found--- an extent
$ dd if=/dev/zero of=/mnt/btrfs/dir/foo bs=4K count=1 seek=5 
conv=notrunc,nocreat; sync
$ filefrag /mnt/btrfs/dir/foo
/mnt/btrfs/dir/foo: 3 extents found   --- with nocow, btrfs breaks the extent 
into three parts

The new created file should not only inherit the NODATACOW flag, but also
honor NODATASUM flag, because we must do COW on a file extent with checksum.

Signed-off-by: Liu Bo bo.li@oracle.com
---
v1-v2: add check for only regular file

 fs/btrfs/inode.c |3 +--
 fs/btrfs/ioctl.c |7 +--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index b2c3514..9bce6e9 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4720,8 +4720,7 @@ static struct inode *btrfs_new_inode(struct 
btrfs_trans_handle *trans,
if (S_ISREG(mode)) {
if (btrfs_test_opt(root, NODATASUM))
BTRFS_I(inode)-flags |= BTRFS_INODE_NODATASUM;
-   if (btrfs_test_opt(root, NODATACOW) ||
-   (BTRFS_I(dir)-flags  BTRFS_INODE_NODATACOW))
+   if (btrfs_test_opt(root, NODATACOW))
BTRFS_I(inode)-flags |= BTRFS_INODE_NODATACOW;
}
 
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 00ddf22..2fd5455 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -140,8 +140,11 @@ void btrfs_inherit_iflags(struct inode *inode, struct 
inode *dir)
BTRFS_I(inode)-flags |= BTRFS_INODE_COMPRESS;
}
 
-   if (flags  BTRFS_INODE_NODATACOW)
-   BTRFS_I(inode)-flags |= BTRFS_INODE_NODATACOW;
+   if (flags  BTRFS_INODE_NODATACOW) {
+   BTRFS_I(inode)-flags |= BTRFS_INODE_NODATACOW |
+   if (S_ISREG(inode-i_mode))
+   BTRFS_I(inode)-flags |= BTRFS_INODE_NODATASUM;
+   }
 
btrfs_update_iflags(inode);
 }
-- 
1.7.7.6

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/6] Btrfs: cleanup for unused ref cache stuff

2012-09-07 Thread Liu Bo
From: liubo liubo2...@cn.fujitsu.com

As ref cache has been removed from btrfs, there is no user on
its lock and its check.

Signed-off-by: Liu Bo liubo2...@cn.fujitsu.com
Signed-off-by: Liu Bo bo.li@oracle.com
---
 fs/btrfs/ctree.h   |3 ---
 fs/btrfs/disk-io.c |5 -
 2 files changed, 0 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0d195b5..4ae593c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1366,9 +1366,6 @@ struct btrfs_fs_info {
struct rb_root defrag_inodes;
atomic_t defrag_running;
 
-   spinlock_t ref_cache_lock;
-   u64 total_ref_cache_size;
-
/*
 * these three are in extended format (availability of single
 * chunks is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE bit, other
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 22e98e0..bcd1703 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2000,7 +2000,6 @@ int open_ctree(struct super_block *sb,
INIT_LIST_HEAD(fs_info-caching_block_groups);
spin_lock_init(fs_info-delalloc_lock);
spin_lock_init(fs_info-trans_lock);
-   spin_lock_init(fs_info-ref_cache_lock);
spin_lock_init(fs_info-fs_roots_radix_lock);
spin_lock_init(fs_info-delayed_iput_lock);
spin_lock_init(fs_info-defrag_inodes_lock);
@@ -3211,10 +3210,6 @@ int close_ctree(struct btrfs_root *root)
printk(KERN_INFO btrfs: at unmount delalloc count %llu\n,
   (unsigned long long)fs_info-delalloc_bytes);
}
-   if (fs_info-total_ref_cache_size) {
-   printk(KERN_INFO btrfs: at umount reference cache size %llu\n,
-  (unsigned long long)fs_info-total_ref_cache_size);
-   }
 
free_extent_buffer(fs_info-extent_root-node);
free_extent_buffer(fs_info-extent_root-commit_root);
-- 
1.7.7.6

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/6] Btrfs: update delayed ref's tracepoints to show sequence

2012-09-07 Thread Liu Bo
We've added a new field 'sequence' to delayed ref node, so update related
tracepoints.

Signed-off-by: Liu Bo bo.li@oracle.com
---
 include/trace/events/btrfs.h |   14 ++
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index 91b91e8..54fab04 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -445,6 +445,7 @@ TRACE_EVENT(btrfs_delayed_tree_ref,
__field(u64,  ref_root  )
__field(int,  level )
__field(int,  type  )
+   __field(u64,  seq   )
),
 
TP_fast_assign(
@@ -455,17 +456,19 @@ TRACE_EVENT(btrfs_delayed_tree_ref,
__entry-ref_root   = full_ref-root;
__entry-level  = full_ref-level;
__entry-type   = ref-type;
+   __entry-seq= ref-seq;
),
 
TP_printk(bytenr = %llu, num_bytes = %llu, action = %s, 
  parent = %llu(%s), ref_root = %llu(%s), level = %d, 
- type = %s,
+ type = %s, seq = %llu,
  (unsigned long long)__entry-bytenr,
  (unsigned long long)__entry-num_bytes,
  show_ref_action(__entry-action),
  show_root_type(__entry-parent),
  show_root_type(__entry-ref_root),
- __entry-level, show_ref_type(__entry-type))
+ __entry-level, show_ref_type(__entry-type),
+ (unsigned long long)__entry-seq)
 );
 
 TRACE_EVENT(btrfs_delayed_data_ref,
@@ -485,6 +488,7 @@ TRACE_EVENT(btrfs_delayed_data_ref,
__field(u64,  owner )
__field(u64,  offset)
__field(int,  type  )
+   __field(u64,  seq   )
),
 
TP_fast_assign(
@@ -496,11 +500,12 @@ TRACE_EVENT(btrfs_delayed_data_ref,
__entry-owner  = full_ref-objectid;
__entry-offset = full_ref-offset;
__entry-type   = ref-type;
+   __entry-seq= ref-seq;
),
 
TP_printk(bytenr = %llu, num_bytes = %llu, action = %s, 
  parent = %llu(%s), ref_root = %llu(%s), owner = %llu, 
- offset = %llu, type = %s,
+ offset = %llu, type = %s, seq = %llu,
  (unsigned long long)__entry-bytenr,
  (unsigned long long)__entry-num_bytes,
  show_ref_action(__entry-action),
@@ -508,7 +513,8 @@ TRACE_EVENT(btrfs_delayed_data_ref,
  show_root_type(__entry-ref_root),
  (unsigned long long)__entry-owner,
  (unsigned long long)__entry-offset,
- show_ref_type(__entry-type))
+ show_ref_type(__entry-type),
+ (unsigned long long)__entry-seq)
 );
 
 TRACE_EVENT(btrfs_delayed_ref_head,
-- 
1.7.7.6

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 5/6] Btrfs: use helper for logical resolve

2012-09-07 Thread Liu Bo
We already have a helper, iterate_inodes_from_logical(), for logical resolve,
so just use it.

Signed-off-by: Liu Bo bo.li@oracle.com
---
 fs/btrfs/ioctl.c |   19 +++
 1 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 365e3e4..7bf3984 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3218,12 +3218,9 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_root 
*root,
 {
int ret = 0;
int size;
-   u64 extent_item_pos;
-   u64 flags = 0;
struct btrfs_ioctl_logical_ino_args *loi;
struct btrfs_data_container *inodes = NULL;
struct btrfs_path *path = NULL;
-   struct btrfs_key key;
 
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
@@ -3249,23 +3246,13 @@ static long btrfs_ioctl_logical_to_ino(struct 
btrfs_root *root,
goto out;
}
 
-   ret = extent_from_logical(root-fs_info, loi-logical, path, key,
- flags);
-   btrfs_release_path(path);
-
-   if (flags  BTRFS_EXTENT_FLAG_TREE_BLOCK)
+   ret = iterate_inodes_from_logical(loi-logical, root-fs_info, path,
+ build_ino_list, inodes);
+   if (ret == -EINVAL)
ret = -ENOENT;
if (ret  0)
goto out;
 
-   extent_item_pos = loi-logical - key.objectid;
-   ret = iterate_extent_inodes(root-fs_info, key.objectid,
-   extent_item_pos, 0, build_ino_list,
-   inodes);
-
-   if (ret  0)
-   goto out;
-
ret = copy_to_user((void *)(unsigned long)loi-inodes,
   (void *)(unsigned long)inodes, size);
if (ret)
-- 
1.7.7.6

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 6/6] Btrfs: use larger limit for translation of logical to inode

2012-09-07 Thread Liu Bo
This is the change of the kernel side.

Translation of logical to inode used to have an upper limit 4k on
inode container's size, but the limit is not large enough for a data
with a great many of refs, so when resolving logical address,
we can end up with
ioctl ret=0, bytes_left=0, bytes_missing=19944, cnt=510, missed=2493

This changes to regard 64k as the upper limit and use vmalloc instead of
kmalloc to get memory more easily.

Signed-off-by: Liu Bo bo.li@oracle.com
---
 fs/btrfs/backref.c |2 +-
 fs/btrfs/ioctl.c   |4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 4e80ba3..fb72931 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -1583,7 +1583,7 @@ struct btrfs_data_container *init_data_container(u32 
total_bytes)
size_t alloc_bytes;
 
alloc_bytes = max_t(size_t, total_bytes, sizeof(*data));
-   data = kmalloc(alloc_bytes, GFP_NOFS);
+   data = vmalloc(alloc_bytes);
if (!data)
return ERR_PTR(-ENOMEM);
 
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 7bf3984..2503e37 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3238,7 +3238,7 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_root 
*root,
goto out;
}
 
-   size = min_t(u32, loi-size, 4096);
+   size = min_t(u32, loi-size, 64 * 1024);
inodes = init_data_container(size);
if (IS_ERR(inodes)) {
ret = PTR_ERR(inodes);
@@ -3260,7 +3260,7 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_root 
*root,
 
 out:
btrfs_free_path(path);
-   kfree(inodes);
+   vfree(inodes);
kfree(loi);
 
return ret;
-- 
1.7.7.6

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html