[Tux3] Prototype of btree node redirect

Daniel Phillips phillips at phunq.net
Tue Jan 13 01:51:01 PST 2009


Here is a prototype of block redirect for btree nodes.  It has not been tested at all, it just compiles (patch attached).  It has one severe deficiency: it can't handle redirecting the root of a btree because the btree cursor does not know where the btree root is cached.

To place this in conext, redirect on write comes in two distinctly different flavors:

  Redirect a data extent in file page cache:
    - Logically mapped
        - no need to relocate data blocks in cache
        - just need to update pointer in parent (dleaf)
    - Handled by map_region

  Redirect a btree node in volume cache:
    - Physically mapped
        - need to move data to a new buffer and release old
    - Handled various functions in btree.c

In either case, we are releasing some data blocks and allocating new ones, because the contents of cache has changed and we need to place it on disk without overwriting any part of the existing, stable filesystem image.

int redirect(struct cursor *cursor, unsigned level)
{
	struct btree *btree = cursor->btree;
	struct sb *sb = btree->sb;
	struct buffer_head *buffer = cursor->path[level].buffer;
	assert(buffer->state >= BUFFER_DIRTY);
	block_t child;
	int err = balloc(sb, 1, &child);
	if (err)
		return err;
	struct buffer_head *shadow = blockget(mapping(sb->volmap), child);
	if (!shadow)
		return -ENOMEM; // ERR_PTR me!!!
	memcpy(bufdata(shadow), bufdata(buffer), sb->blocksize);
	cursor->path[level].buffer = shadow;
	cursor->path[level].next += bufdata(shadow) - bufdata(buffer);
	brelse(buffer);

	// what about redirecting root??? cursor needs to know where root is.
	struct index_entry *entry = cursor->path[level - 1].next - 1;
	block_t parent = bufindex(cursor->path[level - 1].buffer);
	log_alloc(sb, from_be_u64(entry->block), 1, 0);
	log_alloc(sb, child, 1, 1); // implied by update???
	log_update(sb, child, parent, from_be_u64(entry->key));
	entry->block = to_be_u64(child);
	// add old block to free-at-end-of-delta list
	// set_buffer_state(shadow, sb->delta & (BUFFER_DIRTY_STATES - 1));
	return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://phunq.net/pipermail/tux3/attachments/20090113/70266b71/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: redirect.diff
Type: text/x-diff
Size: 2386 bytes
Desc: not available
URL: <http://phunq.net/pipermail/tux3/attachments/20090113/70266b71/attachment.diff>
-------------- next part --------------
_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://mailman.tux3.org/cgi-bin/mailman/listinfo/tux3


More information about the Tux3 mailing list