All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs: fix num_start_workers count if we fail to make an alloc
@ 2011-11-18 19:38 Josef Bacik
  2011-11-18 20:20 ` Al Viro
  0 siblings, 1 reply; 4+ messages in thread
From: Josef Bacik @ 2011-11-18 19:38 UTC (permalink / raw)
  To: linux-btrfs, viro

Al pointed out that if we fail to start a worker for whatever reason (ENOMEM
basically), we could leak our count for num_start_workers, and so we'd think we
had more workers than we actually do.  This could cause us to shrink workers
when we shouldn't or not start workers when we should.  So check the return
value and if we failed fix num_start_workers and fallback.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
---
 fs/btrfs/async-thread.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 7ec1409..09ef1b0 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -568,6 +568,7 @@ static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers)
 	struct btrfs_worker_thread *worker;
 	unsigned long flags;
 	struct list_head *fallback;
+	int ret;
 
 again:
 	spin_lock_irqsave(&workers->lock, flags);
@@ -584,7 +585,13 @@ again:
 			workers->num_workers_starting++;
 			spin_unlock_irqrestore(&workers->lock, flags);
 			/* we're below the limit, start another worker */
-			__btrfs_start_workers(workers, 1);
+			ret = __btrfs_start_workers(workers, 1);
+			if (ret) {
+				spin_lock_irqsave(&workers->lock, flags);
+				workers->num_workers_starting--;
+				spin_unlock_irqrestore(&workers->lock, flags);
+				goto fallback;
+			}
 			goto again;
 		}
 	}
-- 
1.7.5.2


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

end of thread, other threads:[~2011-11-19  2:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-18 19:38 [PATCH] Btrfs: fix num_start_workers count if we fail to make an alloc Josef Bacik
2011-11-18 20:20 ` Al Viro
2011-11-19  1:37   ` Al Viro
2011-11-19  2:12     ` Al Viro

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.