From: NeilBrown Date: Tue, 29 Jun 2010 11:24:27 +0000 (+1000) Subject: Rearrange code in lafs_cluster_allocate. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=0abf58cf3fc67f660e82e13543d8efa84466d8ac;p=LaFS.git Rearrange code in lafs_cluster_allocate. There are two loops in lafs_cluster_allocate that I want to combine into one. Need to get some stuff out of the way first. EmptyIndex handling can move up to the other special-case handling - just change writeback_done to iounlock_block. Converting the iolock to writeback and getting a cluster reference can also move up easily. Signed-off-by: NeilBrown --- diff --git a/cluster.c b/cluster.c index 0dcce8f..b0fc84c 100644 --- a/cluster.c +++ b/cluster.c @@ -681,6 +681,28 @@ int lafs_cluster_allocate(struct block *b, int cnum) return 0; } + if (test_bit(B_EmptyIndex, &b->flags)) { + int credits = 0; + if (test_and_set_bit(B_Writeback, &b->flags)) + LAFS_BUG(1, b); + lafs_iounlock_block(b); + lafs_allocated_block(fs, b, 0); + /* FIXME this is common code - make a function?? */ + if (cnum) { + if (test_and_clear_bit(B_Realloc, &b->flags)) + credits++; + LAFS_BUG(test_bit(B_Dirty, &b->flags), b); + } else { + if (test_and_clear_bit(B_Dirty, &b->flags)) + credits++; + if (test_and_clear_bit(B_Realloc, &b->flags)) + credits++; + } + lafs_writeback_done(b); + lafs_space_return(fs, credits); + return 0; + } + if (!test_bit(B_Index, &b->flags) && LAFSI(b->inode)->type == TypeInodeFile) { struct inode *myi = dblk(b)->my_inode; @@ -718,6 +740,14 @@ int lafs_cluster_allocate(struct block *b, int cnum) putref(b, MKREF(leaf)); } + 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) @@ -727,40 +757,14 @@ int lafs_cluster_allocate(struct block *b, int cnum) } if (err) { /* No cleaner segments - this will have to go - * out with a checkpoint + * out with a checkpoint. + * Block is still 'dirty' - just clear writeback flag. */ - lafs_iounlock_block(b); - mutex_unlock(&wc->lock); - return -ENOSPC; - } - - if (test_and_set_bit(B_Writeback, &b->flags)) - LAFS_BUG(1, b); - lafs_iounlock_block(b); - - if (test_bit(B_EmptyIndex, &b->flags)) { - int credits = 0; - lafs_allocated_block(fs, b, 0); - /* FIXME this is common code - make a function?? */ - if (cnum) { - if (test_and_clear_bit(B_Realloc, &b->flags)) - credits++; - LAFS_BUG(test_bit(B_Dirty, &b->flags), b); - } else { - if (test_and_clear_bit(B_Dirty, &b->flags)) - credits++; - if (test_and_clear_bit(B_Realloc, &b->flags)) - credits++; - } - lafs_space_return(fs, credits); lafs_writeback_done(b); + putref(b, MKREF(cluster)); mutex_unlock(&wc->lock); - return 0; + return -ENOSPC; } - /* insert into list ensuring there is enough space - * in cluster head - */ - getref(b, MKREF(cluster)); /* we soon own a reference in the list */ do { int avail; /* see how much room is in cluster.