Introduce virDomainFSTrim() public API

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.
This commit is contained in:
Michal Privoznik 2012-11-20 16:43:56 +01:00
parent 856a482207
commit 0fbf3704fd
4 changed files with 70 additions and 0 deletions

View File

@ -4457,6 +4457,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:

View File

@ -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

View File

@ -20224,3 +20224,58 @@ 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;
}
if (dom->conn->flags & VIR_CONNECT_RO) {
virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
goto error;
}
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;
}

View File

@ -574,4 +574,9 @@ LIBVIRT_1.0.0 {
virNodeGetCPUMap;
} LIBVIRT_0.10.2;
LIBVIRT_1.0.1 {
global:
virDomainFSTrim;
} LIBVIRT_1.0.0;
# .... define new API here using predicted next version number ....