From nobody Thu May 9 22:09:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1694509021; cv=none; d=zohomail.com; s=zohoarc; b=Yurqh2CTao7BptfyEH5p0W4pcfaYLh114HVfH7VJ+jswKzn69XA7byEzD5xF5DD2SSkKydDI3VLx5iGYJQsXjzA63TuLQ+U4X1kkhJaSxQIqhxPSJOqkbjMpKCPFvpLE86oMRPHRa0dF6QjrEE3SrF9+zkDjCjd0ouXyCXFCmJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694509021; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1eP8kuKM1qKZ8jHbFZXOAaKaPzBH+J+kNlsheIRdgb4=; b=MNErz1sf9ffOVtHvvkPEL9uY8ke0KrdW7OmXzrM6po5lq00c5hG5eTeEbx2J4RQlRL8OqcCDO8EsdZcX9YTCNM1PA6LWqMrbAopb0ZcQfwjEDfcBrR23U7rDpFBM4FkEsMaDA4V7jy7maQ1h/54JuZppcyiulSA7JrFWyx6PqXc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694509021934165.25912308567456; Tue, 12 Sep 2023 01:57:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfzBe-0007xP-VQ; Tue, 12 Sep 2023 04:55:58 -0400 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 1qfzBa-0007qE-2d for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:55:54 -0400 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfzBX-0002AG-M4 for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:55:53 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6c09d760cb9so3644534a34.2 for ; Tue, 12 Sep 2023 01:53:50 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id m6-20020a637d46000000b00570668ccd5bsm6523754pgn.14.2023.09.12.01.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 01:53:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1694508828; x=1695113628; 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=1eP8kuKM1qKZ8jHbFZXOAaKaPzBH+J+kNlsheIRdgb4=; b=SfVm0DpgRA9avVG/eN+qaeeHxcPKByDZtaNZJjE9n4G/pFlYMICa0clx0RUt7eoyEC hUcAnmroB5PWJLbPng8lBDCnu3Dd61ogcs+JTv0ZAViQ6ZgWSxecMUuzUQS1ZdXwhJyU hMkYKEbNsQGS2cMQEW5+VKC2wZcV1jSYATz/jJc5K+NNEJCD0l5NB9nRep9lfyDIckcb /TC+nf/9dSsO4WieCdxWPbUhbLO5zPfNM4yBN6NZO0O+keLehE17GhY5fllWirsXhJkz rq59DYO64g/bvwWtM7WfcJj/Kl6gkiWxhg+9viSZnCthn+iat8+2Y97tXC1L7r+aE0zg 5yqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694508828; x=1695113628; 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=1eP8kuKM1qKZ8jHbFZXOAaKaPzBH+J+kNlsheIRdgb4=; b=rESQAXesb+oUrmsOO/4r2Ff12ZmNHUZsZef1wIzvdjdk0iRjcqqOWIXDcIJOek69XI L57G+8vnMhFTcvP/GZdeFB6pfncXUqhqzSHYsmT2uNmntlhPj+RismF1b1NdXKVhrb9R zUfGa7TZ8vN2R6pveQ4s6fuoUeix22/yOdlyo0nzDMI16r+RUNM9I9s3f4bIUX/Az8GH viTvpWmpk5jpAscJIEvruJ1P8MlxgvsYF7xq6kFFC7VRqGP2OT4NobYrfjwV3bLfS25b LV3qMxb9sETZk8hdYbMKcHCCwXEmswB0Kk2WRHDKQDUFftjOo99Io9act7g5bQhzX+tI nn3A== X-Gm-Message-State: AOJu0YzvbMI/NpEPUj+6kQSX5OfcpOBro6E6HRSmRt3hGR/ZbB4uW363 L65bNebPjVLFqlPNRrhQ7uznKg== X-Google-Smtp-Source: AGHT+IGAFTN9ZcnfepVYRpllrKyik1MiZn5le4uC72FICNx3vX3jObJAVU1Lsohc5cCngfbfxTp2Og== X-Received: by 2002:a05:6359:1a94:b0:141:12d2:921d with SMTP id rv20-20020a0563591a9400b0014112d2921dmr2333623rwb.17.1694508828161; Tue, 12 Sep 2023 01:53:48 -0700 (PDT) From: Li Feng To: Markus Armbruster , "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v4 1/5] vhost-user-common: send get_inflight_fd once Date: Tue, 12 Sep 2023 16:52:43 +0800 Message-ID: <20230912085315.2524857-2-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230912085315.2524857-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230912085315.2524857-1-fengli@smartx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::331; envelope-from=fengli@smartx.com; helo=mail-ot1-x331.google.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1694509023740100002 Content-Type: text/plain; charset="utf-8" Currently the get_inflight_fd will be sent every time the device is started= , and the backend will allocate shared memory to save the inflight state. If the backend finds that it receives the second get_inflight_fd, it will release = the previous shared memory, which breaks inflight working logic. This patch is a preparation for the following patches. Signed-off-by: Li Feng --- hw/scsi/vhost-scsi-common.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c index a06f01af26..a61cd0e907 100644 --- a/hw/scsi/vhost-scsi-common.c +++ b/hw/scsi/vhost-scsi-common.c @@ -52,20 +52,28 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) =20 vsc->dev.acked_features =3D vdev->guest_features; =20 - assert(vsc->inflight =3D=3D NULL); - vsc->inflight =3D g_new0(struct vhost_inflight, 1); - ret =3D vhost_dev_get_inflight(&vsc->dev, - vs->conf.virtqueue_size, - vsc->inflight); + ret =3D vhost_dev_prepare_inflight(&vsc->dev, vdev); if (ret < 0) { - error_report("Error get inflight: %d", -ret); + error_report("Error setting inflight format: %d", -ret); goto err_guest_notifiers; } =20 - ret =3D vhost_dev_set_inflight(&vsc->dev, vsc->inflight); - if (ret < 0) { - error_report("Error set inflight: %d", -ret); - goto err_guest_notifiers; + if (vsc->inflight) { + if (!vsc->inflight->addr) { + ret =3D vhost_dev_get_inflight(&vsc->dev, + vs->conf.virtqueue_size, + vsc->inflight); + if (ret < 0) { + error_report("Error getting inflight: %d", -ret); + goto err_guest_notifiers; + } + } + + ret =3D vhost_dev_set_inflight(&vsc->dev, vsc->inflight); + if (ret < 0) { + error_report("Error setting inflight: %d", -ret); + goto err_guest_notifiers; + } } =20 ret =3D vhost_dev_start(&vsc->dev, vdev, true); @@ -85,9 +93,6 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) return ret; =20 err_guest_notifiers: - g_free(vsc->inflight); - vsc->inflight =3D NULL; - k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false); err_host_notifiers: vhost_dev_disable_notifiers(&vsc->dev, vdev); @@ -111,12 +116,6 @@ void vhost_scsi_common_stop(VHostSCSICommon *vsc) } assert(ret >=3D 0); =20 - if (vsc->inflight) { - vhost_dev_free_inflight(vsc->inflight); - g_free(vsc->inflight); - vsc->inflight =3D NULL; - } - vhost_dev_disable_notifiers(&vsc->dev, vdev); } =20 --=20 2.41.0 From nobody Thu May 9 22:09:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1694509029; cv=none; d=zohomail.com; s=zohoarc; b=i5RvVXmewi4N56Zid/ehDOpPd+j0W8AgpHJMjo1AW9ssyXOBNtWofiI+rW636ijl6sckU9M58fxv3VSghaxCgKAS29IVHRwiHi4yUUJpb8Mwkbj+H8BzY/vSz2HivX8RFe/NPZq3YD14prFjsQcNb6zGd0kPUXNxhi02oR917C0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694509029; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ak3cZicP6FXgjNSZA0EnmzY0v3FARPxaB+bcgiWIe/k=; b=f1xXPkSURNSXZJCxrL1axOgjyBM5L2kCqQPU/6lEGgKdXRaOKsG4LT1dBuR5tzaqO9q2ZI/bInaytOScCxv9hDjISuqPSicLzCl8QiAldY6b+I2lJZv32hmKyTwfIF9wNq01/nC1sQsyKBkTK7AKcvFPkpP+ubyDWoFh254zor4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694509029316148.2114957970092; Tue, 12 Sep 2023 01:57:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfzBf-000834-MX; Tue, 12 Sep 2023 04:55:59 -0400 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 1qfzBb-0007rX-SV for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:55:56 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfzBZ-0002AZ-0d for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:55:55 -0400 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3a76d882052so3823050b6e.0 for ; Tue, 12 Sep 2023 01:53:52 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id m6-20020a637d46000000b00570668ccd5bsm6523754pgn.14.2023.09.12.01.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 01:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1694508832; x=1695113632; 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=Ak3cZicP6FXgjNSZA0EnmzY0v3FARPxaB+bcgiWIe/k=; b=3BY233j733vHXG3eM7dPtsA+7AqBxGZUZ6vdYaTItyCoB314RHz/Gv0Zh+dicZcdSa bjI9t6t68vOY2DMUPrgEL3sgyqwJHROV3bku/BZ59KdvW4c2+8OM61RJFcTqFTBAmhIH XCPgj3u6+Cp+FjAeNEDd+o0MVq/q2eAB/bp7nt1vJ2ypKJFYj15f1WP8VkOWysTCZJK+ qg+lyGynCzvzu2ZJdfgDgbZz0AtpnjbnqWxWgbdCZEDgjUS1JL8p3fBWs1i0/0UPPuAJ G1Gg+wi77Clyx7+xfD1+9U8MNUzb86hs8+8fFMsVozEU18NQ2R0hKWglKh7ggRnMpwv/ jx3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694508832; x=1695113632; 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=Ak3cZicP6FXgjNSZA0EnmzY0v3FARPxaB+bcgiWIe/k=; b=aLtI7iIfI5phk0WKP6P5AApYT41YTvUpeyf+02YXi99tArBATvtStaxgS3P4b24oQx NZ4atTzgIFV0+xhAsdIKcAkSGzw++Qz2U4+2UXVq4x3PFf44+1xWVF3t4ny/XvYW8C4z h695uh2QnJPc0hYWxjsVGbVaq6WyvivogJmb1WRKQxErH3Z7mHmWekQFRZR8GytZ7GEU K0t+VZxw2PWJw9Def07pfNg9LJ8hBOPkBhQ5oW1j8taBlT5C1Tagcua0VLkbjr3zSuuh yf+GBnV52HOTfQNIGTdSzgXxG2p4UAnvG6gmQMVCjilAD7HNpASPlYIcvI8Yr0rBI3ny gQcg== X-Gm-Message-State: AOJu0Yy6TR5Yw23131Gh7lqn8O+MvvHywxfoV3LnOmp0sVy64vLeUncE dWk0qZ20vyUfndCobdEO+m5A0A== X-Google-Smtp-Source: AGHT+IE/O+SlGVsoHz3jY9KbI8GKMMIon48Ogd4jVOl0FBeiBHomgynOYjyJv6TLhdncx+NETC5orw== X-Received: by 2002:a05:6808:1784:b0:3a9:a334:907e with SMTP id bg4-20020a056808178400b003a9a334907emr15269223oib.16.1694508831794; Tue, 12 Sep 2023 01:53:51 -0700 (PDT) From: Li Feng To: Markus Armbruster , "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v4 2/5] vhost: move and rename the conn retry times Date: Tue, 12 Sep 2023 16:52:44 +0800 Message-ID: <20230912085315.2524857-3-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230912085315.2524857-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230912085315.2524857-1-fengli@smartx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::236; envelope-from=fengli@smartx.com; helo=mail-oi1-x236.google.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1694509031436100003 Content-Type: text/plain; charset="utf-8" Multiple devices need this macro, move it to a common header. Signed-off-by: Li Feng Reviewed-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 4 +--- hw/virtio/vhost-user-gpio.c | 3 +-- include/hw/virtio/vhost.h | 2 ++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index eecf3f7a81..3c69fa47d5 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -32,8 +32,6 @@ #include "sysemu/sysemu.h" #include "sysemu/runstate.h" =20 -#define REALIZE_CONNECTION_RETRIES 3 - static const int user_feature_bits[] =3D { VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_SEG_MAX, @@ -482,7 +480,7 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) s->inflight =3D g_new0(struct vhost_inflight, 1); s->vhost_vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); =20 - retries =3D REALIZE_CONNECTION_RETRIES; + retries =3D VU_REALIZE_CONN_RETRIES; assert(!*errp); do { if (*errp) { diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index 3b013f2d0f..d9979aa5db 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -15,7 +15,6 @@ #include "standard-headers/linux/virtio_ids.h" #include "trace.h" =20 -#define REALIZE_CONNECTION_RETRIES 3 #define VHOST_NVQS 2 =20 /* Features required from VirtIO */ @@ -359,7 +358,7 @@ static void vu_gpio_device_realize(DeviceState *dev, Er= ror **errp) qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, vu_gpio_event, NU= LL, dev, NULL, true); =20 - retries =3D REALIZE_CONNECTION_RETRIES; + retries =3D VU_REALIZE_CONN_RETRIES; g_assert(!*errp); do { if (*errp) { diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 6a173cb9fa..ca3131b1af 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -8,6 +8,8 @@ #define VHOST_F_DEVICE_IOTLB 63 #define VHOST_USER_F_PROTOCOL_FEATURES 30 =20 +#define VU_REALIZE_CONN_RETRIES 3 + /* Generic structures common for any vhost based device. */ =20 struct vhost_inflight { --=20 2.41.0 From nobody Thu May 9 22:09:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1694509016; cv=none; d=zohomail.com; s=zohoarc; b=mzZmh0vG8nTimWDDzQvvwgHx/wYkBdVc2ayYdeB3Hn5BmOghnb/AaJOBgm7Ap/sPq/SYfxxYV/BOB07Dc9ewJn4vBE0EcJsh0m78265uACi5mxTpP9cWgGaEtnPPkxHTwOdG+VVY9l4KAKQQVz6I6cefLZdyWLEG1IWlZ99/vnk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694509016; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+XH7wdtDBHjkJj1TRjhNqIG/+/Tyzm+qcFAhIy62ShA=; b=BQsaUWkpRJ5+uUVeoIQR9UkGhPirWbeDttpra+MiAcNNSRufjbUMG52c7yzI7F4/q3OP3Bwn6AtYg+FzHJ71kMLrflxnjzeKaXy39mrFfFNkyEswoQsAkmV8rLLUrc8t4lwJFbl//oWRPcbrTIj5wvGWdIUYk53LvNC4hZCRR8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694509016033202.11628173710073; Tue, 12 Sep 2023 01:56:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfzBh-00086W-9E; Tue, 12 Sep 2023 04:56:01 -0400 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 1qfzBf-000848-PQ for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:55:59 -0400 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfzBc-0002BE-Ut for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:55:59 -0400 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-575f45e255dso3271694eaf.2 for ; Tue, 12 Sep 2023 01:53:56 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id m6-20020a637d46000000b00570668ccd5bsm6523754pgn.14.2023.09.12.01.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 01:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1694508835; x=1695113635; 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=+XH7wdtDBHjkJj1TRjhNqIG/+/Tyzm+qcFAhIy62ShA=; b=eGkFNge31C2jcb5NNce7IHkFw2K7yYw0pjU83EWY+mj7Pqt/KR0A9gQXD7h8ulkf60 v7k8o/gfswLFbBrlYhMqsZj/9FiU0oenkO+I3lGo0jKoR4OjqgndfPt7atMRdQ6hNiE5 2cZMzVjRcpCVSgr7xOUPZQ6VfjtwJsyhBXbt1g27tYmZzWqXNUdyWL7AyC9Sa8HT12HL wf4ZFE0AZNtfEFIjB2K2zesr+V9rIJvx0z6l+QIopCrK9UibQUUTtBglHgnACc3/0xpN PcetfjNyg8XQ3m5KkAZvKJhHrQS3MjkRxKSXclL8Z1UXHxltEVraxOWFXg/lY6WQXSck Lr+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694508835; x=1695113635; 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=+XH7wdtDBHjkJj1TRjhNqIG/+/Tyzm+qcFAhIy62ShA=; b=tZlcDVMqEsdYZcHFoaY9TLTSHotMqKI6bIuk3GHzipKfTU6livVGclEsP0WGcrXQdN 6mOOOZPCCX7cXsbWLCAPm+KFrbnU4rNsx7i/5vuEh69UKbyqbncjWHb8SBjTzHzRqL0g 0FI4QSwtDLP9QbBmRBqc47rolAjPcA7oRCpJXeWBBUFX1+1yQv/BeTVPOC+cgZzqBrSY rM6raNL3U6dELu0NGcd8OZUS7f2X4BnI7Fhz045GKOK+PUkAFTk7AEfn0L94sefxyNhL Qf8oKFrOgvZtEtHmH8KzzXyvnUa7xtq6ONhhfrej1UTZVTVk94X/ECOjuHNs7gDOruIX 8Gtw== X-Gm-Message-State: AOJu0Yz5AgiT/nL1E2HI4I+gK3tQwDRUWioklYTXGcJSReZINFVcT+gd bDvpyVG7hel2P22k2iaQCzXAxg== X-Google-Smtp-Source: AGHT+IEuhR8gYZZpzK7HzrPM7ldpFlE7g5uaAKJBaBHdudFUzdhqwOpMzUGKXHqjym3uP7SgeM596Q== X-Received: by 2002:a05:6871:296:b0:1bf:174b:a17e with SMTP id i22-20020a056871029600b001bf174ba17emr13535556oae.22.1694508835349; Tue, 12 Sep 2023 01:53:55 -0700 (PDT) From: Li Feng To: Markus Armbruster , "Michael S. Tsirkin" , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v4 3/5] vhost-user-scsi: support reconnect to backend Date: Tue, 12 Sep 2023 16:52:45 +0800 Message-ID: <20230912085315.2524857-4-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230912085315.2524857-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230912085315.2524857-1-fengli@smartx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::c2b; envelope-from=fengli@smartx.com; helo=mail-oo1-xc2b.google.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1694509017605100002 Content-Type: text/plain; charset="utf-8" If the backend crashes and restarts, the device is broken. This patch adds reconnect for vhost-user-scsi. This patch also improves the error messages, and reports some silent errors. Tested with spdk backend. Signed-off-by: Li Feng --- hw/scsi/vhost-scsi-common.c | 16 +- hw/scsi/vhost-scsi.c | 5 +- hw/scsi/vhost-user-scsi.c | 204 +++++++++++++++++++++++--- include/hw/virtio/vhost-scsi-common.h | 2 +- include/hw/virtio/vhost-user-scsi.h | 4 + 5 files changed, 201 insertions(+), 30 deletions(-) diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c index a61cd0e907..4c8637045d 100644 --- a/hw/scsi/vhost-scsi-common.c +++ b/hw/scsi/vhost-scsi-common.c @@ -16,6 +16,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/module.h" #include "hw/virtio/vhost.h" @@ -25,7 +26,7 @@ #include "hw/virtio/virtio-access.h" #include "hw/fw-path-provider.h" =20 -int vhost_scsi_common_start(VHostSCSICommon *vsc) +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp) { int ret, i; VirtIODevice *vdev =3D VIRTIO_DEVICE(vsc); @@ -35,18 +36,19 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) VirtIOSCSICommon *vs =3D (VirtIOSCSICommon *)vsc; =20 if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); + error_setg(errp, "binding does not support guest notifiers"); return -ENOSYS; } =20 ret =3D vhost_dev_enable_notifiers(&vsc->dev, vdev); if (ret < 0) { + error_setg_errno(errp, -ret, "Error enabling host notifiers"); return ret; } =20 ret =3D k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, true); if (ret < 0) { - error_report("Error binding guest notifier"); + error_setg_errno(errp, -ret, "Error binding guest notifier"); goto err_host_notifiers; } =20 @@ -54,7 +56,7 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) =20 ret =3D vhost_dev_prepare_inflight(&vsc->dev, vdev); if (ret < 0) { - error_report("Error setting inflight format: %d", -ret); + error_setg_errno(errp, -ret, "Error setting inflight format"); goto err_guest_notifiers; } =20 @@ -64,21 +66,21 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) vs->conf.virtqueue_size, vsc->inflight); if (ret < 0) { - error_report("Error getting inflight: %d", -ret); + error_setg_errno(errp, -ret, "Error getting inflight"); goto err_guest_notifiers; } } =20 ret =3D vhost_dev_set_inflight(&vsc->dev, vsc->inflight); if (ret < 0) { - error_report("Error setting inflight: %d", -ret); + error_setg_errno(errp, -ret, "Error setting inflight"); goto err_guest_notifiers; } } =20 ret =3D vhost_dev_start(&vsc->dev, vdev, true); if (ret < 0) { - error_report("Error start vhost dev"); + error_setg_errno(errp, -ret, "Error starting vhost dev"); goto err_guest_notifiers; } =20 diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 443f67daa4..01a3ab4277 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -75,6 +75,7 @@ static int vhost_scsi_start(VHostSCSI *s) int ret, abi_version; VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); const VhostOps *vhost_ops =3D vsc->dev.vhost_ops; + Error *local_err =3D NULL; =20 ret =3D vhost_ops->vhost_scsi_get_abi_version(&vsc->dev, &abi_version); if (ret < 0) { @@ -88,14 +89,14 @@ static int vhost_scsi_start(VHostSCSI *s) return -ENOSYS; } =20 - ret =3D vhost_scsi_common_start(vsc); + ret =3D vhost_scsi_common_start(vsc, &local_err); if (ret < 0) { return ret; } =20 ret =3D vhost_scsi_set_endpoint(s); if (ret < 0) { - error_report("Error setting vhost-scsi endpoint"); + error_reportf_err(local_err, "Error setting vhost-scsi endpoint"); vhost_scsi_common_stop(vsc); } =20 diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index ee99b19e7a..dc109154ad 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -43,26 +43,56 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_RESET_DEVICE =3D 13, }; =20 +static int vhost_user_scsi_start(VHostUserSCSI *s, Error **errp) +{ + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + int ret; + + ret =3D vhost_scsi_common_start(vsc, errp); + s->started_vu =3D (ret < 0 ? false : true); + + return ret; +} + +static void vhost_user_scsi_stop(VHostUserSCSI *s) +{ + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + + if (!s->started_vu) { + return; + } + s->started_vu =3D false; + + vhost_scsi_common_stop(vsc); +} + static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status) { VHostUserSCSI *s =3D (VHostUserSCSI *)vdev; + DeviceState *dev =3D &s->parent_obj.parent_obj.parent_obj.parent_obj; VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); - bool start =3D (status & VIRTIO_CONFIG_S_DRIVER_OK) && vdev->vm_runnin= g; + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + bool should_start =3D virtio_device_should_start(vdev, status); + Error *local_err =3D NULL; + int ret; =20 - if (vhost_dev_is_started(&vsc->dev) =3D=3D start) { + if (!s->connected) { return; } =20 - if (start) { - int ret; + if (vhost_dev_is_started(&vsc->dev) =3D=3D should_start) { + return; + } =20 - ret =3D vhost_scsi_common_start(vsc); + if (should_start) { + ret =3D vhost_user_scsi_start(s, &local_err); if (ret < 0) { - error_report("unable to start vhost-user-scsi: %s", strerror(-= ret)); - exit(1); + error_reportf_err(local_err, "unable to start vhost-user-scsi:= %s", + strerror(-ret)); + qemu_chr_fe_disconnect(&vs->conf.chardev); } } else { - vhost_scsi_common_stop(vsc); + vhost_user_scsi_stop(s); } } =20 @@ -89,14 +119,127 @@ static void vhost_dummy_handle_output(VirtIODevice *v= dev, VirtQueue *vq) { } =20 +static int vhost_user_scsi_connect(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCSI *s =3D VHOST_USER_SCSI(vdev); + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + int ret =3D 0; + + if (s->connected) { + return 0; + } + s->connected =3D true; + + vsc->dev.num_queues =3D vs->conf.num_queues; + vsc->dev.nvqs =3D VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; + vsc->dev.vqs =3D s->vhost_vqs; + vsc->dev.vq_index =3D 0; + vsc->dev.backend_features =3D 0; + + ret =3D vhost_dev_init(&vsc->dev, &s->vhost_user, VHOST_BACKEND_TYPE_U= SER, 0, + errp); + if (ret < 0) { + return ret; + } + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + ret =3D vhost_user_scsi_start(s, errp); + if (ret < 0) { + return ret; + } + } + + return 0; +} + +static void vhost_user_scsi_event(void *opaque, QEMUChrEvent event); + +static void vhost_user_scsi_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCSI *s =3D VHOST_USER_SCSI(vdev); + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + + if (!s->connected) { + return; + } + s->connected =3D false; + + vhost_user_scsi_stop(s); + + vhost_dev_cleanup(&vsc->dev); + + /* Re-instate the event handler for new connections */ + qemu_chr_fe_set_handlers(&vs->conf.chardev, NULL, NULL, + vhost_user_scsi_event, NULL, dev, NULL, true); +} + +static void vhost_user_scsi_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCSI *s =3D VHOST_USER_SCSI(vdev); + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + Error *local_err =3D NULL; + + switch (event) { + case CHR_EVENT_OPENED: + if (vhost_user_scsi_connect(dev, &local_err) < 0) { + error_report_err(local_err); + qemu_chr_fe_disconnect(&vs->conf.chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &vs->conf.chardev, &vsc->dev, + vhost_user_scsi_disconnect); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static int vhost_user_scsi_realize_connect(VHostUserSCSI *s, Error **errp) +{ + DeviceState *dev =3D &s->parent_obj.parent_obj.parent_obj.parent_obj; + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + int ret; + + s->connected =3D false; + + ret =3D qemu_chr_fe_wait_connected(&vs->conf.chardev, errp); + if (ret < 0) { + return ret; + } + + ret =3D vhost_user_scsi_connect(dev, errp); + if (ret < 0) { + qemu_chr_fe_disconnect(&vs->conf.chardev); + return ret; + } + assert(s->connected); + + return 0; +} + static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) { + ERRP_GUARD(); VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); VHostUserSCSI *s =3D VHOST_USER_SCSI(dev); VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); - struct vhost_virtqueue *vqs =3D NULL; Error *err =3D NULL; int ret; + int retries =3D VU_REALIZE_CONN_RETRIES; =20 if (!vs->conf.chardev.chr) { error_setg(errp, "vhost-user-scsi: missing chardev"); @@ -115,18 +258,28 @@ static void vhost_user_scsi_realize(DeviceState *dev,= Error **errp) goto free_virtio; } =20 - vsc->dev.nvqs =3D VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; - vsc->dev.vqs =3D g_new0(struct vhost_virtqueue, vsc->dev.nvqs); - vsc->dev.vq_index =3D 0; - vsc->dev.backend_features =3D 0; - vqs =3D vsc->dev.vqs; + vsc->inflight =3D g_new0(struct vhost_inflight, 1); + s->vhost_vqs =3D g_new0(struct vhost_virtqueue, + VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues); + + assert(!*errp); + do { + if (*errp) { + error_prepend(errp, "Reconnecting after error: "); + error_report_err(*errp); + *errp =3D NULL; + } + ret =3D vhost_user_scsi_realize_connect(s, errp); + } while (ret < 0 && retries--); =20 - ret =3D vhost_dev_init(&vsc->dev, &s->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { goto free_vhost; } =20 + /* we're fully initialized, now we can operate, so add the handler */ + qemu_chr_fe_set_handlers(&vs->conf.chardev, NULL, NULL, + vhost_user_scsi_event, NULL, (void *)dev, + NULL, true); /* Channel and lun both are 0 for bootable vhost-user-scsi disk */ vsc->channel =3D 0; vsc->lun =3D 0; @@ -135,8 +288,12 @@ static void vhost_user_scsi_realize(DeviceState *dev, = Error **errp) return; =20 free_vhost: + g_free(s->vhost_vqs); + s->vhost_vqs =3D NULL; + g_free(vsc->inflight); + vsc->inflight =3D NULL; vhost_user_cleanup(&s->vhost_user); - g_free(vqs); + free_virtio: virtio_scsi_common_unrealize(dev); } @@ -146,16 +303,23 @@ static void vhost_user_scsi_unrealize(DeviceState *de= v) VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserSCSI *s =3D VHOST_USER_SCSI(dev); VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); - struct vhost_virtqueue *vqs =3D vsc->dev.vqs; + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); =20 /* This will stop the vhost backend. */ vhost_user_scsi_set_status(vdev, 0); + qemu_chr_fe_set_handlers(&vs->conf.chardev, NULL, NULL, NULL, NULL, NU= LL, + NULL, false); =20 vhost_dev_cleanup(&vsc->dev); - g_free(vqs); + g_free(s->vhost_vqs); + s->vhost_vqs =3D NULL; + + vhost_dev_free_inflight(vsc->inflight); + g_free(vsc->inflight); + vsc->inflight =3D NULL; =20 - virtio_scsi_common_unrealize(dev); vhost_user_cleanup(&s->vhost_user); + virtio_scsi_common_unrealize(dev); } =20 static Property vhost_user_scsi_properties[] =3D { diff --git a/include/hw/virtio/vhost-scsi-common.h b/include/hw/virtio/vhos= t-scsi-common.h index 18f115527c..c5d2c09455 100644 --- a/include/hw/virtio/vhost-scsi-common.h +++ b/include/hw/virtio/vhost-scsi-common.h @@ -39,7 +39,7 @@ struct VHostSCSICommon { struct vhost_inflight *inflight; }; =20 -int vhost_scsi_common_start(VHostSCSICommon *vsc); +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp); void vhost_scsi_common_stop(VHostSCSICommon *vsc); char *vhost_scsi_common_get_fw_dev_path(FWPathProvider *p, BusState *bus, DeviceState *dev); diff --git a/include/hw/virtio/vhost-user-scsi.h b/include/hw/virtio/vhost-= user-scsi.h index 521b08e559..b405ec952a 100644 --- a/include/hw/virtio/vhost-user-scsi.h +++ b/include/hw/virtio/vhost-user-scsi.h @@ -29,6 +29,10 @@ OBJECT_DECLARE_SIMPLE_TYPE(VHostUserSCSI, VHOST_USER_SCS= I) struct VHostUserSCSI { VHostSCSICommon parent_obj; VhostUserState vhost_user; + bool connected; + bool started_vu; + + struct vhost_virtqueue *vhost_vqs; }; =20 #endif /* VHOST_USER_SCSI_H */ --=20 2.41.0 From nobody Thu May 9 22:09:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1694509017; cv=none; d=zohomail.com; s=zohoarc; b=V6O7vB6RtMlfVnnOCya3uw4jMTsuhCqDHiIg0+BXhi0MkSFh6LXBrJx/A1RrogfEdaQ9rvN9Hhml+gN+fkSjbFF4SsN+5QqhFE2IQ9k+zzf25Z864dRjEL0Q1h86pae/9ctS3HpbQZzLCBLiWwJ2XXZKBeoMcStsSmxkVo6Je1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694509017; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FJWI2RWxSuuHEAQnNUIufNGq1knrJeTQjKy85JEOKag=; b=X0c045C0Zp8iMPLUrtqntl/NYKfidwjfM3GbjKdx75tc9qOCL51fShWSQQxUlgqF1N0ijdNOt8SUp+io1VgFCUO+Bnb2+cKN9n999SGDjGxzZ7NR1bERzf46WbnoHofqBPqUsLtcKYtUR6LqoHAyIvtLdXzYf7NfoelVla7gFW8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694509017547529.3992226921945; Tue, 12 Sep 2023 01:56:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfzCJ-0008TI-5P; Tue, 12 Sep 2023 04:56:42 -0400 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 1qfzBi-00089f-De for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:56:05 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfzBg-0002BX-8L for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:56:02 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68fb6fd2836so2363579b3a.0 for ; Tue, 12 Sep 2023 01:53:59 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id m6-20020a637d46000000b00570668ccd5bsm6523754pgn.14.2023.09.12.01.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 01:53:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1694508839; x=1695113639; 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=FJWI2RWxSuuHEAQnNUIufNGq1knrJeTQjKy85JEOKag=; b=Y0wAuHOT9T0+nagQBaUXKMVuTplmaZc32HFRKU1xdOOrAlrYZkc2vbbcD156dKKNYW N1ehzaOANtwbd6oL6+3cHKSJ98+zEXldJqY6pb53DM419TTb46uGyjRSEUZOYQTPkAIU EmRRh8pOtbech6t+2KUmGKpZjYnudHlvm6VKdJOg3xJy9zyZpn65TTpKXjObpnmzRScu kxJfx5yq/MR69Fm/VWO+Aqx+taMGRWKUiB/c2MXviWM/yRrw4oAYr7kkvLcRH6YJhlfp jUGSulHoTXsV/gf1c5lilAsraYx9UqRZDlDtl6hmqtgen+FzKpWqBET1W6uEdSF3KVN4 4LDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694508839; x=1695113639; 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=FJWI2RWxSuuHEAQnNUIufNGq1knrJeTQjKy85JEOKag=; b=uTQ1HHzC4ytAWChAMc08hqT1KeqIfblYAXNdWcmW1tXWsdh30Hgw9mzUDT/5TD1GV8 u/uAObpABmEI1h8mIGIcb20qAAt18VgbtJS7fCXwS1JRQAnMaB7qzIeTXSHq3nfzYF21 fF4dZwQPv3JuzlZKABmz3Gt/ZanjplIL+KNoFGgBs/O1KEH24yi+N0dXXEVDNhCYxF7o aQ4kteCQvW8ULjMky4PgxvgkJt+vR1kRq9sFRYeOg0d3y8lUbEydHOVVQOvofGpLTa9g Z+YNAETjQEyVHrt5lgMGBRuGyO0SnyYqUypnjkdLLYEgvnqHR3gA6Ymi5IjYv9N8cXou iDqw== X-Gm-Message-State: AOJu0YyZ0LRgO63oteSNkd9UamPaYU+l43MEoSi/xAyAGqrmlv2rb0Vf wPR1fblGAkZaPmrj8fzKC3hveQ== X-Google-Smtp-Source: AGHT+IFPaMspSeZM32zArizHLAVHaKqFe3uDNwuVgI+71gKGChYirsXrxRMYnABJ7+NAd5LH64MW1g== X-Received: by 2002:a05:6a00:1408:b0:68e:3d83:e501 with SMTP id l8-20020a056a00140800b0068e3d83e501mr14065467pfu.13.1694508838902; Tue, 12 Sep 2023 01:53:58 -0700 (PDT) From: Li Feng To: Markus Armbruster , Raphael Norwitz , "Michael S. Tsirkin" , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v4 4/5] vhost-user-scsi: start vhost when guest kicks Date: Tue, 12 Sep 2023 16:52:46 +0800 Message-ID: <20230912085315.2524857-5-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230912085315.2524857-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230912085315.2524857-1-fengli@smartx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::434; envelope-from=fengli@smartx.com; helo=mail-pf1-x434.google.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1694509019278100007 Content-Type: text/plain; charset="utf-8" Let's keep the same behavior as vhost-user-blk. Some old guests kick virtqueue before setting VIRTIO_CONFIG_S_DRIVER_OK. Signed-off-by: Li Feng --- hw/scsi/vhost-user-scsi.c | 51 +++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index dc109154ad..0effbb4787 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -115,8 +115,48 @@ static void vhost_user_scsi_reset(VirtIODevice *vdev) } } =20 -static void vhost_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq) +static void vhost_user_scsi_handle_output(VirtIODevice *vdev, VirtQueue *v= q) { + VHostUserSCSI *s =3D (VHostUserSCSI *)vdev; + DeviceState *dev =3D &s->parent_obj.parent_obj.parent_obj.parent_obj; + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + + Error *local_err =3D NULL; + int i, ret; + + if (!vdev->start_on_kick) { + return; + } + + if (!s->connected) { + return; + } + + if (vhost_dev_is_started(&vsc->dev)) { + return; + } + + /* + * Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start + * vhost here instead of waiting for .set_status(). + */ + ret =3D vhost_user_scsi_start(s, &local_err); + if (ret < 0) { + error_reportf_err(local_err, "vhost-user-scsi: vhost start failed:= "); + qemu_chr_fe_disconnect(&vs->conf.chardev); + return; + } + + /* Kick right away to begin processing requests already in vring */ + for (i =3D 0; i < vsc->dev.nvqs; i++) { + VirtQueue *kick_vq =3D virtio_get_queue(vdev, i); + + if (!virtio_queue_get_desc_addr(vdev, i)) { + continue; + } + event_notifier_set(virtio_queue_get_host_notifier(kick_vq)); + } } =20 static int vhost_user_scsi_connect(DeviceState *dev, Error **errp) @@ -198,7 +238,8 @@ static void vhost_user_scsi_event(void *opaque, QEMUChr= Event event) case CHR_EVENT_CLOSED: /* defer close until later to avoid circular close */ vhost_user_async_close(dev, &vs->conf.chardev, &vsc->dev, - vhost_user_scsi_disconnect); + vhost_user_scsi_disconnect, + vhost_user_scsi_event); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: @@ -246,9 +287,9 @@ static void vhost_user_scsi_realize(DeviceState *dev, E= rror **errp) return; } =20 - virtio_scsi_common_realize(dev, vhost_dummy_handle_output, - vhost_dummy_handle_output, - vhost_dummy_handle_output, &err); + virtio_scsi_common_realize(dev, vhost_user_scsi_handle_output, + vhost_user_scsi_handle_output, + vhost_user_scsi_handle_output, &err); if (err !=3D NULL) { error_propagate(errp, err); return; --=20 2.41.0 From nobody Thu May 9 22:09:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1694509024; cv=none; d=zohomail.com; s=zohoarc; b=e1b2ylV2jQQXLwYvcXwZGtn5tHc+54YOealKBg8d3PcuVbTiIvTzfeHk4YzAa7DPIzjDtG0H1ksSdYshTdLh34zNmpoW0ugj3XRYavsoVoO4t5itZYiP+OCZWdkLO8MZRi0JaN8fer/b3Il5xaPte4vcfMxPerPYNROUOcvXEBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694509024; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZngRalemChwakz8wrbTdzeq+OAAg9Tm3RzDMb6BGc10=; b=GTeQzJcx7GHrBpffZfSEB5rMp97/K15Hh2Fe7Ssj/by0l0VQQB4OT34ZsE5B45Ox7SQ8qusHBEmFfao6iq0WdmJne3qNjRg47+zFVoAAHT+xekVH2kuy3XnhhFdFCYTf8wXRPvd1x0cQ+OqLp83NiLd3zL2MgkzYXn1Dn71bKxE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169450902435054.656486111639765; Tue, 12 Sep 2023 01:57:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfzC0-0008P9-Db; Tue, 12 Sep 2023 04:56:22 -0400 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 1qfzBm-0008E4-Ar for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:56:07 -0400 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfzBk-0002C0-47 for qemu-devel@nongnu.org; Tue, 12 Sep 2023 04:56:06 -0400 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-572a7141434so3090858eaf.2 for ; Tue, 12 Sep 2023 01:54:03 -0700 (PDT) Received: from 64217.gitgo.cc ([8.210.91.195]) by smtp.gmail.com with ESMTPSA id m6-20020a637d46000000b00570668ccd5bsm6523754pgn.14.2023.09.12.01.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 01:54:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1694508843; x=1695113643; 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=ZngRalemChwakz8wrbTdzeq+OAAg9Tm3RzDMb6BGc10=; b=O6gLf8NhIJgjzA/Xc81o5KC5CLyK0iinAMP/vOXoKS2cNtND1gGAyQSyqjwYkwQddW irG3RZqXgSNX1mHQxFn2r4Euxn1nyhQBUh0H7jsm+AMehMcH+arR/anInptLo1CWHd0F 6Nk3BxzvvlfX4my0hpJc+Jv1+S2vk5biMFOCSkRF8sAWIlENduHbaUmNOF7hW9u82qbU k0zg6ktVeVf+ZLkAlIw8RZMdZnngwNp0wk/JEsqoSNk9z2EsOKsL/xM1BKvyxorNNhWA 9Ioh+fsaKio+TEaE3E2B3kwcm/Z70I62qiGLDRj8AlfsRWYSEkWwb4gSh8s4BWLW1+ky a7CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694508843; x=1695113643; 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=ZngRalemChwakz8wrbTdzeq+OAAg9Tm3RzDMb6BGc10=; b=cdnn2FMh8OmfqoeHEGsaqL8Ftmr25LLq9gHWO354evfo/lHvwMljjTbGKnUS5CYzzY OLs983G9/qmWWppAmpiSWSET40nYD08onmXpqIL7GBk6pZD4x67ukEZGIaUdNIMDl2I0 P2/hXvzseV/x9jhNYfGccPluetAO84GZxKI48WMKuQ0Vg9VtHLJxvXSNS7NvNTTPf35i jTwfKHgbZ/R9vndzmC8o52X1kvPX6CudqrLZRWyla+5vlK56jbXWhRYYEU/q8q8t5GfZ Q24JXQMTD/7TmJIGENsliq3cxnZaGJGlWsvO25klHeAGAlz1HeLx3h/gwPz4xvHxjzfT 12rw== X-Gm-Message-State: AOJu0Yz9Kh4DepSTl+dwJrDfrqHdY3lsUTJLQh+ckKry/PE7BLPJr7K5 4WRCGOXSAQXK1xUVJ89tLJFpRg== X-Google-Smtp-Source: AGHT+IFGbt9vQaNXPVAuhW90D5Tn3O/t6/5Io0taecRANDY8WpyhrJX13sC+2ZotOSuYj8jwxXfuoQ== X-Received: by 2002:a05:6359:4e97:b0:141:10f4:1cbc with SMTP id os23-20020a0563594e9700b0014110f41cbcmr2559945rwb.14.1694508842505; Tue, 12 Sep 2023 01:54:02 -0700 (PDT) From: Li Feng To: Markus Armbruster , Raphael Norwitz , "Michael S. Tsirkin" , Kevin Wolf , Hanna Reitz , Paolo Bonzini , Fam Zheng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Viresh Kumar , qemu-block@nongnu.org (open list:Block layer core), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Li Feng Subject: [PATCH v4 5/5] vhost-user: fix lost reconnect Date: Tue, 12 Sep 2023 16:52:47 +0800 Message-ID: <20230912085315.2524857-6-fengli@smartx.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230912085315.2524857-1-fengli@smartx.com> References: <20230721105205.1714449-1-fengli@smartx.com> <20230912085315.2524857-1-fengli@smartx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::c29; envelope-from=fengli@smartx.com; helo=mail-oo1-xc29.google.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1694509025918100007 Content-Type: text/plain; charset="utf-8" When the vhost-user is reconnecting to the backend, and if the vhost-user f= ails at the get_features in vhost_dev_init(), then the reconnect will fail and it will not be retriggered forever. The reason is: When the vhost-user fails at get_features, the vhost_dev_cleanup will be ca= lled immediately. vhost_dev_cleanup calls 'memset(hdev, 0, sizeof(struct vhost_dev))'. The reconnect path is: vhost_user_blk_event vhost_user_async_close(.. vhost_user_blk_disconnect ..) qemu_chr_fe_set_handlers <----- clear the notifier callback schedule vhost_user_async_close_bh The vhost->vdev is null, so the vhost_user_blk_disconnect will not be called, then the event fd callback will not be reinstalled. All vhost-user devices have this issue, including vhost-user-blk/scsi. With this patch, if the vdev->vdev is null, the fd callback will still be reinstalled. Fixes: 71e076a07d ("hw/virtio: generalise CHR_EVENT_CLOSED handling") Signed-off-by: Li Feng --- hw/block/vhost-user-blk.c | 2 +- hw/virtio/vhost-user-gpio.c | 2 +- hw/virtio/vhost-user.c | 9 +++++++-- include/hw/virtio/vhost-user.h | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 3c69fa47d5..95c758200d 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -391,7 +391,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrE= vent event) case CHR_EVENT_CLOSED: /* defer close until later to avoid circular close */ vhost_user_async_close(dev, &s->chardev, &s->dev, - vhost_user_blk_disconnect); + vhost_user_blk_disconnect, vhost_user_blk_e= vent); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index d9979aa5db..04c2cc79f4 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -283,7 +283,7 @@ static void vu_gpio_event(void *opaque, QEMUChrEvent ev= ent) case CHR_EVENT_CLOSED: /* defer close until later to avoid circular close */ vhost_user_async_close(dev, &gpio->chardev, &gpio->vhost_dev, - vu_gpio_disconnect); + vu_gpio_disconnect, vu_gpio_event); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 8dcf049d42..12c4a41f30 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -2643,6 +2643,7 @@ typedef struct { DeviceState *dev; CharBackend *cd; struct vhost_dev *vhost; + IOEventHandler *event_cb; } VhostAsyncCallback; =20 static void vhost_user_async_close_bh(void *opaque) @@ -2657,7 +2658,10 @@ static void vhost_user_async_close_bh(void *opaque) */ if (vhost->vdev) { data->cb(data->dev); - } + } else if (data->event_cb) { + qemu_chr_fe_set_handlers(data->cd, NULL, NULL, data->event_cb, + NULL, data->dev, NULL, true); + } =20 g_free(data); } @@ -2669,7 +2673,8 @@ static void vhost_user_async_close_bh(void *opaque) */ void vhost_user_async_close(DeviceState *d, CharBackend *chardev, struct vhost_dev *vhost, - vu_async_close_fn cb) + vu_async_close_fn cb, + IOEventHandler *event_cb) { if (!runstate_check(RUN_STATE_SHUTDOWN)) { /* diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index 191216a74f..649e9dd54f 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -84,6 +84,7 @@ typedef void (*vu_async_close_fn)(DeviceState *cb); =20 void vhost_user_async_close(DeviceState *d, CharBackend *chardev, struct vhost_dev *vhost, - vu_async_close_fn cb); + vu_async_close_fn cb, + IOEventHandler *event_cb); =20 #endif --=20 2.41.0