[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] Query block allocation extent from QEMU monitor



On Thu, May 13, 2010 at 08:18:24AM -0600, Eric Blake wrote:
> On 05/13/2010 05:09 AM, Daniel P. Berrange wrote:
> > The virDomainGetBlockInfo API allows query physical block
> > extent and allocated block extent. These are normally the
> > same value unless storing a special format like qcow2
> > inside a block device. In this scenario we can query QEMU
> > to get the actual allocated extent.
> > 
> 
> > +    /* Set default value .. */
> >      info->allocation = info->physical;
> >  
> > -    ret = 0;
> > +    /* ..but if guest is running & not using raw
> > +       disk format and on a block device, then query
> > +       highest allocated extent from QEMU */
> > +    if (virDomainObjIsActive(vm) &&
> > +        meta.format != VIR_STORAGE_FILE_RAW &&
> > +        S_ISBLK(sb.st_mode)) {
> > +        qemuDomainObjPrivatePtr priv = vm->privateData;
> > +        if (qemuDomainObjBeginJob(vm) < 0)
> > +            goto cleanup;
> > +
> > +        qemuDomainObjEnterMonitor(vm);
> > +        ret = qemuMonitorGetBlockExtent(priv->mon,
> > +                                        disk->info.alias,
> > +                                        &info->allocation);
> 
> This sets info->allocation to 0 if...
> 
> > +int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
> > +                              const char *devname,
> > +                              unsigned long long *extent)
> > +{
> > +    int ret;
> > +    DEBUG("mon=%p, fd=%d, devname=%p",
> > +          mon, mon->fd, devname);
> > +
> > +    if (mon->json)
> > +        ret = qemuMonitorJSONGetBlockExtent(mon, devname, extent);
> > +    else
> > +        ret = qemuMonitorTextGetBlockExtent(mon, devname, extent);
> 
> ...we don't have JSON support...
> 
> > +int qemuMonitorTextGetBlockExtent(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
> > +                                  const char *devname ATTRIBUTE_UNUSED,
> > +                                  unsigned long long *extent)
> > +{
> > +    /* Not supported in text monitor, but we don't want to
> > +     * cause an error in callers in this scenario, just
> > +     * fallback to marking the data unavailable */
> > +    *extent = 0;
> > +    return 0;
> > +}
> 
> Wouldn't it be better to check if qemu sets things to 0 (because max
> extent is not supported), and in that case, fall back to the original
> default of info->physical?

I realize that '0' is actually a valid value too. I've changed the caller
so that its only ever invoked for a non-raw block device, and made it
generate a fatal error if the QEMU command isn't supported.

Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]