[PATCH v3 11/17] btrfs: Replace fs_info->cache_workers workqueue with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Replace the fs_info->cache_workers with the newly created
btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  - Use the btrfs_workqueue_struct to replace caching_workers.
---
 fs/btrfs/ctree.h   |  4 ++--
 fs/btrfs/disk-io.c | 12 ++--
 fs/btrfs/extent-tree.c |  6 +++---
 fs/btrfs/super.c   |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 89a5411..edc3097 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1199,7 +1199,7 @@ struct btrfs_caching_control {
struct list_head list;
struct mutex mutex;
wait_queue_head_t wait;
-   struct btrfs_work work;
+   struct btrfs_work_struct work;
struct btrfs_block_group_cache *block_group;
u64 progress;
atomic_t count;
@@ -1494,7 +1494,7 @@ struct btrfs_fs_info {
struct btrfs_workqueue_struct *endio_write_workers;
struct btrfs_workqueue_struct *endio_freespace_worker;
struct btrfs_workqueue_struct *submit_workers;
-   struct btrfs_workers caching_workers;
+   struct btrfs_workqueue_struct *caching_workers;
struct btrfs_workers readahead_workers;
 
/*
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index d6f5cf7..38b65d4 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2004,7 +2004,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info 
*fs_info)
btrfs_destroy_workqueue(fs_info->endio_freespace_worker);
btrfs_destroy_workqueue(fs_info->submit_workers);
btrfs_stop_workers(&fs_info->delayed_workers);
-   btrfs_stop_workers(&fs_info->caching_workers);
+   btrfs_destroy_workqueue(fs_info->caching_workers);
btrfs_stop_workers(&fs_info->readahead_workers);
btrfs_destroy_workqueue(fs_info->flush_workers);
btrfs_stop_workers(&fs_info->qgroup_rescan_workers);
@@ -2502,9 +2502,9 @@ int open_ctree(struct super_block *sb,
fs_devices->num_devices,
max_active), 64);
 
-   btrfs_init_workers(&fs_info->caching_workers, "cache",
-  fs_info->thread_pool_size, NULL);
-
+   fs_info->caching_workers = btrfs_alloc_workqueue("cache", NULL, NULL,
+flags, max_active,
+0);
 
btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1,
   &fs_info->generic_worker);
@@ -2551,7 +2551,6 @@ int open_ctree(struct super_block *sb,
ret = btrfs_start_workers(&fs_info->generic_worker);
ret |= btrfs_start_workers(&fs_info->fixup_workers);
ret |= btrfs_start_workers(&fs_info->delayed_workers);
-   ret |= btrfs_start_workers(&fs_info->caching_workers);
ret |= btrfs_start_workers(&fs_info->readahead_workers);
ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers);
if (ret) {
@@ -2563,7 +2562,8 @@ int open_ctree(struct super_block *sb,
  fs_info->endio_workers && fs_info->endio_meta_workers &&
  fs_info->endio_meta_write_workers &&
  fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
- fs_info->endio_freespace_worker && fs_info->rmw_workers)) {
+ fs_info->endio_freespace_worker && fs_info->rmw_workers &&
+ fs_info->caching_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d58bef1..143acf7 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -378,7 +378,7 @@ static u64 add_new_free_space(struct 
btrfs_block_group_cache *block_group,
return total_added;
 }
 
-static noinline void caching_thread(struct btrfs_work *work)
+static noinline void caching_thread(struct btrfs_work_struct *work)
 {
struct btrfs_block_group_cache *block_group;
struct btrfs_fs_info *fs_info;
@@ -548,7 +548,7 @@ static int cache_block_group(struct btrfs_block_group_cache 
*cache,
caching_ctl->block_group = cache;
caching_ctl->progress = cache->key.objectid;
atomic_set(&caching_ctl->count, 1);
-   caching_ctl->work.func = caching_thread;
+   btrfs_init_work(&caching_ctl->work, caching_thread, NULL, NULL);
 
spin_lock(&cache->lock);
/*
@@ -639,7 +639,7 @@ static int cache_block_group(struct btrfs_block_group_cache 
*cache,
 
btrfs_get_block_group(cache);
 
-   btrfs_queue_worker(&fs_info->caching_workers, &caching_ctl->work);
+   btrfs_queue_work(fs_info->caching_workers, &caching_ctl->work);
 
return ret;
 }
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index a8fc05d..e76c9d5 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1249,7 +1249,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info 

[PATCH v3 02/17] btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue

2013-11-06 Thread Qu Wenruo
Use kernel workqueue to implement a new btrfs_workqueue_struct, which
has the ordering execution feature like the btrfs_worker.

The func is executed in a concurrency way, and the
ordred_func/ordered_free is executed in the sequence them are queued
after the corresponding func is done.
The new btrfs_workqueue use 2 workqueues to implement the original
btrfs_worker, one for the normal work and one for ordered work.

At this patch, high priority work queue or thresholding is not added yet.
The high priority feature and thresholding will be added in the following 
patches.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None.
v2->v3:
  - Fix the potential deadline discovered by kernel lockdep.
  - Reuse the async-thread.[ch] files.
  - Make the ordered_func optional, which makes it adaptable to
all btrfS_workers.
---
 fs/btrfs/async-thread.c | 86 +
 fs/btrfs/async-thread.h | 44 +
 2 files changed, 130 insertions(+)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 08cc08f..00b4913 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2007 Oracle.  All rights reserved.
+ * Copyright (C) 2013 Fujitsu.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public
@@ -21,6 +22,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "async-thread.h"
 
 #define WORK_QUEUED_BIT 0
@@ -725,3 +728,86 @@ void btrfs_queue_worker(struct btrfs_workers *workers, 
struct btrfs_work *work)
wake_up_process(worker->task);
spin_unlock_irqrestore(&worker->lock, flags);
 }
+
+struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name,
+char *ordered_name,
+int flags,
+int max_active)
+{
+   struct btrfs_workqueue_struct *ret = kzalloc(sizeof(*ret), GFP_NOFS);
+   flags |= WQ_UNBOUND;
+   if (unlikely(!ret))
+   return NULL;
+   ret->normal_wq = alloc_workqueue(name, flags, max_active);
+   if (unlikely(!ret->normal_wq)) {
+   kfree(ret);
+   return NULL;
+   }
+
+   if (ordered_name) {
+   ret->ordered_wq = alloc_ordered_workqueue(ordered_name, flags);
+   if (unlikely(!ret->ordered_wq)) {
+   destroy_workqueue(ret->normal_wq);
+   kfree(ret);
+   return NULL;
+   }
+   }
+
+   spin_lock_init(&ret->insert_lock);
+   return ret;
+}
+
+static void normal_work_helper(struct work_struct *arg)
+{
+   struct btrfs_work_struct *work;
+   work = container_of(arg, struct btrfs_work_struct, normal_work);
+   work->func(work);
+   complete(&work->normal_completion);
+}
+
+static void ordered_work_helper(struct work_struct *arg)
+{
+   struct btrfs_work_struct *work;
+   work = container_of(arg, struct btrfs_work_struct, ordered_work);
+   wait_for_completion(&work->normal_completion);
+   work->ordered_func(work);
+   if (work->ordered_free)
+   work->ordered_free(work);
+}
+
+void btrfs_init_work(struct btrfs_work_struct *work,
+void (*func)(struct btrfs_work_struct *),
+void (*ordered_func)(struct btrfs_work_struct *),
+void (*ordered_free)(struct btrfs_work_struct *))
+{
+   work->func = func;
+   work->ordered_func = ordered_func;
+   work->ordered_free = ordered_free;
+   INIT_WORK(&work->normal_work, normal_work_helper);
+   if (work->ordered_func)
+   INIT_WORK(&work->ordered_work, ordered_work_helper);
+   init_completion(&work->normal_completion);
+}
+
+void btrfs_queue_work(struct btrfs_workqueue_struct *wq,
+ struct btrfs_work_struct *work)
+{
+   unsigned long flags;
+   spin_lock_irqsave(&wq->insert_lock, flags);
+   queue_work(wq->normal_wq, &work->normal_work);
+   if (wq->ordered_wq && work->ordered_func)
+   queue_work(wq->ordered_wq, &work->ordered_work);
+   spin_unlock_irqrestore(&wq->insert_lock, flags);
+}
+
+void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq)
+{
+   if (wq->ordered_wq)
+   destroy_workqueue(wq->ordered_wq);
+   destroy_workqueue(wq->normal_wq);
+}
+
+void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max)
+{
+   workqueue_set_max_active(wq->normal_wq, max);
+}
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index 1f26792..eee6709 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2007 Oracle.  All rights reserved.
+ * Copyright (C) 2013 Fujitsu.  All rights reserved.
  *
  * This program is fre

[PATCH v3 04/17] btrfs: Add threshold workqueue based on kernel workqueue

2013-11-06 Thread Qu Wenruo
The original btrfs_workers has thresholding functions to dynamically
create or destroy kthreads.

Though there is no such function in kernel workqueue because the worker
is not created manually, we can still use the workqueue_set_max_active
to simulated the behavior, mainly to achieve a better HDD performance by
setting a high threshold on submit_workers.
(Sadly, no resource can be saved)

So in this patch, extra workqueue pending counters are introduced to
dynamically change the max active of each btrfs_workqueue_struct, hoping
to restore the behavior of the original thresholding function.

Also, workqueue_set_max_active use a mutex to protect workqueue_struct,
which is not meant to be called too frequently, so a new interval
mechanism is applied, that will only call workqueue_set_max_active after
a count of work is queued. Hoping to balance both the random and
sequence performance on HDD.

Signed-off-by: Qu Wenruo 
---
Changelog:
v2->v3:
  - Add thresholding mechanism to simulate the old thresholding mechanism.
  - Will not enable thresholding when thresh is set to small value.
---
 fs/btrfs/async-thread.c | 131 
 fs/btrfs/async-thread.h |  24 -
 2 files changed, 144 insertions(+), 11 deletions(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 925aa6d..1fde6a2 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -31,6 +31,9 @@
 #define WORK_ORDER_DONE_BIT 2
 #define WORK_HIGH_PRIO_BIT 3
 
+#define NO_THRESHOLD (-1)
+#define DFT_THRESHOLD (32)
+
 /*
  * container for the kthread task pointer and the list of pending work
  * One of these is allocated per thread.
@@ -733,13 +736,31 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char 
*name,
 char *ordered_name,
 char *high_name,
 int flags,
-int max_active)
+int max_active,
+int thresh)
 {
struct btrfs_workqueue_struct *ret = kzalloc(sizeof(*ret), GFP_NOFS);
-   flags |= WQ_UNBOUND;
if (unlikely(!ret))
return NULL;
-   ret->normal_wq = alloc_workqueue(name, flags, max_active);
+
+   ret->max_active = max_active;
+   ret->pending = 0;
+   /* default threshold */
+   if (thresh == 0)
+   thresh = DFT_THRESHOLD;
+   /* for low threshold, no threshold is a better choice*/
+   if (thresh < DFT_THRESHOLD) {
+   ret->current_max = max_active;
+   ret->thresh = NO_THRESHOLD;
+   } else {
+   ret->current_max = 1;
+   ret->thresh = thresh;
+   }
+   flags |= WQ_UNBOUND;
+
+   /* The max_active of workqueue will change betwen [1,max_active],
+* or just normal workqueue if NO_THRESHOLD is set*/
+   ret->normal_wq = alloc_workqueue(name, flags, ret->current_max);
if (unlikely(!ret->normal_wq)) {
kfree(ret);
return NULL;
@@ -757,7 +778,7 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char 
*name,
if (high_name) {
ret->high_wq = alloc_workqueue(high_name,
   flags | WQ_HIGHPRI,
-  max_active);
+  ret->current_max);
if (unlikely(!ret->high_wq)) {
destroy_workqueue(ret->normal_wq);
if (ret->ordered_wq)
@@ -767,16 +788,101 @@ struct btrfs_workqueue_struct 
*btrfs_alloc_workqueue(char *name,
}
}
 
+   spin_lock_init(&ret->thresh_lock);
spin_lock_init(&ret->insert_lock);
return ret;
 }
 
+/*
+ * Hook for threshold which will be called in btrfs_queue_work.
+ * This hook WILL be called in IRQ context,
+ * so workqueue_set_max_active MUST NOT be called in this hook
+ */
+static inline void thresh_queue_hook(struct btrfs_workqueue_struct *wq)
+{
+   unsigned long flags;
+   /* Skip if no threshold is set */
+   if (wq->thresh == NO_THRESHOLD)
+   return;
+   /* Since the hook may be executed in IRQ handle, we need to
+* disable the IRQ */
+   spin_lock_irqsave(&wq->thresh_lock, flags);
+   wq->pending++;
+   spin_unlock_irqrestore(&wq->thresh_lock, flags);
+}
+
+/*
+ * Hook for threshold which will be called before executing the work,
+ * This hook is called in kthread content.
+ * So workqueue_set_max_active is called here.
+ */
+static inline void thresh_exec_hook(struct btrfs_workqueue_struct *wq)
+{
+   int new_max_active;
+   int need_change = 0;
+   unsigned long flags;
+
+   /* Skip if no threshold is set */
+   if (wq->thresh == NO_THRESHOL

[PATCH v3 07/17] btrfs: Replace fs_info->submit_workers with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Much like the fs_info->workers, replace the fs_info->submit_workers
use the same btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  None
---
 fs/btrfs/ctree.h   |  2 +-
 fs/btrfs/disk-io.c | 22 +++---
 fs/btrfs/super.c   |  2 +-
 fs/btrfs/volumes.c | 11 ++-
 fs/btrfs/volumes.h |  2 +-
 5 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index f38285e..3edb9e6 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1493,7 +1493,7 @@ struct btrfs_fs_info {
struct btrfs_workers endio_meta_write_workers;
struct btrfs_workers endio_write_workers;
struct btrfs_workers endio_freespace_worker;
-   struct btrfs_workers submit_workers;
+   struct btrfs_workqueue_struct *submit_workers;
struct btrfs_workers caching_workers;
struct btrfs_workers readahead_workers;
 
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index ed2eb52..ec474c8 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2003,7 +2003,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info 
*fs_info)
btrfs_stop_workers(&fs_info->endio_meta_write_workers);
btrfs_stop_workers(&fs_info->endio_write_workers);
btrfs_stop_workers(&fs_info->endio_freespace_worker);
-   btrfs_stop_workers(&fs_info->submit_workers);
+   btrfs_destroy_workqueue(fs_info->submit_workers);
btrfs_stop_workers(&fs_info->delayed_workers);
btrfs_stop_workers(&fs_info->caching_workers);
btrfs_stop_workers(&fs_info->readahead_workers);
@@ -2493,18 +2493,18 @@ int open_ctree(struct super_block *sb,
btrfs_init_workers(&fs_info->flush_workers, "flush_delalloc",
   fs_info->thread_pool_size, NULL);
 
-   btrfs_init_workers(&fs_info->submit_workers, "submit",
-  min_t(u64, fs_devices->num_devices,
-  fs_info->thread_pool_size), NULL);
-
-   btrfs_init_workers(&fs_info->caching_workers, "cache",
-  fs_info->thread_pool_size, NULL);
-
/* a higher idle thresh on the submit workers makes it much more
 * likely that bios will be send down in a sane order to the
 * devices
 */
-   fs_info->submit_workers.idle_thresh = 64;
+   fs_info->submit_workers = btrfs_alloc_workqueue("submit", NULL, NULL,
+   flags, min_t(u64,
+   fs_devices->num_devices,
+   max_active), 64);
+
+   btrfs_init_workers(&fs_info->caching_workers, "cache",
+  fs_info->thread_pool_size, NULL);
+
 
btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1,
   &fs_info->generic_worker);
@@ -2555,7 +2555,6 @@ int open_ctree(struct super_block *sb,
 * return -ENOMEM if any of these fail.
 */
ret = btrfs_start_workers(&fs_info->generic_worker);
-   ret |= btrfs_start_workers(&fs_info->submit_workers);
ret |= btrfs_start_workers(&fs_info->fixup_workers);
ret |= btrfs_start_workers(&fs_info->endio_workers);
ret |= btrfs_start_workers(&fs_info->endio_meta_workers);
@@ -2573,7 +2572,8 @@ int open_ctree(struct super_block *sb,
err = -ENOMEM;
goto fail_sb_buffer;
}
-   if (!(fs_info->workers && fs_info->delalloc_workers)) {
+   if (!(fs_info->workers && fs_info->delalloc_workers &&
+ fs_info->submit_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 6f0d206..4c5b4f2 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1248,7 +1248,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info 
*fs_info,
btrfs_set_max_workers(&fs_info->generic_worker, new_pool_size);
btrfs_workqueue_set_max(fs_info->workers, new_pool_size);
btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size);
-   btrfs_set_max_workers(&fs_info->submit_workers, new_pool_size);
+   btrfs_workqueue_set_max(fs_info->submit_workers, new_pool_size);
btrfs_set_max_workers(&fs_info->caching_workers, new_pool_size);
btrfs_set_max_workers(&fs_info->fixup_workers, new_pool_size);
btrfs_set_max_workers(&fs_info->endio_workers, new_pool_size);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1bd573d..321a687 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -416,7 +416,8 @@ loop_lock:
device->running_pending = 1;
 
spin_unlock(&device->io_lock);
-   btrfs_requeue_work(&device->work);
+   btrfs_queue_work(fs_info->submit_workers,
+&device->work);
goto done;
 

[PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct

2013-11-06 Thread Qu Wenruo
Add a new btrfs_workqueue_struct which use kernel workqueue to implement
most of the original btrfs_workers, to replace btrfs_workers.

With this patchset, redundant workqueue codes are replaced with kernel
workqueue infrastructure, which not only reduces the code size but also the
effort to maintain it.

More performace tests are ongoing, the result from sysbench shows minor
improvement on the following server:
CPU: two-way Xeon X5660
RAM: 4G 
HDD: SAS HDD, 150G total, 40G partition for btrfs test

Test result:
Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel
rndrd   1   4K  none+1.22%
rndrd   1   32K none+1.00%
rndrd   8   32K sync+1.35%
seqrd   8   4K  direct  +5.56%
seqwr   8   4K  none-1.26%
seqwr   8   32K sync+1.20%

Changes below 1% are not mentioned.
Overall the patchset doesn't change the performance on HDD.

Since more tests are needed, more test result are welcomed.

--
Changelog:
v1->v2:
  - Fix some workqueue flags.
v2->v3:
  - Add the thresholding mechanism to simulate the old behavior
  - Convert all the btrfs_workers to btrfs_workrqueue_struct.
  - Fix some potential deadlock when executed in IRQ handler.
--

Qu Wenruo (17):
  btrfs: Cleanup the unused struct async_sched.
  btrfs: Added btrfs_workqueue_struct implemented ordered execution
based on kernel workqueue
  btrfs: Add high priority workqueue support for btrfs_workqueue_struct
  btrfs: Add threshold workqueue based on kernel workqueue
  btrfs: Replace fs_info->workers with btrfs_workqueue.
  btrfs: Replace fs_info->delalloc_workers with btrfs_workqueue
  btrfs: Replace fs_info->submit_workers with btrfs_workqueue.
  btrfs: Replace fs_info->flush_workers with btrfs_workqueue.
  btrfs: Replace fs_info->endio_* workqueue with btrfs_workqueue.
  btrfs: Replace fs_info->rmw_workers workqueue with btrfs_workqueue.
  btrfs: Replace fs_info->cache_workers workqueue with btrfs_workqueue.
  btrfs: Replace fs_info->readahead_workers workqueue with
btrfs_workqueue.
  btrfs: Replace fs_info->fixup_workers workqueue with btrfs_workqueue.
  btrfs: Replace fs_info->delayed_workers workqueue with
btrfs_workqueue.
  btrfs: Replace fs_info->qgroup_rescan_worker workqueue with
btrfs_workqueue.
  btrfs: Replace fs_info->scrub_* workqueue with btrfs_workqueue.
  btrfs: Cleanup the old btrfs_worker.

 fs/btrfs/async-thread.c  | 821 ++-
 fs/btrfs/async-thread.h  | 152 -
 fs/btrfs/ctree.h |  45 ++-
 fs/btrfs/delayed-inode.c |  10 +-
 fs/btrfs/disk-io.c   | 238 ++
 fs/btrfs/extent-tree.c   |   6 +-
 fs/btrfs/inode.c |  53 ++-
 fs/btrfs/ordered-data.c  |  13 +-
 fs/btrfs/ordered-data.h  |   4 +-
 fs/btrfs/qgroup.c|  17 +-
 fs/btrfs/raid56.c|  33 +-
 fs/btrfs/reada.c |  10 +-
 fs/btrfs/scrub.c |  94 +++---
 fs/btrfs/super.c |  36 +--
 fs/btrfs/volumes.c   |  18 +-
 fs/btrfs/volumes.h   |   2 +-
 16 files changed, 503 insertions(+), 1049 deletions(-)

-- 
1.8.4.2

--
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 v3 12/17] btrfs: Replace fs_info->readahead_workers workqueue with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Replace the fs_info->readahead_workers with the newly created
btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  - Use the btrfs_workqueue_struct to replace readahead_workers.
---
 fs/btrfs/ctree.h   |  2 +-
 fs/btrfs/disk-io.c | 12 +---
 fs/btrfs/reada.c   | 10 +-
 fs/btrfs/super.c   |  2 +-
 4 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index edc3097..29fb7a6 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1495,7 +1495,7 @@ struct btrfs_fs_info {
struct btrfs_workqueue_struct *endio_freespace_worker;
struct btrfs_workqueue_struct *submit_workers;
struct btrfs_workqueue_struct *caching_workers;
-   struct btrfs_workers readahead_workers;
+   struct btrfs_workqueue_struct *readahead_workers;
 
/*
 * fixup workers take dirty pages that didn't properly go through
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 38b65d4..fe3a8be 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2005,7 +2005,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info 
*fs_info)
btrfs_destroy_workqueue(fs_info->submit_workers);
btrfs_stop_workers(&fs_info->delayed_workers);
btrfs_destroy_workqueue(fs_info->caching_workers);
-   btrfs_stop_workers(&fs_info->readahead_workers);
+   btrfs_destroy_workqueue(fs_info->readahead_workers);
btrfs_destroy_workqueue(fs_info->flush_workers);
btrfs_stop_workers(&fs_info->qgroup_rescan_workers);
 }
@@ -2536,13 +2536,12 @@ int open_ctree(struct super_block *sb,
btrfs_init_workers(&fs_info->delayed_workers, "delayed-meta",
   fs_info->thread_pool_size,
   &fs_info->generic_worker);
-   btrfs_init_workers(&fs_info->readahead_workers, "readahead",
-  fs_info->thread_pool_size,
-  &fs_info->generic_worker);
+   fs_info->readahead_workers = btrfs_alloc_workqueue("readahead", NULL,
+  NULL, flags,
+  max_active, 2);
btrfs_init_workers(&fs_info->qgroup_rescan_workers, "qgroup-rescan", 1,
   &fs_info->generic_worker);
 
-   fs_info->readahead_workers.idle_thresh = 2;
 
/*
 * btrfs_start_workers can really only fail because of ENOMEM so just
@@ -2551,7 +2550,6 @@ int open_ctree(struct super_block *sb,
ret = btrfs_start_workers(&fs_info->generic_worker);
ret |= btrfs_start_workers(&fs_info->fixup_workers);
ret |= btrfs_start_workers(&fs_info->delayed_workers);
-   ret |= btrfs_start_workers(&fs_info->readahead_workers);
ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers);
if (ret) {
err = -ENOMEM;
@@ -2563,7 +2561,7 @@ int open_ctree(struct super_block *sb,
  fs_info->endio_meta_write_workers &&
  fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
  fs_info->endio_freespace_worker && fs_info->rmw_workers &&
- fs_info->caching_workers)) {
+ fs_info->caching_workers && fs_info->readahead_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index 1031b69..66b6fbe 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -91,8 +91,8 @@ struct reada_zone {
 };
 
 struct reada_machine_work {
-   struct btrfs_work   work;
-   struct btrfs_fs_info*fs_info;
+   struct btrfs_work_structwork;
+   struct btrfs_fs_info*fs_info;
 };
 
 static void reada_extent_put(struct btrfs_fs_info *, struct reada_extent *);
@@ -732,7 +732,7 @@ static int reada_start_machine_dev(struct btrfs_fs_info 
*fs_info,
 
 }
 
-static void reada_start_machine_worker(struct btrfs_work *work)
+static void reada_start_machine_worker(struct btrfs_work_struct *work)
 {
struct reada_machine_work *rmw;
struct btrfs_fs_info *fs_info;
@@ -792,10 +792,10 @@ static void reada_start_machine(struct btrfs_fs_info 
*fs_info)
/* FIXME we cannot handle this properly right now */
BUG();
}
-   rmw->work.func = reada_start_machine_worker;
+   btrfs_init_work(&rmw->work, reada_start_machine_worker, NULL, NULL);
rmw->fs_info = fs_info;
 
-   btrfs_queue_worker(&fs_info->readahead_workers, &rmw->work);
+   btrfs_queue_work(fs_info->readahead_workers, &rmw->work);
 }
 
 #ifdef DEBUG
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index e76c9d5..8e26ec5 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1258,7 +1258,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info 
*fs_info,
btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size);
btrfs_workqueue_set_max(fs_info->endio_frees

[PATCH v3 10/17] btrfs: Replace fs_info->rmw_workers workqueue with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Replace the fs_info->rmw_workers with the newly created
btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  - Use the btrfs_workqueue_struct to replace rmw_workers.
---
 fs/btrfs/ctree.h   |  2 +-
 fs/btrfs/disk-io.c | 12 
 fs/btrfs/raid56.c  | 33 +++--
 3 files changed, 20 insertions(+), 27 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index e8916e3..89a5411 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1489,7 +1489,7 @@ struct btrfs_fs_info {
struct btrfs_workqueue_struct *endio_workers;
struct btrfs_workqueue_struct *endio_meta_workers;
struct btrfs_workqueue_struct *endio_raid56_workers;
-   struct btrfs_workers rmw_workers;
+   struct btrfs_workqueue_struct *rmw_workers;
struct btrfs_workqueue_struct *endio_meta_write_workers;
struct btrfs_workqueue_struct *endio_write_workers;
struct btrfs_workqueue_struct *endio_freespace_worker;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 7099001..d6f5cf7 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1998,7 +1998,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info 
*fs_info)
btrfs_destroy_workqueue(fs_info->endio_workers);
btrfs_destroy_workqueue(fs_info->endio_meta_workers);
btrfs_destroy_workqueue(fs_info->endio_raid56_workers);
-   btrfs_stop_workers(&fs_info->rmw_workers);
+   btrfs_destroy_workqueue(fs_info->rmw_workers);
btrfs_destroy_workqueue(fs_info->endio_meta_write_workers);
btrfs_destroy_workqueue(fs_info->endio_write_workers);
btrfs_destroy_workqueue(fs_info->endio_freespace_worker);
@@ -2524,9 +2524,8 @@ int open_ctree(struct super_block *sb,
  NULL, NULL,
  flags,
  max_active, 4);
-   btrfs_init_workers(&fs_info->rmw_workers,
-  "rmw", fs_info->thread_pool_size,
-  &fs_info->generic_worker);
+   fs_info->rmw_workers = btrfs_alloc_workqueue("rmw", NULL, NULL, flags,
+max_active, 2);
fs_info->endio_write_workers = btrfs_alloc_workqueue("endio-write",
 NULL, NULL,
 flags,
@@ -2543,8 +2542,6 @@ int open_ctree(struct super_block *sb,
btrfs_init_workers(&fs_info->qgroup_rescan_workers, "qgroup-rescan", 1,
   &fs_info->generic_worker);
 
-   fs_info->rmw_workers.idle_thresh = 2;
-
fs_info->readahead_workers.idle_thresh = 2;
 
/*
@@ -2553,7 +2550,6 @@ int open_ctree(struct super_block *sb,
 */
ret = btrfs_start_workers(&fs_info->generic_worker);
ret |= btrfs_start_workers(&fs_info->fixup_workers);
-   ret |= btrfs_start_workers(&fs_info->rmw_workers);
ret |= btrfs_start_workers(&fs_info->delayed_workers);
ret |= btrfs_start_workers(&fs_info->caching_workers);
ret |= btrfs_start_workers(&fs_info->readahead_workers);
@@ -2567,7 +2563,7 @@ int open_ctree(struct super_block *sb,
  fs_info->endio_workers && fs_info->endio_meta_workers &&
  fs_info->endio_meta_write_workers &&
  fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
- fs_info->endio_freespace_worker)) {
+ fs_info->endio_freespace_worker && fs_info->rmw_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index d0ecfbd..c1c68cc 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -88,7 +88,7 @@ struct btrfs_raid_bio {
/*
 * for scheduling work in the helper threads
 */
-   struct btrfs_work work;
+   struct btrfs_work_struct work;
 
/*
 * bio list and bio_list_lock are used
@@ -167,8 +167,8 @@ struct btrfs_raid_bio {
 
 static int __raid56_parity_recover(struct btrfs_raid_bio *rbio);
 static noinline void finish_rmw(struct btrfs_raid_bio *rbio);
-static void rmw_work(struct btrfs_work *work);
-static void read_rebuild_work(struct btrfs_work *work);
+static void rmw_work(struct btrfs_work_struct *work);
+static void read_rebuild_work(struct btrfs_work_struct *work);
 static void async_rmw_stripe(struct btrfs_raid_bio *rbio);
 static void async_read_rebuild(struct btrfs_raid_bio *rbio);
 static int fail_bio_stripe(struct btrfs_raid_bio *rbio, struct bio *bio);
@@ -1417,19 +1417,17 @@ cleanup:
 
 static void async_rmw_stripe(struct btrfs_raid_bio *rbio)
 {
-   rbio->work.flags = 0;
-   rbio->work.func = rmw_work;
+   btrfs_init_work(&rbio->work, rmw_work, NULL, NULL);
 
-   btrfs_queue_worker(&rbio->fs_info->rmw_workers,

[PATCH v3 14/17] btrfs: Replace fs_info->delayed_workers workqueue with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Replace the fs_info->delayed_workers with the newly created
btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  None
---
 fs/btrfs/ctree.h |  2 +-
 fs/btrfs/delayed-inode.c | 10 +-
 fs/btrfs/disk-io.c   | 11 +--
 fs/btrfs/super.c |  2 +-
 4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index a01b399..3493010 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1503,7 +1503,7 @@ struct btrfs_fs_info {
 * for the sys_munmap function call path
 */
struct btrfs_workqueue_struct *fixup_workers;
-   struct btrfs_workers delayed_workers;
+   struct btrfs_workqueue_struct *delayed_workers;
struct task_struct *transaction_kthread;
struct task_struct *cleaner_kthread;
int thread_pool_size;
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index cbd9523..76589ad 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1259,10 +1259,10 @@ void btrfs_remove_delayed_node(struct inode *inode)
 struct btrfs_async_delayed_work {
struct btrfs_delayed_root *delayed_root;
int nr;
-   struct btrfs_work work;
+   struct btrfs_work_struct  work;
 };
 
-static void btrfs_async_run_delayed_root(struct btrfs_work *work)
+static void btrfs_async_run_delayed_root(struct btrfs_work_struct *work)
 {
struct btrfs_async_delayed_work *async_work;
struct btrfs_delayed_root *delayed_root;
@@ -1360,11 +1360,11 @@ static int btrfs_wq_run_delayed_node(struct 
btrfs_delayed_root *delayed_root,
return -ENOMEM;
 
async_work->delayed_root = delayed_root;
-   async_work->work.func = btrfs_async_run_delayed_root;
-   async_work->work.flags = 0;
+   btrfs_init_work(&async_work->work, btrfs_async_run_delayed_root,
+   NULL, NULL);
async_work->nr = nr;
 
-   btrfs_queue_worker(&root->fs_info->delayed_workers, &async_work->work);
+   btrfs_queue_work(root->fs_info->delayed_workers, &async_work->work);
return 0;
 }
 
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index ae8201c..4fc26d2 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2003,7 +2003,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info 
*fs_info)
btrfs_destroy_workqueue(fs_info->endio_write_workers);
btrfs_destroy_workqueue(fs_info->endio_freespace_worker);
btrfs_destroy_workqueue(fs_info->submit_workers);
-   btrfs_stop_workers(&fs_info->delayed_workers);
+   btrfs_destroy_workqueue(fs_info->delayed_workers);
btrfs_destroy_workqueue(fs_info->caching_workers);
btrfs_destroy_workqueue(fs_info->readahead_workers);
btrfs_destroy_workqueue(fs_info->flush_workers);
@@ -2533,9 +2533,9 @@ int open_ctree(struct super_block *sb,
fs_info->endio_freespace_worker =
btrfs_alloc_workqueue("freespace-write", NULL, NULL,
  flags, max_active, 0);
-   btrfs_init_workers(&fs_info->delayed_workers, "delayed-meta",
-  fs_info->thread_pool_size,
-  &fs_info->generic_worker);
+   fs_info->delayed_workers = btrfs_alloc_workqueue("delayed-meta",
+NULL, NULL, flags,
+max_active, 0);
fs_info->readahead_workers = btrfs_alloc_workqueue("readahead", NULL,
   NULL, flags,
   max_active, 2);
@@ -2548,7 +2548,6 @@ int open_ctree(struct super_block *sb,
 * return -ENOMEM if any of these fail.
 */
ret = btrfs_start_workers(&fs_info->generic_worker);
-   ret |= btrfs_start_workers(&fs_info->delayed_workers);
ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers);
if (ret) {
err = -ENOMEM;
@@ -2561,7 +2560,7 @@ int open_ctree(struct super_block *sb,
  fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
  fs_info->endio_freespace_worker && fs_info->rmw_workers &&
  fs_info->caching_workers && fs_info->readahead_workers &&
- fs_info->fixup_workers)) {
+ fs_info->fixup_workers && fs_info->delayed_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 841a72c..8940015 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1256,7 +1256,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info 
*fs_info,
new_pool_size);
btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size);
btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size);
-   btrfs_set_max_workers(&fs

[PATCH v3 08/17] btrfs: Replace fs_info->flush_workers with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Replace the fs_info->submit_workers with the newly created btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  - Use the btrfs_workqueue_struct to replace submit_workers.
---
 fs/btrfs/ctree.h|  4 ++--
 fs/btrfs/disk-io.c  | 10 +-
 fs/btrfs/inode.c|  7 ---
 fs/btrfs/ordered-data.c | 13 +++--
 fs/btrfs/ordered-data.h |  2 +-
 5 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 3edb9e6..c74f27e 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1485,7 +1485,7 @@ struct btrfs_fs_info {
struct btrfs_workers generic_worker;
struct btrfs_workqueue_struct *workers;
struct btrfs_workqueue_struct *delalloc_workers;
-   struct btrfs_workers flush_workers;
+   struct btrfs_workqueue_struct *flush_workers;
struct btrfs_workers endio_workers;
struct btrfs_workers endio_meta_workers;
struct btrfs_workers endio_raid56_workers;
@@ -3625,7 +3625,7 @@ struct btrfs_delalloc_work {
int delay_iput;
struct completion completion;
struct list_head list;
-   struct btrfs_work work;
+   struct btrfs_work_struct work;
 };
 
 struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index ec474c8..3e4adff 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2007,7 +2007,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info 
*fs_info)
btrfs_stop_workers(&fs_info->delayed_workers);
btrfs_stop_workers(&fs_info->caching_workers);
btrfs_stop_workers(&fs_info->readahead_workers);
-   btrfs_stop_workers(&fs_info->flush_workers);
+   btrfs_destroy_workqueue(fs_info->flush_workers);
btrfs_stop_workers(&fs_info->qgroup_rescan_workers);
 }
 
@@ -2490,8 +2490,9 @@ int open_ctree(struct super_block *sb,
  NULL, flags,
  max_active, 2);
 
-   btrfs_init_workers(&fs_info->flush_workers, "flush_delalloc",
-  fs_info->thread_pool_size, NULL);
+   fs_info->flush_workers = btrfs_alloc_workqueue("flush_delalloc",
+   NULL, NULL, flags,
+   max_active, 0);
 
/* a higher idle thresh on the submit workers makes it much more
 * likely that bios will be send down in a sane order to the
@@ -2566,14 +2567,13 @@ int open_ctree(struct super_block *sb,
ret |= btrfs_start_workers(&fs_info->delayed_workers);
ret |= btrfs_start_workers(&fs_info->caching_workers);
ret |= btrfs_start_workers(&fs_info->readahead_workers);
-   ret |= btrfs_start_workers(&fs_info->flush_workers);
ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers);
if (ret) {
err = -ENOMEM;
goto fail_sb_buffer;
}
if (!(fs_info->workers && fs_info->delalloc_workers &&
- fs_info->submit_workers)) {
+ fs_info->submit_workers && fs_info->flush_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 42e3f81..5e5fc7f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8138,7 +8138,7 @@ out_notrans:
return ret;
 }
 
-static void btrfs_run_delalloc_work(struct btrfs_work *work)
+static void btrfs_run_delalloc_work(struct btrfs_work_struct *work)
 {
struct btrfs_delalloc_work *delalloc_work;
 
@@ -8170,6 +8170,7 @@ struct btrfs_delalloc_work 
*btrfs_alloc_delalloc_work(struct inode *inode,
work->inode = inode;
work->wait = wait;
work->delay_iput = delay_iput;
+   btrfs_init_work(&work->work, btrfs_run_delalloc_work, NULL, NULL);
work->work.func = btrfs_run_delalloc_work;
 
return work;
@@ -8222,8 +8223,8 @@ static int __start_delalloc_inodes(struct btrfs_root 
*root, int delay_iput)
goto out;
}
list_add_tail(&work->list, &works);
-   btrfs_queue_worker(&root->fs_info->flush_workers,
-  &work->work);
+   btrfs_queue_work(root->fs_info->flush_workers,
+&work->work);
 
cond_resched();
spin_lock(&root->delalloc_lock);
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index c702cb6..08b30e5 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -550,7 +550,7 @@ void btrfs_remove_ordered_extent(struct inode *inode,
wake_up(&entry->wait);
 }
 
-static void btrfs_run_ordered_extent_work(struct btrfs_work *work)
+static void btrfs_run_ordered_extent_work(struct btrfs_work_struct *work)
 {
struct btrfs_ordered_extent *ordered;
 
@@ -582

[PATCH v3 05/17] btrfs: Replace fs_info->workers with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Use the newly created btrfs_workqueue_struct to replace the original
fs_info->workers

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  None
---
 fs/btrfs/ctree.h   |  2 +-
 fs/btrfs/disk-io.c | 41 +
 fs/btrfs/super.c   |  2 +-
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0506f40..dbc6e2d 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1483,7 +1483,7 @@ struct btrfs_fs_info {
 * two
 */
struct btrfs_workers generic_worker;
-   struct btrfs_workers workers;
+   struct btrfs_workqueue_struct *workers;
struct btrfs_workers delalloc_workers;
struct btrfs_workers flush_workers;
struct btrfs_workers endio_workers;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 62176ad..a467044 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -109,7 +109,7 @@ struct async_submit_bio {
 * can't tell us where in the file the bio should go
 */
u64 bio_offset;
-   struct btrfs_work work;
+   struct btrfs_work_struct work;
int error;
 };
 
@@ -749,12 +749,12 @@ int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, 
struct bio *bio,
 unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info)
 {
unsigned long limit = min_t(unsigned long,
-   info->workers.max_workers,
+   info->thread_pool_size,
info->fs_devices->open_devices);
return 256 * limit;
 }
 
-static void run_one_async_start(struct btrfs_work *work)
+static void run_one_async_start(struct btrfs_work_struct *work)
 {
struct async_submit_bio *async;
int ret;
@@ -767,7 +767,7 @@ static void run_one_async_start(struct btrfs_work *work)
async->error = ret;
 }
 
-static void run_one_async_done(struct btrfs_work *work)
+static void run_one_async_done(struct btrfs_work_struct *work)
 {
struct btrfs_fs_info *fs_info;
struct async_submit_bio *async;
@@ -794,7 +794,7 @@ static void run_one_async_done(struct btrfs_work *work)
   async->bio_offset);
 }
 
-static void run_one_async_free(struct btrfs_work *work)
+static void run_one_async_free(struct btrfs_work_struct *work)
 {
struct async_submit_bio *async;
 
@@ -822,11 +822,9 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, 
struct inode *inode,
async->submit_bio_start = submit_bio_start;
async->submit_bio_done = submit_bio_done;
 
-   async->work.func = run_one_async_start;
-   async->work.ordered_func = run_one_async_done;
-   async->work.ordered_free = run_one_async_free;
+   btrfs_init_work(&async->work, run_one_async_start,
+   run_one_async_done, run_one_async_free);
 
-   async->work.flags = 0;
async->bio_flags = bio_flags;
async->bio_offset = bio_offset;
 
@@ -835,9 +833,9 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, 
struct inode *inode,
atomic_inc(&fs_info->nr_async_submits);
 
if (rw & REQ_SYNC)
-   btrfs_set_work_high_prio(&async->work);
+   btrfs_set_work_high_priority(&async->work);
 
-   btrfs_queue_worker(&fs_info->workers, &async->work);
+   btrfs_queue_work(fs_info->workers, &async->work);
 
while (atomic_read(&fs_info->async_submit_draining) &&
  atomic_read(&fs_info->nr_async_submits)) {
@@ -1997,7 +1995,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info 
*fs_info)
btrfs_stop_workers(&fs_info->generic_worker);
btrfs_stop_workers(&fs_info->fixup_workers);
btrfs_stop_workers(&fs_info->delalloc_workers);
-   btrfs_stop_workers(&fs_info->workers);
+   btrfs_destroy_workqueue(fs_info->workers);
btrfs_stop_workers(&fs_info->endio_workers);
btrfs_stop_workers(&fs_info->endio_meta_workers);
btrfs_stop_workers(&fs_info->endio_raid56_workers);
@@ -2117,6 +2115,8 @@ int open_ctree(struct super_block *sb,
int err = -EINVAL;
int num_backups_tried = 0;
int backup_index = 0;
+   int max_active;
+   int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE;
bool create_uuid_tree;
bool check_uuid_tree;
 
@@ -2477,12 +2477,13 @@ int open_ctree(struct super_block *sb,
goto fail_alloc;
}
 
+   max_active = fs_info->thread_pool_size;
btrfs_init_workers(&fs_info->generic_worker,
   "genwork", 1, NULL);
 
-   btrfs_init_workers(&fs_info->workers, "worker",
-  fs_info->thread_pool_size,
-  &fs_info->generic_worker);
+   fs_info->workers = btrfs_alloc_workqueue("worker", "worker-ordered",
+"worker-high", flags,
+max_active, 16);
 

[PATCH v3 03/17] btrfs: Add high priority workqueue support for btrfs_workqueue_struct

2013-11-06 Thread Qu Wenruo
Add high priority workqueue, which added a new workqueue to
btrfs_workqueue_struct.

Whether using the high priority workqueue must be decided at
initialization.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  None
---
 fs/btrfs/async-thread.c | 25 -
 fs/btrfs/async-thread.h |  8 
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 00b4913..925aa6d 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -731,6 +731,7 @@ void btrfs_queue_worker(struct btrfs_workers *workers, 
struct btrfs_work *work)
 
 struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name,
 char *ordered_name,
+char *high_name,
 int flags,
 int max_active)
 {
@@ -753,6 +754,19 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char 
*name,
}
}
 
+   if (high_name) {
+   ret->high_wq = alloc_workqueue(high_name,
+  flags | WQ_HIGHPRI,
+  max_active);
+   if (unlikely(!ret->high_wq)) {
+   destroy_workqueue(ret->normal_wq);
+   if (ret->ordered_wq)
+   destroy_workqueue(ret->ordered_wq);
+   kfree(ret);
+   return NULL;
+   }
+   }
+
spin_lock_init(&ret->insert_lock);
return ret;
 }
@@ -793,8 +807,13 @@ void btrfs_queue_work(struct btrfs_workqueue_struct *wq,
  struct btrfs_work_struct *work)
 {
unsigned long flags;
+   struct workqueue_struct *dest_wq;
+   if (work->high && wq->high_wq)
+   dest_wq = wq->high_wq;
+   else
+   dest_wq = wq->normal_wq;
spin_lock_irqsave(&wq->insert_lock, flags);
-   queue_work(wq->normal_wq, &work->normal_work);
+   queue_work(dest_wq, &work->normal_work);
if (wq->ordered_wq && work->ordered_func)
queue_work(wq->ordered_wq, &work->ordered_work);
spin_unlock_irqrestore(&wq->insert_lock, flags);
@@ -804,10 +823,14 @@ void btrfs_destroy_workqueue(struct 
btrfs_workqueue_struct *wq)
 {
if (wq->ordered_wq)
destroy_workqueue(wq->ordered_wq);
+   if (wq->high_wq)
+   destroy_workqueue(wq->high_wq);
destroy_workqueue(wq->normal_wq);
 }
 
 void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max)
 {
workqueue_set_max_active(wq->normal_wq, max);
+   if (wq->high_wq)
+   workqueue_set_max_active(wq->high_wq, max);
 }
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index eee6709..4863c38 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -123,6 +123,7 @@ void btrfs_set_work_high_prio(struct btrfs_work *work);
 struct btrfs_workqueue_struct {
struct workqueue_struct *normal_wq;
struct workqueue_struct *ordered_wq;
+   struct workqueue_struct *high_wq;
 
/*
 * Spinlock to ensure that both ordered and normal work can
@@ -141,17 +142,20 @@ struct btrfs_work_struct {
struct work_struct normal_work;
struct work_struct ordered_work;
struct completion normal_completion;
+   int high;
 };
 
 /*
  * ordered_name is optional. If not given(NULL), the ordered
  * workqueue will not be allocated and the ordered excution will not
  * be available. The behavior will not be changed after init.
+ * The same rule is applied to high_name.
  *
  * flags will use the WQ_ flags, ORed with WQ_UNBOUND.
  * */
 struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name,
 char *ordered_name,
+char *high_name,
 int flags,
 int max_active);
 void btrfs_init_work(struct btrfs_work_struct *work,
@@ -162,4 +166,8 @@ void btrfs_queue_work(struct btrfs_workqueue_struct *wq,
  struct btrfs_work_struct *work);
 void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq);
 void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max);
+static inline void btrfs_set_work_high_priority(struct btrfs_work_struct *work)
+{
+   work->high = 1;
+}
 #endif
-- 
1.8.4.2

--
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 v3 16/17] btrfs: Replace fs_info->scrub_* workqueue with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Replace the fs_info->scrub_* with the newly created
btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  - Use the btrfs_workqueue_struct to replace scrub_*.
---
 fs/btrfs/ctree.h |  6 ++--
 fs/btrfs/scrub.c | 94 ++--
 fs/btrfs/super.c |  4 +--
 3 files changed, 56 insertions(+), 48 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 2e7e6a4..1da2f33 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1582,9 +1582,9 @@ struct btrfs_fs_info {
wait_queue_head_t scrub_pause_wait;
struct rw_semaphore scrub_super_lock;
int scrub_workers_refcnt;
-   struct btrfs_workers scrub_workers;
-   struct btrfs_workers scrub_wr_completion_workers;
-   struct btrfs_workers scrub_nocow_workers;
+   struct btrfs_workqueue_struct *scrub_workers;
+   struct btrfs_workqueue_struct *scrub_wr_completion_workers;
+   struct btrfs_workqueue_struct *scrub_nocow_workers;
 
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
u32 check_integrity_print_mask;
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index a18e0e2..e3cd62f 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -96,7 +96,8 @@ struct scrub_bio {
 #endif
int page_count;
int next_free;
-   struct btrfs_work   work;
+   struct btrfs_work_struct
+   work;
 };
 
 struct scrub_block {
@@ -154,7 +155,8 @@ struct scrub_fixup_nodatasum {
struct btrfs_device *dev;
u64 logical;
struct btrfs_root   *root;
-   struct btrfs_work   work;
+   struct btrfs_work_struct
+   work;
int mirror_num;
 };
 
@@ -172,7 +174,8 @@ struct scrub_copy_nocow_ctx {
int mirror_num;
u64 physical_for_dev_replace;
struct list_headinodes;
-   struct btrfs_work   work;
+   struct btrfs_work_struct
+   work;
 };
 
 struct scrub_warning {
@@ -232,7 +235,7 @@ static int scrub_pages(struct scrub_ctx *sctx, u64 logical, 
u64 len,
   u64 gen, int mirror_num, u8 *csum, int force,
   u64 physical_for_dev_replace);
 static void scrub_bio_end_io(struct bio *bio, int err);
-static void scrub_bio_end_io_worker(struct btrfs_work *work);
+static void scrub_bio_end_io_worker(struct btrfs_work_struct *work);
 static void scrub_block_complete(struct scrub_block *sblock);
 static void scrub_remap_extent(struct btrfs_fs_info *fs_info,
   u64 extent_logical, u64 extent_len,
@@ -249,14 +252,14 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx 
*sctx,
struct scrub_page *spage);
 static void scrub_wr_submit(struct scrub_ctx *sctx);
 static void scrub_wr_bio_end_io(struct bio *bio, int err);
-static void scrub_wr_bio_end_io_worker(struct btrfs_work *work);
+static void scrub_wr_bio_end_io_worker(struct btrfs_work_struct *work);
 static int write_page_nocow(struct scrub_ctx *sctx,
u64 physical_for_dev_replace, struct page *page);
 static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root,
  struct scrub_copy_nocow_ctx *ctx);
 static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
int mirror_num, u64 physical_for_dev_replace);
-static void copy_nocow_pages_worker(struct btrfs_work *work);
+static void copy_nocow_pages_worker(struct btrfs_work_struct *work);
 
 
 static void scrub_pending_bio_inc(struct scrub_ctx *sctx)
@@ -394,7 +397,8 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, 
int is_dev_replace)
sbio->index = i;
sbio->sctx = sctx;
sbio->page_count = 0;
-   sbio->work.func = scrub_bio_end_io_worker;
+   btrfs_init_work(&sbio->work, scrub_bio_end_io_worker,
+   NULL, NULL);
 
if (i != SCRUB_BIOS_PER_SCTX - 1)
sctx->bios[i]->next_free = i + 1;
@@ -699,7 +703,7 @@ out:
return -EIO;
 }
 
-static void scrub_fixup_nodatasum(struct btrfs_work *work)
+static void scrub_fixup_nodatasum(struct btrfs_work_struct *work)
 {
int ret;
struct scrub_fixup_nodatasum *fixup;
@@ -963,9 +967,10 @@ nodatasum_case:
fixup_nodatasum->root = fs_info->extent_root;
fixup_nodatasum->mirror_num = failed_mirror_index + 1;
scrub_pending_trans_workers_inc(sctx);
-   fixup_nodatasum->work.func = scrub_fixup_nodatasum;
-   btrfs_queue_worker(&fs_info->scrub_workers,
-  &fixup_nodatasum->work);
+   btrfs_init_work(&fixup_nodatasum->work, scrub_fixup_nodatasum,
+

[PATCH v3 01/17] btrfs: Cleanup the unused struct async_sched.

2013-11-06 Thread Qu Wenruo
The struct async_sched is not used by any codes and can be removed.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None.
v2->v3:
  None.
---
 fs/btrfs/volumes.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b0203b1..1bd573d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5316,13 +5316,6 @@ static void btrfs_end_bio(struct bio *bio, int err)
}
 }
 
-struct async_sched {
-   struct bio *bio;
-   int rw;
-   struct btrfs_fs_info *info;
-   struct btrfs_work work;
-};
-
 /*
  * see run_scheduled_bios for a description of why bios are collected for
  * async submit.
-- 
1.8.4.2

--
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 v3 09/17] btrfs: Replace fs_info->endio_* workqueue with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Replace the fs_info->endio_* workqueues with the newly created
btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  - Use the btrfs_workqueue_struct to replace endio_*.
---
 fs/btrfs/ctree.h|  12 +++---
 fs/btrfs/disk-io.c  | 110 +++-
 fs/btrfs/inode.c|  20 -
 fs/btrfs/ordered-data.h |   2 +-
 fs/btrfs/super.c|  11 ++---
 5 files changed, 74 insertions(+), 81 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index c74f27e..e8916e3 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1486,13 +1486,13 @@ struct btrfs_fs_info {
struct btrfs_workqueue_struct *workers;
struct btrfs_workqueue_struct *delalloc_workers;
struct btrfs_workqueue_struct *flush_workers;
-   struct btrfs_workers endio_workers;
-   struct btrfs_workers endio_meta_workers;
-   struct btrfs_workers endio_raid56_workers;
+   struct btrfs_workqueue_struct *endio_workers;
+   struct btrfs_workqueue_struct *endio_meta_workers;
+   struct btrfs_workqueue_struct *endio_raid56_workers;
struct btrfs_workers rmw_workers;
-   struct btrfs_workers endio_meta_write_workers;
-   struct btrfs_workers endio_write_workers;
-   struct btrfs_workers endio_freespace_worker;
+   struct btrfs_workqueue_struct *endio_meta_write_workers;
+   struct btrfs_workqueue_struct *endio_write_workers;
+   struct btrfs_workqueue_struct *endio_freespace_worker;
struct btrfs_workqueue_struct *submit_workers;
struct btrfs_workers caching_workers;
struct btrfs_workers readahead_workers;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3e4adff..7099001 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -55,7 +55,7 @@
 #endif
 
 static struct extent_io_ops btree_extent_io_ops;
-static void end_workqueue_fn(struct btrfs_work *work);
+static void end_workqueue_fn(struct btrfs_work_struct *work);
 static void free_fs_root(struct btrfs_root *root);
 static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
int read_only);
@@ -87,7 +87,7 @@ struct end_io_wq {
int error;
int metadata;
struct list_head list;
-   struct btrfs_work work;
+   struct btrfs_work_struct work;
 };
 
 /*
@@ -689,32 +689,31 @@ static void end_workqueue_bio(struct bio *bio, int err)
 
fs_info = end_io_wq->info;
end_io_wq->error = err;
-   end_io_wq->work.func = end_workqueue_fn;
-   end_io_wq->work.flags = 0;
+   btrfs_init_work(&end_io_wq->work, end_workqueue_fn, NULL, NULL);
 
if (bio->bi_rw & REQ_WRITE) {
if (end_io_wq->metadata == BTRFS_WQ_ENDIO_METADATA)
-   btrfs_queue_worker(&fs_info->endio_meta_write_workers,
-  &end_io_wq->work);
+   btrfs_queue_work(fs_info->endio_meta_write_workers,
+&end_io_wq->work);
else if (end_io_wq->metadata == BTRFS_WQ_ENDIO_FREE_SPACE)
-   btrfs_queue_worker(&fs_info->endio_freespace_worker,
-  &end_io_wq->work);
+   btrfs_queue_work(fs_info->endio_freespace_worker,
+&end_io_wq->work);
else if (end_io_wq->metadata == BTRFS_WQ_ENDIO_RAID56)
-   btrfs_queue_worker(&fs_info->endio_raid56_workers,
-  &end_io_wq->work);
+   btrfs_queue_work(fs_info->endio_raid56_workers,
+&end_io_wq->work);
else
-   btrfs_queue_worker(&fs_info->endio_write_workers,
-  &end_io_wq->work);
+   btrfs_queue_work(fs_info->endio_write_workers,
+&end_io_wq->work);
} else {
if (end_io_wq->metadata == BTRFS_WQ_ENDIO_RAID56)
-   btrfs_queue_worker(&fs_info->endio_raid56_workers,
-  &end_io_wq->work);
+   btrfs_queue_work(fs_info->endio_raid56_workers,
+&end_io_wq->work);
else if (end_io_wq->metadata)
-   btrfs_queue_worker(&fs_info->endio_meta_workers,
-  &end_io_wq->work);
+   btrfs_queue_work(fs_info->endio_meta_workers,
+&end_io_wq->work);
else
-   btrfs_queue_worker(&fs_info->endio_workers,
-  &end_io_wq->work);
+   btrfs_queue_work(fs_info->endio_workers,
+&end_io_wq->work);
}
 }
 
@@ -1667,7 +1666

[PATCH v3 13/17] btrfs: Replace fs_info->fixup_workers workqueue with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Replace the fs_info->fixup_workers with the newly created
btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  - Use the btrfs_workqueue_struct to replace fixup_workers.
---
 fs/btrfs/ctree.h   |  2 +-
 fs/btrfs/disk-io.c | 10 +-
 fs/btrfs/inode.c   |  8 
 fs/btrfs/super.c   |  1 -
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 29fb7a6..a01b399 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1502,7 +1502,7 @@ struct btrfs_fs_info {
 * the cow mechanism and make them safe to write.  It happens
 * for the sys_munmap function call path
 */
-   struct btrfs_workers fixup_workers;
+   struct btrfs_workqueue_struct *fixup_workers;
struct btrfs_workers delayed_workers;
struct task_struct *transaction_kthread;
struct task_struct *cleaner_kthread;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index fe3a8be..ae8201c 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1992,7 +1992,7 @@ static noinline int next_root_backup(struct btrfs_fs_info 
*info,
 static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
 {
btrfs_stop_workers(&fs_info->generic_worker);
-   btrfs_stop_workers(&fs_info->fixup_workers);
+   btrfs_destroy_workqueue(fs_info->fixup_workers);
btrfs_destroy_workqueue(fs_info->delalloc_workers);
btrfs_destroy_workqueue(fs_info->workers);
btrfs_destroy_workqueue(fs_info->endio_workers);
@@ -2506,8 +2506,8 @@ int open_ctree(struct super_block *sb,
 flags, max_active,
 0);
 
-   btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1,
-  &fs_info->generic_worker);
+   fs_info->fixup_workers = btrfs_alloc_workqueue("fixup", NULL, NULL,
+  flags, 1, 0);
/*
 * endios are largely parallel and should have a very
 * low idle thresh
@@ -2548,7 +2548,6 @@ int open_ctree(struct super_block *sb,
 * return -ENOMEM if any of these fail.
 */
ret = btrfs_start_workers(&fs_info->generic_worker);
-   ret |= btrfs_start_workers(&fs_info->fixup_workers);
ret |= btrfs_start_workers(&fs_info->delayed_workers);
ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers);
if (ret) {
@@ -2561,7 +2560,8 @@ int open_ctree(struct super_block *sb,
  fs_info->endio_meta_write_workers &&
  fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
  fs_info->endio_freespace_worker && fs_info->rmw_workers &&
- fs_info->caching_workers && fs_info->readahead_workers)) {
+ fs_info->caching_workers && fs_info->readahead_workers &&
+ fs_info->fixup_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 9dd807d..f5dce0c 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1729,10 +1729,10 @@ int btrfs_set_extent_delalloc(struct inode *inode, u64 
start, u64 end,
 /* see btrfs_writepage_start_hook for details on why this is required */
 struct btrfs_writepage_fixup {
struct page *page;
-   struct btrfs_work work;
+   struct btrfs_work_struct work;
 };
 
-static void btrfs_writepage_fixup_worker(struct btrfs_work *work)
+static void btrfs_writepage_fixup_worker(struct btrfs_work_struct *work)
 {
struct btrfs_writepage_fixup *fixup;
struct btrfs_ordered_extent *ordered;
@@ -1823,9 +1823,9 @@ static int btrfs_writepage_start_hook(struct page *page, 
u64 start, u64 end)
 
SetPageChecked(page);
page_cache_get(page);
-   fixup->work.func = btrfs_writepage_fixup_worker;
+   btrfs_init_work(&fixup->work, btrfs_writepage_fixup_worker, NULL, NULL);
fixup->page = page;
-   btrfs_queue_worker(&root->fs_info->fixup_workers, &fixup->work);
+   btrfs_queue_work(root->fs_info->fixup_workers, &fixup->work);
return -EBUSY;
 }
 
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 8e26ec5..841a72c 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1250,7 +1250,6 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info 
*fs_info,
btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size);
btrfs_workqueue_set_max(fs_info->submit_workers, new_pool_size);
btrfs_workqueue_set_max(fs_info->caching_workers, new_pool_size);
-   btrfs_set_max_workers(&fs_info->fixup_workers, new_pool_size);
btrfs_workqueue_set_max(fs_info->endio_workers, new_pool_size);
btrfs_workqueue_set_max(fs_info->endio_meta_workers, new_pool_size);
btrfs_workqueue_set_max(fs_info->endio_meta_write_workers,
-- 
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux

[PATCH v3 06/17] btrfs: Replace fs_info->delalloc_workers with btrfs_workqueue

2013-11-06 Thread Qu Wenruo
Much like the fs_info->workers, replace the fs_info->delalloc_workers
use the same btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  None
---
 fs/btrfs/ctree.h   |  2 +-
 fs/btrfs/disk-io.c | 14 ++
 fs/btrfs/inode.c   | 18 --
 fs/btrfs/super.c   |  2 +-
 4 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index dbc6e2d..f38285e 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1484,7 +1484,7 @@ struct btrfs_fs_info {
 */
struct btrfs_workers generic_worker;
struct btrfs_workqueue_struct *workers;
-   struct btrfs_workers delalloc_workers;
+   struct btrfs_workqueue_struct *delalloc_workers;
struct btrfs_workers flush_workers;
struct btrfs_workers endio_workers;
struct btrfs_workers endio_meta_workers;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index a467044..ed2eb52 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1994,7 +1994,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info 
*fs_info)
 {
btrfs_stop_workers(&fs_info->generic_worker);
btrfs_stop_workers(&fs_info->fixup_workers);
-   btrfs_stop_workers(&fs_info->delalloc_workers);
+   btrfs_destroy_workqueue(fs_info->delalloc_workers);
btrfs_destroy_workqueue(fs_info->workers);
btrfs_stop_workers(&fs_info->endio_workers);
btrfs_stop_workers(&fs_info->endio_meta_workers);
@@ -2485,8 +2485,10 @@ int open_ctree(struct super_block *sb,
 "worker-high", flags,
 max_active, 16);
 
-   btrfs_init_workers(&fs_info->delalloc_workers, "delalloc",
-  fs_info->thread_pool_size, NULL);
+   fs_info->delalloc_workers = btrfs_alloc_workqueue("delalloc",
+ "delalloc-ordered",
+ NULL, flags,
+ max_active, 2);
 
btrfs_init_workers(&fs_info->flush_workers, "flush_delalloc",
   fs_info->thread_pool_size, NULL);
@@ -2504,9 +2506,6 @@ int open_ctree(struct super_block *sb,
 */
fs_info->submit_workers.idle_thresh = 64;
 
-   fs_info->delalloc_workers.idle_thresh = 2;
-   fs_info->delalloc_workers.ordered = 1;
-
btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1,
   &fs_info->generic_worker);
btrfs_init_workers(&fs_info->endio_workers, "endio",
@@ -2557,7 +2556,6 @@ int open_ctree(struct super_block *sb,
 */
ret = btrfs_start_workers(&fs_info->generic_worker);
ret |= btrfs_start_workers(&fs_info->submit_workers);
-   ret |= btrfs_start_workers(&fs_info->delalloc_workers);
ret |= btrfs_start_workers(&fs_info->fixup_workers);
ret |= btrfs_start_workers(&fs_info->endio_workers);
ret |= btrfs_start_workers(&fs_info->endio_meta_workers);
@@ -2575,7 +2573,7 @@ int open_ctree(struct super_block *sb,
err = -ENOMEM;
goto fail_sb_buffer;
}
-   if (!(fs_info->workers)) {
+   if (!(fs_info->workers && fs_info->delalloc_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 3b4ffaf..42e3f81 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -306,7 +306,7 @@ struct async_cow {
u64 start;
u64 end;
struct list_head extents;
-   struct btrfs_work work;
+   struct btrfs_work_struct work;
 };
 
 static noinline int add_async_extent(struct async_cow *cow,
@@ -978,7 +978,7 @@ out_unlock:
 /*
  * work queue call back to started compression on a file and pages
  */
-static noinline void async_cow_start(struct btrfs_work *work)
+static noinline void async_cow_start(struct btrfs_work_struct *work)
 {
struct async_cow *async_cow;
int num_added = 0;
@@ -996,7 +996,7 @@ static noinline void async_cow_start(struct btrfs_work 
*work)
 /*
  * work queue call back to submit previously compressed pages
  */
-static noinline void async_cow_submit(struct btrfs_work *work)
+static noinline void async_cow_submit(struct btrfs_work_struct *work)
 {
struct async_cow *async_cow;
struct btrfs_root *root;
@@ -1017,7 +1017,7 @@ static noinline void async_cow_submit(struct btrfs_work 
*work)
submit_compressed_extents(async_cow->inode, async_cow);
 }
 
-static noinline void async_cow_free(struct btrfs_work *work)
+static noinline void async_cow_free(struct btrfs_work_struct *work)
 {
struct async_cow *async_cow;
async_cow = container_of(work, struct async_cow, work);
@@ -1054,17 +1054,15 @@ static int cow_file_range_async(struct inode *inode, 
struct page *locked_page,
async_cow->end = cu

[PATCH v3 15/17] btrfs: Replace fs_info->qgroup_rescan_worker workqueue with btrfs_workqueue.

2013-11-06 Thread Qu Wenruo
Replace the fs_info->qgroup_rescan_worker with the newly created
btrfs_workqueue.

Signed-off-by: Qu Wenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  - Use the btrfs_workqueue_struct to replace qgroup_rescan_workers.
---
 fs/btrfs/ctree.h   |  4 ++--
 fs/btrfs/disk-io.c | 12 ++--
 fs/btrfs/qgroup.c  | 17 +
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 3493010..2e7e6a4 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1625,9 +1625,9 @@ struct btrfs_fs_info {
/* qgroup rescan items */
struct mutex qgroup_rescan_lock; /* protects the progress item */
struct btrfs_key qgroup_rescan_progress;
-   struct btrfs_workers qgroup_rescan_workers;
+   struct btrfs_workqueue_struct *qgroup_rescan_workers;
struct completion qgroup_rescan_completion;
-   struct btrfs_work qgroup_rescan_work;
+   struct btrfs_work_struct qgroup_rescan_work;
 
/* filesystem state */
unsigned long fs_state;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 4fc26d2..6950570 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2007,7 +2007,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info 
*fs_info)
btrfs_destroy_workqueue(fs_info->caching_workers);
btrfs_destroy_workqueue(fs_info->readahead_workers);
btrfs_destroy_workqueue(fs_info->flush_workers);
-   btrfs_stop_workers(&fs_info->qgroup_rescan_workers);
+   btrfs_destroy_workqueue(fs_info->qgroup_rescan_workers);
 }
 
 /* helper to cleanup tree roots */
@@ -2539,16 +2539,15 @@ int open_ctree(struct super_block *sb,
fs_info->readahead_workers = btrfs_alloc_workqueue("readahead", NULL,
   NULL, flags,
   max_active, 2);
-   btrfs_init_workers(&fs_info->qgroup_rescan_workers, "qgroup-rescan", 1,
-  &fs_info->generic_worker);
-
+   fs_info->qgroup_rescan_workers =
+   btrfs_alloc_workqueue("qgroup-rescan", NULL, NULL,
+ flags, 1, 0);
 
/*
 * btrfs_start_workers can really only fail because of ENOMEM so just
 * return -ENOMEM if any of these fail.
 */
ret = btrfs_start_workers(&fs_info->generic_worker);
-   ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers);
if (ret) {
err = -ENOMEM;
goto fail_sb_buffer;
@@ -2560,7 +2559,8 @@ int open_ctree(struct super_block *sb,
  fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
  fs_info->endio_freespace_worker && fs_info->rmw_workers &&
  fs_info->caching_workers && fs_info->readahead_workers &&
- fs_info->fixup_workers && fs_info->delayed_workers)) {
+ fs_info->fixup_workers && fs_info->delayed_workers &&
+ fs_info->qgroup_rescan_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 4e6ef49..521144e 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1516,8 +1516,8 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
ret = qgroup_rescan_init(fs_info, 0, 1);
if (!ret) {
qgroup_rescan_zero_tracking(fs_info);
-   btrfs_queue_worker(&fs_info->qgroup_rescan_workers,
-  &fs_info->qgroup_rescan_work);
+   btrfs_queue_work(fs_info->qgroup_rescan_workers,
+&fs_info->qgroup_rescan_work);
}
ret = 0;
}
@@ -1981,7 +1981,7 @@ out:
return ret;
 }
 
-static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
+static void btrfs_qgroup_rescan_worker(struct btrfs_work_struct *work)
 {
struct btrfs_fs_info *fs_info = container_of(work, struct btrfs_fs_info,
 qgroup_rescan_work);
@@ -2092,7 +2092,8 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 
progress_objectid,
 
memset(&fs_info->qgroup_rescan_work, 0,
   sizeof(fs_info->qgroup_rescan_work));
-   fs_info->qgroup_rescan_work.func = btrfs_qgroup_rescan_worker;
+   btrfs_init_work(&fs_info->qgroup_rescan_work,
+   btrfs_qgroup_rescan_worker, NULL, NULL);
 
if (ret) {
 err:
@@ -2155,8 +2156,8 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info)
 
qgroup_rescan_zero_tracking(fs_info);
 
-   btrfs_queue_worker(&fs_info->qgroup_rescan_workers,
-  &fs_info->qgroup_rescan_work);
+   btrfs_queue_work(fs_info->qgroup_rescan_workers,
+&fs_info->qgroup_rescan_work);
 
return 0;
 }
@@ -2187,6 +2188,6 @@ void
 btrfs

[PATCH v3 17/17] btrfs: Cleanup the old btrfs_worker.

2013-11-06 Thread Qu Wenruo
Since all the btrfs_worker is replaced with the newly created
btrfs_workqueue, the old codes can be easily remove.

Signed-off-by: Quwenruo 
---
Changelog:
v1->v2:
  None
v2->v3:
  - Reuse the old async-thred.[ch] files.
---
 fs/btrfs/async-thread.c | 703 
 fs/btrfs/async-thread.h | 100 ---
 fs/btrfs/ctree.h|   1 -
 fs/btrfs/disk-io.c  |  12 -
 fs/btrfs/super.c|   8 -
 5 files changed, 824 deletions(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 1fde6a2..497cdb1 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -26,712 +26,9 @@
 #include 
 #include "async-thread.h"
 
-#define WORK_QUEUED_BIT 0
-#define WORK_DONE_BIT 1
-#define WORK_ORDER_DONE_BIT 2
-#define WORK_HIGH_PRIO_BIT 3
-
 #define NO_THRESHOLD (-1)
 #define DFT_THRESHOLD (32)
 
-/*
- * container for the kthread task pointer and the list of pending work
- * One of these is allocated per thread.
- */
-struct btrfs_worker_thread {
-   /* pool we belong to */
-   struct btrfs_workers *workers;
-
-   /* list of struct btrfs_work that are waiting for service */
-   struct list_head pending;
-   struct list_head prio_pending;
-
-   /* list of worker threads from struct btrfs_workers */
-   struct list_head worker_list;
-
-   /* kthread */
-   struct task_struct *task;
-
-   /* number of things on the pending list */
-   atomic_t num_pending;
-
-   /* reference counter for this struct */
-   atomic_t refs;
-
-   unsigned long sequence;
-
-   /* protects the pending list. */
-   spinlock_t lock;
-
-   /* set to non-zero when this thread is already awake and kicking */
-   int working;
-
-   /* are we currently idle */
-   int idle;
-};
-
-static int __btrfs_start_workers(struct btrfs_workers *workers);
-
-/*
- * btrfs_start_workers uses kthread_run, which can block waiting for memory
- * for a very long time.  It will actually throttle on page writeback,
- * and so it may not make progress until after our btrfs worker threads
- * process all of the pending work structs in their queue
- *
- * This means we can't use btrfs_start_workers from inside a btrfs worker
- * thread that is used as part of cleaning dirty memory, which pretty much
- * involves all of the worker threads.
- *
- * Instead we have a helper queue who never has more than one thread
- * where we scheduler thread start operations.  This worker_start struct
- * is used to contain the work and hold a pointer to the queue that needs
- * another worker.
- */
-struct worker_start {
-   struct btrfs_work work;
-   struct btrfs_workers *queue;
-};
-
-static void start_new_worker_func(struct btrfs_work *work)
-{
-   struct worker_start *start;
-   start = container_of(work, struct worker_start, work);
-   __btrfs_start_workers(start->queue);
-   kfree(start);
-}
-
-/*
- * helper function to move a thread onto the idle list after it
- * has finished some requests.
- */
-static void check_idle_worker(struct btrfs_worker_thread *worker)
-{
-   if (!worker->idle && atomic_read(&worker->num_pending) <
-   worker->workers->idle_thresh / 2) {
-   unsigned long flags;
-   spin_lock_irqsave(&worker->workers->lock, flags);
-   worker->idle = 1;
-
-   /* the list may be empty if the worker is just starting */
-   if (!list_empty(&worker->worker_list) &&
-   !worker->workers->stopping) {
-   list_move(&worker->worker_list,
-&worker->workers->idle_list);
-   }
-   spin_unlock_irqrestore(&worker->workers->lock, flags);
-   }
-}
-
-/*
- * helper function to move a thread off the idle list after new
- * pending work is added.
- */
-static void check_busy_worker(struct btrfs_worker_thread *worker)
-{
-   if (worker->idle && atomic_read(&worker->num_pending) >=
-   worker->workers->idle_thresh) {
-   unsigned long flags;
-   spin_lock_irqsave(&worker->workers->lock, flags);
-   worker->idle = 0;
-
-   if (!list_empty(&worker->worker_list) &&
-   !worker->workers->stopping) {
-   list_move_tail(&worker->worker_list,
- &worker->workers->worker_list);
-   }
-   spin_unlock_irqrestore(&worker->workers->lock, flags);
-   }
-}
-
-static void check_pending_worker_creates(struct btrfs_worker_thread *worker)
-{
-   struct btrfs_workers *workers = worker->workers;
-   struct worker_start *start;
-   unsigned long flags;
-
-   rmb();
-   if (!workers->atomic_start_pending)
-   return;
-
-   start = kzalloc(sizeof(*start), GFP_NOFS);
-   if (!start)
-   return;
-
-   start->work.func = start_new_worker_func;
-   start->queue = worke

Re: [PATCH 08/16] btrfs-progs: fix resource leak in scrub_start()

2013-11-06 Thread Wang Shilong

On 11/07/2013 11:46 AM, Eric Sandeen wrote:

On 11/6/13, 7:50 PM, Wang Shilong wrote:

On 11/07/2013 09:48 AM, Wang Shilong wrote:

Hi Eric,

On 11/07/2013 07:15 AM, Eric Sandeen wrote:

In the "nothing to resume" case we return directly and leak
several bits of memory; goto out to free them properly.

Resolves-Coverity-CID: 1125934
Resolves-Coverity-CID: 1125935
Resolves-Coverity-CID: 1125936
Signed-off-by: Eric Sandeen 
---
   cmds-scrub.c |3 ++-
   1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/cmds-scrub.c b/cmds-scrub.c
index 605af45..5f3eade 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -1261,7 +1261,8 @@ static int scrub_start(int argc, char **argv, int resume)
   if (!do_quiet)
   printf("scrub: nothing to resume for %s, fsid %s\n",
  path, fsid);
-return 2;
+err = 2;
+goto out;

Thanks for tracking this problem, but
i intend to return 2 in such case originally.
return '!err' will revert to return 1 rather than 2.

see label out:

if (err)
 return 1


Ah, whoops.  Ok, well we still need to fix the leak.

I just expected that setting err & going to out would return err ;)

So probably:

if (err)
return err;

No, we can't.
maybe add a flag, something like:

flag = 0;

/*  we set flag here for a special case */
if (!do_quient)
printf
flag = 2;


then in label
out:
...
/* this happen if nothing resume */
if (flag)
return flag
/* syntax or other error happens */
if (err)
return 1

Previously, 'err' can be an casual positive numbers or error number.
However, we define that we return 1 if syntax error happens.

Thanks,
Wang


will work.

I'll send a V2.

Thanks for catching it on review!

-Eric





--
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 11/16] btrfs-progs: pass positive errno to strerror in cmd_df()

2013-11-06 Thread Anand Jain


Reviewed-by Anand Jain 

On 11/07/2013 07:15 AM, Eric Sandeen wrote:

get_df returns a negative error number, but then
we pass it to strerror, which wants a positive value...

Resolves-Coverity-CID: 1125929
Signed-off-by: Eric Sandeen 
---
  cmds-filesystem.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index df9d1ff..b1291d6 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -173,7 +173,7 @@ static int cmd_df(int argc, char **argv)
print_df(sargs);
free(sargs);
} else {
-   fprintf(stderr, "ERROR: get_df failed %s\n", strerror(ret));
+   fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret));
}

close_file_or_dir(fd, dirstream);


--
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 09/16] btrfs-progs: btrfs_scan_kernel(): fd==0 is not an error

2013-11-06 Thread Anand Jain


Reviewed-by: Anand Jain 


On 11/07/2013 07:15 AM, Eric Sandeen wrote:

The error return from open is -1, so test that, not 0,
for success/failure.

Resolves-Coverity-CID: 1125931
Signed-off-by: Eric Sandeen 
---
  cmds-filesystem.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index e6642ef..df9d1ff 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -362,13 +362,13 @@ static int btrfs_scan_kernel(void *search)
}

fd = open(mnt->mnt_dir, O_RDONLY);
-   if (fd > 0 && !get_df(fd, &space_info_arg)) {
+   if ((fd != -1) && !get_df(fd, &space_info_arg)) {
get_label_mounted(mnt->mnt_dir, label);
print_one_fs(&fs_info_arg, dev_info_arg,
space_info_arg, label, mnt->mnt_dir);
free(space_info_arg);
}
-   if (fd > 0)
+   if (fd != -1)
close(fd);
free(dev_info_arg);
}


--
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 08/16] btrfs-progs: fix resource leak in scrub_start()

2013-11-06 Thread Eric Sandeen
On 11/6/13, 7:50 PM, Wang Shilong wrote:
> On 11/07/2013 09:48 AM, Wang Shilong wrote:
>> Hi Eric,
>>
>> On 11/07/2013 07:15 AM, Eric Sandeen wrote:
>>> In the "nothing to resume" case we return directly and leak
>>> several bits of memory; goto out to free them properly.
>>>
>>> Resolves-Coverity-CID: 1125934
>>> Resolves-Coverity-CID: 1125935
>>> Resolves-Coverity-CID: 1125936
>>> Signed-off-by: Eric Sandeen 
>>> ---
>>>   cmds-scrub.c |3 ++-
>>>   1 files changed, 2 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/cmds-scrub.c b/cmds-scrub.c
>>> index 605af45..5f3eade 100644
>>> --- a/cmds-scrub.c
>>> +++ b/cmds-scrub.c
>>> @@ -1261,7 +1261,8 @@ static int scrub_start(int argc, char **argv, int 
>>> resume)
>>>   if (!do_quiet)
>>>   printf("scrub: nothing to resume for %s, fsid %s\n",
>>>  path, fsid);
>>> -return 2;
>>> +err = 2;
>>> +goto out;
>> Thanks for tracking this problem, but
>> i intend to return 2 in such case originally.
>> return '!err' will revert to return 1 rather than 2.
> see label out:
> 
> if (err)
> return 1
> 

Ah, whoops.  Ok, well we still need to fix the leak.  

I just expected that setting err & going to out would return err ;)

So probably:

if (err)
   return err;

will work.

I'll send a V2.

Thanks for catching it on review!

-Eric

--
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 05/16] btrfs-progs: don't leak fd in test_dev_for_mkfs() error paths

2013-11-06 Thread Anand Jain


Reviewed-by: Anand Jain 


On 11/07/2013 07:15 AM, Eric Sandeen wrote:

Close fd before we return on error paths.

Resolves-Coverity-CID: 1125939
Signed-off-by: Eric Sandeen 
---
  utils.c |2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/utils.c b/utils.c
index c11a7c2..c784345 100644
--- a/utils.c
+++ b/utils.c
@@ -1905,10 +1905,12 @@ int test_dev_for_mkfs(char *file, int force_overwrite, 
char *estr)
if (fstat(fd, &st)) {
snprintf(estr, sz, "unable to stat %s: %s\n", file,
strerror(errno));
+   close(fd);
return 1;
}
if (!S_ISBLK(st.st_mode)) {
fprintf(stderr, "'%s' is not a block device\n", file);
+   close(fd);
return 1;
}
close(fd);


--
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 04/16] btrfs-progs: fix test for return of realpath in find_mount_root()

2013-11-06 Thread Anand Jain


Reviewed-by: Anand Jain 


On 11/07/2013 07:15 AM, Eric Sandeen wrote:

find_mount_root() tries to test for realpath() failure, but
tests the wrong value.  Fix it.

Resolves-Coverity-CID: 1125940
Signed-off-by: Eric Sandeen 
---
  cmds-send.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cmds-send.c b/cmds-send.c
index 39110e7..53e9a53 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -98,7 +98,7 @@ int find_mount_root(const char *path, char **mount_root)

ret = 0;
*mount_root = realpath(longest_match, NULL);
-   if (!mount_root)
+   if (!*mount_root)
ret = -errno;

free(longest_match);


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


[PATCH] btrfs-progs: use /proc/self/mounts

2013-11-06 Thread Anand Jain
Signed-off-by: Anand Jain 
---
 cmds-send.c |2 +-
 utils.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmds-send.c b/cmds-send.c
index 53e9a53..43ea06b 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -72,7 +72,7 @@ int find_mount_root(const char *path, char **mount_root)
return -errno;
close(fd);
 
-   mnttab = fopen("/proc/mounts", "r");
+   mnttab = fopen("/proc/self/mounts", "r");
if (!mnttab)
return -errno;
 
diff --git a/utils.c b/utils.c
index ebd10e5..d2138dd 100644
--- a/utils.c
+++ b/utils.c
@@ -996,7 +996,7 @@ int check_mounted_where(int fd, const char *file, char 
*where, int size,
}
 
/* iterate over the list of currently mountes filesystems */
-   if ((f = setmntent ("/proc/mounts", "r")) == NULL)
+   if ((f = setmntent ("/proc/self/mounts", "r")) == NULL)
return -errno;
 
while ((mnt = getmntent (f)) != NULL) {
-- 
1.7.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


[PATCH] btrfs-progs: use strncpy in btrfs_scan_lblkid()

2013-11-06 Thread Anand Jain
From: Eric Sandeen 

Use strncpy(... ,PATH_MAX) to be sure we don't overflow
the path[PATH_MAX] array.

Resolves-Coverity-CID: 1125941
Signed-off-by: Eric Sandeen 
Signed-off-by: Anand Jain 
---
 utils.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/utils.c b/utils.c
index 753169b..ebd10e5 100644
--- a/utils.c
+++ b/utils.c
@@ -1981,8 +1981,8 @@ int btrfs_scan_lblkid(int update_kernel)
dev = blkid_verify(cache, dev);
if (!dev)
continue;
-   /* if we are here its definitly a btrfs disk*/
-   strcpy(path, blkid_dev_devname(dev));
+   /* if we are here its definitely a btrfs disk*/
+   strncpy(path, blkid_dev_devname(dev), PATH_MAX);
if (test_skip_this_disk(path))
continue;
 
-- 
1.7.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


Re: [PATCH 02/16] btrfs-progs: fix error returns in get_df()

2013-11-06 Thread Anand Jain


 I had just retained whats in the original. But this is
 good change. Thanks Eric.

Reviewed-by: Anand Jain 


On 11/07/2013 07:15 AM, Eric Sandeen wrote:

get_df returns -ERRNO, or maybe (+)errno, or even 0 in
the case where we inexplicably got 0 total_spaces from
the BTRFS_IOC_SPACE_INFO.

Consistently return a negative error number, and return
-ENOENT rather than 0 for total_spaces == 0, so that the
caller will know that **sargs_ret hasn't been set up.

Signed-off-by: Eric Sandeen 
---
  cmds-filesystem.c |7 ---
  1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 0bfd710..e6642ef 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -106,11 +106,12 @@ static int get_df(int fd, struct btrfs_ioctl_space_args 
**sargs_ret)
fprintf(stderr, "ERROR: couldn't get space info - %s\n",
strerror(e));
free(sargs);
-   return ret;
+   return -e;
}
+   /* This really should never happen */
if (!sargs->total_spaces) {
free(sargs);
-   return 0;
+   return -ENOENT;
}
count = sargs->total_spaces;
free(sargs);
@@ -128,7 +129,7 @@ static int get_df(int fd, struct btrfs_ioctl_space_args 
**sargs_ret)
fprintf(stderr, "ERROR: get space info count %llu - %s\n",
count, strerror(e));
free(sargs);
-   return ret;
+   return -e;
}
*sargs_ret = sargs;
return 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 08/16] btrfs-progs: fix resource leak in scrub_start()

2013-11-06 Thread Wang Shilong

On 11/07/2013 09:48 AM, Wang Shilong wrote:

Hi Eric,

On 11/07/2013 07:15 AM, Eric Sandeen wrote:

In the "nothing to resume" case we return directly and leak
several bits of memory; goto out to free them properly.

Resolves-Coverity-CID: 1125934
Resolves-Coverity-CID: 1125935
Resolves-Coverity-CID: 1125936
Signed-off-by: Eric Sandeen 
---
  cmds-scrub.c |3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/cmds-scrub.c b/cmds-scrub.c
index 605af45..5f3eade 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -1261,7 +1261,8 @@ static int scrub_start(int argc, char **argv, 
int resume)

  if (!do_quiet)
  printf("scrub: nothing to resume for %s, fsid %s\n",
 path, fsid);
-return 2;
+err = 2;
+goto out;

Thanks for tracking this problem, but
i intend to return 2 in such case originally.
return '!err' will revert to return 1 rather than 2.

see label out:

if (err)
return 1



Thanks,
Wang

  }
ret = prg_fd = socket(AF_UNIX, SOCK_STREAM, 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



--
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 08/16] btrfs-progs: fix resource leak in scrub_start()

2013-11-06 Thread Wang Shilong

Hi Eric,

On 11/07/2013 07:15 AM, Eric Sandeen wrote:

In the "nothing to resume" case we return directly and leak
several bits of memory; goto out to free them properly.

Resolves-Coverity-CID: 1125934
Resolves-Coverity-CID: 1125935
Resolves-Coverity-CID: 1125936
Signed-off-by: Eric Sandeen 
---
  cmds-scrub.c |3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/cmds-scrub.c b/cmds-scrub.c
index 605af45..5f3eade 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -1261,7 +1261,8 @@ static int scrub_start(int argc, char **argv, int resume)
if (!do_quiet)
printf("scrub: nothing to resume for %s, fsid %s\n",
   path, fsid);
-   return 2;
+   err = 2;
+   goto out;

Thanks for tracking this problem, but
i intend to return 2 in such case originally.
return '!err' will revert to return 1 rather than 2.

Thanks,
Wang

}
  
  	ret = prg_fd = socket(AF_UNIX, SOCK_STREAM, 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] Btrfs: fix negative qgroup tracking from owner accounting (bug #61951)

2013-11-06 Thread Wang Shilong

On 11/07/2013 01:34 AM, Josef Bacik wrote:

On Wed, Nov 06, 2013 at 06:20:47PM +0100, Jan Schmidt wrote:
  
On Mon, November 04, 2013 at 18:42 (+0100), Josef Bacik wrote:

On Thu, Oct 24, 2013 at 03:22:06PM +0200, Jan Schmidt wrote:

btrfs_dec_ref() queued a delayed ref for owner of a tree block. The qgroup
tracking is based on delayed refs. The owner of a tree block is set when a
tree block is allocated, it is never updated.

When you allocate a tree block and then remove the subvolume that did the
allocation, the qgroup accounting for that removal is correct. However, the
removal was accounted again for each subvolume deletion that also referenced
the tree block, because accounting was erroneously based on the owner.

Instead of queueing delayed refs for the non-existent owner, we now
queue delayed refs for the root being removed. This fixes the qgroup
accounting.

Signed-off-by: Jan Schmidt 
Tested-by: 

This breaks btrfs/003, I'm kicking it out.

Can you be a bit more specific? Works fine here.


It's blowing up on the balance, so maybe make a bigger fs and balance that so
you can see it?  It's exploding in __btrfs_free_extent because we can't find the
ref we're trying to drop, so I assume you've broken the dropping of the reloc
root part where it depends on you giving it btrfs_header_owner() instead of
root->root_key.objectid as when we cow blocks that belong to the reloc root we
leave the owner set to whoever owned the block originally and not the reloc
root.  Thanks,

True, i did hit the problem when i test balance regression with btrfs-next.

[ 8468.976315] WARNING: CPU: 3 PID: 14993 at fs/btrfs/extent-tree.c:5783 
__btrfs_free_extent+0x9af/0xa20 [btrfs]()
[ 8468.976316] Modules linked in: btrfs(O) ebtable_nat ip6t_REJECT tun 
xt_CHECKSUM fuse bridge stp llc bluetooth rfkill iptable_mangle 
nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack 
ebtable_filter ebtables ip6table_filter ip6_tables libcrc32c xor 
zlib_deflate raid6_pq r8169 snd_hda_codec_realtek snd_hda_intel 
snd_hda_codec snd_hwdep snd_seq snd_seq_device snd_pcm wmi iTCO_wdt 
iTCO_vendor_support lpc_ich uinput snd_page_alloc snd_timer i2c_i801 snd 
soundcore acpi_cpufreq mperf mfd_core mii pcspkr i915 i2c_algo_bit 
drm_kms_helper drm i2c_core video [last unloaded: btrfs]
[ 8468.976339] CPU: 3 PID: 14993 Comm: btrfs Tainted: G   O 
3.11.0+ #17
[ 8468.976340] Hardware name: LENOVO QiTianM4350/ , BIOS F1KT52AUS 
05/24/2013
[ 8468.976341]  0009 880087c11828 8158f948 

[ 8468.976343]  880087c11860 8104febd 8800ba554ab0 
1b64c000
[ 8468.976344]   fffe  
880087c11870

[ 8468.976346] Call Trace:
[ 8468.976351]  [] dump_stack+0x45/0x56
[ 8468.976354]  [] warn_slowpath_common+0x7d/0xa0
[ 8468.976356]  [] warn_slowpath_null+0x1a/0x20
[ 8468.976361]  [] __btrfs_free_extent+0x9af/0xa20 [btrfs]
[ 8468.976366]  [] ? btrfs_free_path+0x20/0x30 [btrfs]
[ 8468.976375]  [] ? 
btrfs_merge_delayed_refs+0x1f4/0x3d0 [btrfs]

[ 8468.976380]  [] run_clustered_refs+0x46c/0x1080 [btrfs]
[ 8468.976386]  [] btrfs_run_delayed_refs+0xe0/0x540 
[btrfs]
[ 8468.976393]  [] ? 
alloc_backref_node.isra.14+0x23/0x60 [btrfs]

[ 8468.976399]  [] ? tree_insert+0x50/0x60 [btrfs]
[ 8468.976406]  [] ? 
btrfs_reloc_post_snapshot+0xf9/0x360 [btrfs]
[ 8468.976412]  [] create_pending_snapshot+0x706/0x920 
[btrfs]
[ 8468.976418]  [] create_pending_snapshots+0x6a/0x90 
[btrfs]
[ 8468.976424]  [] 
btrfs_commit_transaction+0x384/0x970 [btrfs]
[ 8468.976431]  [] btrfs_mksubvol.isra.30+0x3da/0x460 
[btrfs]
[ 8468.976437]  [] 
btrfs_ioctl_snap_create_transid+0xde/0x170 [btrfs]
[ 8468.976443]  [] 
btrfs_ioctl_snap_create_v2+0xeb/0x130 [btrfs]

[ 8468.976450]  [] btrfs_ioctl+0x11da/0x27a0 [btrfs]
[ 8468.976453]  [] ? handle_mm_fault+0x210/0x310
[ 8468.976456]  [] ? __do_page_fault+0x1f4/0x500
[ 8468.976457]  [] ? do_mmap_pgoff+0x305/0x3c0
[ 8468.976460]  [] do_vfs_ioctl+0x2dd/0x4b0
[ 8468.976461]  [] SyS_ioctl+0x81/0xa0
[ 8468.976463]  [] ? do_page_fault+0xe/0x10
[ 8468.976465]  [] system_call_fastpath+0x16/0x1b

Thanks,
Wang


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



--
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-progs: allow --init-extent-tree to work when extent tree is borked

2013-11-06 Thread Martin
On 28/10/13 15:11, Josef Bacik wrote:
> On Sun, Oct 27, 2013 at 12:16:12AM +0100, Martin wrote:
>> On 25/10/13 19:31, Josef Bacik wrote:
>>> On Fri, Oct 25, 2013 at 07:27:24PM +0100, Martin wrote:
 On 25/10/13 19:01, Josef Bacik wrote:
> Unfortunately you can't run --init-extent-tree if you can't actually read 
> the
> extent root.  Fix this by allowing partial starts with no extent root and 
> then
> have fsck only check to see if the extent root is uptodate _after_ the 
> check to
> see if we are init'ing the extent tree.  Thanks,
>
> Signed-off-by: Josef Bacik 
> ---
>  cmds-check.c |  9 ++---
>  disk-io.c| 16 ++--
>  2 files changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/cmds-check.c b/cmds-check.c
> index 69b0327..8ed7baa 100644
> --- a/cmds-check.c
> +++ b/cmds-check.c

 Hey! Quick work!...

 Is that worth patching locally and trying against my example?

>>>
>>> Yes, I'm a little worried about your particular case so I'd like to see if 
>>> it
>>> works.  If you don't see a lot of output after say 5 minutes let's assume I
>>> didn't fix your problem and let me know so I can make the other change I
>>> considered.  Thanks,
>>
>> Nope... No-go.
>>
> 
> Ok I've sent
> 
> [PATCH] Btrfs-progs: rework open_ctree to take flags, add a new one
> 
> which should address your situation.  Thanks,


Josef,

Tried your patch:


Signed-off-by: Josef Bacik 

 13 files changed, 75 insertions(+), 113 deletions(-)

diff --git a/btrfs-convert.c b/btrfs-convert.c
index 26c7b5f..ae10eed 100644


And the patching fails due to mismatching code...

I have the Gentoo source for:

Btrfs v0.20-rc1-358-g194aa4a

(On Gentoo 3.11.5, will be on 3.11.6 later today.)


What are the magic incantations to download your version of source code
to try please? (Patched or unpatched?)


Many thanks,
Martin


--
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 04/16] btrfs-progs: fix test for return of realpath in find_mount_root()

2013-11-06 Thread Eric Sandeen
find_mount_root() tries to test for realpath() failure, but
tests the wrong value.  Fix it.

Resolves-Coverity-CID: 1125940
Signed-off-by: Eric Sandeen 
---
 cmds-send.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cmds-send.c b/cmds-send.c
index 39110e7..53e9a53 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -98,7 +98,7 @@ int find_mount_root(const char *path, char **mount_root)
 
ret = 0;
*mount_root = realpath(longest_match, NULL);
-   if (!mount_root)
+   if (!*mount_root)
ret = -errno;
 
free(longest_match);
-- 
1.7.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


[PATCH 16/16] btrfs-progs: annotate fallthroughs in parse_limit

2013-11-06 Thread Eric Sandeen
We intentionally fall through these case statements;
just annotate it to be clear.

Resolves-Coverity-CID: 1054884
Signed-off-by: Eric Sandeen 
---
 cmds-qgroup.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 4fe776c..5a393bd 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -120,12 +120,15 @@ static int parse_limit(const char *p, unsigned long long 
*s)
case 'T':
case 't':
size *= 1024;
+   /* fallthrough */
case 'G':
case 'g':
size *= 1024;
+   /* fallthrough */
case 'M':
case 'm':
size *= 1024;
+   /* fallthrough */
case 'K':
case 'k':
size *= 1024;
-- 
1.7.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


[PATCH 10/16] btrfs-progs: Check for open failure in btrfs_scan_lblkid()

2013-11-06 Thread Eric Sandeen
open can fail, of course.

Resolves-Coverity-CID: 1125925
Resolves-Coverity-CID: 1125930
Signed-off-by: Eric Sandeen 
---
 utils.c |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/utils.c b/utils.c
index d8ce153..8471148 100644
--- a/utils.c
+++ b/utils.c
@@ -1955,12 +1955,16 @@ int btrfs_scan_lblkid(int update_kernel)
dev = blkid_verify(cache, dev);
if (!dev)
continue;
-   /* if we are here its definitly a btrfs disk*/
+   /* if we are here its definitely a btrfs disk*/
strncpy(path, blkid_dev_devname(dev), PATH_MAX);
if (test_skip_this_disk(path))
continue;
 
fd = open(path, O_RDONLY);
+   if (fd < 0) {
+   printf("ERROR: could not open %s\n", path);
+   continue;
+   }
btrfs_scan_one_device(fd, path, &tmp_devices,
&num_devices, BTRFS_SUPER_INFO_OFFSET);
close(fd);
-- 
1.7.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


[PATCH 06/16] btrfs-progs: fix leak of "buf" in make_btrfs() error paths

2013-11-06 Thread Eric Sandeen
If any pwrite failed we leaked the allocated "buf" on
return from the function.  "goto out" takes care of
those paths.

Resolves-Coverity-CID: 1125938
Signed-off-by: Eric Sandeen 
---
 utils.c |   62 --
 1 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/utils.c b/utils.c
index c784345..d8ce153 100644
--- a/utils.c
+++ b/utils.c
@@ -210,10 +210,10 @@ int make_btrfs(int fd, const char *device, const char 
*label,
 
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[1]);
-   if (ret < 0)
-   return -errno;
-   else if (ret != leafsize)
-   return -EIO;
+   if (ret != leafsize) {
+   ret = (ret < 0 ? -errno : -EIO);
+   goto out;
+   }
 
/* create the items for the extent tree */
memset(buf->data+sizeof(struct btrfs_header), 0,
@@ -269,10 +269,10 @@ int make_btrfs(int fd, const char *device, const char 
*label,
btrfs_set_header_nritems(buf, nritems);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[2]);
-   if (ret < 0)
-   return -errno;
-   else if (ret != leafsize)
-   return -EIO;
+   if (ret != leafsize) {
+   ret = (ret < 0 ? -errno : -EIO);
+   goto out;
+   }
 
/* create the chunk tree */
memset(buf->data+sizeof(struct btrfs_header), 0,
@@ -356,10 +356,10 @@ int make_btrfs(int fd, const char *device, const char 
*label,
btrfs_set_header_nritems(buf, nritems);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[3]);
-   if (ret < 0)
-   return -errno;
-   else if (ret != leafsize)
-   return -EIO;
+   if (ret != leafsize) {
+   ret = (ret < 0 ? -errno : -EIO);
+   goto out;
+   }
 
/* create the device tree */
memset(buf->data+sizeof(struct btrfs_header), 0,
@@ -395,10 +395,10 @@ int make_btrfs(int fd, const char *device, const char 
*label,
btrfs_set_header_nritems(buf, nritems);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[4]);
-   if (ret < 0)
-   return -errno;
-   else if (ret != leafsize)
-   return -EIO;
+   if (ret != leafsize) {
+   ret = (ret < 0 ? -errno : -EIO);
+   goto out;
+   }
 
/* create the FS root */
memset(buf->data+sizeof(struct btrfs_header), 0,
@@ -408,11 +408,10 @@ int make_btrfs(int fd, const char *device, const char 
*label,
btrfs_set_header_nritems(buf, 0);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[5]);
-   if (ret < 0)
-   return -errno;
-   else if (ret != leafsize)
-   return -EIO;
-
+   if (ret != leafsize) {
+   ret = (ret < 0 ? -errno : -EIO);
+   goto out;
+   }
/* finally create the csum root */
memset(buf->data+sizeof(struct btrfs_header), 0,
leafsize-sizeof(struct btrfs_header));
@@ -421,10 +420,10 @@ int make_btrfs(int fd, const char *device, const char 
*label,
btrfs_set_header_nritems(buf, 0);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[6]);
-   if (ret < 0)
-   return -errno;
-   else if (ret != leafsize)
-   return -EIO;
+   if (ret != leafsize) {
+   ret = (ret < 0 ? -errno : -EIO);
+   goto out;
+   }
 
/* and write out the super block */
BUG_ON(sizeof(super) > sectorsize);
@@ -433,13 +432,16 @@ int make_btrfs(int fd, const char *device, const char 
*label,
buf->len = sectorsize;
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, sectorsize, blocks[0]);
-   if (ret < 0)
-   return -errno;
-   else if (ret != sectorsize)
-   return -EIO;
+   if (ret != sectorsize) {
+   ret = (ret < 0 ? -errno : -EIO);
+   goto out;
+   }
+
+   ret = 0;
 
+out:
free(buf);
-   return 0;
+   return ret;
 }
 
 u64 btrfs_device_size(int fd, struct stat *st)
-- 
1.7.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


[PATCH 14/16] btrfs-progs: check for fstat failure in cmd_defrag

2013-11-06 Thread Eric Sandeen
Resolves-Coverity-CID: 1125924
Signed-off-by: Eric Sandeen 
---
 cmds-filesystem.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index b1291d6..2cb067d 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -661,7 +661,13 @@ static int cmd_defrag(int argc, char **argv)
if (recursive) {
struct stat st;
 
-   fstat(fd, &st);
+   if (fstat(fd, &st)) {
+   fprintf(stderr, "ERROR: failed to stat %s - 
%s\n",
+   argv[i], strerror(errno));
+   defrag_global_errors++;
+   close_file_or_dir(fd, dirstream);
+   continue;
+   }
if (S_ISDIR(st.st_mode)) {
ret = nftw(argv[i], defrag_callback, 10,
FTW_MOUNT | FTW_PHYS);
-- 
1.7.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


[PATCH 07/16] btrfs-progs: don't leak buffer on add_file_items() error

2013-11-06 Thread Eric Sandeen
add_file_items() leaked "buffer" on this error return.
Free it first.

Resolves-Coverity-CID: 1125937
Signed-off-by: Eric Sandeen 
---
 mkfs.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/mkfs.c b/mkfs.c
index d576797..f29f5cd 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -629,6 +629,7 @@ static int add_file_items(struct btrfs_trans_handle *trans,
ret_read = pread64(fd, buffer, st->st_size, bytes_read);
if (ret_read == -1) {
fprintf(stderr, "%s read failed\n", path_name);
+   free(buffer);
goto end;
}
 
-- 
1.7.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


[PATCH 08/16] btrfs-progs: fix resource leak in scrub_start()

2013-11-06 Thread Eric Sandeen
In the "nothing to resume" case we return directly and leak
several bits of memory; goto out to free them properly.

Resolves-Coverity-CID: 1125934
Resolves-Coverity-CID: 1125935
Resolves-Coverity-CID: 1125936
Signed-off-by: Eric Sandeen 
---
 cmds-scrub.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/cmds-scrub.c b/cmds-scrub.c
index 605af45..5f3eade 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -1261,7 +1261,8 @@ static int scrub_start(int argc, char **argv, int resume)
if (!do_quiet)
printf("scrub: nothing to resume for %s, fsid %s\n",
   path, fsid);
-   return 2;
+   err = 2;
+   goto out;
}
 
ret = prg_fd = socket(AF_UNIX, SOCK_STREAM, 0);
-- 
1.7.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


[PATCH 12/16] btrfs-progs: remove more dead code from check_extent_refs

2013-11-06 Thread Eric Sandeen
e0a04278 removed a bunch of dead code but left one little
bit; reinit is always 0, so btrfs_read_block_groups is
never called from here.

Resolves-Coverity-CID: 1125926
Signed-off-by: Eric Sandeen 
---
 cmds-check.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 668af15..263b4ef 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -5040,7 +5040,6 @@ static int check_extent_refs(struct btrfs_trans_handle 
*trans,
int err = 0;
int ret = 0;
int fixed = 0;
-   int reinit = 0;
int had_dups = 0;
 
if (repair) {
@@ -5066,8 +5065,6 @@ static int check_extent_refs(struct btrfs_trans_handle 
*trans,
cache = next_cache_extent(cache);
}
prune_corrupt_blocks(trans, root->fs_info);
-   if (reinit)
-   btrfs_read_block_groups(root->fs_info->extent_root);
reset_cached_block_groups(root->fs_info);
}
 
-- 
1.7.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


[PATCH 11/16] btrfs-progs: pass positive errno to strerror in cmd_df()

2013-11-06 Thread Eric Sandeen
get_df returns a negative error number, but then
we pass it to strerror, which wants a positive value...

Resolves-Coverity-CID: 1125929
Signed-off-by: Eric Sandeen 
---
 cmds-filesystem.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index df9d1ff..b1291d6 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -173,7 +173,7 @@ static int cmd_df(int argc, char **argv)
print_df(sargs);
free(sargs);
} else {
-   fprintf(stderr, "ERROR: get_df failed %s\n", strerror(ret));
+   fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret));
}
 
close_file_or_dir(fd, dirstream);
-- 
1.7.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


[PATCH 05/16] btrfs-progs: don't leak fd in test_dev_for_mkfs() error paths

2013-11-06 Thread Eric Sandeen
Close fd before we return on error paths.

Resolves-Coverity-CID: 1125939
Signed-off-by: Eric Sandeen 
---
 utils.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/utils.c b/utils.c
index c11a7c2..c784345 100644
--- a/utils.c
+++ b/utils.c
@@ -1905,10 +1905,12 @@ int test_dev_for_mkfs(char *file, int force_overwrite, 
char *estr)
if (fstat(fd, &st)) {
snprintf(estr, sz, "unable to stat %s: %s\n", file,
strerror(errno));
+   close(fd);
return 1;
}
if (!S_ISBLK(st.st_mode)) {
fprintf(stderr, "'%s' is not a block device\n", file);
+   close(fd);
return 1;
}
close(fd);
-- 
1.7.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


[PATCH 02/16] btrfs-progs: fix error returns in get_df()

2013-11-06 Thread Eric Sandeen
get_df returns -ERRNO, or maybe (+)errno, or even 0 in
the case where we inexplicably got 0 total_spaces from
the BTRFS_IOC_SPACE_INFO.

Consistently return a negative error number, and return
-ENOENT rather than 0 for total_spaces == 0, so that the
caller will know that **sargs_ret hasn't been set up.

Signed-off-by: Eric Sandeen 
---
 cmds-filesystem.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 0bfd710..e6642ef 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -106,11 +106,12 @@ static int get_df(int fd, struct btrfs_ioctl_space_args 
**sargs_ret)
fprintf(stderr, "ERROR: couldn't get space info - %s\n",
strerror(e));
free(sargs);
-   return ret;
+   return -e;
}
+   /* This really should never happen */
if (!sargs->total_spaces) {
free(sargs);
-   return 0;
+   return -ENOENT;
}
count = sargs->total_spaces;
free(sargs);
@@ -128,7 +129,7 @@ static int get_df(int fd, struct btrfs_ioctl_space_args 
**sargs_ret)
fprintf(stderr, "ERROR: get space info count %llu - %s\n",
count, strerror(e));
free(sargs);
-   return ret;
+   return -e;
}
*sargs_ret = sargs;
return 0;
-- 
1.7.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


[PATCH 09/16] btrfs-progs: btrfs_scan_kernel(): fd==0 is not an error

2013-11-06 Thread Eric Sandeen
The error return from open is -1, so test that, not 0,
for success/failure.

Resolves-Coverity-CID: 1125931
Signed-off-by: Eric Sandeen 
---
 cmds-filesystem.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index e6642ef..df9d1ff 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -362,13 +362,13 @@ static int btrfs_scan_kernel(void *search)
}
 
fd = open(mnt->mnt_dir, O_RDONLY);
-   if (fd > 0 && !get_df(fd, &space_info_arg)) {
+   if ((fd != -1) && !get_df(fd, &space_info_arg)) {
get_label_mounted(mnt->mnt_dir, label);
print_one_fs(&fs_info_arg, dev_info_arg,
space_info_arg, label, mnt->mnt_dir);
free(space_info_arg);
}
-   if (fd > 0)
+   if (fd != -1)
close(fd);
free(dev_info_arg);
}
-- 
1.7.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


[PATCH 13/16] btrfs-progs: check btrfs_scan_one_device in btrfs_scan_lblkid()

2013-11-06 Thread Eric Sandeen
Even if it's "definitely" btrfs at this point,
btrfs_scan_one_device could fail for other reasons.

Check the return value, warn if it fails, and skip
the device register.

Resolves-Coverity-CID: 1125925
Signed-off-by: Eric Sandeen 
---
 utils.c |9 -
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/utils.c b/utils.c
index 8471148..ecacc29 100644
--- a/utils.c
+++ b/utils.c
@@ -1937,6 +1937,7 @@ int test_skip_this_disk(char *path)
 int btrfs_scan_lblkid(int update_kernel)
 {
int fd = -1;
+   int ret;
u64 num_devices;
struct btrfs_fs_devices *tmp_devices;
blkid_dev_iterate iter = NULL;
@@ -1965,8 +1966,14 @@ int btrfs_scan_lblkid(int update_kernel)
printf("ERROR: could not open %s\n", path);
continue;
}
-   btrfs_scan_one_device(fd, path, &tmp_devices,
+   ret = btrfs_scan_one_device(fd, path, &tmp_devices,
&num_devices, BTRFS_SUPER_INFO_OFFSET);
+   if (ret) {
+   printf("ERROR: could not scan %s\n", path);
+   close (fd);
+   continue;
+   }
+
close(fd);
if (update_kernel)
btrfs_register_one_device(path);
-- 
1.7.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


[PATCH 15/16] btrfs-progs: annotate fallthroughs in parse_size

2013-11-06 Thread Eric Sandeen
We intentionally fall through these case statements;
just annotate it to be clear.

Resolves-Coverity-CID: 1054887
Signed-off-by: Eric Sandeen 
---
 utils.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/utils.c b/utils.c
index ecacc29..9aeb5f8 100644
--- a/utils.c
+++ b/utils.c
@@ -1499,16 +1499,22 @@ u64 parse_size(char *s)
switch (c) {
case 'e':
mult *= 1024;
+   /* fallthrough */
case 'p':
mult *= 1024;
+   /* fallthrough */
case 't':
mult *= 1024;
+   /* fallthrough */
case 'g':
mult *= 1024;
+   /* fallthrough */
case 'm':
mult *= 1024;
+   /* fallthrough */
case 'k':
mult *= 1024;
+   /* fallthrough */
case 'b':
break;
default:
-- 
1.7.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


[PATCH 00/16] btrfs-progs: Several more static analysis defect fixes

2013-11-06 Thread Eric Sandeen
These all apply to the integration branch in Chris's current git tree.
(Which saw the defects rise by from 55 to 65 in the last l6 commits :()

This beats back the defect count again.  Compile tested only, FWIW.

Thanks,
-Eric


--
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 01/16] btrfs-progs: fix potential double-frees in cmd_subvol_delete()

2013-11-06 Thread Eric Sandeen
If we "goto again" in cmd_subvol_delete(), and error out to out:
before re-allocating the dupdname and dupvname pointers, we'll
double-free them.

Set them to NULL after freeing to avoid this.

Resolves-Coverity-CID: 1125944
Resolves-Coverity-CID: 1125945
Signed-off-by: Eric Sandeen 
---
 cmds-subvolume.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 63c708e..89b90cf 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -288,6 +288,8 @@ again:
 out:
free(dupdname);
free(dupvname);
+   dupdname = NULL;
+   dupvname = NULL;
cnt++;
if (cnt < argc)
goto again;
-- 
1.7.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


[PATCH 03/16] btrfs-progs: use strncpy in btrfs_scan_lblkid()

2013-11-06 Thread Eric Sandeen
Use strncpy(... ,PATH_MAX) to be sure we don't overflow
the path[PATH_MAX] array.

Resolves-Coverity-CID: 1125941
Signed-off-by: Eric Sandeen 
---
 utils.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/utils.c b/utils.c
index a7441c1..c11a7c2 100644
--- a/utils.c
+++ b/utils.c
@@ -1952,7 +1952,7 @@ int btrfs_scan_lblkid(int update_kernel)
if (!dev)
continue;
/* if we are here its definitly a btrfs disk*/
-   strcpy(path, blkid_dev_devname(dev));
+   strncpy(path, blkid_dev_devname(dev), PATH_MAX);
if (test_skip_this_disk(path))
continue;
 
-- 
1.7.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


Fwd: unable to delete files after kernel upgrade from 3.8.10 to 3.12

2013-11-06 Thread Bartosz Kulicki
Hi,

As per subject. Seems UUID tree creation failed after upgrade. I could
not mount filesystem under 3.12. Going back to 3.8.10 allowed me to
mount fs but I could no longer perform any deletes, writes etc.

I've opened a bug report here.
https://bugzilla.kernel.org/show_bug.cgi?id=64461

I've included link to image captured with btrfs-image.

Please CC me if further information is needed as I'm not subscribed to
the mailing list.

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


[PATCH v2] btrfs:check-integrity.c: replace kmalloc with kmalloc_array and kzalloc with kzalloc_array.

2013-11-06 Thread Himangi Saraogi
This patch replaces kmalloc(size * nr, ) with kmalloc_array(nr, size)
as kmalloc_array() is preferred because it can check that the
calculation doesn't wrap and won't return a smaller allocation.
Also kzalloc(size * nr) was replaced with kzalloc_array().

Signed-off-by: Himangi Saraogi 
---
 fs/btrfs/check-integrity.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 1c47be1..925a52b 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -1660,9 +1660,10 @@ static int btrfsic_read_block(struct btrfsic_state 
*state,
 
num_pages = (block_ctx->len + (u64)PAGE_CACHE_SIZE - 1) >>
PAGE_CACHE_SHIFT;
-   block_ctx->mem_to_free = kzalloc((sizeof(*block_ctx->datav) +
- sizeof(*block_ctx->pagev)) *
-num_pages, GFP_NOFS);
+   block_ctx->mem_to_free = kzalloc_array(num_pages,
+   (sizeof(*block_ctx->datav) +
+sizeof(*block_ctx->pagev)),
+   GFP_NOFS);
if (!block_ctx->mem_to_free)
return -1;
block_ctx->datav = block_ctx->mem_to_free;
@@ -3031,8 +3032,9 @@ void btrfsic_submit_bio(int rw, struct bio *bio)
   (unsigned long long)bio->bi_sector, dev_bytenr,
   bio->bi_bdev);
 
-   mapped_datav = kmalloc(sizeof(*mapped_datav) * bio->bi_vcnt,
-  GFP_NOFS);
+   mapped_datav = kmalloc_array(bio->bi_vcnt,
+sizeof(*mapped_datav),
+GFP_NOFS);
if (!mapped_datav)
goto leave;
for (i = 0; i < bio->bi_vcnt; i++) {
-- 
1.7.9.5

--
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 4/4] btrfs-progs: lblkid wouldn't find non mapper path input

2013-11-06 Thread Josef Bacik
On Mon, Nov 04, 2013 at 11:45:45AM +0800, Anand Jain wrote:
> A new test case when disk is unmounted and if the non mapper
> disk path is given as the argument to the btrfs filesystem show 
> we still need this to work but lblkid will pull only mapper disks,
> it won't match. So this will normalize the input to find btrfs
> by fsid and pass it to the search.
> 
> v2: accepts Josef suggested
> 
> Signed-off-by: Anand Jain 
> ---
>  cmds-filesystem.c |   59 +---
>  1 files changed, 55 insertions(+), 4 deletions(-)
> 
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index f8e8475..f40178a 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -37,6 +37,7 @@
>  #include "version.h"
>  #include "commands.h"
>  #include "list_sort.h"
> +#include "disk-io.h"
>  
>  static const char * const filesystem_cmd_group_usage[] = {
>   "btrfs filesystem []  []",
> @@ -414,6 +415,39 @@ static int btrfs_scan_kernel(void *search)
>   return 0;
>  }
>  
> +static int dev_to_fsid(char *dev, __u8 *fsid)
> +{
> + struct btrfs_super_block *disk_super;
> + char *buf;
> + int ret;
> + int fd;
> +
> + buf = malloc(4096);
> + if (!buf)
> + return -ENOMEM;
> +
> + fd = open(dev, O_RDONLY);
> + if (fd < 0) {
> + ret = -errno;
> + free(buf);
> + return ret;
> + }
> +
> + disk_super = (struct btrfs_super_block *)buf;
> + ret = btrfs_read_dev_super(fd, disk_super,
> + BTRFS_SUPER_INFO_OFFSET);
> + if (ret)
> + goto out;
> +
> + memcpy(fsid, disk_super->fsid, BTRFS_FSID_SIZE);
> + ret = 0;
> +
> +out:
> + close(fd);
> + free(buf);
> + return ret;
> +}
> +
>  static const char * const cmd_show_usage[] = {
>   "btrfs filesystem show [options] [|||label]",
>   "Show the structure of a filesystem",
> @@ -434,6 +468,8 @@ static int cmd_show(int argc, char **argv)
>   int type = 0;
>   char mp[BTRFS_PATH_NAME_MAX + 1];
>   char path[PATH_MAX];
> + __u8 fsid[BTRFS_FSID_SIZE];
> + char uuid_buf[37];
>  
>   while (1) {
>   int long_index;
> @@ -466,6 +502,10 @@ static int cmd_show(int argc, char **argv)
>   if (strlen(search) == 0)
>   usage(cmd_show_usage);
>   type = check_arg_type(search);
> + /*needs spl handling if input arg is block dev
> +  *And if input arg is mount-point just print it
> +  *right away
> + */

Format screwup.  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: [PATCH 3/4 v2] btrfs-progs: fs show should handle if subvol(s) mounted

2013-11-06 Thread Josef Bacik
On Mon, Nov 04, 2013 at 11:45:44AM +0800, Anand Jain wrote:
> as of now with out this patch user would see
> fsinfo per btrfs mount path but which mean multiple
> entry if more than one subvol is mounted of the same
> fsid. so this patch will handle that nicely.
> 
> v2: accepts Zach suggested
> 
> Signed-off-by: Anand Jain 
> ---
>  cmds-filesystem.c |   90 
> +
>  utils.c   |   88 ++-
>  utils.h   |3 +-
>  3 files changed, 130 insertions(+), 51 deletions(-)
> 
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index d2cad81..f8e8475 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -317,6 +317,29 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args 
> *fs_info,
>   return 0;
>  }
>  
> +static void handle_print(char *mnt, char *label)
> +{
> + int fd;
> + struct btrfs_ioctl_fs_info_args fs_info_arg;
> + struct btrfs_ioctl_dev_info_args *dev_info_arg = NULL;
> + struct btrfs_ioctl_space_args *space_info_arg;
> +
> + if (get_fs_info(mnt, &fs_info_arg, &dev_info_arg)) {
> + fprintf(stdout, "ERROR: get_fs_info failed\n");
> + return;
> + }
> +
> + fd = open(mnt, O_RDONLY);
> + if (fd > 0 && !get_df(fd, &space_info_arg)) {

0 is a valid fd.  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: [PATCH 2/4 v2] btrfs-progs: mechanism to fetch fsinfo from btrfs-control

2013-11-06 Thread Josef Bacik
On Mon, Nov 04, 2013 at 11:45:43AM +0800, Anand Jain wrote:
> need fsinfo from btrfs-control that is when mount path is
> not known.
> current method of going through each mount points isn't
> efficient, and multiple subvol of a fsid could be mounted
> means extra logic to handle that. Further this will help
> to revamp check_mounted() (planned)
> 
> check_mounted is heavily used in the btrfs-progs, it
> does full scan of all the disks in the system to confirm
> if a multi-disk btrfs is mounted it doesn't scalable well
> with few hundreds luns, check_mounted for sure needs a
> revamp. using this it can be done easily. which is planned.
> 
> v2: commit reword
> 
> Signed-off-by: Anand Jain 
> ---
>  ioctl.h |   19 +++
>  utils.c |   80 
> +++
>  utils.h |1 +
>  3 files changed, 100 insertions(+), 0 deletions(-)
> 
> diff --git a/ioctl.h b/ioctl.h
> index d21413f..29575d8 100644
> --- a/ioctl.h
> +++ b/ioctl.h
> @@ -506,6 +506,23 @@ static inline char *btrfs_err_str(enum btrfs_err_code 
> err_code)
>   }
>  }
>  
> +/* fs flags */
> +#define BTRFS_FS_MOUNTED (1LLU << 0)
> +
> +struct btrfs_ioctl_fslist {
> + __u64 self_sz;  /* in/out */
> + __u8 fsid[BTRFS_FSID_SIZE]; /* out */
> + __u64 num_devices;
> + __u64 missing_devices;
> + __u64 total_devices;
> + __u64 flags;
> +};
> +
> +struct btrfs_ioctl_fslist_args {
> + __u64 self_sz;  /* in/out */
> + __u64 count;/* out */
> +};
> +
>  #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
>  struct btrfs_ioctl_vol_args)
>  #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
> @@ -604,6 +621,8 @@ struct btrfs_ioctl_clone_range_args {
>   struct btrfs_ioctl_dev_replace_args)
>  #define BTRFS_IOC_DEDUP_CTL _IOWR(BTRFS_IOCTL_MAGIC, 55, \
> struct btrfs_ioctl_dedup_args)
> +#define BTRFS_IOC_GET_FSLIST _IOWR(BTRFS_IOCTL_MAGIC, 56, \
> + struct btrfs_ioctl_fslist_args)
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/utils.c b/utils.c
> index 5bedd97..1798a7c 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -2087,3 +2087,83 @@ int lookup_ino_rootid(int fd, u64 *rootid)
>  
>   return 0;
>  }
> +
> +/* scans for fsid(s) in the kernel using the btrfs-control
> + * interface.
> + */
> +int get_fslist(struct btrfs_ioctl_fslist **out_fslist, int *out_count)
> +{
> + int ret, fd, e;
> + struct btrfs_ioctl_fslist_args *fsargs;
> + struct btrfs_ioctl_fslist *fslist;
> + struct btrfs_ioctl_fslist *fslist_tmp;
> + u64 sz;
> + int count;
> +
> + fd = open("/dev/btrfs-control", O_RDWR);
> + e = errno;
> + if (fd < 0) {
> + perror("failed to open /dev/btrfs-control");
> + return -e;
> + }
> +
> + /* space to hold 512 fsids, doesn't matter if small
> +  * it would fail and return count so then we try again
> +  */
> + count = 512;
> +again:
> + sz = sizeof(*fsargs) + sizeof(*fslist) * count;
> +
> + fsargs = (struct btrfs_ioctl_fslist_args *) malloc(sz);

No need to cast the return value of malloc.

> + memset(fsargs, 0, sz);
> +
> + if (!fsargs) {
> + close(fd);
> + return -ENOMEM;
> + }

Should check !fsargs before memsetting it.

> + fsargs->count = count;
> +
> + ret = ioctl(fd, BTRFS_IOC_GET_FSLIST, fsargs);
> + e = errno;
> + if (ret == 1) {
> + /* out of size so reallocate */
> + count = fsargs->count;
> + free(fsargs);
> + goto again;
> + } else if (ret < 0) {
> + printf("ERROR: scan_fsid ioctl failed - %s\n",
> + strerror(e));
> + ret = -e;
> + goto out;
> + }
> +
> + /* ioctl returns fsid count in count parameter*/
> +
> + *out_count = count = fsargs->count;
> + if (count == 0) {
> + *out_fslist = NULL;
> + ret = 0;
> + goto out;
> + }
> +
> + fslist = (struct btrfs_ioctl_fslist *) (fsargs +
> + sizeof(*fsargs));
> +
> + fslist_tmp = *out_fslist = (struct btrfs_ioctl_fslist *)
> + malloc(sizeof(*fslist) * count);

No need to cast.  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: [PATCH v3] xfstests: add regression test for running btrfs balance and defrag concurrently

2013-11-06 Thread David Sterba
On Thu, Oct 31, 2013 at 05:34:22PM +0800, Liu Bo wrote:
> The test aims to trigger snapshot-aware defrag path in write endio by
> running balance, which is not expected and leads to a crash.
> 
> Signed-off-by: Liu Bo 

Reviewed-by: David Sterba 
--
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:check-integrity.c: replace kmalloc with kmalloc_array

2013-11-06 Thread David Sterba
On Fri, Nov 01, 2013 at 06:16:00AM +0530, Himangi Saraogi wrote:
> This patch replaces kmalloc(size * nr, ) with kmalloc_array(nr, size)
> as kmalloc_array() is preferred because it can check that the
> calculation doesn't wrap and won't return a smaller allocation.

Can you please convert all the instances in one patch? Feel free to use
the following cocinelle script, that found ~16 places that could use
the conversion.

$ cat kmalloc_array.cocci
@ @
expression E1, E2, E3;
@@

* \(kmalloc\|kzalloc\)(E1 * E2, E3)
---

The output is not a straight patch, the instances have to be reviewed manually
because the order of nritems and size may differ at each location.

david
--
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: fix negative qgroup tracking from owner accounting (bug #61951)

2013-11-06 Thread Josef Bacik
On Wed, Nov 06, 2013 at 06:20:47PM +0100, Jan Schmidt wrote:
>  
> On Mon, November 04, 2013 at 18:42 (+0100), Josef Bacik wrote:
> > On Thu, Oct 24, 2013 at 03:22:06PM +0200, Jan Schmidt wrote:
> >> btrfs_dec_ref() queued a delayed ref for owner of a tree block. The qgroup
> >> tracking is based on delayed refs. The owner of a tree block is set when a
> >> tree block is allocated, it is never updated.
> >>
> >> When you allocate a tree block and then remove the subvolume that did the
> >> allocation, the qgroup accounting for that removal is correct. However, the
> >> removal was accounted again for each subvolume deletion that also 
> >> referenced
> >> the tree block, because accounting was erroneously based on the owner.
> >>
> >> Instead of queueing delayed refs for the non-existent owner, we now
> >> queue delayed refs for the root being removed. This fixes the qgroup
> >> accounting.
> >>
> >> Signed-off-by: Jan Schmidt 
> >> Tested-by: 
> > 
> > This breaks btrfs/003, I'm kicking it out.
> 
> Can you be a bit more specific? Works fine here.
> 

It's blowing up on the balance, so maybe make a bigger fs and balance that so
you can see it?  It's exploding in __btrfs_free_extent because we can't find the
ref we're trying to drop, so I assume you've broken the dropping of the reloc
root part where it depends on you giving it btrfs_header_owner() instead of
root->root_key.objectid as when we cow blocks that belong to the reloc root we
leave the owner set to whoever owned the block originally and not the reloc
root.  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: [PATCH] Btrfs: fix negative qgroup tracking from owner accounting (bug #61951)

2013-11-06 Thread Jan Schmidt
 
On Mon, November 04, 2013 at 18:42 (+0100), Josef Bacik wrote:
> On Thu, Oct 24, 2013 at 03:22:06PM +0200, Jan Schmidt wrote:
>> btrfs_dec_ref() queued a delayed ref for owner of a tree block. The qgroup
>> tracking is based on delayed refs. The owner of a tree block is set when a
>> tree block is allocated, it is never updated.
>>
>> When you allocate a tree block and then remove the subvolume that did the
>> allocation, the qgroup accounting for that removal is correct. However, the
>> removal was accounted again for each subvolume deletion that also referenced
>> the tree block, because accounting was erroneously based on the owner.
>>
>> Instead of queueing delayed refs for the non-existent owner, we now
>> queue delayed refs for the root being removed. This fixes the qgroup
>> accounting.
>>
>> Signed-off-by: Jan Schmidt 
>> Tested-by: 
> 
> This breaks btrfs/003, I'm kicking it out.

Can you be a bit more specific? Works fine here.

-Jan
--
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: [RFC PATCH] Btrfs: change ioctl number of BTRFS_IOC_START_SYNC to 21

2013-11-06 Thread David Sterba
On Wed, Nov 06, 2013 at 10:42:35AM +0100, Stefan Behrens wrote:
> Sharing the ioctl value seems to have happened by mistake and is
> uncommon, but IMHO now it's too late to change this interface just for
> esthetical reasons.

Agreed, it's part of ABI, ioctl.h is "append only".
--
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 00/13] [PATCH 00/13] sysfs publishing patchset (v2)

2013-11-06 Thread Jeff Mahoney
On 11/6/13, 12:02 PM, David Sterba wrote:
> On Fri, Nov 01, 2013 at 01:06:54PM -0400, Jeff Mahoney wrote:
>> v2: An earlier version had a chunk intended for fs/btrfs/extent-tree.c
>> added as part of patch 13 instead of patch 10, causing build failures.
>>
>> /devices/sdc1
>> /devices/sdd1
>> /label
>> /allocation/data/flags
> ...
>> /allocation/metadata/flags
> ...
> 
> How is the mixed blockgroup setup presented? I guess that the values
> from used_bytes, total_bytes etc would be the same for data and metadata
> and the flags would denote that it's mixed.

No, since that's not how it's represented in the kernel. There's a
single space_info that's used for both, so allocation/data and
allocation/metadata wouldn't exist at all. allocation/mixed would exist
instead.

-Jeff


-- 
Jeff Mahoney
SUSE Labs



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 00/13] [PATCH 00/13] sysfs publishing patchset (v2)

2013-11-06 Thread David Sterba
On Wed, Nov 06, 2013 at 06:02:26PM +0100, David Sterba wrote:
> How is the mixed blockgroup setup presented? I guess that the values
> from used_bytes, total_bytes etc would be the same for data and metadata
> and the flags would denote that it's mixed.

Found, patch [10/13], it's 'mixed', no separate data or metadata
directories. All the combinations of BG types and raid profiles seem to
be covered.

david
--
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 00/13] [PATCH 00/13] sysfs publishing patchset (v2)

2013-11-06 Thread David Sterba
On Fri, Nov 01, 2013 at 01:06:54PM -0400, Jeff Mahoney wrote:
> v2: An earlier version had a chunk intended for fs/btrfs/extent-tree.c
> added as part of patch 13 instead of patch 10, causing build failures.
> 
> /devices/sdc1
> /devices/sdd1
> /label
> /allocation/data/flags
...
> /allocation/metadata/flags
...

How is the mixed blockgroup setup presented? I guess that the values
from used_bytes, total_bytes etc would be the same for data and metadata
and the flags would denote that it's mixed.

The sysfs hierarchy looks ok to me.

david
--
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: csum failure messages

2013-11-06 Thread David Sterba
On Tue, Nov 05, 2013 at 04:20:58PM -0800, John Williams wrote:
> Is there now a verification test that could detect an issue like this?
> It seems like the sort of thing that needs to be added to automated
> testing.

Yes there is:

xfstests/btrfs/013
https://bugzilla.kernel.org/show_bug.cgi?id=63411
--
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: don't wait for ordered data outside desired range

2013-11-06 Thread Filipe David Borba Manana
In btrfs_wait_ordered_range(), if we found an extent to the left
of the start of our desired wait range and the last byte of that
extent is 1 less than the desired range's start, we would would
wait for the IO completion of that extent unnecessarily.

Signed-off-by: Filipe David Borba Manana 
---
 fs/btrfs/ordered-data.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 25a8f38..c37124b 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -803,7 +803,7 @@ int btrfs_wait_ordered_range(struct inode *inode, u64 
start, u64 len)
btrfs_put_ordered_extent(ordered);
break;
}
-   if (ordered->file_offset + ordered->len < start) {
+   if (ordered->file_offset + ordered->len <= start) {
btrfs_put_ordered_extent(ordered);
break;
}
-- 
1.7.9.5

--
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: 3.11.5 kernel infinite loop

2013-11-06 Thread Duncan
Russell Coker posted on Wed, 06 Nov 2013 12:52:38 +1100 as excerpted:

> I have a system running the Debian package of 3.11.5 with an Amd Opteron
> 1212 processor (2*64bit cores), 8G of RAM, and an Intel 120G SSD for the
> root and home subvols.  It has a RAID-1 array of 2*3TB disks for bulk
> storage (movies etc) but that probably isn't relevant to this problem.
> 
> On the root filesystem I have cron jobs making daily snapshots of / and
> /home and additional snapshots of /home every 15 minutes.  At midnight a
> cron job removes older snapshots.  For the last 8 days the system has
> been reliably hanging at about 5 minutes after midnight and the subvol
> removal cron job is the only thing that has happened then.

I believe there's a btrfs-critical stable-series patch in 3.11.6, that 
you're probably missing with 3.11.5.  (There were unfortunately some 
crossed signals and the patch was skipped for a couple weeks after it 
should have gone in, but it's in now.)

Yes... Just checked the 3.11.6 changelog:

Josef Bacik (1):
  Btrfs: use right root when checking for hash collision


Note that there's another critical patch in-flight, patching a bug 
triggered by btrfs balance on filesystems with pre-allocated files (like 
systemd does with its journal and various torrent clients do with their 
downloads).  But this one is currently being held up because stable rules 
require it to be in current mainline first, and 3.12 is out, but the two-
week 3.13 commit window that would normally be open now is suspended for 
a week, as Linux is traveling without a reliable net connection.  So the 
patch can't hit mainline, and thus won't hit stable unless an exception 
is made, until after Linus' vacation, when the commit window opens and 
the patch is accepted.

See previous discussion here on this list for it, or simply don't do any 
balances if you're running systemd or with any other pre-allocated-file 
apps such as torrent clients running, until after you get that patch.

-- 
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman

--
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: csum failure messages

2013-11-06 Thread Duncan
John Williams posted on Tue, 05 Nov 2013 16:20:58 -0800 as excerpted:

> Is there now a verification test that could detect an issue like this?
> It seems like the sort of thing that needs to be added to automated
> testing.

[Your question is general enough, not mentioning xfs-tests, simply asking 
about general automated testing, I'm assuming a general answer is 
appropriate.]

I haven't tracked this specific issue, but in general, the btrfs devs are 
pretty strict with adding an xfs-tests (NOT used for just xfs, at least 
btrfs and ext4 use it too) package test for any regressions they find, 
and people ARE regularly running those tests on new code, so past issues 
don't happen again.  

If you watch the list you'll see occasional patch rejections due to 
failed xfs-tests, as well as regular new xfs-tests patches adding new 
tests, as well as review discussion requesting an xfs-test be added as 
appropriate.

So I'd be /very/ surprised if this bugfix didn't already have a 
corresponding new xfs-tests test.

-- 
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman

--
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 v6] Btrfs: fix memory leak of orphan block rsv

2013-11-06 Thread Filipe David Manana
On Mon, Nov 4, 2013 at 12:16 PM, Alex Lyakas
 wrote:
> Hi Filipe,
> any luck with this patch?:)

Hey Alex,

I haven't digged further, but I remember I couldn't reproduce your
issue (with latest btrfs-next of that day) of getting the free space
inodes created even when mount option nospace_cache is given.

What kernel were you using?

>
> Alex.
>
> On Wed, Oct 23, 2013 at 5:26 PM, Filipe David Manana  
> wrote:
>> On Wed, Oct 23, 2013 at 3:14 PM, Alex Lyakas
>>  wrote:
>>> Hello,
>>>
>>> On Wed, Oct 23, 2013 at 4:35 PM, Filipe David Manana  
>>> wrote:
 On Wed, Oct 23, 2013 at 2:33 PM, Alex Lyakas
  wrote:
> Hi Filipe,
>
>
> On Tue, Aug 20, 2013 at 2:52 AM, Filipe David Borba Manana
>  wrote:
>>
>> This issue is simple to reproduce and observe if kmemleak is enabled.
>> Two simple ways to reproduce it:
>>
>> ** 1
>>
>> $ mkfs.btrfs -f /dev/loop0
>> $ mount /dev/loop0 /mnt/btrfs
>> $ btrfs balance start /mnt/btrfs
>> $ umount /mnt/btrfs
>>>
>>> So here it seems that the leak can only happen in case the block-group
>>> has a free-space inode. This is what the orphan item is added for.
>>> Yes, here kmemleak reports.
>>> But: if space_cache option is disabled (and nospace_cache) enabled, it
>>> seems that btrfs still creates the FREE_SPACE inodes, although they
>>> are empty because in cache_save_setup:
>>>
>>> inode = lookup_free_space_inode(root, block_group, path);
>>> if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) {
>>> ret = PTR_ERR(inode);
>>> btrfs_release_path(path);
>>> goto out;
>>> }
>>>
>>> if (IS_ERR(inode)) {
>>> ...
>>> ret = create_free_space_inode(root, trans, block_group, path);
>>>
>>> and only later it actually sets BTRFS_DC_WRITTEN if space_cache option
>>> is disabled. Amazing!
>>> Although this is a different issue, do you know perhaps why these
>>> empty inodes are needed?
>>
>> Don't know if they are needed. But you have a point, it seems odd to
>> create the free space cache inode if mount option nospace_cache was
>> supplied. Thanks Alex. Testing the following patch:
>>
>> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
>> index c43ee8a..eb1b7da 100644
>> --- a/fs/btrfs/extent-tree.c
>> +++ b/fs/btrfs/extent-tree.c
>> @@ -3162,6 +3162,9 @@ static int cache_save_setup(struct
>> btrfs_block_group_cache *block_group,
>> int retries = 0;
>> int ret = 0;
>>
>> +   if (!btrfs_test_opt(root, SPACE_CACHE))
>> +   return 0;
>> +
>> /*
>>  * If this block group is smaller than 100 megs don't bother caching 
>> the
>>  * block group.
>>
>>
>>>
>>> Thanks!
>>> Alex.
>>>
>>>
>>>
>>
>> ** 2
>>
>> $ mkfs.btrfs -f /dev/loop0
>> $ mount /dev/loop0 /mnt/btrfs
>> $ touch /mnt/btrfs/foobar
>> $ rm -f /mnt/btrfs/foobar
>> $ umount /mnt/btrfs
>
>
> I tried the second repro script on kernel 3.8.13, and kmemleak does
> not report a leak (even if I force the kmemleak scan). I did not try
> the balance-repro script, though. Am I missing something?

 Maybe it's not an issue on 3.8.13 and older releases.
 This was on btrfs-next from August 19.

 thanks for testing

>
> Thanks,
> Alex.
>
>
>>
>>
>> After a while, kmemleak reports the leak:
>>
>> $ cat /sys/kernel/debug/kmemleak
>> unreferenced object 0x880402b13e00 (size 128):
>>   comm "btrfs", pid 19621, jiffies 4341648183 (age 70057.844s)
>>   hex dump (first 32 bytes):
>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
>> 00 fc c6 b1 04 88 ff ff 04 00 04 00 ad 4e ad de  .N..
>>   backtrace:
>> [] kmemleak_alloc+0x26/0x50
>> [] kmem_cache_alloc_trace+0xeb/0x1d0
>> [] btrfs_alloc_block_rsv+0x39/0x70 [btrfs]
>> [] btrfs_orphan_add+0x13d/0x1b0 [btrfs]
>> [] btrfs_remove_block_group+0x143/0x500 [btrfs]
>> [] btrfs_relocate_chunk.isra.63+0x618/0x790 [btrfs]
>> [] btrfs_balance+0x8f7/0xe90 [btrfs]
>> [] btrfs_ioctl_balance+0x250/0x550 [btrfs]
>> [] btrfs_ioctl+0xdfa/0x25f0 [btrfs]
>> [] do_vfs_ioctl+0x96/0x570
>> [] SyS_ioctl+0x91/0xb0
>> [] system_call_fastpath+0x16/0x1b
>> [] 0x
>>
>> This affects btrfs-next, revision 
>> be8e3cd00d7293dd177e3f8a4a1645ce09ca3acb
>> (Btrfs: separate out tests into their own directory).
>>
>> Signed-off-by: Filipe David Borba Manana 
>> ---
>>
>> V2: removed atomic_t member in struct btrfs_block_rsv, as suggested by
>> Josef Bacik, and use instead the condition reserved == 0 to decide
>> when to free the block.
>> V3: simplified patch, just kfree() (and not btrfs_free_block_rsv) the
>> root's orphan_block_rsv when free'ing the root. Thanks Josef for
>> the suggestion.
>>

[PATCH] Btrfs-progs: set return value to 0 if subvolume get-default successfully

2013-11-06 Thread Eryu Guan
cmd_subvol_get_default() returns 1 even if finds default subvolume
successfully.

Set the correct return value.

Signed-off-by: Eryu Guan 
---
 cmds-subvolume.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index f7249f8..8be6df7 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -691,6 +691,7 @@ static int cmd_subvol_get_default(int argc, char **argv)
/* no need to resolve roots if FS_TREE is default */
if (default_id == BTRFS_FS_TREE_OBJECTID) {
printf("ID 5 (FS_TREE)\n");
+   ret = 0;
goto out;
}
 
-- 
1.8.3.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


Re: [RFC PATCH] Btrfs: change ioctl number of BTRFS_IOC_START_SYNC to 21

2013-11-06 Thread Stefan Behrens
On Wed,  6 Nov 2013 17:01:19 +0800, Liu Bo wrote:
> 24 has been assigned to both BTRFS_IOC_START_SYNC and 
> BTRFS_IOC_SUBVOL_CREATE_V2,
> and BTRFS_IOC_SUBVOL_CREATE_V2 is at least used in btrfs-progs
> while BTRFS_IOC_START_SYNC is not.
> 
> 21 is free according to link[1], and seems safe to be assigned to 
> BTRFS_IOC_START_SYNC.
> 
> [1]:
> https://btrfs.wiki.kernel.org/index.php/Project_ideas
> 
> Signed-off-by: Liu Bo 
> ---
>  include/uapi/linux/btrfs.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
> index 45e6189..0f5a1af 100644
> --- a/include/uapi/linux/btrfs.h
> +++ b/include/uapi/linux/btrfs.h
> @@ -552,7 +552,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code 
> err_code)
>  #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
>  #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
>   struct btrfs_ioctl_space_args)
> -#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
> +#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 21, __u64)
>  #define BTRFS_IOC_WAIT_SYNC  _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
>  #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
>  struct btrfs_ioctl_vol_args_v2)
> 

You don't _have to_ eliminate the duplicated use of the value 24, the
directions are different and the parameter sizes are different,
therefore these ioctls can be distinguished.

Sharing the ioctl value seems to have happened by mistake and is
uncommon, but IMHO now it's too late to change this interface just for
esthetical reasons.

--
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: change ioctl number of BTRFS_IOC_START_SYNC to 21

2013-11-06 Thread Liu Bo
24 has been assigned to both BTRFS_IOC_START_SYNC and 
BTRFS_IOC_SUBVOL_CREATE_V2,
and BTRFS_IOC_SUBVOL_CREATE_V2 is at least used in btrfs-progs
while BTRFS_IOC_START_SYNC is not.

21 is free according to link[1], and seems safe to be assigned to 
BTRFS_IOC_START_SYNC.

[1]:
https://btrfs.wiki.kernel.org/index.php/Project_ideas

Signed-off-by: Liu Bo 
---
 include/uapi/linux/btrfs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index 45e6189..0f5a1af 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -552,7 +552,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code 
err_code)
 #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
 #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
struct btrfs_ioctl_space_args)
-#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
+#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 21, __u64)
 #define BTRFS_IOC_WAIT_SYNC  _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
   struct btrfs_ioctl_vol_args_v2)
-- 
1.8.1.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


[PATCH] Btrfs: fix lockdep error in async commit

2013-11-06 Thread Liu Bo
Lockdep complains about btrfs's async commit:

[ 2372.462171] [ BUG: bad unlock balance detected! ]
[ 2372.462191] 3.12.0+ #32 Tainted: GW
[ 2372.462209] -
[ 2372.462228] ceph-osd/14048 is trying to release lock (sb_internal) at:
[ 2372.462275] [] btrfs_commit_transaction_async+0x1b0/0x2a0 
[btrfs]
[ 2372.462305] but there are no more locks to release!
[ 2372.462324]
[ 2372.462324] other info that might help us debug this:
[ 2372.462349] no locks held by ceph-osd/14048.
[ 2372.462367]
[ 2372.462367] stack backtrace:
[ 2372.462386] CPU: 2 PID: 14048 Comm: ceph-osd Tainted: GW3.12.0+ 
#32
[ 2372.462414] Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./To 
be filled by O.E.M., BIOS 080015  11/09/2011
[ 2372.462455]  a022cb10 88007490fd28 816f094a 
8800378aa320
[ 2372.462491]  88007490fd50 810adf4c 8800378aa320 
88009af97650
[ 2372.462526]  a022cb10 88007490fd88 810b01ee 
8800898c
[ 2372.462562] Call Trace:
[ 2372.462584]  [] ? 
btrfs_commit_transaction_async+0x1b0/0x2a0 [btrfs]
[ 2372.462619]  [] dump_stack+0x45/0x56
[ 2372.462642]  [] print_unlock_imbalance_bug+0xec/0x100
[ 2372.462677]  [] ? 
btrfs_commit_transaction_async+0x1b0/0x2a0 [btrfs]
[ 2372.462710]  [] lock_release+0x18e/0x210
[ 2372.462742]  [] btrfs_commit_transaction_async+0x1d6/0x2a0 
[btrfs]
[ 2372.462783]  [] btrfs_ioctl_start_sync+0x3e/0xc0 [btrfs]
[ 2372.462822]  [] btrfs_ioctl+0x4c3/0x1f70 [btrfs]
[ 2372.462849]  [] ? avc_has_perm+0x121/0x1b0
[ 2372.462873]  [] ? avc_has_perm+0x24/0x1b0
[ 2372.462897]  [] ? sched_clock_cpu+0xa8/0x100
[ 2372.462922]  [] do_vfs_ioctl+0x2e5/0x4e0
[ 2372.462946]  [] ? file_has_perm+0x86/0xa0
[ 2372.462969]  [] SyS_ioctl+0x81/0xa0
[ 2372.462991]  [] tracesys+0xdd/0xe2


It's because that we don't do the right thing when checking if it's ok to
tell lockdep that we're trying to release the rwsem.

If the trans handle's type is TRANS_ATTACH, we won't acquire the freeze rwsem, 
but
as TRANS_ATTACH fits the check (trans < TRANS_JOIN_NOLOCK), we'll release the 
freeze
rwsem, which makes lockdep complains a lot.

Reported-by: Ma Jianpeng 
Signed-off-by: Liu Bo 
Signed-off-by: Miao Xie 
---
 fs/btrfs/transaction.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 8c81bdc..c094f08 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1453,7 +1453,7 @@ static void do_async_commit(struct work_struct *work)
 * We've got freeze protection passed with the transaction.
 * Tell lockdep about it.
 */
-   if (ac->newtrans->type < TRANS_JOIN_NOLOCK)
+   if (ac->newtrans->type & __TRANS_FREEZABLE)
rwsem_acquire_read(
 &ac->root->fs_info->sb->s_writers.lock_map[SB_FREEZE_FS-1],
 0, 1, _THIS_IP_);
@@ -1494,7 +1494,7 @@ int btrfs_commit_transaction_async(struct 
btrfs_trans_handle *trans,
 * Tell lockdep we've released the freeze rwsem, since the
 * async commit thread will be the one to unlock it.
 */
-   if (trans->type < TRANS_JOIN_NOLOCK)
+   if (ac->newtrans->type & __TRANS_FREEZABLE)
rwsem_release(
&root->fs_info->sb->s_writers.lock_map[SB_FREEZE_FS-1],
1, _THIS_IP_);
-- 
1.8.1.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