From patchwork Fri Mar 13 12:33:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maximilian Heyne X-Patchwork-Id: 11436849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D624C92C for ; Fri, 13 Mar 2020 12:35:35 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B33FE20724 for ; Fri, 13 Mar 2020 12:35:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="oCHEmouf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B33FE20724 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCjW6-0006VI-8Y; Fri, 13 Mar 2020 12:34:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCjVN-0006SW-0P for xen-devel@lists.xenproject.org; Fri, 13 Mar 2020 12:33:33 +0000 X-Inumbo-ID: d3fe9c14-6526-11ea-92cf-bc764e2007e4 Received: from smtp-fw-9101.amazon.com (unknown [207.171.184.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d3fe9c14-6526-11ea-92cf-bc764e2007e4; Fri, 13 Mar 2020 12:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1584102804; x=1615638804; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=BChTlQBLR5Hi7t+3wQCEI1Do3gF52UgIeaC1oWVTedE=; b=oCHEmouf9k8ZQ2uZkEiWAdSHsLxik3kPwLKr79KeKl6hFR0SQ0SUjo4E +CTq4R6/LAtkgvZaGKlc5hajq0GYAN4awsT44A9swDFk8bO29Nbs0rtEJ 94cGRjmfQ8L/mjSSM2FRDlvvEJFRxvyh++Q3sxJkx21xcieixEzAh04y4 8=; IronPort-SDR: wRaDgsisarsoZYkLJvW8dTehwKbheRz/m1VJ3n2NI+miGACj9vclYxnhTHZIaZ7OS+cZgcliJ2 KCnvfzQ1keug== X-IronPort-AV: E=Sophos;i="5.70,548,1574121600"; d="scan'208";a="22665808" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 13 Mar 2020 12:33:21 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com (Postfix) with ESMTPS id 3C6D0A2C41; Fri, 13 Mar 2020 12:33:19 +0000 (UTC) Received: from EX13D08EUB001.ant.amazon.com (10.43.166.236) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Fri, 13 Mar 2020 12:33:19 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D08EUB001.ant.amazon.com (10.43.166.236) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Mar 2020 12:33:18 +0000 Received: from dev-dsk-mheyne-60001.pdx1.corp.amazon.com (10.184.85.242) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 13 Mar 2020 12:33:17 +0000 Received: by dev-dsk-mheyne-60001.pdx1.corp.amazon.com (Postfix, from userid 5466572) id 86A0421CA2; Fri, 13 Mar 2020 12:33:16 +0000 (UTC) From: Maximilian Heyne To: Date: Fri, 13 Mar 2020 12:33:15 +0000 Message-ID: <20200313123316.122003-3-mheyne@amazon.de> X-Mailer: git-send-email 2.16.6 In-Reply-To: <20200313123316.122003-1-mheyne@amazon.de> References: <20200313123316.122003-1-mheyne@amazon.de> MIME-Version: 1.0 Precedence: Bulk X-Mailman-Approved-At: Fri, 13 Mar 2020 12:34:17 +0000 Subject: [Xen-devel] [PATCH 2/3] Add exit notifiers. X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Paul Durrant Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Gerd Hoffmann Hook up any cleanup work which needs to be done here. Advantages over using atexit(3): (1) You get passed in a pointer to the notifier. If you embed that into your state struct you can use container_of() to get get your state info. (2) You can unregister, say when un-plugging a device. [ v2: move code out of #ifndef _WIN32 ] Signed-off-by: Anthony Liguori (cherry picked from commit fd42deeb4cb42f90084046e3ebdb4383953195e3) Signed-off-by: Maximilian Heyne Reviewed-by: Paul Durrant --- sysemu.h | 5 +++++ vl.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/sysemu.h b/sysemu.h index 968258a84..759d0e9d5 100644 --- a/sysemu.h +++ b/sysemu.h @@ -2,6 +2,8 @@ #define SYSEMU_H /* Misc. things related to the system emulator. */ +#include "notify.h" + /* vl.c */ extern const char *bios_name; extern const char *bios_dir; @@ -39,6 +41,9 @@ void qemu_system_powerdown(void); #endif void qemu_system_reset(void); +void qemu_add_exit_notifier(Notifier *notify); +void qemu_remove_exit_notifier(Notifier *notify); + void do_savevm(const char *name); void do_loadvm(const char *name); void do_delvm(const char *name); diff --git a/vl.c b/vl.c index c3c5d630e..2163217ec 100644 --- a/vl.c +++ b/vl.c @@ -282,6 +282,9 @@ uint8_t qemu_uuid[16]; #include "xen-vl-extra.c" +static NotifierList exit_notifiers = + NOTIFIER_LIST_INITIALIZER(exit_notifiers); + /***********************************************************/ /* x86 ISA bus support */ @@ -4843,6 +4846,21 @@ static void vcpu_hex_str_to_bitmap(const char *optarg) } } +void qemu_add_exit_notifier(Notifier *notify) +{ + notifier_list_add(&exit_notifiers, notify); +} + +void qemu_remove_exit_notifier(Notifier *notify) +{ + notifier_list_remove(notify); +} + +static void qemu_run_exit_notifiers(void) +{ + notifier_list_notify(&exit_notifiers); +} + int main(int argc, char **argv, char **envp) { #ifdef CONFIG_GDBSTUB @@ -4887,6 +4905,8 @@ int main(int argc, char **argv, char **envp) const char *chroot_dir = NULL; const char *run_as = NULL; + atexit(qemu_run_exit_notifiers); + qemu_cache_utils_init(envp); logfile = stderr; /* initial value */