From nobody Wed Dec 4 08:44:11 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=1725363922; cv=none; d=zohomail.com; s=zohoarc; b=h7g/itdQxvvfn0CDMR64SeEjt+b7xqc9yufovrpn9HKWbDADRybD8mP3rh0yQfeqKC6RWIOsHPC/+0MG7Hd6Hd2c00+CycdO/ufAVfmZB9NAlawqE9fZmND50JLR1STM95NLNGdr0GJd+4xlHUxuxkoS9znI+ljdfx6O/m8rrW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725363922; 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=lcvn7ewWKMXwk4/Zri2I75vp6w3p2veK6Jesxqi/v5s=; b=EJV4ZZp91Zo2VR+UBxWGDEPzMN9VlIsi8YYeFC/dfG7x6QZRor/XRD63BlWoXO7hG199oH9dRw2A5IlWi0baS7bTrvh1OExKQZMSQEQJkJI6cQ4xqbBDBurvPipUUy4olCS0c9n1K002lTeBks0rOA9vabyxJWST+cysHKnJPxM= 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 1725363922101652.1971160123401; Tue, 3 Sep 2024 04:45:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.788996.1198519 (Exim 4.92) (envelope-from ) id 1slRy1-0007jW-1d; Tue, 03 Sep 2024 11:45:01 +0000 Received: by outflank-mailman (output) from mailman id 788996.1198519; Tue, 03 Sep 2024 11:45:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slRy0-0007iF-UA; Tue, 03 Sep 2024 11:45:00 +0000 Received: by outflank-mailman (input) for mailman id 788996; Tue, 03 Sep 2024 11:44:59 +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 1slRxz-0007g4-Tf for xen-devel@lists.xenproject.org; Tue, 03 Sep 2024 11:44:59 +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 f22425b1-69e9-11ef-a0b2-8be0dac302b0; Tue, 03 Sep 2024 13:44:58 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a8684c31c60so578905166b.3 for ; Tue, 03 Sep 2024 04:44:58 -0700 (PDT) Received: from EMEAENGAAD87503.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8988feacd7sm673794266b.34.2024.09.03.04.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 04:44:56 -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: f22425b1-69e9-11ef-a0b2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1725363897; x=1725968697; 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=lcvn7ewWKMXwk4/Zri2I75vp6w3p2veK6Jesxqi/v5s=; b=JxdeqH47NXviRhncG0sLzhugP35kRvGklTONcz1Hz7WSua8QWfCTWrDtHQy+bos06E RiaDQaSQa6+ASxqMqlAA2O1R3FPmLnRfusE6YVtZdhpmS0In5eDhmMwTZRfOUfLt1KXB pE/Mri319bO3zcRAWwfQkeFvR+K4qjT5HhNSs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725363897; x=1725968697; 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=lcvn7ewWKMXwk4/Zri2I75vp6w3p2veK6Jesxqi/v5s=; b=lzowIeFRKmSouc87gd61nZUbIu6rgJgqlkdQ7tfcWzdYjv7y/P/+OyLy+O/iY8/dd3 ra4SiVYuflWgg45rEtNRkO4JyF7DyW7Ucr+4lr4UZPumNW4i18E0sQ0uMD7yTxS4w1aE D6zeOsEmx3W4SaMDlcgQ7mNRhl10s06pcq07PLbo2FjQNily84o1mpk/aukO3kMhKf1f P3UstzrThg2+L0tKEfoe10qp9Yw6jEybV5lzSKQDlWko8pzCNv98vj3t178WxLt/qN5f o44BlwaXPjWfkzjTkBFVO7ajal9QfDiiXwN0CeS7x2qElKMRNifqczkyRpcX5ZsUSXcj E5ww== X-Gm-Message-State: AOJu0YwDI9FExOrszlZngGsXDf2Ut2fOEhxTL1O8dDEJqUZ2pw2Tu/09 AYtYYSWaFilktaPosqiquzEpllusNdKTaD7IOlrd/7aH2sq//3AQk4ZW0pF8g+DQzOLMhKPUKnb tLl8= X-Google-Smtp-Source: AGHT+IFjofnkUaDWuSrGWKJ//n8zTMuZ04j7ne+hY7XPuL45UWwkwudFZknGhNxDEKqkyDYA1N1M/w== X-Received: by 2002:a17:907:980d:b0:a77:e2e3:354d with SMTP id a640c23a62f3a-a897f83a33bmr1258361766b.23.1725363897380; Tue, 03 Sep 2024 04:44:57 -0700 (PDT) From: Andrii Sultanov To: xen-devel@lists.xenproject.org Cc: Andrii Sultanov , Christian Lindig , David Scott , Anthony PERARD Subject: [PATCH v2 1/3] tools/ocaml: Build infrastructure for OCaml dynamic libraries Date: Tue, 3 Sep 2024 12:44:42 +0100 Message-Id: <36a9b5cbaba9bfffe261b824388ee81bb3c0a260.1725363427.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: 1725363923603116600 Content-Type: text/plain; charset="utf-8" Dynamic libraries in OCaml require an additional compilation step on top of the already specified steps for static libraries. Add an appropriate template to Makefile.rules. Signed-off-by: Andrii Sultanov Acked-by: Andrew Cooper Acked-by: Christian Lindig --- tools/ocaml/Makefile.rules | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/ocaml/Makefile.rules b/tools/ocaml/Makefile.rules index 5d534d8754..b9d4b51f0a 100644 --- a/tools/ocaml/Makefile.rules +++ b/tools/ocaml/Makefile.rules @@ -51,12 +51,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 @@ -76,6 +77,19 @@ define OCAML_LIBRARY_template $(call mk-caml-lib-stubs,$$@, $$+, $(foreach lib,$(LIBS_$(1)),$(lib))) 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)) @@ -98,6 +112,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)))) --=20 2.39.2 From nobody Wed Dec 4 08:44:11 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=1725363923; cv=none; d=zohomail.com; s=zohoarc; b=cSf3O1WvJLViKWS3H+JRkb9vZC74YjYaLJqfFcYB2pf2pkGQ2QDJt//jyyJqgY7DTqrwk7pZT3mx72DrTDiqYi83YBXTnU522DZDBzSKxiiSbLdha/b1Nd2DlB+3gNoIAgu6HfgFo7pXksVDu9HZNP4nSaUHEg6NaX5uDQKslVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725363923; 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=ywxkLKS4OQrjeJPdR5be+uTG0E4A2l8FWKHBAiJNfSk=; b=Swmqd9B2tUoyo3JR/7BIEvUBIDjjJ0qNO9fEtfc81J41PY+dVtr53NpBdkh5mHXFa/4ZW3gwf6jGhUeRPGsa9+12j3LLtE13k71gUIi+J/M0Zk1jt0O+mHjhMGRXOLf1/V/YgZJKuBeXwH0yB7q064KNynT7RDIAJy2Zvs9c5LQ= 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 1725363923079382.5714275845364; Tue, 3 Sep 2024 04:45:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.788998.1198541 (Exim 4.92) (envelope-from ) id 1slRy3-0008CX-Jv; Tue, 03 Sep 2024 11:45:03 +0000 Received: by outflank-mailman (output) from mailman id 788998.1198541; Tue, 03 Sep 2024 11:45:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slRy3-0008BY-Bm; Tue, 03 Sep 2024 11:45:03 +0000 Received: by outflank-mailman (input) for mailman id 788998; Tue, 03 Sep 2024 11:45:02 +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 1slRy2-0007fy-EP for xen-devel@lists.xenproject.org; Tue, 03 Sep 2024 11:45:02 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f345ff4d-69e9-11ef-99a1-01e77a169b0f; Tue, 03 Sep 2024 13:45:00 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5353d0b7463so8822617e87.3 for ; Tue, 03 Sep 2024 04:45:00 -0700 (PDT) Received: from EMEAENGAAD87503.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8988feacd7sm673794266b.34.2024.09.03.04.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 04:44:58 -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: f345ff4d-69e9-11ef-99a1-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1725363899; x=1725968699; 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=ywxkLKS4OQrjeJPdR5be+uTG0E4A2l8FWKHBAiJNfSk=; b=I0rkB+2/Hr+Y/bmnAmyNydrRVt0uJ/gy12gq+31fumI+2k5uVWKSn0o5c0epJMet7v bYQcEOaZeumPpcKb7YjZMZ/qUv+mb4m1m0cXj50pv/tQI0s1pf0ZPKbrJGEwMDuwTfhV z/r6XgYJaCtoAJLJwftaPYLoEf6GQapLjuCiQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725363899; x=1725968699; 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=ywxkLKS4OQrjeJPdR5be+uTG0E4A2l8FWKHBAiJNfSk=; b=bY5k+icf3K6IhrSNc4/hgVAqL/HGM6zqQ/w8oC06bujkcZv/g9iYLXYs+usamaQvdg FZPePjCWLH4EAmq+j1wv+Rg1upcZNi6HDJwZmPlWrHX13Eh9Xgq9IumkxISkR7Bc8mCM G+WqGq1pbWR5rreR21++m43tDVyma9z8UdQG2ztzv68NTI6rdcf/OUN96xKZB2DVLseH SxlD5Dn00N/4UIuF59VUVNDTia1pumDj2NJJSnxg/D9TEnsgSaBWM+UAfKDtPzb1SaSu l9DEFjjw57n4mZ3SWQQx/OvoWC2gkSEONpVd/0+E6pkB7eD39Q1tD1EgNr9MuuFJLWlB ufDw== X-Gm-Message-State: AOJu0Yzvf0I+rpejs9i9DRq6kpDXbTPp7fcRaXGZmoIhH8lpHgZJ/2uW Nj/7zB+CzGTv4E6uGD8Af1508IqVVJ5i4TKRWdx4xXvzYM2Mf0EiRgjY1gvxtLZLdVWtRyr+mjX j X-Google-Smtp-Source: AGHT+IERLjPEde4s1TC3Y1UoSvFJPr2XI3MXcKG5jyeancfyrdT/00xpliBBtG8ubYwcCANDSgwUUw== X-Received: by 2002:a05:6512:693:b0:533:407f:5cbd with SMTP id 2adb3069b0e04-53546b191ccmr10505037e87.7.1725363899053; Tue, 03 Sep 2024 04:44:59 -0700 (PDT) From: Andrii Sultanov To: xen-devel@lists.xenproject.org Cc: Andrii Sultanov , Christian Lindig , David Scott , Anthony PERARD Subject: [PATCH v2 2/3] ocaml/libs: Implement a dynamically-loaded plugin for Xenctrl.domain_getinfo Date: Tue, 3 Sep 2024 12:44:43 +0100 Message-Id: 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: 1725363923853116600 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 three 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 Acked-by: Christian Lindig --- tools/ocaml/Makefile | 1 + tools/ocaml/libs/Makefile | 2 +- tools/ocaml/libs/xenstoredglue/META.in | 4 + tools/ocaml/libs/xenstoredglue/Makefile | 46 +++++ .../domain_getinfo_plugin_v1/META.in | 5 + .../domain_getinfo_plugin_v1/Makefile | 38 ++++ .../domain_getinfo_stubs_v1.c | 172 ++++++++++++++++++ .../domain_getinfo_v1.ml | 36 ++++ .../domain_getinfo_v1.mli | 0 .../libs/xenstoredglue/plugin_interface_v1.ml | 28 +++ .../xenstoredglue/plugin_interface_v1.mli | 36 ++++ 11 files changed, 367 insertions(+), 1 deletion(-) 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/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..95818cdf83 --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/Makefile @@ -0,0 +1,46 @@ +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 + mkdir -p $(OCAMLDESTDIR) + $(OCAMLFIND) remove -destdir $(OCAMLDESTDIR) xenstored_glue + $(OCAMLFIND) install -destdir $(OCAMLDESTDIR) -ldconf ignore xenstored_gl= ue META $(INTF) $(LIBS) + $(OCAMLFIND) remove -destdir $(OCAMLDESTDIR) xenstored_glue_dev + $(OCAMLFIND) install -destdir $(OCAMLDESTDIR) -ldconf ignore xenstored_gl= ue_dev META $(INTF) $(LIBS) *.ml *.mli + +.PHONY: uninstall +uninstall: subdirs-uninstall + $(OCAMLFIND) remove -destdir $(OCAMLDESTDIR) xenstored_glue + $(OCAMLFIND) remove -destdir $(OCAMLDESTDIR) xenstored_glue_dev + +.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..9c40026cab --- /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 -I $(OCAML_TOPLEVEL)/libs/xenstoredg= lue +CFLAGS +=3D $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude) $(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)/xenstored_glue/xenctrl_plugin + $(INSTALL_PROG) domain_getinfo_v1.cmxs $(DESTDIR)$(LIBEXEC_BIN)/xenstored= _glue/xenctrl_plugin + +.PHONY: uninstall +uninstall: + rm -f $(DESTDIR)/xenstored_glue/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..69eddd6412 --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/domain_getinf= o_stubs_v1.c @@ -0,0 +1,172 @@ +#define _GNU_SOURCE + +#include +#include +#include + +#define CAML_NAME_SPACE +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "xen-caml-compat.h" + +#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, + const char* func, + unsigned int line) +{ + const xc_error *error =3D xch ? xc_get_last_error(xch) : NULL; + char *str =3D NULL; + CAMLparam0(); + CAMLlocal1(msg); + +#define ERR (error && error->code !=3D XC_ERROR_NONE) + + int ret =3D asprintf(&str, + "%d: %s%s%s - called from %s:%u", + ERR ? error->code : errno, + ERR ? xc_error_code_to_desc(error->code) : stre= rror(errno), + ERR ? ": " : "", + ERR ? error->message : "", + func, line); + +#undef ERR + + if (!*str || (ret =3D=3D -1)) + caml_raise_out_of_memory(); + + msg =3D caml_copy_string(str); + free(str); + + caml_raise_with_arg(*caml_named_value("xsg.error_v1"), msg); +} + +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(const 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, domid_c; + + domid_c =3D Int_val(domid); + caml_enter_blocking_section(); + ret =3D xc_domain_getinfo_single(xch, domid_c, &info); + caml_leave_blocking_section(); + + 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) +{ + CAMLparam2(xch_val, first_domain); + CAMLlocal1(result); + xc_interface *xch =3D xsglue_xch_of_val_v1(xch_val); + xc_domaininfo_t *info; + int i, ret, toalloc, retval; + uint32_t num_domains; + uint32_t c_first_domain; + + /* get the minimum number of allocate byte we need and bump it up to page= boundary */ + c_first_domain =3D Int_val(first_domain); + num_domains =3D DOMID_FIRST_RESERVED - c_first_domain; + toalloc =3D (sizeof(xc_domaininfo_t) * num_domains) | 0xfff; + ret =3D posix_memalign((void **) ((void *) &info), 4096, toalloc); + if (ret) + caml_raise_out_of_memory(); + + caml_enter_blocking_section(); + retval =3D xc_domain_getinfolist(xch, c_first_domain, num_domains, info); + caml_leave_blocking_section(); + + if (retval < 0) { + free(info); + failwith_xc_v1(xch); + } else if (retval > 0) { + result =3D caml_alloc(retval, 0); + for (i =3D 0; i < retval; i++) { + caml_modify(&Field(result, i), xsglue_alloc_domaininfo_v1(info + i)); + } + } else { + result =3D Atom(0); + } + + 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..6f282e4257 --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/domain_getinfo_plugin_v1/domain_getinf= o_v1.ml @@ -0,0 +1,36 @@ +(** Minimal interface on top of unstable Xenctrl for Oxenstored's usage *) + +(** For the full Xenctrl interface, see: tools/ocaml/libs/xc/ *) + +module P =3D Plugin_interface_v1 + +module M : P.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 -> domaininfo array + =3D "stub_xsglue_xc_domain_getinfolist" + + let _ =3D Callback.register_exception "xsg.error_v1" (Error "register_ca= llback") +end + +let () =3D + Printf.ksprintf !P.logging_function "Registration of %s plugin started\n= %!" + __MODULE__; + P.register_plugin_v1 (module M : P.Domain_getinfo_V1); + Printf.ksprintf !P.logging_function "Registration of %s plugin successfu= l\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..131b29d3ee --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/plugin_interface_v1.ml @@ -0,0 +1,28 @@ +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 array +end + +let ignore_logging : string -> unit =3D ignore +let logging_function =3D ref ignore_logging +let register_logging_function func =3D logging_function :=3D func +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..d073a44d0f --- /dev/null +++ b/tools/ocaml/libs/xenstoredglue/plugin_interface_v1.mli @@ -0,0 +1,36 @@ +(** 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 array +end + +val register_logging_function : (string -> unit) -> unit +val logging_function : (string -> unit) ref +val register_plugin_v1 : (module Domain_getinfo_V1) -> unit +val get_plugin_v1 : unit -> (module Domain_getinfo_V1) --=20 2.39.2 From nobody Wed Dec 4 08:44:11 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=1725363926; cv=none; d=zohomail.com; s=zohoarc; b=Iggxs/shhjSPaHQ4NVV/spM0KFHZxC3KQWzQ++mS90lXugwzp0Gy/oAPfJP2kb0Bzc3yoFGv5ssifSpX0MQ4a/ETdf16cG9TEgHPt5KWs7XtwGgdOufbbnzQCGfGk2xHQhjYLtjMz9QwKsqU8pjfCzlBvOQS1xr2HINT50L1Ze4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725363926; 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=0GOU5GNMH42YNVa90LGT+QRduZ2YOSpr6Y65CRTqSeQ=; b=iqs2l0vmmAC/aQLY2tq+1t60YAhvt3rGpxhw0CJ9JOThnAb7tBPdv+0niYxB7/6zXiFXSKt+PzUJ81itYKmZ4ceZFZtRRR8lmCljTj63hF9uHHumCcun90+hi6by2Iy4joNJhyFc3giFzLMnMl6MhO9VNKVKJhoKC9lymUDZbKs= 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 1725363926661252.90339482035733; Tue, 3 Sep 2024 04:45:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.788997.1198534 (Exim 4.92) (envelope-from ) id 1slRy3-00089A-8O; Tue, 03 Sep 2024 11:45:03 +0000 Received: by outflank-mailman (output) from mailman id 788997.1198534; Tue, 03 Sep 2024 11:45:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slRy3-000893-4d; Tue, 03 Sep 2024 11:45:03 +0000 Received: by outflank-mailman (input) for mailman id 788997; Tue, 03 Sep 2024 11:45:02 +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 1slRy2-0007g4-9t for xen-devel@lists.xenproject.org; Tue, 03 Sep 2024 11:45:02 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f404a857-69e9-11ef-a0b2-8be0dac302b0; Tue, 03 Sep 2024 13:45:01 +0200 (CEST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-533521cd1c3so6042083e87.1 for ; Tue, 03 Sep 2024 04:45:01 -0700 (PDT) Received: from EMEAENGAAD87503.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8988feacd7sm673794266b.34.2024.09.03.04.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 04:45:00 -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: f404a857-69e9-11ef-a0b2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1725363901; x=1725968701; 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=0GOU5GNMH42YNVa90LGT+QRduZ2YOSpr6Y65CRTqSeQ=; b=Q1bnSSkNhCOaPm1b++jvJwTk8cWXd6qOckA/HIwDN4uuVlN7nyF8gtX/VFJC7Fm5hE H5EZlrbBZmCAikd6ygiKqEmTxdmrr/drw00uZ7+5xgUIxgSduEVU2uM6RIDffQ3a2Mha deWxAHppQgFFc0a5H7Pz0/HExENtXJQfoGFvY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725363901; x=1725968701; 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=0GOU5GNMH42YNVa90LGT+QRduZ2YOSpr6Y65CRTqSeQ=; b=Jxewm3ys8YBqpuI/Sj1aoIWLhc5P04dal+t/p+uth37WYJ4bdwacBZUq0maXG/hzQ2 qEPdJZ8YQwCQEwoTxFhrMO5DkqCRbdxFsOR523VLTZ+TjYPOs1wHrRyAMEBP1TdmuAB3 lg+T+o5sXLnJ0jBa+8tANE9GCJiWifVnr9/Lgum8seAFn8crc4khYswwRGkzkN/QJRco wshk97XO4rh0owA+Oz0Gpxr6P6g7Yl3JBTKUtNDOgldVGMjiZlScM9CaE3YV6FT4SFqi ljsLGP6YS9eAaNiKkQYT3VsYNCQSXuhFzvrm4nepsXweTWmHMjdYKpPDfcYFuaprrn3B Q88A== X-Gm-Message-State: AOJu0Yx0FOAY/f1ec6knem0N7lD/5isZJfkqq6aq7uI4ReMAfV9OwQUb iI3cH8cNm2z5NXr3L0FeXCYCjnx+D/YMItHA/CXFNcQ/bpVehBNixPz7eJjI+uxsof+ft8/+ugj X7+0= X-Google-Smtp-Source: AGHT+IHV9u/DoSXIJCmcYBImYHr4oz2SO7kZbiM6VUzNEv1i+QjTRkSxmOqTE6BIpDB4oqpO6NOF0w== X-Received: by 2002:ac2:4c54:0:b0:52c:d628:c77c with SMTP id 2adb3069b0e04-53546bdea9dmr12326339e87.43.1725363900566; Tue, 03 Sep 2024 04:45:00 -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 v2 3/3] tools/oxenstored: Use the plugin for Xenctrl.domain_getinfo Date: Tue, 3 Sep 2024 12:44:44 +0100 Message-Id: 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: 1725363927594116600 Content-Type: text/plain; charset="utf-8" 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 Acked-by: Christian Lindig --- 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 :=3D sbindir bindir LIBEXEC LIBEXEC_BIN libdir SHAREDIR \ XENFIRMWAREDIR XEN_CONFIG_DIR XEN_SCRIPT_DIR XEN_LOCK_D= IR \ 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 =20 buildmakevars2file =3D $(eval $(call buildmakevars2file-closure,$(1))) define buildmakevars2file-closure diff --git a/configure b/configure index 2d7b20aa50..20aae12884 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=3D$localstatedir/lib/xen printf "%s\n" "#define XEN_LIB_DIR \"$XEN_LIB_DIR\"" >>confdefs.h =20 =20 +XEN_CTRL_DOMAININFO_PLUGIN=3D$LIBEXEC_BIN/xenstored_glue/xenctrl_plugin + + +printf "%s\n" "#define XEN_CTRL_DOMAININFO_PLUGIN \"$XEN_CTRL_DOMAININFO_P= LUGIN\"" >>confdefs.h + + SHAREDIR=3D$prefix/share =20 =20 diff --git a/m4/paths.m4 b/m4/paths.m4 index 3f94c62efb..533bac919b 100644 --- a/m4/paths.m4 +++ b/m4/paths.m4 @@ -144,6 +144,10 @@ XEN_LIB_DIR=3D$localstatedir/lib/xen AC_SUBST(XEN_LIB_DIR) AC_DEFINE_UNQUOTED([XEN_LIB_DIR], ["$XEN_LIB_DIR"], [Xen's lib dir]) =20 +XEN_CTRL_DOMAININFO_PLUGIN=3D$LIBEXEC_BIN/xenstored_glue/xenctrl_plugin +AC_SUBST(XEN_CTRL_DOMAININFO_PLUGIN) +AC_DEFINE_UNQUOTED([XEN_CTRL_DOMAININFO_PLUGIN], ["$XEN_CTRL_DOMAININFO_PL= UGIN"], [Xenctrl's plugin for Oxenstored]) + SHAREDIR=3D$prefix/share AC_SUBST(SHAREDIR) =20 diff --git a/tools/configure b/tools/configure index 7f98303fdd..830c8c1533 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=3D$localstatedir/lib/xen printf "%s\n" "#define XEN_LIB_DIR \"$XEN_LIB_DIR\"" >>confdefs.h =20 =20 +XEN_CTRL_DOMAININFO_PLUGIN=3D$LIBEXEC_BIN/xenstored_glue/xenctrl_plugin + + +printf "%s\n" "#define XEN_CTRL_DOMAININFO_PLUGIN \"$XEN_CTRL_DOMAININFO_P= LUGIN\"" >>confdefs.h + + SHAREDIR=3D$prefix/share =20 =20 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 +=3D \ -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 =20 LIBS =3D syslog.cma syslog.cmxa poll.cma poll.cmxa syslog_OBJS =3D syslog @@ -59,6 +60,7 @@ INTF =3D symbol.cmi trie.cmi syslog.cmi systemd.cmi poll.= cmi =20 XENSTOREDLIBS =3D \ unix.cmxa \ + dynlink.cmxa \ -ccopt -L -ccopt . syslog.cmxa \ -ccopt -L -ccopt . systemd.cmxa \ -ccopt -L -ccopt . poll.cmxa \ @@ -66,6 +68,7 @@ XENSTOREDLIBS =3D \ -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/e= ventchn/xeneventchn.cmxa \ -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xenc= trl.cmxa \ -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xenb= us.cmxa \ + -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xenstoredglue $(OCAML_TOPLEVEL)/l= ibs/xenstoredglue/plugin_interface_v1.cmxa \ -ccopt -L -ccopt $(XEN_ROOT)/tools/libs/ctrl =20 PROGRAMS =3D oxenstored diff --git a/tools/ocaml/xenstored/domains.ml b/tools/ocaml/xenstored/domai= ns.ml index 7a3056c364..dfff84c918 100644 --- a/tools/ocaml/xenstored/domains.ml +++ b/tools/ocaml/xenstored/domains.ml @@ -20,10 +20,36 @@ let warn fmt =3D Logging.warn "domains" fmt =20 let xc =3D Xenctrl.interface_open () =20 -type domains =3D { - eventchn: Event.t; - table: (Xenctrl.domid, Domain.t) Hashtbl.t; +let load_plug fname =3D + let fail_with fmt =3D Printf.ksprintf failwith fmt in + let fname =3D Dynlink.adapt_filename fname in + if Sys.file_exists fname then + try Dynlink.loadfile fname with + | Dynlink.Error err as e -> + error "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 () =3D + let filepath =3D Paths.xen_ctrl_plugin ^ "/domain_getinfo_v1.cmxs" in + debug "Trying to load plugin '%s'\n%!" filepath; + let list_files =3D Sys.readdir Paths.xen_ctrl_plugin in + debug "Directory listing of '%s'\n%!" Paths.xen_ctrl_plugin; + Array.iter (fun x -> debug "\t%s\n%!" x) list_files; + Dynlink.allow_only [ "Plugin_interface_v1" ]; + load_plug filepath + +module Plugin =3D + (val Plugin_interface_v1.get_plugin_v1 () + : Plugin_interface_v1.Domain_getinfo_V1) + +let handle =3D Plugin.interface_open () =20 +type domains =3D { + eventchn : Event.t; + table : (Plugin.domid, Domain.t) Hashtbl.t; (* N.B. the Queue module is not thread-safe but oxenstored is single-thr= eaded. *) (* 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 =3D let notify =3D ref false in let dead_dom =3D ref [] in =20 - Hashtbl.iter (fun id _ -> if id <> 0 then - try - let info =3D Xenctrl.domain_getinfo xc id in - if info.Xenctrl.shutdown || info.Xenctrl.dying then ( - debug "Domain %u died (dying=3D%b, shutdown %b -- c= ode %d)" - id info.Xenctrl.dying info.Xenctrl.shutdown info.= Xenctrl.shutdown_code; - if info.Xenctrl.dying then - dead_dom :=3D id :: !dead_dom - else - notify :=3D true; - ) - with Xenctrl.Error _ -> - debug "Domain %u died -- no domain info" id; - dead_dom :=3D id :: !dead_dom; - ) doms.table; - List.iter (fun id -> + Hashtbl.iter + (fun id _ -> + if id <> 0 then ( + try + let info =3D Plugin.domain_getinfo handle id in + if info.Plugin.shutdown || info.Plugin.dying then ( + debug "Domain %u died (dying=3D%b, shutdown %b -- code %d)" id + info.Plugin.dying info.Plugin.shutdown info.Plugin.shutdown_= code; + if info.Plugin.dying then dead_dom :=3D id :: !dead_dom else n= otify :=3D true) + with Plugin.Error _ -> + debug "Domain %u died -- no domain info" id; + dead_dom :=3D id :: !dead_dom)) + doms.table; + List.iter + (fun id -> let dom =3D 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/path= s.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 =3D "@XEN_LOG_DIR@" let xen_config_dir =3D "@XEN_CONFIG_DIR@" let xen_run_dir =3D "@XEN_RUN_DIR@" let xen_run_stored =3D "@XEN_RUN_STORED@" +let xen_ctrl_plugin =3D "@XEN_CTRL_DOMAININFO_PLUGIN@" --=20 2.39.2