diff mbox

[v3,6/6] libxl: add force option for xl vcpu-pin

Message ID 1457023730-10997-7-git-send-email-jgross@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jürgen Groß March 3, 2016, 4:48 p.m. UTC
In order to be able to undo a vcpu pin override in case of a kernel
driver error add a flag "-f" to the "xl vcpu-pin" command forcing the
hypervisor to undo the override.

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/libxl/libxl.c       | 31 +++++++++++++++++++++++++------
 tools/libxl/libxl.h       |  4 ++++
 tools/libxl/xl_cmdimpl.c  | 27 +++++++++++++++++++++++----
 tools/libxl/xl_cmdtable.c |  3 ++-
 4 files changed, 54 insertions(+), 11 deletions(-)

Comments

Dario Faggioli March 8, 2016, 1:29 p.m. UTC | #1
On Thu, 2016-03-03 at 17:48 +0100, Juergen Gross wrote:
> In order to be able to undo a vcpu pin override in case of a kernel
> driver error add a flag "-f" to the "xl vcpu-pin" command forcing the
> hypervisor to undo the override.
> 
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Signed-off-by: Juergen Gross <jgross@suse.com>
>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>

With the only comment that, here:

> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -5344,6 +5344,10 @@ int main_vcpulist(int argc, char **argv)
>  
>  int main_vcpupin(int argc, char **argv)
>  {
> +    static struct option opts[] = {
> +        {"force", 0, 0, 'f'},
> +        COMMON_LONG_OPTS
> +    };
>      libxl_vcpuinfo *vcpuinfo;
>      libxl_bitmap cpumap_hard, cpumap_soft;;
>      libxl_bitmap *soft = &cpumap_soft, *hard = &cpumap_hard;
> @@ -5355,13 +5359,17 @@ int main_vcpupin(int argc, char **argv)
>      long vcpuid;
>      const char *vcpu, *hard_str, *soft_str;
>      char *endptr;
> -    int opt, nb_cpu, nb_vcpu, rc = EXIT_FAILURE;
> +    int opt, nb_cpu, nb_vcpu, force = 0, rc = EXIT_FAILURE;
>  
force can be bool.

The Reviewed-by stands both with that changed, and as the patch looks
now.

Regards,
Dario
Wei Liu March 8, 2016, 3:58 p.m. UTC | #2
On Thu, Mar 03, 2016 at 05:48:50PM +0100, Juergen Gross wrote:
[...]
>  int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
>                                 unsigned int max_vcpus,
>                                 const libxl_bitmap *cpumap_hard,
> diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
> index f9e3ef5..19ec076 100644
> --- a/tools/libxl/libxl.h
> +++ b/tools/libxl/libxl.h
> @@ -1715,6 +1715,10 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
>  int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
>                             const libxl_bitmap *cpumap_hard,
>                             const libxl_bitmap *cpumap_soft);
> +int libxl_set_vcpuaffinity_force(libxl_ctx *ctx, uint32_t domid,
> +                                 uint32_t vcpuid,
> +                                 const libxl_bitmap *cpumap_hard,
> +                                 const libxl_bitmap *cpumap_soft);

With the introduction of this new API you need to have a #define in
libxl.h

Wei.
Jürgen Groß March 8, 2016, 4:11 p.m. UTC | #3
On 08/03/16 16:58, Wei Liu wrote:
> On Thu, Mar 03, 2016 at 05:48:50PM +0100, Juergen Gross wrote:
> [...]
>>  int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
>>                                 unsigned int max_vcpus,
>>                                 const libxl_bitmap *cpumap_hard,
>> diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
>> index f9e3ef5..19ec076 100644
>> --- a/tools/libxl/libxl.h
>> +++ b/tools/libxl/libxl.h
>> @@ -1715,6 +1715,10 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
>>  int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
>>                             const libxl_bitmap *cpumap_hard,
>>                             const libxl_bitmap *cpumap_soft);
>> +int libxl_set_vcpuaffinity_force(libxl_ctx *ctx, uint32_t domid,
>> +                                 uint32_t vcpuid,
>> +                                 const libxl_bitmap *cpumap_hard,
>> +                                 const libxl_bitmap *cpumap_soft);
> 
> With the introduction of this new API you need to have a #define in
> libxl.h

Okay.


Juergen
Dario Faggioli March 8, 2016, 5:16 p.m. UTC | #4
On Thu, 2016-03-03 at 17:48 +0100, Juergen Gross wrote:
> In order to be able to undo a vcpu pin override in case of a kernel
> driver error add a flag "-f" to the "xl vcpu-pin" command forcing the
> hypervisor to undo the override.
> 
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>  tools/libxl/libxl.c       | 31 +++++++++++++++++++++++++------
>  tools/libxl/libxl.h       |  4 ++++
>  tools/libxl/xl_cmdimpl.c  | 27 +++++++++++++++++++++++----
>  tools/libxl/xl_cmdtable.c |  3 ++-
>
Actually, there's something I always forget when reviewing xl stuff,
which is that the xl manpage should be modified as well.

Sorry for (nearly) missing this! :-/

Regards,
Dario
Jürgen Groß March 8, 2016, 5:19 p.m. UTC | #5
On 08/03/16 18:16, Dario Faggioli wrote:
> On Thu, 2016-03-03 at 17:48 +0100, Juergen Gross wrote:
>> In order to be able to undo a vcpu pin override in case of a kernel
>> driver error add a flag "-f" to the "xl vcpu-pin" command forcing the
>> hypervisor to undo the override.
>>
>> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
>> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
>> Cc: Wei Liu <wei.liu2@citrix.com>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
>> ---
>>  tools/libxl/libxl.c       | 31 +++++++++++++++++++++++++------
>>  tools/libxl/libxl.h       |  4 ++++
>>  tools/libxl/xl_cmdimpl.c  | 27 +++++++++++++++++++++++----
>>  tools/libxl/xl_cmdtable.c |  3 ++-
>>
> Actually, there's something I always forget when reviewing xl stuff,
> which is that the xl manpage should be modified as well.

Yeah, I already thought of this, too.

Will add it.


Juergen

> 
> Sorry for (nearly) missing this! :-/
> 
> Regards,
> Dario
>
diff mbox

Patch

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 4cdc169..53f0100 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -5301,18 +5301,20 @@  err:
     return NULL;
 }
 
-int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
-                           const libxl_bitmap *cpumap_hard,
-                           const libxl_bitmap *cpumap_soft)
+static int libxl__set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid,
+                                   uint32_t vcpuid,
+                                   const libxl_bitmap *cpumap_hard,
+                                   const libxl_bitmap *cpumap_soft,
+                                   unsigned flags)
 {
     GC_INIT(ctx);
     libxl_bitmap hard, soft;
-    int rc, flags = 0;
+    int rc;
 
     libxl_bitmap_init(&hard);
     libxl_bitmap_init(&soft);
 
-    if (!cpumap_hard && !cpumap_soft) {
+    if (!cpumap_hard && !cpumap_soft && !flags) {
         rc = ERROR_INVAL;
         goto out;
     }
@@ -5327,7 +5329,7 @@  int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
             goto out;
 
         libxl__bitmap_copy_best_effort(gc, &hard, cpumap_hard);
-        flags = XEN_VCPUAFFINITY_HARD;
+        flags |= XEN_VCPUAFFINITY_HARD;
     }
     if (cpumap_soft) {
         rc = libxl_cpu_bitmap_alloc(ctx, &soft, 0);
@@ -5378,6 +5380,23 @@  int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
     return rc;
 }
 
+int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
+                           const libxl_bitmap *cpumap_hard,
+                           const libxl_bitmap *cpumap_soft)
+{
+    return libxl__set_vcpuaffinity(ctx, domid, vcpuid, cpumap_hard,
+                                   cpumap_soft, 0);
+}
+
+int libxl_set_vcpuaffinity_force(libxl_ctx *ctx, uint32_t domid,
+                                 uint32_t vcpuid,
+                                 const libxl_bitmap *cpumap_hard,
+                                 const libxl_bitmap *cpumap_soft)
+{
+    return libxl__set_vcpuaffinity(ctx, domid, vcpuid, cpumap_hard,
+                                   cpumap_soft, XEN_VCPUAFFINITY_FORCE);
+}
+
 int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
                                unsigned int max_vcpus,
                                const libxl_bitmap *cpumap_hard,
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index f9e3ef5..19ec076 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1715,6 +1715,10 @@  int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
 int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
                            const libxl_bitmap *cpumap_hard,
                            const libxl_bitmap *cpumap_soft);
+int libxl_set_vcpuaffinity_force(libxl_ctx *ctx, uint32_t domid,
+                                 uint32_t vcpuid,
+                                 const libxl_bitmap *cpumap_hard,
+                                 const libxl_bitmap *cpumap_soft);
 int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
                                unsigned int max_vcpus,
                                const libxl_bitmap *cpumap_hard,
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 411473d..120f30b 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -5344,6 +5344,10 @@  int main_vcpulist(int argc, char **argv)
 
 int main_vcpupin(int argc, char **argv)
 {
+    static struct option opts[] = {
+        {"force", 0, 0, 'f'},
+        COMMON_LONG_OPTS
+    };
     libxl_vcpuinfo *vcpuinfo;
     libxl_bitmap cpumap_hard, cpumap_soft;;
     libxl_bitmap *soft = &cpumap_soft, *hard = &cpumap_hard;
@@ -5355,13 +5359,17 @@  int main_vcpupin(int argc, char **argv)
     long vcpuid;
     const char *vcpu, *hard_str, *soft_str;
     char *endptr;
-    int opt, nb_cpu, nb_vcpu, rc = EXIT_FAILURE;
+    int opt, nb_cpu, nb_vcpu, force = 0, rc = EXIT_FAILURE;
 
     libxl_bitmap_init(&cpumap_hard);
     libxl_bitmap_init(&cpumap_soft);
 
-    SWITCH_FOREACH_OPT(opt, "", NULL, "vcpu-pin", 3) {
-        /* No options */
+    SWITCH_FOREACH_OPT(opt, "f", opts, "vcpu-pin", 3) {
+    case 'f':
+        force = 1;
+        break;
+    default:
+        break;
     }
 
     domid = find_domain(argv[optind]);
@@ -5376,6 +5384,10 @@  int main_vcpupin(int argc, char **argv)
             fprintf(stderr, "Error: Invalid argument %s as VCPU.\n", vcpu);
             goto out;
         }
+        if (force) {
+            fprintf(stderr, "Error: --force and 'all' as VCPU not allowed.\n");
+            goto out;
+        }
         vcpuid = -1;
     }
 
@@ -5437,7 +5449,14 @@  int main_vcpupin(int argc, char **argv)
         goto out;
     }
 
-    if (vcpuid != -1) {
+    if (force) {
+        if (libxl_set_vcpuaffinity_force(ctx, domid, vcpuid, hard, soft)) {
+            fprintf(stderr, "Could not set affinity for vcpu `%ld'.\n",
+                    vcpuid);
+            goto out;
+        }
+    }
+    else if (vcpuid != -1) {
         if (libxl_set_vcpuaffinity(ctx, domid, vcpuid, hard, soft)) {
             fprintf(stderr, "Could not set affinity for vcpu `%ld'.\n",
                     vcpuid);
diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
index fdc1ac6..7cc0401 100644
--- a/tools/libxl/xl_cmdtable.c
+++ b/tools/libxl/xl_cmdtable.c
@@ -222,7 +222,8 @@  struct cmd_spec cmd_table[] = {
     { "vcpu-pin",
       &main_vcpupin, 1, 1,
       "Set which CPUs a VCPU can use",
-      "<Domain> <VCPU|all> <Hard affinity|-|all> <Soft affinity|-|all>",
+      "[option] <Domain> <VCPU|all> <Hard affinity|-|all> <Soft affinity|-|all>",
+      "-f, --force        undo an override pinning done by the kernel",
     },
     { "vcpu-set",
       &main_vcpuset, 0, 1,