diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 894db374f45bb03efed68e2452fbbaa76e371dfa..f8ca5cfbc744cc33d402c86d6db0a2537d59653e 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 efb41d97a660e4a0192f0013a11b04cc339d30d1..1919e314bce424f4d0aaece40238339b4f778631 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 d5bef925262732760f5675dd00fa7ff9d11639a8..cdd111ce23a965985675dfe241398977ccbd22bd 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 d2f272c555aa84c0653f9fb28d87b6721b130964..d11b742a8a836e9bd087d3eee66832d7de8b74bc 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 ....