17 vtlocaltoglobal \- Venti block cache
29 typedef struct VtBlock
33 uchar score[VtScoreSize];
37 .ta +\w'\fLVtBlock* 'u +\w'\fLxxxxxxxx'u
40 VtCache* vtcachealloc(VtConn *z, int blocksize, ulong nblocks);
43 void vtcachefree(VtCache *c);
46 u32int vtcacheblocksize(VtCache *c);
49 u32int vtglobaltolocal(uchar score[VtScoreSize])
52 void vtlocaltoglobal(u32int local, uchar score[VtScoreSize])
55 VtBlock* vtcacheallocblock(VtCache *c, int type);
58 VtBlock* vtcachelocal(VtCache *c, u32int addr, int type);
61 VtBlock* vtcacheglobal(VtCache *c, uchar[VtScoreSize], int type);
64 void vtblockput(VtBlock *b);
67 void vtblockduplock(VtBlock *b);
70 int vtblockwrite(VtBlock *b);
73 void vtcachesetwrite(VtCache *c,
76 int (*write)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
79 VtBlock* vtblockcopy(VtBlock *b);
82 int vtblockdirty(VtBlock *b);
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.
90 represents a venti data block.
91 Blocks stored on a venti server,
94 are named by the SHA1 hash of their contents.
95 This hash is recorded as the block's
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
101 and have special scores that are 16 zero bytes
102 followed by a 4-byte big-endian
104 The address is an index into the internal set of cache blocks.
106 The user-visible contents of a
110 a pointer to the data;
112 the venti block type;
117 the block's cache address.
120 allocates a new cache using the client connection
125 .IR venti-client (2)),
128 of maximum block size
132 frees a cache and all the associated blocks.
135 returns the cache's maximum block size.
138 returns the local address corresponding to the given
141 If passed a global score,
143 returns the special constant
147 is the opposite, setting
149 to the local score for the cache address
153 allocates a new local block with the given
157 retrieves the local block at address
162 must match the type of the block found at
166 retrieves the block with the given
170 from the cache, consulting the Venti server
172 If passed a local score,
178 The block references returned by
179 .IR vtcacheallocblock ,
183 must be released when no longer needed.
185 releases such a reference.
187 It is occasionally convenient to have multiple variables
188 refer to the same block.
190 increments the block's reference count so that
193 will be required in order to release the block.
196 writes a local block to the Venti server,
197 changing the block to a global block.
201 to write the block to the server.
207 .IR venti-client (2));
211 is used by clients to install replacement functions
212 that run writes in the background or perform other
213 additional processing.
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.
220 The cache only evicts global blocks.
221 Local blocks can only leave the cache via
223 which turns them into global blocks, making them candidates for
226 If a new cache block must be allocated (for
227 .IR vtcacheallocblock ,
232 but the cache is filled (with local blocks and blocks that
233 have not yet been released with
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.
243 .IR venti-client (2),