Re: [PATCH] [RFC] libxl: add discard support to libxl_device_disk

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

 



On Thu, Jan 30, 2014 at 09:35:13PM +0100, Olaf Hering wrote:
> Translate libvirt discard settings into libxl-4.5 discard settings.
> It makes use of upcoming changes for xen-4.5:
> http://lists.xenproject.org/archives/html/xen-devel/2014-01/msg02632.html
> 
> This patch is not compile tested. How is a config file supposed to look
> like to make use of a discard=on|off flag for a given disk image?

Here's two examples:

    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' discard='unmap'/>
      <source file='/var/lib/libvirt/images/f14.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </disk>


    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw' discard='ignore'/>
      <source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>


> 
> Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
> Cc: Jim Fehlig <jfehlig@xxxxxxxx>
> ---
>  src/libxl/libxl_conf.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
> index 4cefadf..8fc5e75 100644
> --- a/src/libxl/libxl_conf.c
> +++ b/src/libxl/libxl_conf.c
> @@ -707,6 +707,26 @@ error:
>      return -1;
>  }
>  
> +static void
> +libxlDiskSetDiscard(libxl_device_disk *x_disk, int discard)
> +{
> +    if (!x_disk->readwrite)
> +        return;
> +#if defined(LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE)
> +    /* libxl 4.5 */
> +    switch (discard) {
> +    case VIR_DOMAIN_DISK_DISCARD_DEFAULT:
> +    case VIR_DOMAIN_DISK_DISCARD_UNMAP:
> +        x_disk->discard_enable = 1;
> +        break;
> +    default:
> +    case VIR_DOMAIN_DISK_DISCARD_IGNORE:
> +        x_disk->discard_enable = 0;
> +        break;
> +    }
> +#endif

In the case where LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE is
not defined, then you should call virReportError with the code
VIR_ERR_CONFIG_UNSUPPORTED, if discard != VIR_DOMAIN_DISK_DISCARD_DEFAULT
This ensures apps get an error if they had requested discard instead
of being silently ignored.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]