From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vincent Hanquez Subject: [PATCH 2/3] add a simple logger to the ocaml bindings Date: Tue, 13 Jul 2010 14:51:12 +0100 Message-ID: <1279029073-28530-3-git-send-email-vincent.hanquez@eu.citrix.com> References: <1279029073-28530-1-git-send-email-vincent.hanquez@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.7.1" Return-path: In-Reply-To: <1279029073-28530-1-git-send-email-vincent.hanquez@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Xen Devel Cc: Vincent Hanquez List-Id: xen-devel@lists.xenproject.org --------------1.7.1 Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: quoted-printable Signed-off-by: Vincent Hanquez --- tools/ocaml/libs/xl/xl_stubs.c | 131 ++++++++++++++++++++++------------= ----- 1 files changed, 74 insertions(+), 57 deletions(-) --------------1.7.1 Content-Type: text/x-patch; name="0002-add-a-simple-logger-to-the-ocaml-bindings.patch" Content-Disposition: attachment; filename="0002-add-a-simple-logger-to-the-ocaml-bindings.patch" Content-Transfer-Encoding: quoted-printable diff --git a/tools/ocaml/libs/xl/xl_stubs.c b/tools/ocaml/libs/xl/xl_stub= s.c index 07809fd..2d0bb54 100644 --- a/tools/ocaml/libs/xl/xl_stubs.c +++ b/tools/ocaml/libs/xl/xl_stubs.c @@ -28,24 +28,41 @@ =20 #include "libxl.h" =20 +struct caml_logger { + struct xentoollog_logger logger; + int log_offset; + char log_buf[2048]; +}; + +void log_vmessage(struct xentoollog_logger *logger, xentoollog_level lev= el, + int errnoval, const char *context, const char *format,= va_list al) +{ + struct caml_logger *ologger =3D (struct caml_logger *) logger; + + ologger->log_offset +=3D vsnprintf(ologger->log_buf + ologger->log_offs= et, + 2048 - ologger->log_offset, format, al= ); +} + +void log_destroy(struct xentoollog_logger *logger) +{ +} + #define INIT_CTX() \ - ret =3D libxl_ctx_init(&ctx, LIBXL_VERSION, NULL); \ + lg.logger.vmessage =3D log_vmessage; \ + lg.logger.destroy =3D log_destroy; \ + lg.logger.progress =3D NULL; \ + ret =3D libxl_ctx_init(&ctx, LIBXL_VERSION, (struct xentoollog_logger *= ) &lg); \ if (ret !=3D 0) \ - failwith_xl("cannot init context"); + failwith_xl("cannot init context", &lg); =20 #define FREE_CTX() \ libxl_ctx_free(&ctx) =20 -void log_callback(void *userdata, int loglevel, const char *file, - int line, const char *func, char *s) -{ -} - -void failwith_xl(char *log_data) +void failwith_xl(char *fname, struct caml_logger *lg) { - char s[1024]; - snprintf(s, 1024, "proper logging not implemented yet: error in %s", lo= g_data); - caml_raise_with_string(*caml_named_value("xl.error"), log_data); + char *s; + s =3D (lg) ? lg->log_buf : fname; + caml_raise_with_string(*caml_named_value("xl.error"), s); } =20 static int string_string_tuple_array_val (char ***c_val, value v) @@ -298,7 +315,7 @@ static value Val_physinfo(struct libxl_physinfo *c_va= l) value stub_xl_domain_make(value info) { CAMLparam1(info); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; uint32_t domid; libxl_domain_create_info c_info; int ret; @@ -309,7 +326,7 @@ value stub_xl_domain_make(value info) =20 ret =3D libxl_domain_make(&ctx, &c_info, &domid); if (ret !=3D 0) - failwith_xl("domain make"); + failwith_xl("domain make", &lg); =20 FREE_CTX(); =20 @@ -323,7 +340,7 @@ value stub_xl_domain_build(value info, value domid) { CAMLparam2(info, domid); CAMLlocal1(result); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; libxl_domain_build_info c_info; libxl_domain_build_state c_state; int ret; @@ -336,7 +353,7 @@ value stub_xl_domain_build(value info, value domid) =20 ret =3D libxl_domain_build(&ctx, &c_info, c_domid, &c_state); if (ret !=3D 0) - failwith_xl("domain_build"); + failwith_xl("domain_build", &lg); =20 result =3D Val_domain_build_state(&c_state); FREE_CTX(); @@ -348,7 +365,7 @@ value stub_xl_disk_add(value info, value domid) { CAMLparam2(info, domid); libxl_device_disk c_info; - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 device_disk_val(&c_info, info); @@ -357,7 +374,7 @@ value stub_xl_disk_add(value info, value domid) INIT_CTX(); ret =3D libxl_device_disk_add(&ctx, Int_val(domid), &c_info); if (ret !=3D 0) - failwith_xl("disk_add"); + failwith_xl("disk_add", &lg); FREE_CTX(); CAMLreturn(Val_unit); } @@ -366,7 +383,7 @@ value stub_xl_disk_remove(value info, value domid) { CAMLparam2(info, domid); libxl_device_disk c_info; - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 device_disk_val(&c_info, info); @@ -375,7 +392,7 @@ value stub_xl_disk_remove(value info, value domid) INIT_CTX(); ret =3D libxl_device_disk_del(&ctx, &c_info, 0); if (ret !=3D 0) - failwith_xl("disk_remove"); + failwith_xl("disk_remove", &lg); FREE_CTX(); CAMLreturn(Val_unit); } @@ -383,7 +400,7 @@ value stub_xl_disk_remove(value info, value domid) value stub_xl_nic_add(value info, value domid) { CAMLparam2(info, domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; libxl_device_nic c_info; int ret; =20 @@ -393,7 +410,7 @@ value stub_xl_nic_add(value info, value domid) INIT_CTX(); ret =3D libxl_device_nic_add(&ctx, Int_val(domid), &c_info); if (ret !=3D 0) - failwith_xl("nic_add"); + failwith_xl("nic_add", &lg); FREE_CTX(); CAMLreturn(Val_unit); } @@ -401,7 +418,7 @@ value stub_xl_nic_add(value info, value domid) value stub_xl_nic_remove(value info, value domid) { CAMLparam2(info, domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; libxl_device_nic c_info; int ret; =20 @@ -411,7 +428,7 @@ value stub_xl_nic_remove(value info, value domid) INIT_CTX(); ret =3D libxl_device_nic_del(&ctx, &c_info, 0); if (ret !=3D 0) - failwith_xl("nic_remove"); + failwith_xl("nic_remove", &lg); FREE_CTX(); CAMLreturn(Val_unit); } @@ -419,7 +436,7 @@ value stub_xl_nic_remove(value info, value domid) value stub_xl_console_add(value info, value state, value domid) { CAMLparam3(info, state, domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; libxl_device_console c_info; libxl_domain_build_state c_state; int ret; @@ -432,7 +449,7 @@ value stub_xl_console_add(value info, value state, va= lue domid) INIT_CTX(); ret =3D libxl_device_console_add(&ctx, Int_val(domid), &c_info); if (ret !=3D 0) - failwith_xl("console_add"); + failwith_xl("console_add", &lg); FREE_CTX(); CAMLreturn(Val_unit); } @@ -440,7 +457,7 @@ value stub_xl_console_add(value info, value state, va= lue domid) value stub_xl_vkb_add(value info, value domid) { CAMLparam2(info, domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; libxl_device_vkb c_info; int ret; =20 @@ -450,7 +467,7 @@ value stub_xl_vkb_add(value info, value domid) INIT_CTX(); ret =3D libxl_device_vkb_add(&ctx, Int_val(domid), &c_info); if (ret !=3D 0) - failwith_xl("vkb_add"); + failwith_xl("vkb_add", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -459,13 +476,13 @@ value stub_xl_vkb_add(value info, value domid) value stub_xl_vkb_clean_shutdown(value domid) { CAMLparam1(domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 INIT_CTX(); ret =3D libxl_device_vkb_clean_shutdown(&ctx, Int_val(domid)); if (ret !=3D 0) - failwith_xl("vkb_clean_shutdown"); + failwith_xl("vkb_clean_shutdown", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -474,13 +491,13 @@ value stub_xl_vkb_clean_shutdown(value domid) value stub_xl_vkb_hard_shutdown(value domid) { CAMLparam1(domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 INIT_CTX(); ret =3D libxl_device_vkb_hard_shutdown(&ctx, Int_val(domid)); if (ret !=3D 0) - failwith_xl("vkb_hard_shutdown"); + failwith_xl("vkb_hard_shutdown", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -489,7 +506,7 @@ value stub_xl_vkb_hard_shutdown(value domid) value stub_xl_vfb_add(value info, value domid) { CAMLparam2(info, domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; libxl_device_vfb c_info; int ret; =20 @@ -499,7 +516,7 @@ value stub_xl_vfb_add(value info, value domid) INIT_CTX(); ret =3D libxl_device_vfb_add(&ctx, Int_val(domid), &c_info); if (ret !=3D 0) - failwith_xl("vfb_add"); + failwith_xl("vfb_add", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -508,13 +525,13 @@ value stub_xl_vfb_add(value info, value domid) value stub_xl_vfb_clean_shutdown(value domid) { CAMLparam1(domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 INIT_CTX(); ret =3D libxl_device_vfb_clean_shutdown(&ctx, Int_val(domid)); if (ret !=3D 0) - failwith_xl("vfb_clean_shutdown"); + failwith_xl("vfb_clean_shutdown", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -523,13 +540,13 @@ value stub_xl_vfb_clean_shutdown(value domid) value stub_xl_vfb_hard_shutdown(value domid) { CAMLparam1(domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 INIT_CTX(); ret =3D libxl_device_vfb_hard_shutdown(&ctx, Int_val(domid)); if (ret !=3D 0) - failwith_xl("vfb_hard_shutdown"); + failwith_xl("vfb_hard_shutdown", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -538,7 +555,7 @@ value stub_xl_vfb_hard_shutdown(value domid) value stub_xl_pci_add(value info, value domid) { CAMLparam2(info, domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; libxl_device_pci c_info; int ret; =20 @@ -547,7 +564,7 @@ value stub_xl_pci_add(value info, value domid) INIT_CTX(); ret =3D libxl_device_pci_add(&ctx, Int_val(domid), &c_info); if (ret !=3D 0) - failwith_xl("pci_add"); + failwith_xl("pci_add", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -556,7 +573,7 @@ value stub_xl_pci_add(value info, value domid) value stub_xl_pci_remove(value info, value domid) { CAMLparam2(info, domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; libxl_device_pci c_info; int ret; =20 @@ -565,7 +582,7 @@ value stub_xl_pci_remove(value info, value domid) INIT_CTX(); ret =3D libxl_device_pci_remove(&ctx, Int_val(domid), &c_info); if (ret !=3D 0) - failwith_xl("pci_remove"); + failwith_xl("pci_remove", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -574,13 +591,13 @@ value stub_xl_pci_remove(value info, value domid) value stub_xl_pci_shutdown(value domid) { CAMLparam1(domid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 INIT_CTX(); ret =3D libxl_device_pci_shutdown(&ctx, Int_val(domid)); if (ret !=3D 0) - failwith_xl("pci_shutdown"); + failwith_xl("pci_shutdown", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -589,13 +606,13 @@ value stub_xl_pci_shutdown(value domid) value stub_xl_button_press(value domid, value button) { CAMLparam2(domid, button); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =09 INIT_CTX(); ret =3D libxl_button_press(&ctx, Int_val(domid), Int_val(button) + POWE= R_BUTTON); if (ret !=3D 0) - failwith_xl("button_press"); + failwith_xl("button_press", &lg); FREE_CTX(); =20 CAMLreturn(Val_unit); @@ -605,14 +622,14 @@ value stub_xl_physinfo(value unit) { CAMLparam1(unit); CAMLlocal1(physinfo); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; struct libxl_physinfo c_physinfo; int ret; =20 INIT_CTX(); ret =3D libxl_get_physinfo(&ctx, &c_physinfo); if (ret !=3D 0) - failwith_xl("physinfo"); + failwith_xl("physinfo", &lg); FREE_CTX(); =09 physinfo =3D Val_physinfo(&c_physinfo); @@ -623,14 +640,14 @@ value stub_xl_sched_credit_domain_get(value domid) { CAMLparam1(domid); CAMLlocal1(scinfo); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; struct libxl_sched_credit c_scinfo; int ret; =20 INIT_CTX(); ret =3D libxl_sched_credit_domain_get(&ctx, Int_val(domid), &c_scinfo); if (ret !=3D 0) - failwith_xl("sched_credit_domain_get"); + failwith_xl("sched_credit_domain_get", &lg); FREE_CTX(); =09 scinfo =3D Val_sched_credit(&c_scinfo); @@ -640,7 +657,7 @@ value stub_xl_sched_credit_domain_get(value domid) value stub_xl_sched_credit_domain_set(value domid, value scinfo) { CAMLparam2(domid, scinfo); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; struct libxl_sched_credit c_scinfo; int ret; =20 @@ -649,7 +666,7 @@ value stub_xl_sched_credit_domain_set(value domid, va= lue scinfo) INIT_CTX(); ret =3D libxl_sched_credit_domain_set(&ctx, Int_val(domid), &c_scinfo); if (ret !=3D 0) - failwith_xl("sched_credit_domain_set"); + failwith_xl("sched_credit_domain_set", &lg); FREE_CTX(); =09 CAMLreturn(Val_unit); @@ -658,13 +675,13 @@ value stub_xl_sched_credit_domain_set(value domid, = value scinfo) value stub_xl_send_trigger(value domid, value trigger, value vcpuid) { CAMLparam3(domid, trigger, vcpuid); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 INIT_CTX(); ret =3D libxl_send_trigger(&ctx, Int_val(domid), String_val(trigger), I= nt_val(vcpuid)); if (ret !=3D 0) - failwith_xl("send_trigger"); + failwith_xl("send_trigger", &lg); FREE_CTX(); CAMLreturn(Val_unit); } @@ -672,13 +689,13 @@ value stub_xl_send_trigger(value domid, value trigg= er, value vcpuid) value stub_xl_send_sysrq(value domid, value sysrq) { CAMLparam2(domid, sysrq); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 INIT_CTX(); ret =3D libxl_send_sysrq(&ctx, Int_val(domid), Int_val(sysrq)); if (ret !=3D 0) - failwith_xl("send_sysrq"); + failwith_xl("send_sysrq", &lg); FREE_CTX(); CAMLreturn(Val_unit); } @@ -686,13 +703,13 @@ value stub_xl_send_sysrq(value domid, value sysrq) value stub_xl_send_debug_keys(value keys) { CAMLparam1(keys); - struct libxl_ctx ctx; + struct libxl_ctx ctx; struct caml_logger lg; int ret; =20 INIT_CTX(); ret =3D libxl_send_debug_keys(&ctx, String_val(keys)); if (ret !=3D 0) - failwith_xl("send_debug_keys"); + failwith_xl("send_debug_keys", &lg); FREE_CTX(); CAMLreturn(Val_unit); } --------------1.7.1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------1.7.1--