OSDN Git Service

hw/xen: Add basic XenStore tree walk and write/read/directory support
authorDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 20 Jan 2023 01:36:38 +0000 (01:36 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 7 Mar 2023 17:04:30 +0000 (17:04 +0000)
commit3ef7ff83caa27d8b3bfc76805cd47bc97d23b7d7
tree5b705f935bed497efe22eada97ae57193d79bb52
parent0254c4d19df3e89e964f121df1e73f2d871fd46e
hw/xen: Add basic XenStore tree walk and write/read/directory support

This is a fairly simple implementation of a copy-on-write tree.

The node walk function starts off at the root, with 'inplace == true'.
If it ever encounters a node with a refcount greater than one (including
the root node), then that node is shared with other trees, and cannot
be modified in place, so the inplace flag is cleared and we copy on
write from there on down.

Xenstore write has 'mkdir -p' semantics and will create the intermediate
nodes if they don't already exist, so in that case we flip the inplace
flag back to true as we populate the newly-created nodes.

We put a copy of the absolute path into the buffer in the struct walk_op,
with *two* NUL terminators at the end. As xs_node_walk() goes down the
tree, it replaces the next '/' separator with a NUL so that it can use
the 'child name' in place. The next recursion down then puts the '/'
back and repeats the exercise for the next path element... if it doesn't
hit that *second* NUL termination which indicates the true end of the
path.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
hw/i386/kvm/xenstore_impl.c
tests/unit/meson.build
tests/unit/test-xs-node.c [new file with mode: 0644]