Skip to contentSkip to conversation

libxl: fix compile error of libvirt

PATCH In review Bamvor Jian Zhang 4 participants 18 messages Feb 20, 2012 – Feb 24, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: fix compile error of libvirt

a, libxl_event.h is included in libxl.h. So, the former one also need to be installed.
b, define __XEN_TOOLS__ in libxl.h:
the head file "xen/sysctl.h" need check this macro.
It is the same way used by the xen libxc public headers(tools/libxc/xenctrl.h and tools/libxc/xenctrlosdep.h).

tools/libxl/MakefileMon Feb 20 15:36:09 2012 +0800 renamed from tools/libxl/MakefileFri Feb 17 12:24:38 2012 +0000 +1 -1
diff -r 87218bd367be tools/libxl/Makefile 
@@ -163,7 +163,7 @@ 
 ln -sf libxlutil.so.$(XLUMAJOR).$(XLUMINOR) $(DESTDIR)$(LIBDIR)/libxlutil.so.$(XLUMAJOR) 
 ln -sf libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(LIBDIR)/libxlutil.so 
 $(INSTALL_DATA) libxlutil.a $(DESTDIR)$(LIBDIR) 
-$(INSTALL_DATA) libxl.h libxl_json.h _libxl_types.h _libxl_types_json.h _libxl_list.h libxl_utils.h libxl_uuid.h $(DESTDIR)$(INCLUDEDIR) 
+$(INSTALL_DATA) libxl.h libxl_json.h _libxl_types.h _libxl_types_json.h _libxl_list.h libxl_utils.h libxl_uuid.h libxl_event.h $(DESTDIR)$(INCLUDEDIR) 
 $(INSTALL_DATA) bash-completion $(DESTDIR)$(BASH_COMPLETION_DIR)/xl.sh 
  
 .PHONY: clean 
tools/libxl/libxl.hMon Feb 20 15:36:09 2012 +0800 renamed from tools/libxl/libxl.hFri Feb 17 12:24:38 2012 +0000 +5 -0
diff -r 87218bd367be tools/libxl/libxl.h 
@@ -127,6 +127,11 @@ 
 #ifndef LIBXL_H 
 #define LIBXL_H 
  
+/* Tell the Xen public headers we are a user-space tools build. */ 
+#ifndef __XEN_TOOLS__ 
+#define __XEN_TOOLS__ 1 
+#endif  
+ 
 #include <stdbool.h> 
 #include <stdint.h> 
 #include <stdarg.h>

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw

Bamvor Jian Zhang writes ("[Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 3 lines

a, libxl_event.h is included in libxl.h. So, the former one also need to be installed.

Well spotted. However, I'm afraid your mail has been very badly mangled by whatever program you used to send it. For this patch I reconstructed the change by hand and have committed it.

Quoted 2 lines

b, define __XEN_TOOLS__ in libxl.h:
the head file "xen/sysctl.h" need check this macro.

I don't think this is correct.

Quoted 2 lines

It is the same way used by the xen libxc public headers(tools/libxc/xenctrl.h and tools/libxc/xenctrlosdep.h).

Users of libxl should not be using libxc directly and therefore should not be including xenctrl.h.

Note that the API for libxl has changed in xen-unstable.hg compared to 4.1, and further changes are forthcoming. So there will have to be changes in libvirt.

Thanks,
Ian.

#2 lore raw
Quoted 10 lines · Ian Jackson

Bamvor Jian Zhang writes ("[Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 3 lines

a, libxl_event.h is included in libxl.h. So, the former one also need to be installed.

Well spotted. However, I'm afraid your mail has been very badly mangled by whatever program you used to send it. For this patch I reconstructed the change by hand and have committed it.

thanks. I will be careful in future.

Quoted 7 lines
Quoted 2 lines

b, define __XEN_TOOLS__ in libxl.h:
the head file "xen/sysctl.h" need check this macro.

I don't think this is correct.

Quoted 1 line

It is the same way used by the xen libxc public

headers(tools/libxc/xenctrl.h

Quoted 9 lines
Quoted 1 line

and tools/libxc/xenctrlosdep.h).

Users of libxl should not be using libxc directly and therefore should not be including xenctrl.h.

Note that the API for libxl has changed in xen-unstable.hg compared to 4.1, and further changes are forthcoming. So there will have to be changes in libvirt.

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.

Quoted 3 lines

Thanks,
Ian.

Thanks
bamvor

#3 lore raw

Bamvor Jian Zhang writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 3 lines
Quoted 2 lines · Ian Jackson

Users of libxl should not be using libxc directly and therefore should not be including xenctrl.h.

...

Quoted 2 lines

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.

Now there is an existing libxc/libxenstore-based libvirt driver for Xen but that should be in a separate file. The libxl-based driver should not use libxc.

Ian.

#4 lore raw
Quoted 10 lines · Ian Jackson

Bamvor Jian Zhang writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 3 lines
Quoted 2 lines · Ian Jackson

Users of libxl should not be using libxc directly and therefore should not be including xenctrl.h.

...

Quoted 2 lines

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.

Is the problem here libxc or the Xen public headers?

I thought we'd decided the latter was OK in users of libxl. e.g. xl has to use the SHUTDOWN_{poweroff,reboot,suspend} constants from xen/include/public/sched.h (and indeed libxl.h includes this header).

libxl.h also includes Xen's sysctl.h -- seems to be for XEN_SYSCTL_PHYSCAP_*. Really this case would be better exposing as a series of bools which are initialised from the hypercall provided flags mask by libxl (like we do for the various dominfo flags)

Personally I'd be happy to have libxl always define its own constants and remove this need for libxl users to use the Xen headers.

If we are going to do that it should go onto the 4.2 TODO list.

Ian.

#5 lore raw
In reply to Ian Jackson
Quoted 7 lines · Ian Jackson

Bamvor Jian Zhang writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 5 lines
Quoted 3 lines · Ian Jackson

Users of libxl should not be using libxc directly and therefore should not be including xenctrl.h.

Quoted 9 lines

...

Quoted 3 lines

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.

Regards,
Jim

#6 lore raw
Quoted 18 lines · Jim Fehlig
Quoted 7 lines · Ian Jackson

Bamvor Jian Zhang writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 5 lines
Quoted 3 lines · Ian Jackson

Users of libxl should not be using libxc directly and therefore should not be including xenctrl.h.

Quoted 9 lines

...

Quoted 3 lines

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.

Quoted 8 lines

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 <[email protected]> # 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.

tools/libxl/libxl.c +12 -11
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl.c
@@ -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");
tools/libxl/libxl.h +3 -3
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl.h
@@ -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);
tools/libxl/libxl_types.idl +12 -2
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl_types.idl
@@ -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", [
tools/libxl/libxl_utils.c +0 -34
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl_utils.c
@@ -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);
tools/libxl/libxl_utils.h +0 -2
diff -r aa82c27ea0a3 -r d256d6b42ee7 tools/libxl/libxl_utils.h
@@ -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);
tools/libxl/xl_cmdimpl.c +21 -23

155 lines not on this page · raw message

#7 lore raw
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Jim Fehlig
Quoted 7 lines · Ian Jackson

Bamvor Jian Zhang writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 5 lines
Quoted 3 lines · Ian Jackson

Users of libxl should not be using libxc directly and therefore should not be including xenctrl.h.

Quoted 9 lines

...

Quoted 3 lines

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

Quoted 6 lines
Quoted 1 line

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:

I also have the following, I think the benefits are less obvious for this one though but it does mean we are consistently avoiding all xen public headers in the libxl public API which at least has the benefit of being simple to describe.

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

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1329986824 0
# Node ID ad39625c16966fe004c25e5be81af0e32cf8646a # Parent d256d6b42ee77cdff0356c37d6fcaf6203a21ba6
libxl: Remove xen/sched.h from public interface

tools/libxl/libxl.h +1 -8
diff -r d256d6b42ee7 -r ad39625c1696 tools/libxl/libxl.h
@@ -137,8 +137,6 @@
 
 #include <xentoollog.h>
 
-#include <xen/sched.h>
-
 #include <libxl_uuid.h>
 #include <_libxl_list.h>
 
@@ -638,12 +636,7 @@ int libxl_cpupool_cpuremove(libxl_ctx *c
 int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus);
 int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid);
 
-static inline int libxl_domid_valid_guest(uint32_t domid)
-{
-    /* returns 1 if the value _could_ be a valid guest domid, 0 otherwise
-     * does not check whether the domain actually exists */
-    return domid > 0 && domid < DOMID_FIRST_RESERVED;
-}
+int libxl_domid_valid_guest(uint32_t domid);
 
 int libxl_flask_context_to_sid(libxl_ctx *ctx, char *buf, size_t len,
                                uint32_t *ssidref);
tools/libxl/libxl_types.idl +10 -1
diff -r d256d6b42ee7 -r ad39625c1696 tools/libxl/libxl_types.idl
@@ -107,6 +107,15 @@ libxl_scheduler = Enumeration("scheduler
     (7, "arinc653"),
     ])
 
+# Consistent with SHUTDOWN_* in sched.h
+libxl_shutdown_reason = Enumeration("shutdown_reason", [
+    (0, "poweroff"),
+    (1, "reboot"),
+    (2, "suspend"),
+    (3, "crash"),
+    (4, "watchdog"),
+    ])
+
 #
 # Complex libxl types
 #
@@ -154,7 +163,7 @@ libxl_dominfo = Struct("dominfo",[
     #
     # Otherwise set to a value guaranteed not to clash with any valid
     # SHUTDOWN_* constant.
-    ("shutdown_reason", uint8),
+    ("shutdown_reason", libxl_shutdown_reason),
     ("current_memkb",   uint64),
     ("shared_memkb", uint64),
     ("max_memkb",   uint64),
tools/libxl/libxl_utils.c +7 -0
diff -r d256d6b42ee7 -r ad39625c1696 tools/libxl/libxl_utils.c
@@ -507,6 +507,13 @@ void libxl_cputopology_list_free(libxl_c
     free(list);
 }
 
+int libxl_domid_valid_guest(uint32_t domid)
+{
+    /* returns 1 if the value _could_ be a valid guest domid, 0 otherwise
+     * does not check whether the domain actually exists */
+    return domid > 0 && domid < DOMID_FIRST_RESERVED;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/xl_cmdimpl.c +5 -5
diff -r d256d6b42ee7 -r ad39625c1696 tools/libxl/xl_cmdimpl.c
@@ -1230,19 +1230,19 @@ static int handle_domain_death(libxl_ctx
     libxl_action_on_shutdown action;
 
     switch (event->u.domain_shutdown.shutdown_reason) {
-    case SHUTDOWN_poweroff:
+    case LIBXL_SHUTDOWN_REASON_POWEROFF:
         action = d_config->on_poweroff;
         break;
-    case SHUTDOWN_reboot:
+    case LIBXL_SHUTDOWN_REASON_REBOOT:
         action = d_config->on_reboot;
         break;
-    case SHUTDOWN_suspend:
+    case LIBXL_SHUTDOWN_REASON_SUSPEND:
         LOG("Domain has suspended.");
         return 0;
-    case SHUTDOWN_crash:
+    case LIBXL_SHUTDOWN_REASON_CRASH:
         action = d_config->on_crash;
         break;
-    case SHUTDOWN_watchdog:
+    case LIBXL_SHUTDOWN_REASON_WATCHDOG:
         action = d_config->on_watchdog;
         break;
     default:
#8 lore raw
Quoted 27 lines · Ian Campbell
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Jim Fehlig
Quoted 7 lines · Ian Jackson

Bamvor Jian Zhang writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 5 lines
Quoted 3 lines · Ian Jackson

Users of libxl should not be using libxc directly and therefore should not be including xenctrl.h.

Quoted 9 lines

...

Quoted 3 lines

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

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

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:

I also have the following,

One or both of which break the bindings build...

I'll resend as precursor to my resend of the "better defaults handling". Simply because there are some textual conflicts between the two.

I'd still be happy to have Acks for the libxl side though (the bindings changes will be obvious I expect)

Ian.

#9 lore raw
In reply to Jim Fehlig

Jim Fehlig writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 8 lines

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 see. Hmm. I have investigated further and:

xl.c contained #include <xenctrl.h> which is definitely very wrong. when I
(a) #undef __XEN_TOOLS__ at the top of xl.c
(b) remove that
I can reproduce the error in-tree.

I'm unsure as to whether we should expect libxl callers include <xen/sysctl.h>. I think my view is that including these Xen public headers for things like Xen sysctl numbers, scheduler parameter numbers, etc., is fine. Ian, what do you think ?

But we definitely need to do something to stop libxl callers, including xl, including xenctrl.h.

Ian.

#10 lore raw
Quoted 10 lines · Ian Jackson

Jim Fehlig writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 8 lines

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.

Quoted 7 lines

I see. Hmm. I have investigated further and:

xl.c contained #include <xenctrl.h> which is definitely very wrong. when I
(a) #undef __XEN_TOOLS__ at the top of xl.c
(b) remove that
I can reproduce the error in-tree.

Doing this with the two patches I sent yesterday works. (I resewnt them at the head of my repost of the "libxl: improved handling for default values in API" series.

We should arrange for xl*.c to not have __XEN_TOOLS__ defined though.

-D__XEN_TOOLS__ is part of the base CFLAGS defined in tools/Rules.mk but perhaps we could add -U__XEN_TOOLS__ to the xl specific cflags?

Quoted 7 lines

I'm unsure as to whether we should expect libxl callers include <xen/sysctl.h>. I think my view is that including these Xen public headers for things like Xen sysctl numbers, scheduler parameter numbers, etc., is fine. Ian, what do you think ?

But we definitely need to do something to stop libxl callers, including xl, including xenctrl.h.

We can stop xl by just not doing it (TM), for other callers of libxl -- well, we say you shouldn't need it for toolstack operations and that libxl should provide all the functionality but if they _really_ want to ignore that...

Also a toolstack may have functionality which is not considered "toolstack functionality" per the remit of libxl and for which they wish to use xenctrl directly. e.g. perhaps they communicate with a guest agent using their own shared ring protocol for which they require the ability to map domain memory.

Ian.

#11 lore raw

Ian Campbell writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 4 lines

We should arrange for xl*.c to not have __XEN_TOOLS__ defined though.

-D__XEN_TOOLS__ is part of the base CFLAGS defined in tools/Rules.mk but perhaps we could add -U__XEN_TOOLS__ to the xl specific cflags?

That would be a possibility but if we define it in libxl.h that will fix the problem, if we are happy for libxl callers to be using hypervisor public headers.

Quoted 10 lines

We can stop xl by just not doing it (TM), for other callers of libxl -- well, we say you shouldn't need it for toolstack operations and that libxl should provide all the functionality but if they _really_ want to ignore that...

Also a toolstack may have functionality which is not considered "toolstack functionality" per the remit of libxl and for which they wish to use xenctrl directly. e.g. perhaps they communicate with a guest agent using their own shared ring protocol for which they require the ability to map domain memory.

How about the patch below. This would be an alternative to your version which buries all the hypervisor public headers.

Ian.

From: Ian Jackson <[email protected]>
Subject: [PATCH] libxl: Forbid <xenctrl.h>, allow Xen public headers

Rationalise and enforce the header-inclusion policy for libxl.

libxl applications are allowed to use symbols (mostly #defines) from the Xen public headers, where these are useful (for example, where they are the numeric arguments to libxl calls). This avoids us having to veneer the whole of the Xen public API. For this to work without special measures on the part of the application, libxl.h should define __XEN_TOOLS__.

However libxl applications are not normally expected to want to use libxc directly, so take steps to prevent them including <xenctrl.h> unless they declare (as libxl itself does) that doing so is OK by defining LIBXL_ALLOW_XENCTRL. (We have to add a hook at the end of xenctrl.h so that we can spot the case where xenctrl.h is included second.)

Make xc.c comply with the policy: remove the redundant inclusion of xenctrl.h.

This patch should make life easier for out-of-tree libxl callers and hopefully prevent future mistakes relating to api visibility.

---
 tools/libxc/xenctrl.h        |    4 ++++
 tools/libxl/libxl.h          |   10 ++++++++++
 tools/libxl/libxl_internal.h |    2 ++
 tools/libxl/xl.c             |    1 -
 4 files changed, 16 insertions(+), 1 deletions(-)
tools/libxc/xenctrl.h +4 -0
index 73d24e5..8441b62 100644
@@ -2047,4 +2047,8 @@ int xc_compression_uncompress_page(xc_interface *xch, char *compbuf,
 				   unsigned long compbuf_size,
 				   unsigned long *compbuf_pos, char *dest);
 
+#ifdef XENCTRL_DO_INCLUDE
+#include XENCTRL_DO_INCLUDE
+#endif
+
 #endif /* XENCTRL_H */
tools/libxl/libxl.h +10 -0
index 1bffa03..86a308d 100644
@@ -124,9 +124,19 @@
  * Therefore public functions which initialize a libxl__gc MUST call
  * libxl__free_all() before returning.
  */
+
+#if !defined(LIBXL_ALLOW_XENCTRL)
+#ifdef XENCTRL_H
+#error applications which use libxl should not normally use xenctrl.h too
+#endif
+#define XENCTRL_DO_INCLUDE <libxl.h> /* spot if xenctrl.h came second */
+#endif /* !defined(LIBXL_ALLOW_XENCTRL) */
+
 #ifndef LIBXL_H
 #define LIBXL_H
 
+#define __XEN_TOOLS__ 1
+
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdarg.h>
tools/libxl/libxl_internal.h +2 -0
index 46e131a..478de48 100644
@@ -17,6 +17,8 @@
 #ifndef LIBXL_INTERNAL_H
 #define LIBXL_INTERNAL_H
 
+#define LIBXL_ALLOW_XENCTRL
+
 #include "libxl_osdeps.h" /* must come before any other headers */
 
 #include <assert.h>
tools/libxl/xl.c +0 -1
index df9b1e7..2b14814 100644
@@ -26,7 +26,6 @@
 #include <fcntl.h>
 #include <ctype.h>
 #include <inttypes.h>
-#include <xenctrl.h>
 
 #include "libxl.h"
 #include "libxl_utils.h"
Signature · 1 line
tg: (fa6fc38..) t/xen/xl.xenctrl.forbid (depends on: t/xen/gitignore)
#12 lore raw

(I could have sworn I hit send on this. apologies if you get it twice somehow)

Quoted 15 lines · Ian Jackson

Ian Campbell writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 4 lines

We should arrange for xl*.c to not have __XEN_TOOLS__ defined though.

-D__XEN_TOOLS__ is part of the base CFLAGS defined in tools/Rules.mk but perhaps we could add -U__XEN_TOOLS__ to the xl specific cflags?

That would be a possibility but if we define it in libxl.h that will fix the problem, if we are happy for libxl callers to be using hypervisor public headers.

Quoted 5 lines

We can stop xl by just not doing it (TM), for other callers of libxl -- well, we say you shouldn't need it for toolstack operations and that libxl should provide all the functionality but if they _really_ want to ignore that...

Quoted 8 lines
Quoted 5 lines

Also a toolstack may have functionality which is not considered "toolstack functionality" per the remit of libxl and for which they wish to use xenctrl directly. e.g. perhaps they communicate with a guest agent using their own shared ring protocol for which they require the ability to map domain memory.

How about the patch below. This would be an alternative to your version which buries all the hypervisor public headers.

It's clever, some might say too clever ;-)

I'm a bit concerned about the use of domctl and sysctl in the libxl API anyway -- I'm not convinced those are guaranteed to be stable ABIs by the hypervisor (in fact, I'm reasonably sure they are not -- hence the #error), in which case we mustn't expose them to libxl's users.

sched.h concerns me less -- that one is guest visible API IIRC and therefore stable. But sched.h doesn't have a #error in it so isn't a problem.

So I think we have to take the first of my patches. At which point we can avoid the twisty maze of your patch using -U... as necessary.

Ian.

Quoted 99 lines

Ian.

From: Ian Jackson <[email protected]>
Subject: [PATCH] libxl: Forbid <xenctrl.h>, allow Xen public headers

Rationalise and enforce the header-inclusion policy for libxl.

libxl applications are allowed to use symbols (mostly #defines) from the Xen public headers, where these are useful (for example, where they are the numeric arguments to libxl calls). This avoids us having to veneer the whole of the Xen public API. For this to work without special measures on the part of the application, libxl.h should define __XEN_TOOLS__.

However libxl applications are not normally expected to want to use libxc directly, so take steps to prevent them including <xenctrl.h> unless they declare (as libxl itself does) that doing so is OK by defining LIBXL_ALLOW_XENCTRL. (We have to add a hook at the end of xenctrl.h so that we can spot the case where xenctrl.h is included second.)

Make xc.c comply with the policy: remove the redundant inclusion of xenctrl.h.

This patch should make life easier for out-of-tree libxl callers and hopefully prevent future mistakes relating to api visibility.

---
 tools/libxc/xenctrl.h        |    4 ++++
 tools/libxl/libxl.h          |   10 ++++++++++
 tools/libxl/libxl_internal.h |    2 ++
 tools/libxl/xl.c             |    1 -
 4 files changed, 16 insertions(+), 1 deletions(-)
tools/libxc/xenctrl.h +4 -0
index 73d24e5..8441b62 100644
@@ -2047,4 +2047,8 @@ int xc_compression_uncompress_page(xc_interface *xch, char *compbuf,
 				   unsigned long compbuf_size,
 				   unsigned long *compbuf_pos, char *dest);
 
+#ifdef XENCTRL_DO_INCLUDE
+#include XENCTRL_DO_INCLUDE
+#endif
+
 #endif /* XENCTRL_H */
tools/libxl/libxl.h +10 -0
index 1bffa03..86a308d 100644
@@ -124,9 +124,19 @@
  * Therefore public functions which initialize a libxl__gc MUST call
  * libxl__free_all() before returning.
  */
+
+#if !defined(LIBXL_ALLOW_XENCTRL)
+#ifdef XENCTRL_H
+#error applications which use libxl should not normally use xenctrl.h too
+#endif
+#define XENCTRL_DO_INCLUDE <libxl.h> /* spot if xenctrl.h came second */
+#endif /* !defined(LIBXL_ALLOW_XENCTRL) */
+
 #ifndef LIBXL_H
 #define LIBXL_H
 
+#define __XEN_TOOLS__ 1
+
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdarg.h>
tools/libxl/libxl_internal.h +2 -0
index 46e131a..478de48 100644
@@ -17,6 +17,8 @@
 #ifndef LIBXL_INTERNAL_H
 #define LIBXL_INTERNAL_H
 
+#define LIBXL_ALLOW_XENCTRL
+
 #include "libxl_osdeps.h" /* must come before any other headers */
 
 #include <assert.h>
tools/libxl/xl.c +0 -1
index df9b1e7..2b14814 100644
@@ -26,7 +26,6 @@
 #include <fcntl.h>
 #include <ctype.h>
 #include <inttypes.h>
-#include <xenctrl.h>
 
 #include "libxl.h"
 #include "libxl_utils.h"
#13 lore raw
In reply to Ian Jackson
Quoted 10 lines · Ian Jackson

Bamvor Jian Zhang writes ("Re: [Xen-devel] [xen-devel] [PATCH] libxl: fix compile error of libvirt"):

Quoted 3 lines
Quoted 2 lines · Ian Jackson

Users of libxl should not be using libxc directly and therefore should not be including xenctrl.h.

...

Quoted 2 lines

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.

libtool: compile: gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I.. -I../gnulib/lib -I../gnulib/lib -I../include -I../include -I../src/util -DIN_LIBVIRT -I../src/conf -I../src/xenxs -I/usr/include/libxml2 -Wall -W -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wvolatile-register-var -Wdisabled-optimization -Wattributes -Wcoverage-mismatch -Wmultichar -Wdeprecated-declarations -Wdiv-by-zero -Wendif-labels -Wextra -Wformat-contains-nul -Wformat-
extra-args -Wformat-zero-length -Wformat=2 -Wmultichar -Wnormalized=nfc -Woverflow -Wpointer-to-int-cast -Wpragmas -Wno-missing-field-initializers -Wno-sign-compare -Wno-format-nonliteral -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time -fipa-pure-const -Werror -g -O2 -MT libvirt_driver_libxl_la-libxl_conf.lo -MD -MP -MF .deps/libvirt_driver_libxl_la-libxl_conf.Tpo -c libxl/libxl_conf.c -fPIC -DPIC -o .libs/libvirt_driver_libxl_la-libxl_conf.o
In file included from /usr/include/libxl.h:140,

                 from libxl/libxl_conf.c:29:
/usr/include/xen/sysctl.h:31:2: error: #error "sysctl operations are intended for use by node control tools only"
In file included from /usr/include/xen/sysctl.h:35,
                 from /usr/include/libxl.h:140,
                 from libxl/libxl_conf.c:29:
/usr/include/xen/domctl.h:32:2: error: #error "domctl operations are intended for use by node control tools only"
In file included from /usr/include/xen/sysctl.h:35,
                 from /usr/include/libxl.h:140,
                 from libxl/libxl_conf.c:29:
Quoted 5 lines

Now there is an existing libxc/libxenstore-based libvirt driver for Xen but that should be in a separate file. The libxl-based driver should not use libxc.

Ian.

#14 lore raw
In reply to Ian Jackson
Quoted 4 lines · Ian Jackson

Note that the API for libxl has changed in xen-unstable.hg compared to 4.1, and further changes are forthcoming. So there will have to be changes in libvirt.

I suppose libvirt is the only out-of-tree libxl app feeling this pain :-(.

Regards,
Jim

#15 lore raw
Quoted 7 lines · Jim Fehlig
Quoted 4 lines · Ian Jackson

Note that the API for libxl has changed in xen-unstable.hg compared to 4.1, and further changes are forthcoming. So there will have to be changes in libvirt.

I suppose libvirt is the only out-of-tree libxl app feeling this pain :-(.

We're sorry about this, we felt it was necessary to break the API between 4.1 and 4.2 in order that we can support a stable API from 4.2 onwards (I think we discussed this at the time?). From 4.2 onwards we will make changes in a compatible way or provide compatibility shims etc or in extreme circumstances do things in a way which is easily detectable e.g. via configure tests.

I was wondering the other day if "libxl v2" support for libvirt might make a nice GSoC project, what do you think? Would you be interested in mentoring such a project?

Ian.

#16 lore raw
Quoted 9 lines · Ian Campbell
Quoted 7 lines · Jim Fehlig
Quoted 5 lines · Ian Jackson

Note that the API for libxl has changed in xen-unstable.hg compared to 4.1, and further changes are forthcoming. So there will have to be changes in libvirt.

Quoted 6 lines
Quoted 2 lines

I suppose libvirt is the only out-of-tree libxl app feeling this pain :-(.

We're sorry about this, we felt it was necessary to break the API between 4.1 and 4.2 in order that we can support a stable API from 4.2 onwards (I think we discussed this at the time?).

Yes we did, and I need to stop whining about it :-).

Quoted 5 lines

From 4.2 onwards we
will make changes in a compatible way or provide compatibility shims etc or in extreme circumstances do things in a way which is easily detectable e.g. via configure tests.

That would be much appreciated. Maybe we'll start seeing more libxl apps...

Quoted 4 lines

I was wondering the other day if "libxl v2" support for libvirt might make a nice GSoC project, what do you think? Would you be interested in mentoring such a project?

I agree that it would make a nice GSoC project, but I had encouraged Bamvor to take on the task. It's a good project for becoming familiar with xen and libvirt.

Regards,
Jim

#17 lore raw
Quoted 9 lines · Jim Fehlig
Quoted 4 lines

I was wondering the other day if "libxl v2" support for libvirt might make a nice GSoC project, what do you think? Would you be interested in mentoring such a project?

I agree that it would make a nice GSoC project, but I had encouraged Bamvor to take on the task. It's a good project for becoming familiar with xen and libvirt.

Absolutely, good to see Bamvor will be working on it!

Are there any related subprojects or features relating to libvirt+libxl which might make a good GSoC thing?

Ian.