[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt



On Wed, 2012-02-22 at 21:40 +0000, Jim Fehlig wrote:
> Ian Jackson wrote:
> > Bamvor Jian Zhang writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix 
> > compile error of libvirt"):
> >   
> >> Ian Jackson wrote: 
> >>     
> >>> Users of libxl should not be using libxc directly and therefore should 
> >>> not be including xenctrl.h. 
> >>>       
> > ...
> >   
> >> but after your commit "23174:751c6dcec0d4"(remove xenctrl.h from libxl.h), 
> >> the aplication(like libvirt) compile fail. How do i deal with it? 
> >> it seems that add __XEN_TOOLS_ to libvirt code is not good. 
> >>     
> >
> > Can you tell us the error message you get ?  I think the problem is
> > probably that libvirt is trying to use libxc directly.
> >   
> 
> The libvirt libxl driver doesn't use libxc directly. AFAICT, the problem
> is that libxl.h includes <xen/sysctl.h>, which has this
> 
> #if !defined(__XEN__) && !defined(__XEN_TOOLS__)
> #error "sysctl operations are intended for use by node control tools only"
> #endif
> 
> Without the defines, Bamvor is hitting the #error directive.

I thought we'd discussed and resolved this ages ago but I guess we only
discussed it...

How about the following:

8<-------------------------------------------------

# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1329986233 0
# Node ID d256d6b42ee77cdff0356c37d6fcaf6203a21ba6
# Parent  aa82c27ea0a3cdfb5e58244918d2046cf4e314a9
libxl: remove sysctl.h from public interface

Using sysctl.h is restricted to "node control tools only" and requires magic
defines. Therefore make its use internal to libxl.

Also removes an indirect include of domctl.h which has the same restrction.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Feb 22 14:43:57 2012 +0000
+++ b/tools/libxl/libxl.c       Thu Feb 23 08:37:13 2012 +0000
@@ -491,7 +491,7 @@ libxl_cpupoolinfo * libxl_list_cpupool(l
         }
         ptr = tmp;
         ptr[i].poolid = info->cpupool_id;
-        ptr[i].sched_id = info->sched_id;
+        ptr[i].sched = info->sched_id;
         ptr[i].n_dom = info->n_dom;
         if (libxl_cpumap_alloc(ctx, &ptr[i].cpumap)) {
             xc_cpupool_infofree(ctx->xch, info);
@@ -2750,7 +2750,10 @@ int libxl_get_physinfo(libxl_ctx *ctx, l
     physinfo->sharing_used_frames = xc_sharing_used_frames(ctx->xch);
     physinfo->nr_nodes = xcphysinfo.nr_nodes;
     memcpy(physinfo->hw_cap,xcphysinfo.hw_cap, sizeof(physinfo->hw_cap));
-    physinfo->phys_cap = xcphysinfo.capabilities;
+
+    physinfo->cap_hvm = !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_hvm);
+    physinfo->cap_hvm_directio =
+        !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_hvm_directio);
 
     return 0;
 }
@@ -2965,14 +2968,11 @@ out:
     return rc;
 }
 
-/*
- * returns one of the XEN_SCHEDULER_* constants from public/domctl.h
- */
-int libxl_get_sched_id(libxl_ctx *ctx)
+libxl_scheduler libxl_get_scheduler(libxl_ctx *ctx)
 {
-    int sched, ret;
-
-    if ((ret = xc_sched_id(ctx->xch, &sched)) != 0) {
+    libxl_scheduler sched, ret;
+
+    if ((ret = xc_sched_id(ctx->xch, (int *)&sched)) != 0) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain info list");
         return ERROR_FAIL;
     }
@@ -3445,7 +3445,8 @@ int libxl_get_freecpus(libxl_ctx *ctx, l
     return 0;
 }
 
-int libxl_cpupool_create(libxl_ctx *ctx, const char *name, int schedid,
+int libxl_cpupool_create(libxl_ctx *ctx, const char *name,
+                         libxl_scheduler sched,
                          libxl_cpumap cpumap, libxl_uuid *uuid,
                          uint32_t *poolid)
 {
@@ -3461,7 +3462,7 @@ int libxl_cpupool_create(libxl_ctx *ctx,
         return ERROR_NOMEM;
     }
 
-    rc = xc_cpupool_create(ctx->xch, poolid, schedid);
+    rc = xc_cpupool_create(ctx->xch, poolid, sched);
     if (rc) {
         LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
            "Could not create cpupool");
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Feb 22 14:43:57 2012 +0000
+++ b/tools/libxl/libxl.h       Thu Feb 23 08:37:13 2012 +0000
@@ -138,7 +138,6 @@
 #include <xentoollog.h>
 
 #include <xen/sched.h>
-#include <xen/sysctl.h>
 
 #include <libxl_uuid.h>
 #include <_libxl_list.h>
@@ -584,7 +583,7 @@ int libxl_set_vcpuaffinity_all(libxl_ctx
                                unsigned int max_vcpus, libxl_cpumap *cpumap);
 int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_cpumap *cpumap);
 
-int libxl_get_sched_id(libxl_ctx *ctx);
+libxl_scheduler libxl_get_scheduler(libxl_ctx *ctx);
 
 
 int libxl_sched_credit_domain_get(libxl_ctx *ctx, uint32_t domid,
@@ -627,7 +626,8 @@ int libxl_tmem_shared_auth(libxl_ctx *ct
 int libxl_tmem_freeable(libxl_ctx *ctx);
 
 int libxl_get_freecpus(libxl_ctx *ctx, libxl_cpumap *cpumap);
-int libxl_cpupool_create(libxl_ctx *ctx, const char *name, int schedid,
+int libxl_cpupool_create(libxl_ctx *ctx, const char *name,
+                         libxl_scheduler sched,
                          libxl_cpumap cpumap, libxl_uuid *uuid,
                          uint32_t *poolid);
 int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid);
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl       Wed Feb 22 14:43:57 2012 +0000
+++ b/tools/libxl/libxl_types.idl       Thu Feb 23 08:37:13 2012 +0000
@@ -99,6 +99,14 @@ libxl_timer_mode = Enumeration("timer_mo
     (3, "one_missed_tick_pending"),
     ])
 
+# Consistent with values defined in domctl.h
+libxl_scheduler = Enumeration("scheduler", [
+    (4, "sedf"),
+    (5, "credit"),
+    (6, "credit2"),
+    (7, "arinc653"),
+    ])
+
 #
 # Complex libxl types
 #
@@ -158,7 +166,7 @@ libxl_dominfo = Struct("dominfo",[
 
 libxl_cpupoolinfo = Struct("cpupoolinfo", [
     ("poolid",      uint32),
-    ("sched_id",    uint32),
+    ("sched",       libxl_scheduler),
     ("n_dom",       uint32),
     ("cpumap",      libxl_cpumap)
     ])
@@ -381,7 +389,9 @@ libxl_physinfo = Struct("physinfo", [
 
     ("nr_nodes", uint32),
     ("hw_cap", libxl_hwcap),
-    ("phys_cap", uint32),
+
+    ("cap_hvm", bool),
+    ("cap_hvm_directio", bool),
     ], dispose_fn=None, dir=DIR_OUT)
 
 libxl_cputopology = Struct("cputopology", [
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Wed Feb 22 14:43:57 2012 +0000
+++ b/tools/libxl/libxl_utils.c Thu Feb 23 08:37:13 2012 +0000
@@ -19,18 +19,6 @@
 
 #include "libxl_internal.h"
 
-struct schedid_name {
-    char *name;
-    int id;
-};
-
-static struct schedid_name schedid_name[] = {
-    { "credit", XEN_SCHEDULER_CREDIT },
-    { "sedf", XEN_SCHEDULER_SEDF },
-    { "credit2", XEN_SCHEDULER_CREDIT2 },
-    { NULL, -1 }
-};
-
 const char *libxl_basename(const char *name)
 {
     const char *filename;
@@ -151,28 +139,6 @@ int libxl_name_to_cpupoolid(libxl_ctx *c
     return ret;
 }
 
-int libxl_name_to_schedid(libxl_ctx *ctx, const char *name)
-{
-    int i;
-
-    for (i = 0; schedid_name[i].name != NULL; i++)
-        if (strcmp(name, schedid_name[i].name) == 0)
-            return schedid_name[i].id;
-
-    return ERROR_INVAL;
-}
-
-char *libxl_schedid_to_name(libxl_ctx *ctx, int schedid)
-{
-    int i;
-
-    for (i = 0; schedid_name[i].name != NULL; i++)
-        if (schedid_name[i].id == schedid)
-            return schedid_name[i].name;
-
-    return "unknown";
-}
-
 int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid)
 {
     GC_INIT(ctx);
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h Wed Feb 22 14:43:57 2012 +0000
+++ b/tools/libxl/libxl_utils.h Thu Feb 23 08:37:13 2012 +0000
@@ -24,8 +24,6 @@ int libxl_name_to_domid(libxl_ctx *ctx, 
 char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid);
 int libxl_name_to_cpupoolid(libxl_ctx *ctx, const char *name, uint32_t 
*poolid);
 char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid);
-int libxl_name_to_schedid(libxl_ctx *ctx, const char *name);
-char *libxl_schedid_to_name(libxl_ctx *ctx, int schedid);
 int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid);
 int libxl_is_stubdom(libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid);
 int libxl_create_logfile(libxl_ctx *ctx, char *name, char **full_name);
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed Feb 22 14:43:57 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Thu Feb 23 08:37:13 2012 +0000
@@ -3688,15 +3688,15 @@ int main_vcpuset(int argc, char **argv)
 static void output_xeninfo(void)
 {
     const libxl_version_info *info;
-    int sched_id;
+    libxl_scheduler sched;
 
     if (!(info = libxl_get_version_info(ctx))) {
         fprintf(stderr, "libxl_get_version_info failed.\n");
         return;
     }
 
-    if ((sched_id = libxl_get_sched_id(ctx)) < 0) {
-        fprintf(stderr, "get_sched_id sysctl failed.\n");
+    if ((sched = libxl_get_scheduler(ctx)) < 0) {
+        fprintf(stderr, "get_scheduler sysctl failed.\n");
         return;
     }
 
@@ -3704,7 +3704,7 @@ static void output_xeninfo(void)
     printf("xen_minor              : %d\n", info->xen_version_minor);
     printf("xen_extra              : %s\n", info->xen_version_extra);
     printf("xen_caps               : %s\n", info->capabilities);
-    printf("xen_scheduler          : %s\n", libxl_schedid_to_name(ctx, 
sched_id));
+    printf("xen_scheduler          : %s\n", libxl_scheduler_to_string(sched));
     printf("xen_pagesize           : %u\n", info->pagesize);
     printf("platform_params        : virt_start=0x%"PRIx64"\n", 
info->virt_start);
     printf("xen_changeset          : %s\n", info->changeset);
@@ -3752,9 +3752,9 @@ static void output_physinfo(void)
     for (i = 0; i < 8; i++)
         printf("%08x%c", info.hw_cap[i], i < 7 ? ':' : '\n');
     printf("virt_caps              :");
-    if (info.phys_cap & XEN_SYSCTL_PHYSCAP_hvm)
+    if (info.cap_hvm)
         printf(" hvm");
-    if (info.phys_cap & XEN_SYSCTL_PHYSCAP_hvm_directio)
+    if (info.cap_hvm_directio)
         printf(" hvm_directio");
     printf("\n");
     vinfo = libxl_get_version_info(ctx);
@@ -4060,7 +4060,7 @@ static int sched_sedf_domain_output(
 }
 
 static int sched_domain_output(
-    uint32_t sched, int (*output)(int), const char *cpupool)
+    libxl_scheduler sched, int (*output)(int), const char *cpupool)
 {
     libxl_dominfo *info;
     libxl_cpupoolinfo *poolinfo = NULL;
@@ -4089,7 +4089,7 @@ static int sched_domain_output(
     }
 
     for (p = 0; !rc && (p < n_pools); p++) {
-        if ((poolinfo[p].sched_id != sched) ||
+        if ((poolinfo[p].sched != sched) ||
             (cpupool && (poolid != poolinfo[p].poolid)))
             continue;
 
@@ -4170,7 +4170,7 @@ int main_sched_credit(int argc, char **a
     }
 
     if (!dom) { /* list all domain's credit scheduler info */
-        return -sched_domain_output(XEN_SCHEDULER_CREDIT,
+        return -sched_domain_output(LIBXL_SCHEDULER_CREDIT,
                                     sched_credit_domain_output, cpupool);
     } else {
         find_domain(dom);
@@ -4246,7 +4246,7 @@ int main_sched_credit2(int argc, char **
     }
 
     if (!dom) { /* list all domain's credit scheduler info */
-        return -sched_domain_output(XEN_SCHEDULER_CREDIT2,
+        return -sched_domain_output(LIBXL_SCHEDULER_CREDIT2,
                                     sched_credit2_domain_output, cpupool);
     } else {
         find_domain(dom);
@@ -4348,7 +4348,7 @@ int main_sched_sedf(int argc, char **arg
     }
 
     if (!dom) { /* list all domain's credit scheduler info */
-        return -sched_domain_output(XEN_SCHEDULER_SEDF,
+        return -sched_domain_output(LIBXL_SCHEDULER_SEDF,
                                     sched_sedf_domain_output, cpupool);
     } else {
         find_domain(dom);
@@ -5287,9 +5287,8 @@ int main_cpupoolcreate(int argc, char **
     XLU_Config *config;
     const char *buf;
     const char *name;
-    const char *sched;
     uint32_t poolid;
-    int schedid = -1;
+    libxl_scheduler sched = 0;
     XLU_ConfigList *cpus;
     XLU_ConfigList *nodes;
     int n_cpus, n_nodes, i, n;
@@ -5384,17 +5383,16 @@ int main_cpupoolcreate(int argc, char **
     }
 
     if (!xlu_cfg_get_string (config, "sched", &buf, 0)) {
-        if ((schedid = libxl_name_to_schedid(ctx, buf)) < 0) {
+        if ((libxl_scheduler_from_string(buf, &sched)) < 0) {
             fprintf(stderr, "Unknown scheduler\n");
             return -ERROR_FAIL;
         }
     } else {
-        if ((schedid = libxl_get_sched_id(ctx)) < 0) {
-            fprintf(stderr, "get_sched_id sysctl failed.\n");
+        if ((sched = libxl_get_scheduler(ctx)) < 0) {
+            fprintf(stderr, "get_scheduler sysctl failed.\n");
             return -ERROR_FAIL;
         }
     }
-    sched = libxl_schedid_to_name(ctx, schedid);
 
     if (libxl_get_freecpus(ctx, &freemap)) {
         fprintf(stderr, "libxl_get_freecpus failed\n");
@@ -5462,14 +5460,14 @@ int main_cpupoolcreate(int argc, char **
 
     printf("Using config file \"%s\"\n", filename);
     printf("cpupool name:   %s\n", name);
-    printf("scheduler:      %s\n", sched);
+    printf("scheduler:      %s\n", libxl_scheduler_to_string(sched));
     printf("number of cpus: %d\n", n_cpus);
 
     if (dryrun_only)
         return 0;
 
     poolid = 0;
-    if (libxl_cpupool_create(ctx, name, schedid, cpumap, &uuid, &poolid)) {
+    if (libxl_cpupool_create(ctx, name, sched, cpumap, &uuid, &poolid)) {
         fprintf(stderr, "error on creating cpupool\n");
         return -ERROR_FAIL;
     }
@@ -5554,7 +5552,7 @@ int main_cpupoollist(int argc, char **ar
                     }
                 if (!opt_cpus) {
                     printf("%3d %9s       y       %4d", n,
-                           libxl_schedid_to_name(ctx, poolinfo[p].sched_id),
+                           libxl_scheduler_to_string(poolinfo[p].sched),
                            poolinfo[p].n_dom);
                 }
                 printf("\n");
@@ -5739,7 +5737,7 @@ int main_cpupoolnumasplit(int argc, char
     int c;
     int n;
     uint32_t poolid;
-    int schedid;
+    libxl_scheduler sched;
     int n_pools;
     int node;
     int n_cpus;
@@ -5760,7 +5758,7 @@ int main_cpupoolnumasplit(int argc, char
         return -ERROR_NOMEM;
     }
     poolid = poolinfo[0].poolid;
-    schedid = poolinfo[0].sched_id;
+    sched = poolinfo[0].sched;
     for (p = 0; p < n_pools; p++) {
         libxl_cpupoolinfo_dispose(poolinfo + p);
     }
@@ -5840,7 +5838,7 @@ int main_cpupoolnumasplit(int argc, char
         snprintf(name, 15, "Pool-node%d", node);
         libxl_uuid_generate(&uuid);
         poolid = 0;
-        ret = -libxl_cpupool_create(ctx, name, schedid, cpumap, &uuid, 
&poolid);
+        ret = -libxl_cpupool_create(ctx, name, sched, cpumap, &uuid, &poolid);
         if (ret) {
             fprintf(stderr, "error on creating cpupool\n");
             goto out;



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.