Re: [PATCH] Btrfs: fix subvolume fake mount problem when default subvolume is set

2011-04-06 Thread Goffredo Baroncelli
Hi
On 04/06/2011 11:34 AM, Zhong, Xin wrote:
> We create two subvolumes (meego_root and meego_home) in
> btrfs root directory. And set meego_root as default mount
> subvolume. After we remount btrfs, meego_root is mounted
> to top directory by default. Then if we create a directory with
> the same name as meego_home, we can mount meego_home subvolume
> sucessfully (subvol=meego_home). But this is incorrect. What we
> do in this mount point will not change anything in meego_home
> subvolume. The problem is when default mount subvolume is set to
> meego_root, we search meego_home in meego_root. But if we find a
> directory with the same name, we will treat it as subvolume. So
> the solution is to check if what we find is really a subvolume.

I think that this a bug, so a warning should be raised. We had a lot of
problem because "btrfsctl -s " did the same thing: if we referred to a
directory, they snapshot the directory's subvolume and the user didn't
understood what happened.

Personally I prefer that in case a wrong option the kernel raises a
warning and stops, not that it makes a choice about which default is
more reasonable.

Reagrds
G.Baroncelli


> 
> Signed-off-by: Zhong, Xin 
> ---
>  fs/btrfs/super.c |4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index b85fe78..66a76b7 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -823,7 +823,9 @@ static int btrfs_get_sb(struct file_system_type *fs_type, 
> int flags,
>   error = PTR_ERR(new_root);
>   goto error_free_subvol_name;
>   }
> - if (!new_root->d_inode) {
> + if (!new_root->d_inode ||
> + /* new_root is a directory, not subvolume */
> + new_root->d_inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) {
>   dput(root);
>   dput(new_root);
>   deactivate_locked_super(s);

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


2.6.39-rc2 filesystem balance lock ordering...

2011-04-06 Thread Daniel J Blueman
While trying to reproduce an earlier problem on 2.6.39-rc2, we see a
possible deadlock from locks being taken in an inconsistent order:

===
[ INFO: possible circular locking dependency detected ]
2.6.39-rc2-350cd #2
---
btrfs/27867 is trying to acquire lock:
 (&sb->s_type->i_mutex_key#13){+.+.+.}, at: []
prealloc_file_extent_cluster+0x59/0x180

but task is already holding lock:
 (&fs_info->cleaner_mutex){+.+...}, at: []
btrfs_relocate_block_group+0x197/0x2d0

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (&fs_info->cleaner_mutex){+.+...}:
   [] validate_chain+0x5a7/0x6c0
   [] __lock_acquire+0x495/0x920
   [] lock_acquire+0x5a/0x70
   [] mutex_lock_nested+0x5e/0x390
   [] btrfs_commit_super+0x21/0xe0
   [] close_ctree+0x258/0x2d0
   [] btrfs_put_super+0x18/0x30
   [] generic_shutdown_super+0x6d/0xf0
   [] kill_anon_super+0x11/0x60
   [] deactivate_locked_super+0x45/0x60
   [] deactivate_super+0x45/0x60
   [] mntput_no_expire+0x99/0xf0
   [] sys_umount+0x67/0xd0
   [] system_call_fastpath+0x16/0x1b

-> #1 (&type->s_umount_key#32){+.}:
   [] validate_chain+0x5a7/0x6c0
   [] __lock_acquire+0x495/0x920
   [] lock_acquire+0x5a/0x70
   [] down_read+0x42/0x60
   [] writeback_inodes_sb_nr_if_idle+0x35/0x60
   [] shrink_delalloc+0xee/0x180
   [] reserve_metadata_bytes+0xc3/0x200
   [] btrfs_delalloc_reserve_metadata+0xc4/0x150
   [] btrfs_delalloc_reserve_space+0x3b/0x60
   [] __btrfs_buffered_write+0x153/0x320
   [] btrfs_file_aio_write+0x230/0x310
   [] aio_rw_vect_retry+0x74/0x1d0
   [] aio_run_iocb+0x61/0x180
   [] io_submit_one+0x15f/0x210
   [] do_io_submit+0x118/0x1d0
   [] sys_io_submit+0xb/0x10
   [] system_call_fastpath+0x16/0x1b

-> #0 (&sb->s_type->i_mutex_key#13){+.+.+.}:
   [] check_prev_add+0x705/0x720
   [] validate_chain+0x5a7/0x6c0
   [] __lock_acquire+0x495/0x920
   [] lock_acquire+0x5a/0x70
   [] mutex_lock_nested+0x5e/0x390
   [] prealloc_file_extent_cluster+0x59/0x180
   [] relocate_file_extent_cluster+0x91/0x380
   [] relocate_data_extent+0x3f/0xd0
   [] relocate_block_group+0x323/0x600
   [] btrfs_relocate_block_group+0x1a8/0x2d0
   [] btrfs_relocate_chunk+0x6d/0x3b0
   [] btrfs_shrink_device+0x21a/0x3d0
   [] btrfs_balance+0x10b/0x280
   [] btrfs_ioctl+0x450/0x590
   [] do_vfs_ioctl+0x8d/0x330
   [] sys_ioctl+0x4a/0x80
   [] system_call_fastpath+0x16/0x1b

other info that might help us debug this:

2 locks held by btrfs/27867:
 #0:  (&fs_info->volume_mutex){+.+...}, at: []
btrfs_balance+0x8b/0x280
 #1:  (&fs_info->cleaner_mutex){+.+...}, at: []
btrfs_relocate_block_group+0x197/0x2d0

stack backtrace:
Pid: 27867, comm: btrfs Tainted: GW   2.6.39-rc2-350cd #2
Call Trace:
 [] print_circular_bug+0xeb/0xf0
 [] check_prev_add+0x705/0x720
 [] validate_chain+0x5a7/0x6c0
 [] __lock_acquire+0x495/0x920
 [] ? unmap_extent_buffer+0xe/0x40
 [] ? generic_bin_search+0x19c/0x210
 [] ? prealloc_file_extent_cluster+0x59/0x180
 [] lock_acquire+0x5a/0x70
 [] ? prealloc_file_extent_cluster+0x59/0x180
 [] ? add_preempt_count+0x7d/0xd0
 [] mutex_lock_nested+0x5e/0x390
 [] ? prealloc_file_extent_cluster+0x59/0x180
 [] ? mark_held_locks+0x6c/0xa0
 [] ? __slab_alloc+0x18d/0x480
 [] ? trace_hardirqs_on_caller+0x14d/0x190
 [] prealloc_file_extent_cluster+0x59/0x180
 [] ? relocate_file_extent_cluster+0x76/0x380
 [] relocate_file_extent_cluster+0x91/0x380
 [] ? __btrfs_end_transaction+0x15f/0x240
 [] relocate_data_extent+0x3f/0xd0
 [] relocate_block_group+0x323/0x600
 [] btrfs_relocate_block_group+0x1a8/0x2d0
 [] btrfs_relocate_chunk+0x6d/0x3b0
 [] ? sub_preempt_count+0x9d/0xd0
 [] ? unmap_extent_buffer+0xe/0x40
 [] ? btrfs_dev_extent_chunk_offset+0xe5/0xf0
 [] btrfs_shrink_device+0x21a/0x3d0
 [] btrfs_balance+0x10b/0x280
 [] ? up_read+0x1e/0x40
 [] ? do_page_fault+0x1cc/0x440
 [] btrfs_ioctl+0x450/0x590
 [] do_vfs_ioctl+0x8d/0x330
 [] ? fget_light+0x2bf/0x3c0
 [] ? trace_hardirqs_on_caller+0x14d/0x190
 [] sys_ioctl+0x4a/0x80
 [] system_call_fastpath+0x16/0x1b
-- 
Daniel J Blueman
--
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: BUG: unable to handle kernel NULL pointer dereference at (null)

2011-04-06 Thread Johannes Hirte
On Wednesday 06 April 2011 22:47:28 Jordan Patterson wrote:
> Hi Josef:
> 
> I tried your latest patch, since I had the same issue from the first
> email.  With the patch applied, I am now hitting the
> BUG_ON(block_group->total_bitmaps >= max_bitmaps); in add_new_bitmap
> in
> fs/btrfs/free-space-cache.c:1246 as soon as I mount the filesystem,
> with or without -o clear_cache.
> 
> It works fine in 2.6.38.  I get the same error after mounting with
> clear_cache under 2.6.38 and rebooting into the current kernel with
> your patch.
> 
> Jordan

What filesystem is it and how did you mount it with -o clear_cache? If it is 
your rootfs did you applied clear_cache to /etc/fstab or your bootloader? If 
it was the latter it won't work. For the rootfs you need to add it to the boot 
options. For me this worked every time.
Josef, is there any way to detect a wrong cache, saved by an pre-2.6.39 kernel 
and discard it?


regards,
  Johannes
--
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: BUG: unable to handle kernel NULL pointer dereference at (null)

2011-04-06 Thread Jordan Patterson
Hi Josef:

I tried your latest patch, since I had the same issue from the first
email.  With the patch applied, I am now hitting the
BUG_ON(block_group->total_bitmaps >= max_bitmaps); in add_new_bitmap
in
fs/btrfs/free-space-cache.c:1246 as soon as I mount the filesystem,
with or without -o clear_cache.

It works fine in 2.6.38.  I get the same error after mounting with
clear_cache under 2.6.38 and rebooting into the current kernel with
your patch.

Jordan

On Wed, Apr 6, 2011 at 11:15 AM, Josef Bacik  wrote:
> On Wed, Apr 06, 2011 at 01:10:38PM +0200, Johannes Hirte wrote:
>> On Tuesday 05 April 2011 23:57:53 Josef Bacik wrote:
>> > > Now it hit
>> >
>> > Man I cannot catch a break.  I hope this is the last one.  Thanks,
>> >
>
> Ok I give up, I just cleaned it all up and don't mark the pages as dirty 
> unless
> we're actually going to succeed at writing them.  This should fix everything
>
> ---
>  fs/btrfs/ctree.h            |    5 ++
>  fs/btrfs/file.c             |   21 +++
>  fs/btrfs/free-space-cache.c |  117 
> ---
>  3 files changed, 69 insertions(+), 74 deletions(-)
>
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 3458b57..0d00a07 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -2576,6 +2576,11 @@ int btrfs_drop_extents(struct btrfs_trans_handle 
> *trans, struct inode *inode,
>  int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
>                              struct inode *inode, u64 start, u64 end);
>  int btrfs_release_file(struct inode *inode, struct file *file);
> +void btrfs_drop_pages(struct page **pages, size_t num_pages);
> +int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,
> +                     struct page **pages, size_t num_pages,
> +                     loff_t pos, size_t write_bytes,
> +                     struct extent_state **cached);
>
>  /* tree-defrag.c */
>  int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index e621ea5..75899a0 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -104,7 +104,7 @@ static noinline int btrfs_copy_from_user(loff_t pos, int 
> num_pages,
>  /*
>  * unlocks pages after btrfs_file_write is done with them
>  */
> -static noinline void btrfs_drop_pages(struct page **pages, size_t num_pages)
> +void btrfs_drop_pages(struct page **pages, size_t num_pages)
>  {
>        size_t i;
>        for (i = 0; i < num_pages; i++) {
> @@ -127,16 +127,13 @@ static noinline void btrfs_drop_pages(struct page 
> **pages, size_t num_pages)
>  * this also makes the decision about creating an inline extent vs
>  * doing real data extents, marking pages dirty and delalloc as required.
>  */
> -static noinline int dirty_and_release_pages(struct btrfs_root *root,
> -                                           struct file *file,
> -                                           struct page **pages,
> -                                           size_t num_pages,
> -                                           loff_t pos,
> -                                           size_t write_bytes)
> +int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,
> +                     struct page **pages, size_t num_pages,
> +                     loff_t pos, size_t write_bytes,
> +                     struct extent_state **cached)
>  {
>        int err = 0;
>        int i;
> -       struct inode *inode = fdentry(file)->d_inode;
>        u64 num_bytes;
>        u64 start_pos;
>        u64 end_of_last_block;
> @@ -149,7 +146,7 @@ static noinline int dirty_and_release_pages(struct 
> btrfs_root *root,
>
>        end_of_last_block = start_pos + num_bytes - 1;
>        err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block,
> -                                       NULL);
> +                                       cached);
>        if (err)
>                return err;
>
> @@ -992,9 +989,9 @@ static noinline ssize_t __btrfs_buffered_write(struct 
> file *file,
>                }
>
>                if (copied > 0) {
> -                       ret = dirty_and_release_pages(root, file, pages,
> -                                                     dirty_pages, pos,
> -                                                     copied);
> +                       ret = btrfs_dirty_pages(root, inode, pages,
> +                                               dirty_pages, pos, copied,
> +                                               NULL);
>                        if (ret) {
>                                btrfs_delalloc_release_space(inode,
>                                        dirty_pages << PAGE_CACHE_SHIFT);
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index f561c95..a3f420d 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -508,6 +508,7 @@ int btrfs_write_out_cache(struct btrfs_root *root,
>        struct inode *inode;
>        struct rb_node *node;
>        

[patch] trivial: fix 'btrfS' spelling on error

2011-04-06 Thread Sergei Trofimovich
noticed on horribly broken btrfs image.
Patch is against 2.6.39-rc2.

-- 

  Sergei
From 95b9e84c22bcc31d1f42d62c5956083f6c39eb2b Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich 
Date: Wed, 6 Apr 2011 16:49:17 +0300
Subject: [PATCH 3/4] btrfs: typo: 'btrfS' -> 'btrfs'

Signed-off-by: Sergei Trofimovich 
---
 fs/btrfs/dir-item.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c
index c62f02f..dec9348 100644
--- a/fs/btrfs/dir-item.c
+++ b/fs/btrfs/dir-item.c
@@ -452,7 +452,7 @@ int verify_dir_item(struct btrfs_root *root,
 		namelen = XATTR_NAME_MAX;
 
 	if (btrfs_dir_name_len(leaf, dir_item) > namelen) {
-		printk(KERN_CRIT "btrfS: invalid dir item name len: %u\n",
+		printk(KERN_CRIT "btrfs: invalid dir item name len: %u\n",
 		   (unsigned)btrfs_dir_data_len(leaf, dir_item));
 		return 1;
 	}
-- 
1.7.3.4



signature.asc
Description: PGP signature


[PATCH] Btrfs: reuse the extent_map we found when calling btrfs_get_extent

2011-04-06 Thread Josef Bacik
In btrfs_get_block_direct we call btrfs_get_extent to lookup the extent for the
range that we are looking for.  If we don't find an extent, btrfs_get_extent
will insert a extent_map for that area and mark it as a hole.  So it does the
job of allocating a new extent map and inserting it into the io tree.  But if
we're creating a new extent we free it up and redo all of that work.  So instead
pass the em to btrfs_new_extent_direct(), and if it will work just allocate the
disk space and set it up properly and bypass the freeing/allocating of a new
extent map and the expensive operation of inserting the thing into the io_tree.
Thanks,

Signed-off-by: Josef Bacik 
---
 fs/btrfs/inode.c |   36 
 1 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 93ed346..032e8fb 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5443,17 +5443,30 @@ out:
 }
 
 static struct extent_map *btrfs_new_extent_direct(struct inode *inode,
+ struct extent_map *em,
  u64 start, u64 len)
 {
struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_trans_handle *trans;
-   struct extent_map *em;
struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
struct btrfs_key ins;
u64 alloc_hint;
int ret;
+   bool insert = false;
 
-   btrfs_drop_extent_cache(inode, start, start + len - 1, 0);
+   /*
+* Ok if the extent map we looked up is a hole and is for the exact
+* range we want, there is no reason to allocate a new one, however if
+* it is not right then we need to free this one and drop the cache for
+* our range.
+*/
+   if (em->block_start != EXTENT_MAP_HOLE || em->start != start ||
+   em->len != len) {
+   free_extent_map(em);
+   em = NULL;
+   insert = true;
+   btrfs_drop_extent_cache(inode, start, start + len - 1, 0);
+   }
 
trans = btrfs_join_transaction(root, 0);
if (IS_ERR(trans))
@@ -5469,10 +5482,12 @@ static struct extent_map 
*btrfs_new_extent_direct(struct inode *inode,
goto out;
}
 
-   em = alloc_extent_map(GFP_NOFS);
if (!em) {
-   em = ERR_PTR(-ENOMEM);
-   goto out;
+   em = alloc_extent_map(GFP_NOFS);
+   if (!em) {
+   em = ERR_PTR(-ENOMEM);
+   goto out;
+   }
}
 
em->start = start;
@@ -5482,9 +5497,15 @@ static struct extent_map *btrfs_new_extent_direct(struct 
inode *inode,
em->block_start = ins.objectid;
em->block_len = ins.offset;
em->bdev = root->fs_info->fs_devices->latest_bdev;
+
+   /*
+* We need to do this because if we're using the original em we searched
+* for, we could have EXTENT_FLAG_VACANCY set, and we don't want that.
+*/
+   em->flags = 0;
set_bit(EXTENT_FLAG_PINNED, &em->flags);
 
-   while (1) {
+   while (insert) {
write_lock(&em_tree->lock);
ret = add_extent_mapping(em_tree, em);
write_unlock(&em_tree->lock);
@@ -5702,8 +5723,7 @@ must_cow:
 * it above
 */
len = bh_result->b_size;
-   free_extent_map(em);
-   em = btrfs_new_extent_direct(inode, start, len);
+   em = btrfs_new_extent_direct(inode, em, start, len);
if (IS_ERR(em))
return PTR_ERR(em);
len = min(len, em->len - (start - em->start));
-- 
1.7.2.3

--
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: do not use async submit for small DIO io's

2011-04-06 Thread Josef Bacik
When looking at our DIO performance Chris said that for small IO's doing the
async submit stuff tends to be more overhead than it's worth.  With this on top
of my other fixes I get about a 17-20% speedup doing a sequential dd with 4k
IO's.  Basically if we don't have to split the bio for the map length it's small
enough to be directly submitted, otherwise go back to the async submit.  Thanks,

Signed-off-by: Josef Bacik 
---
 fs/btrfs/inode.c |   24 +++-
 1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 5144d5c..93ed346 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5955,7 +5955,7 @@ static struct bio *btrfs_dio_bio_alloc(struct 
block_device *bdev,
 
 static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode,
 int rw, u64 file_offset, int skip_sum,
-u32 *csums)
+u32 *csums, int async_submit)
 {
int write = rw & REQ_WRITE;
struct btrfs_root *root = BTRFS_I(inode)->root;
@@ -5966,13 +5966,24 @@ static inline int __btrfs_submit_dio_bio(struct bio 
*bio, struct inode *inode,
if (ret)
goto err;
 
-   if (write && !skip_sum) {
+   if (skip_sum)
+   goto map;
+
+   if (write && async_submit) {
ret = btrfs_wq_submit_bio(root->fs_info,
   inode, rw, bio, 0, 0,
   file_offset,
   __btrfs_submit_bio_start_direct_io,
   __btrfs_submit_bio_done);
goto err;
+   } else if (write) {
+   /*
+* If we aren't doing async submit, calculate the csum of the
+* bio now.
+*/
+   ret = btrfs_csum_one_bio(root, inode, bio, file_offset, 1);
+   if (ret)
+   goto err;
} else if (!skip_sum) {
ret = btrfs_lookup_bio_sums_dio(root, inode, bio,
  file_offset, csums);
@@ -5980,7 +5991,8 @@ static inline int __btrfs_submit_dio_bio(struct bio *bio, 
struct inode *inode,
goto err;
}
 
-   ret = btrfs_map_bio(root, rw, bio, 0, 1);
+map:
+   ret = btrfs_map_bio(root, rw, bio, 0, async_submit);
 err:
bio_put(bio);
return ret;
@@ -6002,6 +6014,7 @@ static int btrfs_submit_direct_hook(int rw, struct 
btrfs_dio_private *dip,
int nr_pages = 0;
u32 *csums = dip->csums;
int ret = 0;
+   int async_submit = 0;
int write = rw & REQ_WRITE;
 
map_length = orig_bio->bi_size;
@@ -6017,6 +6030,7 @@ static int btrfs_submit_direct_hook(int rw, struct 
btrfs_dio_private *dip,
goto submit;
}
 
+   async_submit = 1;
bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, start_sector, GFP_NOFS);
if (!bio)
return -ENOMEM;
@@ -6037,7 +6051,7 @@ static int btrfs_submit_direct_hook(int rw, struct 
btrfs_dio_private *dip,
atomic_inc(&dip->pending_bios);
ret = __btrfs_submit_dio_bio(bio, inode, rw,
 file_offset, skip_sum,
-csums);
+csums, async_submit);
if (ret) {
bio_put(bio);
atomic_dec(&dip->pending_bios);
@@ -6076,7 +6090,7 @@ static int btrfs_submit_direct_hook(int rw, struct 
btrfs_dio_private *dip,
 
 submit:
ret = __btrfs_submit_dio_bio(bio, inode, rw, file_offset, skip_sum,
-csums);
+csums, async_submit);
if (!ret)
return 0;
 
-- 
1.7.2.3

--
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: BUG: unable to handle kernel NULL pointer dereference at (null)

2011-04-06 Thread Josef Bacik
On Wed, Apr 06, 2011 at 01:10:38PM +0200, Johannes Hirte wrote:
> On Tuesday 05 April 2011 23:57:53 Josef Bacik wrote:
> > > Now it hit
> > 
> > Man I cannot catch a break.  I hope this is the last one.  Thanks,
> > 

Ok I give up, I just cleaned it all up and don't mark the pages as dirty unless
we're actually going to succeed at writing them.  This should fix everything

---
 fs/btrfs/ctree.h|5 ++
 fs/btrfs/file.c |   21 +++
 fs/btrfs/free-space-cache.c |  117 ---
 3 files changed, 69 insertions(+), 74 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 3458b57..0d00a07 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2576,6 +2576,11 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, 
struct inode *inode,
 int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
  struct inode *inode, u64 start, u64 end);
 int btrfs_release_file(struct inode *inode, struct file *file);
+void btrfs_drop_pages(struct page **pages, size_t num_pages);
+int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,
+ struct page **pages, size_t num_pages,
+ loff_t pos, size_t write_bytes,
+ struct extent_state **cached);
 
 /* tree-defrag.c */
 int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e621ea5..75899a0 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -104,7 +104,7 @@ static noinline int btrfs_copy_from_user(loff_t pos, int 
num_pages,
 /*
  * unlocks pages after btrfs_file_write is done with them
  */
-static noinline void btrfs_drop_pages(struct page **pages, size_t num_pages)
+void btrfs_drop_pages(struct page **pages, size_t num_pages)
 {
size_t i;
for (i = 0; i < num_pages; i++) {
@@ -127,16 +127,13 @@ static noinline void btrfs_drop_pages(struct page 
**pages, size_t num_pages)
  * this also makes the decision about creating an inline extent vs
  * doing real data extents, marking pages dirty and delalloc as required.
  */
-static noinline int dirty_and_release_pages(struct btrfs_root *root,
-   struct file *file,
-   struct page **pages,
-   size_t num_pages,
-   loff_t pos,
-   size_t write_bytes)
+int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,
+ struct page **pages, size_t num_pages,
+ loff_t pos, size_t write_bytes,
+ struct extent_state **cached)
 {
int err = 0;
int i;
-   struct inode *inode = fdentry(file)->d_inode;
u64 num_bytes;
u64 start_pos;
u64 end_of_last_block;
@@ -149,7 +146,7 @@ static noinline int dirty_and_release_pages(struct 
btrfs_root *root,
 
end_of_last_block = start_pos + num_bytes - 1;
err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block,
-   NULL);
+   cached);
if (err)
return err;
 
@@ -992,9 +989,9 @@ static noinline ssize_t __btrfs_buffered_write(struct file 
*file,
}
 
if (copied > 0) {
-   ret = dirty_and_release_pages(root, file, pages,
- dirty_pages, pos,
- copied);
+   ret = btrfs_dirty_pages(root, inode, pages,
+   dirty_pages, pos, copied,
+   NULL);
if (ret) {
btrfs_delalloc_release_space(inode,
dirty_pages << PAGE_CACHE_SHIFT);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index f561c95..a3f420d 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -508,6 +508,7 @@ int btrfs_write_out_cache(struct btrfs_root *root,
struct inode *inode;
struct rb_node *node;
struct list_head *pos, *n;
+   struct page **pages;
struct page *page;
struct extent_state *cached_state = NULL;
struct btrfs_free_cluster *cluster = NULL;
@@ -517,13 +518,13 @@ int btrfs_write_out_cache(struct btrfs_root *root,
u64 start, end, len;
u64 bytes = 0;
u32 *crc, *checksums;
-   pgoff_t index = 0, last_index = 0;
unsigned long first_page_offset;
-   int num_checksums;
+   int index = 0, num_pages = 0;
int entries = 0;
int bitmaps = 0;
int ret = 0;
bool next_page = false;
+   bool out_of_space = false;
 
root = root->fs_info->tree_root;
 
@@ -551,2

Re: [PATCH] Btrfs: don't kzalloc the ordered extents

2011-04-06 Thread Josef Bacik

On 04/06/2011 07:06 AM, Chris Mason wrote:

Excerpts from Arne Jansen's message of 2011-04-06 03:54:07 -0400:

On 06.04.2011 01:20, Josef Bacik wrote:

We initialize almost all of the fields when we allocate an ordered extent, so
use kmalloc instead of kzalloc and just initialize the other fields that we
don't already initialize yet.  Thanks,

Is it really worth it? we have seen a few bugs in the past resulting
from uninitialized structure element, that even made it to disk.
Using kzalloc makes maintenance much easier.

I'm a big kzalloc fan unless this particular caller shows up in
benchmarks.  Josef how much did this one help?

-chris
.1 mb/s, give or take .1 mb/s :).  Just low hanging fruit since we're 
already doing all the initialization anyway, but it's up to you, kind of 
just was fixing everything I could get my hands on :).  Thanks,


Josef
--
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: cloning single-device btrfs file system onto multi-device one

2011-04-06 Thread Arne Jansen
On 06.04.2011 14:05, Stephane Chazelas wrote:
> 2011-04-06 10:25:00 +0200, Arne Jansen:
>> On 28.03.2011 15:17, Stephane Chazelas wrote:
>>>
>>> I then did a btrfs fi balance again and let it run through. However here is
>>> what I get:
>>>
>>> $ df -h /mnt
>>> FilesystemSize  Used Avail Use% Mounted on
>>> /dev/sdb  8.2T  3.5T  3.2T  53% /mnt
>>>
>>> Only 3.2T left. How would I reclaim the missing space?
>>>
>>> $ sudo btrfs fi show
>>> Label: none  uuid: ...
>>> Total devices 3 FS bytes used 3.43TB
>>> devid4 size 2.73TB used 1.17TB path /dev/sdc
>>> devid3 size 2.73TB used 1.17TB path /dev/sdb
>>> devid2 size 2.70TB used 1.14TB path /dev/sda4
>>> $ sudo btrfs fi df /mnt
>>> Data, RAID0: total=3.41TB, used=3.41TB
>>> System, RAID1: total=16.00MB, used=232.00KB
>>> Metadata, RAID1: total=35.25GB, used=20.55GB
>>>
>>> So that kind of worked but that is of little use to me as 2TB
>>> kind of disappeared under my feet in the process.
>>>
>>> Any idea, anyone?
>>>
>>
>> This can just be a miscalculation. Can you please send the output
>> of btrfs-debug-tree -d /dev/sdc? Shouldn't be too long.
> [..]
> 
> Hi Arne,
> 
> Here it is below (compressed and b64-uuencoded as it's about 1MB
> large)
> 
> begin-base64 600 bdt.log.xz

The tree says:
2x28.25 GB in metadata
3,41 TB in data
16MB in system

so I'd say the calculation of Avail in df is just wrong.

-Arne


--
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: cloning single-device btrfs file system onto multi-device one

2011-04-06 Thread Stephane Chazelas
2011-03-28 14:17:48 +0100, Stephane Chazelas:
[...]
> So here is how I transferred a 6TB btrfs on one 6TB raid5 device
> (on host src) over the network onto a btrfs on 3 3TB hard drives
[...]
> I then did a btrfs fi balance again and let it run through. However here is
> what I get:
[...]

Sorry, it didn't run through and it is still running (after 9
days) and there are indications it  could still be running 8 years from
now (see other thread). There hasn't been any change in the
amount of free space reported by df since the beginning of  the
balance (there still are 2TB missing).

Cheers,
Stephane
--
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: btrfs balancing start - and stop?

2011-04-06 Thread Stephane Chazelas
2011-04-04 20:07:54 +0100, Stephane Chazelas:
[...]
> > > 4.7 more days to go. And I reckon it will have written about 9
> > > TB to disk by that time (which is the total size of the volume,
> > > though only 3.8TB are occupied).
> > 
> > Yes - that's the pessimistic estimation. As Hugo has explained it can  
> > finish faster - just look to the data tomorrow again.
> [...]
> 
> That may be an optimistic estimation actually, as there hasn't
> been much progress in the last 34 hours:
[...]

The rate is going down. It's now down to about 14kB/s

[658654.295752] btrfs: relocating block group 3919858106368 flags 20
[671932.913235] btrfs: relocating block group 3919589670912 flags 20
[686189.296126] btrfs: relocating block group 3919321235456 flags 20
[701511.523990] btrfs: relocating block group 391905280 flags 20
[718591.316339] btrfs: relocating block group 3918784364544 flags 20
[725567.081031] btrfs: relocating block group 3918515929088 flags 20
[744415.011581] btrfs: relocating block group 3918247493632 flags 20
[762365.021458] btrfs: relocating block group 3917979058176 flags 20
[780504.726067] btrfs: relocating block group 3917710622720 flags 20

Even though it is reading and writing to disk at a much higher
rate. Here stats every second:

--dsk/sda-dsk/sdb-dsk/sdc--
 read  writ: read  writ: read  writ
   0 0 : 540k0 :  12k0
   0 0 : 704k0 :  20k0
   0 0 :1068k0 :  24k0
   0 0 : 968k0 :   0 0
   0 0 : 932k0 :4096B0
   0 0 : 832k  880k: 152k 1320k
  60k 4096B: 880k  140k:   028M
  68k0 : 308k0 :4096B 9240k
   048k:   0 0 :   0  7852k
   0 0 : 576k 6192k:4096B   26M
   0 0 : 100k   18M:   0 0
   0 0 :  28k   10M:   0 0
   0 0 :   0  7020k:   0 0
   0 0 :  52k   13M:   0 0
   012k: 528k   17M:   012k
   0 0 : 884k0 :8192B0
   0 0 :1068k0 :  20k0
   0 0 : 660k0 :   0 0
   040k: 776k0 :4096B0
   0 0 : 576k0 :   0 0
   0 0 : 596k0 :8192B0
1096k   28k: 664k0 :4096B0
   0 0 : 660k0 :   0 0
   0 0 : 592k0 :8192B0

At this rate, the balancing would be over in about 8 years.

Since the start of the balance:
Device:tpsMB_read/sMB_wrtn/sMB_readMB_wrtn
sda  10.04 1.56 1.5712282861237359
sdc 396.24 1.77 3.9513970153115057
sdb 421.17 1.87 3.9514737593115093

I think that's the end of my attempt to transfer that FS to
another machine (see other thread). I'll have to ditch that copy
and try again from scratch with another approach.

Before I do that, is there anything I can do to help investigate
the problem?

regards,
Stephane
--
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: BUG: unable to handle kernel NULL pointer dereference at (null)

2011-04-06 Thread Johannes Hirte
On Tuesday 05 April 2011 23:57:53 Josef Bacik wrote:
> > Now it hit
> 
> Man I cannot catch a break.  I hope this is the last one.  Thanks,
> 
> Josef
> 
> ---
>  fs/btrfs/free-space-cache.c |   32 
>  1 files changed, 32 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 74bc432..b8052be 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -522,6 +522,7 @@ int btrfs_write_out_cache(struct btrfs_root *root,
>   int bitmaps = 0;
>   int ret = 0;
>   bool next_page = false;
> + bool out_of_space = false;
> 
>   root = root->fs_info->tree_root;
> 
> @@ -629,6 +630,11 @@ int btrfs_write_out_cache(struct btrfs_root *root,
>   offset = start_offset;
>   }
> 
> + if (index > last_index) {
> + out_of_space = true;
> + break;
> + }
> +
>   page = find_get_page(inode->i_mapping, index);
> 
>   addr = kmap(page);
> @@ -732,6 +738,10 @@ int btrfs_write_out_cache(struct btrfs_root *root,
>   struct btrfs_free_space *entry =
>   list_entry(pos, struct btrfs_free_space, list);
> 
> + if (index > last_index) {
> + out_of_space = true;
> + break;
> + }
>   page = find_get_page(inode->i_mapping, index);
> 
>   addr = kmap(page);
> @@ -754,6 +764,28 @@ int btrfs_write_out_cache(struct btrfs_root *root,
>   index++;
>   }
> 
> + if (out_of_space) {
> + page = find_get_page(inode->i_mapping, 0);
> +
> + /*
> +  * Have to do the normal stuff in case writeback gets started on
> +  * this page before we invalidate it.
> +  */
> + ClearPageChecked(page);
> + set_page_extent_mapped(page);
> + SetPageUptodate(page);
> + set_page_dirty(page);
> + unlock_page(page);
> + page_cache_release(page);
> + page_cache_release(page);
> +
> + ret = 0;
> + unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0,
> +  i_size_read(inode) - 1, &cached_state,
> +  GFP_NOFS);
> + goto out_free;
> + }
> +
>   /* Zero out the rest of the pages just to make sure */
>   while (index <= last_index) {
>   void *addr;

Sorry no, it still hits the BUG() in inode.c (line 1565). It takes longer to 
hit than before but is still reproducible.
--
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: [PATCH] Btrfs: don't kzalloc the ordered extents

2011-04-06 Thread Chris Mason
Excerpts from Arne Jansen's message of 2011-04-06 03:54:07 -0400:
> On 06.04.2011 01:20, Josef Bacik wrote:
> > We initialize almost all of the fields when we allocate an ordered extent, 
> > so
> > use kmalloc instead of kzalloc and just initialize the other fields that we
> > don't already initialize yet.  Thanks,
> 
> Is it really worth it? we have seen a few bugs in the past resulting
> from uninitialized structure element, that even made it to disk.
> Using kzalloc makes maintenance much easier.

I'm a big kzalloc fan unless this particular caller shows up in
benchmarks.  Josef how much did this one help?

-chris
--
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: fix subvolume fake mount problem when default subvolume is set

2011-04-06 Thread Zhong, Xin
We create two subvolumes (meego_root and meego_home) in
btrfs root directory. And set meego_root as default mount
subvolume. After we remount btrfs, meego_root is mounted
to top directory by default. Then if we create a directory with
the same name as meego_home, we can mount meego_home subvolume
sucessfully (subvol=meego_home). But this is incorrect. What we
do in this mount point will not change anything in meego_home
subvolume. The problem is when default mount subvolume is set to
meego_root, we search meego_home in meego_root. But if we find a
directory with the same name, we will treat it as subvolume. So
the solution is to check if what we find is really a subvolume.

Signed-off-by: Zhong, Xin 
---
 fs/btrfs/super.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index b85fe78..66a76b7 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -823,7 +823,9 @@ static int btrfs_get_sb(struct file_system_type *fs_type, 
int flags,
error = PTR_ERR(new_root);
goto error_free_subvol_name;
}
-   if (!new_root->d_inode) {
+   if (!new_root->d_inode ||
+   /* new_root is a directory, not subvolume */
+   new_root->d_inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) {
dput(root);
dput(new_root);
deactivate_locked_super(s);
-- 
1.7.0.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


[RFC][PATCH] btrfs: using cached extent_state in set/unlock combinations

2011-04-06 Thread Arne Jansen
In several places the sequence (set_extent_uptodate, unlock_extent) is used.
This leads to a duplicate lookup of the extent state. This patch lets
set_extent_uptodate return a cached extent_state which can be passed to
unlock_extent_cached.
The occurences of the above sequences are updated to use the cache. Only
end_bio_extent_readpage is updated that it first gets a cached state to
pass it to the readpage_end_io_hook as the prototype requested and is later
on being used for set/unlock.

Signed-off-by: Arne Jansen 
---
 fs/btrfs/extent_io.c |   70 +
 fs/btrfs/extent_io.h |2 +-
 fs/btrfs/inode.c |2 +-
 3 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 9fcb5ed..9e8230d 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -690,6 +690,17 @@ static void cache_state(struct extent_state *state,
}
 }
 
+static void uncache_state(struct extent_state **cached_ptr)
+{
+   if (cached_ptr && (*cached_ptr)) {
+   struct extent_state *state = *cached_ptr;
+   if (state->state & (EXTENT_IOBITS | EXTENT_BOUNDARY)) {
+   *cached_ptr = NULL;
+   free_extent_state(state);
+   }
+   }
+}
+
 /*
  * set some bits on a range in the tree.  This may require allocations or
  * sleeping, so the gfp mask is used to indicate what is allowed.
@@ -940,10 +951,10 @@ static int clear_extent_new(struct extent_io_tree *tree, 
u64 start, u64 end,
 }
 
 int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
-   gfp_t mask)
+   struct extent_state **cached_state, gfp_t mask)
 {
-   return set_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, NULL,
- NULL, mask);
+   return set_extent_bit(tree, start, end, EXTENT_UPTODATE, 0,
+ NULL, cached_state, mask);
 }
 
 static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,
@@ -1012,8 +1023,7 @@ int unlock_extent_cached(struct extent_io_tree *tree, u64 
start, u64 end,
mask);
 }
 
-int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end,
- gfp_t mask)
+int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask)
 {
return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, NULL,
mask);
@@ -1735,6 +1745,9 @@ static void end_bio_extent_readpage(struct bio *bio, int 
err)
 
do {
struct page *page = bvec->bv_page;
+   struct extent_state *cached = NULL;
+   struct extent_state *state;
+
tree = &BTRFS_I(page->mapping->host)->io_tree;
 
start = ((u64)page->index << PAGE_CACHE_SHIFT) +
@@ -1749,9 +1762,20 @@ static void end_bio_extent_readpage(struct bio *bio, int 
err)
if (++bvec <= bvec_end)
prefetchw(&bvec->bv_page->flags);
 
+   spin_lock(&tree->lock);
+   state = find_first_extent_bit_state(tree, start, 0);
+   if (state) {
+   /*
+* take a reference on the state, unlock will drop
+* the ref
+*/
+   cache_state(state, &cached);
+   }
+   spin_unlock(&tree->lock);
+
if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) {
ret = tree->ops->readpage_end_io_hook(page, start, end,
- NULL);
+ state);
if (ret)
uptodate = 0;
}
@@ -1764,15 +1788,16 @@ static void end_bio_extent_readpage(struct bio *bio, 
int err)
test_bit(BIO_UPTODATE, &bio->bi_flags);
if (err)
uptodate = 0;
+   uncache_state(&cached);
continue;
}
}
 
if (uptodate) {
-   set_extent_uptodate(tree, start, end,
+   set_extent_uptodate(tree, start, end, &cached,
GFP_ATOMIC);
}
-   unlock_extent(tree, start, end, GFP_ATOMIC);
+   unlock_extent_cached(tree, start, end, &cached, GFP_ATOMIC);
 
if (whole_page) {
if (uptodate) {
@@ -1811,6 +1836,7 @@ static void end_bio_extent_preparewrite(struct bio *bio, 
int err)
 
do {
struct page *page = bvec->bv_page;
+   struct extent_state *cached = NULL;
tree = &BTRFS_I(page->mappin

[PATCH] Trace: add __print_symbolic_u64 to avoid warnings on 32bit machine

2011-04-06 Thread liubo

Btrfs has some "ULL" macros, and when these macros are passed to tracepoints'
__print_symbolic(), there will be 64->32 truncate WARNINGS during compiling
on 32bit box.

Signed-off-by: Liu Bo 
---
 include/linux/ftrace_event.h |   12 
 include/trace/events/btrfs.h |4 ++--
 include/trace/ftrace.h   |   13 +
 kernel/trace/trace_output.c  |   27 +++
 4 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 22b32af..6b2e245 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -16,6 +16,11 @@ struct trace_print_flags {
const char  *name;
 };
 
+struct trace_print_flags_u64 {
+   unsigned long long  mask;
+   const char  *name;
+};
+
 const char *ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
   unsigned long flags,
   const struct trace_print_flags *flag_array);
@@ -23,6 +28,13 @@ const char *ftrace_print_flags_seq(struct trace_seq *p, 
const char *delim,
 const char *ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
 const struct trace_print_flags 
*symbol_array);
 
+#if BITS_PER_LONG == 32
+const char *ftrace_print_symbols_seq_u64(struct trace_seq *p,
+unsigned long long val,
+const struct trace_print_flags_u64
+*symbol_array);
+#endif
+
 const char *ftrace_print_hex_seq(struct trace_seq *p,
 const unsigned char *buf, int len);
 
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index f445cff..4114129 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -28,7 +28,7 @@ struct extent_buffer;
{ BTRFS_SHARED_DATA_REF_KEY,"SHARED_DATA_REF" })
 
 #define __show_root_type(obj)  \
-   __print_symbolic(obj,   \
+   __print_symbolic_u64(obj,   \
{ BTRFS_ROOT_TREE_OBJECTID, "ROOT_TREE" },  \
{ BTRFS_EXTENT_TREE_OBJECTID,   "EXTENT_TREE"   },  \
{ BTRFS_CHUNK_TREE_OBJECTID,"CHUNK_TREE"},  \
@@ -125,7 +125,7 @@ DEFINE_EVENT(btrfs__inode, btrfs_inode_evict,
 );
 
 #define __show_map_type(type)  \
-   __print_symbolic(type,  \
+   __print_symbolic_u64(type,  \
{ EXTENT_MAP_LAST_BYTE, "LAST_BYTE" },  \
{ EXTENT_MAP_HOLE,  "HOLE"  },  \
{ EXTENT_MAP_INLINE,"INLINE"},  \
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index 3e68366..533c49f 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -205,6 +205,19 @@
ftrace_print_symbols_seq(p, value, symbols);\
})
 
+#undef __print_symbolic_u64
+#if BITS_PER_LONG == 32
+#define __print_symbolic_u64(value, symbol_array...)   \
+   ({  \
+   static const struct trace_print_flags_u64 symbols[] =   \
+   { symbol_array, { -1, NULL } }; \
+   ftrace_print_symbols_seq_u64(p, value, symbols);\
+   })
+#else
+#define __print_symbolic_u64(value, symbol_array...)   \
+   __print_symbolic(value, symbol_array)
+#endif
+
 #undef __print_hex
 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
 
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 456be90..47aafa9 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -353,6 +353,33 @@ ftrace_print_symbols_seq(struct trace_seq *p, unsigned 
long val,
 }
 EXPORT_SYMBOL(ftrace_print_symbols_seq);
 
+#if BITS_PER_LONG == 32
+const char *
+ftrace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
+const struct trace_print_flags_u64 *symbol_array)
+{
+   int i;
+   const char *ret = p->buffer + p->len;
+
+   for (i = 0;  symbol_array[i].name; i++) {
+
+   if (val != symbol_array[i].mask)
+   continue;
+
+   trace_seq_puts(p, symbol_array[i].name);
+   break;
+   }
+
+   if (!p->len)
+   trace_seq_printf(p, "0x%llx", val);
+
+   trace_seq_putc(p, 0);
+
+   return ret;
+}
+EXPORT_SYMBOL(ftrace_print_symbols_seq_u64);
+#endif
+
 const char *
 ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int 

RE: [PATCH V3] Btrfs: fix subvolume mount by name problem when default mount subvolume is set

2011-04-06 Thread Zhong, Xin
> -Original Message-
> From: Andreas Philipp [mailto:philipp.andr...@gmail.com]
> Sent: Wednesday, April 06, 2011 4:39 PM
> To: Zhong, Xin
> Cc: linux-btrfs@vger.kernel.org; Andreas Philipp
> Subject: Re: [PATCH V3] Btrfs: fix subvolume mount by name problem when
> default mount subvolume is set
> 
> 
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> Just a (probably) short question. This means, one now can mount any
> subvolume which lies directly in another subvolume by name, as long as
> one passes the correct subvolrootid=X mount option?

Yes. That's exactly what this patch does. Thanks!

> 
> Thanks,
> Andreas Philipp
> 
> On 06.04.2011 09:33, Zhong, Xin wrote:
> > We create two subvolumes (meego_root and meego_home) in
> > btrfs root directory. And set meego_root as default mount
> > subvolume. After we remount btrfs, meego_root is mounted
> > to top directory by default. Then when we try to mount
> > meego_home (subvol=meego_home) to a subdirectory, it failed.
> > The problem is when default mount subvolume is set to
> > meego_root, we search meego_home in meego_root but can not find
> > it. So the solution is to add a new mount option (subvolrootid)
> > to specify subvol id of root and search subvol name in it. For
> > our case, now we can use "-o subvolrootid=0,subvol=meego_home)
> > to mount meego_home.
> >
> > Detail information can be found in meego bugzilla:
> > https://bugs.meego.com/show_bug.cgi?id=15055
> >
> > Signed-off-by: Zhong, Xin 
> > ---
> > fs/btrfs/super.c | 42 +-
> > 1 files changed, 33 insertions(+), 9 deletions(-)
> >
> > diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> > index db0a827..b85fe78 100644
> > --- a/fs/btrfs/super.c
> > +++ b/fs/btrfs/super.c
> > @@ -156,7 +156,7 @@ enum {
> > Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
> > Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
> > Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
> > - Opt_enospc_debug, Opt_err,
> > + Opt_enospc_debug, Opt_subvolrootid, Opt_err,
> > };
> >
> > static match_table_t tokens = {
> > @@ -186,6 +186,7 @@ static match_table_t tokens = {
> > {Opt_clear_cache, "clear_cache"},
> > {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
> > {Opt_enospc_debug, "enospc_debug"},
> > + {Opt_subvolrootid, "subvolrootid=%d"},
> > {Opt_err, NULL},
> > };
> >
> > @@ -229,6 +230,7 @@ int btrfs_parse_options(struct btrfs_root *root,
> char *options)
> > break;
> > case Opt_subvol:
> > case Opt_subvolid:
> > + case Opt_subvolrootid:
> > case Opt_device:
> > /*
> > * These are parsed by btrfs_parse_early_options
> > @@ -385,7 +387,7 @@ out:
> > */
> > static int btrfs_parse_early_options(const char *options, fmode_t
> flags,
> > void *holder, char **subvol_name, u64 *subvol_objectid,
> > - struct btrfs_fs_devices **fs_devices)
> > + u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
> > {
> > substring_t args[MAX_OPT_ARGS];
> > char *opts, *orig, *p;
> > @@ -426,6 +428,18 @@ static int btrfs_parse_early_options(const char
> *options, fmode_t flags,
> > *subvol_objectid = intarg;
> > }
> > break;
> > + case Opt_subvolrootid:
> > + intarg = 0;
> > + error = match_int(&args[0], &intarg);
> > + if (!error) {
> > + /* we want the original fs_tree */
> > + if (!intarg)
> > + *subvol_rootid =
> > + BTRFS_FS_TREE_OBJECTID;
> > + else
> > + *subvol_rootid = intarg;
> > + }
> > + break;
> > case Opt_device:
> > error = btrfs_scan_one_device(match_strdup(&args[0]),
> > flags, holder, fs_devices);
> > @@ -715,6 +729,7 @@ static int btrfs_get_sb(struct file_system_type
> *fs_type, int flags,
> > fmode_t mode = FMODE_READ;
> > char *subvol_name = NULL;
> > u64 subvol_objectid = 0;
> > + u64 subvol_rootid = 0;
> > int error = 0;
> >
> > if (!(flags & MS_RDONLY))
> > @@ -722,7 +737,7 @@ static int btrfs_get_sb(struct file_system_type
> *fs_type, int flags,
> >
> > error = btrfs_parse_early_options(data, mode, fs_type,
> > &subvol_name, &subvol_objectid,
> > - &fs_devices);
> > + &subvol_rootid, &fs_devices);
> > if (error)
> > return error;
> >
> > @@ -786,15 +801,17 @@ static int btrfs_get_sb(struct file_system_type
> *fs_type, int flags,
> > s->s_flags |= MS_ACTIVE;
> > }
> >
> > - root = get_default_root(s, subvol_objectid);
> > - if (IS_ERR(root)) {
> > - error = PTR_ERR(root);
> > - deactivate_locked_super(s);
> > - goto error_free_subvol_name;
> > - }
> > /* if they gave us a subvolume name bind mount into that */
> > if (strcmp(subvol_name, ".")) {
> > struct dentry *new_root;
> > +
> > + root = get_default_root(s, subvol_rootid);
> > + if (IS_ERR(root)) {
> > + error = PTR_ERR(root);
> > + deactivate_locked_super(s);
> > + goto error_free_subvol_name;
> > + }
> > +
> > mutex_lock(&root->d_inode->i_mutex);
> > new_root = lookup_one_len(subvol_name, root,
> > strlen(subvol_name));
> > @@ -815,6 +832,13 @@ static int btrfs_get_sb(struct file_system_type
> *fs_type, int flags,
> > }
> > dput(root);
> > root = new_root;
>

Re: [PATCH V3] Btrfs: fix subvolume mount by name problem when default mount subvolume is set

2011-04-06 Thread Andreas Philipp

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
 
Just a (probably) short question. This means, one now can mount any
subvolume which lies directly in another subvolume by name, as long as
one passes the correct subvolrootid=X mount option?

Thanks,
Andreas Philipp

On 06.04.2011 09:33, Zhong, Xin wrote:
> We create two subvolumes (meego_root and meego_home) in
> btrfs root directory. And set meego_root as default mount
> subvolume. After we remount btrfs, meego_root is mounted
> to top directory by default. Then when we try to mount
> meego_home (subvol=meego_home) to a subdirectory, it failed.
> The problem is when default mount subvolume is set to
> meego_root, we search meego_home in meego_root but can not find
> it. So the solution is to add a new mount option (subvolrootid)
> to specify subvol id of root and search subvol name in it. For
> our case, now we can use "-o subvolrootid=0,subvol=meego_home)
> to mount meego_home.
>
> Detail information can be found in meego bugzilla:
> https://bugs.meego.com/show_bug.cgi?id=15055
>
> Signed-off-by: Zhong, Xin 
> ---
> fs/btrfs/super.c | 42 +-
> 1 files changed, 33 insertions(+), 9 deletions(-)
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index db0a827..b85fe78 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -156,7 +156,7 @@ enum {
> Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
> Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
> Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
> - Opt_enospc_debug, Opt_err,
> + Opt_enospc_debug, Opt_subvolrootid, Opt_err,
> };
>
> static match_table_t tokens = {
> @@ -186,6 +186,7 @@ static match_table_t tokens = {
> {Opt_clear_cache, "clear_cache"},
> {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
> {Opt_enospc_debug, "enospc_debug"},
> + {Opt_subvolrootid, "subvolrootid=%d"},
> {Opt_err, NULL},
> };
>
> @@ -229,6 +230,7 @@ int btrfs_parse_options(struct btrfs_root *root,
char *options)
> break;
> case Opt_subvol:
> case Opt_subvolid:
> + case Opt_subvolrootid:
> case Opt_device:
> /*
> * These are parsed by btrfs_parse_early_options
> @@ -385,7 +387,7 @@ out:
> */
> static int btrfs_parse_early_options(const char *options, fmode_t flags,
> void *holder, char **subvol_name, u64 *subvol_objectid,
> - struct btrfs_fs_devices **fs_devices)
> + u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
> {
> substring_t args[MAX_OPT_ARGS];
> char *opts, *orig, *p;
> @@ -426,6 +428,18 @@ static int btrfs_parse_early_options(const char
*options, fmode_t flags,
> *subvol_objectid = intarg;
> }
> break;
> + case Opt_subvolrootid:
> + intarg = 0;
> + error = match_int(&args[0], &intarg);
> + if (!error) {
> + /* we want the original fs_tree */
> + if (!intarg)
> + *subvol_rootid =
> + BTRFS_FS_TREE_OBJECTID;
> + else
> + *subvol_rootid = intarg;
> + }
> + break;
> case Opt_device:
> error = btrfs_scan_one_device(match_strdup(&args[0]),
> flags, holder, fs_devices);
> @@ -715,6 +729,7 @@ static int btrfs_get_sb(struct file_system_type
*fs_type, int flags,
> fmode_t mode = FMODE_READ;
> char *subvol_name = NULL;
> u64 subvol_objectid = 0;
> + u64 subvol_rootid = 0;
> int error = 0;
>
> if (!(flags & MS_RDONLY))
> @@ -722,7 +737,7 @@ static int btrfs_get_sb(struct file_system_type
*fs_type, int flags,
>
> error = btrfs_parse_early_options(data, mode, fs_type,
> &subvol_name, &subvol_objectid,
> - &fs_devices);
> + &subvol_rootid, &fs_devices);
> if (error)
> return error;
>
> @@ -786,15 +801,17 @@ static int btrfs_get_sb(struct file_system_type
*fs_type, int flags,
> s->s_flags |= MS_ACTIVE;
> }
>
> - root = get_default_root(s, subvol_objectid);
> - if (IS_ERR(root)) {
> - error = PTR_ERR(root);
> - deactivate_locked_super(s);
> - goto error_free_subvol_name;
> - }
> /* if they gave us a subvolume name bind mount into that */
> if (strcmp(subvol_name, ".")) {
> struct dentry *new_root;
> +
> + root = get_default_root(s, subvol_rootid);
> + if (IS_ERR(root)) {
> + error = PTR_ERR(root);
> + deactivate_locked_super(s);
> + goto error_free_subvol_name;
> + }
> +
> mutex_lock(&root->d_inode->i_mutex);
> new_root = lookup_one_len(subvol_name, root,
> strlen(subvol_name));
> @@ -815,6 +832,13 @@ static int btrfs_get_sb(struct file_system_type
*fs_type, int flags,
> }
> dput(root);
> root = new_root;
> + } else {
> + root = get_default_root(s, subvol_objectid);
> + if (IS_ERR(root)) {
> + error = PTR_ERR(root);
> + deactivate_locked_super(s);
> + goto error_free_subvol_name;
> + }
> }
>
> mnt->mnt_sb = s;
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
iQIcBAEBAgAGBQJNnCaeAAoJEJIcBJ3+Xkgi8AYP/2kZW9AkQOJoCFQiDipTF5ck
yeXqKAqaMnmry0XY3I3ideZKpFp5C1U6QqoA/uy/ieHDx1OPix+wciLuqo/uxbKj
LG3bKJTEcZ5swdjY6oHsTp9iQFXn5tNHTb0Sayha6QaJgkQ/FU4AV5jPmXdN5DvE
xGuaY08rvshE2Bm6nqG5KpRIeuaPoGRd7qFvorhzzMDZ1bEZ8OcbDy4q4SgTR3ji
mgDARmtnh38IASIb5/6CXLVsCgMf2t4lKlXA6pwFXruKy

[PATCH V3] Btrfs: fix subvolume mount by name problem when default mount subvolume is set

2011-04-06 Thread Zhong, Xin
We create two subvolumes (meego_root and meego_home) in
btrfs root directory. And set meego_root as default mount
subvolume. After we remount btrfs, meego_root is mounted
to top directory by default. Then when we try to mount
meego_home (subvol=meego_home) to a subdirectory, it failed.
The problem is when default mount subvolume is set to
meego_root, we search meego_home in meego_root but can not find
it. So the solution is to add a new mount option (subvolrootid)
to specify subvol id of root and search subvol name in it. For
our case, now we can use "-o subvolrootid=0,subvol=meego_home)
to mount meego_home.

Detail information can be found in meego bugzilla:
https://bugs.meego.com/show_bug.cgi?id=15055

Signed-off-by: Zhong, Xin 
---
 fs/btrfs/super.c |   42 +-
 1 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index db0a827..b85fe78 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -156,7 +156,7 @@ enum {
Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
-   Opt_enospc_debug, Opt_err,
+   Opt_enospc_debug, Opt_subvolrootid, Opt_err,
 };
 
 static match_table_t tokens = {
@@ -186,6 +186,7 @@ static match_table_t tokens = {
{Opt_clear_cache, "clear_cache"},
{Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
{Opt_enospc_debug, "enospc_debug"},
+   {Opt_subvolrootid, "subvolrootid=%d"},
{Opt_err, NULL},
 };
 
@@ -229,6 +230,7 @@ int btrfs_parse_options(struct btrfs_root *root, char 
*options)
break;
case Opt_subvol:
case Opt_subvolid:
+   case Opt_subvolrootid:
case Opt_device:
/*
 * These are parsed by btrfs_parse_early_options
@@ -385,7 +387,7 @@ out:
  */
 static int btrfs_parse_early_options(const char *options, fmode_t flags,
void *holder, char **subvol_name, u64 *subvol_objectid,
-   struct btrfs_fs_devices **fs_devices)
+   u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
 {
substring_t args[MAX_OPT_ARGS];
char *opts, *orig, *p;
@@ -426,6 +428,18 @@ static int btrfs_parse_early_options(const char *options, 
fmode_t flags,
*subvol_objectid = intarg;
}
break;
+   case Opt_subvolrootid:
+   intarg = 0;
+   error = match_int(&args[0], &intarg);
+   if (!error) {
+   /* we want the original fs_tree */
+   if (!intarg)
+   *subvol_rootid =
+   BTRFS_FS_TREE_OBJECTID;
+   else
+   *subvol_rootid = intarg;
+   }
+   break;
case Opt_device:
error = btrfs_scan_one_device(match_strdup(&args[0]),
flags, holder, fs_devices);
@@ -715,6 +729,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, 
int flags,
fmode_t mode = FMODE_READ;
char *subvol_name = NULL;
u64 subvol_objectid = 0;
+   u64 subvol_rootid = 0;
int error = 0;
 
if (!(flags & MS_RDONLY))
@@ -722,7 +737,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, 
int flags,
 
error = btrfs_parse_early_options(data, mode, fs_type,
  &subvol_name, &subvol_objectid,
- &fs_devices);
+ &subvol_rootid, &fs_devices);
if (error)
return error;
 
@@ -786,15 +801,17 @@ static int btrfs_get_sb(struct file_system_type *fs_type, 
int flags,
s->s_flags |= MS_ACTIVE;
}
 
-   root = get_default_root(s, subvol_objectid);
-   if (IS_ERR(root)) {
-   error = PTR_ERR(root);
-   deactivate_locked_super(s);
-   goto error_free_subvol_name;
-   }
/* if they gave us a subvolume name bind mount into that */
if (strcmp(subvol_name, ".")) {
struct dentry *new_root;
+
+   root = get_default_root(s, subvol_rootid);
+   if (IS_ERR(root)) {
+   error = PTR_ERR(root);
+   deactivate_locked_super(s);
+   goto error_free_subvol_name;
+   }
+
mutex_lock(&root->d_inode->i_mutex);
new_root = lookup_one_len(subvol_name, root,
  strlen(subvol_name));
@@ -815,6 +832

Re: cloning single-device btrfs file system onto multi-device one

2011-04-06 Thread Arne Jansen
On 28.03.2011 15:17, Stephane Chazelas wrote:
> 
> I then did a btrfs fi balance again and let it run through. However here is
> what I get:
> 
> $ df -h /mnt
> FilesystemSize  Used Avail Use% Mounted on
> /dev/sdb  8.2T  3.5T  3.2T  53% /mnt
> 
> Only 3.2T left. How would I reclaim the missing space?
> 
> $ sudo btrfs fi show
> Label: none  uuid: ...
> Total devices 3 FS bytes used 3.43TB
> devid4 size 2.73TB used 1.17TB path /dev/sdc
> devid3 size 2.73TB used 1.17TB path /dev/sdb
> devid2 size 2.70TB used 1.14TB path /dev/sda4
> $ sudo btrfs fi df /mnt
> Data, RAID0: total=3.41TB, used=3.41TB
> System, RAID1: total=16.00MB, used=232.00KB
> Metadata, RAID1: total=35.25GB, used=20.55GB
> 
> So that kind of worked but that is of little use to me as 2TB
> kind of disappeared under my feet in the process.
> 
> Any idea, anyone?
> 

This can just be a miscalculation. Can you please send the output
of btrfs-debug-tree -d /dev/sdc? Shouldn't be too long.

Thanks,
Arne
--
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: [PATCH V2] Btrfs: fix subvolume mount by name problem when default mount subvolume is set

2011-04-06 Thread Zhong, Xin
> -Original Message-
> From: linux-btrfs-ow...@vger.kernel.org [mailto:linux-btrfs-
> ow...@vger.kernel.org] On Behalf Of Li Zefan
> Sent: Wednesday, April 06, 2011 2:34 PM
> To: Zhong, Xin
> Cc: linux-btrfs@vger.kernel.org
> Subject: Re: [PATCH V2] Btrfs: fix subvolume mount by name problem when
> default mount subvolume is set
> 
> 13:27, Zhong, Xin wrote:
> > We create two subvolumes (meego_root and meego_home) in
> > btrfs root directory. And set meego_root as default mount
> > subvolume. After we remount btrfs, meego_root is mounted
> > to top directory by default. Then when we try to mount
> > meego_home (subvol=meego_home) to a subdirectory, it failed.
> > The problem is when default mount subvolume is set to
> > meego_root, we search meego_home in meego_root but can not find
> > it. So the solution is to add a new mount option (subvolrootid)
> > to specify subvol id of root and search subvol name in it. For
> > our case, now we can use "-o subvolrootid=0,subvol=meego_home)
> > to mount meego_home.
> >
> > Detail information can be found in meego bugzilla:
> > https://bugs.meego.com/show_bug.cgi?id=15055
> >
> > Signed-off-by: Zhong, Xin 
> > ---
> >  fs/btrfs/super.c |   43 ++-
> >  1 files changed, 34 insertions(+), 9 deletions(-)
> >
> 
> I guess you forgot to run checkpatch.pl.

Sorry for my mistake. I have fixed it and resubmit. Thanks!

> 
> ERROR: trailing whitespace
> #183: FILE: fs/btrfs/super.c:807:
> +^I^I$
> 
> ERROR: else should follow close brace '}'
> #198: FILE: fs/btrfs/super.c:836:
> }
> +   else {
> 
> total: 2 errors, 0 warnings, 100 lines checked
> --
> 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
N�r��yb�X��ǧv�^�)޺{.n�+{�n�߲)w*jg����ݢj/���z�ޖ��2�ޙ&�)ߡ�a�����G���h��j:+v���w��٥

[PATCH V2] Btrfs: fix subvolume mount by name problem when default mount subvolume is set

2011-04-06 Thread Zhong, Xin
We create two subvolumes (meego_root and meego_home) in
btrfs root directory. And set meego_root as default mount
subvolume. After we remount btrfs, meego_root is mounted
to top directory by default. Then when we try to mount
meego_home (subvol=meego_home) to a subdirectory, it failed.
The problem is when default mount subvolume is set to
meego_root, we search meego_home in meego_root but can not find
it. So the solution is to add a new mount option (subvolrootid)
to specify subvol id of root and search subvol name in it. For
our case, now we can use "-o subvolrootid=0,subvol=meego_home)
to mount meego_home.

Detail information can be found in meego bugzilla:
https://bugs.meego.com/show_bug.cgi?id=15055

Signed-off-by: Zhong, Xin 
---
 fs/btrfs/super.c |   43 ++-
 1 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index db0a827..5e7bc51 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -156,7 +156,7 @@ enum {
Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
-   Opt_enospc_debug, Opt_err,
+   Opt_enospc_debug, Opt_subvolrootid, Opt_err,
 };
 
 static match_table_t tokens = {
@@ -186,6 +186,7 @@ static match_table_t tokens = {
{Opt_clear_cache, "clear_cache"},
{Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
{Opt_enospc_debug, "enospc_debug"},
+   {Opt_subvolrootid, "subvolrootid=%d"},
{Opt_err, NULL},
 };
 
@@ -229,6 +230,7 @@ int btrfs_parse_options(struct btrfs_root *root, char 
*options)
break;
case Opt_subvol:
case Opt_subvolid:
+   case Opt_subvolrootid:
case Opt_device:
/*
 * These are parsed by btrfs_parse_early_options
@@ -385,7 +387,7 @@ out:
  */
 static int btrfs_parse_early_options(const char *options, fmode_t flags,
void *holder, char **subvol_name, u64 *subvol_objectid,
-   struct btrfs_fs_devices **fs_devices)
+   u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
 {
substring_t args[MAX_OPT_ARGS];
char *opts, *orig, *p;
@@ -426,6 +428,18 @@ static int btrfs_parse_early_options(const char *options, 
fmode_t flags,
*subvol_objectid = intarg;
}
break;
+   case Opt_subvolrootid:
+   intarg = 0;
+   error = match_int(&args[0], &intarg);
+   if (!error) {
+   /* we want the original fs_tree */
+   if (!intarg)
+   *subvol_rootid =
+   BTRFS_FS_TREE_OBJECTID;
+   else
+   *subvol_rootid = intarg;
+   }
+   break;
case Opt_device:
error = btrfs_scan_one_device(match_strdup(&args[0]),
flags, holder, fs_devices);
@@ -715,6 +729,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, 
int flags,
fmode_t mode = FMODE_READ;
char *subvol_name = NULL;
u64 subvol_objectid = 0;
+   u64 subvol_rootid = 0;
int error = 0;
 
if (!(flags & MS_RDONLY))
@@ -722,7 +737,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, 
int flags,
 
error = btrfs_parse_early_options(data, mode, fs_type,
  &subvol_name, &subvol_objectid,
- &fs_devices);
+ &subvol_rootid, &fs_devices);
if (error)
return error;
 
@@ -786,15 +801,17 @@ static int btrfs_get_sb(struct file_system_type *fs_type, 
int flags,
s->s_flags |= MS_ACTIVE;
}
 
-   root = get_default_root(s, subvol_objectid);
-   if (IS_ERR(root)) {
-   error = PTR_ERR(root);
-   deactivate_locked_super(s);
-   goto error_free_subvol_name;
-   }
/* if they gave us a subvolume name bind mount into that */
if (strcmp(subvol_name, ".")) {
struct dentry *new_root;
+
+   root = get_default_root(s, subvol_rootid);
+   if (IS_ERR(root)) {
+   error = PTR_ERR(root);
+   deactivate_locked_super(s);
+   goto error_free_subvol_name;
+   }
+
mutex_lock(&root->d_inode->i_mutex);
new_root = lookup_one_len(subvol_name, root,
  strlen(subvol_name));
@@ -816,6 +83

Re: [PATCH] Btrfs: don't kzalloc the ordered extents

2011-04-06 Thread Arne Jansen
On 06.04.2011 01:20, Josef Bacik wrote:
> We initialize almost all of the fields when we allocate an ordered extent, so
> use kmalloc instead of kzalloc and just initialize the other fields that we
> don't already initialize yet.  Thanks,

Is it really worth it? we have seen a few bugs in the past resulting
from uninitialized structure element, that even made it to disk.
Using kzalloc makes maintenance much easier.

-Arne

> 
> Signed-off-by: Josef Bacik 
> ---
>  fs/btrfs/ordered-data.c |4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
> index 083a554..2edc837 100644
> --- a/fs/btrfs/ordered-data.c
> +++ b/fs/btrfs/ordered-data.c
> @@ -179,7 +179,7 @@ static int __btrfs_add_ordered_extent(struct inode 
> *inode, u64 file_offset,
>   struct btrfs_ordered_extent *entry;
>  
>   tree = &BTRFS_I(inode)->ordered_tree;
> - entry = kzalloc(sizeof(*entry), GFP_NOFS);
> + entry = kmalloc(sizeof(*entry), GFP_NOFS);
>   if (!entry)
>   return -ENOMEM;
>  
> @@ -190,6 +190,7 @@ static int __btrfs_add_ordered_extent(struct inode 
> *inode, u64 file_offset,
>   entry->bytes_left = len;
>   entry->inode = inode;
>   entry->compress_type = compress_type;
> + entry->flags = 0;
>   if (type != BTRFS_ORDERED_IO_DONE && type != BTRFS_ORDERED_COMPLETE)
>   set_bit(type, &entry->flags);
>  
> @@ -201,6 +202,7 @@ static int __btrfs_add_ordered_extent(struct inode 
> *inode, u64 file_offset,
>   init_waitqueue_head(&entry->wait);
>   INIT_LIST_HEAD(&entry->list);
>   INIT_LIST_HEAD(&entry->root_extent_list);
> + RB_CLEAR_NODE(&entry->rb_node);
>  
>   spin_lock(&tree->lock);
>   node = tree_insert(&tree->tree, file_offset,

--
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: cloning single-device btrfs file system onto multi-device one

2011-04-06 Thread Helmut Hullen
Hallo, Stephane,

Du meintest am 28.03.11:

> I then did a btrfs fi balance again and let it run through. However
> here is what I get:

> $ df -h /mnt
> FilesystemSize  Used Avail Use% Mounted on
> /dev/sdb  8.2T  3.5T  3.2T  53% /mnt

> Only 3.2T left. How would I reclaim the missing space?

> $ sudo btrfs fi show
> Label: none  uuid: ...
> Total devices 3 FS bytes used 3.43TB
> devid4 size 2.73TB used 1.17TB path /dev/sdc
> devid3 size 2.73TB used 1.17TB path /dev/sdb
> devid2 size 2.70TB used 1.14TB path /dev/sda4
> $ sudo btrfs fi df /mnt
> Data, RAID0: total=3.41TB, used=3.41TB
> System, RAID1: total=16.00MB, used=232.00KB
> Metadata, RAID1: total=35.25GB, used=20.55GB

> So that kind of worked but that is of little use to me as 2TB
> kind of disappeared under my feet in the process.

It may not please you - I've seen this nasty effect too. Reproducable.

I presume that "balance" eats disk space.

But "balance" seems to be necessary if I want to delete a device, and  
deleting a device is one of the features I'd like to use with btrfs  
(adding a new bigger device, then deleting an old smaller device).

Viele Gruesse!
Helmut
--
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: cloning single-device btrfs file system onto multi-device one

2011-04-06 Thread Helmut Hullen
Hallo, Evert,

Du meintest am 05.04.11:

>> I then did a btrfs fi balance again and let it run through. However
>> here is what I get:
>>
>> $ df -h /mnt
>> Filesystem            Size  Used Avail Use% Mounted on
>> /dev/sdb              8.2T  3.5T  3.2T  53% /mnt
>>
>> Only 3.2T left. How would I reclaim the missing space?
>>
>> $ sudo btrfs fi show
>> Label: none  uuid: ...
>>        Total devices 3 FS bytes used 3.43TB
>>        devid    4 size 2.73TB used 1.17TB path /dev/sdc
>>        devid    3 size 2.73TB used 1.17TB path /dev/sdb
>>        devid    2 size 2.70TB used 1.14TB path /dev/sda4
>> $ sudo btrfs fi df /mnt
>> Data, RAID0: total=3.41TB, used=3.41TB
>> System, RAID1: total=16.00MB, used=232.00KB
>> Metadata, RAID1: total=35.25GB, used=20.55GB
>>
>> So that kind of worked but that is of little use to me as 2TB
>> kind of disappeared under my feet in the process.

> From my limited understanding, btrfs will write metadata in raid1 by
> default. So, this could be where your 2TB has gone.

> I am assuming you used raid0 for the three new disks?

No - take a look at the (shown) output of "btrfs fi df /mnt". "DATA" is RAID0.

Viele Gruesse!
Helmut
--
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