Blob


1 typedef struct Source Source;
2 typedef struct VacFile VacFile;
3 typedef struct MetaBlock MetaBlock;
4 typedef struct MetaEntry MetaEntry;
5 typedef struct Lump Lump;
6 typedef struct Cache Cache;
7 typedef struct Super Super;
9 enum {
10 NilBlock = (~0UL),
11 MaxBlock = (1UL<<31),
12 };
15 struct VacFS {
16 int ref;
18 /* need a read write lock? */
20 uchar score[VtScoreSize];
21 VacFile *root;
23 VtSession *z;
24 int readOnly;
25 int bsize; /* maximum block size */
26 uvlong qid; /* next qid */
27 Cache *cache;
28 };
31 struct Source {
32 VtLock *lk;
34 Cache *cache; /* immutable */
35 int readOnly; /* immutable */
37 Lump *lump; /* lump containing venti dir entry */
38 ulong block; /* block number within parent: immutable */
39 int entry; /* which entry in the block: immutable */
41 /* most of a VtEntry, except the score */
42 ulong gen; /* generation: immutable */
43 int dir; /* dir flags: immutable */
44 int depth; /* number of levels of pointer blocks */
45 int psize; /* pointer block size: immutable */
46 int dsize; /* data block size: immutable */
47 uvlong size; /* size in bytes of file */
49 int epb; /* dir entries per block = dize/VtEntrySize: immutable */
50 };
52 struct MetaEntry {
53 uchar *p;
54 ushort size;
55 };
57 struct MetaBlock {
58 int maxsize; /* size of block */
59 int size; /* size used */
60 int free; /* free space within used size */
61 int maxindex; /* entries allocated for table */
62 int nindex; /* amount of table used */
63 int unbotch;
64 uchar *buf;
65 };
67 /*
68 * contains a one block buffer
69 * to avoid problems of the block changing underfoot
70 * and to enable an interface that supports unget.
71 */
72 struct VacDirEnum {
73 VacFile *file;
75 ulong block; /* current block */
76 MetaBlock mb; /* parsed version of block */
77 int index; /* index in block */
78 };
80 /* Lump states */
81 enum {
82 LumpFree,
83 LumpVenti, /* on venti server: score > 2^32: just a cached copy */
84 LumpActive, /* active */
85 LumpActiveRO, /* active: read only block */
86 LumpActiveA, /* active: achrived */
87 LumpSnap, /* snapshot: */
88 LumpSnapRO, /* snapshot: read only */
89 LumpSnapA, /* snapshot: achived */
90 LumpZombie, /* block with no pointer to it: waiting to be freed */
92 LumpMax
93 };
95 /*
96 * Each lump has a state and generation
97 * The following invariants are maintained
98 * Each lump has no more than than one parent per generation
99 * For Active*, no child has a parent of a greater generation
100 * For Snap*, there is a snap parent of given generation and there are
101 * no parents of greater gen - implies no children of a greater gen
102 * For *RO, the lump is fixed - no change ca be made - all pointers
103 * are valid venti addresses
104 * For *A, the lump is on the venti server
105 * There are no pointers to Zombie lumps
107 * Transitions
108 * Archiver at generation g
109 * Mutator at generation h
111 * Want to modify a lump
112 * Venti: create new Active(h)
113 * Active(x): x == h: do nothing
114 * Acitve(x): x < h: change to Snap(h-1) + add Active(h)
115 * ActiveRO(x): change to SnapRO(h-1) + add Active(h)
116 * ActiveA(x): add Active(h)
117 * Snap*(x): should not occur
118 * Zombie(x): should not occur
119 * Want to archive
120 * Active(x): x != g: should never happen
121 * Active(x): x == g fix children and free them: move to ActoveRO(g);
122 * ActiveRO(x): x != g: should never happen
123 * ActiveRO(x): x == g: wait until it hits ActiveA or SnapA
124 * ActiveA(x): done
125 * Active(x): x < g: should never happen
126 * Snap(x): x >= g: fix children, freeing all SnapA(y) x == y;
127 * SnapRO(x): wait until it hits SnapA
129 */
132 struct Lump {
133 int ref;
135 Cache *c;
137 VtLock *lk;
139 int state;
140 ulong gen;
142 uchar *data;
143 uchar score[VtScoreSize]; /* score of packet */
144 uchar vscore[VtScoreSize]; /* venti score - when archived */
145 u8int type; /* type of packet */
146 int dir; /* part of a directory - extension of type */
147 u16int asize; /* allocated size of block */
148 Lump *next; /* doubly linked hash chains */
149 Lump *prev;
150 u32int heap; /* index in heap table */
151 u32int used; /* last reference times */
152 u32int used2;
154 u32int addr; /* mutable block address */
155 };