aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vac/dat.h
blob: a468668d612e95e0aa9d9754c31d82457f7d34db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
typedef struct Source Source;
typedef struct VacFile VacFile;
typedef struct MetaBlock MetaBlock;
typedef struct MetaEntry MetaEntry;
typedef struct Lump Lump;
typedef struct Cache Cache;
typedef struct Super Super;

enum {
	NilBlock	= (~0UL),
	MaxBlock	= (1UL<<31),
};


struct VacFS {
	int ref;
	
	/* need a read write lock? */

	uchar score[VtScoreSize];
	VacFile *root;
	
	VtSession *z;
	int readOnly;
	int bsize;		/* maximum block size */
	uvlong qid;		/* next qid */
	Cache *cache;
};


struct Source {
	VtLock *lk;

	Cache *cache;	/* immutable */
	int readOnly;	/* immutable */

	Lump *lump;	/* lump containing venti dir entry */
	ulong block;	/* block number within parent: immutable */
	int entry;	/* which entry in the block: immutable */

	/* most of a VtEntry, except the score */
	ulong gen;	/* generation: immutable */
	int dir;	/* dir flags: immutable */
	int depth;	/* number of levels of pointer blocks */
	int psize;	/* pointer block size: immutable */
	int dsize;	/* data block size: immutable */
	uvlong size;	/* size in bytes of file */

	int epb;	/* dir entries per block = dize/VtEntrySize: immutable */
};

struct MetaEntry {
	uchar *p;
	ushort size;
};

struct MetaBlock {
	int maxsize;		/* size of block */
	int size;		/* size used */
	int free;		/* free space within used size */
	int maxindex;		/* entries allocated for table */
	int nindex;		/* amount of table used */
	int unbotch;
	uchar *buf;
};

/*
 * contains a one block buffer
 * to avoid problems of the block changing underfoot
 * and to enable an interface that supports unget.
 */
struct VacDirEnum {
	VacFile *file;
	
	ulong block;	/* current block */
	MetaBlock mb;	/* parsed version of block */
	int index;	/* index in block */
};

/* Lump states */
enum {
	LumpFree,
	LumpVenti,	/* on venti server: score > 2^32: just a cached copy */
	LumpActive,	/* active */
	LumpActiveRO,	/* active: read only block */
	LumpActiveA,	/* active: achrived */
	LumpSnap,	/* snapshot: */
	LumpSnapRO,	/* snapshot: read only */
	LumpSnapA,	/* snapshot: achived */
	LumpZombie,	/* block with no pointer to it: waiting to be freed */
	
	LumpMax
};

/*
 * Each lump has a state and generation
 * The following invariants are maintained
 * 	Each lump has no more than than one parent per generation
 * 	For Active*, no child has a parent of a greater generation
 *	For Snap*, there is a snap parent of given generation and there are
 *		no parents of greater gen - implies no children of a greater gen
 *	For *RO, the lump is fixed - no change ca be made - all pointers
 *		are valid venti addresses
 *	For *A, the lump is on the venti server
 *	There are no pointers to Zombie lumps
 *
 * Transitions
 *	Archiver at generation g
 *	Mutator at generation h
 *	
 *	Want to modify a lump
 *		Venti: create new Active(h)
 *		Active(x): x == h: do nothing
 *		Acitve(x): x < h: change to Snap(h-1) + add Active(h)
 *		ActiveRO(x): change to SnapRO(h-1) + add Active(h)
 *		ActiveA(x): add Active(h)
 *		Snap*(x): should not occur
 *		Zombie(x): should not occur
 *	Want to archive
 *		Active(x): x != g: should never happen
 *		Active(x): x == g fix children and free them: move to ActoveRO(g);
 *		ActiveRO(x): x != g: should never happen
 *		ActiveRO(x): x == g: wait until it hits ActiveA or SnapA
 *		ActiveA(x): done
 *		Active(x): x < g: should never happen
 *		Snap(x): x >= g: fix children, freeing all SnapA(y) x == y;
 *		SnapRO(x): wait until it hits SnapA
 *
 */


struct Lump {
	int ref;

	Cache *c;

	VtLock *lk;
	
	int state;
	ulong gen;

	uchar 	*data;
	uchar	score[VtScoreSize];	/* score of packet */
	uchar	vscore[VtScoreSize];	/* venti score - when archived */
	u8int	type;			/* type of packet */
	int	dir;			/* part of a directory - extension of type */
	u16int	asize;			/* allocated size of block */
	Lump	*next;			/* doubly linked hash chains */
	Lump	*prev;
	u32int	heap;			/* index in heap table */
	u32int	used;			/* last reference times */
	u32int	used2;

	u32int	addr;			/* mutable block address */
};