From caef87d5577a90c33a6bebd512bd0633e5446eb2 Mon Sep 17 00:00:00 2001 From: Osier Yang Date: Tue, 29 Nov 2011 17:59:15 +0800 Subject: [PATCH] block_resize: Define the new API 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 894db374f4..f8ca5cfbc7 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1400,7 +1400,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 efb41d97a6..1919e314bc 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 *path, + unsigned long long size, + unsigned int flags); typedef int (*virDrvDomainMemoryPeek) (virDomainPtr domain, @@ -846,6 +851,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 d5bef92526..cdd111ce23 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -7090,6 +7090,74 @@ error: return -1; } +/** + * 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 sub-element, such as + * "/path/to/image"), or (since 0.9.5) the device target shorthand + * (the 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 diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index d2f272c555..d11b742a8a 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -503,6 +503,7 @@ LIBVIRT_0.9.8 { virConnectIsAlive; virConnectSetKeepAlive; virNodeSuspendForDuration; + virDomainBlockResize; } LIBVIRT_0.9.7; # .... define new API here using predicted next version number ....