From nobody Mon Feb 9 14:03:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1638204019529549.4352027442891; Mon, 29 Nov 2021 08:40:19 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-27-3PT-jBxLPaGqW_IpI5zkrw-1; Mon, 29 Nov 2021 11:40:15 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C9A718A0F27; Mon, 29 Nov 2021 16:40:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4220D1002388; Mon, 29 Nov 2021 16:40:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0B7434A705; Mon, 29 Nov 2021 16:40:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1ATGd6Vd017747 for ; Mon, 29 Nov 2021 11:39:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7DF122166B2D; Mon, 29 Nov 2021 16:39:06 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 77AE22166B26 for ; Mon, 29 Nov 2021 16:39:06 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5899E10726A5 for ; Mon, 29 Nov 2021 16:39:06 +0000 (UTC) Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-363-SOe01rxGMlWYHCMaH4OU1g-1; Mon, 29 Nov 2021 11:39:04 -0500 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2050.outbound.protection.outlook.com [104.47.14.50]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-32-Ea54k0QoOf-6jj0dHGEGjg-1; Mon, 29 Nov 2021 17:39:02 +0100 Received: from AM0PR04MB4899.eurprd04.prod.outlook.com (2603:10a6:208:c5::16) by AM9PR04MB7537.eurprd04.prod.outlook.com (2603:10a6:20b:282::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22; Mon, 29 Nov 2021 16:39:01 +0000 Received: from AM0PR04MB4899.eurprd04.prod.outlook.com ([fe80::c58b:de4e:3ba7:9ef6]) by AM0PR04MB4899.eurprd04.prod.outlook.com ([fe80::c58b:de4e:3ba7:9ef6%4]) with mapi id 15.20.4734.024; Mon, 29 Nov 2021 16:39:01 +0000 Received: from localhost (75.169.35.15) by AM6P191CA0045.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:7f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23 via Frontend Transport; Mon, 29 Nov 2021 16:39:00 +0000 X-MC-Unique: 3PT-jBxLPaGqW_IpI5zkrw-1 X-MC-Unique: SOe01rxGMlWYHCMaH4OU1g-1 X-MC-Unique: Ea54k0QoOf-6jj0dHGEGjg-1 From: Jim Fehlig To: libvir-list@redhat.com Subject: [PATCH 4/6] libxl: Handle domain death events in a thread Date: Mon, 29 Nov 2021 09:38:43 -0700 Message-ID: <20211129163845.12713-5-jfehlig@suse.com> In-Reply-To: <20211129163845.12713-1-jfehlig@suse.com> References: <20211129163845.12713-1-jfehlig@suse.com> X-ClientProxiedBy: AM6P191CA0045.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:7f::22) To AM0PR04MB4899.eurprd04.prod.outlook.com (2603:10a6:208:c5::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e6e761f8-2422-487c-1786-08d9b356bf86 X-MS-TrafficTypeDiagnostic: AM9PR04MB7537: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: mEK45e9cqWCJ7Kwkb+n+sv401pgCNViF2BnT963Kdoip6ysPpTjAdoWsa6pa+YK6EzmjFO1Kcwu1rUzUmtTRXm+5jMfCs0iUxgR9dP/9KS/MmQdEXfedYJw124PiYpdlHUlbCzpZnfNVETdou9KYhNqdFgP4BaJNRGI8b1Crh/tnrhh17asnjuwC9EHNgQzldENy13J0d622NwRcGdAK1X91OZXWx/QXls2prZzsSzSvj+4zMzpNjjZMMYapwU/HSPYLL35cLGO3bgJviQsXv5C6sYrHfCBt6w535Bdh5s3u0dEkjxtbTYUdB6c0EIyH1TBaWdkkon4hoFnqX4WTxO/9cn7MIfG6y0uduH3vlaQzlgfs9FpncfSFvEUyHLMfGv4oLyDfJL7SO16GEY+NYMDNSlfxcJTQDC6BFad/h5H4SK61VB7t2zBoeZCHwdq/apX17WmRExEGS+tFPfjiCHSQiM4MvsidHWIAxvKsnm4a7n3z5DzakdkNxb6UV2Q5bZ00x4pTx8ZsYddD678kX+HPL3GTYgH2WPhQblPE4iOS4z5Wbe6W8VRuz+QU+CJOkWH/PwwlycoJSi/OrCq5ri48IEToWsjhQ7Lm+JtvtL0023sZIzly1JaujDldclUzKIo4yVF9+aay5e2ce/WJale2WZLttyjbUtE0f9FlujYeEb2bVlmMaFlWQ7WIMMIj9Rn2STnXGrBAnmaZWv92bw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB4899.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(316002)(66946007)(66556008)(2906002)(956004)(8676002)(38100700002)(6496006)(6666004)(186003)(508600001)(2616005)(66476007)(8936002)(6486002)(1076003)(83380400001)(26005)(5660300002)(36756003)(6916009)(219283001); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?l3vMF0w99fWlUGM1fRMZHKV4u9eEH97KMEseY5KKGYbbgnvNBFni2Mqb54oF?= =?us-ascii?Q?gPYt2H6aobblHfbAj+p7EeJT2IgBVLfCHv67uEV/jMcuPVKPTZ8VE96KFr6j?= =?us-ascii?Q?Kc5qr6P4tLLDZ5wcg3iutfejVc+A3zosD/Zrg27UgtZhPrw72jknLkP8i8pe?= =?us-ascii?Q?B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BH/kOzqa75a9FKWgUGTVQfPI?= =?us-ascii?Q?oA50QrMm1ibABE+00nOP9fI5lBlf5kNMKaI3M6CvsC1LGIgupR/5fL5Pk2Nd?= =?us-ascii?Q?fsueG+XJFs2KaYbCFTf91Wzvrx4HhiK+Td6G2BgfAci89MfX3xSCIHpyJahP?= =?us-ascii?Q?fPsidJn44SzzePmHAmqRl9ygN4EmIaGIXUaj8+SDSeK9ShFmKxXdUhe/MPMT?= =?us-ascii?Q?8f96TciuvmEZDlaENSEEYu0ywbMK0t8iB2vAWj3vo/X75CD5BIuZuDo1vPIw?= =?us-ascii?Q?HY1RtmfycIavn59ifkvvZLaBnHjcSvgRd6W1BB5Sd3TGMEseN3szzQB1hOZ5?= =?us-ascii?Q?ppTHY1sJIjfxqL1cHLcckd66xCxyFmJOolBYGWour6kyw7YAAN1f/CjG6uaX?= =?us-ascii?Q?0a3ZslE57KSh5TkRA/1WOo9OZjOD6Up3C2OZXgKcx+7kSoto8Z8Fj5FMnXvH?= =?us-ascii?Q?EQWRxjSbqTA7f0X/PHeVIr9vMnBbP0ROF9Y7PEGo8pVY7gvKav7xP3m205+4?= =?us-ascii?Q?itlkatA33cI7JywcidoBit/80V0+CQ1QhxNziROTxCpzQUkem7cZrNW6HcYQ?= =?us-ascii?Q?+cvZLKoJm5GwOvYSRdvaKUI=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6e761f8-2422-487c-1786-08d9b356bf86 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB4899.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2021 16:39:01.4189 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MTewY3zCyz4H6kHWbclsUlmtjURV43ScS3oYLLR2OPcgD9rW2gCRcal/J0wA8Unlt/ca024PIpS/6ad3Lk3tyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7537 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1ATGd6Vd017747 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638204020161100003 Content-Type: text/plain; charset="utf-8" Similar to domain shutdown events, processing domain death events can be a lengthy process and we don't want to block the event handler while the operation completes. Move the death handling function to a thread. Signed-off-by: Jim Fehlig --- src/libxl/libxl_domain.c | 67 ++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 5d0034102e..d6c5f7e5b7 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -613,12 +613,17 @@ libxlDomainShutdownThread(void *opaque) } =20 static void -libxlDomainHandleDeath(libxlDriverPrivate *driver, virDomainObj *vm) +libxlDomainDeathThread(void *opaque) { + struct libxlEventHandlerThreadInfo *death_info =3D opaque; + virDomainObj *vm =3D death_info->vm; + libxl_event *ev =3D death_info->event; + libxlDriverPrivate *driver =3D death_info->driver; virObjectEvent *dom_event =3D NULL; + g_autoptr(libxlDriverConfig) cfg =3D libxlDriverConfigGet(driver); =20 if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) - return; + goto cleanup; =20 virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_DESTRO= YED); dom_event =3D virDomainEventLifecycleNewFromObj(vm, @@ -629,6 +634,11 @@ libxlDomainHandleDeath(libxlDriverPrivate *driver, vir= DomainObj *vm) virDomainObjListRemove(driver->domains, vm); libxlDomainObjEndJob(driver, vm); virObjectEventStateQueue(driver->domainEventState, dom_event); + + cleanup: + virDomainObjEndAPI(&vm); + libxl_event_free(cfg->ctx, ev); + VIR_FREE(death_info); } =20 =20 @@ -642,6 +652,9 @@ libxlDomainEventHandler(void *data, libxl_event *event) libxl_shutdown_reason xl_reason =3D event->u.domain_shutdown.shutdown_= reason; virDomainObj *vm =3D NULL; g_autoptr(libxlDriverConfig) cfg =3D NULL; + struct libxlEventHandlerThreadInfo *thread_info =3D NULL; + virThread thread; + g_autofree char *thread_name =3D NULL; =20 VIR_DEBUG("Received libxl event '%d' for domid '%d'", event->type, eve= nt->domid); =20 @@ -664,31 +677,27 @@ libxlDomainEventHandler(void *data, libxl_event *even= t) goto cleanup; } =20 + /* + * Start event-specific threads to handle shutdown and death. + * They are potentially lengthy operations and we don't want to be + * blocking this event handler while they are in progress. + */ if (event->type =3D=3D LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN) { - struct libxlEventHandlerThreadInfo *shutdown_info =3D NULL; - virThread thread; - g_autofree char *name =3D NULL; + thread_info =3D g_new0(struct libxlEventHandlerThreadInfo, 1); =20 - /* - * Start a thread to handle shutdown. We don't want to be tying up - * libxl's event machinery by doing a potentially lengthy shutdown. - */ - shutdown_info =3D g_new0(struct libxlEventHandlerThreadInfo, 1); - - shutdown_info->driver =3D driver; - shutdown_info->vm =3D vm; - shutdown_info->event =3D (libxl_event *)event; - name =3D g_strdup_printf("shutdown-event-%d", event->domid); + thread_info->driver =3D driver; + thread_info->vm =3D vm; + thread_info->event =3D (libxl_event *)event; + thread_name =3D g_strdup_printf("shutdown-event-%d", event->domid); /* * Cleanup will be handled by the shutdown thread. */ if (virThreadCreateFull(&thread, false, libxlDomainShutdownThread, - name, false, shutdown_info) < 0) { + thread_name, false, thread_info) < 0) { /* * Not much we can do on error here except log it. */ VIR_ERROR(_("Failed to create thread to handle domain shutdown= ")); - VIR_FREE(shutdown_info); goto cleanup; } /* @@ -697,15 +706,33 @@ libxlDomainEventHandler(void *data, libxl_event *even= t) */ return; } else if (event->type =3D=3D LIBXL_EVENT_TYPE_DOMAIN_DEATH) { + thread_info =3D g_new0(struct libxlEventHandlerThreadInfo, 1); + + thread_info->driver =3D driver; + thread_info->vm =3D vm; + thread_info->event =3D (libxl_event *)event; + thread_name =3D g_strdup_printf("death-event-%d", event->domid); /* - * On death the domain is cleaned up from Xen's perspective. - * Cleanup on the libvirt side can be done synchronously. + * Cleanup will be handled by the death thread. */ - libxlDomainHandleDeath(driver, vm); + if (virThreadCreateFull(&thread, false, libxlDomainDeathThread, + thread_name, false, thread_info) < 0) { + /* + * Not much we can do on error here except log it. + */ + VIR_ERROR(_("Failed to create thread to handle domain death")); + goto cleanup; + } + /* + * virDomainObjEndAPI is called in the death thread, where + * libxlEventHandlerThreadInfo and libxl_event are also freed. + */ + return; } =20 cleanup: virDomainObjEndAPI(&vm); + VIR_FREE(thread_info); cfg =3D libxlDriverConfigGet(driver); /* Cast away any const */ libxl_event_free(cfg->ctx, (libxl_event *)event); --=20 2.33.0