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 | 4 ++ python/generator.py | 1 + src/driver.h | 7 ++++ src/libvirt.c | 68 ++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 5 +++ 5 files changed, 85 insertions(+), 0 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 5771ba7..0fd20b6 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1180,6 +1180,10 @@ int virDomainBlockPeek (virDomainPtr dom, size_t size, void *buffer, unsigned int flags); +int virDomainBlockResize (virDomainPtr dom, + const char *path, + unsigned long long size, + unsigned int flags); /** virDomainBlockInfo: diff --git a/python/generator.py b/python/generator.py index d0d3ae6..28c15c1 100755 --- a/python/generator.py +++ b/python/generator.py @@ -370,6 +370,7 @@ skip_impl = ( 'virNodeGetCPUStats', 'virNodeGetMemoryStats', 'virDomainGetBlockJobInfo', + 'virDomainBlockResize', ) diff --git a/src/driver.h b/src/driver.h index 5136fb5..ad6b541 100644 --- a/src/driver.h +++ b/src/driver.h @@ -366,6 +366,12 @@ typedef int unsigned long long offset, size_t size, void *buffer, unsigned int flags); +typedef int + (*virDrvDomainBlockResize) + (virDomainPtr domain, + const char *path, + unsigned long long size, + unsigned int flags); typedef int (*virDrvDomainMemoryPeek) @@ -799,6 +805,7 @@ struct _virDriver { virDrvDomainMigratePrepare domainMigratePrepare; virDrvDomainMigratePerform domainMigratePerform; virDrvDomainMigrateFinish domainMigrateFinish; + virDrvDomainBlockResize domainBlockResize; virDrvDomainBlockStats domainBlockStats; virDrvDomainInterfaceStats domainInterfaceStats; virDrvDomainMemoryStats domainMemoryStats; diff --git a/src/libvirt.c b/src/libvirt.c index 5ff8d89..3deafd1 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -6533,6 +6533,74 @@ error: } /** + * virDomainBlockResize: + * @dom: pointer to the domain object + * @path: path to the block image + * @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. + * + * 'path' must be a device or file corresponding to the domain. + * In other words it must be the precise string returned in + * a <disk><source dev='...'/></disk> from + * virDomainGetXMLDesc. + * + * 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 *path, + unsigned long long size, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(dom, "path=%s, size=%llu, flags=%x", + path, 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 (!path) { + virLibDomainError(VIR_ERR_INVALID_ARG, + _("path is NULL")); + goto error; + } + + if (conn->driver->domainBlockResize) { + int ret; + ret =conn->driver->domainBlockResize(dom, path, 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 c2b6666..448209d 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -480,4 +480,9 @@ LIBVIRT_0.9.4 { virDomainBlockPull; } LIBVIRT_0.9.3; +LIBVIRT_0.9.5 { + global: + virDomainBlockResize; +} LIBVIRT_0.9.4; + # .... define new API here using predicted next version number .... -- 1.7.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list