From nobody Sun Nov 24 06:39:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1724317698; cv=none; d=zohomail.com; s=zohoarc; b=EjXKGYe3gVoA3Dxy+m7uxzGCs4Ek7mRcKTeCq6Z55lYEfZIwwpeEJ3gWT+oMFcAAE1RRfVW8FONiJ3yAKo7i1nZDhyL7MtF/92gd8wwEO27utmjOEOT+corNIWh7syThVHPg1C5HrcQRPhCUsoAG69sw7rNhv3teODbvmTmPwzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724317698; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kWxy1XT9RvB6ymqJ3xYxgfXq+O27Deowe7jItjsgCQc=; b=Uoca8YDUxX/WRJbfNT2Q6nD66QG8QI0VIrVWtt+x1LWRhbuxxmd3oSyk6B9YMNr33j7SPMYH458GuG10k/Loo3o5WHhpg7CD0Om4LCown41DoJNWDwlk7UIsHn4HFPsPKYMtV2O58vDKNm/yeX2wh9bWH5LaV4tZnZq8OVAGl2U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1724317698657925.5327025943226; Thu, 22 Aug 2024 02:08:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.781625.1191119 (Exim 4.92) (envelope-from ) id 1sh3nK-0003EW-Qc; Thu, 22 Aug 2024 09:07:50 +0000 Received: by outflank-mailman (output) from mailman id 781625.1191119; Thu, 22 Aug 2024 09:07:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sh3nK-0003DN-MH; Thu, 22 Aug 2024 09:07:50 +0000 Received: by outflank-mailman (input) for mailman id 781625; Thu, 22 Aug 2024 09:06:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sh3mE-00031f-CF for xen-devel@lists.xenproject.org; Thu, 22 Aug 2024 09:06:42 +0000 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [2a00:1450:4864:20::530]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d7cfc6d4-6065-11ef-8776-851b0ebba9a2; Thu, 22 Aug 2024 11:06:40 +0200 (CEST) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5bed72ff2f2so827532a12.2 for ; Thu, 22 Aug 2024 02:06:40 -0700 (PDT) Received: from EMEAENGAAD87503.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a868f2e6717sm88948266b.96.2024.08.22.02.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 02:06:38 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d7cfc6d4-6065-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1724317599; x=1724922399; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kWxy1XT9RvB6ymqJ3xYxgfXq+O27Deowe7jItjsgCQc=; b=eLnXtIpUkVLwUNxrm0cC/CqdYM60hNNUFIIoPHx9QMVhFCkXWUuO2NBrLQptwd5z4W IbTGmhBLXC+2vBXaLjjGEU0Rkm43Mic5/TRuve/Q2ElN5WZvwPRXDt97FQZyQk16aKxs u2NevLxqzCOioFvIG2ogNpuAfz/2QUNN0HCvs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724317599; x=1724922399; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kWxy1XT9RvB6ymqJ3xYxgfXq+O27Deowe7jItjsgCQc=; b=j+0HX7geah8CPiibGCmX8cfQrcTLv3AD1wD+Z1Euq0h7Z1rdROjCojPnmfHci6i56S r4BN4yO84wzG/ks2cO+ZvAozbksTSX8JGOgBNZA9nbX2A3aJ0tuYnJlyJ0iZOYo6YBZA 3yEqexPdgz+jTYL4VeSFb7bLspAw7MCANedFQpMq7NQtAOwzBwjR5d721h4LADkHvJ5L cHcuEiNWvEghVmJaZGQG10LTRexbS8NxDpPVpmie2rVMLuM5jaWI+3UeMay+7dJSe8y2 Yjt/w2tg5GglbEpXlBKz2tzqpav3CSUuxWnSRjhIpY2WHRYBfXiBa8gvdh/URGcDuuyt KeQA== X-Gm-Message-State: AOJu0YzhR78irXWaQs/usbOQcgY4Kzcdu0RSVGYo3v382vZt1so3q/hs 3busTI07OaRS5PpP+mcmgKngkGIjnz1Nr77AsBR98EhB2qU73qyMlmynxk/JzX7zcVtW0gGVQk3 wjE0= X-Google-Smtp-Source: AGHT+IFlLETmcRyIz7ND8jOO3vVUr1MX+pWtVnX6qPCrLgEg16gc99LhCVGWWK8MhMoKIvXaA6IawQ== X-Received: by 2002:a17:907:9495:b0:a86:8368:860a with SMTP id a640c23a62f3a-a868368886dmr262561766b.35.1724317599189; Thu, 22 Aug 2024 02:06:39 -0700 (PDT) From: Andrii Sultanov To: xen-devel@lists.xenproject.org Cc: Andrii Sultanov , Christian Lindig , David Scott , Anthony PERARD Subject: [PATCH v1 2/4] ocaml/libs: Implement a dynamically-loaded plugin for Xenctrl.domain_getinfo Date: Thu, 22 Aug 2024 10:06:03 +0100 Message-Id: <6d4b94939c8910ffd7d70301b1d26c828f72ad86.1724314239.git.andrii.sultanov@cloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1724317700475116600 Content-Type: text/plain; charset="utf-8" This plugin intends to hide the unstable Xenctrl interface under a stable one. In case of the change in the interface, a V2 of this plugin would need to be produced, but V1 with the old interface would need to be kept (with potential change in the implementation) in the meantime. To reduce the need for such changes in the future, this plugin only provides the absolute minimum functionality that Oxenstored uses - only four fields of the domaininfo struct are used and presented here. Oxenstored currently uses the single-domain domain_getinfo function, whereas Cxenstored uses the more-efficient domain_getinfolist. Both of these are provided in the plugin to allow a transition from one to the other without modifying the interface in the future. Both return identical structures and rely on the same fields in xenctrl, thus if one of them breaks, both will break, and a new version of the interface would need to be issued. Signed-off-by: Andrii Sultanov --- tools/ocaml/Makefile | 1 + tools/ocaml/Makefile.rules | 17 +- tools/ocaml/libs/Makefile | 2 +- tools/ocaml/libs/xenstoredglue/META.in | 4 + tools/ocaml/libs/xenstoredglue/Makefile | 39 ++++ .../domain_getinfo_plugin_v1/META.in | 5 + .../domain_getinfo_plugin_v1/Makefile | 38 ++++ .../domain_getinfo_stubs_v1.c | 169 ++++++++++++++++++ .../domain_getinfo_v1.ml | 51 ++++++ .../domain_getinfo_v1.mli | 0 .../libs/xenstoredglue/plugin_interface_v1.ml | 25 +++ .../xenstoredglue/plugin_interface_v1.mli | 34 ++++ 12 files changed, 383 insertions(+), 2 deletions(-) create mode 100644 tools/ocaml/libs/xenstoredglue/META.in create mode 100644 tools/ocaml/libs/xenstoredglue/Makefile create mode 100644 tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1= /META.in create mode 100644 tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1= /Makefile create mode 100644 tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1= /domain_getinfo_stubs_v1.c create mode 100644 tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1= /domain_getinfo_v1.ml create mode 100644 tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1= /domain_getinfo_v1.mli create mode 100644 tools/ocaml/libs/xenstoredglue/plugin_interface_v1.ml create mode 100644 tools/ocaml/libs/xenstoredglue/plugin_interface_v1.mli diff --git a/tools/ocaml/Makefile b/tools/ocaml/Makefile index 1557fd6c3c..eb426f2ee5 100644 --- a/tools/ocaml/Makefile +++ b/tools/ocaml/Makefile @@ -29,6 +29,7 @@ build-tools-oxenstored: $(MAKE) -s -C libs/mmap $(MAKE) -s -C libs/xb $(MAKE) -s -C libs/xc + $(MAKE) -s -C libs/xenstoredglue $(MAKE) -C xenstored =20 .PHONY: format diff --git a/tools/ocaml/Makefile.rules b/tools/ocaml/Makefile.rules index 0d3c6ac839..0444e95f17 100644 --- a/tools/ocaml/Makefile.rules +++ b/tools/ocaml/Makefile.rules @@ -50,12 +50,13 @@ ifneq ($(MAKECMDGOALS),clean) endif =20 clean: $(CLEAN_HOOKS) - $(Q)rm -f .*.d *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot *.spot= *.spit $(LIBS) $(PROGRAMS) $(GENERATED_FILES) .ocamldep.make META + $(Q)rm -f .*.d *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.cmxs *.annot= *.spot *.spit $(LIBS) $(PROGRAMS) $(GENERATED_FILES) .ocamldep.make META =20 distclean: clean =20 quiet-command =3D $(if $(V),$1,@printf " %-8s %s\n" "$2" "$3" && $1) =20 +mk-caml-shared-lib-native =3D $(call quiet-command, $(OCAMLOPT) $(OCAMLOPT= FLAGS) -shared -linkall -o $1 $2 $3,MLA,$1) mk-caml-lib-native =3D $(call quiet-command, $(OCAMLOPT) $(OCAMLOPTFLAGS) = -a -o $1 $2 $3,MLA,$1) mk-caml-lib-bytecode =3D $(call quiet-command, $(OCAMLC) $(OCAMLCFLAGS) -a= -o $1 $2 $3,MLA,$1) =20 @@ -75,6 +76,19 @@ define OCAML_LIBRARY_template $(call mk-caml-lib-stubs,$$@, $$+) endef =20 +# Dynamically linked OCaml libraries ("plugins" in Dynlink parlance) +# need to compile an .cmxs file +define OCAML_DYN_LIBRARY_template + $(1).cmxs: $(1).cmxa + $(call mk-caml-shared-lib-native,$$@, $(1).cmxa) + $(1).cmxa: lib$(1)_stubs.a $(foreach obj,$($(1)_OBJS),$(obj).cmx) + $(call mk-caml-lib-native,$$@, -cclib -l$(1)_stubs $(foreach lib,$(LIBS_$= (1)),-cclib $(lib)), $(foreach obj,$($(1)_OBJS),$(obj).cmx)) + $(1)_stubs.a: $(foreach obj,$$($(1)_C_OBJS),$(obj).o) + $(call mk-caml-stubs,$$@, $$+) + lib$(1)_stubs.a: $(foreach obj,$($(1)_C_OBJS),$(obj).o) + $(call mk-caml-lib-stubs,$$@, $$+) +endef + define OCAML_NOC_LIBRARY_template $(1).cmxa: $(foreach obj,$($(1)_OBJS),$(obj).cmx) $(call mk-caml-lib-native,$$@, , $(foreach obj,$($(1)_OBJS),$(obj).cmx)) @@ -97,6 +111,7 @@ endef -include .ocamldep.make =20 $(foreach lib,$(OCAML_LIBRARY),$(eval $(call OCAML_LIBRARY_template,$(lib)= ))) +$(foreach lib,$(OCAML_DYN_LIBRARY),$(eval $(call OCAML_DYN_LIBRARY_templat= e,$(lib)))) $(foreach lib,$(OCAML_NOC_LIBRARY),$(eval $(call OCAML_NOC_LIBRARY_templat= e,$(lib)))) $(foreach p,$(OCAML_PROGRAM),$(eval $(call OCAML_PROGRAM_template,$(p)))) $(foreach p,$(C_PROGRAM),$(eval $(call C_PROGRAM_template,$(p)))) diff --git a/tools/ocaml/libs/Makefile b/tools/ocaml/libs/Makefile index 89350aa12f..828fbf859d 100644 --- a/tools/ocaml/libs/Makefile +++ b/tools/ocaml/libs/Makefile @@ -4,7 +4,7 @@ include $(XEN_ROOT)/tools/Rules.mk SUBDIRS=3D \ mmap \ eventchn xc \ - xb xs + xb xs xenstoredglue =20 .PHONY: all all: subdirs-all diff --git a/tools/ocaml/libs/xenstoredglue/META.in b/tools/ocaml/libs/xens= toredglue/META.in new file mode 100644 index 0000000000..dbd584ac17 --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/META.in @@ -0,0 +1,4 @@ +version =3D "@VERSION@" +description =3D "A small library on top of unstable Xenctrl interfaces use= d by Oxenstored" +archive(byte) =3D "plugin_interface_v1.cma" +archive(native) =3D "plugin_interface_v1.cmxa" diff --git a/tools/ocaml/libs/xenstoredglue/Makefile b/tools/ocaml/libs/xen= storedglue/Makefile new file mode 100644 index 0000000000..020acd3bef --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/Makefile @@ -0,0 +1,39 @@ +OCAML_TOPLEVEL=3D$(CURDIR)/../.. +XEN_ROOT=3D$(OCAML_TOPLEVEL)/../.. +include $(OCAML_TOPLEVEL)/common.make + +SUBDIRS=3D domain_getinfo_plugin_v1 + +CFLAGS +=3D $(CFLAGS_xeninclude) +OCAMLOPTFLAGS +=3D -opaque + +OBJS =3D plugin_interface_v1 +INTF =3D $(foreach obj, $(OBJS),$(obj).cmi) +LIBS =3D plugin_interface_v1.cma plugin_interface_v1.cmxa +LIBS_plugin_interface_v1 =3D +plugin_interface_v1_OBJS=3D$(OBJS) + +.PHONY: all +all: $(INTF) $(LIBS) $(PROGRAMS) subdirs-all + +bins: $(PROGRAMS) + +libs: $(LIBS) + +plugin_interface_v1 =3D $(OBJS) + +OCAML_NOC_LIBRARY =3D plugin_interface_v1 + +.PHONY: install +install: $(LIBS) META subdirs-install + +.PHONY: uninstall +uninstall: subdirs-uninstall + +.PHONY: clean +clean: subdirs-clean + +.PHONY: distclean +distclean: subdirs-distclean + +include $(OCAML_TOPLEVEL)/Makefile.rules diff --git a/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/META.i= n b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/META.in new file mode 100644 index 0000000000..fb917def62 --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/META.in @@ -0,0 +1,5 @@ +version =3D "@VERSION@" +description =3D "Xenstored plugin for Xenctrl.domain_getinfo unstable inte= rface - V1" +requires =3D "plugin_interface_v1" +archive(byte) =3D "domain_getinfo_v1.cma" +archive(native) =3D "domain_getinfo_v1.cmxa" diff --git a/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/Makefi= le b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/Makefile new file mode 100644 index 0000000000..eae44f8326 --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/Makefile @@ -0,0 +1,38 @@ +OCAML_TOPLEVEL=3D$(CURDIR)/../../.. +XEN_ROOT=3D$(OCAML_TOPLEVEL)/../.. +include $(OCAML_TOPLEVEL)/common.make + +CFLAGS +=3D -I $(OCAML_TOPLEVEL)/libs/xenstoredglue $(CFLAGS_libxenctrl) $= (CFLAGS_xeninclude) +CFLAGS +=3D $(APPEND_CFLAGS) +OCAMLOPTFLAGS +=3D -opaque +OCAMLINCLUDE +=3D -I ../ -I ./ + +OBJS =3D domain_getinfo_v1 +INTF =3D $(foreach obj, $(OBJS),$(obj).cmi) +LIBS =3D domain_getinfo_v1.cmxa domain_getinfo_v1.cmxs + +LIBS_xenstoredglue =3D $(call xenlibs-ldflags-ldlibs,xenctrl) + +all: $(INTF) $(LIBS) $(PROGRAMS) + +bins: $(PROGRAMS) + +libs: $(LIBS) + +domain_getinfo_v1_OBJS =3D $(OBJS) +domain_getinfo_v1 =3D $(OBJS) +domain_getinfo_v1_C_OBJS =3D domain_getinfo_stubs_v1 + +OCAML_DYN_LIBRARY =3D domain_getinfo_v1 + +.PHONY: install +install: $(LIBS) META + $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)/xenctrl_plugin + $(INSTALL_PROG) domain_getinfo_v1.cmxs $(DESTDIR)$(LIBEXEC_BIN)/xenctrl_p= lugin + +.PHONY: uninstall +uninstall: + rm -f $(DESTDIR)$(LIBEXEC_BIN)/xenctrl_plugin/domain_getinfo_v1.cmxs + +include $(OCAML_TOPLEVEL)/Makefile.rules + diff --git a/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/domain= _getinfo_stubs_v1.c b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_= v1/domain_getinfo_stubs_v1.c new file mode 100644 index 0000000000..a29ac7c877 --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/domain_getinf= o_stubs_v1.c @@ -0,0 +1,169 @@ +#define _XOPEN_SOURCE 600 +#include +#include + +#define CAML_NAME_SPACE +#include +#include +#include +#include +#include +#include + +#include + +#include + +#define XC_WANT_COMPAT_MAP_FOREIGN_API +#include + +#define ERR_MSG_LEN (XC_MAX_ERROR_MSG_LEN + 6) +#define MAX_FUNC_LINE_LEN 64 +#define failwith_xc_v1(xch) xsglue_failwith_xc(xch, __FUNCTION__, __LINE__) + +// This is a minimal stub to xenctrl for oxenstored's purposes +// For the full xenctrl stubs, see tools/ocaml/libs/xc/xenctrl_stubs.c + +static inline xc_interface *xsglue_xch_of_val_v1(value v) +{ + xc_interface *xch =3D *(xc_interface **)Data_custom_val(v); + + return xch; +} + +static void xsglue_xenctrl_finalize(value v) +{ + xc_interface *xch =3D xsglue_xch_of_val_v1(v); + + xc_interface_close(xch); +} + +static struct custom_operations xsglue_xenctrl_ops =3D { + .identifier =3D "xenctrl", + .finalize =3D xsglue_xenctrl_finalize, + .compare =3D custom_compare_default, /* Can't compare */ + .hash =3D custom_hash_default, /* Can't hash */ + .serialize =3D custom_serialize_default, /* Can't serialize */ + .deserialize =3D custom_deserialize_default, /* Can't deserialize */ + .compare_ext =3D custom_compare_ext_default, /* Can't compare */ +}; + +static void Noreturn xsglue_failwith_xc(xc_interface *xch, + char const* func, + int line) +{ + char error_str[ERR_MSG_LEN + MAX_FUNC_LINE_LEN]; + size_t str_len =3D 0; + if (xch) { + const xc_error *error =3D xc_get_last_error(xch); + if (error->code =3D=3D XC_ERROR_NONE) + str_len =3D snprintf(error_str, ERR_MSG_LEN, + "%d: %s", errno, strerror(errno)); + else + str_len =3D snprintf(error_str, ERR_MSG_LEN, + "%d: %s: %s", error->code, + xc_error_code_to_desc(error->code), + error->message); + } else { + str_len =3D snprintf(error_str, ERR_MSG_LEN, + "Unable to open XC interface"); + } + str_len =3D str_len < ERR_MSG_LEN ? str_len : ERR_MSG_LEN; + // Log caller's source code function and line + snprintf(error_str+str_len, MAX_FUNC_LINE_LEN, + " - called from %s:%d", func, line); + caml_raise_with_string(*caml_named_value("xsg.error"), error_str); +} + +CAMLprim value stub_xsglue_xc_interface_open(value unit) +{ + CAMLparam1(unit); + CAMLlocal1(result); + xc_interface *xch; + + result =3D caml_alloc_custom(&xsglue_xenctrl_ops, sizeof(xch), 0, 1); + + caml_enter_blocking_section(); + xch =3D xc_interface_open(NULL, NULL, 0); + caml_leave_blocking_section(); + + if ( !xch ) + failwith_xc_v1(xch); + + *(xc_interface **)Data_custom_val(result) =3D xch; + + CAMLreturn(result); +} + +static value xsglue_alloc_domaininfo_v1(xc_domaininfo_t * info) +{ + CAMLparam0(); + CAMLlocal1(result); + result =3D caml_alloc_tuple(4); + + Store_field(result, 0, Val_int(info->domain)); + Store_field(result, 1, Val_bool(info->flags & XEN_DOMINF_dying)); + Store_field(result, 2, Val_bool(info->flags & XEN_DOMINF_shutdown)); + Store_field(result, 3, Val_int(MASK_EXTR(info->flags, XEN_DOMINF_shutdow= nmask))); + + CAMLreturn(result); +} + +CAMLprim value stub_xsglue_xc_domain_getinfo(value xch_val, value domid) +{ + CAMLparam2(xch_val, domid); + CAMLlocal1(result); + xc_interface *xch =3D xsglue_xch_of_val_v1(xch_val); + xc_domaininfo_t info; + int ret; + + ret =3D xc_domain_getinfo_single(xch, Int_val(domid), &info); + if (ret < 0) + failwith_xc_v1(xch); + + result =3D xsglue_alloc_domaininfo_v1(&info); + + CAMLreturn(result); +} + +CAMLprim value stub_xsglue_xc_domain_getinfolist(value xch_val, value firs= t_domain, value nb) +{ + CAMLparam3(xch_val, first_domain, nb); + CAMLlocal2(result, temp); + xc_interface *xch =3D xsglue_xch_of_val_v1(xch_val); + xc_domaininfo_t * info; + int i, ret, toalloc, retval; + unsigned int c_max_domains; + uint32_t c_first_domain; + + /* get the minimum number of allocate byte we need and bump it up to page= boundary */ + toalloc =3D (sizeof(xc_domaininfo_t) * Int_val(nb)) | 0xfff; + ret =3D posix_memalign((void **) ((void *) &info), 4096, toalloc); + if (ret) + caml_raise_out_of_memory(); + + result =3D temp =3D Val_emptylist; + + c_first_domain =3D Int_val(first_domain); + c_max_domains =3D Int_val(nb); + caml_enter_blocking_section(); + retval =3D xc_domain_getinfolist(xch, c_first_domain, + c_max_domains, info); + caml_leave_blocking_section(); + + if (retval < 0) { + free(info); + failwith_xc_v1(xch); + } + for (i =3D 0; i < retval; i++) { + result =3D caml_alloc_small(2, Tag_cons); + Field(result, 0) =3D Val_int(0); + Field(result, 1) =3D temp; + temp =3D result; + + Store_field(result, 0, xsglue_alloc_domaininfo_v1(info + i)); + } + + free(info); + CAMLreturn(result); +} diff --git a/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/domain= _getinfo_v1.ml b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/do= main_getinfo_v1.ml new file mode 100644 index 0000000000..d8947b618f --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/domain_getinf= o_v1.ml @@ -0,0 +1,51 @@ +(** Minimal interface on top of unstable Xenctrl for Oxenstored's usage *) + +(** For the full Xenctrl interface, see: tools/ocaml/libs/xc/ *) + +module M : Plugin_interface_v1.Domain_getinfo_V1 =3D struct + exception Error of string + + type domid =3D int + type handle + + type domaininfo =3D { + domid : domid; + dying : bool; + shutdown : bool; + shutdown_code : int; + } + + external interface_open : unit -> handle =3D "stub_xsglue_xc_interface_o= pen" + + external domain_getinfo : handle -> domid -> domaininfo + =3D "stub_xsglue_xc_domain_getinfo" + + external __domain_getinfolist : handle -> domid -> int -> domaininfo list + =3D "stub_xsglue_xc_domain_getinfolist" + + let domain_getinfolist handle first_domain =3D + (* [rev_concat lst] is equivalent to [lst |> List.concat |> List.rev] + * except it is tail recursive, whereas [List.concat] isn't. + * Example: + * rev_concat [[10;9;8];[7;6];[5]]] =3D [5; 6; 7; 8; 9; 10] + *) + let rev_append_fold acc e =3D List.rev_append e acc in + let rev_concat lst =3D List.fold_left rev_append_fold [] lst in + + let nb =3D 1024 in + let rec __getlist lst from =3D + (* _domain_getinfolist returns domains in reverse order, largest fir= st *) + match __domain_getinfolist handle from nb with + | [] -> rev_concat lst + | hd :: _ as l -> __getlist (l :: lst) (hd.domid + 1) + in + __getlist [] first_domain + + let _ =3D Callback.register_exception "xsg.error" (Error "register_callb= ack") +end + +let () =3D + Printf.printf "Registration of %s plugin started\n%!" __MODULE__; + Plugin_interface_v1.register_plugin_v1 + (module M : Plugin_interface_v1.Domain_getinfo_V1); + Printf.printf "Registration of %s plugin successful\n%!" __MODULE__ diff --git a/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/domain= _getinfo_v1.mli b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/d= omain_getinfo_v1.mli new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/ocaml/libs/xenstoredglue/plugin_interface_v1.ml b/tools/= ocaml/libs/xenstoredglue/plugin_interface_v1.ml new file mode 100644 index 0000000000..6398b697ed --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/plugin_interface_v1.ml @@ -0,0 +1,25 @@ +module type Domain_getinfo_V1 =3D sig + exception Error of string + + type domid =3D int + type handle + + type domaininfo =3D { + domid : domid; + dying : bool; + shutdown : bool; + shutdown_code : int; + } + + val interface_open : unit -> handle + val domain_getinfo : handle -> domid -> domaininfo + val domain_getinfolist : handle -> domid -> domaininfo list +end + +let plugin_implementation_v1 : (module Domain_getinfo_V1) option ref =3D r= ef None +let register_plugin_v1 m =3D plugin_implementation_v1 :=3D Some m + +let get_plugin_v1 () : (module Domain_getinfo_V1) =3D + match !plugin_implementation_v1 with + | Some s -> s + | None -> failwith "No plugin loaded" diff --git a/tools/ocaml/libs/xenstoredglue/plugin_interface_v1.mli b/tools= /ocaml/libs/xenstoredglue/plugin_interface_v1.mli new file mode 100644 index 0000000000..cf20cc5efa --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/plugin_interface_v1.mli @@ -0,0 +1,34 @@ +(** To avoid breaking the plugin interface, this module needs to be + standalone and can't rely on any other Xen library. Even unrelated + changes in the interfaces of those modules would change the hash + of this interface and break the plugin system. + It can only depend on Stdlib, therefore all of the types (domid, + domaininfo etc.) are redefined here instead of using alternatives + defined elsewhere. + + NOTE: The signature of this interface should not be changed (no + functions or types can be added, modified, or removed). If + underlying Xenctrl changes require a new interface, a V2 with a + corresponding plugin should be created. + *) + +module type Domain_getinfo_V1 =3D sig + exception Error of string + + type domid =3D int + type handle + + type domaininfo =3D { + domid : domid; + dying : bool; + shutdown : bool; + shutdown_code : int; + } + + val interface_open : unit -> handle + val domain_getinfo : handle -> domid -> domaininfo + val domain_getinfolist : handle -> domid -> domaininfo list +end + +val register_plugin_v1 : (module Domain_getinfo_V1) -> unit +val get_plugin_v1 : unit -> (module Domain_getinfo_V1) --=20 2.39.2