vz: support virDomainBlockResize

Acked-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Konstantin Neumoin <kneumoin@virtuozzo.com>
This commit is contained in:
Konstantin Neumoin 2017-04-14 17:53:53 +03:00 committed by Maxim Nestratov
parent d678379df1
commit f99bc451fe
3 changed files with 96 additions and 0 deletions

View File

@ -3945,6 +3945,63 @@ static int vzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
return vzDomainSetVcpusFlags(dom, nvcpus,
VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG);
}
static int
vzDomainBlockResize(virDomainPtr domain,
const char *path,
unsigned long long size,
unsigned int flags)
{
virDomainObjPtr dom = NULL;
virDomainDiskDefPtr disk = NULL;
int ret = -1;
bool job = false;
virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1);
if (!(dom = vzDomObjFromDomainRef(domain)))
goto cleanup;
if (virDomainBlockResizeEnsureACL(domain->conn, dom->def) < 0)
goto cleanup;
if (path[0] == '\0') {
virReportError(VIR_ERR_INVALID_ARG,
"%s", _("empty path"));
goto cleanup;
}
/* sdk wants Mb */
if (flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES)
size /= 1024;
size /= 1024;
if (!(disk = virDomainDiskByName(dom->def, path, false))) {
virReportError(VIR_ERR_INVALID_ARG,
_("invalid path: %s"), path);
goto cleanup;
}
if (vzDomainObjBeginJob(dom) < 0)
goto cleanup;
job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
if (!virDomainObjIsActive(dom)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto cleanup;
}
ret = prlsdkResizeImage(dom, disk, size);
cleanup:
if (job)
vzDomainObjEndJob(dom);
virDomainObjEndAPI(&dom);
return ret;
}
static virHypervisorDriver vzHypervisorDriver = {
.name = "vz",
@ -4046,6 +4103,7 @@ static virHypervisorDriver vzHypervisorDriver = {
.connectGetAllDomainStats = vzConnectGetAllDomainStats, /* 3.1.0 */
.domainAbortJob = vzDomainAbortJob, /* 3.1.0 */
.domainReset = vzDomainReset, /* 3.1.0 */
.domainBlockResize = vzDomainBlockResize, /* 3.3.0 */
};
static virConnectDriver vzConnectDriver = {

View File

@ -4925,3 +4925,40 @@ int prlsdkSetCpuCount(virDomainObjPtr dom, unsigned int count)
error:
return -1;
}
int prlsdkResizeImage(virDomainObjPtr dom, virDomainDiskDefPtr disk,
unsigned long long newsize)
{
int ret = -1;
PRL_RESULT pret;
vzDomObjPtr privdom = dom->privateData;
PRL_UINT32 emulatedType;
PRL_HANDLE job = PRL_INVALID_HANDLE;
PRL_HANDLE prldisk = PRL_INVALID_HANDLE;
prldisk = prlsdkGetDisk(privdom->sdkdom, disk);
if (prldisk == PRL_INVALID_HANDLE)
goto cleanup;
pret = PrlVmDev_GetEmulatedType(prldisk, &emulatedType);
prlsdkCheckRetGoto(pret, cleanup);
if (emulatedType != PDT_USE_IMAGE_FILE &&
emulatedType != PDT_USE_FILE_SYSTEM) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("Only disk image supported for resize"));
goto cleanup;
}
job = PrlVmDev_ResizeImage(prldisk, newsize,
PRIF_RESIZE_LAST_PARTITION);
if (PRL_FAILED(waitJob(job)))
goto cleanup;
ret = 0;
cleanup:
PrlHandle_Free(prldisk);
return ret;
}

View File

@ -90,3 +90,4 @@ prlsdkMigrate(virDomainObjPtr dom,
PRL_HANDLE
prlsdkSdkDomainLookupByName(vzDriverPtr driver, const char *name);
int prlsdkCancelJob(virDomainObjPtr dom);
int prlsdkResizeImage(virDomainObjPtr dom, virDomainDiskDefPtr disk, unsigned long long newsize);