From 0a758e9a665aca8b4c7cca93e8ad6433c320b22c Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 29 Jun 2010 21:34:24 +1000 Subject: [PATCH] combine two loops in lafs_cluster_allocate There are two loops which try to cluster_flush to get enough space. One calls new_segment, the other assumes cluster_flush will do that, which it might or might not. Combine these into a single loop, and move the handling of error from new_segment closer to the call. Signed-off-by: NeilBrown --- cluster.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/cluster.c b/cluster.c index b0fc84c..abfdb51 100644 --- a/cluster.c +++ b/cluster.c @@ -743,28 +743,9 @@ int lafs_cluster_allocate(struct block *b, int cnum) if (test_and_set_bit(B_Writeback, &b->flags)) LAFS_BUG(1, b); lafs_iounlock_block(b); - /* insert into list ensuring there is enough space - * in cluster head - */ + getref(b, MKREF(cluster)); /* we soon own a reference in the list */ - while (!err && wc->remaining < 2) { - // printk("Call flush - remaining = %d\n", wc->remaining); - if (wc->slhead.b == NULL) - err = new_segment(fs, cnum); - else - cluster_flush(fs, cnum); - } - if (err) { - /* No cleaner segments - this will have to go - * out with a checkpoint. - * Block is still 'dirty' - just clear writeback flag. - */ - lafs_writeback_done(b); - putref(b, MKREF(cluster)); - mutex_unlock(&wc->lock); - return -ENOSPC; - } do { int avail; /* see how much room is in cluster. @@ -788,7 +769,21 @@ int lafs_cluster_allocate(struct block *b, int cnum) if (used < 0) { /* won't fit */ // printk("Wont fit - used = %d\n", used); - cluster_flush(fs, cnum); + if (wc->slhead.b == NULL) { + err = new_segment(fs, cnum); + if (err) { + /* No cleaner segments - this will have to go + * out with a checkpoint. + * Block is still 'dirty' - just clear + * writeback flag. + */ + lafs_writeback_done(b); + putref(b, MKREF(cluster)); + mutex_unlock(&wc->lock); + return -ENOSPC; + } + } else + cluster_flush(fs, cnum); } else lafs_io_wake(b); } while (used < 0); -- 2.39.5