The new API is named as "virDomainBlockResize", intending to add support for qemu monitor command "block_resize" (both HMP and QMP). Similar with APIs like "virDomainSetMemoryFlags", the units for argument "size" is kilobytes. --- include/libvirt/libvirt.h.in | 5 ++- src/driver.h | 8 ++++- src/libvirt.c | 68 ++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 0787f18..0ec4959 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1384,7 +1384,10 @@ int virDomainBlockPeek (virDomainPtr dom, size_t size, void *buffer, unsigned int flags); - +int virDomainBlockResize (virDomainPtr dom, + const char *disk, + unsigned long long size, + unsigned int flags); /** virDomainBlockInfo: * diff --git a/src/driver.h b/src/driver.h index 9e78257..015afc5 100644 --- a/src/driver.h +++ b/src/driver.h @@ -377,7 +377,12 @@ typedef int unsigned long long offset, size_t size, void *buffer, unsigned int flags); - +typedef int + (*virDrvDomainBlockResize) + (virDomainPtr domain, + const char *disk, + unsigned long long size, + unsigned int flags); typedef int (*virDrvDomainMemoryPeek) (virDomainPtr domain, @@ -841,6 +846,7 @@ struct _virDriver { virDrvDomainMigratePrepare domainMigratePrepare; virDrvDomainMigratePerform domainMigratePerform; virDrvDomainMigrateFinish domainMigrateFinish; + virDrvDomainBlockResize domainBlockResize; virDrvDomainBlockStats domainBlockStats; virDrvDomainBlockStatsFlags domainBlockStatsFlags; virDrvDomainInterfaceStats domainInterfaceStats; diff --git a/src/libvirt.c b/src/libvirt.c index b428fe6..7efa4a3 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -7028,6 +7028,74 @@ error: } /** + * virDomainBlockResize: + * @dom: pointer to the domain object + * @disk: path to the block image, or shorthand + * @size: new size of the block image in kilobytes + * @flags: unused, always pass 0 + * + * Note that this call may fail if the underlying virtualization hypervisor + * does not support it. And this call requires privileged access to the + * hypervisor. + * + * The @disk parameter is either an unambiguous source name of the + * block device (the <source file='...'/> sub-element, such as + * "/path/to/image"), or (since 0.9.5) the device target shorthand + * (the <target dev='...'/> sub-element, such as "xvda"). Valid names + * can be found by calling virDomainGetXMLDesc() and inspecting + * elements within //domain/devices/disk. + * + * Resize a block device of domain while the domain is running. + * + * Returns: 0 in case of success or -1 in case of failure. + */ + +int +virDomainBlockResize (virDomainPtr dom, + const char *disk, + unsigned long long size, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(dom, "disk=%s, size=%llu, flags=%x", disk, size, flags); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN (dom)) { + virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + virDispatchError(NULL); + return -1; + } + conn = dom->conn; + + if (dom->conn->flags & VIR_CONNECT_RO) { + virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__); + goto error; + } + + if (!disk) { + virLibDomainError(VIR_ERR_INVALID_ARG, + _("disk is NULL")); + goto error; + } + + if (conn->driver->domainBlockResize) { + int ret; + ret =conn->driver->domainBlockResize(dom, disk, size, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibDomainError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(dom->conn); + return -1; +} + +/** * virDomainMemoryPeek: * @dom: pointer to the domain object * @start: start of memory to peek diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 6ba1526..e78f353 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -502,6 +502,7 @@ LIBVIRT_0.9.8 { global: virConnectIsAlive; virConnectSetKeepAlive; + virDomainBlockResize; } LIBVIRT_0.9.7; # .... define new API here using predicted next version number .... -- 1.7.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list