From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667316559; cv=none; d=zohomail.com; s=zohoarc; b=K3M8bwlWQyIIwD5KuqCL7Eyd2jXEp2FCC/pCq3wrcRSRg3Vzo9mfokiwOHwJ3OmvXXQhQBdhtKq6ncVvML7mTJzR/Q52tC7UKqDy0Jd8G52MRm2IK7Pb1OEIUhadmvZ0zqoiP5gTqGxF4FNNIK0xaEhSMFF7kJ5B9AbgUqvq7UY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667316559; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2kCPlZkMn4lMbWZL1TxCM0JXd1CkVTaMTWMc1Tu0JRs=; b=DXOCxeV8TTc+Ik0mIZLNXUjJ2vHT2AxXDsungSXupi3xM9pUSPbVw1fMu1NSIQr7X24znbP5zUt25phU3DOx/moeBvbULp0vUSkVIqsrv74oH+T7S8KRryJm1e7SAbOQ/DUdsn1L9953MVEPfcmEMENhqtlaIzfdJ9vLv85HFrk= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 166731655909868.46415333037248; Tue, 1 Nov 2022 08:29:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434829.687457 (Exim 4.92) (envelope-from ) id 1optCB-0007Uk-82; Tue, 01 Nov 2022 15:28:55 +0000 Received: by outflank-mailman (output) from mailman id 434829.687457; Tue, 01 Nov 2022 15:28:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optCB-0007Ud-33; Tue, 01 Nov 2022 15:28:55 +0000 Received: by outflank-mailman (input) for mailman id 434829; Tue, 01 Nov 2022 15:28:53 +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 1optC9-0007Tl-Pn for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:28:53 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e3924cde-59f9-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:28:52 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B778C1F8E3; Tue, 1 Nov 2022 15:28:51 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 882431346F; Tue, 1 Nov 2022 15:28:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HBTaHzM7YWOBYAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:28:51 +0000 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: e3924cde-59f9-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316531; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2kCPlZkMn4lMbWZL1TxCM0JXd1CkVTaMTWMc1Tu0JRs=; b=UhkOmD9eqKepd1DwAGoQnmkF54esO2ORp7c5GTlAIM5iUH+zcY9MWpgGafI54QEl8nmjv5 NMjJqRr3JPo8y4AhoZjG1pmBTBmf+OXP0tKOQrfriHwS19OdzjvE4WUYBYH8RTG0htlbkY L8o20/0kxNP8peDj3efPqVmq6PpqTLo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Julien Grall Subject: [PATCH 01/20] tools/xenstore: remove XEN_LIB_STORED and XENSTORED_ROOTDIR Date: Tue, 1 Nov 2022 16:28:23 +0100 Message-Id: <20221101152842.4257-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667316561707100001 Content-Type: text/plain; charset="utf-8" XEN_LIB_STORED is serving no real purpose, as it is a mount point for a tmpfs, so it can be replaced easily by XEN_RUN_STORED. XENSTORED_ROOTDIR is basically unused already, there is just a single reference in xs_daemon_rootdir() with a fallback to XEN_LIB_STORED, and a .gdbinit file setting it. Remove the .gdbinit file, as it is not known having been used since ages, and make xs_daemon_rootdir() an alias of xs_daemon_rundir(). Signed-off-by: Juergen Gross Acked-by: Andrew Cooper Reported-by: Andrew Cooper --- config/Paths.mk.in | 1 - configure | 4 ---- docs/configure | 4 ---- m4/paths.m4 | 3 --- tools/configure | 7 +------ tools/configure.ac | 1 - tools/hotplug/FreeBSD/rc.d/xencommons.in | 6 ------ tools/hotplug/Linux/systemd/Makefile | 1 - .../hotplug/Linux/systemd/var-lib-xenstored.mount.in | 12 ------------ tools/libs/store/Makefile | 1 - tools/xenstore/.gdbinit | 4 ---- tools/xenstore/Makefile | 4 ---- tools/xenstore/Makefile.common | 1 - tools/xenstore/xs_lib.c | 11 +++++------ 14 files changed, 6 insertions(+), 54 deletions(-) delete mode 100644 tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in delete mode 100644 tools/xenstore/.gdbinit diff --git a/config/Paths.mk.in b/config/Paths.mk.in index 416fc7aab9..44bab1d748 100644 --- a/config/Paths.mk.in +++ b/config/Paths.mk.in @@ -41,7 +41,6 @@ MAN8DIR :=3D $(mandir)/man8 XEN_RUN_DIR :=3D @XEN_RUN_DIR@ XEN_LOG_DIR :=3D @XEN_LOG_DIR@ XEN_LIB_DIR :=3D @XEN_LIB_DIR@ -XEN_LIB_STORED :=3D @XEN_LIB_STORED@ XEN_RUN_STORED :=3D @XEN_RUN_STORED@ =20 CONFIG_DIR :=3D @CONFIG_DIR@ diff --git a/configure b/configure index bb7f27ddad..b51174f2ef 100755 --- a/configure +++ b/configure @@ -603,7 +603,6 @@ INITD_DIR SHAREDIR XEN_LIB_DIR XEN_RUN_STORED -XEN_LIB_STORED XEN_LOG_DIR XEN_RUN_DIR XENFIRMWAREDIR @@ -2081,9 +2080,6 @@ cat >>confdefs.h <<_ACEOF _ACEOF =20 =20 -XEN_LIB_STORED=3D$localstatedir/lib/xenstored - - XEN_RUN_STORED=3D$rundir_path/xenstored =20 =20 diff --git a/docs/configure b/docs/configure index d4fced9858..f008ca0565 100755 --- a/docs/configure +++ b/docs/configure @@ -601,7 +601,6 @@ INITD_DIR SHAREDIR XEN_LIB_DIR XEN_RUN_STORED -XEN_LIB_STORED XEN_LOG_DIR XEN_RUN_DIR XENFIRMWAREDIR @@ -1984,9 +1983,6 @@ cat >>confdefs.h <<_ACEOF _ACEOF =20 =20 -XEN_LIB_STORED=3D$localstatedir/lib/xenstored - - XEN_RUN_STORED=3D$rundir_path/xenstored =20 =20 diff --git a/m4/paths.m4 b/m4/paths.m4 index 826faada45..e4104bcce0 100644 --- a/m4/paths.m4 +++ b/m4/paths.m4 @@ -136,9 +136,6 @@ XEN_LOG_DIR=3D$localstatedir/log/xen AC_SUBST(XEN_LOG_DIR) AC_DEFINE_UNQUOTED([XEN_LOG_DIR], ["$XEN_LOG_DIR"], [Xen's log dir]) =20 -XEN_LIB_STORED=3D$localstatedir/lib/xenstored -AC_SUBST(XEN_LIB_STORED) - XEN_RUN_STORED=3D$rundir_path/xenstored AC_SUBST(XEN_RUN_STORED) =20 diff --git a/tools/configure b/tools/configure index 6199823f5a..ffe3f48901 100755 --- a/tools/configure +++ b/tools/configure @@ -725,7 +725,6 @@ INITD_DIR SHAREDIR XEN_LIB_DIR XEN_RUN_STORED -XEN_LIB_STORED XEN_LOG_DIR XEN_RUN_DIR XENFIRMWAREDIR @@ -4065,9 +4064,6 @@ cat >>confdefs.h <<_ACEOF _ACEOF =20 =20 -XEN_LIB_STORED=3D$localstatedir/lib/xenstored - - XEN_RUN_STORED=3D$rundir_path/xenstored =20 =20 @@ -10085,7 +10081,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/xen-init-dom0.service hotplug/Linux/systemd/xen-qe= mu-dom0-disk-backend.service hotplug/Linux/systemd/xen-watchdog.service hot= plug/Linux/systemd/xenconsoled.service hotplug/Linux/systemd/xendomains.ser= vice hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xe= nstored.service" =20 =20 fi @@ -10967,7 +10963,6 @@ do "ocaml/xenstored/oxenstored.conf") CONFIG_FILES=3D"$CONFIG_FILES ocaml= /xenstored/oxenstored.conf" ;; "config.h") CONFIG_HEADERS=3D"$CONFIG_HEADERS config.h" ;; "hotplug/Linux/systemd/proc-xen.mount") CONFIG_FILES=3D"$CONFIG_FILES = hotplug/Linux/systemd/proc-xen.mount" ;; - "hotplug/Linux/systemd/var-lib-xenstored.mount") CONFIG_FILES=3D"$CONF= IG_FILES hotplug/Linux/systemd/var-lib-xenstored.mount" ;; "hotplug/Linux/systemd/xen-init-dom0.service") CONFIG_FILES=3D"$CONFIG= _FILES hotplug/Linux/systemd/xen-init-dom0.service" ;; "hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service") CONFIG_FIL= ES=3D"$CONFIG_FILES hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.servic= e" ;; "hotplug/Linux/systemd/xen-watchdog.service") CONFIG_FILES=3D"$CONFIG_= FILES hotplug/Linux/systemd/xen-watchdog.service" ;; diff --git a/tools/configure.ac b/tools/configure.ac index 18e481d77e..3a2f6a2da9 100644 --- a/tools/configure.ac +++ b/tools/configure.ac @@ -482,7 +482,6 @@ AX_AVAILABLE_SYSTEMD() AS_IF([test "x$systemd" =3D "xy"], [ AC_CONFIG_FILES([ hotplug/Linux/systemd/proc-xen.mount - 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 diff --git a/tools/hotplug/FreeBSD/rc.d/xencommons.in b/tools/hotplug/FreeB= SD/rc.d/xencommons.in index fddcce314c..7f7cda289f 100644 --- a/tools/hotplug/FreeBSD/rc.d/xencommons.in +++ b/tools/hotplug/FreeBSD/rc.d/xencommons.in @@ -14,7 +14,6 @@ export LD_LIBRARY_PATH =20 name=3D"xencommons" rcvar=3D"xencommons_enable" -start_precmd=3D"xen_precmd" start_cmd=3D"xen_startcmd" stop_cmd=3D"xen_stop" status_cmd=3D"xen_status" @@ -30,11 +29,6 @@ XENSTORED_PIDFILE=3D"@XEN_RUN_DIR@/xenstored.pid" load_rc_config $name : ${xencommons_enable:=3Dno} =20 -xen_precmd() -{ - mkdir -p @XEN_LIB_STORED@ || exit 1 -} - xen_startcmd() { local time=3D0 diff --git a/tools/hotplug/Linux/systemd/Makefile b/tools/hotplug/Linux/sys= temd/Makefile index 26df2a43b1..e29889156d 100644 --- a/tools/hotplug/Linux/systemd/Makefile +++ b/tools/hotplug/Linux/systemd/Makefile @@ -4,7 +4,6 @@ include $(XEN_ROOT)/tools/Rules.mk XEN_SYSTEMD_MODULES :=3D xen.conf =20 XEN_SYSTEMD_MOUNT :=3D proc-xen.mount -XEN_SYSTEMD_MOUNT +=3D var-lib-xenstored.mount =20 XEN_SYSTEMD_SERVICE :=3D xenstored.service XEN_SYSTEMD_SERVICE +=3D xenconsoled.service diff --git a/tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in b/tools= /hotplug/Linux/systemd/var-lib-xenstored.mount.in deleted file mode 100644 index 11a7d50edc..0000000000 --- a/tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=3Dmount xenstore file system -Requires=3Dproc-xen.mount -After=3Dproc-xen.mount -ConditionPathExists=3D/proc/xen/capabilities -RefuseManualStop=3Dtrue - -[Mount] -What=3Dxenstore -Where=3D@XEN_LIB_STORED@ -Type=3Dtmpfs -Options=3Dmode=3D755 diff --git a/tools/libs/store/Makefile b/tools/libs/store/Makefile index 2334c953bb..3557a8c76d 100644 --- a/tools/libs/store/Makefile +++ b/tools/libs/store/Makefile @@ -18,7 +18,6 @@ include ../libs.mk # Include configure output (config.h) CFLAGS +=3D -include $(XEN_ROOT)/tools/config.h CFLAGS +=3D $(CFLAGS_libxentoolcore) -CFLAGS +=3D -DXEN_LIB_STORED=3D"\"$(XEN_LIB_STORED)\"" CFLAGS +=3D -DXEN_RUN_STORED=3D"\"$(XEN_RUN_STORED)\"" =20 vpath xs_lib.c $(XEN_ROOT)/tools/xenstore diff --git a/tools/xenstore/.gdbinit b/tools/xenstore/.gdbinit deleted file mode 100644 index 9a71b20ac4..0000000000 --- a/tools/xenstore/.gdbinit +++ /dev/null @@ -1,4 +0,0 @@ -set environment XENSTORED_RUNDIR=3Dtestsuite/tmp -set environment XENSTORED_ROOTDIR=3Dtestsuite/tmp -handle SIGUSR1 noprint nostop -handle SIGPIPE noprint nostop diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile index 1b66190cc5..ce7a68178f 100644 --- a/tools/xenstore/Makefile +++ b/tools/xenstore/Makefile @@ -69,7 +69,6 @@ install: all $(INSTALL_DIR) $(DESTDIR)$(bindir) ifeq ($(XENSTORE_XENSTORED),y) $(INSTALL_DIR) $(DESTDIR)$(sbindir) - $(INSTALL_DIR) $(DESTDIR)$(XEN_LIB_STORED) $(INSTALL_PROG) xenstored $(DESTDIR)$(sbindir) endif $(INSTALL_PROG) xenstore-control $(DESTDIR)$(bindir) @@ -85,9 +84,6 @@ uninstall: rm -f $(DESTDIR)$(bindir)/xenstore-control ifeq ($(XENSTORE_XENSTORED),y) rm -f $(DESTDIR)$(sbindir)/xenstored - if [ -d $(DESTDIR)$(XEN_LIB_STORED) ]; then \ - rmdir --ignore-fail-on-non-empty $(DESTDIR)$(XEN_LIB_STORED); \ - fi endif if [ -d $(DESTDIR)$(includedir)/xenstore-compat ]; then \ rmdir --ignore-fail-on-non-empty $(DESTDIR)$(includedir)/xenstore-compat= ; \ diff --git a/tools/xenstore/Makefile.common b/tools/xenstore/Makefile.common index ddbac052ac..b18f95c103 100644 --- a/tools/xenstore/Makefile.common +++ b/tools/xenstore/Makefile.common @@ -16,7 +16,6 @@ CFLAGS +=3D $(CFLAGS_libxenevtchn) CFLAGS +=3D $(CFLAGS_libxenctrl) CFLAGS +=3D $(CFLAGS_libxenguest) CFLAGS +=3D $(CFLAGS_libxentoolcore) -CFLAGS +=3D -DXEN_LIB_STORED=3D"\"$(XEN_LIB_STORED)\"" CFLAGS +=3D -DXEN_RUN_STORED=3D"\"$(XEN_RUN_STORED)\"" =20 ifdef CONFIG_STUBDOM diff --git a/tools/xenstore/xs_lib.c b/tools/xenstore/xs_lib.c index 10fa4c3ad0..b9941c567c 100644 --- a/tools/xenstore/xs_lib.c +++ b/tools/xenstore/xs_lib.c @@ -26,18 +26,17 @@ =20 /* Common routines for the Xen store daemon and client library. */ =20 -const char *xs_daemon_rootdir(void) -{ - char *s =3D getenv("XENSTORED_ROOTDIR"); - return (s ? s : XEN_LIB_STORED); -} - const char *xs_daemon_rundir(void) { char *s =3D getenv("XENSTORED_RUNDIR"); return (s ? s : XEN_RUN_STORED); } =20 +const char *xs_daemon_rootdir(void) +{ + return xs_daemon_rundir(); +} + static const char *xs_daemon_path(void) { static char buf[PATH_MAX]; --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667316567; cv=none; d=zohomail.com; s=zohoarc; b=knJZz+37yLoktAAJ7IAxMzRueDMSqTAAY4LxjQ4oWJXsmqcDL+NoQkNTS7PoAmOdTTpw5XNlFSBjfC0CuhfLrnIQPVKm1i1MvQLF73fWc+P+Tw0jJ39eMOcIE+xJqsvGcVB+XpJrBHP+DL/LW8eDHIapAMQkRTNYMDAr7Qk4PYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667316567; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wnyre0lY6vh0o8N40Ag5noXJoA9j7rscMFp/jnaPIq8=; b=S38i7CEDZ6tJgXi58cCD8cdDn2C2t4ZB5FuopHuI4msbclZCAgVz3O3U2CkohVeF6xbv+zNlumB/RUg2X+0WIFqLvIx65p66vRjcsa9cJI5bT7VyXxDbfUKhK2ETJhg2WasQPL+C3VpBKgbnULUKg6iNrLA1u8RjJL0g4wSR/L4= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667316567716542.0041721648626; Tue, 1 Nov 2022 08:29:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434830.687468 (Exim 4.92) (envelope-from ) id 1optCG-0007ou-G3; Tue, 01 Nov 2022 15:29:00 +0000 Received: by outflank-mailman (output) from mailman id 434830.687468; Tue, 01 Nov 2022 15:29:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optCG-0007oc-Cs; Tue, 01 Nov 2022 15:29:00 +0000 Received: by outflank-mailman (input) for mailman id 434830; Tue, 01 Nov 2022 15:28:58 +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 1optCE-0007Tl-Fg for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:28:58 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e6ee5cff-59f9-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:28:57 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6151F2256A; Tue, 1 Nov 2022 15:28:57 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 312DD1346F; Tue, 1 Nov 2022 15:28:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ycfICTk7YWOJYAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:28:57 +0000 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: e6ee5cff-59f9-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316537; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wnyre0lY6vh0o8N40Ag5noXJoA9j7rscMFp/jnaPIq8=; b=Zn1xF+Ym/ToL4Sea/vmyDRyR+YP9a0QGM/fOrIlRVDmhnWgjY67i9mtfxFj+fd6smJpMfC dB3+Hf2D27zHF24nuIjT/U7cH1kDHYB1SykNnHSFKuvibo1HnoNn504Bdgdo+L9ekqltmu 8A0EqqpmOYtjJ6oRGv3Q+TCaPMIcrUU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH 02/20] tools/xenstore: call remove_domid_from_perm() for special nodes Date: Tue, 1 Nov 2022 16:28:24 +0100 Message-Id: <20221101152842.4257-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667316569248100005 Content-Type: text/plain; charset="utf-8" When destroying a domain, any stale permissions of the domain must be removed from the special nodes "@...", too. This was not done in the fix for XSA-322. Fixes: 496306324d8d ("tools/xenstore: revoke access rights for removed doma= ins") Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/xenstored_domain.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 84b7817cd5..aa86892fed 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -227,6 +227,27 @@ static void unmap_interface(void *interface) xengnttab_unmap(*xgt_handle, interface, 1); } =20 +static void remove_domid_from_perm(struct node_perms *perms, + struct domain *domain) +{ + unsigned int cur, new; + + if (perms->p[0].id =3D=3D domain->domid) + perms->p[0].id =3D priv_domid; + + for (cur =3D new =3D 1; cur < perms->num; cur++) { + if (perms->p[cur].id =3D=3D domain->domid) + continue; + + if (new !=3D cur) + perms->p[new] =3D perms->p[cur]; + + new++; + } + + perms->num =3D new; +} + static int domain_tree_remove_sub(const void *ctx, struct connection *conn, struct node *node, void *arg) { @@ -277,6 +298,9 @@ static void domain_tree_remove(struct domain *domain) syslog(LOG_ERR, "error when looking for orphaned nodes\n"); } + + remove_domid_from_perm(&dom_release_perms, domain); + remove_domid_from_perm(&dom_introduce_perms, domain); } =20 static int destroy_domain(void *_domain) --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667316569; cv=none; d=zohomail.com; s=zohoarc; b=TM9dgwCKpnywiL/UJIbhccYmtAeFeDX1tpSGrbhEJxefNAQhRPBpdDtjtosxrQZR8nyk4EI4hry3kaa/+1+vVHYjQGKfFuPbD+TGb1U6M3zJ2I84yQGmbZyzUYwLE11kbbg6NJC/jWQWcXlfnYccQhUY8kdw3kI6P+mxTXYGkTQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667316569; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2WmsoGzujtIkC6YuYigP+4ElT2gZKOfCQSt1d9XlPlQ=; b=ZJbA8MloZ10QZScalVYCkNjPeUUO7Flgt9Kb5oesAaWH5+Hee1aQZP2l01b2J0DAEBCymL9nnnxvWk75YXJup/NxLj0KtZ84Yt2I7koKn0IizBx7uMXm5sLbrViPb+n9LRP4WAwY0U5fcAEvlzCaFwPfZCstNj9f6B11Z80iHP8= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667316569489634.2601803092148; Tue, 1 Nov 2022 08:29:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434832.687483 (Exim 4.92) (envelope-from ) id 1optCK-00089v-SV; Tue, 01 Nov 2022 15:29:04 +0000 Received: by outflank-mailman (output) from mailman id 434832.687483; Tue, 01 Nov 2022 15:29:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optCK-00089k-Op; Tue, 01 Nov 2022 15:29:04 +0000 Received: by outflank-mailman (input) for mailman id 434832; Tue, 01 Nov 2022 15:29:04 +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 1optCK-0007Bd-0Q for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:04 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ea41e590-59f9-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 16:29:03 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id EF674336C7; Tue, 1 Nov 2022 15:29:02 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C1D391346F; Tue, 1 Nov 2022 15:29:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id NKPuLT47YWOWYAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:02 +0000 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: ea41e590-59f9-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316542; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2WmsoGzujtIkC6YuYigP+4ElT2gZKOfCQSt1d9XlPlQ=; b=cfwPiTtHeymrVNMf5+4iT9g56NXixGH35F1GILJ1i/A5austDtqWq5FupnFdRKURsnfF3t BfengqzNG3xV8ujPQgjGRVHJOYHjpzHn/NzFk5RAIX36oOde+glQbL8vMPZ0sG3lsVktGE Ck+ub/XCeVK18+c+sK1oIWKS7fo8qtE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 03/20] tools/xenstore: let talloc_free() preserve errno Date: Tue, 1 Nov 2022 16:28:25 +0100 Message-Id: <20221101152842.4257-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667316571307100007 Content-Type: text/plain; charset="utf-8" Today talloc_free() is not guaranteed to preserve errno, especially in case a custom destructor is being used. Change that by renaming talloc_free() to _talloc_free() in talloc.c and adding a wrapper to talloc.c. This allows to remove some errno saving outside of talloc.c. Signed-off-by: Juergen Gross --- tools/xenstore/talloc.c | 25 ++++++++++++++++++------- tools/xenstore/xenstored_core.c | 2 -- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tools/xenstore/talloc.c b/tools/xenstore/talloc.c index d7edcf3a93..5fbefdf091 100644 --- a/tools/xenstore/talloc.c +++ b/tools/xenstore/talloc.c @@ -103,6 +103,8 @@ struct talloc_chunk { unsigned flags; }; =20 +static int _talloc_free(void *ptr); + /* 16 byte alignment seems to keep everyone happy */ #define TC_HDR_SIZE ((sizeof(struct talloc_chunk)+15)&~15) #define TC_PTR_FROM_CHUNK(tc) ((void *)(TC_HDR_SIZE + (char*)tc)) @@ -245,7 +247,7 @@ static int talloc_reference_destructor(void *ptr) tc1->destructor =3D NULL; } _TLIST_REMOVE(tc2->refs, handle); - talloc_free(handle); + _talloc_free(handle); return 0; } =20 @@ -311,7 +313,7 @@ static int talloc_unreference(const void *context, cons= t void *ptr) =20 talloc_set_destructor(h, NULL); _TLIST_REMOVE(tc->refs, h); - talloc_free(h); + _talloc_free(h); return 0; } =20 @@ -349,7 +351,7 @@ int talloc_unlink(const void *context, void *ptr) tc_p =3D talloc_chunk_from_ptr(ptr); =20 if (tc_p->refs =3D=3D NULL) { - return talloc_free(ptr); + return _talloc_free(ptr); } =20 new_p =3D talloc_parent_chunk(tc_p->refs); @@ -521,7 +523,7 @@ static void talloc_free_children(void *ptr) struct talloc_chunk *p =3D talloc_parent_chunk(tc->child->refs); if (p) new_parent =3D TC_PTR_FROM_CHUNK(p); } - if (talloc_free(child) =3D=3D -1) { + if (_talloc_free(child) =3D=3D -1) { if (new_parent =3D=3D null_context) { struct talloc_chunk *p =3D talloc_parent_chunk(ptr); if (p) new_parent =3D TC_PTR_FROM_CHUNK(p); @@ -539,7 +541,7 @@ static void talloc_free_children(void *ptr) will not be freed if the ref_count is > 1 or the destructor (if any) returns non-zero */ -int talloc_free(void *ptr) +static int _talloc_free(void *ptr) { struct talloc_chunk *tc; =20 @@ -597,7 +599,16 @@ int talloc_free(void *ptr) return 0; } =20 +int talloc_free(void *ptr) +{ + int ret; + int saved_errno =3D errno; =20 + ret =3D _talloc_free(ptr); + errno =3D saved_errno; + + return ret; +} =20 /* A talloc version of realloc. The context argument is only used if @@ -610,7 +621,7 @@ void *_talloc_realloc(const void *context, void *ptr, s= ize_t size, const char *n =20 /* size zero is equivalent to free() */ if (size =3D=3D 0) { - talloc_free(ptr); + _talloc_free(ptr); return NULL; } =20 @@ -1243,7 +1254,7 @@ void *talloc_realloc_fn(const void *context, void *pt= r, size_t size) =20 static void talloc_autofree(void) { - talloc_free(cleanup_context); + _talloc_free(cleanup_context); cleanup_context =3D NULL; } =20 diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 476d5c6d51..5a174b9881 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -771,9 +771,7 @@ struct node *read_node(struct connection *conn, const v= oid *ctx, return node; =20 error: - err =3D errno; talloc_free(node); - errno =3D err; return NULL; } =20 --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667316566; cv=none; d=zohomail.com; s=zohoarc; b=mlFN/Ry8yMuCR0G/g6Cb/JubXBTH64Wx5/nxsmACMDjniEqRSHzRJbrqG5JbD+NcVPmU/6TodMSC5LXflsNk5P4nzdXOLnD7M+D+2GAznVg9p1+dj5j98PVcJE3Og9MDvfFILN4xFRqVUiL+QL45yK972o6YZtKUQhhDoxlveXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667316566; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kI1Emp5xZULnpO1cGT8dYHVyoLvYXhzW8MdJFPz/OVo=; b=TgtkqXfePhbIbx853N3kPR8Cjh0s8LYAC1qcpLpIllWO3zUS+kPc8jag9Xldy3v/k8SMrHHzHgNzHW4BwwJLbkrfPxmmnXsgmRIhtr9jYa+n7aqBkk+pqFEHnrcnVMKo6EG5siOXvMY3IsHMKm0KOesUFvCZA+2HiqG0+Lr5N1Q= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667316566959911.035015056401; Tue, 1 Nov 2022 08:29:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434833.687494 (Exim 4.92) (envelope-from ) id 1optCR-00009J-4F; Tue, 01 Nov 2022 15:29:11 +0000 Received: by outflank-mailman (output) from mailman id 434833.687494; Tue, 01 Nov 2022 15:29:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optCR-000094-0j; Tue, 01 Nov 2022 15:29:11 +0000 Received: by outflank-mailman (input) for mailman id 434833; Tue, 01 Nov 2022 15:29:09 +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 1optCP-0007Tl-DS for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:09 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ed91d5d7-59f9-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:29:08 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 818151F8E3; Tue, 1 Nov 2022 15:29:08 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 58D0B1346F; Tue, 1 Nov 2022 15:29:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IcyBFEQ7YWOlYAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:08 +0000 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: ed91d5d7-59f9-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316548; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kI1Emp5xZULnpO1cGT8dYHVyoLvYXhzW8MdJFPz/OVo=; b=f+5YMk/mhCQx9Q20fUu9M/tLuSwPFGVsS8ZSkbQN1Wh2FhBWbY6fnFKbCVLOJfd6Ux6rCG 0URdb6sg6n09kSXpJK2vBV3QLHAjaUquslVDFAaSI2pKnyJ4TnxV9/QOuoG0OhS5dgzw8d NNt0R2+HG5nVWdCQ6NSIF/DT3Daft60= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 04/20] tools/xenstore: let tdb_logger() preserve errno Date: Tue, 1 Nov 2022 16:28:26 +0100 Message-Id: <20221101152842.4257-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667316567247100003 Content-Type: text/plain; charset="utf-8" tdb_logger() is called by TDB for logging errors. As errno is checked often after doing the logging, tdb_logger() should preserve errno. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/xenstored_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 5a174b9881..d48208ecfe 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2345,6 +2345,7 @@ static void tdb_logger(TDB_CONTEXT *tdb, int level, c= onst char * fmt, ...) { va_list ap; char *s; + int saved_errno =3D errno; =20 va_start(ap, fmt); s =3D talloc_vasprintf(NULL, fmt, ap); @@ -2360,6 +2361,8 @@ static void tdb_logger(TDB_CONTEXT *tdb, int level, c= onst char * fmt, ...) trace("talloc failure during logging\n"); syslog(LOG_ERR, "talloc failure during logging\n"); } + + errno =3D saved_errno; } =20 void setup_structure(bool live_update) --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667316574; cv=none; d=zohomail.com; s=zohoarc; b=Vv0MawM6i+Q/ijq73te/owrLWAMvZw6LLIBWwFmn26Mk4Juo/eLZ/N00ONzjTecc4s+ks0sDynPaPazMdL+3kEakfiA0ToVPH+P4uTC4UMFMOoEjZc5Cg5ZNx1rjBoXeWJ5LAFqFdvQOPEv0Sh++CWbsJB5IsXwJRP/HO4dcPj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667316574; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SuvESnVvB2BaByGaIJAGNczPYSTrohyV2ePtAUTn3Zo=; b=gAIStJafh3a2M9dymWG0j/KoId27WU8dAgzr5adWMHD0wpvBu0AevTf9iLdw5z9zWi3q9QBkqPySJXxJD1R5OlEylTGUlwmJxuqvp0hG4YdxEfYPyTQfURm+nD0/84TYhYB0QpXxS+GEN0FdiJuyGnbiGUzHcVAzt8QsN8G0Fp8= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667316574378666.8503991153158; Tue, 1 Nov 2022 08:29:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434835.687509 (Exim 4.92) (envelope-from ) id 1optCW-0000gp-F3; Tue, 01 Nov 2022 15:29:16 +0000 Received: by outflank-mailman (output) from mailman id 434835.687509; Tue, 01 Nov 2022 15:29:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optCW-0000ge-AL; Tue, 01 Nov 2022 15:29:16 +0000 Received: by outflank-mailman (input) for mailman id 434835; Tue, 01 Nov 2022 15:29:15 +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 1optCU-0007Tl-Ul for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:14 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f0e9d469-59f9-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:29:14 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 238181F8E3; Tue, 1 Nov 2022 15:29:14 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E1FD41346F; Tue, 1 Nov 2022 15:29:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6NvLNUk7YWOuYAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:13 +0000 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: f0e9d469-59f9-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316554; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SuvESnVvB2BaByGaIJAGNczPYSTrohyV2ePtAUTn3Zo=; b=r5QuV7JC7wkD4s9mWUzioVvFGyOcQt6tK54cHnqZqJUEHkisMCSL2jMJCVwEf78RCBDYGI 57TyhVRZRE66CLy+U/cvO3/oR1WCLifZj34+TYcXP2GX2Lha7Y+wyW8SeDivHuo4jVimj9 mKKVe5DrQ9JKXAgd6WGdcGBdQxLYrn4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 05/20] tools/xenstore: preserve errno across corrupt() Date: Tue, 1 Nov 2022 16:28:27 +0100 Message-Id: <20221101152842.4257-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667316575365100001 Content-Type: text/plain; charset="utf-8" Let corrupt() preserve errno in order to be able to simplify error handling in future. This is rather easy as the errno value when entering corrupt() is saved already. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/xenstored_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index d48208ecfe..8c2cca62b7 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2549,6 +2549,8 @@ void corrupt(struct connection *conn, const char *fmt= , ...) talloc_free(str); =20 check_store(); + + errno =3D saved_errno; } =20 #ifndef NO_SOCKETS --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667316579; cv=none; d=zohomail.com; s=zohoarc; b=I2Wq0DCymD/l4EgmCaVpkZ77CEoLrE+W+1qn1GyNl1KPRYJ66chHJtTDAX7qzdfZl01NdLhA9qrBlarM5YPsXleiwgvnfo7novwsfzexeYAZcll3WE68RdxaTu0ijybLmrsmD1j7obZdykDNK8dQuO+odYbZVTVT5q2ablSxkfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667316579; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EBpnpvtRtx53neoNfKJ9kBe5E0CVVtJQnxw6pFlViTQ=; b=DtxqxlWRV73EL7qeUXJgu9j4C6fsKQODeI0CbVKiErdrtvCb43ASN4Glbbv5WSJ91no5vyFDUyrAY+4Nru/E18LTmJBVsBLWC2OCDKxI9aHmLEb2rAIb1bTvSaOr7irVU9yeIe4zMKPf5jdye0Mh0kZlhZd/g/fh4RUygAIpWvs= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667316579358252.39818511869805; Tue, 1 Nov 2022 08:29:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434842.687524 (Exim 4.92) (envelope-from ) id 1optCc-0001RH-47; Tue, 01 Nov 2022 15:29:22 +0000 Received: by outflank-mailman (output) from mailman id 434842.687524; Tue, 01 Nov 2022 15:29:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optCb-0001Qc-TB; Tue, 01 Nov 2022 15:29:21 +0000 Received: by outflank-mailman (input) for mailman id 434842; Tue, 01 Nov 2022 15:29:21 +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 1optCb-0007Tl-AO for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:21 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f43d8c1a-59f9-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:29:19 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B133F1F8E3; Tue, 1 Nov 2022 15:29:19 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 849211346F; Tue, 1 Nov 2022 15:29:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4R78Hk87YWO+YAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:19 +0000 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: f43d8c1a-59f9-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316559; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EBpnpvtRtx53neoNfKJ9kBe5E0CVVtJQnxw6pFlViTQ=; b=Ryg26mb5pXdhw1khCYn7z4/27NjZGgmswuPON1qOxmwXcRX/BRryG4vFYnp8VE2FNaCGn3 SBN2aXbQQJFrICf0GUkGjL6TijOAETGDR8pxGd0auGbXfC/AQyX1s1I+PZsF2105saUIlK D0sEVKe4jiVvjo2y2GpJ9Xl2CicbWXQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 06/20] tools/xenstore: remove all watches when a domain has stopped Date: Tue, 1 Nov 2022 16:28:28 +0100 Message-Id: <20221101152842.4257-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667316581381100001 Content-Type: text/plain; charset="utf-8" When a domain has been recognized to have stopped, remove all its registered watches. This avoids sending watch events to the dead domain when all the nodes related to it are being removed by the Xen tools. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_domain.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index aa86892fed..1516df71d8 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -364,6 +364,12 @@ void check_domains(void) && !domain->shutdown) { domain->shutdown =3D true; notify =3D 1; + /* + * Avoid triggering watch events when the + * domain's nodes are being deleted. + */ + if (domain->conn) + conn_delete_all_watches(domain->conn); } if (!dominfo.dying) continue; --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317445; cv=none; d=zohomail.com; s=zohoarc; b=iewB6Mqt2UngSzeLFXt+JM87ZlCO69iuB1QPYtsogf15wPV3aTMzfvDwUrN5YOUoZpba7MF0akC3t540T3bsANm7SqiZZV4bIhOGe02JxhsqR840cEIZtH+fnxg+sowyA0Pt5Sg9m5YiNlH9f2x/hRR5l791bb9k/Er0SWp0ih0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317445; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jhFlAl8E/ZVxI2AuUFyhPfvdnWASnzhuJ0AtRWUI/hQ=; b=gTnpO6d8189UUlYeX/WY5pXqn45NfK7aAf58EWY5SBedb7fP6AB0uskrJ6FokatNGTDxgzMx0DaOiVsbNXvzsBixSf5ocyfnXhGgreyqdimuQLKgZrcJtFsHuUebUtg6mOMu6V9jp4W3rI6EUTRaAVNYr4EvWVTRxB8N7Uhd1+U= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317445299927.0339817420673; Tue, 1 Nov 2022 08:44:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434984.687976 (Exim 4.92) (envelope-from ) id 1optQX-0004qd-3Z; Tue, 01 Nov 2022 15:43:45 +0000 Received: by outflank-mailman (output) from mailman id 434984.687976; Tue, 01 Nov 2022 15:43:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQW-0004o0-Sv; Tue, 01 Nov 2022 15:43:44 +0000 Received: by outflank-mailman (input) for mailman id 434984; Tue, 01 Nov 2022 15:43:43 +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 1optCh-0007Tl-J1 for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:27 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f792a4f8-59f9-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:29:25 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4C0581F8E3; Tue, 1 Nov 2022 15:29:25 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 201DC1346F; Tue, 1 Nov 2022 15:29:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5smIBlU7YWPPYAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:25 +0000 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: f792a4f8-59f9-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316565; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jhFlAl8E/ZVxI2AuUFyhPfvdnWASnzhuJ0AtRWUI/hQ=; b=bGuDis76nzl50gDl8gQleQdWKLKz16tCHn071OCHWJCPe60hDOgaxI0a4BBznOO058Xf7p Nxk4FmR38xb+m7BclrF1Oek4rMkrawdd5C98mCqE31GIIkycd7Wa6P24fc2zpdKzOtyyxM +sSqPJyb71vIzsGSrrBOVUysY64bZpE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 07/20] tools/xenstore: enhance hashtable implementation Date: Tue, 1 Nov 2022 16:28:29 +0100 Message-Id: <20221101152842.4257-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317446370100001 Content-Type: text/plain; charset="utf-8" Today it is possible to set a flag when calling hashtable_destroy() in order to specify whether the data associated with the hashtable entries should be freed or not. The keys of the entries will always be freed. Change that by replacing the flag of hashtable_destroy() by two flags for create_hashtable() which will specify whether the data and/or the key of each entry should be freed or not. This will enable users to have the key e.g. as part of the data. Add a new function hashtable_iterate() to call a user specified function for each entry in the hashtable. Add new primes to the primetable in order to support smaller sizes of the hashtable. The primes are selected according to: https://planetmath.org/goodhashtableprimes Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/hashtable.c | 66 +++++++++++++++++++++++---------- tools/xenstore/hashtable.h | 35 +++++++++++++++-- tools/xenstore/xenstored_core.c | 7 ++-- 3 files changed, 82 insertions(+), 26 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 6ac336eff1..7a1548c490 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -16,6 +16,7 @@ struct entry =20 struct hashtable { unsigned int tablelength; + unsigned int flags; struct entry **table; unsigned int entrycount; unsigned int loadlimit; @@ -25,12 +26,11 @@ struct hashtable { }; =20 /* -Credit for primes table: Aaron Krowne - http://br.endernet.org/~akrowne/ - http://planetmath.org/encyclopedia/GoodHashTablePrimes.html -*/ + * Credit for primes table: Aaron Krowne + * https://planetmath.org/goodhashtableprimes + */ static const unsigned int primes[] =3D { -53, 97, 193, 389, +11, 23, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, @@ -52,7 +52,8 @@ indexFor(unsigned int tablelength, unsigned int hashvalue= ) { struct hashtable * create_hashtable(unsigned int minsize, unsigned int (*hashf) (void*), - int (*eqf) (void*,void*)) + int (*eqf) (void*,void*), + unsigned int flags) { struct hashtable *h; unsigned int pindex, size =3D primes[0]; @@ -73,6 +74,7 @@ create_hashtable(unsigned int minsize, goto err1; =20 h->tablelength =3D size; + h->flags =3D flags; h->primeindex =3D pindex; h->entrycount =3D 0; h->hashfn =3D hashf; @@ -235,7 +237,8 @@ hashtable_remove(struct hashtable *h, void *k) *pE =3D e->next; h->entrycount--; v =3D e->v; - free(e->k); + if (h->flags & HASHTABLE_FREE_KEY) + free(e->k); free(e); return v; } @@ -246,29 +249,52 @@ hashtable_remove(struct hashtable *h, void *k) } =20 /*************************************************************************= ****/ -/* destroy */ -void -hashtable_destroy(struct hashtable *h, int free_values) +int +hashtable_iterate(struct hashtable *h, + int (*func)(void *k, void *v, void *arg), void *arg) { + int ret; unsigned int i; struct entry *e, *f; struct entry **table =3D h->table; - if (free_values) + + for (i =3D 0; i < h->tablelength; i++) { - for (i =3D 0; i < h->tablelength; i++) + e =3D table[i]; + while (e) { - e =3D table[i]; - while (NULL !=3D e) - { f =3D e; e =3D e->next; free(f->k); free(f->v); free(f); } + f =3D e; + e =3D e->next; + ret =3D func(f->k, f->v, arg); + if (ret) + return ret; } } - else + + return 0; +} + +/*************************************************************************= ****/ +/* destroy */ +void +hashtable_destroy(struct hashtable *h) +{ + unsigned int i; + struct entry *e, *f; + struct entry **table =3D h->table; + + for (i =3D 0; i < h->tablelength; i++) { - for (i =3D 0; i < h->tablelength; i++) + e =3D table[i]; + while (NULL !=3D e) { - e =3D table[i]; - while (NULL !=3D e) - { f =3D e; e =3D e->next; free(f->k); free(f); } + f =3D e; + e =3D e->next; + if (h->flags & HASHTABLE_FREE_KEY) + free(f->k); + if (h->flags & HASHTABLE_FREE_VALUE) + free(f->v); + free(f); } } free(h->table); diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index 62fef6081a..b31eeaea26 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -12,13 +12,21 @@ struct hashtable; * @param minsize minimum initial size of hashtable * @param hashfunction function for hashing keys * @param key_eq_fn function for determining key equality + * @param flags flags HASHTABLE_* * @return newly created hashtable or NULL on failure */ =20 +/* Let hashtable_destroy() free the entries' values. */ +#define HASHTABLE_FREE_VALUE (1U << 0) +/* Let hashtable_remove() and hashtable_destroy() free the entries' keys. = */ +#define HASHTABLE_FREE_KEY (1U << 1) + struct hashtable * create_hashtable(unsigned int minsize, unsigned int (*hashfunction) (void*), - int (*key_eq_fn) (void*,void*)); + int (*key_eq_fn) (void*,void*), + unsigned int flags +); =20 /*************************************************************************= **** * hashtable_insert @@ -76,16 +84,37 @@ hashtable_remove(struct hashtable *h, void *k); unsigned int hashtable_count(struct hashtable *h); =20 +/*************************************************************************= **** + * hashtable_iterate + + * @name hashtable_iterate + * @param h the hashtable + * @param func function to call for each entry + * @param arg user supplied parameter for func + * @return 0 if okay, non-zero return value of func (and iteration + * was aborted) + * + * Iterates over all entries in the hashtable and calls func with the + * key, value, and the user supplied parameter. + * func returning a non-zero value will abort the iteration. In case func = is + * removing an entry other than itself from the hashtable, it must return a + * non-zero value in order to abort the iteration. Inserting entries is + * allowed, but it is undefined whether func will be called for those new + * entries during this iteration. + */ +int +hashtable_iterate(struct hashtable *h, + int (*func)(void *k, void *v, void *arg), void *arg); + /*************************************************************************= **** * hashtable_destroy =20 * @name hashtable_destroy * @param h the hashtable - * @param free_values whether to call 'free' on the remaining va= lues */ =20 void -hashtable_destroy(struct hashtable *h, int free_values); +hashtable_destroy(struct hashtable *h); =20 #endif /* __HASHTABLE_CWC22_H__ */ =20 diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 8c2cca62b7..1650821922 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2512,7 +2512,9 @@ void check_store(void) .enoent =3D check_store_enoent, }; =20 - reachable =3D create_hashtable(16, hash_from_key_fn, keys_equal_fn); + /* Don't free values (they are all void *1) */ + reachable =3D create_hashtable(16, hash_from_key_fn, keys_equal_fn, + HASHTABLE_FREE_KEY); if (!reachable) { log("check_store: ENOMEM"); return; @@ -2526,8 +2528,7 @@ void check_store(void) clean_store(reachable); log("Checking store complete."); =20 - hashtable_destroy(reachable, 0 /* Don't free values (they are all - (void *)1) */); + hashtable_destroy(reachable); } =20 =20 --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667316591; cv=none; d=zohomail.com; s=zohoarc; b=aV3I0Xpqy9OiVYzXYk+dhfZGmlVGGlCl2gGeMBm5aWUFlX9tYrLTJTDmYv26ypZaShHekB1BjdPr56e5eIT5ue4WJEegfrrpvOcS7EPjBiRKDV7f2DUUQ2us5UeE3AAJ8Wn9VA1DoXGWFyFzqeM2bocpZoEzBSfVKguC2vyZ6LY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667316591; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=anDpkDCTkclPSUMBJP+Mdb2oOV35Mkg0KiisY71X+Fk=; b=k9Q2OVJnDeKYGPYqrj8K7NzBZ9E8fYNtiAhl6l2txMDojAvrBZnuDTEgs1Dp+2JPrWNAjbpljswxM+SuS3FOvFYLjnbPIygIJiQsJqkwXrXGeqlr3DMOTvao1gnnJckwkmx1xUT1/hZ/IHRs9m7wEaHLvSQOTaNRFUDhs+UvOiA= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667316591883715.7416671760142; Tue, 1 Nov 2022 08:29:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434849.687539 (Exim 4.92) (envelope-from ) id 1optCo-0002Jd-EK; Tue, 01 Nov 2022 15:29:34 +0000 Received: by outflank-mailman (output) from mailman id 434849.687539; Tue, 01 Nov 2022 15:29:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optCo-0002JW-92; Tue, 01 Nov 2022 15:29:34 +0000 Received: by outflank-mailman (input) for mailman id 434849; Tue, 01 Nov 2022 15:29:33 +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 1optCn-0007Bd-BZ for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:33 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fae2c300-59f9-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 16:29:31 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D4FF8336C7; Tue, 1 Nov 2022 15:29:30 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AD8681346F; Tue, 1 Nov 2022 15:29:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id nbMkKVo7YWPbYAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:30 +0000 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: fae2c300-59f9-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=anDpkDCTkclPSUMBJP+Mdb2oOV35Mkg0KiisY71X+Fk=; b=MFWcpC6+nbBGxiQJabTdKQpyqv5tBenYSnNEdeSD2WFCL4wO3ERGddNQ7FSV6FA+HxACkq YPzH+jn7bvlLLTm7LPlFjJ2Is6WlMjh3TKFH4kE71KCXFW2kZlIlgaBhz2CQe6LLw/lU5o YFtHuf4AdYzy7I/+T9xSq45ZLZixcvw= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 08/20] tools/xenstore: add hashlist for finding struct domain by domid Date: Tue, 1 Nov 2022 16:28:30 +0100 Message-Id: <20221101152842.4257-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667316593525100001 Content-Type: text/plain; charset="utf-8" Today finding a struct domain by its domain id requires to scan the list of domains until finding the correct domid. Add a hashlist for being able to speed this up. This allows to remove the linking of struct domain in a list. Note that the list of changed domains per transaction is kept as a list, as there are no known use cases with more than 4 domains being touched in a single transaction (this would be a device handled by a driver domain and being assigned to a HVM domain with device model in a stubdom, plus the control domain). Some simple performance tests comparing the scanning and hashlist have shown that the hashlist will win as soon as more than 6 entries need to be scanned. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_domain.c | 112 +++++++++++++++++------------- 1 file changed, 65 insertions(+), 47 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 1516df71d8..f6797e53c5 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -48,8 +48,6 @@ static struct node_perms dom_introduce_perms; =20 struct domain { - struct list_head list; - /* The id of this domain */ unsigned int domid; =20 @@ -96,7 +94,7 @@ struct domain bool wrl_delay_logged; }; =20 -static LIST_HEAD(domains); +static struct hashtable *domhash; =20 static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) { @@ -309,7 +307,7 @@ static int destroy_domain(void *_domain) =20 domain_tree_remove(domain); =20 - list_del(&domain->list); + hashtable_remove(domhash, &domain->domid); =20 if (!domain->introduced) return 0; @@ -341,49 +339,56 @@ static bool get_domain_info(unsigned int domid, xc_do= minfo_t *dominfo) dominfo->domid =3D=3D domid; } =20 -void check_domains(void) +static int check_domain(void *k, void *v, void *arg) { xc_dominfo_t dominfo; - struct domain *domain; struct connection *conn; - int notify =3D 0; bool dom_valid; + struct domain *domain =3D v; + bool *notify =3D arg; =20 - again: - list_for_each_entry(domain, &domains, list) { - dom_valid =3D get_domain_info(domain->domid, &dominfo); - if (!domain->introduced) { - if (!dom_valid) { - talloc_free(domain); - goto again; - } - continue; - } - if (dom_valid) { - if ((dominfo.crashed || dominfo.shutdown) - && !domain->shutdown) { - domain->shutdown =3D true; - notify =3D 1; - /* - * Avoid triggering watch events when the - * domain's nodes are being deleted. - */ - if (domain->conn) - conn_delete_all_watches(domain->conn); - } - if (!dominfo.dying) - continue; + dom_valid =3D get_domain_info(domain->domid, &dominfo); + if (!domain->introduced) { + if (!dom_valid) { + talloc_free(domain); + return 1; } - if (domain->conn) { - /* domain is a talloc child of domain->conn. */ - conn =3D domain->conn; - domain->conn =3D NULL; - talloc_unlink(talloc_autofree_context(), conn); - notify =3D 0; /* destroy_domain() fires the watch */ - goto again; + return 0; + } + if (dom_valid) { + if ((dominfo.crashed || dominfo.shutdown) + && !domain->shutdown) { + domain->shutdown =3D true; + *notify =3D true; + /* + * Avoid triggering watch events when the domain's + * nodes are being deleted. + */ + if (domain->conn) + conn_delete_all_watches(domain->conn); } + if (!dominfo.dying) + return 0; + } + if (domain->conn) { + /* domain is a talloc child of domain->conn. */ + conn =3D domain->conn; + domain->conn =3D NULL; + talloc_unlink(talloc_autofree_context(), conn); + *notify =3D false; /* destroy_domain() fires the watch */ + return 1; } =20 + return 0; +} + +void check_domains(void) +{ + bool notify =3D false; + + while (hashtable_iterate(domhash, check_domain, ¬ify)) + ; + if (notify) fire_watches(NULL, NULL, "@releaseDomain", NULL, true, NULL); } @@ -421,13 +426,7 @@ static char *talloc_domain_path(const void *context, u= nsigned int domid) =20 static struct domain *find_domain_struct(unsigned int domid) { - struct domain *i; - - list_for_each_entry(i, &domains, list) { - if (i->domid =3D=3D domid) - return i; - } - return NULL; + return hashtable_search(domhash, &domid); } =20 int domain_get_quota(const void *ctx, struct connection *conn, @@ -476,9 +475,13 @@ static struct domain *alloc_domain(const void *context= , unsigned int domid) domain->generation =3D generation; domain->introduced =3D false; =20 - talloc_set_destructor(domain, destroy_domain); + if (!hashtable_insert(domhash, &domain->domid, domain)) { + talloc_free(domain); + errno =3D ENOMEM; + return NULL; + } =20 - list_add(&domain->list, &domains); + talloc_set_destructor(domain, destroy_domain); =20 return domain; } @@ -909,10 +912,25 @@ void dom0_init(void) xenevtchn_notify(xce_handle, dom0->port); } =20 +static unsigned int domhash_fn(void *k) +{ + return *(unsigned int *)k; +} + +static int domeq_fn(void *key1, void *key2) +{ + return *(unsigned int *)key1 =3D=3D *(unsigned int *)key2; +} + void domain_init(int evtfd) { int rc; =20 + /* Start with a random rather low domain count for the hashtable. */ + domhash =3D create_hashtable(8, domhash_fn, domeq_fn, 0); + if (!domhash) + barf_perror("Failed to allocate domain hashtable"); + xc_handle =3D talloc(talloc_autofree_context(), xc_interface*); if (!xc_handle) barf_perror("Failed to allocate domain handle"); --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317441; cv=none; d=zohomail.com; s=zohoarc; b=Oy6o5MpBKvJiG7MJi2E2aYHMMB4l9ps1bRZwB54vduicQ0piOzItRL7rDCu6oSqaKNWDwAx8U4BjuEqKZtukqU1W8KptE8ECKRvAxktYhfFLfO4cwj/Qhlnr73JNxyemJcqayV1bwZFNLaJEcvCz0zB5QdWBQX2QyYukhaMxkJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317441; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tg8TSEeYBIF2KJ0g+f5733uhCW0POMvEIJ3tLX8Z4xA=; b=awZ+wiv6m1qVefy4ErYZtxD90HSads5kCRmkHBnNc1gn8mFIUPVEgyr2oRlm2CYYN0AB/YaX7OB3d0uWAL+wNx3sghKgFqzuiGQhnVT02IYMeplhLHaFwyGWwWVkB+bdjnpSnU/nL8q8ao8iGfcq3sNTOXFtXIs/kXP3U2v+o6c= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317441367364.94777667324786; Tue, 1 Nov 2022 08:44:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434980.687965 (Exim 4.92) (envelope-from ) id 1optQW-0004eR-6k; Tue, 01 Nov 2022 15:43:44 +0000 Received: by outflank-mailman (output) from mailman id 434980.687965; Tue, 01 Nov 2022 15:43:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQW-0004e2-0k; Tue, 01 Nov 2022 15:43:44 +0000 Received: by outflank-mailman (input) for mailman id 434980; Tue, 01 Nov 2022 15:43: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 1optCs-0007Bd-8J for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:38 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fe3239c3-59f9-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 16:29:36 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 67F39336C7; Tue, 1 Nov 2022 15:29:36 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3C29A1346F; Tue, 1 Nov 2022 15:29:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6EFVDWA7YWPjYAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:36 +0000 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: fe3239c3-59f9-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316576; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tg8TSEeYBIF2KJ0g+f5733uhCW0POMvEIJ3tLX8Z4xA=; b=YudtRelzqL4HQQP/fQ7qugSrRsQJ8Dr+UwF3rEg/kAa1MwwJlMQuqjJMZ3ZlMV40lw537a fuWCg8yOwgyLFylEJtGSkzoYIN5ZZqf2NUU2TKBMEPIwvqRbtOGOm4qAN8xns9Tzcj/ObO OgoK8ng0tkNzMrufvn4MhN1DZrY41yU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 09/20] tools/xenstore: introduce dummy nodes for special watch paths Date: Tue, 1 Nov 2022 16:28:31 +0100 Message-Id: <20221101152842.4257-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317442350100015 Content-Type: text/plain; charset="utf-8" Instead of special casing the permission handling and watch event firing for the special watch paths "@introduceDomain" and "@releaseDomain", use static dummy nodes added to the data base when starting Xenstore. This allows to simplify quite some code. Note that this requires to rework the calls of fire_watches() for the special events in order to avoid leaking memory. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_control.c | 3 - tools/xenstore/xenstored_core.c | 67 +++++++----- tools/xenstore/xenstored_domain.c | 162 ++++------------------------- tools/xenstore/xenstored_domain.h | 6 -- tools/xenstore/xenstored_watch.c | 17 +-- 5 files changed, 63 insertions(+), 192 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index d1aaa00bf4..41e6992591 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -676,9 +676,6 @@ static const char *lu_dump_state(const void *ctx, struc= t connection *conn) if (ret) goto out; ret =3D dump_state_connections(fp); - if (ret) - goto out; - ret =3D dump_state_special_nodes(fp); if (ret) goto out; ret =3D dump_state_nodes(fp, ctx); diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 1650821922..cadb339486 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -616,7 +616,8 @@ static void get_acc_data(TDB_DATA *key, struct node_acc= ount_data *acc) static unsigned int get_acc_domid(struct connection *conn, TDB_DATA *key, unsigned int domid) { - return (!conn || key->dptr[0] =3D=3D '/') ? domid : conn->id; + return (!conn || key->dptr[0] =3D=3D '/' || key->dptr[0] =3D=3D '@') + ? domid : conn->id; } =20 int do_tdb_write(struct connection *conn, TDB_DATA *key, TDB_DATA *data, @@ -1780,14 +1781,6 @@ static int do_set_perms(const void *ctx, struct conn= ection *conn, if (perms.p[0].perms & XS_PERM_IGNORE) return ENOENT; =20 - /* First arg is node name. */ - if (strstarts(in->buffer, "@")) { - if (set_perms_special(conn, in->buffer, &perms)) - return errno; - send_ack(conn, XS_SET_PERMS); - return 0; - } - /* We must own node to do this (tools can do this too). */ node =3D get_node_canonicalized(conn, ctx, in->buffer, &name, XS_PERM_WRITE | XS_PERM_OWNER); @@ -2388,7 +2381,9 @@ void setup_structure(bool live_update) manual_node("/", "tool"); manual_node("/tool", "xenstored"); manual_node("/tool/xenstored", NULL); - domain_entry_fix(dom0_domid, 3, true); + manual_node("@releaseDomain", NULL); + manual_node("@introduceDomain", NULL); + domain_entry_fix(dom0_domid, 5, true); } =20 check_store(); @@ -3170,6 +3165,23 @@ static int dump_state_node(const void *ctx, struct c= onnection *conn, return WALK_TREE_OK; } =20 +static int dump_state_special_node(FILE *fp, const void *ctx, + struct dump_node_data *data, + const char *name) +{ + struct node *node; + int ret; + + node =3D read_node(NULL, ctx, name); + if (!node) + return dump_state_node_err(data, "Dump node read node error"); + + ret =3D dump_state_node(ctx, NULL, node, data); + talloc_free(node); + + return ret; +} + const char *dump_state_nodes(FILE *fp, const void *ctx) { struct dump_node_data data =3D { @@ -3181,6 +3193,11 @@ const char *dump_state_nodes(FILE *fp, const void *c= tx) if (walk_node_tree(ctx, NULL, "/", &walkfuncs, &data)) return data.err; =20 + if (dump_state_special_node(fp, ctx, &data, "@releaseDomain")) + return data.err; + if (dump_state_special_node(fp, ctx, &data, "@introduceDomain")) + return data.err; + return NULL; } =20 @@ -3354,25 +3371,21 @@ void read_state_node(const void *ctx, const void *s= tate) node->perms.p[i].id =3D sn->perms[i].domid; } =20 - if (strstarts(name, "@")) { - set_perms_special(&conn, name, &node->perms); - talloc_free(node); - return; - } - - parentname =3D get_parent(node, name); - if (!parentname) - barf("allocation error restoring node"); - parent =3D read_node(NULL, node, parentname); - if (!parent) - barf("read parent error restoring node"); + if (!strstarts(name, "@")) { + parentname =3D get_parent(node, name); + if (!parentname) + barf("allocation error restoring node"); + parent =3D read_node(NULL, node, parentname); + if (!parent) + barf("read parent error restoring node"); =20 - if (add_child(node, parent, name)) - barf("allocation error restoring node"); + if (add_child(node, parent, name)) + barf("allocation error restoring node"); =20 - set_tdb_key(parentname, &key); - if (write_node_raw(NULL, &key, parent, true)) - barf("write parent error restoring node"); + set_tdb_key(parentname, &key); + if (write_node_raw(NULL, &key, parent, true)) + barf("write parent error restoring node"); + } =20 set_tdb_key(name, &key); if (write_node_raw(NULL, &key, node, true)) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index f6797e53c5..5756010944 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -43,9 +43,6 @@ static evtchn_port_t virq_port; =20 xenevtchn_handle *xce_handle =3D NULL; =20 -static struct node_perms dom_release_perms; -static struct node_perms dom_introduce_perms; - struct domain { /* The id of this domain */ @@ -225,27 +222,6 @@ static void unmap_interface(void *interface) xengnttab_unmap(*xgt_handle, interface, 1); } =20 -static void remove_domid_from_perm(struct node_perms *perms, - struct domain *domain) -{ - unsigned int cur, new; - - if (perms->p[0].id =3D=3D domain->domid) - perms->p[0].id =3D priv_domid; - - for (cur =3D new =3D 1; cur < perms->num; cur++) { - if (perms->p[cur].id =3D=3D domain->domid) - continue; - - if (new !=3D cur) - perms->p[new] =3D perms->p[cur]; - - new++; - } - - perms->num =3D new; -} - static int domain_tree_remove_sub(const void *ctx, struct connection *conn, struct node *node, void *arg) { @@ -297,8 +273,24 @@ static void domain_tree_remove(struct domain *domain) "error when looking for orphaned nodes\n"); } =20 - remove_domid_from_perm(&dom_release_perms, domain); - remove_domid_from_perm(&dom_introduce_perms, domain); + walk_node_tree(domain, NULL, "@releaseDomain", &walkfuncs, domain); + walk_node_tree(domain, NULL, "@introduceDomain", &walkfuncs, domain); +} + +static void fire_special_watches(const char *name) +{ + void *ctx =3D talloc_new(NULL); + struct node *node; + + if (!ctx) + return; + + node =3D read_node(NULL, ctx, name); + + if (node) + fire_watches(NULL, ctx, name, node, true, NULL); + + talloc_free(ctx); } =20 static int destroy_domain(void *_domain) @@ -326,7 +318,7 @@ static int destroy_domain(void *_domain) unmap_interface(domain->interface); } =20 - fire_watches(NULL, domain, "@releaseDomain", NULL, true, NULL); + fire_special_watches("@releaseDomain"); =20 wrl_domain_destroy(domain); =20 @@ -390,7 +382,7 @@ void check_domains(void) ; =20 if (notify) - fire_watches(NULL, NULL, "@releaseDomain", NULL, true, NULL); + fire_special_watches("@releaseDomain"); } =20 /* We scan all domains rather than use the information given here. */ @@ -639,8 +631,7 @@ static struct domain *introduce_domain(const void *ctx, } =20 if (!is_master_domain && !restore) - fire_watches(NULL, ctx, "@introduceDomain", NULL, - true, NULL); + fire_special_watches("@introduceDomain"); } else { /* Use XS_INTRODUCE for recreating the xenbus event-channel. */ if (domain->port) @@ -843,59 +834,6 @@ const char *get_implicit_path(const struct connection = *conn) return conn->domain->path; } =20 -static int set_dom_perms_default(struct node_perms *perms) -{ - perms->num =3D 1; - perms->p =3D talloc_array(NULL, struct xs_permissions, perms->num); - if (!perms->p) - return -1; - perms->p->id =3D 0; - perms->p->perms =3D XS_PERM_NONE; - - return 0; -} - -static struct node_perms *get_perms_special(const char *name) -{ - if (!strcmp(name, "@releaseDomain")) - return &dom_release_perms; - if (!strcmp(name, "@introduceDomain")) - return &dom_introduce_perms; - return NULL; -} - -int set_perms_special(struct connection *conn, const char *name, - struct node_perms *perms) -{ - struct node_perms *p; - - p =3D get_perms_special(name); - if (!p) - return EINVAL; - - if ((perm_for_conn(conn, p) & (XS_PERM_WRITE | XS_PERM_OWNER)) !=3D - (XS_PERM_WRITE | XS_PERM_OWNER)) - return EACCES; - - p->num =3D perms->num; - talloc_free(p->p); - p->p =3D perms->p; - talloc_steal(NULL, perms->p); - - return 0; -} - -bool check_perms_special(const char *name, struct connection *conn) -{ - struct node_perms *p; - - p =3D get_perms_special(name); - if (!p) - return false; - - return perm_for_conn(conn, p) & XS_PERM_READ; -} - void dom0_init(void) { evtchn_port_t port; @@ -965,10 +903,6 @@ void domain_init(int evtfd) if (xce_handle =3D=3D NULL) barf_perror("Failed to open evtchn device"); =20 - if (set_dom_perms_default(&dom_release_perms) || - set_dom_perms_default(&dom_introduce_perms)) - barf_perror("Failed to set special permissions"); - if ((rc =3D xenevtchn_bind_virq(xce_handle, VIRQ_DOM_EXC)) =3D=3D -1) barf_perror("Failed to bind to domain exception virq port"); virq_port =3D rc; @@ -1538,60 +1472,6 @@ const char *dump_state_connections(FILE *fp) return ret; } =20 -static const char *dump_state_special_node(FILE *fp, const char *name, - const struct node_perms *perms) -{ - struct xs_state_record_header head; - struct xs_state_node sn; - unsigned int pathlen; - const char *ret; - - pathlen =3D strlen(name) + 1; - - head.type =3D XS_STATE_TYPE_NODE; - head.length =3D sizeof(sn); - - sn.conn_id =3D 0; - sn.ta_id =3D 0; - sn.ta_access =3D 0; - sn.perm_n =3D perms->num; - sn.path_len =3D pathlen; - sn.data_len =3D 0; - head.length +=3D perms->num * sizeof(*sn.perms); - head.length +=3D pathlen; - head.length =3D ROUNDUP(head.length, 3); - if (fwrite(&head, sizeof(head), 1, fp) !=3D 1) - return "Dump special node error"; - if (fwrite(&sn, sizeof(sn), 1, fp) !=3D 1) - return "Dump special node error"; - - ret =3D dump_state_node_perms(fp, perms->p, perms->num); - if (ret) - return ret; - - if (fwrite(name, pathlen, 1, fp) !=3D 1) - return "Dump special node path error"; - - ret =3D dump_state_align(fp); - - return ret; -} - -const char *dump_state_special_nodes(FILE *fp) -{ - const char *ret; - - ret =3D dump_state_special_node(fp, "@releaseDomain", - &dom_release_perms); - if (ret) - return ret; - - ret =3D dump_state_special_node(fp, "@introduceDomain", - &dom_introduce_perms); - - return ret; -} - void read_state_connection(const void *ctx, const void *state) { const struct xs_state_connection *sc =3D state; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index b38c82991d..630641d620 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -99,11 +99,6 @@ void domain_outstanding_domid_dec(unsigned int domid); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); =20 -/* Special node permission handling. */ -int set_perms_special(struct connection *conn, const char *name, - struct node_perms *perms); -bool check_perms_special(const char *name, struct connection *conn); - /* Write rate limiting */ =20 #define WRL_FACTOR 1000 /* for fixed-point arithmetic */ @@ -132,7 +127,6 @@ void wrl_apply_debit_direct(struct connection *conn); void wrl_apply_debit_trans_commit(struct connection *conn); =20 const char *dump_state_connections(FILE *fp); -const char *dump_state_special_nodes(FILE *fp); =20 void read_state_connection(const void *ctx, const void *state); =20 diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index 316c08b7f7..75748ac109 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -46,13 +46,6 @@ struct watch char *node; }; =20 -static bool check_special_event(const char *name) -{ - assert(name); - - return strstarts(name, "@"); -} - /* Is child a subnode of parent, or equal? */ static bool is_child(const char *child, const char *parent) { @@ -153,14 +146,8 @@ void fire_watches(struct connection *conn, const void = *ctx, const char *name, =20 /* Create an event for each watch. */ list_for_each_entry(i, &connections, list) { - /* introduce/release domain watches */ - if (check_special_event(name)) { - if (!check_perms_special(name, i)) - continue; - } else { - if (!watch_permitted(i, ctx, name, node, perms)) - continue; - } + if (!watch_permitted(i, ctx, name, node, perms)) + continue; =20 list_for_each_entry(watch, &i->watches, list) { if (exact) { --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317064; cv=none; d=zohomail.com; s=zohoarc; b=hsbHUf/V58mJ1r/QdL/4UDz1CvaTeNRCRY2x1isBIYYWog2asuswumVnugdsC4igkNTx+0KCH/0KScN0cySeymXswOTOA4slkE7+hRDaQtPFAmajKM0PIHfwt5yMLqY2yfMsBh+CtCl5RujqRofJb3ReedA0WTT2EypEyUAdkfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317064; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SBeCcFuOhLUEwWwrku8ezHj3ySsRMOxBoKQyjJXO/Rw=; b=My6fbIKD7GCcbyBcAN1p6p607cvLAiqPjXd4nxo/zDqWjrVArCNme+x5qkUVKZtrhNK2LTjcpp98g14ZaNDELB+smSBKCaouMgwiHXJuBZRa06MEtmy5ooFcwcacjfMhoRJOd0gHVdL/cfwfSXe57XBAtNyopEin5HIahG8O3gM= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317064247655.0826157908243; Tue, 1 Nov 2022 08:37:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434913.687745 (Exim 4.92) (envelope-from ) id 1optKN-0007Ii-22; Tue, 01 Nov 2022 15:37:23 +0000 Received: by outflank-mailman (output) from mailman id 434913.687745; Tue, 01 Nov 2022 15:37:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optKM-0007Ib-Uv; Tue, 01 Nov 2022 15:37:22 +0000 Received: by outflank-mailman (input) for mailman id 434913; Tue, 01 Nov 2022 15:37:21 +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 1optCy-0007Tl-Nq for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:44 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0183a777-59fa-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:29:42 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F3FA51F8E3; Tue, 1 Nov 2022 15:29:41 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C7DC61346F; Tue, 1 Nov 2022 15:29:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id W4FOL2U7YWPvYAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:41 +0000 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: 0183a777-59fa-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SBeCcFuOhLUEwWwrku8ezHj3ySsRMOxBoKQyjJXO/Rw=; b=GKHnzEtw0Utvfi1KYA0w3j9knflkiyuEPxBNpn2l9n0YccG2EaIzQKsOPnEcyzTgHKs2xI /VfnGYAfcuqBZH3aP7VUxPEthZNYbq4ikvy+v9S829wbxc9iXLJ/sfJ5N3LuPj2952BFvC +LNPV+7SFeCLpynsKx1ITNzbn9F/KMI= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 10/20] tools/xenstore: replace watch->relative_path with a prefix length Date: Tue, 1 Nov 2022 16:28:32 +0100 Message-Id: <20221101152842.4257-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317066005100001 Content-Type: text/plain; charset="utf-8" Instead of storing a pointer to the path which is prepended to relative paths in struct watch, just use the length of the prepended path. It should be noted that the now removed special case of the relative path being "" in get_watch_path() can't happen at all. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_watch.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index 75748ac109..8bed967c56 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -39,8 +39,8 @@ struct watch /* Current outstanding events applying to this watch. */ struct list_head events; =20 - /* Is this relative to connnection's implicit path? */ - const char *relative_path; + /* Offset into path for skipping prefix (used for relative paths). */ + unsigned int prefix_len; =20 char *token; char *node; @@ -66,15 +66,7 @@ static bool is_child(const char *child, const char *pare= nt) =20 static const char *get_watch_path(const struct watch *watch, const char *n= ame) { - const char *path =3D name; - - if (watch->relative_path) { - path +=3D strlen(watch->relative_path); - if (*path =3D=3D '/') /* Could be "" */ - path++; - } - - return path; + return name + watch->prefix_len; } =20 /* @@ -211,10 +203,7 @@ static struct watch *add_watch(struct connection *conn= , char *path, char *token, no_quota_check)) goto nomem; =20 - if (relative) - watch->relative_path =3D get_implicit_path(conn); - else - watch->relative_path =3D NULL; + watch->prefix_len =3D relative ? strlen(get_implicit_path(conn)) + 1 : 0; =20 INIT_LIST_HEAD(&watch->events); =20 @@ -316,7 +305,6 @@ const char *dump_state_watches(FILE *fp, struct connect= ion *conn, struct watch *watch; struct xs_state_watch sw; struct xs_state_record_header head; - const char *path; =20 head.type =3D XS_STATE_TYPE_WATCH; =20 @@ -324,8 +312,7 @@ const char *dump_state_watches(FILE *fp, struct connect= ion *conn, head.length =3D sizeof(sw); =20 sw.conn_id =3D conn_id; - path =3D get_watch_path(watch, watch->node); - sw.path_length =3D strlen(path) + 1; + sw.path_length =3D strlen(watch->node + watch->prefix_len) + 1; sw.token_length =3D strlen(watch->token) + 1; head.length +=3D sw.path_length + sw.token_length; head.length =3D ROUNDUP(head.length, 3); @@ -334,7 +321,8 @@ const char *dump_state_watches(FILE *fp, struct connect= ion *conn, if (fwrite(&sw, sizeof(sw), 1, fp) !=3D 1) return "Dump watch state error"; =20 - if (fwrite(path, sw.path_length, 1, fp) !=3D 1) + if (fwrite(watch->node + watch->prefix_len, sw.path_length, + 1, fp) !=3D 1) return "Dump watch path error"; if (fwrite(watch->token, sw.token_length, 1, fp) !=3D 1) return "Dump watch token error"; --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317440; cv=none; d=zohomail.com; s=zohoarc; b=nvDqyXybY1F9zmzR8wKj1bzGobbCWJQ8Ia4j3ggPwpMm97fNpsd7urFjnALx5SFYpJoN/8MXJJgPpZVcxfVHD9rpOH9Hu2uOUX+jRAHcT6z23d1vJKqctxMUbTDuyHeC1GDjNmxomN8JienAkf+89gc/Sv5IKfTQyogy5ZQVkYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317440; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YEuNMFZScrBO9VppDIj+NvcWUmoCWDv+0NHEQClkkiM=; b=f+JX5YQOhUkg2d07bO0QzkMXCVCgMIzIlnodCKbegySBnxQ4mYOS764q/v4/KTLk2wyFfQLuWm800to/GHusm2cvB25iXf/y7yTpi3i1PJKpHceUpUYHnl9MYgn02HRqWiV3P92l7wb1yYYHaJYDvr3LsWSDZfVKC7jUegqfV2I= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317440802381.1297347657818; Tue, 1 Nov 2022 08:44:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434985.687983 (Exim 4.92) (envelope-from ) id 1optQX-00053L-Ty; Tue, 01 Nov 2022 15:43:45 +0000 Received: by outflank-mailman (output) from mailman id 434985.687983; Tue, 01 Nov 2022 15:43:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQX-0004xE-If; Tue, 01 Nov 2022 15:43:45 +0000 Received: by outflank-mailman (input) for mailman id 434985; Tue, 01 Nov 2022 15:43:43 +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 1optD2-0007Tl-Jm for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:48 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 04d736a9-59fa-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:29:47 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8B9013385D; Tue, 1 Nov 2022 15:29:47 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5DC971346F; Tue, 1 Nov 2022 15:29:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id tUCKFWs7YWP5YAAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:47 +0000 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: 04d736a9-59fa-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316587; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YEuNMFZScrBO9VppDIj+NvcWUmoCWDv+0NHEQClkkiM=; b=KtJt4+Wu1b0GgfxVWcgP6BYrWFjgfvpI6FE79lMDZjQWT4zRpDGJvbk0Igj6yCZZekx51h U/+p2cUN+TIp+V+4e3yCfIgIppE4PNpXfHvuFR1EQvGSVisJJ5nrNM/SbFc07gVhE+0BSn uwh8V3w+HA7OgA34dk+5L3f6LXykKnk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 11/20] tools/xenstore: move changed domain handling Date: Tue, 1 Nov 2022 16:28:33 +0100 Message-Id: <20221101152842.4257-12-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317442341100014 Content-Type: text/plain; charset="utf-8" Move all code related to struct changed_domain from xenstored_transaction.c to xenstored_domain.c. This will be needed later in order to simplify the accounting data updates in cases of errors during a request. Split the code to have a more generic base framework. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_domain.c | 85 +++++++++++++++++++++++++- tools/xenstore/xenstored_domain.h | 3 + tools/xenstore/xenstored_transaction.c | 64 ++----------------- 3 files changed, 90 insertions(+), 62 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 5756010944..14fd84c288 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -91,6 +91,18 @@ struct domain bool wrl_delay_logged; }; =20 +struct changed_domain +{ + /* List of all changed domains. */ + struct list_head list; + + /* Identifier of the changed domain. */ + unsigned int domid; + + /* Amount by which this domain's nbentry field has changed. */ + int nbentry; +}; + static struct hashtable *domhash; =20 static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) @@ -492,8 +504,12 @@ static struct domain *find_or_alloc_existing_domain(un= signed int domid) xc_dominfo_t dominfo; =20 domain =3D find_domain_struct(domid); - if (!domain && get_domain_info(domid, &dominfo)) - domain =3D alloc_domain(NULL, domid); + if (!domain) { + if (!get_domain_info(domid, &dominfo)) + errno =3D ENOENT; + else + domain =3D alloc_domain(NULL, domid); + } =20 return domain; } @@ -547,6 +563,71 @@ static struct domain *find_domain_by_domid(unsigned in= t domid) return (d && d->introduced) ? d : NULL; } =20 +int acc_fix_domains(struct list_head *head, bool update) +{ + struct changed_domain *cd; + int cnt; + + list_for_each_entry(cd, head, list) { + cnt =3D domain_entry_fix(cd->domid, cd->nbentry, update); + if (!update) { + if (cnt >=3D quota_nb_entry_per_domain) + return ENOSPC; + if (cnt < 0) + return ENOMEM; + } + } + + return 0; +} + +static struct changed_domain *acc_find_changed_domain(struct list_head *he= ad, + unsigned int domid) +{ + struct changed_domain *cd; + + list_for_each_entry(cd, head, list) { + if (cd->domid =3D=3D domid) + return cd; + } + + return NULL; +} + +static struct changed_domain *acc_get_changed_domain(const void *ctx, + struct list_head *head, + unsigned int domid) +{ + struct changed_domain *cd; + + cd =3D acc_find_changed_domain(head, domid); + if (cd) + return cd; + + cd =3D talloc_zero(ctx, struct changed_domain); + if (!cd) + return NULL; + + cd->domid =3D domid; + list_add_tail(&cd->list, head); + + return cd; +} + +int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, + unsigned int domid) +{ + struct changed_domain *cd; + + cd =3D acc_get_changed_domain(ctx, head, domid); + if (!cd) + return errno; + + cd->nbentry +=3D val; + + return 0; +} + static void domain_conn_reset(struct domain *domain) { struct connection *conn =3D domain->conn; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 630641d620..9e20d2b17d 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -98,6 +98,9 @@ void domain_outstanding_dec(struct connection *conn); void domain_outstanding_domid_dec(unsigned int domid); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); +int acc_fix_domains(struct list_head *head, bool update); +int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, + unsigned int domid); =20 /* Write rate limiting */ =20 diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index ac854197ca..89b92f0baf 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -137,18 +137,6 @@ struct accessed_node bool watch_exact; }; =20 -struct changed_domain -{ - /* List of all changed domains in the context of this transaction. */ - struct list_head list; - - /* Identifier of the changed domain. */ - unsigned int domid; - - /* Amount by which this domain's nbentry field has changed. */ - int nbentry; -}; - struct transaction { /* List of all transactions active on this connection. */ @@ -514,24 +502,6 @@ int do_transaction_start(const void *ctx, struct conne= ction *conn, return 0; } =20 -static int transaction_fix_domains(struct transaction *trans, bool update) -{ - struct changed_domain *d; - int cnt; - - list_for_each_entry(d, &trans->changed_domains, list) { - cnt =3D domain_entry_fix(d->domid, d->nbentry, update); - if (!update) { - if (cnt >=3D quota_nb_entry_per_domain) - return ENOSPC; - if (cnt < 0) - return ENOMEM; - } - } - - return 0; -} - int do_transaction_end(const void *ctx, struct connection *conn, struct buffered_data *in) { @@ -558,7 +528,7 @@ int do_transaction_end(const void *ctx, struct connecti= on *conn, if (streq(arg, "T")) { if (trans->fail) return ENOMEM; - ret =3D transaction_fix_domains(trans, false); + ret =3D acc_fix_domains(&trans->changed_domains, false); if (ret) return ret; ret =3D finalize_transaction(conn, trans, &is_corrupt); @@ -568,7 +538,7 @@ int do_transaction_end(const void *ctx, struct connecti= on *conn, wrl_apply_debit_trans_commit(conn); =20 /* fix domain entry for each changed domain */ - transaction_fix_domains(trans, true); + acc_fix_domains(&trans->changed_domains, true); =20 if (is_corrupt) corrupt(conn, "transaction inconsistency"); @@ -580,44 +550,18 @@ int do_transaction_end(const void *ctx, struct connec= tion *conn, =20 void transaction_entry_inc(struct transaction *trans, unsigned int domid) { - struct changed_domain *d; - - list_for_each_entry(d, &trans->changed_domains, list) - if (d->domid =3D=3D domid) { - d->nbentry++; - return; - } - - d =3D talloc(trans, struct changed_domain); - if (!d) { + if (acc_add_dom_nbentry(trans, &trans->changed_domains, 1, domid)) { /* Let the transaction fail. */ trans->fail =3D true; - return; } - d->domid =3D domid; - d->nbentry =3D 1; - list_add_tail(&d->list, &trans->changed_domains); } =20 void transaction_entry_dec(struct transaction *trans, unsigned int domid) { - struct changed_domain *d; - - list_for_each_entry(d, &trans->changed_domains, list) - if (d->domid =3D=3D domid) { - d->nbentry--; - return; - } - - d =3D talloc(trans, struct changed_domain); - if (!d) { + if (acc_add_dom_nbentry(trans, &trans->changed_domains, -1, domid)) { /* Let the transaction fail. */ trans->fail =3D true; - return; } - d->domid =3D domid; - d->nbentry =3D -1; - list_add_tail(&d->list, &trans->changed_domains); } =20 void fail_transaction(struct transaction *trans) --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317060; cv=none; d=zohomail.com; s=zohoarc; b=IOVc6qxTJs/wC3unR9F0781rczQ78RuPXvBlX3uBEAAWrW+uc1ie/1+EaZ+aoR5DJmFbmPrBbtsri8biOcsfW9WC2WkBtewLs/5xnm9RIuoHE+Rbv602KEsh5E/rKmmNxIlHqLtOtQzAX6vEH64yAf+ciEKyPWKQBn0BGnYfZ/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317060; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6cO3bOwodibHGnM88vggzXd4Fv7IsN58rIy1QvyWOFY=; b=IskddSDtAXR6pbR+8JplaRZYIhA+qgWev487or0v8JqggZmwImZS0BZUN2CayxbTLbAttxGtWlpbuB6kBKE5AeO6XZzp+vd20RXgVyQ4FxDHYHoDfRwlHK/3hv0P/OjHpsqKGVlB3UOEJk+gVaSrANAKDb16Xr1M0EISNg+w2Fc= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317060401652.0777307583564; Tue, 1 Nov 2022 08:37:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434916.687750 (Exim 4.92) (envelope-from ) id 1optKN-0007Ll-9T; Tue, 01 Nov 2022 15:37:23 +0000 Received: by outflank-mailman (output) from mailman id 434916.687750; Tue, 01 Nov 2022 15:37:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optKN-0007Kc-4w; Tue, 01 Nov 2022 15:37:23 +0000 Received: by outflank-mailman (input) for mailman id 434916; Tue, 01 Nov 2022 15:37:22 +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 1optD8-0007Tl-Gs for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:54 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0829b728-59fa-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:29:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 233BA3385D; Tue, 1 Nov 2022 15:29:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EA98E1346F; Tue, 1 Nov 2022 15:29:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id McwcOHA7YWMIYQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:52 +0000 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: 0829b728-59fa-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316593; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6cO3bOwodibHGnM88vggzXd4Fv7IsN58rIy1QvyWOFY=; b=rBc42uxY2f851cPpNm3gakPKlOQ4MiD3BFBidWinnPFaun+bkqxw8u+DqJ9hwPXuaVh3nA dM7ijcgocM0A3yC5ll/Mi2Bn7kKfd/tMHyBRRLLMqKX4Rr+q/OayYhkQsz4cLt3NNm1MC/ xB4+CFgxem0/t552v7QmYeoPzzzfO4g= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 12/20] tools/xenstore: change per-domain node accounting interface Date: Tue, 1 Nov 2022 16:28:34 +0100 Message-Id: <20221101152842.4257-13-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317061893100001 Content-Type: text/plain; charset="utf-8" Rework the interface and the internals of the per-domain node accounting: - rename the functions to domain_nbentry_*() in order to better match the related counter name - switch from node pointer to domid as interface, as all nodes have the owner filled in - use a common internal function for adding a value to the counter For the transaction case add a helper function to get the list head of the per-transaction changed domains, enabling to eliminate the transaction_entry_*() functions. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 22 ++--- tools/xenstore/xenstored_domain.c | 122 +++++++++++-------------- tools/xenstore/xenstored_domain.h | 10 +- tools/xenstore/xenstored_transaction.c | 15 +-- tools/xenstore/xenstored_transaction.h | 7 +- 5 files changed, 72 insertions(+), 104 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index cadb339486..5fd4f8e606 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1449,7 +1449,7 @@ static void destroy_node_rm(struct connection *conn, = struct node *node) static int destroy_node(struct connection *conn, struct node *node) { destroy_node_rm(conn, node); - domain_entry_dec(conn, node); + domain_nbentry_dec(conn, node->perms.p[0].id); =20 /* * It is not possible to easily revert the changes in a transaction. @@ -1488,7 +1488,7 @@ static struct node *create_node(struct connection *co= nn, const void *ctx, for (i =3D node; i; i =3D i->parent) { /* i->parent is set for each new node, so check quota. */ if (i->parent && - domain_entry(conn) >=3D quota_nb_entry_per_domain) { + domain_nbentry(conn) >=3D quota_nb_entry_per_domain) { ret =3D ENOSPC; goto err; } @@ -1499,7 +1499,7 @@ static struct node *create_node(struct connection *co= nn, const void *ctx, =20 /* Account for new node */ if (i->parent) { - if (domain_entry_inc(conn, i)) { + if (domain_nbentry_inc(conn, i->perms.p[0].id)) { destroy_node_rm(conn, i); return NULL; } @@ -1652,7 +1652,7 @@ static int delnode_sub(const void *ctx, struct connec= tion *conn, watch_exact =3D strcmp(root, node->name); fire_watches(conn, ctx, node->name, node, watch_exact, NULL); =20 - domain_entry_dec(conn, node); + domain_nbentry_dec(conn, node->perms.p[0].id); =20 return WALK_TREE_RM_CHILDENTRY; } @@ -1793,25 +1793,25 @@ static int do_set_perms(const void *ctx, struct con= nection *conn, return EPERM; =20 old_perms =3D node->perms; - domain_entry_dec(conn, node); + domain_nbentry_dec(conn, node->perms.p[0].id); node->perms =3D perms; - if (domain_entry_inc(conn, node)) { + if (domain_nbentry_inc(conn, node->perms.p[0].id)) { node->perms =3D old_perms; /* * This should never fail because we had a reference on the * domain before and Xenstored is single-threaded. */ - domain_entry_inc(conn, node); + domain_nbentry_inc(conn, node->perms.p[0].id); return ENOMEM; } =20 if (write_node(conn, node, false)) { int saved_errno =3D errno; =20 - domain_entry_dec(conn, node); + domain_nbentry_dec(conn, node->perms.p[0].id); node->perms =3D old_perms; /* No failure possible as above. */ - domain_entry_inc(conn, node); + domain_nbentry_inc(conn, node->perms.p[0].id); =20 errno =3D saved_errno; return errno; @@ -2383,7 +2383,7 @@ void setup_structure(bool live_update) manual_node("/tool/xenstored", NULL); manual_node("@releaseDomain", NULL); manual_node("@introduceDomain", NULL); - domain_entry_fix(dom0_domid, 5, true); + domain_nbentry_fix(dom0_domid, 5, true); } =20 check_store(); @@ -3391,7 +3391,7 @@ void read_state_node(const void *ctx, const void *sta= te) if (write_node_raw(NULL, &key, node, true)) barf("write node error restoring node"); =20 - if (domain_entry_inc(&conn, node)) + if (domain_nbentry_inc(&conn, node->perms.p[0].id)) barf("node accounting error restoring node"); =20 talloc_free(node); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 14fd84c288..b737a77683 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -249,7 +249,7 @@ static int domain_tree_remove_sub(const void *ctx, stru= ct connection *conn, domain->nbentry--; node->perms.p[0].id =3D priv_domid; node->acc.memory =3D 0; - domain_entry_inc(NULL, node); + domain_nbentry_inc(NULL, priv_domid); if (write_node_raw(NULL, &key, node, true)) { /* That's unfortunate. We only can try to continue. */ syslog(LOG_ERR, @@ -569,7 +569,7 @@ int acc_fix_domains(struct list_head *head, bool update) int cnt; =20 list_for_each_entry(cd, head, list) { - cnt =3D domain_entry_fix(cd->domid, cd->nbentry, update); + cnt =3D domain_nbentry_fix(cd->domid, cd->nbentry, update); if (!update) { if (cnt >=3D quota_nb_entry_per_domain) return ENOSPC; @@ -614,18 +614,19 @@ static struct changed_domain *acc_get_changed_domain(= const void *ctx, return cd; } =20 -int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, - unsigned int domid) +static int acc_add_dom_nbentry(const void *ctx, struct list_head *head, in= t val, + unsigned int domid) { struct changed_domain *cd; =20 cd =3D acc_get_changed_domain(ctx, head, domid); if (!cd) - return errno; + return 0; =20 + errno =3D 0; cd->nbentry +=3D val; =20 - return 0; + return cd->nbentry; } =20 static void domain_conn_reset(struct domain *domain) @@ -995,30 +996,6 @@ void domain_deinit(void) xenevtchn_unbind(xce_handle, virq_port); } =20 -int domain_entry_inc(struct connection *conn, struct node *node) -{ - struct domain *d; - unsigned int domid; - - if (!node->perms.p) - return 0; - - domid =3D node->perms.p[0].id; - - if (conn && conn->transaction) { - transaction_entry_inc(conn->transaction, domid); - } else { - d =3D (conn && domid =3D=3D conn->id && conn->domain) ? conn->domain - : find_or_alloc_existing_domain(domid); - if (d) - d->nbentry++; - else - return ENOMEM; - } - - return 0; -} - /* * Check whether a domain was created before or after a specific generation * count (used for testing whether a node permission is older than a domai= n). @@ -1086,62 +1063,67 @@ int domain_adjust_node_perms(struct node *node) return 0; } =20 -void domain_entry_dec(struct connection *conn, struct node *node) +static int domain_nbentry_add(struct connection *conn, unsigned int domid, + int add, bool dom_exists) { struct domain *d; - unsigned int domid; - - if (!node->perms.p) - return; + struct list_head *head; + int ret; =20 - domid =3D node->perms.p ? node->perms.p[0].id : conn->id; + if (conn && domid =3D=3D conn->id && conn->domain) + d =3D conn->domain; + else if (dom_exists) { + d =3D find_domain_struct(domid); + if (!d) { + errno =3D ENOENT; + corrupt(conn, "Missing domain %u\n", domid); + return -1; + } + } else { + d =3D find_or_alloc_existing_domain(domid); + if (!d) { + errno =3D ENOMEM; + return -1; + } + } =20 if (conn && conn->transaction) { - transaction_entry_dec(conn->transaction, domid); - } else { - d =3D (conn && domid =3D=3D conn->id && conn->domain) ? conn->domain - : find_domain_struct(domid); - if (d) { - d->nbentry--; - } else { - errno =3D ENOENT; - corrupt(conn, - "Node \"%s\" owned by non-existing domain %u\n", - node->name, domid); + head =3D transaction_get_changed_domains(conn->transaction); + ret =3D acc_add_dom_nbentry(conn->transaction, head, add, domid); + if (errno) { + fail_transaction(conn->transaction); + return -1; } + return d->nbentry + ret; } + + d->nbentry +=3D add; + + return d->nbentry; } =20 -int domain_entry_fix(unsigned int domid, int num, bool update) +int domain_nbentry_inc(struct connection *conn, unsigned int domid) { - struct domain *d; - int cnt; + return (domain_nbentry_add(conn, domid, 1, false) < 0) ? errno : 0; +} =20 - if (update) { - d =3D find_domain_struct(domid); - assert(d); - } else { - /* - * We are called first with update =3D=3D false in order to catch - * any error. So do a possible allocation and check for error - * only in this case, as in the case of update =3D=3D true nothing - * can go wrong anymore as the allocation already happened. - */ - d =3D find_or_alloc_existing_domain(domid); - if (!d) - return -1; - } +int domain_nbentry_dec(struct connection *conn, unsigned int domid) +{ + return (domain_nbentry_add(conn, domid, -1, true) < 0) ? errno : 0; +} =20 - cnt =3D d->nbentry + num; - assert(cnt >=3D 0); +int domain_nbentry_fix(unsigned int domid, int num, bool update) +{ + int ret; =20 - if (update) - d->nbentry =3D cnt; + ret =3D domain_nbentry_add(NULL, domid, update ? num : 0, update); + if (ret < 0 || update) + return ret; =20 - return domid_is_unprivileged(domid) ? cnt : 0; + return domid_is_unprivileged(domid) ? ret + num : 0; } =20 -int domain_entry(struct connection *conn) +int domain_nbentry(struct connection *conn) { return (domain_is_unprivileged(conn)) ? conn->domain->nbentry diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 9e20d2b17d..1e402f2609 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -66,10 +66,10 @@ int domain_adjust_node_perms(struct node *node); int domain_alloc_permrefs(struct node_perms *perms); =20 /* Quota manipulation */ -int domain_entry_inc(struct connection *conn, struct node *); -void domain_entry_dec(struct connection *conn, struct node *); -int domain_entry_fix(unsigned int domid, int num, bool update); -int domain_entry(struct connection *conn); +int domain_nbentry_inc(struct connection *conn, unsigned int domid); +int domain_nbentry_dec(struct connection *conn, unsigned int domid); +int domain_nbentry_fix(unsigned int domid, int num, bool update); +int domain_nbentry(struct connection *conn); int domain_memory_add(unsigned int domid, int mem, bool no_quota_check); =20 /* @@ -99,8 +99,6 @@ void domain_outstanding_domid_dec(unsigned int domid); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); int acc_fix_domains(struct list_head *head, bool update); -int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, - unsigned int domid); =20 /* Write rate limiting */ =20 diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 89b92f0baf..82e5e66c18 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -548,20 +548,9 @@ int do_transaction_end(const void *ctx, struct connect= ion *conn, return 0; } =20 -void transaction_entry_inc(struct transaction *trans, unsigned int domid) +struct list_head *transaction_get_changed_domains(struct transaction *tran= s) { - if (acc_add_dom_nbentry(trans, &trans->changed_domains, 1, domid)) { - /* Let the transaction fail. */ - trans->fail =3D true; - } -} - -void transaction_entry_dec(struct transaction *trans, unsigned int domid) -{ - if (acc_add_dom_nbentry(trans, &trans->changed_domains, -1, domid)) { - /* Let the transaction fail. */ - trans->fail =3D true; - } + return &trans->changed_domains; } =20 void fail_transaction(struct transaction *trans) diff --git a/tools/xenstore/xenstored_transaction.h b/tools/xenstore/xensto= red_transaction.h index 3417303f94..b6f8cb7d0a 100644 --- a/tools/xenstore/xenstored_transaction.h +++ b/tools/xenstore/xenstored_transaction.h @@ -36,10 +36,6 @@ int do_transaction_end(const void *ctx, struct connectio= n *conn, =20 struct transaction *transaction_lookup(struct connection *conn, uint32_t i= d); =20 -/* inc/dec entry number local to trans while changing a node */ -void transaction_entry_inc(struct transaction *trans, unsigned int domid); -void transaction_entry_dec(struct transaction *trans, unsigned int domid); - /* This node was accessed. */ int __must_check access_node(struct connection *conn, struct node *node, enum node_access_type type, TDB_DATA *key); @@ -54,6 +50,9 @@ void transaction_prepend(struct connection *conn, const c= har *name, /* Mark the transaction as failed. This will prevent it to be committed. */ void fail_transaction(struct transaction *trans); =20 +/* Get the list head of the changed domains. */ +struct list_head *transaction_get_changed_domains(struct transaction *tran= s); + void conn_delete_all_transactions(struct connection *conn); int check_transactions(struct hashtable *hash); =20 --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317436; cv=none; d=zohomail.com; s=zohoarc; b=VZ1PDTQMyHqIJAcBDJTlpMMw7juaKjr9G6zFCJ8IT+8jmf/hC8ts+tAuGWVl3Bi7Lmc2qi7cfrqH6B+xMQH/eAiZvQg044qy/wDPCyq5HyG1JHzJ+pnQzUK89dm2U3B0kiOMYvSz8tMZgXK6eBSaNTyhJFBx31swd7NweBLIeYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317436; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E0EnVO0aZYolAaiP6qGG7pTwSLxkIEF5XkBdvMekgyk=; b=m85R62s0BWPrE8iPRofuyizsWTJs4VB89dMqnJwRiK9UIf2zK+HXq9DGUQR0hS/bsqD95TEXN7B9qKMoTONEk6uyYAiJUmvwrC6e+ZRLo3IsjPAm0g4nO4YCMNjLhKVycdH2f0b8Jhqpk3sC0usaetoqyRouQgxAjq2U9EY8bEY= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317436042161.3821576104882; Tue, 1 Nov 2022 08:43:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434972.687908 (Exim 4.92) (envelope-from ) id 1optQO-0002vH-En; Tue, 01 Nov 2022 15:43:36 +0000 Received: by outflank-mailman (output) from mailman id 434972.687908; Tue, 01 Nov 2022 15:43:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQO-0002tJ-9d; Tue, 01 Nov 2022 15:43:36 +0000 Received: by outflank-mailman (input) for mailman id 434972; Tue, 01 Nov 2022 15:43:35 +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 1optDD-0007Bd-Ln for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:29:59 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0b7c0860-59fa-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 16:29:59 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B0D111F8E3; Tue, 1 Nov 2022 15:29:58 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 828381346F; Tue, 1 Nov 2022 15:29:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7z17HnY7YWMYYQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:29:58 +0000 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: 0b7c0860-59fa-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316598; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E0EnVO0aZYolAaiP6qGG7pTwSLxkIEF5XkBdvMekgyk=; b=hHzm9gqbBIbfmvXUshM5RoHjqnOu/zNp8CQR1IJ87mbtBAEmKfoIblzWK+VjbElb5T/OEu XdPBz/nP50myYPQJ2i/WT/tJCJX9CJhnZQJfrAFgJiHv3hVd1+VDlls8DXO+7G1RuWFXYK 8y2zmaa//bnv7roGpGGHu5LFXRL/FXo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 13/20] tools/xenstore: don't allow creating too many nodes in a transaction Date: Tue, 1 Nov 2022 16:28:35 +0100 Message-Id: <20221101152842.4257-14-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317436497100001 Content-Type: text/plain; charset="utf-8" The accounting for the number of nodes of a domain in an active transaction is not working correctly, as it allows to create arbitrary number of nodes. The transaction will finally fail due to exceeding the number of nodes quota, but before closing the transaction an unprivileged guest could cause Xenstore to use a lot of memory. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_domain.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index b737a77683..529ffb522a 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1125,9 +1125,8 @@ int domain_nbentry_fix(unsigned int domid, int num, b= ool update) =20 int domain_nbentry(struct connection *conn) { - return (domain_is_unprivileged(conn)) - ? conn->domain->nbentry - : 0; + return domain_is_unprivileged(conn) + ? domain_nbentry_add(conn, conn->id, 0, true) : 0; } =20 static bool domain_chk_quota(struct domain *domain, int mem) --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667316931; cv=none; d=zohomail.com; s=zohoarc; b=L5uhcZnkzDk4C+/4+a89h3jbf7iXmjBvaRIIHTkNztRzvl2llXhAN7h3e7sz76WGzMQP5R30Csnzy8lAtmfDBO8SITp/KPonHATw8yuK/4OvILbMkBQqchSUTXceyK7K+rBtK28MYur7tj6sXvCXi1iTiPJum8Qc1bZiwNcryCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667316931; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OXW2q3TSE2sqfE+CLKAdRKeOGAyBZRR57o9SMNJeWXg=; b=Rjr+bp3C5d2sCiJGQ0lDpmxEdicPpsY7kVsveFijM/REEMV1AfjhpNFth6Bed9WL/oBApvaq2EDOCz+79P3hAbM+dY9hxdlre5bux9vldMQJfXEdO6/naLHJ7tKounXXMO20Qm5pz+l5IrJzeQ2aF3HsdVbWOd9tiqpxsGRCjME= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 166731693104370.27500162078286; Tue, 1 Nov 2022 08:35:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434893.687682 (Exim 4.92) (envelope-from ) id 1optIB-00061c-SF; Tue, 01 Nov 2022 15:35:07 +0000 Received: by outflank-mailman (output) from mailman id 434893.687682; Tue, 01 Nov 2022 15:35:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optIB-00061S-PN; Tue, 01 Nov 2022 15:35:07 +0000 Received: by outflank-mailman (input) for mailman id 434893; Tue, 01 Nov 2022 15:35:06 +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 1optDJ-0007Bd-Od for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:30:05 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0ece2237-59fa-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 16:30:04 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 48C743385D; Tue, 1 Nov 2022 15:30:04 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1A3B71346F; Tue, 1 Nov 2022 15:30:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id xksRBXw7YWNGYQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:30:04 +0000 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: 0ece2237-59fa-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316604; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OXW2q3TSE2sqfE+CLKAdRKeOGAyBZRR57o9SMNJeWXg=; b=pc2W4hcBKUl9aOOF72kOOB4n9AKlmfC1e8IkhndZQOTiqKbPKFuijJs0z9Y6+sW1T08mzB OKo2cL5KltYgbWsalH1cehr4oR+QcU0I/IYnvH/9LdCL4MNVlfMNOXndZ/HgL9uIsu9yWv SMShbQdmKerTHLJN4putmEXddYa3JQI= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 14/20] tools/xenstore: replace literal domid 0 with dom0_domid Date: Tue, 1 Nov 2022 16:28:36 +0100 Message-Id: <20221101152842.4257-15-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667316932065100001 Content-Type: text/plain; charset="utf-8" There are some places left where dom0 is associated with domid 0. Use dom0_domid instead. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - new patch --- tools/xenstore/xenstored_core.c | 5 +++-- tools/xenstore/xenstored_domain.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 5fd4f8e606..5013f8b909 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2302,9 +2302,10 @@ static void accept_connection(int sock) return; =20 conn =3D new_connection(&socket_funcs); - if (conn) + if (conn) { conn->fd =3D fd; - else + conn->id =3D dom0_domid; + } else close(fd); } #endif diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 529ffb522a..0f1c903ee6 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -324,7 +324,7 @@ static int destroy_domain(void *_domain) if (domain->interface) { /* Domain 0 was mapped by dom0_init, so it must be unmapped using munmap() and not the grant unmap call. */ - if (domain->domid =3D=3D 0) + if (domain->domid =3D=3D dom0_domid) unmap_xenbus(domain->interface); else unmap_interface(domain->interface); @@ -414,7 +414,7 @@ void handle_event(void) =20 static bool domid_is_unprivileged(unsigned int domid) { - return domid !=3D 0 && domid !=3D priv_domid; + return domid !=3D dom0_domid && domid !=3D priv_domid; } =20 bool domain_is_unprivileged(struct connection *conn) @@ -806,7 +806,7 @@ static struct domain *onearg_domain(struct connection *= conn, return ERR_PTR(-EINVAL); =20 domid =3D atoi(domid_str); - if (!domid) + if (domid =3D=3D dom0_domid) return ERR_PTR(-EINVAL); =20 return find_connected_domain(domid); @@ -1009,7 +1009,7 @@ static int chk_domain_generation(unsigned int domid, = uint64_t gen) { struct domain *d; =20 - if (!xc_handle && domid =3D=3D 0) + if (!xc_handle && domid =3D=3D dom0_domid) return 1; =20 d =3D find_domain_struct(domid); --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317436; cv=none; d=zohomail.com; s=zohoarc; b=GSc953wP9zMkjVC/kLC28CdlQZ3Ye/VfHwgQ7giesN8yD/bAr3IsKxLw20FEJ/sntJvPUwSEpYUG2Tcbd5q71jyvtXJ54aNb570R3Dm0sjR0sT08Qw3dOpMwf6Q/Y1USi5fVoRE2M3vBr4r0FlamMnY7/8lisCzDo5G9BCfe9Ks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317436; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vs7tzrOYBYmkzYl4ReCdb5HC0Yd5c99GD/sLiCRSObs=; b=VGVE/3SRhzFl8Cdab9DhURIUriF4Y6/Mu3ORCo3VhZmF4Uc1UyYtPqVLTVTa3wGamooKo/0MT0AhYF2Dn1j6bM5x2py3ea6CdHxqUBVjJLXvRP+m4n3ISlwSL8hHEPp/viSz8jAUSsj4MvcIXRljBuzQGvatmON6pQpY4bOBR24= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317436158149.96690937910853; Tue, 1 Nov 2022 08:43:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434967.687899 (Exim 4.92) (envelope-from ) id 1optQN-0002mm-UM; Tue, 01 Nov 2022 15:43:35 +0000 Received: by outflank-mailman (output) from mailman id 434967.687899; Tue, 01 Nov 2022 15:43:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQN-0002mf-QQ; Tue, 01 Nov 2022 15:43:35 +0000 Received: by outflank-mailman (input) for mailman id 434967; Tue, 01 Nov 2022 15:43:34 +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 1optDO-0007Bd-QY for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:30:10 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1221cb66-59fa-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 16:30:10 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D61673385D; Tue, 1 Nov 2022 15:30:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A94561346F; Tue, 1 Nov 2022 15:30:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ryH+J4E7YWNRYQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:30:09 +0000 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: 1221cb66-59fa-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316609; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vs7tzrOYBYmkzYl4ReCdb5HC0Yd5c99GD/sLiCRSObs=; b=JyayYnxYUI0yFc9zniEKm81TdEP1b/ntvCh06rddcmY1ci4r4xDwFisg+YxZctujASetHc KGj17238bpgMoSPs87kJ6y1pbGQ7iSmIuNYw2uXTRJ+hK5CQA9nRZw626TbTd3J88cGR/g HLlAZbTFJSeiacENHkHtB2xy+bRZFJ4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 15/20] tools/xenstore: make domain_is_unprivileged() an inline function Date: Tue, 1 Nov 2022 16:28:37 +0100 Message-Id: <20221101152842.4257-16-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317438302100005 Content-Type: text/plain; charset="utf-8" clang is complaining about a NULL dereference for constructs like: domain_is_unprivileged(conn) ? conn->in : NULL as it can't know that domain_is_unprivileged(conn) will return false if conn is NULL. Fix that by making domain_is_unprivileged() an inline function (and related to that domid_is_unprivileged(), too). In order not having to make struct domain public, use conn->id instead of conn->domain->domid for the test. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- tools/xenstore/xenstored_core.h | 10 ++++++++++ tools/xenstore/xenstored_domain.c | 11 ----------- tools/xenstore/xenstored_domain.h | 2 -- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 37006d508d..3c4e27d0dd 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -297,6 +297,16 @@ void unmap_xenbus(void *interface); =20 static inline int xenbus_master_domid(void) { return dom0_domid; } =20 +static inline bool domid_is_unprivileged(unsigned int domid) +{ + return domid !=3D dom0_domid && domid !=3D priv_domid; +} + +static inline bool domain_is_unprivileged(const struct connection *conn) +{ + return conn && domid_is_unprivileged(conn->id); +} + /* Return the event channel used by xenbus. */ evtchn_port_t xenbus_evtchn(void); =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 0f1c903ee6..368b9bc2b7 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -412,17 +412,6 @@ void handle_event(void) barf_perror("Failed to write to event fd"); } =20 -static bool domid_is_unprivileged(unsigned int domid) -{ - return domid !=3D dom0_domid && domid !=3D priv_domid; -} - -bool domain_is_unprivileged(struct connection *conn) -{ - return conn && conn->domain && - domid_is_unprivileged(conn->domain->domid); -} - static char *talloc_domain_path(const void *context, unsigned int domid) { return talloc_asprintf(context, "/local/domain/%u", domid); diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 1e402f2609..22996e2576 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -59,8 +59,6 @@ void ignore_connection(struct connection *conn, unsigned = int err); /* Returns the implicit path of a connection (only domains have this) */ const char *get_implicit_path(const struct connection *conn); =20 -bool domain_is_unprivileged(struct connection *conn); - /* Remove node permissions for no longer existing domains. */ int domain_adjust_node_perms(struct node *node); int domain_alloc_permrefs(struct node_perms *perms); --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317438; cv=none; d=zohomail.com; s=zohoarc; b=STuKpUuu+3CxGpwphGL8tH8c8l7KOjHSpoZD0EpxDUqoRHtwZVI+TyibLzSSfvFtkzoFwGrAbrmX9GJt7y6sIDaBAoP4NfilASiPHbgmmvcQ0UosjuZHYj8NEssN7eDOv7ipet+ur02G7C8xBLoqxCBBH/RssjY0kirIJgQ0wEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317438; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EV5pCY35LkOt79N6jfSZOmuhj6wp/oTOWnMIlMFabww=; b=VhMhqeHgdQ7H3y2c78eoQtFNcgzq1416QtmO4bc3X8h9mfsQdEvHULiSk2HGPBYjILTtwRBkHaoBQOdlKrBbmfv9L2njoe2cFGXUFGql/mmKAlC5AAGrSJIycP0KqVdXpuR0BKdSPI5+psIoS389VxQzLb02AIIanucA7LRL+do= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317438167979.1101010947299; Tue, 1 Nov 2022 08:43:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434979.687949 (Exim 4.92) (envelope-from ) id 1optQR-0003z5-R1; Tue, 01 Nov 2022 15:43:39 +0000 Received: by outflank-mailman (output) from mailman id 434979.687949; Tue, 01 Nov 2022 15:43:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQR-0003wZ-Jk; Tue, 01 Nov 2022 15:43:39 +0000 Received: by outflank-mailman (input) for mailman id 434979; Tue, 01 Nov 2022 15:43:37 +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 1optDU-0007Bd-Ai for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:30:16 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 15709a41-59fa-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 16:30:15 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 67CB53385D; Tue, 1 Nov 2022 15:30:15 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3B03A1346F; Tue, 1 Nov 2022 15:30:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PZsPDYc7YWNeYQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:30:15 +0000 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: 15709a41-59fa-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316615; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EV5pCY35LkOt79N6jfSZOmuhj6wp/oTOWnMIlMFabww=; b=GRx9hABOt4TyefgU+wj81x3BQMxKCDd14fhzqJ5Tfds0etLA/HyNb4T+OTHrqNx7PsS3LN q/aQqm5siFsg0Aorcp3txVxTKg261+rDl3ERYDowpX6kfe5a9Izak8jQBVSo2fXgb2TM/y n++oVlUZeHXDYSkSTKW4xx5z1HdTaIA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 16/20] tools/xenstore: let chk_domain_generation() return a bool Date: Tue, 1 Nov 2022 16:28:38 +0100 Message-Id: <20221101152842.4257-17-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317440289100009 Content-Type: text/plain; charset="utf-8" Instead of returning 0 or 1 let chk_domain_generation() return a boolean value. Simplify the only caller by removing the ret variable. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/xenstored_domain.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 368b9bc2b7..3d460a6fa8 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -990,20 +990,20 @@ void domain_deinit(void) * count (used for testing whether a node permission is older than a domai= n). * * Return values: - * 0: domain has higher generation count (it is younger than a node with = the - * given count), or domain isn't existing any longer - * 1: domain is older than the node + * false: domain has higher generation count (it is younger than a node w= ith + * the given count), or domain isn't existing any longer + * true: domain is older than the node */ -static int chk_domain_generation(unsigned int domid, uint64_t gen) +static bool chk_domain_generation(unsigned int domid, uint64_t gen) { struct domain *d; =20 if (!xc_handle && domid =3D=3D dom0_domid) - return 1; + return true; =20 d =3D find_domain_struct(domid); =20 - return (d && d->generation <=3D gen) ? 1 : 0; + return d && d->generation <=3D gen; } =20 /* @@ -1038,14 +1038,12 @@ int domain_alloc_permrefs(struct node_perms *perms) int domain_adjust_node_perms(struct node *node) { unsigned int i; - int ret; =20 for (i =3D 1; i < node->perms.num; i++) { if (node->perms.p[i].perms & XS_PERM_IGNORE) continue; - ret =3D chk_domain_generation(node->perms.p[i].id, - node->generation); - if (!ret) + if (!chk_domain_generation(node->perms.p[i].id, + node->generation)) node->perms.p[i].perms |=3D XS_PERM_IGNORE; } =20 --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317440; cv=none; d=zohomail.com; s=zohoarc; b=GS3kCRf/UP2n3+Gr7R1B3A9eW9F93gADUs7rCe3rUEbufVKBHyxfTn7q+qKeZiK0WV6T91NU2MXqzowjRt8vge6Llpvajq9T2gHUc6sURXPcciPTjbN+KU7pYMfXHvcniiQoyC/wxBd5HfxZBn22zntj0lwUNsu92I/daj/MDjE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317440; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ic6QdQsT3IiF6Ltj3wF/G4ESqbAyko/szkpr1ypz+8c=; b=X5GgYaB4JAyuM5rnqOBao4CLEMyA9ClOd4p+VOk7ADeNnOBltwvEvljaVsaagXBXvb0jfjO6ud+oLJ6l4U/mUQdP6IJ0uCM1D4WvRDPsJg7V168EnHgYvq/phbqWDI0unrF8ZEL3+D9fnZOiSVhBUCFoTBj+L2hP63d0z893KEc= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317440137771.9749241360798; Tue, 1 Nov 2022 08:44:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434982.687971 (Exim 4.92) (envelope-from ) id 1optQW-0004ik-Kl; Tue, 01 Nov 2022 15:43:44 +0000 Received: by outflank-mailman (output) from mailman id 434982.687971; Tue, 01 Nov 2022 15:43:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQW-0004iD-Cc; Tue, 01 Nov 2022 15:43:44 +0000 Received: by outflank-mailman (input) for mailman id 434982; Tue, 01 Nov 2022 15:43: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 1optDa-0007Bd-59 for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:30:22 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 18bfe960-59fa-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 16:30:21 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F00081F90F; Tue, 1 Nov 2022 15:30:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C4CA81346F; Tue, 1 Nov 2022 15:30:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sFyNLow7YWNqYQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:30:20 +0000 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: 18bfe960-59fa-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316620; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ic6QdQsT3IiF6Ltj3wF/G4ESqbAyko/szkpr1ypz+8c=; b=tRkxrFYV3oaB/2utzN949AwMp4KgL1SdgHyhRiBQW6W5TqBAHM4BNUS6x4vFwpgMq6oGYU BOwywZvi2T2Cyd3Id+NmSYyZI1eHlWz99UzigKQJ5T7bTGiilX1EVe1yVf7eCZRO4eV2Cu 5eRpY9D3VSDjUASKrKfbzg5rCjAcUxg= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 17/20] tools/xenstore: switch hashtable to use the talloc framework Date: Tue, 1 Nov 2022 16:28:39 +0100 Message-Id: <20221101152842.4257-18-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317442330100013 Content-Type: text/plain; charset="utf-8" Instead of using malloc() and friends, let the hashtable implementation use the talloc framework. Signed-off-by: Juergen Gross --- tools/xenstore/hashtable.c | 86 ++++++++++++------------------- tools/xenstore/hashtable.h | 3 +- tools/xenstore/xenstored_core.c | 5 +- tools/xenstore/xenstored_domain.c | 2 +- 4 files changed, 39 insertions(+), 57 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 7a1548c490..1c8656e016 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include "talloc.h" =20 struct entry { @@ -50,7 +52,7 @@ indexFor(unsigned int tablelength, unsigned int hashvalue= ) { =20 /*************************************************************************= ****/ struct hashtable * -create_hashtable(unsigned int minsize, +create_hashtable(const void *ctx, unsigned int minsize, unsigned int (*hashf) (void*), int (*eqf) (void*,void*), unsigned int flags) @@ -66,10 +68,10 @@ create_hashtable(unsigned int minsize, if (primes[pindex] > minsize) { size =3D primes[pindex]; break; } } =20 - h =3D (struct hashtable *)calloc(1, sizeof(struct hashtable)); + h =3D talloc_zero(ctx, struct hashtable); if (NULL =3D=3D h) goto err0; - h->table =3D (struct entry **)calloc(size, sizeof(struct entry *)); + h->table =3D talloc_zero_array(h, struct entry *, size); if (NULL =3D=3D h->table) goto err1; =20 @@ -83,7 +85,7 @@ create_hashtable(unsigned int minsize, return h; =20 err1: - free(h); + talloc_free(h); err0: return NULL; } @@ -115,47 +117,32 @@ hashtable_expand(struct hashtable *h) if (h->primeindex =3D=3D (prime_table_length - 1)) return 0; newsize =3D primes[++(h->primeindex)]; =20 - newtable =3D (struct entry **)calloc(newsize, sizeof(struct entry*)); - if (NULL !=3D newtable) + newtable =3D talloc_realloc(h, h->table, struct entry *, newsize); + if (!newtable) { - /* This algorithm is not 'stable'. ie. it reverses the list - * when it transfers entries between the tables */ - for (i =3D 0; i < h->tablelength; i++) { - while (NULL !=3D (e =3D h->table[i])) { - h->table[i] =3D e->next; - index =3D indexFor(newsize,e->h); + h->primeindex--; + return 0; + } + + h->table =3D newtable; + memset(newtable + h->tablelength, 0, + (newsize - h->tablelength) * sizeof(*newtable)); + for (i =3D 0; i < h->tablelength; i++) { + for (pE =3D &(newtable[i]), e =3D *pE; e !=3D NULL; e =3D *pE) { + index =3D indexFor(newsize,e->h); + if (index =3D=3D i) + { + pE =3D &(e->next); + } + else + { + *pE =3D e->next; e->next =3D newtable[index]; newtable[index] =3D e; } } - free(h->table); - h->table =3D newtable; - } - /* Plan B: realloc instead */ - else=20 - { - newtable =3D (struct entry **) - realloc(h->table, newsize * sizeof(struct entry *)); - if (NULL =3D=3D newtable) { (h->primeindex)--; return 0; } - h->table =3D newtable; - memset(newtable + h->tablelength, 0, - (newsize - h->tablelength) * sizeof(*newtable)); - for (i =3D 0; i < h->tablelength; i++) { - for (pE =3D &(newtable[i]), e =3D *pE; e !=3D NULL; e =3D *pE)= { - index =3D indexFor(newsize,e->h); - if (index =3D=3D i) - { - pE =3D &(e->next); - } - else - { - *pE =3D e->next; - e->next =3D newtable[index]; - newtable[index] =3D e; - } - } - } } + h->tablelength =3D newsize; h->loadlimit =3D (unsigned int) (((uint64_t)newsize * max_load_factor) / 100); @@ -184,7 +171,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) * element may be ok. Next time we insert, we'll try expanding aga= in.*/ hashtable_expand(h); } - e =3D (struct entry *)calloc(1, sizeof(struct entry)); + e =3D talloc_zero(h, struct entry); if (NULL =3D=3D e) { --(h->entrycount); return 0; } /*oom*/ e->h =3D hash(h,k); index =3D indexFor(h->tablelength,e->h); @@ -238,8 +225,8 @@ hashtable_remove(struct hashtable *h, void *k) h->entrycount--; v =3D e->v; if (h->flags & HASHTABLE_FREE_KEY) - free(e->k); - free(e); + talloc_free(e->k); + talloc_free(e); return v; } pE =3D &(e->next); @@ -280,25 +267,20 @@ void hashtable_destroy(struct hashtable *h) { unsigned int i; - struct entry *e, *f; + struct entry *e; struct entry **table =3D h->table; =20 for (i =3D 0; i < h->tablelength; i++) { - e =3D table[i]; - while (NULL !=3D e) + for (e =3D table[i]; e; e =3D e->next) { - f =3D e; - e =3D e->next; if (h->flags & HASHTABLE_FREE_KEY) - free(f->k); + talloc_free(e->k); if (h->flags & HASHTABLE_FREE_VALUE) - free(f->v); - free(f); + talloc_free(e->v); } } - free(h->table); - free(h); + talloc_free(h); } =20 /* diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index b31eeaea26..07fdc1a82b 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -9,6 +9,7 @@ struct hashtable; * create_hashtable =20 * @name create_hashtable + * @param ctx talloc context to use for allocations * @param minsize minimum initial size of hashtable * @param hashfunction function for hashing keys * @param key_eq_fn function for determining key equality @@ -22,7 +23,7 @@ struct hashtable; #define HASHTABLE_FREE_KEY (1U << 1) =20 struct hashtable * -create_hashtable(unsigned int minsize, +create_hashtable(const void *ctx, unsigned int minsize, unsigned int (*hashfunction) (void*), int (*key_eq_fn) (void*,void*), unsigned int flags diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 5013f8b909..9361ee7696 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2410,11 +2410,10 @@ static int keys_equal_fn(void *key1, void *key2) =20 int remember_string(struct hashtable *hash, const char *str) { - char *k =3D malloc(strlen(str) + 1); + char *k =3D talloc_strdup(NULL, str); =20 if (!k) return 0; - strcpy(k, str); return hashtable_insert(hash, k, (void *)1); } =20 @@ -2509,7 +2508,7 @@ void check_store(void) }; =20 /* Don't free values (they are all void *1) */ - reachable =3D create_hashtable(16, hash_from_key_fn, keys_equal_fn, + reachable =3D create_hashtable(NULL, 16, hash_from_key_fn, keys_equal_fn, HASHTABLE_FREE_KEY); if (!reachable) { log("check_store: ENOMEM"); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 3d460a6fa8..0bf35cd353 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -936,7 +936,7 @@ void domain_init(int evtfd) int rc; =20 /* Start with a random rather low domain count for the hashtable. */ - domhash =3D create_hashtable(8, domhash_fn, domeq_fn, 0); + domhash =3D create_hashtable(NULL, 8, domhash_fn, domeq_fn, 0); if (!domhash) barf_perror("Failed to allocate domain hashtable"); =20 --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317435; cv=none; d=zohomail.com; s=zohoarc; b=I2/QxlmaO81P/dnsbLcMXFPTEFokz1BwQBfRLkv3JM9wl/C40JnUX+fVQxp+tgEu8hWIvUJzPGroHItC8UHm68dD9905yBiWmzPcGvRTJ5rpTn3GkLKFv0Az3FhN0y6AIbkAiKkYjvgpgJ/7LovNIdw7MSNsgyL9RqzFNDaUv5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317435; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Zmqv1jjZI833QBU+Sj0Qlh8Q6xTSbx5Wk7y/ffO7mPc=; b=M2gt4dwLeMlrrWn4VWQ/qXTStB+szlhNPa0ZElhWCmvPFVGlf0RkTMSm3cTPc3HgpGUXB8ePcVz57BFgcVGEwj5FRDvGTHJPHhXT+SL4zUZA7/x35MHTsz7/DDi+XHnbI2+B18oRl2gI3zTqxQ1TlM410H99nt3QKzMx/8E9DT8= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 166731743546775.57794252224062; Tue, 1 Nov 2022 08:43:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434975.687930 (Exim 4.92) (envelope-from ) id 1optQP-0003Xc-Rz; Tue, 01 Nov 2022 15:43:37 +0000 Received: by outflank-mailman (output) from mailman id 434975.687930; Tue, 01 Nov 2022 15:43:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQP-0003Ts-NB; Tue, 01 Nov 2022 15:43:37 +0000 Received: by outflank-mailman (input) for mailman id 434975; Tue, 01 Nov 2022 15:43:36 +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 1optDf-0007Tl-FT for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:30:27 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1c1ccdb4-59fa-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:30:26 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 955E51F8CA; Tue, 1 Nov 2022 15:30:26 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5D57F1346F; Tue, 1 Nov 2022 15:30:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id h95oFZI7YWNzYQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:30:26 +0000 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: 1c1ccdb4-59fa-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316626; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zmqv1jjZI833QBU+Sj0Qlh8Q6xTSbx5Wk7y/ffO7mPc=; b=DQqxx27m1f+pKfkMF7ChunHMN3E8sERsgD7maErBhwwQX+N23pWIH5UC+abafJh0xEMkE1 rVQ9phzVjpds2mp7buNQ0yxBAFSVS6CgWwp9DAUDUfErcov+WzUplR4ZcYKxQ3lq79PGrO 7otG+23o+9ArqnZxWKOEJQeuP1yiabs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 18/20] tools/xenstore: make log macro globally available Date: Tue, 1 Nov 2022 16:28:40 +0100 Message-Id: <20221101152842.4257-19-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317436499100002 Content-Type: text/plain; charset="utf-8" Move the definition of the log() macro to xenstored_core.h in order to make it usable from other source files, too. While at it preserve errno from being modified. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - preserve errno (Julien Grall) --- tools/xenstore/xenstored_core.c | 14 -------------- tools/xenstore/xenstored_core.h | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 9361ee7696..e79d82cbff 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -88,20 +88,6 @@ TDB_CONTEXT *tdb_ctx =3D NULL; =20 static const char *sockmsg_string(enum xsd_sockmsg_type type); =20 -#define log(...) \ - do { \ - char *s =3D talloc_asprintf(NULL, __VA_ARGS__); \ - if (s) { \ - trace("%s\n", s); \ - syslog(LOG_ERR, "%s\n", s); \ - talloc_free(s); \ - } else { \ - trace("talloc failure during logging\n"); \ - syslog(LOG_ERR, "talloc failure during logging\n"); \ - } \ - } while (0) - - int quota_nb_entry_per_domain =3D 1000; int quota_nb_watch_per_domain =3D 128; int quota_max_entry_size =3D 2048; /* 2K */ diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 3c4e27d0dd..3b96ecd018 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -267,6 +267,21 @@ void trace(const char *fmt, ...) __attribute__ ((forma= t (printf, 1, 2))); void reopen_log(void); void close_log(void); =20 +#define log(...) \ + do { \ + int _saved_errno =3D errno; \ + char *s =3D talloc_asprintf(NULL, __VA_ARGS__); \ + if (s) { \ + trace("%s\n", s); \ + syslog(LOG_ERR, "%s\n", s); \ + talloc_free(s); \ + } else { \ + trace("talloc failure during logging\n"); \ + syslog(LOG_ERR, "talloc failure during logging\n"); \ + } \ + errno =3D _saved_errno; \ + } while (0) + extern int orig_argc; extern char **orig_argv; =20 --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317438; cv=none; d=zohomail.com; s=zohoarc; b=gDtDWH5A/eWJPqmiE0wdS8LJR5Y7roFX7VgLtOyQh8SRaMoHHYK5Bh4MEWMVP7FRUj9dObghLf8h/Kj5fO4LVE19Ja12kHaze5e92reZr9Zi2mxhgfcvxH3xddXWHZdgVmPWQGElKKwpWtoLXJ//bpnbd7GsdtpgjUaPMwLEr14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317438; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Jp/wq4hw5G22takTn0GXQsF4DTUlBtleEPwgDpe2N2w=; b=IELkXBGzb+KqaiJZGgPz/g7YqyGBEBbws67wRnnbWV7iO4Q3ONH0hUlWCVIIcZoQVW1tsbd4X5iCkIY/u78JwT4fIrBIdkCsMbvd71hXM+vZQF5bvkf0jSfTanIFYbTp85MXu3+rSl9z70WnWF/oR3Z68kbuSrthRdMcRkxOYGQ= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317438972786.2073274341483; Tue, 1 Nov 2022 08:43:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434977.687942 (Exim 4.92) (envelope-from ) id 1optQR-0003qz-6P; Tue, 01 Nov 2022 15:43:39 +0000 Received: by outflank-mailman (output) from mailman id 434977.687942; Tue, 01 Nov 2022 15:43:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQR-0003q9-26; Tue, 01 Nov 2022 15:43:39 +0000 Received: by outflank-mailman (input) for mailman id 434977; Tue, 01 Nov 2022 15:43:37 +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 1optDl-0007Tl-Fd for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:30:33 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1f7647a8-59fa-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:30:32 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3749F1F8CA; Tue, 1 Nov 2022 15:30:32 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E95471346F; Tue, 1 Nov 2022 15:30:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ACOxN5c7YWN8YQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:30:31 +0000 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: 1f7647a8-59fa-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316632; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jp/wq4hw5G22takTn0GXQsF4DTUlBtleEPwgDpe2N2w=; b=VOH4FDu+f21xeut1KkronhOOj6gpTJwpJrvxdsvQ7VelIq34XFnchQYDzHiiR9tfGBrCKA f7l592e6rFlBB6FdvA+G8+BWV2JeL9CBXeYz7StmdM/p0ZnsXlJ3FT/czpyBL2JOGZ7KXY Du1EhRWa1wCxXgWt5lRNAcMKBDf2bZ4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Anthony PERARD Subject: [PATCH 19/20] tools/xenstore: introduce trace classes Date: Tue, 1 Nov 2022 16:28:41 +0100 Message-Id: <20221101152842.4257-20-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317440323100011 Content-Type: text/plain; charset="utf-8" Make the xenstored internal trace configurable by adding classes which can be switched on and off independently from each other. Define the following classes: - obj: Creation and deletion of interesting "objects" (watch, transaction, connection) - io: incoming requests and outgoing responses - wrl: write limiting Per default "obj" and "io" are switched on. Entries written via trace() will always be printed (if tracing is on at all). Rename the misnamed xenstore-control commands "logfile" to "tracefile" and "log" to "trace". Add the capability to control the trace settings via the "trace" command and via a new "--trace-control" command line option. Add a missing trace_create() call for creating a transaction. Signed-off-by: Juergen Gross --- docs/misc/xenstore.txt | 18 +++++++---- tools/xenstore/xenstored_control.c | 41 +++++++++++++++++++----- tools/xenstore/xenstored_core.c | 44 +++++++++++++++++++++++--- tools/xenstore/xenstored_core.h | 6 ++++ tools/xenstore/xenstored_domain.c | 27 ++++++++-------- tools/xenstore/xenstored_transaction.c | 1 + 6 files changed, 105 insertions(+), 32 deletions(-) diff --git a/docs/misc/xenstore.txt b/docs/misc/xenstore.txt index 44428ae3a7..9db0385120 100644 --- a/docs/misc/xenstore.txt +++ b/docs/misc/xenstore.txt @@ -409,14 +409,8 @@ CONTROL |[|] error string in case of failure. -s can return "BUSY" in case of an active transaction, a retry of -s can be done in that case. - log|on - turn xenstore logging on - log|off - turn xenstore logging off - logfile| - log to specified file memreport|[] - print memory statistics to logfile (no + print memory statistics to tracefile (no specified) or to specific file print| print to syslog (xenstore runs as daemon) or @@ -432,6 +426,16 @@ CONTROL |[|] the domain quota-soft|[set ] like the "quota" command, but for soft-quota. + trace|[+|-] + without parameters: show possible trace switches + + activates trace entries for , + - deactivates trace entries for + trace|on + turn xenstore tracing on + trace|off + turn xenstore tracing off + tracefile| + trace to specified file help return list of supported commands for CONTROL =20 diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 41e6992591..0a985a1faa 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -179,9 +179,31 @@ static int do_control_check(const void *ctx, struct co= nnection *conn, return 0; } =20 -static int do_control_log(const void *ctx, struct connection *conn, - char **vec, int num) +static int do_control_trace(const void *ctx, struct connection *conn, + char **vec, int num) { + int ret; + + if (num =3D=3D 0) { + char *resp =3D talloc_asprintf(ctx, "Trace switch settings:\n"); + unsigned int idx; + bool on; + + if (!resp) + return ENOMEM; + for (idx =3D 0; trace_switches[idx]; idx++) { + on =3D trace_flags & (1u << idx); + resp =3D talloc_asprintf_append(resp, "%-8s: %s\n", + trace_switches[idx], + on ? "on" : "off"); + if (!resp) + return ENOMEM; + } + + send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); + return 0; + } + if (num !=3D 1) return EINVAL; =20 @@ -189,8 +211,11 @@ static int do_control_log(const void *ctx, struct conn= ection *conn, reopen_log(); else if (!strcmp(vec[0], "off")) close_log(); - else - return EINVAL; + else { + ret =3D set_trace_switch(vec[0]); + if (ret) + return ret; + } =20 send_ack(conn, XS_CONTROL); return 0; @@ -318,8 +343,8 @@ static int do_control_memreport(const void *ctx, struct= connection *conn, return 0; } #else -static int do_control_logfile(const void *ctx, struct connection *conn, - char **vec, int num) +static int do_control_tracefile(const void *ctx, struct connection *conn, + char **vec, int num) { if (num !=3D 1) return EINVAL; @@ -923,7 +948,7 @@ static int do_control_help(const void *, struct connect= ion *, char **, int); =20 static struct cmd_s cmds[] =3D { { "check", do_control_check, "" }, - { "log", do_control_log, "on|off" }, + { "trace", do_control_trace, "[on|off|[!]]" }, =20 #ifndef NO_LIVE_UPDATE /* @@ -949,7 +974,7 @@ static struct cmd_s cmds[] =3D { #ifdef __MINIOS__ { "memreport", do_control_memreport, "" }, #else - { "logfile", do_control_logfile, "" }, + { "tracefile", do_control_tracefile, "" }, { "memreport", do_control_memreport, "[]" }, #endif { "print", do_control_print, "" }, diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index e79d82cbff..86ef511ac0 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -85,6 +85,7 @@ static int reopen_log_pipe[2]; static int reopen_log_pipe0_pollfd_idx =3D -1; char *tracefile =3D NULL; TDB_CONTEXT *tdb_ctx =3D NULL; +unsigned int trace_flags =3D TRACE_OBJ | TRACE_IO; =20 static const char *sockmsg_string(enum xsd_sockmsg_type type); =20 @@ -139,13 +140,13 @@ static void trace_io(const struct connection *conn, time_t now; struct tm *tm; =20 - if (tracefd < 0) + if (tracefd < 0 || !(trace_flags & TRACE_IO)) return; =20 now =3D time(NULL); tm =3D localtime(&now); =20 - trace("%s %p %04d%02d%02d %02d:%02d:%02d %s (", + trace("io: %s %p %04d%02d%02d %02d:%02d:%02d %s (", out ? "OUT" : "IN", conn, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, @@ -158,12 +159,14 @@ static void trace_io(const struct connection *conn, =20 void trace_create(const void *data, const char *type) { - trace("CREATE %s %p\n", type, data); + if (trace_flags & TRACE_OBJ) + trace("obj: CREATE %s %p\n", type, data); } =20 void trace_destroy(const void *data, const char *type) { - trace("DESTROY %s %p\n", type, data); + if (trace_flags & TRACE_OBJ) + trace("obj: DESTROY %s %p\n", type, data); } =20 /** @@ -2590,6 +2593,8 @@ static void usage(void) " -N, --no-fork to request that the daemon does not fork,\n" " -P, --output-pid to request that the pid of the daemon is output= ,\n" " -T, --trace-file giving the file for logging, and\n" +" --trace-control [!] activate (no \"!\" prepended) or deacti= vate\n" +" a specific \n" " -E, --entry-nb limit the number of entries per domain,\n" " -S, --entry-size limit the size of entry per domain, and\n" " -W, --watch-nb limit the number of watches per domain,\n" @@ -2633,6 +2638,7 @@ static struct option options[] =3D { { "output-pid", 0, NULL, 'P' }, { "entry-size", 1, NULL, 'S' }, { "trace-file", 1, NULL, 'T' }, + { "trace-control", 1, NULL, 1 }, { "transaction", 1, NULL, 't' }, { "perm-nb", 1, NULL, 'A' }, { "path-max", 1, NULL, 'M' }, @@ -2707,6 +2713,33 @@ static void set_quota(const char *arg, bool soft) barf("unknown quota \"%s\"\n", arg); } =20 +/* Sorted by bit values of TRACE_* flags. Flag is (1u << index). */ +const char *trace_switches[] =3D { + "obj", "io", "wrl", + NULL +}; + +int set_trace_switch(const char *arg) +{ + bool remove =3D (arg[0] =3D=3D '!'); + unsigned int idx; + + if (remove) + arg++; + + for (idx =3D 0; trace_switches[idx]; idx++) { + if (!strcmp(arg, trace_switches[idx])) { + if (remove) + trace_flags &=3D ~(1u << idx); + else + trace_flags |=3D 1u << idx; + return 0; + } + } + + return EINVAL; +} + int main(int argc, char *argv[]) { int opt; @@ -2755,6 +2788,9 @@ int main(int argc, char *argv[]) case 'T': tracefile =3D optarg; break; + case 1: + set_trace_switch(optarg); + break; case 'I': if (optarg && !strcmp(optarg, "off")) tdb_flags =3D 0; diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 3b96ecd018..c85b15515c 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -287,6 +287,12 @@ extern char **orig_argv; =20 extern char *tracefile; extern int tracefd; +extern unsigned int trace_flags; +#define TRACE_OBJ 0x00000001 +#define TRACE_IO 0x00000002 +#define TRACE_WRL 0x00000004 +extern const char *trace_switches[]; +int set_trace_switch(const char *arg); =20 extern TDB_CONTEXT *tdb_ctx; extern int dom0_domid; diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 0bf35cd353..70d9e9572d 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1256,6 +1256,12 @@ static long wrl_ndomains; static wrl_creditt wrl_reserve; /* [-wrl_config_newdoms_dburst, +_gburst ]= */ static time_t wrl_log_last_warning; /* 0: no previous warning */ =20 +#define trace_wrl(...) \ +do { \ + if (trace_flags & TRACE_WRL) \ + trace("wrl: " __VA_ARGS__); \ +} while (0) + void wrl_gettime_now(struct wrl_timestampt *now_wt) { struct timespec now_ts; @@ -1361,12 +1367,9 @@ void wrl_credit_update(struct domain *domain, struct= wrl_timestampt now) =20 domain->wrl_timestamp =3D now; =20 - trace("wrl: dom %4d %6ld msec %9ld credit %9ld reserve" - " %9ld discard\n", - domain->domid, - msec, - (long)domain->wrl_credit, (long)wrl_reserve, - (long)surplus); + trace_wrl("dom %4d %6ld msec %9ld credit %9ld reserve %9ld discard\n", + domain->domid, msec, (long)domain->wrl_credit, + (long)wrl_reserve, (long)surplus); } =20 void wrl_check_timeout(struct domain *domain, @@ -1398,10 +1401,9 @@ void wrl_check_timeout(struct domain *domain, if (*ptimeout=3D=3D-1 || wakeup < *ptimeout) *ptimeout =3D wakeup; =20 - trace("wrl: domain %u credit=3D%ld (reserve=3D%ld) SLEEPING for %d\n", - domain->domid, - (long)domain->wrl_credit, (long)wrl_reserve, - wakeup); + trace_wrl("domain %u credit=3D%ld (reserve=3D%ld) SLEEPING for %d\n", + domain->domid, (long)domain->wrl_credit, (long)wrl_reserve, + wakeup); } =20 #define WRL_LOG(now, ...) \ @@ -1419,9 +1421,8 @@ void wrl_apply_debit_actual(struct domain *domain) wrl_credit_update(domain, now); =20 domain->wrl_credit -=3D wrl_config_writecost; - trace("wrl: domain %u credit=3D%ld (reserve=3D%ld)\n", - domain->domid, - (long)domain->wrl_credit, (long)wrl_reserve); + trace_wrl("domain %u credit=3D%ld (reserve=3D%ld)\n", domain->domid, + (long)domain->wrl_credit, (long)wrl_reserve); =20 if (domain->wrl_credit < 0) { if (!domain->wrl_delay_logged) { diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 82e5e66c18..1aa9d3cb3d 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -475,6 +475,7 @@ int do_transaction_start(const void *ctx, struct connec= tion *conn, if (!trans) return ENOMEM; =20 + trace_create(trans, "transaction"); INIT_LIST_HEAD(&trans->accessed); INIT_LIST_HEAD(&trans->changed_domains); trans->conn =3D conn; --=20 2.35.3 From nobody Wed May 15 19:31:09 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317436; cv=none; d=zohomail.com; s=zohoarc; b=RYT+hDprDmJodmuFi9OInsumpm0Z7vZPR0ncXUugdDvl2N/JWmrPRzVJtZAqM1PI/0JUvd24GONMToX0o61HoM7Jbqp9AiujEC8zatry8g/1aDtOp6INAvQBbtGQmv/FEJ/A053Z18d9hPP1LAwnFudRcrau2E5rtb3Y3Q8wc+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317436; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/+Sd+O8DwggSngPmK/S4X0Rtl1nPCQzxh+jG+tl/sB8=; b=iplfcqnkgxEOcxlgC350hpLQ77yCjUk7zvsK3rf5pTCw9Rk4GLHG41T+wbMVxEpKLfDecCEJVysrr/593IMecppggH7958qxOlsGM0cm8f6nVjRl8letFrMEGdD48c7tIqRHSSVPFDj+UCa4eHg2b4AgAg3GvF7u28OZsKx/saA= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317436072664.5262763034333; Tue, 1 Nov 2022 08:43:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434970.687904 (Exim 4.92) (envelope-from ) id 1optQO-0002pO-6b; Tue, 01 Nov 2022 15:43:36 +0000 Received: by outflank-mailman (output) from mailman id 434970.687904; Tue, 01 Nov 2022 15:43:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQO-0002p3-21; Tue, 01 Nov 2022 15:43:36 +0000 Received: by outflank-mailman (input) for mailman id 434970; Tue, 01 Nov 2022 15:43:34 +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 1optDq-0007Bd-SB for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:30:38 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 22c7567f-59fa-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 16:30:38 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C4FED1F8CA; Tue, 1 Nov 2022 15:30:37 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9490E1346F; Tue, 1 Nov 2022 15:30:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mFb7Ip07YWONYQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:30:37 +0000 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: 22c7567f-59fa-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/+Sd+O8DwggSngPmK/S4X0Rtl1nPCQzxh+jG+tl/sB8=; b=OZi+DTTliQy3mYT5OtMAMeO6qOucSYwr5MUNVeNgg2oypDwI8JKcFeZv2xvHG00kTNxpaI 98EQ5FftHfze3iM/f9hoP/P1J5BgG7+HjCF9IC7c9GsowoAGf+STae0SE9AnLfaV6elaQK N9lYVW8IlIaWMDKzuJQsWeoxfERjHeo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 20/20] tools/xenstore: let check_store() check the accounting data Date: Tue, 1 Nov 2022 16:28:42 +0100 Message-Id: <20221101152842.4257-21-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317438318100006 Content-Type: text/plain; charset="utf-8" Today check_store() is only testing the correctness of the node tree. Add verification of the accounting data (number of nodes) and correct the data if it is wrong. Do the initial check_store() call only after Xenstore entries of a live update have been read. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 62 ++++++++++++++++------ tools/xenstore/xenstored_domain.c | 86 +++++++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 4 ++ 3 files changed, 137 insertions(+), 15 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 86ef511ac0..ea0e6292d3 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2375,8 +2375,6 @@ void setup_structure(bool live_update) manual_node("@introduceDomain", NULL); domain_nbentry_fix(dom0_domid, 5, true); } - - check_store(); } =20 static unsigned int hash_from_key_fn(void *k) @@ -2419,20 +2417,28 @@ int remember_string(struct hashtable *hash, const c= har *str) * As we go, we record each node in the given reachable hashtable. These * entries will be used later in clean_store. */ + +struct check_store_data { + struct hashtable *reachable; + struct hashtable *domains; +}; + static int check_store_step(const void *ctx, struct connection *conn, struct node *node, void *arg) { - struct hashtable *reachable =3D arg; + struct check_store_data *data =3D arg; =20 - if (hashtable_search(reachable, (void *)node->name)) { + if (hashtable_search(data->reachable, (void *)node->name)) { log("check_store: '%s' is duplicated!", node->name); return recovery ? WALK_TREE_RM_CHILDENTRY : WALK_TREE_SKIP_CHILDREN; } =20 - if (!remember_string(reachable, node->name)) + if (!remember_string(data->reachable, node->name)) return WALK_TREE_ERROR_STOP; =20 + domain_check_acc_add(node, data->domains); + return WALK_TREE_OK; } =20 @@ -2482,37 +2488,61 @@ static int clean_store_(TDB_CONTEXT *tdb, TDB_DATA = key, TDB_DATA val, * Given the list of reachable nodes, iterate over the whole store, and * remove any that were not reached. */ -static void clean_store(struct hashtable *reachable) +static void clean_store(struct check_store_data *data) { - tdb_traverse(tdb_ctx, &clean_store_, reachable); + tdb_traverse(tdb_ctx, &clean_store_, data->reachable); + domain_check_acc(data->domains); } =20 +int check_store_path(const char *name, struct check_store_data *data) +{ + struct node *node; + + node =3D read_node(NULL, NULL, name); + if (!node) { + log("check_store: error %d reading special node '%s'", errno, + name); + return errno; + } + + return check_store_step(NULL, NULL, node, data); +} =20 void check_store(void) { - struct hashtable *reachable; struct walk_funcs walkfuncs =3D { .enter =3D check_store_step, .enoent =3D check_store_enoent, }; + struct check_store_data data; =20 /* Don't free values (they are all void *1) */ - reachable =3D create_hashtable(NULL, 16, hash_from_key_fn, keys_equal_fn, - HASHTABLE_FREE_KEY); - if (!reachable) { + data.reachable =3D create_hashtable(NULL, 16, hash_from_key_fn, + keys_equal_fn, HASHTABLE_FREE_KEY); + if (!data.reachable) { log("check_store: ENOMEM"); return; } =20 + data.domains =3D domain_check_acc_init(); + if (!data.domains) { + log("check_store: ENOMEM"); + goto out_hash; + } + log("Checking store ..."); - if (walk_node_tree(NULL, NULL, "/", &walkfuncs, reachable)) { + if (walk_node_tree(NULL, NULL, "/", &walkfuncs, &data)) { if (errno =3D=3D ENOMEM) log("check_store: ENOMEM"); - } else if (!check_transactions(reachable)) - clean_store(reachable); + } else if (!check_store_path("@introduceDomain", &data) && + !check_store_path("@releaseDomain", &data) && + !check_transactions(data.reachable)) + clean_store(&data); log("Checking store complete."); =20 - hashtable_destroy(reachable); + hashtable_destroy(data.domains); + out_hash: + hashtable_destroy(data.reachable); } =20 =20 @@ -2900,6 +2930,8 @@ int main(int argc, char *argv[]) lu_read_state(); #endif =20 + check_store(); + /* Get ready to listen to the tools. */ initialize_fds(&sock_pollfd_idx, &timeout); =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 70d9e9572d..582b78b0ee 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1569,6 +1569,92 @@ void read_state_connection(const void *ctx, const vo= id *state) read_state_buffered_data(ctx, conn, sc); } =20 +struct domain_acc { + unsigned int domid; + int nodes; +}; + +static int domain_check_acc_init_sub(void *k, void *v, void *arg) +{ + struct hashtable *domains =3D arg; + struct domain *d =3D v; + struct domain_acc *dom; + + dom =3D talloc_zero(NULL, struct domain_acc); + if (!dom) + return -1; + + dom->domid =3D d->domid; + /* + * Set the initial value to the negative one of the current domain. + * If everything is correct incrementing the value for each node will + * result in dom->nodes being 0 at the end. + */ + dom->nodes =3D -d->nbentry; + + if (!hashtable_insert(domains, &dom->domid, dom)) { + talloc_free(dom); + return -1; + } + + return 0; +} + +struct hashtable *domain_check_acc_init(void) +{ + struct hashtable *domains; + + domains =3D create_hashtable(NULL, 8, domhash_fn, domeq_fn, + HASHTABLE_FREE_VALUE); + if (!domains) + return NULL; + + if (hashtable_iterate(domhash, domain_check_acc_init_sub, domains)) { + hashtable_destroy(domains); + return NULL; + } + + return domains; +} + +void domain_check_acc_add(const struct node *node, struct hashtable *domai= ns) +{ + struct domain_acc *dom; + unsigned int domid; + + domid =3D node->perms.p[0].id; + dom =3D hashtable_search(domains, &domid); + if (!dom) + log("Node %s owned by unknown domain %u", node->name, domid); + else + dom->nodes++; +} + +static int domain_check_acc_sub(void *k, void *v, void *arg) +{ + struct domain_acc *dom =3D v; + struct domain *d; + + if (!dom->nodes) + return 0; + + log("Correct accounting data for domain %u: nodes are %d off", + dom->domid, dom->nodes); + + d =3D find_domain_struct(dom->domid); + if (!d) + return 0; + + d->nbentry +=3D dom->nodes; + + return 0; +} + +void domain_check_acc(struct hashtable *domains) +{ + hashtable_iterate(domains, domain_check_acc_sub, NULL); +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 22996e2576..dc4660861e 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -129,4 +129,8 @@ const char *dump_state_connections(FILE *fp); =20 void read_state_connection(const void *ctx, const void *state); =20 +struct hashtable *domain_check_acc_init(void); +void domain_check_acc_add(const struct node *node, struct hashtable *domai= ns); +void domain_check_acc(struct hashtable *domains); + #endif /* _XENSTORED_DOMAIN_H */ --=20 2.35.3