From nobody Sat Apr 20 01:22:09 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=1558087093; cv=none; d=zoho.com; s=zohoarc; b=Ugjq7HLHhi8cMwBaLmXg3SXEZOGZOMckcF17uRn2Fm5els+wbv1xgCj/P9Q9V30W3XH2VNPCUrU1SqaKRJDU04rMSQYBRQzM1NrYXBPDw95zM0CA1jXjcD/OHwY6LstFWressthQtF+RmiVmy8xIazTGEEH4KGTRBrbuMpgbkw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558087093; 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=io41DvelKUNxDVbjh+jENNiPY3e6epps8H/oQlnXYEM=; b=IkZP4sQFsfj86R7+d6vkPbXQqlLVd7ahJ1A/zrX8Xw9bUVmrsGIGerMWCE6vuvbTxTnJgsQdW2JgYj4bmCALFIwrHE/mzz0yAUEsVS640KRkY+8Bm4pfj8zA1UVFk3pvZB9nh7MgtVXfdbPr2A/yd69DRu/iJzyfrPNPzH7Dfhk= 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 1558087091949421.4198376212713; Fri, 17 May 2019 02:58:11 -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 1hRZbT-0000eS-6F; Fri, 17 May 2019 09:56:39 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hRZbQ-0000eN-U1 for xen-devel@lists.xenproject.org; Fri, 17 May 2019 09:56:37 +0000 Received: from mo6-p00-ob.smtp.rzone.de (unknown [2a01:238:20a:202:5300::6]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 0d698c03-788a-11e9-8980-bc764e045a96; Fri, 17 May 2019 09:56:34 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 44.20 SBL|AUTH) with ESMTPSA id U080cav4H9uPIkq (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); Fri, 17 May 2019 11:56:25 +0200 (CEST) X-Inumbo-ID: 0d698c03-788a-11e9-8980-bc764e045a96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1558086993; 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=YxlvULY7Wix7R2tard+3IAarBDAuSqcninP/b4W1dYs=; b=B8ncoP1SSbVDpEdL9rLqDS8eDnjD9Ik5EN9lHBkm2tCzzmLm0wsFB/xX9+1f5lsgKj 3da81BQoDJ0nQYDdp9gSN5ZXeH1YcIGWpWXYdmynU2uHRhUyTCgk3KECfCEU5sJGhn4w udFvHzHxYhVl4bRM7Yd2RzDT3DdULWTuO7CqdTMQHrntOS6JcBa9LLpK4gQsOntwGzyX k4eo3yLthkK2Yb0t71vJj8Ck5NqY9806EGHgKFSMx+9cybGTuRz65v9/HqXgPB5lv+uB bktrjVe2A1RfHLttCesJJAX0/FBHzgJuq7dz489RTqgXBM72r+VSpmwvMm5R8kf654bU /uCg== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3GlOjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Date: Fri, 17 May 2019 11:56:21 +0200 Message-Id: <20190517095621.24271-1-olaf@aepfle.de> X-Mailer: git-send-email 2.16.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] hotplug/Linux: fix starting of xenstored with restarting 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. The chain of events is basically: xenstored.service sends the notification to systemd, this is a one-way event. Then systemd may be restarted by the other unit. During this time xenstored.service is done and exits. Once systemd is done with its restart it collects the pending notifications and childs. If it does not find the unit which sent the notification it will declare it as failed. A workaround for this scenario is to wait for a short time after sending to notification. If systemd happens to restart it will still find the unit it launched. Adjust the callers of launch-xenstore to specifiy the init system. Do not fork xenstored with systemd, preserve pid. Be verbose about xenstored startup only with sysv to avoid interleaved output in systemd journal. Do the same also for domain case, even if is not strictly needed because init-xenstore-domain has no output. The fix for upstream systemd which is supposed to fix it: 575b300b795b6 ("pid1: rework how we dispatch SIGCHLD and other signals") v02: - preserve Type=3Dnotify Signed-off-by: Olaf Hering --- tools/hotplug/Linux/init.d/xencommons.in | 2 +- tools/hotplug/Linux/launch-xenstore.in | 56 ++++++++++++++++++--= ---- tools/hotplug/Linux/systemd/xenstored.service.in | 2 +- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/tools/hotplug/Linux/init.d/xencommons.in b/tools/hotplug/Linux= /init.d/xencommons.in index 7fd6903b98..dcb0ce4b73 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' || 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..8ff243670d 100644 --- a/tools/hotplug/Linux/launch-xenstore.in +++ b/tools/hotplug/Linux/launch-xenstore.in @@ -15,6 +15,16 @@ # License along with this library; If not, see . # =20 +initd=3D$1 + +case "$initd" in + sysv|systemd) ;; + *) + echo "first argument must be 'sysv' or 'systemd'" + exit 1 + ;; +esac + XENSTORED=3D@XENSTORED@ =20 . @XEN_SCRIPT_DIR@/hotplugpath.sh @@ -44,15 +54,9 @@ 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 +run_xenstored () { + local maybe_exec=3D$1 =20 -/bin/mkdir -p @XEN_RUN_DIR@ - -[ "$XENSTORETYPE" =3D "daemon" ] && { [ -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@ @@ -60,13 +64,30 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . = @CONFIG_DIR@/@CONFIG_LEAF echo "No xenstored found" exit 1 } + $maybe_exec $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_= ARGS +} =20 - echo -n Starting $XENSTORED... - $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_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 =20 - exit 0 +[ "$XENSTORETYPE" =3D "" ] && XENSTORETYPE=3Ddaemon + +/bin/mkdir -p @XEN_RUN_DIR@ + +[ "$XENSTORETYPE" =3D "daemon" ] && { + if test "$initd" =3D 'sysv' ; then + echo -n Starting $XENSTORED... + run_xenstored '' + timeout_xenstore $XENSTORED || exit 1 + exit 0 + else + XENSTORED_ARGS=3D"$XENSTORED_ARGS -N" + run_xenstored 'exec' + exit 1 + fi } =20 [ "$XENSTORETYPE" =3D "domain" ] && { @@ -76,9 +97,16 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @= CONFIG_DIR@/@CONFIG_LEAF XENSTORE_DOMAIN_ARGS=3D"$XENSTORE_DOMAIN_ARGS --memory $XENSTORE_DOMAIN_S= IZE" [ -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... + if test "$initd" =3D 'sysv' ; then + echo -n Starting $XENSTORE_DOMAIN_KERNEL... + else + echo Starting $XENSTORE_DOMAIN_KERNEL... + fi ${LIBEXEC_BIN}/init-xenstore-domain $XENSTORE_DOMAIN_ARGS || exit 1 - systemd-notify --ready 2>/dev/null + if test "$initd" =3D 'systemd' ; then + systemd-notify --ready + sleep 9 + fi =20 exit 0 } diff --git a/tools/hotplug/Linux/systemd/xenstored.service.in b/tools/hotpl= ug/Linux/systemd/xenstored.service.in index 80c1d408a5..c226eb3635 100644 --- a/tools/hotplug/Linux/systemd/xenstored.service.in +++ b/tools/hotplug/Linux/systemd/xenstored.service.in @@ -11,7 +11,7 @@ Type=3Dnotify NotifyAccess=3Dall 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