typedef struct VtBlock
VtCache*vtcachealloc(VtConn *z, ulong maxmem);
void vtcachefree(VtCache *c);
u32int vtglobaltolocal(uchar score[VtScoreSize])
void vtlocaltoglobal(u32int local, uchar score[VtScoreSize])
VtBlock*vtcacheallocblock(VtCache *c, int type, ulong size);
VtBlock*vtcachelocal(VtCache *c, u32int addr, int type);
VtBlock*vtcacheglobal(VtCache *c, uchar[VtScoreSize], int type, ulong size);
void vtblockput(VtBlock *b);
void vtblockduplock(VtBlock *b);
int vtblockwrite(VtBlock *b);
void vtcachesetwrite(VtCache *c,
int (*write)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
These functions provide access to a simple in-memory
cache of blocks already stored on a Venti server
and blocks that will eventually be stored on a Venti server.
VtBlock represents a venti data block.
Blocks stored on a venti server,
global blocks, are named by the SHA1 hash of their contents.
This hash is recorded as the blocks
score. Such blocks are immutable.
The cache also stores mutable blocks that have not yet been
written to a venti server. These blocks are called
local blocks, and have special scores that are 16 zero bytes
followed by a 4-byte big-endian
address. The address is an index into the internal set of cache blocks.
The user-visible contents of a
data, a pointer to the data;
type, the venti block type;
score, the blocks score;
addr, the blocks cache address.
Vtcachealloc allocates a new cache using the client connection
maxmem bytes of memory.
Vtcachefree frees a cache and all the associated blocks.
Vtglobaltolocal returns the local address corresponding to the given
score. If passed a global score,
vtglobaltolocal returns the special constant
Vtlocaltoglobal is the opposite, setting
score to the local score for the cache address
Vtcacheallocblock allocates a new local block with the given
Vtcachelocal retrieves the local block at address
addr from the cache.
type must match the type of the block found at
Vtcacheglobal retrieves the block with the given
size from the cache, consulting the Venti server
If passed a local score,
The block references returned by
vtcacheglobal must be released when no longer needed.
Vtblockput releases such a reference.
It is occasionally convenient to have multiple variables
refer to the same block.
Vtblockduplock increments the blocks reference count so that
vtblockput will be required in order to release the block.
Vtblockwrite writes a local block to the Venti server,
changing the block to a global block.
It calls the caches
to write the block to the server.
write function is
vtsetcachewrite sets it.
Vtsetcachewrite is used by clients to install replacement functions
that run writes in the background or perform other
Vtblockcopy copies a block in preparation for modifying its contents.
The old block may be a local or global block,
but the new block will be a local block.
The cache only evicts global blocks.
Local blocks can only leave the cache via
vtblockwrite, which turns them into global blocks, making them candidates for
If a new cache block must be allocated (for
vtblockcopy), but the cache is filled (with local blocks and blocks that
have not yet been released with
vtblockput), the library prints the score and reference count of
every block in the cache and then aborts.
A full cache indicates either that the cache is too small,
or, more commonly, that cache blocks are being leaked.