@@ -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+
499508static int
500509virCHMonitorBuildVMJson (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+
15331573int
15341574virCHMonitorShutdownVMM (virCHMonitorPtr mon )
15351575{
0 commit comments