Fix xl vcpu-set to decrease an guest vCPU amoutn without complaints.
PATCH v4 1/1 Fix xl vcpu-set to decrease an guest vCPU amoutn without complaints.
Hey Ian and Ian,
Since v3 [http://lists.xen.org/archives/html/xen-devel/2015-03/msg02822.html]
- Constify the libxl_dominfo and handle libxl_domain_info errors.
- Made libxl_domain_info use logging if domain is gone.
- Drop libxl: Add to libxl__domain_type a new return value (LIBXL_DOMAIN_TYPE_NOTFOUND)
In v2 [http://lists.xen.org/archives/html/xen-devel/2015-03/msg01787.html]:
- Fixed up #1 "libxl: Add ERROR_DOMAIN_NOTFOUND for libxl_domain_info" per your review.
- Moved the check from vcpuset to libxl_set_vcpuonline to check if the set bits of the cpumap is greater than the maximum vCPU that the guest can have (and added printks).
- Added LIBXL_DOMAIN_TYPE_NOTFOUND so that libxl_set_vcpuonline can report that the domain id is for an non-existent guest.
- Added an #define in libxl.h to expose the new _NOTFOUND error value.
git://xenbits.xen.org/people/konradwilk/xen.git vcpuset.v4
In short, these two patches were modified since v3 posting:
[PATCH v4 2/7] libxl: In libxl_set_vcpuonline check for maximum [PATCH v4 7/7] libxl/vcpu-set - allow to decrease vcpu count on
while the rest is the same.
Thank you for taking the time to review these patches!
tools/libxl/libxl.c | 73 ++++++++++++++++++++++++++++----------------- tools/libxl/libxl.h | 9 +++++- tools/libxl/libxl_types.idl | 1 + tools/libxl/xl_cmdimpl.c | 47 ++++++++++++++++++----------- 4 files changed, 84 insertions(+), 46 deletions(-)
Konrad Rzeszutek Wilk (7):
libxl: Add ERROR_DOMAIN_NOTFOUND for libxl_domain_info when it cannot find the domain
libxl: In libxl_set_vcpuonline check for maximum number of VCPUs against the cpumap. libxl/libxl_domain_info: Log if domain not found.
libxl/vcpuset: Print error if libxl_set_vcpuonline returns ERROR_DOMAIN_NOTFOUND libxl/vcpuset: Return error value if failed.
libxl/vcpuset: Remove useless limit on max_vcpus.
libxl/vcpuset - allow to decrease vcpu count on overcommitted guests (v5)
PATCH v4 1/7 libxl: Add ERROR_DOMAIN_NOTFOUND for libxl_domain_info when it cannot find the domain
And use that for all of its callers in the tree.
--- tools/libxl/libxl.c | 19 +++++++++++-------- tools/libxl/libxl.h | 9 ++++++++- tools/libxl/libxl_types.idl | 1 + tools/libxl/xl_cmdimpl.c | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-)
tools/libxl/libxl.c +11 -8
@@ -455,7 +455,7 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,/* update /vm/<uuid>/name */ rc =libxl_domain_info (ctx, &info, domid);if (rc) - goto x_fail; + goto x_rc; uuid =GCSPRINTF (LIBXL_UUID_FMT ,LIBXL_UUID_BYTES (info.uuid)); vm_name_path =GCSPRINTF ("/vm/%s/name" , uuid);
@@ -698,7 +698,7 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo *info_r,LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting domain info list" );return ERROR_FAIL ; } -if (ret==0 || xcinfo.domain != domid)return ERROR_INVAL ; +if (ret==0 || xcinfo.domain != domid)return ERROR_DOMAIN_NOTFOUND ;if (info_r)xcinfo2xlinfo (ctx, &xcinfo, info_r);
@@ -1577,7 +1577,7 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)switch (rc) {case 0 :break ; -case ERROR_INVAL : +case ERROR_DOMAIN_NOTFOUND :LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"non-existant domain %d" , domid);default : goto out;
@@ -5448,14 +5448,16 @@ static int libxl__set_vcpuonline_xenstore(libxl__gc *gc, uint32_t domid,libxl_dominfo info;char *dompath;xs_transaction_t t; -int i, rc =ERROR_FAIL ; +int i, rc;libxl_dominfo_init (&info); -if (libxl_domain_info (CTX , &info, domid) <0 ) { + rc =libxl_domain_info (CTX , &info, domid); +if (rc <0 ) {LOGE (ERROR ,"getting domain info list" ); goto out; } + rc =ERROR_FAIL ;if (!(dompath =libxl__xs_get_dompath (gc, domid))) goto out;
@@ -5479,14 +5481,15 @@ static int libxl__set_vcpuonline_qmp(libxl__gc *gc, uint32_t domid, libxl_bitmap *cpumap) {libxl_dominfo info; -int i; +int i, rc;libxl_dominfo_init (&info); -if (libxl_domain_info (CTX , &info, domid) <0 ) { + rc =libxl_domain_info (CTX , &info, domid); +if (rc <0 ) {LOGE (ERROR ,"getting domain info list" );libxl_dominfo_dispose (&info); -return ERROR_FAIL ; +return rc; }for (i =0 ; i <= info.vcpu_max_id; i++) {if (libxl_bitmap_test (cpumap, i)) {
tools/libxl/libxl.h +8 -1
@@ -179,6 +179,11 @@#define LIBXL_HAVE_BUILDINFO_HVM_MMIO_HOLE_MEMKB 1/* +* libxl_domain_info returns ERROR_DOMAIN_NOTFOUND if the domain +* is not present, instead of ERROR_INVAL. +*/ +#define LIBXL_HAVE_ERROR_DOMAIN_NOTFOUND 1 +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility
@@ -1104,7 +1109,9 @@ int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num,*/ int libxl_primary_console_get_tty (libxl_ctx *ctx,uint32_t domid_vm,char **path); -/* May be called with info_r == NULL to check for domain's existance */ +/* May be called with info_r == NULL to check for domain's existence. +* Returns ERROR_DOMAIN_NOTFOUND if domain does not exist (used to return +* ERROR_INVAL for this scenario). */ int libxl_domain_info (libxl_ctx *,libxl_dominfo *info_r,uint32_t domid);
tools/libxl/libxl_types.idl +1 -0
@@ -64,6 +64,7 @@ libxl_error = Enumeration("error", [ (-18, "REMUS_DEVOPS_DOES_NOT_MATCH"), (-19, "REMUS_DEVICE_NOT_SUPPORTED"), (-20, "VNUMA_CONFIG_INVALID"), + (-21, "DOMAIN_NOTFOUND"), ], value_namespace = "") libxl_domain_type = Enumeration("domain_type", [
tools/libxl/xl_cmdimpl.c +2 -2
@@ -4736,7 +4736,7 @@ int main_list(int argc, char **argv) }else if (optind == argc-1 ) {uint32_t domid =find_domain (argv[optind]); rc =libxl_domain_info (ctx, &info_buf, domid); -if (rc ==ERROR_INVAL ) { +if (rc ==ERROR_DOMAIN_NOTFOUND ) {fprintf (stderr,"Error: Domain \'%s\' does not exist.\n" , argv[optind]);return -rc;
@@ -5507,7 +5507,7 @@ int main_sharing(int argc, char **argv) }else if (optind == argc-1 ) {uint32_t domid =find_domain (argv[optind]); rc =libxl_domain_info (ctx, &info_buf, domid); -if (rc ==ERROR_INVAL ) { +if (rc ==ERROR_DOMAIN_NOTFOUND ) {fprintf (stderr,"Error: Domain \'%s\' does not exist.\n" , argv[optind]);return -rc;
Signature · 1 line
2.1.0
PATCH v4 2/7 libxl: In libxl_set_vcpuonline check for maximum number of VCPUs against the cpumap.
In reply to Konrad Rzeszutek WilkThere is no sense in trying to online (or offline) CPUs when the size of cpumap is greater than the maximum number of VCPUs the guest can go to.
As such fail the operation if the count of CPUs to online is greater than what the guest started with. For the offline case we do not check (as the bits are unset in the cpumap) and let it go through.
We coalesce some of the underlaying libxl_set_vcpuonline code together to take advantage for the QMP and XenStore ways.
--- tools/libxl/libxl.c | 70 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 29 deletions(-)
tools/libxl/libxl.c +41 -29
@@ -5442,28 +5442,34 @@ int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,return 0 ; } +static int libxl__check_max (libxl__gc *gc,const libxl_dominfo *info, +libxl_bitmap *cpumap) +{ +int maxcpus =libxl_bitmap_count_set (cpumap); + +if (maxcpus > info->vcpu_max_id +1 ) + { +LOGE (ERROR ,"Requested %d VCPUs, however maxcpus is %d!" , + maxcpus, info->vcpu_max_id +1 ); +return ERROR_FAIL ; + } +return 0 ; +} +static int libxl__set_vcpuonline_xenstore (libxl__gc *gc,uint32_t domid, -libxl_bitmap *cpumap) +libxl_bitmap *cpumap, +const libxl_dominfo *info) { -libxl_dominfo info;char *dompath;xs_transaction_t t; -int i, rc; - -libxl_dominfo_init (&info); +int i, rc =ERROR_FAIL ; - rc =libxl_domain_info (CTX , &info, domid); -if (rc <0 ) { -LOGE (ERROR ,"getting domain info list" ); - goto out; - } - rc =ERROR_FAIL ;if (!(dompath =libxl__xs_get_dompath (gc, domid))) goto out; retry_transaction: t =xs_transaction_start (CTX ->xsh); -for (i =0 ; i <= info.vcpu_max_id; i++) +for (i =0 ; i <= info->vcpu_max_id; i++)libxl__xs_write (gc, t,libxl__sprintf (gc,"%s/cpu/%u/availability" , dompath, i),"%s" ,libxl_bitmap_test (cpumap, i) ?"online" :"offline" );
@@ -5473,25 +5479,16 @@ retry_transaction: }else rc =0 ; out: -libxl_dominfo_dispose (&info);return rc; }static int libxl__set_vcpuonline_qmp (libxl__gc *gc,uint32_t domid, -libxl_bitmap *cpumap) +libxl_bitmap *cpumap, +const libxl_dominfo *info) { -libxl_dominfo info; -int i, rc; - -libxl_dominfo_init (&info); +int i; - rc =libxl_domain_info (CTX , &info, domid); -if (rc <0 ) { -LOGE (ERROR ,"getting domain info list" ); -libxl_dominfo_dispose (&info); -return rc; - } -for (i =0 ; i <= info.vcpu_max_id; i++) { +for (i =0 ; i <= info->vcpu_max_id; i++) {if (libxl_bitmap_test (cpumap, i)) {/* Return value is ignore because it does not tell anything useful * on the completion of the command.
@@ -5501,7 +5498,6 @@ static int libxl__set_vcpuonline_qmp(libxl__gc *gc, uint32_t domid,libxl__qmp_cpu_add (gc, domid, i); } } -libxl_dominfo_dispose (&info);return 0 ; }
@@ -5509,25 +5505,41 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap) {GC_INIT (ctx);int rc; +libxl_dominfo info; + +libxl_dominfo_init (&info); + + rc =libxl_domain_info (CTX , &info, domid); +if (rc <0 ) { +LOGE (ERROR ,"getting domain info list" ); + goto out; + } + + rc =libxl__check_max (gc, &info, cpumap); +if (rc) + goto out; +switch (libxl__domain_type (gc, domid)) {case LIBXL_DOMAIN_TYPE_HVM :switch (libxl__device_model_version_running (gc, domid)) {case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : - rc =libxl__set_vcpuonline_xenstore (gc, domid, cpumap); + rc =libxl__set_vcpuonline_xenstore (gc, domid, cpumap, &info);break ;case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : - rc =libxl__set_vcpuonline_qmp (gc, domid, cpumap); + rc =libxl__set_vcpuonline_qmp (gc, domid, cpumap, &info);break ;default : rc =ERROR_INVAL ; }break ;case LIBXL_DOMAIN_TYPE_PV : - rc =libxl__set_vcpuonline_xenstore (gc, domid, cpumap); + rc =libxl__set_vcpuonline_xenstore (gc, domid, cpumap, &info);break ;default : rc =ERROR_INVAL ; } +out: +libxl_dominfo_dispose (&info);GC_FREE ;return rc; }
Signature · 1 line
2.1.0
Re: [PATCH v4 2/7] libxl: In libxl_set_vcpuonline check for maximum number of VCPUs against the cpumap.
Quoted 8 lines · Konrad Rzeszutek Wilk
There is no sense in trying to online (or offline) CPUs when the size of cpumap is greater than the maximum number of VCPUs the guest can go to.
As such fail the operation if the count of CPUs to online is greater than what the guest started with. For the offline case we do not check (as the bits are unset in the cpumap) and let it go through.
We coalesce some of the underlaying
libxl_set_vcpuonlinecode
"underlying"
Quoted 13 lines
together to take advantage for the QMP and XenStore ways.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>[v2: constify the libxl_domain and handle libxl_domain_info error]--- tools/libxl/libxl.c | 70 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 29 deletions(-)tools/libxl/libxl.c +0
-0
tools/libxl/libxl.c int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid, · line 5445
Quoted 4 lines
tools/libxl/libxl.c +1
-0@@ -5442,28 +5442,34 @@ int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,return 0 ; } +static int libxl__check_max(libxl__gc *gc, const libxl_dominfo *info,
The name is so generic (max what?) and the implementation so simple I'd suggest to just inline the check at the one call site.
Otherwise looks ok, thanks.
Re: [PATCH v4 2/7] libxl: In libxl_set_vcpuonline check for maximum number of VCPUs against the cpumap.
Quoted 11 lines · Ian Campbell
Quoted 8 lines · Konrad Rzeszutek Wilk
There is no sense in trying to online (or offline) CPUs when the size of cpumap is greater than the maximum number of VCPUs the guest can go to.
As such fail the operation if the count of CPUs to online is greater than what the guest started with. For the offline case we do not check (as the bits are unset in the cpumap) and let it go through.
We coalesce some of the underlaying
libxl_set_vcpuonlinecode"underlying"
Whoa! Just to make sure I understand why I used the incorrect word.
I used an verb while I should have used an adjective - which 'underlying' is, right?
Quoted 25 lines
Quoted 14 lines
together to take advantage for the QMP and XenStore ways.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>[v2: constify the libxl_domain and handle libxl_domain_info error]--- tools/libxl/libxl.c | 70 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 29 deletions(-)tools/libxl/libxl.c +0
-0tools/libxl/libxl.c int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid, · line 5445
Quoted 4 lines
tools/libxl/libxl.c +1
-0@@ -5442,28 +5442,34 @@ int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,return 0 ; } +static int libxl__check_max(libxl__gc *gc, const libxl_dominfo *info,The name is so generic (max what?) and the implementation so simple I'd suggest to just inline the check at the one call site.
Otherwise looks ok, thanks.
Re: [PATCH v4 2/7] libxl: In libxl_set_vcpuonline check for maximum number of VCPUs against the cpumap.
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line
"underlying"
Whoa! Just to make sure I understand why I used the incorrect word.
I used an verb while I should have used an adjective - which 'underlying' is, right?
Err, I haven't done English grammar since the mid 90s (and it was out of fashion in our education system at the time...), I'm just coasting on being allowed to speak my native tongue around here...
To lay is indeed a verb. (It also has other forms, e.g. you can be a lay preacher or take in the lay of the land, lets skip all that!).
"lying" in the sense of underlying is some form (present participle?) of "To lie" as in to lie down. i.e. underlying means to lie beneath something.
Ian.
PATCH v4 3/7 libxl/libxl_domain_info: Log if domain not found.
In reply to Konrad Rzeszutek WilkIf we cannot find the domain - log an error (and still continue returning an error).
--- tools/libxl/libxl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +4 -2
@@ -698,8 +698,10 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo *info_r,LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting domain info list" );return ERROR_FAIL ; } -if (ret==0 || xcinfo.domain != domid)return ERROR_DOMAIN_NOTFOUND ; - +if (ret==0 || xcinfo.domain != domid) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"Domain %d not found!" , domid); +return ERROR_DOMAIN_NOTFOUND ; + }if (info_r)xcinfo2xlinfo (ctx, &xcinfo, info_r);return 0 ;
Signature · 1 line
2.1.0
Re: [PATCH v4 3/7] libxl/libxl_domain_info: Log if domain not found.
Quoted 4 lines · Konrad Rzeszutek Wilk
If we cannot find the domain - log an error (and still continue returning an error).
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
PATCH v4 4/7 libxl/vcpuset: Print error if libxl_set_vcpuonline returns ERROR_DOMAIN_NOTFOUND
In reply to Konrad Rzeszutek WilkInstead of just printing an generic error.
--- tools/libxl/xl_cmdimpl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/libxl/xl_cmdimpl.c +7 -2
@@ -5223,6 +5223,7 @@ static void vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)char *endptr;unsigned int max_vcpus, i;libxl_bitmap cpumap; +int rc;libxl_bitmap_init (&cpumap); max_vcpus =strtoul (nr_vcpus, &endptr,10 );
@@ -5253,8 +5254,12 @@ static void vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)for (i =0 ; i < max_vcpus; i++)libxl_bitmap_set (&cpumap, i); -if (libxl_set_vcpuonline (ctx, domid, &cpumap) <0 ) -fprintf (stderr,"libxl_set_vcpuonline failed domid=%d max_vcpus=%d\n" , domid, max_vcpus); + rc =libxl_set_vcpuonline (ctx, domid, &cpumap); +if (rc ==ERROR_DOMAIN_NOTFOUND ) +fprintf (stderr,"Domain %u does not exist.\n" , domid); +else if (rc) +fprintf (stderr,"libxl_set_vcpuonline failed domid=%d max_vcpus=%d," \ +" rc: %d\n" , domid, max_vcpus, rc);libxl_bitmap_dispose (&cpumap); }
Signature · 1 line
2.1.0
PATCH v4 5/7 libxl/vcpuset: Return error value if failed.
In reply to Konrad Rzeszutek WilkThe function does not return any values at all. Convert the internal libxl errors (ERROR_FAIL, ..., etc) to 1.
--- tools/libxl/xl_cmdimpl.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
tools/libxl/xl_cmdimpl.c +9 -8
@@ -5218,7 +5218,7 @@ int main_vcpupin(int argc, char **argv)return rc; } -static void vcpuset (uint32_t domid,const char * nr_vcpus,int check_host) +static int vcpuset (uint32_t domid,const char * nr_vcpus,int check_host) {char *endptr;unsigned int max_vcpus, i;
@@ -5229,7 +5229,7 @@ static void vcpuset(uint32_t domid, const char* nr_vcpus, int check_host) max_vcpus =strtoul (nr_vcpus, &endptr,10 );if (nr_vcpus == endptr) {fprintf (stderr,"Error: Invalid argument.\n" ); -return ; +return 1 ; }/*
@@ -5242,14 +5242,15 @@ static void vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)fprintf (stderr,"You are overcommmitting! You have %d physical " \" CPUs and want %d vCPUs! Aborting, use --ignore-host to " \" continue\n" , host_cpu, max_vcpus); -return ; +return 1 ; }/* NB: This also limits how many are set in the bitmap */ max_vcpus = (max_vcpus > host_cpu ? host_cpu : max_vcpus); } -if (libxl_cpu_bitmap_alloc (ctx, &cpumap, max_vcpus)) { -fprintf (stderr,"libxl_cpu_bitmap_alloc failed\n" ); -return ; + rc =libxl_cpu_bitmap_alloc (ctx, &cpumap, max_vcpus); +if (rc) { +fprintf (stderr,"libxl_cpu_bitmap_alloc failed, rc: %d\n" , rc); +return 1 ; }for (i =0 ; i < max_vcpus; i++)libxl_bitmap_set (&cpumap, i);
@@ -5262,6 +5263,7 @@ static void vcpuset(uint32_t domid, const char* nr_vcpus, int check_host) " rc: %d\n", domid, max_vcpus, rc);libxl_bitmap_dispose (&cpumap); +return rc ?1 :0 ; }int main_vcpuset (int argc,char **argv)
@@ -5280,8 +5282,7 @@ int main_vcpuset(int argc, char **argv)break ; } -vcpuset (find_domain (argv[optind]), argv[optind +1 ], check_host); -return 0 ; +return vcpuset (find_domain (argv[optind]), argv[optind +1 ], check_host); }static void output_xeninfo (void )
Signature · 1 line
2.1.0
PATCH v4 6/7 libxl/vcpuset: Remove useless limit on max_vcpus.
In reply to Konrad Rzeszutek WilkThe check is superflous. If the 'max_vcpus' (argument value) is greater than pCPU and --ignore-host has not been supplied we would print an warning and return and not call this code.
If the --ignore-host parameter had been used we would never end up in this condition and enforce 'max_vcpus'.
The only time it would be invoked is if max_vcpus < host_cpu in which case it would set max_vcpus to max_vcpus.
In short - it is dead code.
--- tools/libxl/xl_cmdimpl.c | 2 -- 1 file changed, 2 deletions(-)
tools/libxl/xl_cmdimpl.c +0 -2
@@ -5244,8 +5244,6 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host) " continue\n", host_cpu, max_vcpus);return 1 ; } -/* NB: This also limits how many are set in the bitmap */ - max_vcpus = (max_vcpus > host_cpu ? host_cpu : max_vcpus); } rc =libxl_cpu_bitmap_alloc (ctx, &cpumap, max_vcpus);if (rc) {
Signature · 1 line
2.1.0
PATCH v4 7/7 libxl/vcpu-set - allow to decrease vcpu count on overcommitted guests (v5)
In reply to Konrad Rzeszutek WilkWe have a check to warn the user if they are overcommitting. But the check only checks the hosts CPU amount and does not take into account the case when the user is trying to fix the overcommit. That is - they want to limit the amount of online VCPUs.
This fix allows the user to offline vCPUs without any warnings when they are running an overcommitted guest.
Also fix the extra space in the message.
---
[v2: Remove crud code as spotted by Boris]
[v3: Moved crud code removal to another patch] [v4: Remove the fprintf as it is done in libxl_domain_info] [v5: Fix memory leak]
--- tools/libxl/xl_cmdimpl.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
tools/libxl/xl_cmdimpl.c +13 -4
@@ -5238,12 +5238,21 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)*/ if (check_host) {unsigned int host_cpu =libxl_get_max_cpus (ctx); -if (max_vcpus > host_cpu) { -fprintf (stderr,"You are overcommmitting! You have %d physical " \ -" CPUs and want %d vCPUs! Aborting, use --ignore-host to " \ -" continue\n" , host_cpu, max_vcpus); +libxl_dominfo dominfo; + + rc =libxl_domain_info (ctx, &dominfo, domid); +if (rc)return 1 ; + +if (max_vcpus > dominfo.vcpu_online && max_vcpus > host_cpu) { +fprintf (stderr,"You are overcommmitting! You have %d physical" \ +" CPUs and want %d vCPUs! Aborting, use --ignore-host to" \ +" continue\n" , host_cpu, max_vcpus); + rc =1 ; } +libxl_dominfo_dispose (&dominfo); +if (rc) +return 1 ; } rc =libxl_cpu_bitmap_alloc (ctx, &cpumap, max_vcpus);if (rc) {
Signature · 1 line
2.1.0
Re: [PATCH v4 7/7] libxl/vcpu-set - allow to decrease vcpu count on overcommitted guests (v5)
Quoted 6 lines · Konrad Rzeszutek Wilk
We have a check to warn the user if they are overcommitting. But the check only checks the hosts CPU amount and does not take into account the case when the user is trying to fix the overcommit. That is - they want to limit the amount of online VCPUs.
Quoted 6 lines
This fix allows the user to offline vCPUs without any warnings when they are running an overcommitted guest.
Also fix the extra space in the message.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>