From nobody Wed Dec 4 19:02:12 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 --- 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