]> git.neil.brown.name Git - lafs-utils.git/blob - lib/lafs_cluster_allocate.c
d04240101786a1d96472549080452fef69e21c4f
[lafs-utils.git] / lib / lafs_cluster_allocate.c
1
2 /*
3  * allocate a dirty block to a cluster so we can easily write it
4  * for a flush.
5  *
6  * FIXME
7  * For now, don't sort the blocks and assume that the cluster head
8  * and segment will have adequate room for all blocks.
9  * That is sufficient for mkfs
10  */
11 #include <lafs/lafs.h>
12 #include <stdlib.h>
13 #include "internal.h"
14
15 void lafs_cluster_allocate(struct lafs_blk *b, int cnum)
16 {
17         struct lafs *fs = b->ino->fs;
18         struct lafs_cluster *wc;
19         if (!(b->flags & B_Dirty))
20                 abort();
21         if (!(b->flags & B_Sched))
22                 abort();
23
24         if (!(b->flags & B_Index) && 
25             b->ino->type == TypeInodeFile &&
26             dblk(b)->my_inode &&
27             (dblk(b)->my_inode->iflags & I_Dirty))
28                 lafs_inode_fillblock(dblk(b)->my_inode, b->data);
29
30         if ((b->flags & B_Index) &&
31             b->ino->iblock == iblk(b)) {
32                 /* InoIdx block - cannot write that, must write the
33                  * data block instead */
34                 lafs_dirty_blk(&b->ino->dblock->b);
35                 de_sched(b);
36                 return;
37         }
38
39
40         wc = &fs->wc[cnum];
41
42         if (wc->remaining == 0) {
43                 /* FIXME lafs_cluster_flush(fs, cnum) ?? */
44                 lafs_new_segment(fs, cnum);
45                 if (!wc->remaining)
46                         abort();
47         }
48         wc->remaining--;
49         list_add_tail(&b->leafs, &wc->blocks);
50 }