Userspace-Controlled CoW Device
Hi all,
I'm planning to begin work on a device mapper extension for flexible CoW devices. By flexible, I mean that the block-allocation decisions are made by a userspace daemon, as opposed to the current kernel-based method used by dm-snap. Below, I explain my motivation and proposed design. I would appreciate comments, criticisms, and suggestions.
Motivation
----------
By moving the block-allocation decisions from kernel to userspace, you gain the ability to easily support different algorithms. For example, a plugin could be written that would allow reading and writing of QEMU's qcow disk images. Xen would directly benefit from this feature.
I did investigate extending the existing exception-store facility in dm-snap, but decided against it. AFAICT, dm-snap expects to write a block immediately after letting the store decide where to put it. Obviously, this would not lend itself to deferring to userspace. If a modification to dm-snap would be preferred to a separate implementation, I could focus my efforts there. I think, however, that putting the complexity into userspace rather than kernel space would be a Good Thing.
Design
------
I plan to create a dm-cow module that would be initialized by a table entry like this:
0 100 cow /dev/hdb /dev/hdc [32]
The first two arguments would be the base and CoW devices and the optional third argument would be the chunk size in megabytes. Reads to unaltered blocks are passed directly, just as dm-linear does; write requests are queued. The userspace daemon (which polls or blocks on a character device) will read write requests, make a block-allocation decision for each, and write a response back to the character device. This response write will trigger a copy of the originating block to the CoW device, and, upon completion, a flush of the queued write.
Subsequent accesses that arrive while waiting for userspace to provide the mapping will be queued with the initial write and flushed after the block copy has completed.
Periodically, the userspace daemon would reload the device with a new table that uses dm-linear to map modified blocks directly into the CoW device. This would eliminate the need to replicate the existing fast table searching code. The kernel module would maintain a temporary list of remapped blocks for use until a table reload occurs.
Comments?
I've been working on a proof-of-concept of the above design. It is all bubble-gum-and-duct-tape right now. Below is a link to the work-in-progress kernel module, if anyone is interested.
http://static.danplanet.com/tmp/dm-cow.c
Signature · 4 lines
Dan Smith IBM Linux Technology Center Open Hypervisor Team email: [email protected]
Quoted 1 line · Dan Smith
Comments?
1.)
Is there any technically convincing reason why the qcow thing must be an integral part of the CoW target?
I'm thinking that it's possibly cleaner to implement a device-mapper target that presents a block device of a custom size to upper layers, while actually storing data in a qcow file, regular sparse file, or what not. For the sake of discussion, let's call this dm extension 'dm-autogrow'.
What you're trying to do could then be accomplished by layering dm-snapshot on top of dm-autogrow. It requires a bit more scripting magic, but in the end the implementation might turn out to be simpler, and you get to reuse dm-snapshot.
A dm-autogrow target is potentially useful for other things. There are various applications that would like to read a qcow file as a block device, for example. Perhaps the QEMU folks would be helpful wrt. the implementation stuff, since QEMU could potentially use it too.
That said, I feel that 'qcow' is a bit of a misnomer. It's not like QEMU is actually copying any blocks anywhere is it? It's a file that grows automatically, but AFAIK QEMU has absolutely no snapshot / CoW support.
With the above in mind, and assuming that you want the qcow image as the write target, I'm unsure why it would even be useful to use a qcow image in particular. It's not like qemu will be able to make any sense of the qcow file afterwards, since it will only contain half a filesystem... or am I completely wrong here?
2.)
A couple of things I would personally like to see wrt. Xen and CoW.
a.) Avoid write reordering (= avoid breaking journal filesystems in Xen vms).
b.) When an entire block of zeros is written, nuke it from the qcow
image or "sparsify" the block in the underlying sparse file.
Point b) requires a patch to guest domains so that the filesystem zero released blocks, but that already exists for ext3, I think.
(An alternative approach to that would be to make a target in between the guest and the CoW device that understands the ext3 filesystem. It could catch when ext3 writes to the list of free filesystem blocks and zero those blocks..)
... too tired to come up with anything else right now :-).
MB> 1.) Is there any technically convincing reason why the qcow thing MB> must be an integral part of the CoW target?
No, there isn't. That's why I propose that all the qcow-related logic be in userspace, instead of part of the target. The dm-cow target would be a generic enabler for any kind of CoW implementation, which would be implemented in userspace.
It is possible that other CoW algorithms or strategies would provide different benefits to certain situations. The idea is to provide a generic enabler and the ability to implement such algorithms in userspace, not just to support qcow.
MB> I'm thinking that it's possibly cleaner to implement a MB> device-mapper target that presents a block device of a custom size MB> to upper layers, while actually storing data in a qcow file, MB> regular sparse file, or what not. For the sake of discussion, MB> let's call this dm extension 'dm-autogrow'.
MB> What you're trying to do could then be accomplished by layering MB> dm-snapshot on top of dm-autogrow. It requires a bit more MB> scripting magic, but in the end the implementation might turn out MB> to be simpler, and you get to reuse dm-snapshot.
I'm confused. Assuming the qcow case, how could dm-snapshot be reused, when the allocation of a CoW block must be done in accordance with the qcow algorithm? And how would scripting magic be cleaner?
MB> That said, I feel that 'qcow' is a bit of a misnomer. It's not MB> like QEMU is actually copying any blocks anywhere is it? It's a MB> file that grows automatically, but AFAIK QEMU has absolutely no MB> snapshot / CoW support.
Yes, it does. QEMU has a disk format called 'qcow' which compliments an existing base image. The qcow disk image must be used in conjunction with the base image. See this page:
http://fabrice.bellard.free.fr/qemu/qemu-doc.html#SEC18
MB> With the above in mind, and assuming that you want the qcow image MB> as the write target, I'm unsure why it would even be useful to use MB> a qcow image in particular. It's not like qemu will be able to MB> make any sense of the qcow file afterwards, since it will only MB> contain half a filesystem... or am I completely wrong here?
I think you misunderstood my intent. I want the qcow image (along with the base image) to remain valid while using it, so that it could be later re-used with QEMU.
Signature · 4 lines
Dan Smith IBM Linux Technology Center Open Hypervisor Team email: [email protected]