Skip to contentSkip to conversation

libxl: include a XLU_Config in _libxlDriverConfig

PATCH Superseded Olaf Hering 3 participants 10 messages Apr 28, 2015 – May 7, 2015 5 messages not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: include a XLU_Config in _libxlDriverConfig

Upcoming changes for vscsi will use libxlutil.so to prepare the configuration for libxl. The helpers needs a xlu struct for logging. Provide one and reuse the existing output as log target.

---
 src/libxl/libxl_conf.c | 6 ++++++
 src/libxl/libxl_conf.h | 7 +++++++
 2 files changed, 13 insertions(+)
src/libxl/libxl_conf.c +6 -0
index 53f327b..f9bb5ed 100644
@@ -1454,6 +1454,12 @@ libxlDriverConfigNew(void)
         goto error;
     }
 
+    cfg->xlu = xlu_cfg_init(cfg->logger_file, "libvirt");
+    if (!cfg->xlu) {
+        VIR_ERROR(_("cannot create xlu for libxenlight, disabling driver"));
+        goto error;
+    }
+
     if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, cfg->logger)) {
         VIR_ERROR(_("cannot initialize libxenlight context, probably not "
                     "running in a Xen Dom0, disabling driver"));
src/libxl/libxl_conf.h +7 -0
index 5ba1a71..bdc68d4 100644
@@ -27,6 +27,12 @@
 # define LIBXL_CONF_H
 
 # include <libxl.h>
+#ifdef HAVE_LIBXLUTIL_H
+# include <libxlutil.h>
+#else
+typedef struct XLU_Config XLU_Config;
+XLU_Config *xlu_cfg_init(FILE *report, const char *report_filename);
+#endif
 
 # include "internal.h"
 # include "libvirt_internal.h"
@@ -91,6 +97,7 @@ struct _libxlDriverConfig {
     /* log stream for driver-wide libxl ctx */
     FILE *logger_file;
     xentoollog_logger *logger;
+    XLU_Config *xlu;
     /* libxl ctx for driver wide ops; getVersion, getNodeInfo, ... */
     libxl_ctx *ctx;
#1 lore raw
Quoted 4 lines · Olaf Hering

Upcoming changes for vscsi will use libxlutil.so to prepare the configuration for libxl. The helpers needs a xlu struct for logging. Provide one and reuse the existing output as log target.

Do you not need to call xlu_cfg_destroy at some point?

Wei.

#3 lore raw
In reply to a message not in the archive
Quoted 7 lines · Wei Liu
Quoted 4 lines · Olaf Hering

Upcoming changes for vscsi will use libxlutil.so to prepare the configuration for libxl. The helpers needs a xlu struct for logging. Provide one and reuse the existing output as log target.

Do you not need to call xlu_cfg_destroy at some point?

Since libvirtd runs forever there is very little code to undo most things. But I will see if there is any unload function, did not actively look for such thing.

Olaf

#5 lore raw
In reply to a message not in the archive
Quoted 3 lines · Olaf Hering

Since libvirtd runs forever there is very little code to undo most things. But I will see if there is any unload function, did not actively look for such thing.

Looking through libxlStateDriver it seems that libxl and libxlu remains as is. Not sure if thats supposed that way or if perhaps libxl should be fully reinitialized during ->stateReload, and if logfiles should be closed in ->stateCleanup.

Olaf

#7 lore raw
In reply to a message not in the archive
Quoted 11 lines · Olaf Hering
Quoted 3 lines · Olaf Hering

Since libvirtd runs forever there is very little code to undo most things. But I will see if there is any unload function, did not actively look for such thing.

Looking through libxlStateDriver it seems that libxl and libxlu remains as is. Not sure if thats supposed that way or if perhaps libxl should be fully reinitialized during ->stateReload, and if logfiles should be closed in ->stateCleanup.

FWIW libxl ctx is destroy in libxlDriverConfigDispose. You can probably just call xlu_cfg_destroy there.

Anyway, I'm not a libvirt expert. I just don't like leaking memory. :-)

Wei.

Quoted 1 line

Olaf

#8 lore raw
In reply to a message not in the archive
Quoted 8 lines · Olaf Hering
Quoted 4 lines · Olaf Hering

Since libvirtd runs forever there is very little code to undo most things. But I will see if there is any unload function, did not actively look for such thing.

Quoted 5 lines

Looking through libxlStateDriver it seems that libxl and libxlu remains as is. Not sure if thats supposed that way or if perhaps libxl should be fully reinitialized during ->stateReload, and if logfiles should be closed in ->stateCleanup.

Closing log files, freeing libxl_ctx, etc. is done (indirectly) in stateCleanup. The libxlDriverConfig object is unrefed, which should result in calling libxlDriverConfigDispose().

Jim

#10 lore raw
In reply to a message not in the archive
Quoted 16 lines · Wei Liu
Quoted 13 lines · Olaf Hering
Quoted 4 lines · Olaf Hering

Since libvirtd runs forever there is very little code to undo most things. But I will see if there is any unload function, did not actively look for such thing.

Looking through libxlStateDriver it seems that libxl and libxlu remains as is. Not sure if thats supposed that way or if perhaps libxl should be fully reinitialized during ->stateReload, and if logfiles should be closed in ->stateCleanup.

Quoted 3 lines

FWIW libxl ctx is destroy in libxlDriverConfigDispose. You can probably just call xlu_cfg_destroy there.

Right. Any additions to the libxlDriverConfig object that needs to be cleaned up should be done in libxlDriverConfigDispose.

Regards,
Jim

#14 lore raw
In reply to Olaf Hering
Quoted 33 lines · Olaf Hering

Upcoming changes for vscsi will use libxlutil.so to prepare the configuration for libxl. The helpers needs a xlu struct for logging. Provide one and reuse the existing output as log target.

---
 src/libxl/libxl_conf.c | 6 ++++++
 src/libxl/libxl_conf.h | 7 +++++++
 2 files changed, 13 insertions(+)
src/libxl/libxl_conf.c +6 -0
index 53f327b..f9bb5ed 100644
@@ -1454,6 +1454,12 @@ libxlDriverConfigNew(void)
         goto error;
     }
 
+    cfg->xlu = xlu_cfg_init(cfg->logger_file, "libvirt");
+    if (!cfg->xlu) {
+        VIR_ERROR(_("cannot create xlu for libxenlight, disabling driver"));
+        goto error;
+    }
+
     if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, cfg->logger)) {
         VIR_ERROR(_("cannot initialize libxenlight context, probably not "
                     "running in a Xen Dom0, disabling driver"));
src/libxl/libxl_conf.h +0 -0
index 5ba1a71..bdc68d4 100644

src/libxl/libxl_conf.h line 36

Quoted 10 lines
src/libxl/libxl_conf.h +6 -0
@@ -27,6 +27,12 @@
 # define LIBXL_CONF_H
 
 # include <libxl.h>
+#ifdef HAVE_LIBXLUTIL_H
+# include <libxlutil.h>
+#else
+typedef struct XLU_Config XLU_Config;
+XLU_Config *xlu_cfg_init(FILE *report, const char *report_filename);
+#endif
 

In addition to the cleanup mentioned by Wei, you'll need to fix the indentation of these preprocessor directives. 'make syntax-check' would have caught that if you had cppi installed.

Regards,
Jim

#11 lore raw
In reply to a message not in the archive
Quoted 7 lines · Wei Liu
Quoted 6 lines · Olaf Hering
Quoted 3 lines · Olaf Hering

Since libvirtd runs forever there is very little code to undo most things. But I will see if there is any unload function, did not actively look for such thing.

Quoted 8 lines
Quoted 5 lines

Looking through libxlStateDriver it seems that libxl and libxlu remains as is. Not sure if thats supposed that way or if perhaps libxl should be fully reinitialized during ->stateReload, and if logfiles should be closed in ->stateCleanup.

FWIW libxl ctx is destroy in libxlDriverConfigDispose. You can probably just call xlu_cfg_destroy there.

In libvirt libxlDriverConfigDispose calls both libxl_ctx_free and xtl_logger_destroy. Both functions check if the input is valid, just xlu_cfg_destroy dereferences the input unconditionally. Should xlu_cfg_destroy be changed to do nothing if it gets passed a NULL pointer?

Olaf

#13 lore raw
In reply to a message not in the archive
Quoted 15 lines · Olaf Hering
Quoted 13 lines · Wei Liu
Quoted 11 lines · Olaf Hering
Quoted 3 lines · Olaf Hering

Since libvirtd runs forever there is very little code to undo most things. But I will see if there is any unload function, did not actively look for such thing.

Looking through libxlStateDriver it seems that libxl and libxlu remains as is. Not sure if thats supposed that way or if perhaps libxl should be fully reinitialized during ->stateReload, and if logfiles should be closed in ->stateCleanup.

Quoted 9 lines
Quoted 2 lines

FWIW libxl ctx is destroy in libxlDriverConfigDispose. You can probably just call xlu_cfg_destroy there.

In libvirt libxlDriverConfigDispose calls both libxl_ctx_free and xtl_logger_destroy. Both functions check if the input is valid, just xlu_cfg_destroy dereferences the input unconditionally. Should xlu_cfg_destroy be changed to do nothing if it gets passed a NULL pointer?

That is orthogonal to this patch. I don't particularly care if it's NULL-tolerant or not. In any case, You will need to check validity for older libxl's xlu_cfg_destroy.

Wei.

Quoted 1 line

Olaf