On Wed, Jan 26, 2011 at 03:16:50PM +0000, Matthew Booth wrote:
I observed that qemu-img *does* get the correct 'virtual size' for both block devices and regular files. I don't want to use more external tools than required, so I'd prefer not to call blockdev. Why wouldn't you trust qemu-img here? [...]
Actually I've looked at the code (qemu/block/*.c), yes I would trust it. It uses 'lseek (fd, 0, SEEK_END)' for raw format block devices and files. It uses the metadata for qcow2.
As for $st->blocks, any idea when it wouldn't be valid? As it happens, you can assume that this is in units of 512 (see man 2 stat). Although block sizes have moved on, I guess this value has been grandfathered for compatibility.
OK it does appear to say that. Still I wouldn't be wholly trusting of this, particularly when you mix in 4K sectors and other operating systems. Anyway qemu-img seems to be doing the right thing, so go with that, unless you really need the on-disk allocated size for some reason. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org