[PATCH 2/2] btrfs: Add ftrace for btrfs_workqueue

2014-03-05 Thread quwen...@cn.fujitsu.com
Add ftrace for btrfs_workqueue for further workqueue tunning.
This patch needs to applied after the workqueue replace patchset.

Signed-off-by: Qu Wenruo 
---
 fs/btrfs/async-thread.c  |  7 
 include/trace/events/btrfs.h | 82 
 2 files changed, 89 insertions(+)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index d8c07e5..00623dd 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include "async-thread.h"
+#include "ctree.h"
 
 #define WORK_DONE_BIT 0
 #define WORK_ORDER_DONE_BIT 1
@@ -210,6 +211,7 @@ static void run_ordered_work(struct __btrfs_workqueue *wq)
 */
if (test_and_set_bit(WORK_ORDER_DONE_BIT, &work->flags))
break;
+   trace_btrfs_ordered_sched(work);
spin_unlock_irqrestore(lock, flags);
work->ordered_func(work);
 
@@ -223,6 +225,7 @@ static void run_ordered_work(struct __btrfs_workqueue *wq)
 * with the lock held though
 */
work->ordered_free(work);
+   trace_btrfs_all_work_done(work);
}
spin_unlock_irqrestore(lock, flags);
 }
@@ -246,12 +249,15 @@ static void normal_work_helper(struct work_struct *arg)
need_order = 1;
wq = work->wq;
 
+   trace_btrfs_work_sched(work);
thresh_exec_hook(wq);
work->func(work);
if (need_order) {
set_bit(WORK_DONE_BIT, &work->flags);
run_ordered_work(wq);
}
+   if (!need_order)
+   trace_btrfs_all_work_done(work);
 }
 
 void btrfs_init_work(struct btrfs_work *work,
@@ -280,6 +286,7 @@ static inline void __btrfs_queue_work(struct 
__btrfs_workqueue *wq,
spin_unlock_irqrestore(&wq->list_lock, flags);
}
queue_work(wq->normal_wq, &work->normal_work);
+   trace_btrfs_work_queued(work);
 }
 
 void btrfs_queue_work(struct btrfs_workqueue *wq,
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index 3176cdc..c346919 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -21,6 +21,7 @@ struct btrfs_block_group_cache;
 struct btrfs_free_cluster;
 struct map_lookup;
 struct extent_buffer;
+struct btrfs_work;
 
 #define show_ref_type(type)\
__print_symbolic(type,  \
@@ -982,6 +983,87 @@ TRACE_EVENT(free_extent_state,
  (void *)__entry->ip)
 );
 
+DECLARE_EVENT_CLASS(btrfs__work,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work),
+
+   TP_STRUCT__entry(
+   __field(void *, work)
+   __field(void *, wq  )
+   __field(void *, func)
+   __field(void *, ordered_func)
+   __field(void *, ordered_free)
+   ),
+
+   TP_fast_assign(
+   __entry->work   = work;
+   __entry->wq = work->wq;
+   __entry->func   = work->func;
+   __entry->ordered_func   = work->ordered_func;
+   __entry->ordered_free   = work->ordered_free;
+   ),
+
+   TP_printk("work=%p, wq=%p, func=%p, ordered_func=%p, ordered_free=%p",
+ __entry->work, __entry->wq, __entry->func,
+ __entry->ordered_func, __entry->ordered_free)
+);
+
+/* For situiations that the work is freed */
+DECLARE_EVENT_CLASS(btrfs__work__done,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work),
+
+   TP_STRUCT__entry(
+   __field(void *, work)
+   ),
+
+   TP_fast_assign(
+   __entry->work   = work;
+   ),
+
+   TP_printk("work->%p", __entry->work)
+);
+
+DEFINE_EVENT(btrfs__work, btrfs_work_queued,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+DEFINE_EVENT(btrfs__work, btrfs_work_sched,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+DEFINE_EVENT(btrfs__work, btrfs_normal_work_done,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+DEFINE_EVENT(btrfs__work__done, btrfs_all_work_done,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+DEFINE_EVENT(btrfs__work, btrfs_ordered_sched,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+
 #endif /* _TRACE_BTRFS_H */
 
 /* This part must be outside protection */
-- 
1.9.0
--
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 1/2] btrfs: Cleanup the btrfs_workqueue related function type

2014-03-05 Thread quwen...@cn.fujitsu.com
The new btrfs_workqueue still use open-coded function defition,
this patch will change them into btrfs_func_t type which is much the
same as kernel workqueue.

Signed-off-by: Qu Wenruo 
---
 fs/btrfs/async-thread.c |  6 +++---
 fs/btrfs/async-thread.h | 20 +++-
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index a709585..d8c07e5 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -255,9 +255,9 @@ static void normal_work_helper(struct work_struct *arg)
 }
 
 void btrfs_init_work(struct btrfs_work *work,
-void (*func)(struct btrfs_work *),
-void (*ordered_func)(struct btrfs_work *),
-void (*ordered_free)(struct btrfs_work *))
+btrfs_func_t func,
+btrfs_func_t ordered_func,
+btrfs_func_t ordered_free)
 {
work->func = func;
work->ordered_func = ordered_func;
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index 08d7174..0a891cd 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -23,11 +23,13 @@
 struct btrfs_workqueue;
 /* Internal use only */
 struct __btrfs_workqueue;
+struct btrfs_work;
+typedef void (*btrfs_func_t)(struct btrfs_work *arg);
 
 struct btrfs_work {
-   void (*func)(struct btrfs_work *arg);
-   void (*ordered_func)(struct btrfs_work *arg);
-   void (*ordered_free)(struct btrfs_work *arg);
+   btrfs_func_t func;
+   btrfs_func_t ordered_func;
+   btrfs_func_t ordered_free;
 
/* Don't touch things below */
struct work_struct normal_work;
@@ -37,13 +39,13 @@ struct btrfs_work {
 };
 
 struct btrfs_workqueue *btrfs_alloc_workqueue(char *name,
-int flags,
-int max_active,
-int thresh);
+ int flags,
+ int max_active,
+ int thresh);
 void btrfs_init_work(struct btrfs_work *work,
-void (*func)(struct btrfs_work *),
-void (*ordered_func)(struct btrfs_work *),
-void (*ordered_free)(struct btrfs_work *));
+btrfs_func_t func,
+btrfs_func_t ordered_func,
+btrfs_func_t ordered_free);
 void btrfs_queue_work(struct btrfs_workqueue *wq,
  struct btrfs_work *work);
 void btrfs_destroy_workqueue(struct btrfs_workqueue *wq);
-- 
1.9.0
--
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 2/2] btrfs: Add ftrace for btrfs_workqueue

2014-03-05 Thread quwen...@cn.fujitsu.com
Add ftrace for btrfs_workqueue for further workqueue tunning.
This patch needs to applied after the workqueue replace patchset.

Signed-off-by: Qu Wenruo 
---
 fs/btrfs/async-thread.c  |  7 
 include/trace/events/btrfs.h | 82 
 2 files changed, 89 insertions(+)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index d8c07e5..00623dd 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include "async-thread.h"
+#include "ctree.h"
 
 #define WORK_DONE_BIT 0
 #define WORK_ORDER_DONE_BIT 1
@@ -210,6 +211,7 @@ static void run_ordered_work(struct __btrfs_workqueue *wq)
 */
if (test_and_set_bit(WORK_ORDER_DONE_BIT, &work->flags))
break;
+   trace_btrfs_ordered_sched(work);
spin_unlock_irqrestore(lock, flags);
work->ordered_func(work);
 
@@ -223,6 +225,7 @@ static void run_ordered_work(struct __btrfs_workqueue *wq)
 * with the lock held though
 */
work->ordered_free(work);
+   trace_btrfs_all_work_done(work);
}
spin_unlock_irqrestore(lock, flags);
 }
@@ -246,12 +249,15 @@ static void normal_work_helper(struct work_struct *arg)
need_order = 1;
wq = work->wq;
 
+   trace_btrfs_work_sched(work);
thresh_exec_hook(wq);
work->func(work);
if (need_order) {
set_bit(WORK_DONE_BIT, &work->flags);
run_ordered_work(wq);
}
+   if (!need_order)
+   trace_btrfs_all_work_done(work);
 }
 
 void btrfs_init_work(struct btrfs_work *work,
@@ -280,6 +286,7 @@ static inline void __btrfs_queue_work(struct 
__btrfs_workqueue *wq,
spin_unlock_irqrestore(&wq->list_lock, flags);
}
queue_work(wq->normal_wq, &work->normal_work);
+   trace_btrfs_work_queued(work);
 }
 
 void btrfs_queue_work(struct btrfs_workqueue *wq,
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index 3176cdc..c346919 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -21,6 +21,7 @@ struct btrfs_block_group_cache;
 struct btrfs_free_cluster;
 struct map_lookup;
 struct extent_buffer;
+struct btrfs_work;
 
 #define show_ref_type(type)\
__print_symbolic(type,  \
@@ -982,6 +983,87 @@ TRACE_EVENT(free_extent_state,
  (void *)__entry->ip)
 );
 
+DECLARE_EVENT_CLASS(btrfs__work,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work),
+
+   TP_STRUCT__entry(
+   __field(void *, work)
+   __field(void *, wq  )
+   __field(void *, func)
+   __field(void *, ordered_func)
+   __field(void *, ordered_free)
+   ),
+
+   TP_fast_assign(
+   __entry->work   = work;
+   __entry->wq = work->wq;
+   __entry->func   = work->func;
+   __entry->ordered_func   = work->ordered_func;
+   __entry->ordered_free   = work->ordered_free;
+   ),
+
+   TP_printk("work=%p, wq=%p, func=%p, ordered_func=%p, ordered_free=%p",
+ __entry->work, __entry->wq, __entry->func,
+ __entry->ordered_func, __entry->ordered_free)
+);
+
+/* For situiations that the work is freed */
+DECLARE_EVENT_CLASS(btrfs__work__done,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work),
+
+   TP_STRUCT__entry(
+   __field(void *, work)
+   ),
+
+   TP_fast_assign(
+   __entry->work   = work;
+   ),
+
+   TP_printk("work->%p", __entry->work)
+);
+
+DEFINE_EVENT(btrfs__work, btrfs_work_queued,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+DEFINE_EVENT(btrfs__work, btrfs_work_sched,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+DEFINE_EVENT(btrfs__work, btrfs_normal_work_done,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+DEFINE_EVENT(btrfs__work__done, btrfs_all_work_done,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+DEFINE_EVENT(btrfs__work, btrfs_ordered_sched,
+
+   TP_PROTO(struct btrfs_work *work),
+
+   TP_ARGS(work)
+);
+
+
 #endif /* _TRACE_BTRFS_H */
 
 /* This part must be outside protection */
-- 
1.9.0
--
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 1/2] btrfs: Cleanup the btrfs_workqueue related function type

2014-03-05 Thread quwen...@cn.fujitsu.com
The new btrfs_workqueue still use open-coded function defition,
this patch will change them into btrfs_func_t type which is much the
same as kernel workqueue.

Signed-off-by: Qu Wenruo 
---
 fs/btrfs/async-thread.c |  6 +++---
 fs/btrfs/async-thread.h | 20 +++-
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index a709585..d8c07e5 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -255,9 +255,9 @@ static void normal_work_helper(struct work_struct *arg)
 }
 
 void btrfs_init_work(struct btrfs_work *work,
-void (*func)(struct btrfs_work *),
-void (*ordered_func)(struct btrfs_work *),
-void (*ordered_free)(struct btrfs_work *))
+btrfs_func_t func,
+btrfs_func_t ordered_func,
+btrfs_func_t ordered_free)
 {
work->func = func;
work->ordered_func = ordered_func;
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index 08d7174..0a891cd 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -23,11 +23,13 @@
 struct btrfs_workqueue;
 /* Internal use only */
 struct __btrfs_workqueue;
+struct btrfs_work;
+typedef void (*btrfs_func_t)(struct btrfs_work *arg);
 
 struct btrfs_work {
-   void (*func)(struct btrfs_work *arg);
-   void (*ordered_func)(struct btrfs_work *arg);
-   void (*ordered_free)(struct btrfs_work *arg);
+   btrfs_func_t func;
+   btrfs_func_t ordered_func;
+   btrfs_func_t ordered_free;
 
/* Don't touch things below */
struct work_struct normal_work;
@@ -37,13 +39,13 @@ struct btrfs_work {
 };
 
 struct btrfs_workqueue *btrfs_alloc_workqueue(char *name,
-int flags,
-int max_active,
-int thresh);
+ int flags,
+ int max_active,
+ int thresh);
 void btrfs_init_work(struct btrfs_work *work,
-void (*func)(struct btrfs_work *),
-void (*ordered_func)(struct btrfs_work *),
-void (*ordered_free)(struct btrfs_work *));
+btrfs_func_t func,
+btrfs_func_t ordered_func,
+btrfs_func_t ordered_free);
 void btrfs_queue_work(struct btrfs_workqueue *wq,
  struct btrfs_work *work);
 void btrfs_destroy_workqueue(struct btrfs_workqueue *wq);
-- 
1.9.0
--
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: Kernel BUG: btrfs send - Incremental backup

2014-03-09 Thread quwen...@cn.fujitsu.com
On Sat, 8 Mar 2014 08:35:17 +0100, Swâmi Petaramesh wrote:
> Hi there,
>
> I tried to perform an incremental backup as described in
> https://btrfs.wiki.kernel.org/index.php/Incremental_Backup  between 2 external
> USB drives,
>
> The 1st "btrfs send foo/snap1 | btrfs receive bar" went well, although it took
> 5-6 times the time the same workload takes in ZFS.
>
> Then "btrfs send -v -p foo/snap1 foo/snap2 | btrfs receive bar" crashed on me.
>
> After a reboot and retry, I get a KERNEL BUG again :
>
>
> # uname -a
> Linux tethys 3.13.5-1-ARCH #1 SMP PREEMPT Sun Feb 23 00:25:24 CET 2014 x86_64
> GNU/Linux
>
> btrfs send -v -p foo/snap1 foo/snap2 | btrfs receive bar
>
>
> mars 08 08:22:01 tethys kernel: [ cut here ]
> mars 08 08:22:01 tethys kernel: kernel BUG at fs/btrfs/send.c:4398!
> mars 08 08:22:02 tethys kernel: invalid opcode:  [#1] PREEMPT SMP
> mars 08 08:22:02 tethys kernel: Modules linked in: usb_storage md5 fuse ecb
> ecryptfs encrypted_keys hmac trusted tpm ctr ccm intel_rapl
> x86_pkg_temp_thermal rts5139(C)
> mars 08 08:22:02 tethys kernel:  usbhid hid sr_mod cdrom sd_mod atkbd libps2
> crct10dif_pclmul crct10dif_common crc32_pclmul ahci crc32c_intel
> ghash_clmulni_intel libahc
> mars 08 08:22:02 tethys kernel: CPU: 0 PID: 2432 Comm: btrfs Tainted: P
> C O 3.13.5-1-ARCH #1
> mars 08 08:22:02 tethys kernel: Hardware name: TOSHIBA SATELLITE L735/Base
> Board Product Name, BIOS 2.50 06/26/2012
> mars 08 08:22:02 tethys kernel: task: 880041724800 ti: 88003b84a000
> task.ti: 88003b84a000
> mars 08 08:22:02 tethys kernel: RIP: 0010:[]  
> []
> changed_cb+0x9e5/0x9f0 [btrfs]
> mars 08 08:22:02 tethys kernel: RSP: 0018:88003b84bb48  EFLAGS: 00010283
> mars 08 08:22:02 tethys kernel: RAX: 000579d5 RBX: 88013279ea00 
> RCX:
> 0060
> mars 08 08:22:02 tethys kernel: RDX: 88003b84bc65 RSI: 000579cd 
> RDI:
> 88013279ea00
> mars 08 08:22:02 tethys kernel: RBP: 88003b84bbe0 R08: 88003b84bc65 
> R09:
> 0002
> mars 08 08:22:02 tethys kernel: R10: 88005981a900 R11:  
> R12:
> 0002
> mars 08 08:22:02 tethys kernel: R13: 88003b84bc65 R14: 88007c628800 
> R15:
> 2ad1
> mars 08 08:22:02 tethys kernel: FS:  7fceade62880()
> GS:88014f40() knlGS:
> mars 08 08:22:02 tethys kernel: CS:  0010 DS:  ES:  CR0:
> 80050033
> mars 08 08:22:02 tethys kernel: CR2: 7fb4cc8c8000 CR3: 41a99000
> CR4: 000407f0
> mars 08 08:22:02 tethys kernel: Stack:
> mars 08 08:22:02 tethys kernel:  88003b84bb88 a03206ec 
> 08ca
> 88005981a900
> mars 08 08:22:02 tethys kernel:   88005981a900
> 88005981a870 
> mars 08 08:22:02 tethys kernel:  88003b84bbe0 a03161e9 
> 88003b84bc76
> 88003b84bbe0
> mars 08 08:22:02 tethys kernel: Call Trace:
> mars 08 08:22:02 tethys kernel:  [] ?
> read_extent_buffer+0xbc/0x110 [btrfs]
> mars 08 08:22:02 tethys kernel:  [] ?
> btrfs_get_token_32+0x59/0xe0 [btrfs]
> mars 08 08:22:02 tethys kernel:  [] ?
> memcmp_extent_buffer+0xc1/0x120 [btrfs]
> mars 08 08:22:02 tethys kernel:  []
> btrfs_compare_trees+0x790/0x970 [btrfs]
> mars 08 08:22:02 tethys kernel:  [] ?
> finish_inode_if_needed+0x4e0/0x4e0 [btrfs]
> mars 08 08:22:02 tethys kernel:  [] 
> btrfs_ioctl_send+0x8a8/0xc80
> [btrfs]
> mars 08 08:22:02 tethys kernel:  [] btrfs_ioctl+0xfee/0x27a0
> [btrfs]
> mars 08 08:22:02 tethys kernel:  [] ? 
> __enqueue_entity+0x78/0x80
> mars 08 08:22:02 tethys kernel:  [] ? 
> enqueue_entity+0x29b/0xa10
> mars 08 08:22:02 tethys kernel:  [] ?
> enqueue_task_fair+0x107/0x540
> mars 08 08:22:02 tethys kernel:  [] ? enqueue_task+0x3a/0x60
> mars 08 08:22:02 tethys kernel:  [] ?
> check_preempt_curr+0x75/0xa0
> mars 08 08:22:02 tethys kernel:  [] do_vfs_ioctl+0x2e0/0x4c0
> mars 08 08:22:02 tethys kernel:  [] ? do_fork+0x12f/0x320
> mars 08 08:22:02 tethys kernel:  [] SyS_ioctl+0x81/0xa0
> mars 08 08:22:02 tethys kernel:  []
> system_call_fastpath+0x1a/0x1f
> mars 08 08:22:02 tethys kernel: Code: 48 8d 75 b6 45 31 c0 b9 01 00 00 00 4c
> 89 e2 4c 89 f7 e8 2f eb f7 ff 85 c0 0f 89 77 ff ff ff e9 a0 fd ff ff 31 c0 e9 
> 99 fd
> ff ff <
> mars 08 08:22:02 tethys kernel: RIP  [] 
> changed_cb+0x9e5/0x9f0
> [btrfs]
> mars 08 08:22:02 tethys kernel:  RSP 
> mars 08 08:22:02 tethys kernel: ---[ end trace 718b3fc11b4d9241 ]---
>
>
> HTH, TIA.
>
Hi,

Does the filesystem pass the btrfsck?
If not, would you please try btrfsck first?

Thanks.
QuN�r��yb�X��ǧv�^�)޺{.n�+{�n�߲)w*jg����ݢj/���z�ޖ��2�ޙ&�)ߡ�a�����G���h��j:+v���w��٥

Re: Kernel BUG: btrfs send - Incremental backup

2014-03-10 Thread quwen...@cn.fujitsu.com
On Mon, 10 Mar 2014 08:25:26 +0100, Swâmi Petaramesh wrote:
> Le lundi 10 mars 2014 02:16:01 vous avez écrit :
>> Does the filesystem pass the btrfsck?
>> If not, would you please try btrfsck first?
> It passes scrub with 0 errors... Do I need to bring it offline to pass btrfsck
> anyway ?
>
Better check it offline, since online check may not comprehensive than 
offline check.

Thanks.
Qu

Re: Building a brtfs filesystem < 70M?

2014-03-11 Thread quwen...@cn.fujitsu.com
On Tue, 11 Mar 2014 09:37:00 -0700, Zach Brown wrote:
>> There seems to be an issue if we try to build a btrfs based FS that
>> is less than 70M, we get the following assertion failure:
>>
>> mkfs.btrfs: extent-tree.c:2682: btrfs_reserve_extent: Assertion
>> `!(ret)' failed.
>> mkfs.btrfs -b 104857600 -r rootfs rootfs.btrfs
> Honestly, the path of least resistance is probably to avoid the -r
> option all together.  As you've found, it's not reliable.
>
> I'd take the time to roll the infrastrcture to populate the image by
> writing to a mounted image with the kernel code.
>
> - z
> --
> 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
>
I although agree with the mount + cp(kernel) way to populate the filesystem.
Also I think the implement of "-r" should be somewhat like mount+cp 
other than the current way,
since the userland implement is noticeably slow than kernel way.

Cc:Donggeun Kim
I also wonder why "-r" option is needed, since IMO the "-r" options is 
only needed
if the filesystem is full readonly and must be populated on 
initialization like squashfs.
And since btrfs is a filesystem that can be read and write,
the "-r" option is not somewhat needed.

So I prefer to remove the "-r" option.


Thanks
QuN�r��yb�X��ǧv�^�)޺{.n�+{�n�߲)w*jg����ݢj/���z�ޖ��2�ޙ&�)ߡ�a�����G���h��j:+v���w��٥

Re: [PATCH] Btrfs: add missing kfree in btrfs_destroy_workqueue

2014-03-11 Thread quwen...@cn.fujitsu.com
On Tue, 11 Mar 2014 14:31:44 +, Filipe David Borba Manana wrote:
> Signed-off-by: Filipe David Borba Manana 
> ---
>  fs/btrfs/async-thread.c |1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
> index 00623dd..66532b8 100644
> --- a/fs/btrfs/async-thread.c
> +++ b/fs/btrfs/async-thread.c
> @@ -315,6 +315,7 @@ void btrfs_destroy_workqueue(struct btrfs_workqueue *wq)
>   if (wq->high)
>   __btrfs_destroy_workqueue(wq->high);
>   __btrfs_destroy_workqueue(wq->normal);
> + kfree(wq);
>  }
>  
>  void btrfs_workqueue_set_max(struct btrfs_workqueue *wq, int max)
Thanks for finding out the missing kfree.
That's my fault

Qu.

[PATCH] btrfs: Add trace for btrfs_workqueue alloc/destroy

2014-03-12 Thread quwen...@cn.fujitsu.com
Since most of the btrfs_workqueue is printed as pointer address,
for easier analysis, add trace for btrfs_workqueue alloc/destroy.
So it is possible to determine the workqueue that a given work belongs
to(by comparing the wq pointer address with alloc trace event).

Signed-off-by: Qu Wenruo 
---
 fs/btrfs/async-thread.c  |  7 --
 fs/btrfs/async-thread.h  |  2 +-
 include/trace/events/btrfs.h | 55 
 3 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 00623dd..c74b910 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -56,7 +56,8 @@ struct btrfs_workqueue {
 };
 
 static inline struct __btrfs_workqueue
-*__btrfs_alloc_workqueue(char *name, int flags, int max_active, int thresh)
+*__btrfs_alloc_workqueue(const char *name, int flags, int max_active,
+int thresh)
 {
struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_NOFS);
 
@@ -92,13 +93,14 @@ static inline struct __btrfs_workqueue
INIT_LIST_HEAD(&ret->ordered_list);
spin_lock_init(&ret->list_lock);
spin_lock_init(&ret->thres_lock);
+   trace_btrfs_workqueue_alloc(ret, name, flags & WQ_HIGHPRI);
return ret;
 }
 
 static inline void
 __btrfs_destroy_workqueue(struct __btrfs_workqueue *wq);
 
-struct btrfs_workqueue *btrfs_alloc_workqueue(char *name,
+struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
  int flags,
  int max_active,
  int thresh)
@@ -305,6 +307,7 @@ static inline void
 __btrfs_destroy_workqueue(struct __btrfs_workqueue *wq)
 {
destroy_workqueue(wq->normal_wq);
+   trace_btrfs_workqueue_destroy(wq);
kfree(wq);
 }
 
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index 0a891cd..9c6b66d 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -38,7 +38,7 @@ struct btrfs_work {
unsigned long flags;
 };
 
-struct btrfs_workqueue *btrfs_alloc_workqueue(char *name,
+struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
  int flags,
  int max_active,
  int thresh);
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index c346919..4ee4e30 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -22,6 +22,7 @@ struct btrfs_free_cluster;
 struct map_lookup;
 struct extent_buffer;
 struct btrfs_work;
+struct __btrfs_workqueue;
 
 #define show_ref_type(type)\
__print_symbolic(type,  \
@@ -1063,6 +1064,60 @@ DEFINE_EVENT(btrfs__work, btrfs_ordered_sched,
TP_ARGS(work)
 );
 
+DECLARE_EVENT_CLASS(btrfs__workqueue,
+
+   TP_PROTO(struct __btrfs_workqueue *wq, const char *name, int high),
+
+   TP_ARGS(wq, name, high),
+
+   TP_STRUCT__entry(
+   __field(void *, wq  )
+   __string(   name,   name)
+   __field(int ,   high)
+   ),
+
+   TP_fast_assign(
+   __entry->wq = wq;
+   __assign_str(name, name);
+   __entry->high   = high;
+   ),
+
+   TP_printk("name=%s%s, wq=%p", __get_str(name),
+ __print_flags(__entry->high, "",
+   {(WQ_HIGHPRI),  "-high"}),
+ __entry->wq)
+);
+
+DEFINE_EVENT(btrfs__workqueue, btrfs_workqueue_alloc,
+
+   TP_PROTO(struct __btrfs_workqueue *wq, const char *name, int high),
+
+   TP_ARGS(wq, name, high)
+);
+
+DECLARE_EVENT_CLASS(btrfs__workqueue_done,
+
+   TP_PROTO(struct __btrfs_workqueue *wq),
+
+   TP_ARGS(wq),
+
+   TP_STRUCT__entry(
+   __field(void *, wq  )
+   ),
+
+   TP_fast_assign(
+   __entry->wq = wq;
+   ),
+
+   TP_printk("wq=%p", __entry->wq)
+);
+
+DEFINE_EVENT(btrfs__workqueue_done, btrfs_workqueue_destroy,
+
+   TP_PROTO(struct __btrfs_workqueue *wq),
+
+   TP_ARGS(wq)
+);
 
 #endif /* _TRACE_BTRFS_H */
 
-- 
1.9.0
--
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 2/2] btrfs-progs: Fix a memleak in btrfs_scan_lblkid().

2014-03-13 Thread quwen...@cn.fujitsu.com
In btrfs_scan_lblkid(), blkid_get_cache() is called but cache not freed.
This patch adds blkid_put_cache() to free it.

Signed-off-by: Qu Wenruo 
---
 utils.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/utils.c b/utils.c
index 93cf9ac..b809bc5 100644
--- a/utils.c
+++ b/utils.c
@@ -2067,6 +2067,7 @@ int btrfs_scan_lblkid(int update_kernel)
btrfs_register_one_device(path);
}
blkid_dev_iterate_end(iter);
+   blkid_put_cache(cache);
return 0;
 }
 
-- 
1.9.0
--
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 1/2] btrfs-progs: Fix a memleak in btrfs_scan_one_device.

2014-03-13 Thread quwen...@cn.fujitsu.com
Valgrind reports memleak in btrfs_scan_one_device() about allocating
btrfs_device but on btrfs_close_devices() they are not reclaimed.

Although not a bug since after btrfs_close_devices() btrfs will exit so
memory will be reclaimed by system anyway, it's better to fix it anyway.

Signed-off-by: Qu Wenruo 
---
 cmds-filesystem.c |  6 ++
 volumes.c | 13 ++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index f02e871..c9e27fc 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -651,6 +651,12 @@ devs_only:
if (search && !found)
ret = 1;
 
+   while (!list_empty(all_uuids)) {
+   fs_devices = list_entry(all_uuids->next,
+   struct btrfs_fs_devices, list);
+   list_del(&fs_devices->list);
+   btrfs_close_devices(fs_devices);
+   }
 out:
printf("%s\n", BTRFS_BUILD_VERSION);
free_seen_fsid();
diff --git a/volumes.c b/volumes.c
index 8c45851..77ffd32 100644
--- a/volumes.c
+++ b/volumes.c
@@ -160,11 +160,12 @@ static int device_list_add(const char *path,
 int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
 {
struct btrfs_fs_devices *seed_devices;
-   struct list_head *cur;
struct btrfs_device *device;
+
 again:
-   list_for_each(cur, &fs_devices->devices) {
-   device = list_entry(cur, struct btrfs_device, dev_list);
+   while (!list_empty(&fs_devices->devices)) {
+   device = list_entry(fs_devices->devices.next,
+   struct btrfs_device, dev_list);
if (device->fd != -1) {
fsync(device->fd);
if (posix_fadvise(device->fd, 0, 0, 
POSIX_FADV_DONTNEED))
@@ -173,6 +174,11 @@ again:
device->fd = -1;
}
device->writeable = 0;
+   list_del(&device->dev_list);
+   /* free the memory */
+   free(device->name);
+   free(device->label);
+   free(device);
}
 
seed_devices = fs_devices->seed;
@@ -182,6 +188,7 @@ again:
goto again;
}
 
+   free(fs_devices);
return 0;
 }
 
-- 
1.9.0
--
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 1/2] btrfs: Cleanup the btrfs_workqueue related function type

2014-03-15 Thread quwen...@cn.fujitsu.com
On Fri, 14 Mar 2014 15:39:03 +0100, David Sterba wrote:
> On Thu, Mar 06, 2014 at 04:19:50AM +0000, quwen...@cn.fujitsu.com wrote:
>> @@ -23,11 +23,13 @@
>>   struct btrfs_workqueue;
>>   /* Internal use only */
>>   struct __btrfs_workqueue;
>> +struct btrfs_work;
>> +typedef void (*btrfs_func_t)(struct btrfs_work *arg);
> I don't see what's wrong with the non-typedef type, CodingStyle
> discourages from using typedefs in general (Chapter 5).
>
> The name btrfs_func_t is a generic, if you really need to use a typedef
> here, please change it to something closer to the workqueues, eg.
> btrfs_work_func_t.
>
btrfs_func_t is just following the work_func_t naming style,
for btrfs it's only used to reduce the length of prototype definition.

Since btrfs_func_t is only used in btrfs, this patch can be ignored.

Thanks
Qu

[PATCH 3/3] btrfs-progs: Modify the help string to keep consistent with man page.

2014-03-18 Thread quwen...@cn.fujitsu.com
Help string of "btrfs dev scan" is inconsistent with man page,
which lacks the fact that -d|--all-device is conflict with .
This patch fixes the description

Signed-off-by: Qu Wenruo 
---
 cmds-device.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/cmds-device.c b/cmds-device.c
index 58a336f..a9b4a38 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -188,9 +188,8 @@ static int cmd_rm_dev(int argc, char **argv)
 }
 
 static const char * const cmd_scan_dev_usage[] = {
-   "btrfs device scan [options] [ [...]]",
+   "btrfs device scan [(-d|--all-devices)| [...]]",
"Scan devices for a btrfs filesystem",
-   "-d|--all-devicesscan all devices under /dev",
NULL
 };
 
-- 
1.9.0
--
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 1/3] btrfs-progs: Fix memleak in get_raid56_used()

2014-03-18 Thread quwen...@cn.fujitsu.com
Fix memleak in get_raid56_used().

Signed-off-by: Qu Wenruo 
---
 cmds-fi-disk_usage.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c
index a3b06be..2bd591d 100644
--- a/cmds-fi-disk_usage.c
+++ b/cmds-fi-disk_usage.c
@@ -352,6 +352,7 @@ static int get_raid56_used(int fd, u64 *raid5_used, u64 
*raid6_used)
if (p->type & BTRFS_BLOCK_GROUP_RAID6)
(*raid6_used) += p->size / (p->num_stripes -2);
}
+   free(info_ptr);
 
return 0;
 
-- 
1.9.0
--
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 2/3] btrfs-progs: Fix minor problems in man page of btrfs

2014-03-18 Thread quwen...@cn.fujitsu.com
Man page of btrfs has some minor problem like:
1. Duplicant entry for "filesystem df"
2. Inconsistent parameters
3. Non-paired parens
4. Missing options
5. Wrong parameters

This patch fixes these minor bug.
Signed-off-by: Qu Wenruo 
---
 man/btrfs.8.in | 184 -
 1 file changed, 102 insertions(+), 82 deletions(-)

diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 7fbde82..3846f19 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -23,9 +23,9 @@ btrfs \- control a btrfs filesystem
 \fBbtrfs\fP \fBsubvolume show\fP\fI \fP
 .PP
 .PP
-\fBbtrfs\fP \fBfilesystem df\fP\fI \fP
+\fBbtrfs\fP \fBfilesystem df\fP\fI [-b] \fIpath [path..]\fR\fP
 .PP
-\fBbtrfs\fP \fBfilesystem show\fP 
[\fI--mounted\fP|\fI--all-devices\fP|\fI\fP]\fP
+\fBbtrfs\fP \fBfilesystem show\fP 
[\fI--mounted\fP|\fI--all-devices\fP|\fI\fP|\fI\fP|\fI\fP|\fI\fP]\fP
 .PP
 \fBbtrfs\fP \fBfilesystem sync\fP\fI  \fP
 .PP
@@ -35,12 +35,11 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBfilesystem label\fP [\fI\fP|\fI\fP] 
[\fI\fP]
 .PP
-\fBbtrfs\fP \fBfilesystem filesystem disk-usage [-t][-b]\fP\fI  
+\fBbtrfs\fP \fBfilesystem disk-usage [-tb]\fP\fI  
 [path..]\fP
 .PP
-\fBbtrfs\fP \fBfilesystem df\fP\fI [-b] \fIpath [path..]\fR\fP
 .PP
-\fBbtrfs\fP \fBfilesystem balance\fP\fI  \fP
+\fBbtrfs\fP \fB[filesystem] balance\fP\fI  \fP
 .PP
 \fBbtrfs\fP \fB[filesystem] balance start\fP [\fIoptions\fP] \fI\fP
 .PP
@@ -57,11 +56,10 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBdevice delete\fP \fI\fP [\fI...\fP] \fI\fP
 .PP
-\fBbtrfs\fP \fBdevice scan\fP [\fI--all-devices\fP|\fI 
\P[\fI...\fP]
+\fBbtrfs\fP \fBdevice scan\fP [(\fI-d\fP|\fI--all-devices\fP)|\fI\fP 
[\fI...\fP]]
 .PP
 \fBbtrfs\fP \fBdevice disk-usage\fP\fI [-b]  [...] \fP
 .PP
-.PP
 \fBbtrfs\fP \fBdevice ready\fP\fI \fP
 .PP
 \fBbtrfs\fP \fBdevice stats\fP [-z] {\fI\fP|\fI\fP}
@@ -78,11 +76,11 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBcheck\fP [\fIoptions\fP] \fI\fP
 .PP
-\fBbtrfs\fP \fBrescue chunk-recover\fP [\fIoptions\fP] \fI\fP
+\fBbtrfs\fP \fBrescue chunk-recover\fP [\fIoptions\fP] \fI\fP
 .PP
-\fBbtrfs\fP \fBrescue super-recover\fP [\fIoptions\fP] \fI\fP
+\fBbtrfs\fP \fBrescue super-recover\fP [\fIoptions\fP] \fI\fP
 .PP
-\fBbtrfs\fP \fBrestore\fP [\fIoptions\fP] \fI\fP
+\fBbtrfs\fP \fBrestore\fP [\fIoptions\fP] \fI\fP \fI\fP | -l 
\fI\fP
 .PP
 .PP
 \fBbtrfs\fP \fBinspect-internal inode-resolve\fP [-v] \fI\fP 
\fI\fP
@@ -103,7 +101,7 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBquota disable\fP\fI \fP
 .PP
-\fBbtrfs\fP \fBquota rescan\fP [-s] \fI\fP
+\fBbtrfs\fP \fBquota rescan\fP [-sw] \fI\fP
 .PP
 .PP
 \fBbtrfs\fP \fBqgroup assign\fP \fI\fP \fI\fP \fI\fP
@@ -114,7 +112,7 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBqgroup destroy\fP \fI\fP \fI\fP
 .PP
-\fBbtrfs\fP \fBqgroup show\fP \fI\fP
+\fBbtrfs\fP \fBqgroup show\fP [\fIoptions\fP] \fI\fP
 .PP
 \fBbtrfs\fP \fBqgroup limit\fP [\fIoptions\fP] \fI\fP|\fBnone\fP 
[\fI\fP] \fI\fP
 .PP
@@ -286,12 +284,55 @@ List the recently modified files in a subvolume, after 
\fI\fR ID.
 Show information of a given subvolume in the \fI\fR.
 .TP
 
-\fBfilesystem df\fP\fI \fR
+\fBfilesystem df\fP [-b] \fIpath [path..]\fR
+
 Show space usage information for a mount point.
+
+\fB-b\fP Set byte as unit
+
+The command \fBbtrfs filesystem df\fP is used to query how many space on the 
+disk(s) are used and an estimation of the free
+space of the filesystem.
+The output of the command \fBbtrfs filesystem df\fP shows:
+
+.RS
+.IP \fBDisk\ size\fP
+the total size of the disks which compose the filesystem.
+
+.IP \fBDisk\ allocated\fP
+the size of the area of the disks used by the chunks.
+
+.IP \fBDisk\ unallocated\fP 
+the size of the area of the disks which is free (i.e.
+the differences of the values above).
+
+.IP \fBUsed\fP
+the portion of the logical space used by the file and metadata.
+
+.IP \fBFree\ (estimated)\fP
+the estimated free space available: i.e. how many space can be used
+by the user. The evaluation 
+cannot be rigorous because it depends by the allocation policy (DUP, Single,
+RAID1...) of the metadata and data chunks. If every chunk is stored as
+"Single" the sum of the \fBfree (estimated)\fP space and the \fBused\fP 
+space  is equal to the \fBdisk size\fP.
+Otherwise if all the chunk are mirrored (raid1 or raid10) or duplicated
+the sum of the \fBfree (estimated)\fP space and the \fBused\fP space is
+half of the \fBdisk size\fP. Normally the \fBfree (estimated)\fP is between
+these two limits.
+
+.IP \fBData\ to\ disk\ ratio\fP
+the ratio betwen the \fBlogical size\fP (i.e. the space available by
+the chunks) and the \fBdisk allocated\fP (by the chunks). Normally it is 
+lower than 100% because the metadata is duplicated for security reasons.
+If all the data and metadata are duplicated (or have a profile like RAID1)
+the \fBData\ to\ disk\ ratio\fP could be 50%.
+.RE
 .TP
 
-\fBfilesystem show\fR [\fI--mounted\fP|\

[PATCH] btrfs: Change the expanding write sequence to fix snapshot related bug.

2014-03-26 Thread quwen...@cn.fujitsu.com
When testing fsstress with snapshot making background, some snapshot
following problem.

Snapshot 270:
inode 323: size 0

Snapshot 271:
inode 323: size 349145
|---Hole---|-Empty gap---|---Hole-|
0   122880  172032349145

Snapshot 272:
inode 323: size 349145
|---Hole---|Data-|---Hole-|
0   122880  172032349145

The fsstress operation on inode 323 is the following:
write:  offset  126832  len 43124
truncate:   size349145

Since the write with offset is consist of 2 operations:
1. punch hole
2. write data
Hole punching is faster than data write, so hole punching in write
and truncate is done first and then buffered write, so the snapshot 271 got
empty gap, which will not pass btrfsck.

To fix the bug, this patch will change the write sequence which will
first punch a hole covering the write end if a hole is needed.

Reported-by: Gui Hecheng 
Signed-off-by: Qu Wenruo 
---
 fs/btrfs/file.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index b2143b8..f53f592 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1718,6 +1718,7 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
struct btrfs_root *root = BTRFS_I(inode)->root;
loff_t *ppos = &iocb->ki_pos;
u64 start_pos;
+   u64 end_pos;
ssize_t num_written = 0;
ssize_t err = 0;
size_t count, ocount;
@@ -1772,7 +1773,9 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
 
start_pos = round_down(pos, root->sectorsize);
if (start_pos > i_size_read(inode)) {
-   err = btrfs_cont_expand(inode, i_size_read(inode), start_pos);
+   /* Expand hole size to cover write data, preventing empty gap */
+   end_pos = round_up(pos + iov->iov_len, root->sectorsize);
+   err = btrfs_cont_expand(inode, i_size_read(inode), end_pos);
if (err) {
mutex_unlock(&inode->i_mutex);
goto out;
-- 
1.9.1
--
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