[et-mgmt-tools] virt-df (a 'df' tool for virtual domains)

Richard W.M. Jones rjones at redhat.com
Thu Sep 27 18:07:00 UTC 2007

Brave (or foolhardy?) souls may want to try out the almost-working 
version of 'virt-df' that I wrote:

   hg clone http://hg.et.redhat.com/virt/applications/virt-top--devel

Usage is similar to ordinary 'df'.  It understands the -h 
(human-readable) and -i (show inodes) options.  You need to run it on 
the dom0, it won't work remotely.

# virt-df.opt -c qemu:///system
debian32kvm /dev/hda (3.9 GiB) /var/lib/xen/images/debian32kvm.img
         hda1 3662792 990276 2672516 Linux ext2/3
         hda5 232908 Linux swap

[The numbers are 1K blocks total, used, available]

# virt-df.opt -c qemu:///system -h
debian32kvm /dev/hda (3.9 GiB) /var/lib/xen/images/debian32kvm.img
         hda1 3.5 GiB 967.1 MiB 2.5 GiB Linux ext2/3
         hda5 227.4 MiB Linux swap

 From the README file:

virt-df is a 'df' tool for printing out the used and available disk 
space in all active and inactive domains.  Without this tool you would 
need to log in to each domain individually or set up monitoring.

It is only a proof-of-concept.  Please bare in mind the following 
limitations when using this tool:

(1) It does not work over remote connections.  Part of the reason why I 
wrote virt-df was to get an idea of how the remote storage API for 
libvirt might look.

(2) It only understands a limited set of partition types.  Assuming that 
the files and partitions that we get back from libvirt / Xen correspond 
to block devices in the guests, we can go some way towards manually 
parsing those partitions to find out what they contain.  We can read the 
MBR, EBR, superblocks and so on.  However that's a lot of parsing work, 
and currently there is no library which understands a wide range of 
partition schemes and filesystem types (not even libparted which doesn't 
support LVM yet).  The Linux kernel does support that, but there's not 
really any good way to access that work.

The current implementation uses a hand-coded parser which understands 
some simple formats (MBR, EBR, ext2/3, not LVM yet but coming soon).  In 
future we should use something like libparted.

(3) The statistics you get are delayed.  The real state of, for example, 
an ext2 filesystem is only stored in the memory of the guest's kernel. 
The ext2 superblock contains some meta-information about blocks used and 
free, but this superblock is not up to date.  In fact the guest kernel 
may not update it even on a 'sync', not until the filesystem is 
unmounted.  Some operations do appear to write the superblock, for 
example fsync(2) [that is my reading of the ext2/3 source code at least].

$ wc -l virt-df/*.ml
    84 virt-df/virt_df_ext2.ml
    24 virt-df/virt_df_linux_swap.ml
    22 virt-df/virt_df_lvm2.ml
     5 virt-df/virt_df_main.ml
   460 virt-df/virt_df.ml
   595 total


Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/et-mgmt-tools/attachments/20070927/22351bbe/attachment.bin>

More information about the et-mgmt-tools mailing list