From patchwork Tue Nov 7 18:02:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 13449146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6ED5AC4332F for ; Tue, 7 Nov 2023 18:04:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r0QPd-000858-0M; Tue, 07 Nov 2023 13:02:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r0QPb-00084j-3M for qemu-devel@nongnu.org; Tue, 07 Nov 2023 13:02:51 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r0QPZ-0000db-F7 for qemu-devel@nongnu.org; Tue, 07 Nov 2023 13:02:50 -0500 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40850b244beso45162005e9.2 for ; Tue, 07 Nov 2023 10:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699380168; x=1699984968; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kZRUMwiWEGUH1111nhqAP/d0bCasvHH98Sdsmx1hRdc=; b=Fa5PCKPXL1VSdVK2ytgFmIZHbyQogAr9WI/CA5VWqWjl61+73Bs/bN/szmxWMtnazX aj9CYqUW1TOrBzcIjnWk6969E3OcNyHTDrRPgRYX1I8NbuAt0aulDCON9Ajl5d5MW2Fh 9MYbWkEpsV0FyiUedYYwaJd5lxy0X5ck/qBoYRI8wVqCE4XzqfDnuCg7VZx9N5Ve1F71 fZyEMU9wekBEAAWWKWTy4U2G9pvqyzM0U4C90WKxsv4UMD4Hjozl0GGm3b4ulS1h+odS j+1aujhBFiC5LTCQTuc27uuc9usjlnNBnU9NNvRJFe/fOJg5Eux+8F5hwowWV53TBSyZ jCTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699380168; x=1699984968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kZRUMwiWEGUH1111nhqAP/d0bCasvHH98Sdsmx1hRdc=; b=qpLY5AX6lqD2opz3clnfKGXlqCotaN7/5JU46JMQCbdMLqeUZEWbuAJuPT3VJZRHhA R4e0Q76pm0j9zmv/cyx8W+oOmYgv5BGt75H00PiNUyiU4aUOLFJPVGT9Y3eiEYIm5XOX HdkePfKF42p4A3H61SwPDbw9UTk4dWFvpnCfFsPY6/US9s+S7bWEPRlHbOevCya0baTU FP2uPo9THbgK50CEl3ZeOfdgp+0AAdoXGLcQf7xQrRDEnzhgRfeOmM+DGjNBFl38z3Dk KShB8I6YRcCFP+9YXjynWF9qu/aRD3r2CyXda6wrA5bJ77D+TSTAA3caj1BYlo7di+/M XIRQ== X-Gm-Message-State: AOJu0Yx2oIMbwvL9i70DmmzBvXym3Z6j/YkmEjwbMw8oO8/zKhVaLomm 8ilp1DRBoZwdJdhye03GYwBDBQ== X-Google-Smtp-Source: AGHT+IH5Ryzsi9s/1ylT5IsaR8y0tc+oSuQ7xkUfXzGmGXVbCjonk34PYJZKQK1B2eV24Pca0Bsrvg== X-Received: by 2002:a05:600c:4f92:b0:405:82c0:d9f3 with SMTP id n18-20020a05600c4f9200b0040582c0d9f3mr3196022wmq.30.1699380167943; Tue, 07 Nov 2023 10:02:47 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id b5-20020a05600c4e0500b00407b93d8085sm16656588wmq.27.2023.11.07.10.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 10:02:47 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id D6DE16573E; Tue, 7 Nov 2023 18:02:46 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Eric Blake , Gerd Hoffmann , =?utf-8?q?Alex_Benn=C3=A9e?= , Fam Zheng , Jason Wang , =?utf-8?q?Dan?= =?utf-8?q?iel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-An?= =?utf-8?q?dr=C3=A9_Lureau?= , Viresh Kumar , Manos Pitsidianakis , Raphael Norwitz , Hanna Reitz , Erik Schilling , "Michael S. Tsirkin" , Mathieu Poirier , qemu-block@nongnu.org, Paolo Bonzini , Eduardo Habkost , Markus Armbruster , Stefan Hajnoczi , Mark Cave-Ayland , virtio-fs@redhat.com, Kevin Wolf , "Gonglei (Arei)" Subject: [PATCH v7 2/7] hw/virtio: convert vhost-user-base to async shutdown Date: Tue, 7 Nov 2023 18:02:41 +0000 Message-Id: <20231107180246.3456598-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231107180246.3456598-1-alex.bennee@linaro.org> References: <20231107180246.3456598-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We are about to convert at least one stubs which was using the async teardown so lets use it for all the cases. Signed-off-by: Alex Bennée --- hw/virtio/vhost-user-base.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c index 620fa5cb4a..78cfa9a5bb 100644 --- a/hw/virtio/vhost-user-base.c +++ b/hw/virtio/vhost-user-base.c @@ -201,6 +201,8 @@ static int vub_connect(DeviceState *dev) return 0; } +static void vub_event(void *opaque, QEMUChrEvent event); + static void vub_disconnect(DeviceState *dev) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -211,9 +213,13 @@ static void vub_disconnect(DeviceState *dev) } vub->connected = false; - if (vhost_dev_is_started(&vub->vhost_dev)) { - vub_stop(vdev); - } + vub_stop(vdev); + vhost_dev_cleanup(&vub->vhost_dev); + + /* Re-instate the event handler for new connections */ + qemu_chr_fe_set_handlers(&vub->chardev, + NULL, NULL, vub_event, + NULL, dev, NULL, true); } static void vub_event(void *opaque, QEMUChrEvent event) @@ -230,7 +236,9 @@ static void vub_event(void *opaque, QEMUChrEvent event) } break; case CHR_EVENT_CLOSED: - vub_disconnect(dev); + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &vub->chardev, &vub->vhost_dev, + vub_disconnect, vub_event); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: