15 vtlocaltoglobal \- Venti block cache
27 typedef struct VtBlock
31 uchar score[VtScoreSize];
35 .ta +\w'\fLVtBlock* 'u +\w'\fLxxxxxxxx'u
38 VtCache* vtcachealloc(VtConn *z, ulong maxmem);
41 void vtcachefree(VtCache *c);
44 u32int vtglobaltolocal(uchar score[VtScoreSize])
47 void vtlocaltoglobal(u32int local, uchar score[VtScoreSize])
50 VtBlock* vtcacheallocblock(VtCache *c, int type, ulong size);
53 VtBlock* vtcachelocal(VtCache *c, u32int addr, int type);
56 VtBlock* vtcacheglobal(VtCache *c, uchar[VtScoreSize], int type, ulong size);
59 void vtblockput(VtBlock *b);
62 void vtblockduplock(VtBlock *b);
65 int vtblockwrite(VtBlock *b);
68 void vtcachesetwrite(VtCache *c,
71 int (*write)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
74 VtBlock* vtblockcopy(VtBlock *b);
76 These functions provide access to a simple in-memory
77 cache of blocks already stored on a Venti server
78 and blocks that will eventually be stored on a Venti server.
82 represents a venti data block.
83 Blocks stored on a venti server,
86 are named by the SHA1 hash of their contents.
87 This hash is recorded as the block's
89 Such blocks are immutable.
90 The cache also stores mutable blocks that have not yet been
91 written to a venti server. These blocks are called
93 and have special scores that are 16 zero bytes
94 followed by a 4-byte big-endian
96 The address is an index into the internal set of cache blocks.
98 The user-visible contents of a
102 a pointer to the data;
104 the venti block type;
109 the block's cache address.
112 allocates a new cache using the client connection
117 .IR venti-client (3)),
123 frees a cache and all the associated blocks.
126 returns the local address corresponding to the given
129 If passed a global score,
131 returns the special constant
135 is the opposite, setting
137 to the local score for the cache address
141 allocates a new local block with the given
147 retrieves the local block at address
152 must match the type of the block found at
156 retrieves the block with the given
161 from the cache, consulting the Venti server
163 If passed a local score,
169 The block references returned by
170 .IR vtcacheallocblock ,
174 must be released when no longer needed.
176 releases such a reference.
178 It is occasionally convenient to have multiple variables
179 refer to the same block.
181 increments the block's reference count so that
184 will be required in order to release the block.
187 writes a local block to the Venti server,
188 changing the block to a global block.
192 to write the block to the server.
198 .IR venti-client (3));
202 is used by clients to install replacement functions
203 that run writes in the background or perform other
204 additional processing.
207 copies a block in preparation for modifying its contents.
208 The old block may be a local or global block,
209 but the new block will be a local block.
211 The cache only evicts global blocks.
212 Local blocks can only leave the cache via
214 which turns them into global blocks, making them candidates for
217 If a new cache block must be allocated (for
218 .IR vtcacheallocblock ,
223 but the cache is filled (with local blocks and blocks that
224 have not yet been released with
226 the library prints the score and reference count of
227 every block in the cache and then aborts.
228 A full cache indicates either that the cache is too small,
229 or, more commonly, that cache blocks are being leaked.
234 .IR venti-client (3),