Blob


1 .TH VENTI-CACHE 3
2 .SH NAME
3 VtBlock, VtCache,
4 vtblockcopy,
5 vtblockdirty,
6 vtblockduplock,
7 vtblockput,
8 vtblockwrite,
9 vtcachealloc,
10 vtcacheallocblock,
11 vtcacheblocksize,
12 vtcachefree,
13 vtcacheglobal,
14 vtcachelocal,
15 vtcachesetwrite,
16 vtglobaltolocal,
17 vtlocaltoglobal \- Venti block cache
18 .SH SYNOPSIS
19 .ft L
20 #include <u.h>
21 .br
22 #include <libc.h>
23 .br
24 #include <venti.h>
25 .ta +\w'\fLxxxx 'u
26 .PP
27 .ft L
28 .nf
29 typedef struct VtBlock
30 {
31 uchar *data;
32 uchar type;
33 uchar score[VtScoreSize];
34 u32int addr;
35 ...
36 } VtBlock;
37 .ta +\w'\fLVtBlock* 'u +\w'\fLxxxxxxxx'u
38 .PP
39 .B
40 VtCache* vtcachealloc(VtConn *z, int blocksize, ulong nblocks);
41 .PP
42 .B
43 void vtcachefree(VtCache *c);
44 .PP
45 .B
46 u32int vtcacheblocksize(VtCache *c);
47 .PP
48 .B
49 u32int vtglobaltolocal(uchar score[VtScoreSize])
50 .br
51 .B
52 void vtlocaltoglobal(u32int local, uchar score[VtScoreSize])
53 .PP
54 .B
55 VtBlock* vtcacheallocblock(VtCache *c, int type);
56 .PP
57 .B
58 VtBlock* vtcachelocal(VtCache *c, u32int addr, int type);
59 .PP
60 .B
61 VtBlock* vtcacheglobal(VtCache *c, uchar[VtScoreSize], int type);
62 .PP
63 .B
64 void vtblockput(VtBlock *b);
65 .PP
66 .B
67 void vtblockduplock(VtBlock *b);
68 .PP
69 .B
70 int vtblockwrite(VtBlock *b);
71 .PP
72 .B
73 void vtcachesetwrite(VtCache *c,
74 .br
75 .B
76 int (*write)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
77 .PP
78 .B
79 VtBlock* vtblockcopy(VtBlock *b);
80 .PP
81 .B
82 int vtblockdirty(VtBlock *b);
83 .SH DESCRIPTION
84 These functions provide access to a simple in-memory
85 cache of blocks already stored on a Venti server
86 and blocks that will eventually be stored on a Venti server.
87 .PP
88 A
89 .B VtBlock
90 represents a venti data block.
91 Blocks stored on a venti server,
92 called
93 .IR "global blocks" ,
94 are named by the SHA1 hash of their contents.
95 This hash is recorded as the block's
96 .IR score .
97 Such blocks are immutable.
98 The cache also stores mutable blocks that have not yet been
99 written to a venti server. These blocks are called
100 .IR "local blocks" ,
101 and have special scores that are 16 zero bytes
102 followed by a 4-byte big-endian
103 .IR address .
104 The address is an index into the internal set of cache blocks.
105 .PP
106 The user-visible contents of a
107 .B VtBlock
108 are
109 .BR data ,
110 a pointer to the data;
111 .BR type ,
112 the venti block type;
113 .BR score ,
114 the block's score;
115 and
116 .BR addr ,
117 the block's cache address.
118 .PP
119 .I Vtcachealloc
120 allocates a new cache using the client connection
121 .I z
122 (see
123 .IR venti-conn (3)
124 and
125 .IR venti-client (3)),
126 with room for
127 .I nblocks
128 of maximum block size
129 .I blocksize .
130 .PP
131 .I Vtcachefree
132 frees a cache and all the associated blocks.
133 .PP
134 .I Vtcacheblocksize
135 returns the cache's maximum block size.
136 .PP
137 .I Vtglobaltolocal
138 returns the local address corresponding to the given
139 local
140 .IR score .
141 If passed a global score,
142 .I vtglobaltolocal
143 returns the special constant
144 .B NilBlock
145 .RB ( ~0 ).
146 .I Vtlocaltoglobal
147 is the opposite, setting
148 .I score
149 to the local score for the cache address
150 .IR local .
151 .PP
152 .I Vtcacheallocblock
153 allocates a new local block with the given
154 .IR type .
155 .PP
156 .I Vtcachelocal
157 retrieves the local block at address
158 .I addr
159 from the cache.
160 The given
161 .I type
162 must match the type of the block found at
163 .IR addr .
164 .PP
165 .I Vtcacheglobal
166 retrieves the block with the given
167 .I score
168 and
169 .I dtype
170 from the cache, consulting the Venti server
171 if necessary.
172 If passed a local score,
173 .I vtcacheglobal
174 invokes
175 .I vtcachelocal
176 appropriately.
177 .PP
178 The block references returned by
179 .IR vtcacheallocblock ,
180 .IR vtcachelocal ,
181 and
182 .I vtcacheglobal
183 must be released when no longer needed.
184 .I Vtblockput
185 releases such a reference.
186 .PP
187 It is occasionally convenient to have multiple variables
188 refer to the same block.
189 .I Vtblockduplock
190 increments the block's reference count so that
191 an extra
192 .I vtblockput
193 will be required in order to release the block.
194 .PP
195 .I Vtblockwrite
196 writes a local block to the Venti server,
197 changing the block to a global block.
198 It calls the cache's
199 .I write
200 function
201 to write the block to the server.
202 The default
203 .I write
204 function is
205 .I vtwrite
206 (see
207 .IR venti-client (3));
208 .I vtsetcachewrite
209 sets it.
210 .I Vtsetcachewrite
211 is used by clients to install replacement functions
212 that run writes in the background or perform other
213 additional processing.
214 .PP
215 .I Vtblockcopy
216 copies a block in preparation for modifying its contents.
217 The old block may be a local or global block,
218 but the new block will be a local block.
219 .PP
220 The cache only evicts global blocks.
221 Local blocks can only leave the cache via
222 .IR vtblockwrite ,
223 which turns them into global blocks, making them candidates for
224 eviction.
225 .PP
226 If a new cache block must be allocated (for
227 .IR vtcacheallocblock ,
228 .IR vtcachelocal ,
229 .IR vtcacheglobal ,
230 or
231 .IR vtblockcopy ),
232 but the cache is filled (with local blocks and blocks that
233 have not yet been released with
234 .IR vtblockput ),
235 the library prints the score and reference count of
236 every block in the cache and then aborts.
237 A full cache indicates either that the cache is too small,
238 or, more commonly, that cache blocks are being leaked.
239 .SH SOURCE
240 .B \*9/src/libventi
241 .SH SEE ALSO
242 .IR venti (3),
243 .IR venti-client (3),
244 .IR venti-conn (3),
245 .IR venti-file (3),
246 .IR venti (7)