16 vtlocaltoglobal \- Venti block cache
28 typedef struct VtBlock
32 uchar score[VtScoreSize];
36 .ta +\w'\fLVtBlock* 'u +\w'\fLxxxxxxxx'u
39 VtCache* vtcachealloc(VtConn *z, int blocksize, ulong nblocks);
42 void vtcachefree(VtCache *c);
45 u32int vtcacheblocksize(VtCache *c);
48 u32int vtglobaltolocal(uchar score[VtScoreSize])
51 void vtlocaltoglobal(u32int local, uchar score[VtScoreSize])
54 VtBlock* vtcacheallocblock(VtCache *c, int type);
57 VtBlock* vtcachelocal(VtCache *c, u32int addr, int type);
60 VtBlock* vtcacheglobal(VtCache *c, uchar[VtScoreSize], int type);
63 void vtblockput(VtBlock *b);
66 void vtblockduplock(VtBlock *b);
69 int vtblockwrite(VtBlock *b);
72 void vtcachesetwrite(VtCache *c,
75 int (*write)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
78 VtBlock* vtblockcopy(VtBlock *b);
80 These functions provide access to a simple in-memory
81 cache of blocks already stored on a Venti server
82 and blocks that will eventually be stored on a Venti server.
86 represents a venti data block.
87 Blocks stored on a venti server,
90 are named by the SHA1 hash of their contents.
91 This hash is recorded as the block's
93 Such blocks are immutable.
94 The cache also stores mutable blocks that have not yet been
95 written to a venti server. These blocks are called
97 and have special scores that are 16 zero bytes
98 followed by a 4-byte big-endian
100 The address is an index into the internal set of cache blocks.
102 The user-visible contents of a
106 a pointer to the data;
108 the venti block type;
113 the block's cache address.
116 allocates a new cache using the client connection
121 .IR venti-client (3)),
124 of maximum block size
128 frees a cache and all the associated blocks.
131 returns the cache's maximum block size.
134 returns the local address corresponding to the given
137 If passed a global score,
139 returns the special constant
143 is the opposite, setting
145 to the local score for the cache address
149 allocates a new local block with the given
153 retrieves the local block at address
158 must match the type of the block found at
162 retrieves the block with the given
166 from the cache, consulting the Venti server
168 If passed a local score,
174 The block references returned by
175 .IR vtcacheallocblock ,
179 must be released when no longer needed.
181 releases such a reference.
183 It is occasionally convenient to have multiple variables
184 refer to the same block.
186 increments the block's reference count so that
189 will be required in order to release the block.
192 writes a local block to the Venti server,
193 changing the block to a global block.
197 to write the block to the server.
203 .IR venti-client (3));
207 is used by clients to install replacement functions
208 that run writes in the background or perform other
209 additional processing.
212 copies a block in preparation for modifying its contents.
213 The old block may be a local or global block,
214 but the new block will be a local block.
216 The cache only evicts global blocks.
217 Local blocks can only leave the cache via
219 which turns them into global blocks, making them candidates for
222 If a new cache block must be allocated (for
223 .IR vtcacheallocblock ,
228 but the cache is filled (with local blocks and blocks that
229 have not yet been released with
231 the library prints the score and reference count of
232 every block in the cache and then aborts.
233 A full cache indicates either that the cache is too small,
234 or, more commonly, that cache blocks are being leaked.
239 .IR venti-client (3),