From patchwork Thu Aug 22 09:06:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Sultanov X-Patchwork-Id: 13773037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14E59C5321E for ; Thu, 22 Aug 2024 09:08:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.781623.1191112 (Exim 4.92) (envelope-from ) id 1sh3nK-00038X-Hy; Thu, 22 Aug 2024 09:07:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 781623.1191112; 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-00037Y-Du; Thu, 22 Aug 2024 09:07:50 +0000 Received: by outflank-mailman (input) for mailman id 781623; Thu, 22 Aug 2024 09:06:39 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sh3mB-0002Rz-46 for xen-devel@lists.xenproject.org; Thu, 22 Aug 2024 09:06:39 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d6ada0fc-6065-11ef-a50a-bb4a2ccca743; Thu, 22 Aug 2024 11:06:38 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5334adf7249so794967e87.3 for ; Thu, 22 Aug 2024 02:06:38 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 02:06:36 -0700 (PDT) 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: d6ada0fc-6065-11ef-a50a-bb4a2ccca743 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1724317597; x=1724922397; 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=cORQBguaRrQouCupVhe68zYd4OsX8uT6R2EJjrpteaQ=; b=MOdW12v15WQoXrweKS/DwZ/wBOrbCdw9QggTD4gV+5sKUdhNW76TrBF/fz3jOA5vzu kPgAPhsiSEdp2XBP9buyhL+mzSAGu8lefyP6kEh9hTDpxicbBUnR6pO+1NPZVTx7aux8 ZH7Lhs7NgXFe/zxHvMR3ks4KGa5XLFQqVh8VY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724317597; x=1724922397; 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=cORQBguaRrQouCupVhe68zYd4OsX8uT6R2EJjrpteaQ=; b=I9iZHlN/FVsiOZ6OQ8b7gwitpnYQnHjy070pVnAGKYxSrhKw3w2kCmtmyZtlOFxHE1 KIAQLNy+IrAUxXuUmggtZZPx7depoW1nabBnAuJBa8UlM2YPuYwviIFqm7DsejieanB4 oFkxykc2kcGXdjGvBVxXUhqvH8DNYTUKbMQvIJsU/xUOjfV5uWLglcfQodJxP48qwuZ/ ao4bFYAIvc+bH22H+zTvJQ3yiPGECnnAPvE98imO0cgwuGRuQkrqC70EGwgV6BukIReJ A5oMywFNvmnNFqElMS/W12u+pscbF5m/uT5QzfjLiFDBxIR+y6dXiRt0bxgWf5Nzuhtm 7weQ== X-Gm-Message-State: AOJu0YySCfphLfo8mJj5+tmcJ+FO7QODTkpk5Doq9ZaWXBitNdWqeopv BdK9Bbtk63aqtE6phpH5xSg5ofaQmH+aryBojUEWW5Gz/FAx8NPxbt/Y5p5krv+ivukINllNspr ICjM= X-Google-Smtp-Source: AGHT+IFZoC7jcASMVLRGYIPkD8jDYYqSOXmqVpo3vYtIjOVyDqELzPmYTBq5UG2H7gbAjBder2DQiw== X-Received: by 2002:a05:6512:39c7:b0:52c:d76f:7f61 with SMTP id 2adb3069b0e04-53348602056mr3554992e87.56.1724317597214; Thu, 22 Aug 2024 02:06:37 -0700 (PDT) From: Andrii Sultanov To: xen-devel@lists.xenproject.org Cc: Andrii Sultanov , Christian Lindig , David Scott , Anthony PERARD Subject: [PATCH v1 1/4] tools/ocaml/common.make: Remove '-cc $(CC)' flag from OCAMLOPTFLAGS Date: Thu, 22 Aug 2024 10:06:02 +0100 Message-Id: <110f63b76a12e8a9fead09f47319a35229222953.1724314239.git.andrii.sultanov@cloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 This flag does not work as assumed and will not pass options (such as -shared) to the C compiler: https://github.com/ocaml/ocaml/issues/12284 Signed-off-by: Andrii Sultanov --- tools/ocaml/common.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ocaml/common.make b/tools/ocaml/common.make index 0c8a597d5b..cc126b749f 100644 --- a/tools/ocaml/common.make +++ b/tools/ocaml/common.make @@ -12,7 +12,7 @@ OCAMLFIND ?= ocamlfind CFLAGS += -fPIC -I$(shell ocamlc -where) OCAMLOPTFLAG_G := $(shell $(OCAMLOPT) -h 2>&1 | sed -n 's/^ *\(-g\) .*/\1/p') -OCAMLOPTFLAGS = $(OCAMLOPTFLAG_G) -ccopt "$(LDFLAGS)" -dtypes $(OCAMLINCLUDE) -cc $(CC) -w F -warn-error F +OCAMLOPTFLAGS = $(OCAMLOPTFLAG_G) -ccopt "$(LDFLAGS)" -dtypes $(OCAMLINCLUDE) -w F -warn-error F OCAMLCFLAGS += -g $(OCAMLINCLUDE) -w F -warn-error F VERSION := 4.1 From patchwork Thu Aug 22 09:06:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Sultanov X-Patchwork-Id: 13773039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BBE22C5320E for ; Thu, 22 Aug 2024 09:08:03 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 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 .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 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 distclean: clean quiet-command = $(if $(V),$1,@printf " %-8s %s\n" "$2" "$3" && $1) +mk-caml-shared-lib-native = $(call quiet-command, $(OCAMLOPT) $(OCAMLOPTFLAGS) -shared -linkall -o $1 $2 $3,MLA,$1) mk-caml-lib-native = $(call quiet-command, $(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $1 $2 $3,MLA,$1) mk-caml-lib-bytecode = $(call quiet-command, $(OCAMLC) $(OCAMLCFLAGS) -a -o $1 $2 $3,MLA,$1) @@ -75,6 +76,19 @@ define OCAML_LIBRARY_template $(call mk-caml-lib-stubs,$$@, $$+) endef +# 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 $(foreach lib,$(OCAML_LIBRARY),$(eval $(call OCAML_LIBRARY_template,$(lib)))) +$(foreach lib,$(OCAML_DYN_LIBRARY),$(eval $(call OCAML_DYN_LIBRARY_template,$(lib)))) $(foreach lib,$(OCAML_NOC_LIBRARY),$(eval $(call OCAML_NOC_LIBRARY_template,$(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= \ mmap \ eventchn xc \ - xb xs + xb xs xenstoredglue .PHONY: all all: subdirs-all diff --git a/tools/ocaml/libs/xenstoredglue/META.in b/tools/ocaml/libs/xenstoredglue/META.in new file mode 100644 index 0000000000..dbd584ac17 --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/META.in @@ -0,0 +1,4 @@ +version = "@VERSION@" +description = "A small library on top of unstable Xenctrl interfaces used by Oxenstored" +archive(byte) = "plugin_interface_v1.cma" +archive(native) = "plugin_interface_v1.cmxa" diff --git a/tools/ocaml/libs/xenstoredglue/Makefile b/tools/ocaml/libs/xenstoredglue/Makefile new file mode 100644 index 0000000000..020acd3bef --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/Makefile @@ -0,0 +1,39 @@ +OCAML_TOPLEVEL=$(CURDIR)/../.. +XEN_ROOT=$(OCAML_TOPLEVEL)/../.. +include $(OCAML_TOPLEVEL)/common.make + +SUBDIRS= domain_getinfo_plugin_v1 + +CFLAGS += $(CFLAGS_xeninclude) +OCAMLOPTFLAGS += -opaque + +OBJS = plugin_interface_v1 +INTF = $(foreach obj, $(OBJS),$(obj).cmi) +LIBS = plugin_interface_v1.cma plugin_interface_v1.cmxa +LIBS_plugin_interface_v1 = +plugin_interface_v1_OBJS=$(OBJS) + +.PHONY: all +all: $(INTF) $(LIBS) $(PROGRAMS) subdirs-all + +bins: $(PROGRAMS) + +libs: $(LIBS) + +plugin_interface_v1 = $(OBJS) + +OCAML_NOC_LIBRARY = 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.in 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 = "@VERSION@" +description = "Xenstored plugin for Xenctrl.domain_getinfo unstable interface - V1" +requires = "plugin_interface_v1" +archive(byte) = "domain_getinfo_v1.cma" +archive(native) = "domain_getinfo_v1.cmxa" diff --git a/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/Makefile 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=$(CURDIR)/../../.. +XEN_ROOT=$(OCAML_TOPLEVEL)/../.. +include $(OCAML_TOPLEVEL)/common.make + +CFLAGS += -I $(OCAML_TOPLEVEL)/libs/xenstoredglue $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude) +CFLAGS += $(APPEND_CFLAGS) +OCAMLOPTFLAGS += -opaque +OCAMLINCLUDE += -I ../ -I ./ + +OBJS = domain_getinfo_v1 +INTF = $(foreach obj, $(OBJS),$(obj).cmi) +LIBS = domain_getinfo_v1.cmxa domain_getinfo_v1.cmxs + +LIBS_xenstoredglue = $(call xenlibs-ldflags-ldlibs,xenctrl) + +all: $(INTF) $(LIBS) $(PROGRAMS) + +bins: $(PROGRAMS) + +libs: $(LIBS) + +domain_getinfo_v1_OBJS = $(OBJS) +domain_getinfo_v1 = $(OBJS) +domain_getinfo_v1_C_OBJS = domain_getinfo_stubs_v1 + +OCAML_DYN_LIBRARY = 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_plugin + +.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_getinfo_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 = *(xc_interface **)Data_custom_val(v); + + return xch; +} + +static void xsglue_xenctrl_finalize(value v) +{ + xc_interface *xch = xsglue_xch_of_val_v1(v); + + xc_interface_close(xch); +} + +static struct custom_operations xsglue_xenctrl_ops = { + .identifier = "xenctrl", + .finalize = xsglue_xenctrl_finalize, + .compare = custom_compare_default, /* Can't compare */ + .hash = custom_hash_default, /* Can't hash */ + .serialize = custom_serialize_default, /* Can't serialize */ + .deserialize = custom_deserialize_default, /* Can't deserialize */ + .compare_ext = 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 = 0; + if (xch) { + const xc_error *error = xc_get_last_error(xch); + if (error->code == XC_ERROR_NONE) + str_len = snprintf(error_str, ERR_MSG_LEN, + "%d: %s", errno, strerror(errno)); + else + str_len = snprintf(error_str, ERR_MSG_LEN, + "%d: %s: %s", error->code, + xc_error_code_to_desc(error->code), + error->message); + } else { + str_len = snprintf(error_str, ERR_MSG_LEN, + "Unable to open XC interface"); + } + str_len = 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 = caml_alloc_custom(&xsglue_xenctrl_ops, sizeof(xch), 0, 1); + + caml_enter_blocking_section(); + xch = xc_interface_open(NULL, NULL, 0); + caml_leave_blocking_section(); + + if ( !xch ) + failwith_xc_v1(xch); + + *(xc_interface **)Data_custom_val(result) = xch; + + CAMLreturn(result); +} + +static value xsglue_alloc_domaininfo_v1(xc_domaininfo_t * info) +{ + CAMLparam0(); + CAMLlocal1(result); + result = 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_shutdownmask))); + + CAMLreturn(result); +} + +CAMLprim value stub_xsglue_xc_domain_getinfo(value xch_val, value domid) +{ + CAMLparam2(xch_val, domid); + CAMLlocal1(result); + xc_interface *xch = xsglue_xch_of_val_v1(xch_val); + xc_domaininfo_t info; + int ret; + + ret = xc_domain_getinfo_single(xch, Int_val(domid), &info); + if (ret < 0) + failwith_xc_v1(xch); + + result = xsglue_alloc_domaininfo_v1(&info); + + CAMLreturn(result); +} + +CAMLprim value stub_xsglue_xc_domain_getinfolist(value xch_val, value first_domain, value nb) +{ + CAMLparam3(xch_val, first_domain, nb); + CAMLlocal2(result, temp); + xc_interface *xch = 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 = (sizeof(xc_domaininfo_t) * Int_val(nb)) | 0xfff; + ret = posix_memalign((void **) ((void *) &info), 4096, toalloc); + if (ret) + caml_raise_out_of_memory(); + + result = temp = Val_emptylist; + + c_first_domain = Int_val(first_domain); + c_max_domains = Int_val(nb); + caml_enter_blocking_section(); + retval = 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 = 0; i < retval; i++) { + result = caml_alloc_small(2, Tag_cons); + Field(result, 0) = Val_int(0); + Field(result, 1) = temp; + temp = 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/domain_getinfo_v1.ml new file mode 100644 index 0000000000..d8947b618f --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/domain_getinfo_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 = struct + exception Error of string + + type domid = int + type handle + + type domaininfo = { + domid : domid; + dying : bool; + shutdown : bool; + shutdown_code : int; + } + + external interface_open : unit -> handle = "stub_xsglue_xc_interface_open" + + external domain_getinfo : handle -> domid -> domaininfo + = "stub_xsglue_xc_domain_getinfo" + + external __domain_getinfolist : handle -> domid -> int -> domaininfo list + = "stub_xsglue_xc_domain_getinfolist" + + let domain_getinfolist handle first_domain = + (* [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]]] = [5; 6; 7; 8; 9; 10] + *) + let rev_append_fold acc e = List.rev_append e acc in + let rev_concat lst = List.fold_left rev_append_fold [] lst in + + let nb = 1024 in + let rec __getlist lst from = + (* _domain_getinfolist returns domains in reverse order, largest first *) + match __domain_getinfolist handle from nb with + | [] -> rev_concat lst + | hd :: _ as l -> __getlist (l :: lst) (hd.domid + 1) + in + __getlist [] first_domain + + let _ = Callback.register_exception "xsg.error" (Error "register_callback") +end + +let () = + 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/domain_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 = sig + exception Error of string + + type domid = int + type handle + + type domaininfo = { + 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 = ref None +let register_plugin_v1 m = plugin_implementation_v1 := Some m + +let get_plugin_v1 () : (module Domain_getinfo_V1) = + 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 = sig + exception Error of string + + type domid = int + type handle + + type domaininfo = { + 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) From patchwork Thu Aug 22 09:06:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Sultanov X-Patchwork-Id: 13773036 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9C8CC5321D for ; Thu, 22 Aug 2024 09:08:01 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.781627.1191126 (Exim 4.92) (envelope-from ) id 1sh3nL-0003Je-4e; Thu, 22 Aug 2024 09:07:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 781627.1191126; Thu, 22 Aug 2024 09:07:51 +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-0003Ha-TZ; Thu, 22 Aug 2024 09:07:50 +0000 Received: by outflank-mailman (input) for mailman id 781627; Thu, 22 Aug 2024 09:06:44 +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 1sh3mG-00031f-CA for xen-devel@lists.xenproject.org; Thu, 22 Aug 2024 09:06:44 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d946fc37-6065-11ef-8776-851b0ebba9a2; Thu, 22 Aug 2024 11:06:42 +0200 (CEST) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a866cea40c4so73624966b.0 for ; Thu, 22 Aug 2024 02:06:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 02:06:41 -0700 (PDT) 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: d946fc37-6065-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1724317602; x=1724922402; 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=apMXWG5KKVJZvsURjvsfLTCaQHUpHrA7Cdja1G+UXWs=; b=AruAVyGQhVxatR+S7RPsTdJQbBYUU+BuJeSW0pwuA7OM11GEVF8vwWfBe4vGyUFF4Q jmtskHDsuzH8VrvuAgbmE0O72JC1iE01jZXI0lQUXVgJ/6RahRxa0fei/7dyYMmpLle/ ZyqmmO4sTkg3oaokOLosDQnNQgv9uPaT2FZ5c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724317602; x=1724922402; 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=apMXWG5KKVJZvsURjvsfLTCaQHUpHrA7Cdja1G+UXWs=; b=CwHSREgkjHOMDXbS6eYHJFmFIGqIwb1GN5KQqgCmgf3DV+hu0hTzyUPNBoC8fQ5x7w I0DfvVU1jUogULuhRH8duxZQTeIJSM7fEcCQyhgUxGbiAji7OMOfTY8LBrL71u/Lpeib HD82cibKeEELiBXf/tR/yq02UyvXo46s1QyRPcFS7o60SnVHo+61rpHwZBpfcPATk06G lWP5u3c9b6LOsJuOh38C93J0TYRw2IDu9K2oZYYnjgiCH5/zkS+mO8CUDX7ZxVS+wJKb bz7sdOeFyHIXX2A0PG2doLbuT4y+u1BNCNIqJ1xIXvVTzGcjmFnrVWqNMVZjNc36vcsd vzpg== X-Gm-Message-State: AOJu0Yw9Owy8/RWXqh/eeqsBWc7lKo6xbqZGrvcyiX3NWptEwW8ucwqZ h/hMXoBUYAYKlIIRBcaCI2E5SQKLJ03scXRWv6zjsjnhMIBj4XBDy8vNO7dr53jOka8CP8LO5z+ T7mA= X-Google-Smtp-Source: AGHT+IErlCYaMdMcS77XZoDN4Dk2S07zgJchi44QkpyQRX2Xr3FKCRaBdbA86xHlcke/JOJlC4Ge8A== X-Received: by 2002:a17:907:808:b0:a77:e48d:bc8 with SMTP id a640c23a62f3a-a866f27a0d1mr448033366b.21.1724317601732; Thu, 22 Aug 2024 02:06:41 -0700 (PDT) From: Andrii Sultanov To: xen-devel@lists.xenproject.org Cc: Andrii Sultanov , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Anthony PERARD , Christian Lindig , David Scott Subject: [PATCH v1 3/4] tools/oxenstored: Use the plugin for Xenctrl.domain_getinfo Date: Thu, 22 Aug 2024 10:06:04 +0100 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Oxenstored dynamically loads the plugin provided in ocaml/libs/xenstoredglue. The plugin is verified to be providing the specified plugin_interface during its loading. If a V2 of the plugin is produced, V1 will still be present, and a new version should only be loaded if it's verified to exist (New oxenstored can run in an environment with only V1 of the plugin). Signed-off-by: Andrii Sultanov --- Config.mk | 2 +- configure | 7 ++++ m4/paths.m4 | 4 ++ tools/configure | 7 ++++ tools/ocaml/xenstored/Makefile | 5 ++- tools/ocaml/xenstored/domains.ml | 63 +++++++++++++++++++++---------- tools/ocaml/xenstored/paths.ml.in | 1 + 7 files changed, 68 insertions(+), 21 deletions(-) diff --git a/Config.mk b/Config.mk index 1a3938b6c4..4be7d8a573 100644 --- a/Config.mk +++ b/Config.mk @@ -160,7 +160,7 @@ endef BUILD_MAKE_VARS := sbindir bindir LIBEXEC LIBEXEC_BIN libdir SHAREDIR \ XENFIRMWAREDIR XEN_CONFIG_DIR XEN_SCRIPT_DIR XEN_LOCK_DIR \ XEN_RUN_DIR XEN_PAGING_DIR XEN_DUMP_DIR XEN_LOG_DIR \ - XEN_LIB_DIR XEN_RUN_STORED + XEN_LIB_DIR XEN_RUN_STORED XEN_CTRL_DOMAININFO_PLUGIN buildmakevars2file = $(eval $(call buildmakevars2file-closure,$(1))) define buildmakevars2file-closure diff --git a/configure b/configure index 2d7b20aa50..1a473ad2dd 100755 --- a/configure +++ b/configure @@ -631,6 +631,7 @@ XEN_PAGING_DIR XEN_LOCK_DIR INITD_DIR SHAREDIR +XEN_CTRL_DOMAININFO_PLUGIN XEN_LIB_DIR XEN_RUN_STORED XEN_LOG_DIR @@ -2199,6 +2200,12 @@ XEN_LIB_DIR=$localstatedir/lib/xen printf "%s\n" "#define XEN_LIB_DIR \"$XEN_LIB_DIR\"" >>confdefs.h +XEN_CTRL_DOMAININFO_PLUGIN=$LIBEXEC_BIN/xenctrl_plugin + + +printf "%s\n" "#define XEN_CTRL_DOMAININFO_PLUGIN \"$XEN_CTRL_DOMAININFO_PLUGIN\"" >>confdefs.h + + SHAREDIR=$prefix/share diff --git a/m4/paths.m4 b/m4/paths.m4 index 3f94c62efb..e538445810 100644 --- a/m4/paths.m4 +++ b/m4/paths.m4 @@ -144,6 +144,10 @@ XEN_LIB_DIR=$localstatedir/lib/xen AC_SUBST(XEN_LIB_DIR) AC_DEFINE_UNQUOTED([XEN_LIB_DIR], ["$XEN_LIB_DIR"], [Xen's lib dir]) +XEN_CTRL_DOMAININFO_PLUGIN=$LIBEXEC_BIN/xenctrl_plugin +AC_SUBST(XEN_CTRL_DOMAININFO_PLUGIN) +AC_DEFINE_UNQUOTED([XEN_CTRL_DOMAININFO_PLUGIN], ["$XEN_CTRL_DOMAININFO_PLUGIN"], [Xenctrl's plugin for Oxenstored]) + SHAREDIR=$prefix/share AC_SUBST(SHAREDIR) diff --git a/tools/configure b/tools/configure index 7f98303fdd..24b12a1f5d 100755 --- a/tools/configure +++ b/tools/configure @@ -743,6 +743,7 @@ XEN_PAGING_DIR XEN_LOCK_DIR INITD_DIR SHAREDIR +XEN_CTRL_DOMAININFO_PLUGIN XEN_LIB_DIR XEN_RUN_STORED XEN_LOG_DIR @@ -4530,6 +4531,12 @@ XEN_LIB_DIR=$localstatedir/lib/xen printf "%s\n" "#define XEN_LIB_DIR \"$XEN_LIB_DIR\"" >>confdefs.h +XEN_CTRL_DOMAININFO_PLUGIN=$LIBEXEC_BIN/xenctrl_plugin + + +printf "%s\n" "#define XEN_CTRL_DOMAININFO_PLUGIN \"$XEN_CTRL_DOMAININFO_PLUGIN\"" >>confdefs.h + + SHAREDIR=$prefix/share diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile index fa45305d8c..09896732ed 100644 --- a/tools/ocaml/xenstored/Makefile +++ b/tools/ocaml/xenstored/Makefile @@ -15,7 +15,8 @@ OCAMLINCLUDE += \ -I $(OCAML_TOPLEVEL)/libs/xb \ -I $(OCAML_TOPLEVEL)/libs/mmap \ -I $(OCAML_TOPLEVEL)/libs/xc \ - -I $(OCAML_TOPLEVEL)/libs/eventchn + -I $(OCAML_TOPLEVEL)/libs/eventchn \ + -I $(OCAML_TOPLEVEL)/libs/xenstoredglue LIBS = syslog.cma syslog.cmxa poll.cma poll.cmxa syslog_OBJS = syslog @@ -59,6 +60,7 @@ INTF = symbol.cmi trie.cmi syslog.cmi systemd.cmi poll.cmi XENSTOREDLIBS = \ unix.cmxa \ + dynlink.cmxa \ -ccopt -L -ccopt . syslog.cmxa \ -ccopt -L -ccopt . systemd.cmxa \ -ccopt -L -ccopt . poll.cmxa \ @@ -66,6 +68,7 @@ XENSTOREDLIBS = \ -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/eventchn/xeneventchn.cmxa \ -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xenctrl.cmxa \ -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xenbus.cmxa \ + -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xenstoredglue $(OCAML_TOPLEVEL)/libs/xenstoredglue/plugin_interface_v1.cmxa \ -ccopt -L -ccopt $(XEN_ROOT)/tools/libs/ctrl PROGRAMS = oxenstored diff --git a/tools/ocaml/xenstored/domains.ml b/tools/ocaml/xenstored/domains.ml index 7a3056c364..e3edee6de6 100644 --- a/tools/ocaml/xenstored/domains.ml +++ b/tools/ocaml/xenstored/domains.ml @@ -20,10 +20,36 @@ let warn fmt = Logging.warn "domains" fmt let xc = Xenctrl.interface_open () -type domains = { - eventchn: Event.t; - table: (Xenctrl.domid, Domain.t) Hashtbl.t; +let load_plug fname = + let fail_with fmt = Printf.ksprintf failwith fmt in + let fname = Dynlink.adapt_filename fname in + if Sys.file_exists fname then + try Dynlink.loadfile fname with + | Dynlink.Error err as e -> + Printf.eprintf "ERROR loading plugin '%s': %s\n%!" fname + (Dynlink.error_message err); + raise e + | _ -> fail_with "Unknown error while loading plugin" + else fail_with "Plugin file '%s' does not exist" fname + +let () = + let filepath = Paths.xen_ctrl_plugin ^ "/domain_getinfo_v1.cmxs" in + Printf.printf "Trying to load plugin '%s'\n%!" filepath; + let list_files = Sys.readdir Paths.xen_ctrl_plugin in + Printf.printf "Directory listing of '%s'\n%!" Paths.xen_ctrl_plugin; + Array.iter (fun x -> Printf.printf "\t%s\n%!" x) list_files; + Dynlink.allow_only [ "Plugin_interface_v1" ]; + load_plug filepath + +module Plugin = + (val Plugin_interface_v1.get_plugin_v1 () + : Plugin_interface_v1.Domain_getinfo_V1) + +let handle = Plugin.interface_open () +type domains = { + eventchn : Event.t; + table : (Plugin.domid, Domain.t) Hashtbl.t; (* N.B. the Queue module is not thread-safe but oxenstored is single-threaded. *) (* Domains queue up to regain conflict-credit; we have a queue for domains that are carrying some penalty and so are below the @@ -93,22 +119,21 @@ let cleanup doms = let notify = ref false in let dead_dom = ref [] in - Hashtbl.iter (fun id _ -> if id <> 0 then - try - let info = Xenctrl.domain_getinfo xc id in - if info.Xenctrl.shutdown || info.Xenctrl.dying then ( - debug "Domain %u died (dying=%b, shutdown %b -- code %d)" - id info.Xenctrl.dying info.Xenctrl.shutdown info.Xenctrl.shutdown_code; - if info.Xenctrl.dying then - dead_dom := id :: !dead_dom - else - notify := true; - ) - with Xenctrl.Error _ -> - debug "Domain %u died -- no domain info" id; - dead_dom := id :: !dead_dom; - ) doms.table; - List.iter (fun id -> + Hashtbl.iter + (fun id _ -> + if id <> 0 then ( + try + let info = Plugin.domain_getinfo handle id in + if info.Plugin.shutdown || info.Plugin.dying then ( + debug "Domain %u died (dying=%b, shutdown %b -- code %d)" id + info.Plugin.dying info.Plugin.shutdown info.Plugin.shutdown_code; + if info.Plugin.dying then dead_dom := id :: !dead_dom else notify := true) + with Plugin.Error _ -> + debug "Domain %u died -- no domain info" id; + dead_dom := id :: !dead_dom)) + doms.table; + List.iter + (fun id -> let dom = Hashtbl.find doms.table id in Domain.close dom; Hashtbl.remove doms.table id; diff --git a/tools/ocaml/xenstored/paths.ml.in b/tools/ocaml/xenstored/paths.ml.in index 37949dc8f3..67276dda94 100644 --- a/tools/ocaml/xenstored/paths.ml.in +++ b/tools/ocaml/xenstored/paths.ml.in @@ -2,3 +2,4 @@ let xen_log_dir = "@XEN_LOG_DIR@" let xen_config_dir = "@XEN_CONFIG_DIR@" let xen_run_dir = "@XEN_RUN_DIR@" let xen_run_stored = "@XEN_RUN_STORED@" +let xen_ctrl_plugin = "@XEN_CTRL_DOMAININFO_PLUGIN@" From patchwork Thu Aug 22 09:06:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Sultanov X-Patchwork-Id: 13773035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AAE5CC3DA4A for ; Thu, 22 Aug 2024 09:08:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.781629.1191135 (Exim 4.92) (envelope-from ) id 1sh3nL-0003T0-I3; Thu, 22 Aug 2024 09:07:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 781629.1191135; Thu, 22 Aug 2024 09:07:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sh3nL-0003RG-8t; Thu, 22 Aug 2024 09:07:51 +0000 Received: by outflank-mailman (input) for mailman id 781629; Thu, 22 Aug 2024 09:06:46 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sh3mI-0002Rz-46 for xen-devel@lists.xenproject.org; Thu, 22 Aug 2024 09:06:46 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id db150d48-6065-11ef-a50a-bb4a2ccca743; Thu, 22 Aug 2024 11:06:45 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a8682bb5e79so84090066b.2 for ; Thu, 22 Aug 2024 02:06:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 02:06:44 -0700 (PDT) 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: db150d48-6065-11ef-a50a-bb4a2ccca743 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1724317605; x=1724922405; 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=zC1kK8nz8HkQxKR7SEj5x2jWrRcksrvnhTGjt2Y7Jm0=; b=Ct8oVTsOgGyNIzbVsr2+HYumQqPbQG7YupRH6TU4GykhlcWy1aiHBNPGZ4RBMSZM9q YrQSpfvagb5mj+wSlcUOOTW7OghmW6rZQpirl2IG21qU+72fmKSLQzsLS+phhCsnCABB 12s8W7a1tWjmmgPWEU260xNjIZu0U6J1iYSEI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724317605; x=1724922405; 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=zC1kK8nz8HkQxKR7SEj5x2jWrRcksrvnhTGjt2Y7Jm0=; b=uYWEiP1pnk8a0SLqGY6rwyQxFXfDqwU4DhkGG4Voa6Wo18Tlcx+L3LRDHcfnHU/jrK RRGuKeZJ3THZZ1/Kz2vOJUJULm5mZ0E+7U7dxTUG9lT1KH2LV+NP1wBCuM1tv9m+o7lc W3l//XOe2qjtyk8+y6/SWLddmAom9EQSz5KTnawub6/QyIgZm/Mk76BU2+WkXKkCfYTT dX2ertkcUbcPa0mV52j9KEbIedrzrL1TfG5RxGiGZ0Lh7quz6/41FenM+L0nOkkMTBIg 1RfuX4PjbKwV41ilHg7bNLys4dd+gS2kM44S0e2/HF0GtVaIyO856QNjfiexw/VQIRFv STVQ== X-Gm-Message-State: AOJu0YxTR+RtQrlqMymeZ/CvL374Sc8aktJGXlWC2ud6TprdD9+FiFNn 9YEJucM+h1SyDURyKb8qDjGxssIhQJg3LAEwVZICmB+Ovy9HmMpfsvvwBoFURN8GNB6lpc4IrL8 p X-Google-Smtp-Source: AGHT+IElPbcnHvnSCRtgGX92MGchEdfdBCL53x2SJ5xhZmDJgNNrDED3WbicO7q4ifC1QOYuvtSDVw== X-Received: by 2002:a17:907:7f1f:b0:a86:89ea:ee6c with SMTP id a640c23a62f3a-a8689eaefe8mr191195266b.30.1724317604700; Thu, 22 Aug 2024 02:06:44 -0700 (PDT) From: Andrii Sultanov To: xen-devel@lists.xenproject.org Cc: Andrii Sultanov , Christian Lindig , David Scott , Anthony PERARD Subject: [PATCH v1 4/4] Makefile.rules: Fix OCaml libs Date: Thu, 22 Aug 2024 10:06:05 +0100 Message-Id: <9c9eac180468d1c4044048094956951bcc2edaa6.1724314239.git.andrii.sultanov@cloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 This commit upstreams the pre-existing patch from https://github.com/xenserver/xen.pg/blob/XS-8/patches/fix-ocaml-libs.patch Signed-off-by: Andrii Sultanov --- tools/ocaml/Makefile.rules | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/ocaml/Makefile.rules b/tools/ocaml/Makefile.rules index 0444e95f17..84f5ecafe7 100644 --- a/tools/ocaml/Makefile.rules +++ b/tools/ocaml/Makefile.rules @@ -62,18 +62,18 @@ mk-caml-lib-bytecode = $(call quiet-command, $(OCAMLC) $(OCAMLCFLAGS) -a -o $1 $ mk-caml-stubs = $(call quiet-command, $(OCAMLMKLIB) -o `basename $1 .a` $2,MKLIB,$1) mk-caml-lib-stubs = \ - $(call quiet-command, $(AR) rcs $1 $2 && $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $2,MKLIB,$1) + $(call quiet-command, $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $2 $3,MKLIB,$1) # define a library target .cmxa and .cma define OCAML_LIBRARY_template $(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).cma: $(foreach obj,$($(1)_OBJS),$(obj).cmo) - $(call mk-caml-lib-bytecode,$$@, -dllib dll$(1)_stubs.so -cclib -l$(1)_stubs, $$+) + $(call mk-caml-lib-bytecode,$$@, -dllib dll$(1)_stubs.so -cclib -l$(1)_stubs $(foreach lib,$(LIBS_$(1)),-cclib $(lib)), $$+) $(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,$$@, $$+) + $(call mk-caml-lib-stubs,$$@, $$+, $(foreach lib,$(LIBS_$(1)),$(lib))) endef # Dynamically linked OCaml libraries ("plugins" in Dynlink parlance)