Skip to content

Commit f105948

Browse files
committed
ch: Add monitor portion of resize cpu.
Use the newly introduced virCHMonitorPut and add logic to build the json for Cloud-Hypervisor.
1 parent aa7c8b5 commit f105948

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/ch/ch_monitor.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,15 @@ virCHMonitorBuildDevicesJson(virJSONValuePtr content, virDomainDefPtr vmdef)
496496
return -1;
497497
}
498498

499+
static int
500+
virCHMonitorBuildResizeCPUsJson(virJSONValuePtr content, unsigned int nvcpus)
501+
{
502+
if (virJSONValueObjectAppendNumberUint(content, "desired_vcpus", nvcpus) < 0)
503+
return -1;
504+
505+
return 0;
506+
}
507+
499508
static int
500509
virCHMonitorBuildVMJson(virDomainObjPtr vm, virDomainDefPtr vmdef, char **jsonstr,
501510
size_t *nnicindexes, int **nicindexes)
@@ -547,6 +556,26 @@ virCHMonitorBuildVMJson(virDomainObjPtr vm, virDomainDefPtr vmdef, char **jsonst
547556
return ret;
548557
}
549558

559+
static int
560+
virCHMonitorBuildResizeJson(const unsigned int nvcpus,
561+
char **jsonstr)
562+
{
563+
virJSONValuePtr content = virJSONValueNewObject();
564+
int ret = -1;
565+
566+
if (virCHMonitorBuildResizeCPUsJson(content, nvcpus) < 0)
567+
goto cleanup;
568+
569+
if (!(*jsonstr = virJSONValueToString(content, false)))
570+
goto cleanup;
571+
572+
ret = 0;
573+
574+
cleanup:
575+
virJSONValueFree(content);
576+
return ret;
577+
}
578+
550579
/* generate command to launch Cloud-Hypervisor socket
551580
return -1 - error
552581
0 - OK
@@ -1530,6 +1559,17 @@ virCHMonitorPingVMM(virCHMonitorPtr mon)
15301559
return virCHMonitorGet(mon, URL_VMM_PING, NULL);
15311560
}
15321561

1562+
int
1563+
virCHMonitorResizeCPU(virCHMonitorPtr mon,
1564+
unsigned int nvcpus)
1565+
{
1566+
g_autofree char *payload = NULL;
1567+
if (virCHMonitorBuildResizeJson(nvcpus, &payload))
1568+
return -1;
1569+
1570+
return virCHMonitorPut(mon, URL_VM_RESIZE, payload);
1571+
}
1572+
15331573
int
15341574
virCHMonitorShutdownVMM(virCHMonitorPtr mon)
15351575
{

src/ch/ch_monitor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define URL_VMM_SHUTDOWN "vmm.shutdown"
3131
#define URL_VMM_PING "vmm.ping"
3232
#define URL_VM_CREATE "vm.create"
33+
#define URL_VM_RESIZE "vm.resize"
3334
#define URL_VM_DELETE "vm.delete"
3435
#define URL_VM_BOOT "vm.boot"
3536
#define URL_VM_SHUTDOWN "vm.shutdown"
@@ -173,3 +174,7 @@ int virCHMonitorGetIOThreads(virCHMonitorPtr mon,
173174
virDomainIOThreadInfoPtr **iothreads);
174175

175176
int virCHMonitorGetInfo(virCHMonitorPtr mon, virJSONValuePtr *info);
177+
178+
int
179+
virCHMonitorResizeCPU(virCHMonitorPtr mon,
180+
unsigned int nvcpus);

0 commit comments

Comments
 (0)