Re: [PATCH 1/4] Introduce virDomainFSTrim() public API

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

 



On Tue, Nov 20, 2012 at 07:47:35PM +0100, Michal Privoznik wrote:
> This will call FITRIM within guest. The API has 4 arguments,
> however, only 2 will be used for now (@dom and @minumum).
> The rest two are there if in future qemu guest agent learns them.
> ---
>  include/libvirt/libvirt.h.in |    4 +++
>  src/driver.h                 |    6 +++++
>  src/libvirt.c                |   50 ++++++++++++++++++++++++++++++++++++++++++
>  src/libvirt_public.syms      |    5 ++++
>  4 files changed, 65 insertions(+), 0 deletions(-)
> 
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index 49a361a..b161bce 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -4438,6 +4438,10 @@ int virDomainOpenGraphics(virDomainPtr dom,
>  
>  int virDomainInjectNMI(virDomainPtr domain, unsigned int flags);
>  
> +int virDomainFSTrim(virDomainPtr dom,
> +                    const char *mountPoint,
> +                    unsigned long long minimum,
> +                    unsigned int flags);
>  
>  /**
>   * virSchedParameterType:
> diff --git a/src/driver.h b/src/driver.h
> index 7ba66ad..5163840 100644
> --- a/src/driver.h
> +++ b/src/driver.h
> @@ -903,6 +903,11 @@ typedef int
>                             unsigned char **cpumap,
>                             unsigned int *online,
>                             unsigned int flags);
> +typedef int
> +    (*virDrvDomainFSTrim)(virDomainPtr dom,
> +                          const char *mountPoint,
> +                          unsigned long long minimum,
> +                          unsigned int flags);
>  
>  /**
>   * _virDriver:
> @@ -1094,6 +1099,7 @@ struct _virDriver {
>      virDrvNodeGetMemoryParameters       nodeGetMemoryParameters;
>      virDrvNodeSetMemoryParameters       nodeSetMemoryParameters;
>      virDrvNodeGetCPUMap                 nodeGetCPUMap;
> +    virDrvDomainFSTrim                  domainFSTrim;
>  };
>  
>  typedef int
> diff --git a/src/libvirt.c b/src/libvirt.c
> index bdb1dc6..1c6863f 100644
> --- a/src/libvirt.c
> +++ b/src/libvirt.c
> @@ -20164,3 +20164,53 @@ error:
>      virDispatchError(conn);
>      return -1;
>  }
> +
> +/**
> + * virDomainFSTrim:
> + * @dom: a domain object
> + * @mountPoint: which mount point trim
> + * @minimum: Minimum contiguous free range to discard in bytes
> + * @flags: extra flags, not used yet, so callers should always pass 0
> + *
> + * Calls FITRIM within the guest (hence guest agent may be
> + * required depending on hypervisor used). Either call it on each
> + * mounted filesystem (@mountPoint is NULL) or just on specified
> + * @mountPoint. @minimum tell that free ranges smaller than this
> + * may be ignored (this is a hint and the guest may not respect
> + * it).  By increasing this value, the fstrim operation will
> + * complete more quickly for filesystems with badly fragmented
> + * free space, although not all blocks will be discarded.
> + *
> + * Returns 0 on success, -1 otherwise.
> + */
> +int
> +virDomainFSTrim(virDomainPtr dom,
> +                const char *mountPoint,
> +                unsigned long long minimum,
> +                unsigned int flags)
> +{
> +    VIR_DOMAIN_DEBUG(dom, "mountPoint=%s, minimum=%llu, flags=%x",
> +                     mountPoint, minimum, flags);
> +
> +    virResetLastError();
> +
> +    if (!VIR_IS_DOMAIN(dom)) {
> +        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
> +        virDispatchError(NULL);
> +        return -1;
> +    }

You're missing the check for read-only connections

> +
> +    if (dom->conn->driver->domainFSTrim) {
> +        int ret = dom->conn->driver->domainFSTrim(dom, mountPoint,
> +                                                  minimum, flags);
> +        if (ret < 0)
> +            goto error;
> +        return ret;
> +    }
> +
> +    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
> +
> +error:
> +    virDispatchError(dom->conn);
> +    return -1;
> +}


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]