From nobody Fri Mar 29 14:44:08 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1557932909; cv=none; d=zoho.com; s=zohoarc; b=llputS3tRwcnjKlRIE/B8iKoig/9T/G1EXPnqW/Q5ZoDdO+BjAMiOW8FrmrOxeDHLnAJqIOCdh99vW2jD5cIOCwPlFODcSmk4L92063sgnOjN52sOLdH2c4cecB9HwxRNp5icTKahX2gFjcsCFjNCB6I03hVGoynAln3Wr9qEi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557932909; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=m1WIc14SZMd4y9Ox8RGsoSLynXrzQZpLSgArWy6gHEw=; b=No9yxMJOQSXq3MYJ8J7hJnitP56RIHS0S9rnBFlJ9QKJasznrOpmx+xfq68dUXDgDCth896pzKOgIJ7CKdebrLSiTz8ndMlSjuL+YTDCqVPncDgXZz+Hx0fpkyNVcGnkJq/+Lj+hiawepFcNgaGJNZdU0y/UxwoX/RkXXX8i+jE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1557932908376934.4007005717634; Wed, 15 May 2019 08:08:28 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQvUW-0004Wm-NU; Wed, 15 May 2019 15:06:48 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQvUT-0004Wh-PB for xen-devel@lists.xenproject.org; Wed, 15 May 2019 15:06:46 +0000 Received: from mo6-p00-ob.smtp.rzone.de (unknown [2a01:238:20a:202:5300::5]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 0c3a383b-7723-11e9-8980-bc764e045a96; Wed, 15 May 2019 15:06:43 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 44.20 DYNA|AUTH) with ESMTPSA id U080cav4FF6aBIk (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Wed, 15 May 2019 17:06:36 +0200 (CEST) X-Inumbo-ID: 0c3a383b-7723-11e9-8980-bc764e045a96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1557932802; s=strato-dkim-0002; d=aepfle.de; h=Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=EI2sv9uL8hwDaaKTspU7HU5tpMumzFYKjCTIIbhN4ws=; b=VeS8TYTQmMTNnroYs6wz7C3NcIyPU7eEpBUC8v62HbOILBGciU1mnWPaR9U4t7nNK9 pQ0A++82Dmj9HVUtfL9EAKgY1Dzko7LOpHRzab1ESr4tawsuCih7vYUcZ87ptlGJ7F7r Xa/v7uNrcatog5z0q3qfFIKuEWHl4iGLBLI/NJ0hI9UuMcZSJyS/23Kwf5NhUyFao9gk SsKTraa2+IPrnMzGm0rMX9Xq/o/qpl/Up2lUOG+fGoAMu4A3IDrvt2QRO9XL+qvYn0YF iW6VDBnAfd/Ilpt6rR30frt5lp4WaoxlnU5jr5bcTxv6KN7QXtSXRZQKFU1bDK+6iEPU FkMQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3GpFjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Date: Wed, 15 May 2019 17:06:32 +0200 Message-Id: <20190515150632.16269-1-olaf@aepfle.de> X-Mailer: git-send-email 2.16.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v1] hotplug/Linux: fix starting of xenstored with systemd X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Olaf Hering , Ian Jackson Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) A hard to trigger race with another unrelated systemd service and xenstored.service unveiled a bug in the way how xenstored is launched with systemd. launch-xenstore may start either a daemon or a domain. In case a domain is used, systemd-notify was called. If another service triggered a restart of systemd while xenstored.service was executed, systemd may temporary lose track of services with Type=3Dnotify. As a result, xenstored.service would be marked as failed and units that depend on it will not be started anymore. This breaks the enire Xen toolstack. Currently the decision which variant of xenstore should be used is controlled via /etc/sysconfig/xencommons:XENSTORETYPE=3D[domain|daemon]. This change preserves this functionality for the sysv and systemd. One way to fix it is to handle the domain case as Type=3Doneshot because there is nothing to monitor for systemd. The daemon case has to be handled as Type=3Dsimple, which is the default if no Type=3D is specified. A single unit can have just one type, so a new unit for the daemon case has to be created to preserve existing setups during upgrading of Xen. This new xenstored-daemon.service is started on demand by the existing xenstored.service. Since it is a separate unit, systemd will supervise the xenstored daemon in dom0. launch-xenstore expects now two arguments, the type of the init system, and the optional xenstore type. The systemd-notify calls are removed because systemd does not expect any notification with the updated .service files. In case the init system is systemd the daemon or init-xenstore-domain is started via exec to make sure systemd monitors the process it has just launched. Various things specific to either sysv or systemd are now handled separately. The start of xenstored-daemon.service in launch-xenstore will essentially call this helper twice. A separate internal state is introduced to deal with this. This is required to handle the xencommons case explained above. A followup change will remove the code which calls to sd_notify, they are not needed after the separation of Type=3Doneshot for domain and Type=3Dsimple for daemon. Signed-off-by: Olaf Hering --- Tested with systemd on SLE15. sysv case untested because support for SLE11 was dropped a while ago. tools/configure | 3 +- tools/configure.ac | 1 + tools/hotplug/Linux/init.d/xencommons.in | 2 +- tools/hotplug/Linux/launch-xenstore.in | 66 +++++++++++++++++-= ---- .../Linux/systemd/xenstored-daemon.service.in | 17 ++++++ tools/hotplug/Linux/systemd/xenstored.service.in | 5 +- 6 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 tools/hotplug/Linux/systemd/xenstored-daemon.service.in diff --git a/tools/configure b/tools/configure index 0be0be75de..2612c11490 100755 --- a/tools/configure +++ b/tools/configure @@ -9761,7 +9761,7 @@ fi =20 if test "x$systemd" =3D "xy"; then : =20 - ac_config_files=3D"$ac_config_files hotplug/Linux/systemd/proc-xen.mou= nt hotplug/Linux/systemd/var-lib-xenstored.mount hotplug/Linux/systemd/xen-= init-dom0.service hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service = hotplug/Linux/systemd/xen-watchdog.service hotplug/Linux/systemd/xenconsole= d.service hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xe= ndriverdomain.service hotplug/Linux/systemd/xenstored.service" + ac_config_files=3D"$ac_config_files hotplug/Linux/systemd/proc-xen.mou= nt hotplug/Linux/systemd/var-lib-xenstored.mount hotplug/Linux/systemd/xen-= init-dom0.service hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service = hotplug/Linux/systemd/xen-watchdog.service hotplug/Linux/systemd/xenconsole= d.service hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xe= ndriverdomain.service hotplug/Linux/systemd/xenstored.service hotplug/Linux= /systemd/xenstored-daemon.service" =20 =20 fi @@ -10516,6 +10516,7 @@ do "hotplug/Linux/systemd/xendomains.service") CONFIG_FILES=3D"$CONFIG_FI= LES hotplug/Linux/systemd/xendomains.service" ;; "hotplug/Linux/systemd/xendriverdomain.service") CONFIG_FILES=3D"$CONF= IG_FILES hotplug/Linux/systemd/xendriverdomain.service" ;; "hotplug/Linux/systemd/xenstored.service") CONFIG_FILES=3D"$CONFIG_FIL= ES hotplug/Linux/systemd/xenstored.service" ;; + "hotplug/Linux/systemd/xenstored-daemon.service") CONFIG_FILES=3D"$CON= FIG_FILES hotplug/Linux/systemd/xenstored-daemon.service" ;; =20 *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac diff --git a/tools/configure.ac b/tools/configure.ac index fcf282e74e..c61a327d73 100644 --- a/tools/configure.ac +++ b/tools/configure.ac @@ -481,6 +481,7 @@ AS_IF([test "x$systemd" =3D "xy"], [ hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xenstored.service + hotplug/Linux/systemd/xenstored-daemon.service ]) ]) =20 diff --git a/tools/hotplug/Linux/init.d/xencommons.in b/tools/hotplug/Linux= /init.d/xencommons.in index 7fd6903b98..e5a91350a2 100644 --- a/tools/hotplug/Linux/init.d/xencommons.in +++ b/tools/hotplug/Linux/init.d/xencommons.in @@ -60,7 +60,7 @@ do_start () { mkdir -m700 -p ${XEN_LOCK_DIR} mkdir -p ${XEN_LOG_DIR} =20 - @XEN_SCRIPT_DIR@/launch-xenstore || exit 1 + @XEN_SCRIPT_DIR@/launch-xenstore 'sysv' "${XENSTORETYPE}" || exit 1 =20 echo Setting domain 0 name, domid and JSON config... ${LIBEXEC_BIN}/xen-init-dom0 ${XEN_DOM0_UUID} diff --git a/tools/hotplug/Linux/launch-xenstore.in b/tools/hotplug/Linux/l= aunch-xenstore.in index 991dec8d25..e97e339481 100644 --- a/tools/hotplug/Linux/launch-xenstore.in +++ b/tools/hotplug/Linux/launch-xenstore.in @@ -15,6 +15,26 @@ # License along with this library; If not, see . # =20 +initd=3D$1 +xenstore_type=3D$2 +maybe_exec=3D + +case "$initd" in + sysv) ;; + systemd) maybe_exec=3D'exec' ;; + *) + echo "first argument must be 'sysv' or 'systemd'" + exit 1 + ;; +esac +case "$xenstore_type" in + ""|daemon|domain|supervised-by-systemd) ;; + *) + echo "second argument must be one of 'daemon', 'domain', 'supervised-by-= systemd', or empty" + exit 1 + ;; +esac + XENSTORED=3D@XENSTORED@ =20 . @XEN_SCRIPT_DIR@/hotplugpath.sh @@ -44,15 +64,7 @@ timeout_xenstore () { return 0 } =20 -test_xenstore && exit 0 - -test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @CONFIG_DIR@/@CONFI= G_LEAF_DIR@/xencommons - -[ "$XENSTORETYPE" =3D "" ] && XENSTORETYPE=3Ddaemon - -/bin/mkdir -p @XEN_RUN_DIR@ - -[ "$XENSTORETYPE" =3D "daemon" ] && { +run_xenstored () { [ -z "$XENSTORED_ROOTDIR" ] && XENSTORED_ROOTDIR=3D"@XEN_LIB_STORED@" [ -z "$XENSTORED_TRACE" ] || XENSTORED_ARGS=3D"$XENSTORED_ARGS -T @XEN_LO= G_DIR@/xenstored-trace.log" [ -z "$XENSTORED" ] && XENSTORED=3D@XENSTORED@ @@ -61,15 +73,40 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . = @CONFIG_DIR@/@CONFIG_LEAF exit 1 } =20 - echo -n Starting $XENSTORED... - $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS + ${maybe_exec} $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORE= D_ARGS +} + +if test "$initd" =3D 'sysv' ; then + test_xenstore && exit 0 +fi =20 - systemd-notify --booted 2>/dev/null || timeout_xenstore $XENSTORED || exi= t 1 +test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @CONFIG_DIR@/@CONFI= G_LEAF_DIR@/xencommons + +[ "$XENSTORETYPE" =3D "" ] && XENSTORETYPE=3Ddaemon +[ "$xenstore_type" =3D "" ] && xenstore_type=3D"$XENSTORETYPE" + +/bin/mkdir -p @XEN_RUN_DIR@ + +[ "$xenstore_type" =3D "supervised-by-systemd" ] && { + XENSTORED_ARGS=3D"$XENSTORED_ARGS -N" + run_xenstored + exit 1 +} + +[ "$xenstore_type" =3D "daemon" ] && { + + if test "$initd" =3D 'sysv' ; then + echo -n Starting $XENSTORED... + run_xenstored + timeout_xenstore $XENSTORED || exit 1 + else + systemctl start xenstored-daemon.service + fi =20 exit 0 } =20 -[ "$XENSTORETYPE" =3D "domain" ] && { +[ "$xenstore_type" =3D "domain" ] && { [ -z "$XENSTORE_DOMAIN_KERNEL" ] && XENSTORE_DOMAIN_KERNEL=3D@LIBEXEC@/bo= ot/xenstore-stubdom.gz XENSTORE_DOMAIN_ARGS=3D"$XENSTORE_DOMAIN_ARGS --kernel $XENSTORE_DOMAIN_K= ERNEL" [ -z "$XENSTORE_DOMAIN_SIZE" ] && XENSTORE_DOMAIN_SIZE=3D8 @@ -77,8 +114,7 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @= CONFIG_DIR@/@CONFIG_LEAF [ -z "$XENSTORE_MAX_DOMAIN_SIZE" ] || XENSTORE_DOMAIN_ARGS=3D"$XENSTORE_D= OMAIN_ARGS --maxmem $XENSTORE_MAX_DOMAIN_SIZE" =20 echo -n Starting $XENSTORE_DOMAIN_KERNEL... - ${LIBEXEC_BIN}/init-xenstore-domain $XENSTORE_DOMAIN_ARGS || exit 1 - systemd-notify --ready 2>/dev/null + ${maybe_exec} ${LIBEXEC_BIN}/init-xenstore-domain $XENSTORE_DOMAIN_ARGS |= | exit 1 =20 exit 0 } diff --git a/tools/hotplug/Linux/systemd/xenstored-daemon.service.in b/tool= s/hotplug/Linux/systemd/xenstored-daemon.service.in new file mode 100644 index 0000000000..5158df304b --- /dev/null +++ b/tools/hotplug/Linux/systemd/xenstored-daemon.service.in @@ -0,0 +1,17 @@ +[Unit] +Description=3DThe xenstore daemon in dom0 +Requires=3Dproc-xen.mount var-lib-xenstored.mount +After=3Dproc-xen.mount var-lib-xenstored.mount +Before=3Dlibvirtd.service libvirt-guests.service +RefuseManualStop=3Dtrue +ConditionPathExists=3D/proc/xen/capabilities + +[Service] +PIDFile=3D@XEN_RUN_DIR@/xenstored.pid +ExecStartPre=3D/bin/grep -q control_d /proc/xen/capabilities +ExecStart=3D@XEN_SCRIPT_DIR@/launch-xenstore 'systemd' 'supervised-by-syst= emd' + +[Install] +WantedBy=3Dmulti-user.target +Also=3Dproc-xen.mount +Also=3Dvar-lib-xenstored.mount diff --git a/tools/hotplug/Linux/systemd/xenstored.service.in b/tools/hotpl= ug/Linux/systemd/xenstored.service.in index 80c1d408a5..268e33399b 100644 --- a/tools/hotplug/Linux/systemd/xenstored.service.in +++ b/tools/hotplug/Linux/systemd/xenstored.service.in @@ -7,11 +7,10 @@ RefuseManualStop=3Dtrue ConditionPathExists=3D/proc/xen/capabilities =20 [Service] -Type=3Dnotify -NotifyAccess=3Dall +Type=3Doneshot RemainAfterExit=3Dtrue ExecStartPre=3D/bin/grep -q control_d /proc/xen/capabilities -ExecStart=3D@XEN_SCRIPT_DIR@/launch-xenstore +ExecStart=3D@XEN_SCRIPT_DIR@/launch-xenstore 'systemd' '' =20 [Install] WantedBy=3Dmulti-user.target _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel