• E
    qemu: let blockinfo reuse virStorageSource · 89646e69
    Eric Blake 提交于
    Right now, grabbing blockinfo always calls stat on the disk, then
    opens the image to determine the capacity, using a throw-away
    virStorageSourcePtr.  This has a couple of drawbacks:
    
    1. We are calling stat and opening a file on every invocation of
    the API.  However, there are cases where the stats should NOT be
    changing between successive calls (if a domain is running, no
    one should be changing the physical size of a block device or raw
    image behind our backs; capacity of read-only files should not
    be changing; and we are the gateway to the block-resize command
    to know when the capacity of read-write files should be changing).
    True, we still have to use stat in some cases (a sparse raw file
    changes allocation if it is read-write and the amount of holes is
    changing, and a read-write qcow2 image stored in a file changes
    physical size if it was not fully pre-allocated).  But for
    read-only images, even this should be something we can remember
    from the previous time, rather than repeating every call.
    
    2. We want to enhance the power of virDomainListGetStats, by
    sharing code.  But we already have a virStorageSourcePtr for
    each disk, and it would be easier to reuse the common structure
    than to have to worry about the one-off virDomainBlockInfoPtr.
    
    While this patch does not optimize reuse of information in point
    1, it does get us closer to being able to do so; by updating a
    structure that survives between consecutive calls.
    
    * src/util/virstoragefile.h (_virStorageSource): Add physical, to
    mirror virDomainBlockInfo; rearrange fields to match public struct.
    (virStorageSourceCopy): Copy the new field.
    * src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Store into
    storage source, then copy to block info.
    Signed-off-by: NEric Blake <eblake@redhat.com>
    89646e69
virstoragefile.c 76.4 KB