From nobody Thu Mar 28 13:36:13 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623253884; cv=none; d=zohomail.com; s=zohoarc; b=GdLxcbHWrxBecRXNRAe7/WrNVllM53DztOYwAxcLiknNoTi6X6b71QBgDnAtw2by7fpcm732OSnTLbpLjGgrzSOP9vRARfcr68KKSUbnk+8m98+bO7RBk50HSC/hjMKmDRZRVcr+nO2NyXhmO29GJd1Q/84Ri0SJggB2iQkNEpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623253884; h=Content-Type: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=QsRenvlp3nKG96CwCi8OsCLbPvu0maTogj4ozGKWBqA=; b=RBbC5t812Ydi703A1NZvMlbz+I1htTfg6rjJ97jFoBd/0Ea62vdFGgoA6SSWzByVVLYylVKmapEK52bDEcYBsW2xtmyV/zV9vVPttWmSsWqdOaDRmevHo9zW41LMnX8qVMSOADTuGmP5IAp+LnG3VvqEZ2Zhw+uL4wonyO9J+Ug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623253884276831.2312650779403; Wed, 9 Jun 2021 08:51:24 -0700 (PDT) Received: from localhost ([::1]:33366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lr0UF-0004vQ-IH for importer2@patchew.org; Wed, 09 Jun 2021 11:51:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QM-00078K-QY for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57421) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QJ-0003Wa-Dz for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-Ewwj0n-cMSWBJ2JCN2oN2A-1; Wed, 09 Jun 2021 11:47:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 29D2B800C60; Wed, 9 Jun 2021 15:47:14 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-230.ams2.redhat.com [10.36.114.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id E164360C04; Wed, 9 Jun 2021 15:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623253638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QsRenvlp3nKG96CwCi8OsCLbPvu0maTogj4ozGKWBqA=; b=W+SJVIduHf5dRK74PA5UJ0tPLG5NbbdZBTMFmg2JVfoX9f/BIJwLuun1SCXl8IaK1d02Oz SBSVkD03Y1BsaPm4Gr/wqOgeRE2lMCGfDAewTs2Ap57oRI5SQltZkxzqBVBXtNhFXchEYm l4HPkm3hIsvo4WrNNvbTdZxrFr9cJCc= X-MC-Unique: Ewwj0n-cMSWBJ2JCN2oN2A-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 1/7] vhost: Add Error parameter to vhost_dev_init() Date: Wed, 9 Jun 2021 17:46:52 +0200 Message-Id: <20210609154658.350308-2-kwolf@redhat.com> In-Reply-To: <20210609154658.350308-1-kwolf@redhat.com> References: <20210609154658.350308-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, raphael.norwitz@nutanix.com, qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This allows callers to return better error messages instead of making one up while the real error ends up on stderr. Most callers can immediately make use of this because they already have an Error parameter themselves. The others just keep printing the error with error_report_err(). Signed-off-by: Kevin Wolf Reviewed-by: Raphael Norwitz Reviewed-by: Stefano Garzarella --- include/hw/virtio/vhost.h | 2 +- backends/cryptodev-vhost.c | 5 ++++- backends/vhost-user.c | 4 ++-- hw/block/vhost-user-blk.c | 4 ++-- hw/net/vhost_net.c | 6 +++++- hw/scsi/vhost-scsi.c | 4 +--- hw/scsi/vhost-user-scsi.c | 4 +--- hw/virtio/vhost-user-fs.c | 3 +-- hw/virtio/vhost-user-vsock.c | 3 +-- hw/virtio/vhost-vsock.c | 3 +-- hw/virtio/vhost.c | 16 ++++++++++------ 11 files changed, 29 insertions(+), 25 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 21a9a52088..2d7aaad67b 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -104,7 +104,7 @@ struct vhost_net { =20 int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, - uint32_t busyloop_timeout); + uint32_t busyloop_timeout, Error **errp); void vhost_dev_cleanup(struct vhost_dev *hdev); int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 8231e7f1bc..bc13e466b4 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -52,6 +52,7 @@ cryptodev_vhost_init( { int r; CryptoDevBackendVhost *crypto; + Error *local_err =3D NULL; =20 crypto =3D g_new(CryptoDevBackendVhost, 1); crypto->dev.max_queues =3D 1; @@ -66,8 +67,10 @@ cryptodev_vhost_init( /* vhost-user needs vq_index to initiate a specific queue pair */ crypto->dev.vq_index =3D crypto->cc->queue_index * crypto->dev.nvqs; =20 - r =3D vhost_dev_init(&crypto->dev, options->opaque, options->backend_t= ype, 0); + r =3D vhost_dev_init(&crypto->dev, options->opaque, options->backend_t= ype, 0, + &local_err); if (r < 0) { + error_report_err(local_err); goto fail; } =20 diff --git a/backends/vhost-user.c b/backends/vhost-user.c index b366610e16..10b39992d2 100644 --- a/backends/vhost-user.c +++ b/backends/vhost-user.c @@ -48,9 +48,9 @@ vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODe= vice *vdev, b->dev.nvqs =3D nvqs; b->dev.vqs =3D g_new0(struct vhost_virtqueue, nvqs); =20 - ret =3D vhost_dev_init(&b->dev, &b->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0); + ret =3D vhost_dev_init(&b->dev, &b->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0, + errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost initialization failed"); return -1; } =20 diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index c6210fad0c..0cb56baefb 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -332,9 +332,9 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) =20 vhost_dev_set_config_notifier(&s->dev, &blk_ops); =20 - ret =3D vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0); + ret =3D vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0, + errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost initialization failed"); return ret; } =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 44c1ed92dc..447b119f85 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -22,6 +22,7 @@ #include "standard-headers/linux/vhost_types.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" +#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" =20 @@ -157,6 +158,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) bool backend_kernel =3D options->backend_type =3D=3D VHOST_BACKEND_TYP= E_KERNEL; struct vhost_net *net =3D g_new0(struct vhost_net, 1); uint64_t features =3D 0; + Error *local_err =3D NULL; =20 if (!options->net_backend) { fprintf(stderr, "vhost-net requires net backend to be setup\n"); @@ -187,8 +189,10 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opti= ons) } =20 r =3D vhost_dev_init(&net->dev, options->opaque, - options->backend_type, options->busyloop_timeout); + options->backend_type, options->busyloop_timeout, + &local_err); if (r < 0) { + error_report_err(local_err); goto fail; } if (backend_kernel) { diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 4d70fa036b..8c611bfd2d 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -219,10 +219,8 @@ static void vhost_scsi_realize(DeviceState *dev, Error= **errp) vsc->dev.backend_features =3D 0; =20 ret =3D vhost_dev_init(&vsc->dev, (void *)(uintptr_t)vhostfd, - VHOST_BACKEND_TYPE_KERNEL, 0); + VHOST_BACKEND_TYPE_KERNEL, 0, errp); if (ret < 0) { - error_setg(errp, "vhost-scsi: vhost initialization failed: %s", - strerror(-ret)); goto free_vqs; } =20 diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 4666019442..1b2f7eed98 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -122,10 +122,8 @@ static void vhost_user_scsi_realize(DeviceState *dev, = Error **errp) vqs =3D vsc->dev.vqs; =20 ret =3D vhost_dev_init(&vsc->dev, &s->vhost_user, - VHOST_BACKEND_TYPE_USER, 0); + VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { - error_setg(errp, "vhost-user-scsi: vhost initialization failed: %s= ", - strerror(-ret)); goto free_vhost; } =20 diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 6f7f91533d..c595957983 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -235,9 +235,8 @@ static void vuf_device_realize(DeviceState *dev, Error = **errp) fs->vhost_dev.nvqs =3D 1 + fs->conf.num_request_queues; fs->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, fs->vhost_dev.nvq= s); ret =3D vhost_dev_init(&fs->vhost_dev, &fs->vhost_user, - VHOST_BACKEND_TYPE_USER, 0); + VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost_dev_init failed"); goto err_virtio; } =20 diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c index a6f08c26b9..b6a4a25ea1 100644 --- a/hw/virtio/vhost-user-vsock.c +++ b/hw/virtio/vhost-user-vsock.c @@ -108,9 +108,8 @@ static void vuv_device_realize(DeviceState *dev, Error = **errp) vhost_dev_set_config_notifier(&vvc->vhost_dev, &vsock_ops); =20 ret =3D vhost_dev_init(&vvc->vhost_dev, &vsock->vhost_user, - VHOST_BACKEND_TYPE_USER, 0); + VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost_dev_init failed"); goto err_virtio; } =20 diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index 8ddfb9abfe..777cafe70d 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -170,9 +170,8 @@ static void vhost_vsock_device_realize(DeviceState *dev= , Error **errp) vhost_vsock_common_realize(vdev, "vhost-vsock"); =20 ret =3D vhost_dev_init(&vvc->vhost_dev, (void *)(uintptr_t)vhostfd, - VHOST_BACKEND_TYPE_KERNEL, 0); + VHOST_BACKEND_TYPE_KERNEL, 0, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost-vsock: vhost_dev_init failed"); goto err_virtio; } =20 diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 7b7bde7657..991c67ddcd 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1286,7 +1286,8 @@ static void vhost_virtqueue_cleanup(struct vhost_virt= queue *vq) } =20 int vhost_dev_init(struct vhost_dev *hdev, void *opaque, - VhostBackendType backend_type, uint32_t busyloop_timeou= t) + VhostBackendType backend_type, uint32_t busyloop_timeou= t, + Error **errp) { uint64_t features; int i, r, n_initialized_vqs =3D 0; @@ -1300,24 +1301,26 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, =20 r =3D hdev->vhost_ops->vhost_backend_init(hdev, opaque); if (r < 0) { + error_setg(errp, "vhost_backend_init failed"); goto fail; } =20 r =3D hdev->vhost_ops->vhost_set_owner(hdev); if (r < 0) { - VHOST_OPS_DEBUG("vhost_set_owner failed"); + error_setg(errp, "vhost_set_owner failed"); goto fail; } =20 r =3D hdev->vhost_ops->vhost_get_features(hdev, &features); if (r < 0) { - VHOST_OPS_DEBUG("vhost_get_features failed"); + error_setg(errp, "vhost_get_features failed"); goto fail; } =20 for (i =3D 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i= ); if (r < 0) { + error_setg_errno(errp, -r, "Failed to initialize virtqueue %d"= , i); goto fail; } } @@ -1327,6 +1330,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, r =3D vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_inde= x + i, busyloop_timeout); if (r < 0) { + error_setg(errp, "Failed to set busyloop timeout"); goto fail_busyloop; } } @@ -1367,7 +1371,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, if (hdev->migration_blocker !=3D NULL) { r =3D migrate_add_blocker(hdev->migration_blocker, &local_err); if (local_err) { - error_report_err(local_err); + error_propagate(errp, local_err); error_free(hdev->migration_blocker); goto fail_busyloop; } @@ -1384,8 +1388,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); =20 if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev= )) { - error_report("vhost backend memory slots limit is less" - " than current number of present memory slots"); + error_setg(errp, "vhost backend memory slots limit is less" + " than current number of present memory slots"); r =3D -1; goto fail_busyloop; } --=20 2.30.2 From nobody Thu Mar 28 13:36:13 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623254100; cv=none; d=zohomail.com; s=zohoarc; b=JQmu6grZsi/ZzjHJrB+OO43qkBNEm92dwA3FTA9PgfSoTJNmokfK0i1DDJCey6qETYFZCMRA+Sc0c0cQrM++Ih33GkdEENHsU7S/he3FFLMgbPMvYxVQnj+Umu+vegbIfXPvfrhm4NFfnZ9Q6VCmeuT3fJ4bliCKRZsoGVx+ce0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623254100; h=Content-Type: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=jf6IwMWyNVTUnSBHgtlV4DtEob3+rpzWaDyNe4htD5g=; b=iEKmK0aOj+MFZTtx2ioD+ozBlW7/VGQ1QgHfmyMYZZiVRaV7dTAjEvBaUisU6Ln67fRDOmTDaLaH9I5GyfpSunlXyPaoYKjqOr/iqS+cfHjE8QFQ+QCyQJI4GgzvQyJZyKmVZjaGmu5S28hW8QOHJnq3fXBoEL+4t25KdUPsnCs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623254100339840.7290665606686; Wed, 9 Jun 2021 08:55:00 -0700 (PDT) Received: from localhost ([::1]:38752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lr0Xi-00007r-VK for importer2@patchew.org; Wed, 09 Jun 2021 11:54:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QO-0007Dn-6o for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QK-0003Ws-DG for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-469-TkYEZD0jP72DXhsLIzv2JQ-1; Wed, 09 Jun 2021 11:47:16 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 883341922962; Wed, 9 Jun 2021 15:47:15 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-230.ams2.redhat.com [10.36.114.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71F4A60E3A; Wed, 9 Jun 2021 15:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623253639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jf6IwMWyNVTUnSBHgtlV4DtEob3+rpzWaDyNe4htD5g=; b=KM4o029cj3rUEXoyk0Hu+YpptBYtCI+6fkO+XyzpmUpOJ0ie4tn5l/do0cDj/Oq3V28CvN IsYeN2/HffZaGH1ehFrGmuPnXPPXALXoLzUFIQrecNza0/Dci9JwaLg4kTePJ4lHRMHYLO ULwlp5M0LaNSLerilHd+bLxG8IyeqCU= X-MC-Unique: TkYEZD0jP72DXhsLIzv2JQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 2/7] vhost: Distinguish errors in vhost_backend_init() Date: Wed, 9 Jun 2021 17:46:53 +0200 Message-Id: <20210609154658.350308-3-kwolf@redhat.com> In-Reply-To: <20210609154658.350308-1-kwolf@redhat.com> References: <20210609154658.350308-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, raphael.norwitz@nutanix.com, qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of just returning 0/-1 and letting the caller make up a meaningless error message, add an Error parameter to allow reporting the real error and switch to 0/-errno so that different kind of errors can be distinguished in the caller. Specifically, in vhost-user, EPROTO is used for all errors that relate to the connection itself, whereas other error codes are used for errors relating to the content of the connection. This will allow us later to automatically reconnect when the connection goes away, without ending up in an endless loop if it's a permanent error in the configuration. Signed-off-by: Kevin Wolf Reviewed-by: Raphael Norwitz Reviewed-by: Stefano Garzarella --- include/hw/virtio/vhost-backend.h | 3 ++- hw/virtio/vhost-backend.c | 2 +- hw/virtio/vhost-user.c | 41 ++++++++++++++++--------------- hw/virtio/vhost-vdpa.c | 2 +- hw/virtio/vhost.c | 13 +++++----- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 8a6f8e2a7a..728ebb0ed9 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -37,7 +37,8 @@ struct vhost_scsi_target; struct vhost_iotlb_msg; struct vhost_virtqueue; =20 -typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque); +typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque, + Error **errp); typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev); =20 diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 31b33bde37..f4f71cf58a 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -30,7 +30,7 @@ static int vhost_kernel_call(struct vhost_dev *dev, unsig= ned long int request, return ioctl(fd, request, arg); } =20 -static int vhost_kernel_init(struct vhost_dev *dev, void *opaque) +static int vhost_kernel_init(struct vhost_dev *dev, void *opaque, Error **= errp) { assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_KERNEL); =20 diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index ee57abe045..024cb201bb 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1856,7 +1856,8 @@ static int vhost_user_postcopy_notifier(NotifierWithR= eturn *notifier, return 0; } =20 -static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque) +static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque, + Error **errp) { uint64_t features, protocol_features, ram_slots; struct vhost_user *u; @@ -1871,7 +1872,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque) =20 err =3D vhost_user_get_features(dev, &features); if (err < 0) { - return err; + return -EPROTO; } =20 if (virtio_has_feature(features, VHOST_USER_F_PROTOCOL_FEATURES)) { @@ -1880,7 +1881,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque) err =3D vhost_user_get_u64(dev, VHOST_USER_GET_PROTOCOL_FEATURES, &protocol_features); if (err < 0) { - return err; + return -EPROTO; } =20 dev->protocol_features =3D @@ -1891,14 +1892,14 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque) dev->protocol_features &=3D ~(1ULL << VHOST_USER_PROTOCOL_F_CO= NFIG); } else if (!(protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_CONFIG))) { - error_report("Device expects VHOST_USER_PROTOCOL_F_CONFIG " - "but backend does not support it."); - return -1; + error_setg(errp, "Device expects VHOST_USER_PROTOCOL_F_CONFIG " + "but backend does not support it."); + return -EINVAL; } =20 err =3D vhost_user_set_protocol_features(dev, dev->protocol_featur= es); if (err < 0) { - return err; + return -EPROTO; } =20 /* query the max queues we support if backend supports Multiple Qu= eue */ @@ -1906,12 +1907,12 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque) err =3D vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues); if (err < 0) { - return err; + return -EPROTO; } } if (dev->num_queues && dev->max_queues < dev->num_queues) { - error_report("The maximum number of queues supported by the " - "backend is %" PRIu64, dev->max_queues); + error_setg(errp, "The maximum number of queues supported by th= e " + "backend is %" PRIu64, dev->max_queues); return -EINVAL; } =20 @@ -1920,9 +1921,9 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque) VHOST_USER_PROTOCOL_F_SLAVE_REQ) && virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_REPLY_ACK))) { - error_report("IOMMU support requires reply-ack and " - "slave-req protocol features."); - return -1; + error_setg(errp, "IOMMU support requires reply-ack and " + "slave-req protocol features."); + return -EINVAL; } =20 /* get max memory regions if backend supports configurable RAM slo= ts */ @@ -1932,15 +1933,15 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque) } else { err =3D vhost_user_get_max_memslots(dev, &ram_slots); if (err < 0) { - return err; + return -EPROTO; } =20 if (ram_slots < u->user->memory_slots) { - error_report("The backend specified a max ram slots limit " - "of %" PRIu64", when the prior validated limi= t was %d. " - "This limit should never decrease.", ram_slot= s, - u->user->memory_slots); - return -1; + error_setg(errp, "The backend specified a max ram slots li= mit " + "of %" PRIu64", when the prior validated limit = was " + "%d. This limit should never decrease.", ram_sl= ots, + u->user->memory_slots); + return -EINVAL; } =20 u->user->memory_slots =3D MIN(ram_slots, VHOST_USER_MAX_RAM_SL= OTS); @@ -1958,7 +1959,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque) if (dev->vq_index =3D=3D 0) { err =3D vhost_setup_slave_channel(dev); if (err < 0) { - return err; + return -EPROTO; } } =20 diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index ee51863d28..c2aadb57cb 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -273,7 +273,7 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev= , uint8_t status) vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s); } =20 -static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque) +static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **er= rp) { struct vhost_vdpa *v; uint64_t features; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 991c67ddcd..fd13135706 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1289,9 +1289,9 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, VhostBackendType backend_type, uint32_t busyloop_timeou= t, Error **errp) { + ERRP_GUARD(); uint64_t features; int i, r, n_initialized_vqs =3D 0; - Error *local_err =3D NULL; =20 hdev->vdev =3D NULL; hdev->migration_blocker =3D NULL; @@ -1299,9 +1299,11 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opa= que, r =3D vhost_set_backend_type(hdev, backend_type); assert(r >=3D 0); =20 - r =3D hdev->vhost_ops->vhost_backend_init(hdev, opaque); + r =3D hdev->vhost_ops->vhost_backend_init(hdev, opaque, errp); if (r < 0) { - error_setg(errp, "vhost_backend_init failed"); + if (!*errp) { + error_setg_errno(errp, -r, "vhost_backend_init failed"); + } goto fail; } =20 @@ -1369,9 +1371,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } =20 if (hdev->migration_blocker !=3D NULL) { - r =3D migrate_add_blocker(hdev->migration_blocker, &local_err); - if (local_err) { - error_propagate(errp, local_err); + r =3D migrate_add_blocker(hdev->migration_blocker, errp); + if (*errp) { error_free(hdev->migration_blocker); goto fail_busyloop; } --=20 2.30.2 From nobody Thu Mar 28 13:36:13 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623253900; cv=none; d=zohomail.com; s=zohoarc; b=fxY/ZtR0ZyTNRO5Oq8bdgLzm1EnjCQRJX+wdQZ6eZ0cWAaAPyqswLCrXfVhhzVgH9C7m7gcDJdHXn0NHIsti8PgC92KudvyhICiuLWjpMZoW066DkfRIQ4MSW4YpqlLnd5f51L7ZUvgjxXn71WLEJ00yfegLgIMCM+D+lRJFDYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623253900; h=Content-Type: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=AwLhbYdao90/bmCOvITHKciKwVoD7vt+yrLhOBsJ2ho=; b=f1JDP6UjOg/dgYwzUtR/0do11APHiJ327RwxMS4t22ywMQ/n8xlh6CTEvAkYPgFMVv97WJX90XJEaGc0pC1+a/bChirkBoJdIp8LmaHBkoTP2tlxIEdT1sEygDSbDQjca5YsExnPF49B326XWWNsm1Zl1Y5gz/6Tiv7yxsi108I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623253900607451.47163307470976; Wed, 9 Jun 2021 08:51:40 -0700 (PDT) Received: from localhost ([::1]:34354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lr0UV-0005b2-K5 for importer2@patchew.org; Wed, 09 Jun 2021 11:51:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QN-0007B0-Gc for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60345) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QL-0003Xp-Qz for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-223-LrlaAbO5N3eyuw6XpGuOJA-1; Wed, 09 Jun 2021 11:47:18 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4754A40C4; Wed, 9 Jun 2021 15:47:16 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-230.ams2.redhat.com [10.36.114.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEB8060CCC; Wed, 9 Jun 2021 15:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623253641; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AwLhbYdao90/bmCOvITHKciKwVoD7vt+yrLhOBsJ2ho=; b=VspE5LY4nDh4oKuRDO/3zvlkVJ/aX1if+Ssb2BBjiJ8DRlgqCbrO8I/dIpiyH8Mrz+Ky4G x/H2zzwDap8XlX3gWdtSXu5aVdM3zmw54P7BmFtPP22qJj/r3ot/4/use4berhCQNEiAGE zfFe8yP9ZSqND+JvKDiVhhmxh2OCtvc= X-MC-Unique: LrlaAbO5N3eyuw6XpGuOJA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 3/7] vhost: Return 0/-errno in vhost_dev_init() Date: Wed, 9 Jun 2021 17:46:54 +0200 Message-Id: <20210609154658.350308-4-kwolf@redhat.com> In-Reply-To: <20210609154658.350308-1-kwolf@redhat.com> References: <20210609154658.350308-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, raphael.norwitz@nutanix.com, qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of just returning 0/-1 and letting the caller make up a meaningless error message, switch to 0/-errno so that different kinds of errors can be distinguished in the caller. This involves changing a few more callbacks in VhostOps to return 0/-errno: .vhost_set_owner(), .vhost_get_features() and .vhost_virtqueue_set_busyloop_timeout(). The implementations of these functions are trivial as they generally just send a message to the backend. Signed-off-by: Kevin Wolf Reviewed-by: Raphael Norwitz Reviewed-by: Stefano Garzarella --- hw/virtio/vhost-backend.c | 4 +++- hw/virtio/vhost-user.c | 10 +++++++--- hw/virtio/vhost-vdpa.c | 4 +++- hw/virtio/vhost.c | 8 ++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index f4f71cf58a..594d770b75 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -24,10 +24,12 @@ static int vhost_kernel_call(struct vhost_dev *dev, uns= igned long int request, void *arg) { int fd =3D (uintptr_t) dev->opaque; + int ret; =20 assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_KERNEL); =20 - return ioctl(fd, request, arg); + ret =3D ioctl(fd, request, arg); + return ret < 0 ? -errno : ret; } =20 static int vhost_kernel_init(struct vhost_dev *dev, void *opaque, Error **= errp) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 024cb201bb..889559d86a 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1353,7 +1353,11 @@ static int vhost_user_get_u64(struct vhost_dev *dev,= int request, uint64_t *u64) =20 static int vhost_user_get_features(struct vhost_dev *dev, uint64_t *featur= es) { - return vhost_user_get_u64(dev, VHOST_USER_GET_FEATURES, features); + if (vhost_user_get_u64(dev, VHOST_USER_GET_FEATURES, features) < 0) { + return -EPROTO; + } + + return 0; } =20 static int vhost_user_set_owner(struct vhost_dev *dev) @@ -1364,7 +1368,7 @@ static int vhost_user_set_owner(struct vhost_dev *dev) }; =20 if (vhost_user_write(dev, &msg, NULL, 0) < 0) { - return -1; + return -EPROTO; } =20 return 0; @@ -1872,7 +1876,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, =20 err =3D vhost_user_get_features(dev, &features); if (err < 0) { - return -EPROTO; + return err; } =20 if (virtio_has_feature(features, VHOST_USER_F_PROTOCOL_FEATURES)) { diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index c2aadb57cb..71897c1a01 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -253,10 +253,12 @@ static int vhost_vdpa_call(struct vhost_dev *dev, uns= igned long int request, { struct vhost_vdpa *v =3D dev->opaque; int fd =3D v->device_fd; + int ret; =20 assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); =20 - return ioctl(fd, request, arg); + ret =3D ioctl(fd, request, arg); + return ret < 0 ? -errno : ret; } =20 static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index fd13135706..c7f9d8bb06 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1309,13 +1309,13 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, =20 r =3D hdev->vhost_ops->vhost_set_owner(hdev); if (r < 0) { - error_setg(errp, "vhost_set_owner failed"); + error_setg_errno(errp, -r, "vhost_set_owner failed"); goto fail; } =20 r =3D hdev->vhost_ops->vhost_get_features(hdev, &features); if (r < 0) { - error_setg(errp, "vhost_get_features failed"); + error_setg_errno(errp, -r, "vhost_get_features failed"); goto fail; } =20 @@ -1332,7 +1332,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, r =3D vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_inde= x + i, busyloop_timeout); if (r < 0) { - error_setg(errp, "Failed to set busyloop timeout"); + error_setg_errno(errp, -r, "Failed to set busyloop timeout= "); goto fail_busyloop; } } @@ -1391,7 +1391,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev= )) { error_setg(errp, "vhost backend memory slots limit is less" " than current number of present memory slots"); - r =3D -1; + r =3D -EINVAL; goto fail_busyloop; } =20 --=20 2.30.2 From nobody Thu Mar 28 13:36:13 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623254030; cv=none; d=zohomail.com; s=zohoarc; b=eKps2nDQ6fmt7KI+cxJRyuOeJHcKlzI7loJeojSCiA0bSAJKQU43ISAS2Od5p2UbqdjddP7PkTh3R0VnKWGNQkTmKKaP4XkwLvnwK7AnyKxoF/DLxUcLR9RJ6qryLCn2A889d09by4WbmW7aAoi/RBNlBWETGeEBwoUyk3f4EY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623254030; h=Content-Type: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=q3FKQlHkGfNUWftxKfhvnk0jyAMxY9WtPIUYiEnccnU=; b=azTfV0zbXw18GTdeR9ZEgjvneGYCwGZRBs+VIgH4wts9JWm7C6O+Xc/1vD2TP/utC/dN1KhKQlnAcWq0cn1+CTz11IH6rnBxjMLZpxXFobr3BfVcvb152d3xwSF5Uq37TuaLH+cM94YnYo5SYXl0yrHHRoMC61jnybLxOp+lz7I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623254030586756.9213711878836; Wed, 9 Jun 2021 08:53:50 -0700 (PDT) Received: from localhost ([::1]:38086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lr0Wb-00087X-Fg for importer2@patchew.org; Wed, 09 Jun 2021 11:53:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QS-0007X3-RW for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44060) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QN-0003Yh-Mu for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-31-I-yG0DLDPTG-Yxp3AqPYGQ-1; Wed, 09 Jun 2021 11:47:21 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 908D01922963; Wed, 9 Jun 2021 15:47:20 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-230.ams2.redhat.com [10.36.114.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36BB760C04; Wed, 9 Jun 2021 15:47:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623253643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q3FKQlHkGfNUWftxKfhvnk0jyAMxY9WtPIUYiEnccnU=; b=ROC5FkTg46AtIwdcFF6no+zMlBmUJ4swVZXzProQN49tXteSVm4ymcEXLKNQ1Dnmcsp2BI yB0tBxpA/GglEy+4/gdvJUmUkZck0GyGj7NNZwHVjFUdnT+8YNffXSoX8a2QG8Jaq5M+o4 594QolWYf2XRnx74m5AZ5FfaehrWT8U= X-MC-Unique: I-yG0DLDPTG-Yxp3AqPYGQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 4/7] vhost-user-blk: Add Error parameter to vhost_user_blk_start() Date: Wed, 9 Jun 2021 17:46:55 +0200 Message-Id: <20210609154658.350308-5-kwolf@redhat.com> In-Reply-To: <20210609154658.350308-1-kwolf@redhat.com> References: <20210609154658.350308-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, raphael.norwitz@nutanix.com, qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of letting the caller make up a meaningless error message, add an Error parameter to allow reporting the real error. Signed-off-by: Kevin Wolf Reviewed-by: Raphael Norwitz Reviewed-by: Stefano Garzarella --- hw/block/vhost-user-blk.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 0cb56baefb..e9382e152a 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -113,7 +113,7 @@ const VhostDevConfigOps blk_ops =3D { .vhost_dev_config_notifier =3D vhost_user_blk_handle_config_change, }; =20 -static int vhost_user_blk_start(VirtIODevice *vdev) +static int vhost_user_blk_start(VirtIODevice *vdev, Error **errp) { VHostUserBlk *s =3D VHOST_USER_BLK(vdev); BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); @@ -121,19 +121,19 @@ static int vhost_user_blk_start(VirtIODevice *vdev) int i, ret; =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(&s->dev, vdev); if (ret < 0) { - error_report("Error enabling host notifiers: %d", -ret); + error_setg_errno(errp, -ret, "Error enabling host notifiers"); return ret; } =20 ret =3D k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true); if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); + error_setg_errno(errp, -ret, "Error binding guest notifier"); goto err_host_notifiers; } =20 @@ -141,27 +141,27 @@ static int vhost_user_blk_start(VirtIODevice *vdev) =20 ret =3D vhost_dev_prepare_inflight(&s->dev, vdev); if (ret < 0) { - error_report("Error set inflight format: %d", -ret); + error_setg_errno(errp, -ret, "Error setting inflight format"); goto err_guest_notifiers; } =20 if (!s->inflight->addr) { ret =3D vhost_dev_get_inflight(&s->dev, s->queue_size, s->inflight= ); if (ret < 0) { - error_report("Error get inflight: %d", -ret); + error_setg_errno(errp, -ret, "Error getting inflight"); goto err_guest_notifiers; } } =20 ret =3D vhost_dev_set_inflight(&s->dev, s->inflight); if (ret < 0) { - error_report("Error set inflight: %d", -ret); + error_setg_errno(errp, -ret, "Error setting inflight"); goto err_guest_notifiers; } =20 ret =3D vhost_dev_start(&s->dev, vdev); if (ret < 0) { - error_report("Error starting vhost: %d", -ret); + error_setg_errno(errp, -ret, "Error starting vhost"); goto err_guest_notifiers; } s->started_vu =3D true; @@ -214,6 +214,7 @@ static void vhost_user_blk_set_status(VirtIODevice *vde= v, uint8_t status) { VHostUserBlk *s =3D VHOST_USER_BLK(vdev); bool should_start =3D virtio_device_started(vdev, status); + Error *local_err =3D NULL; int ret; =20 if (!vdev->vm_running) { @@ -229,10 +230,9 @@ static void vhost_user_blk_set_status(VirtIODevice *vd= ev, uint8_t status) } =20 if (should_start) { - ret =3D vhost_user_blk_start(vdev); + ret =3D vhost_user_blk_start(vdev, &local_err); if (ret < 0) { - error_report("vhost-user-blk: vhost start failed: %s", - strerror(-ret)); + error_reportf_err(local_err, "vhost-user-blk: vhost start fail= ed: "); qemu_chr_fe_disconnect(&s->chardev); } } else { @@ -270,6 +270,7 @@ static uint64_t vhost_user_blk_get_features(VirtIODevic= e *vdev, static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) { VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + Error *local_err =3D NULL; int i, ret; =20 if (!vdev->start_on_kick) { @@ -287,10 +288,9 @@ static void vhost_user_blk_handle_output(VirtIODevice = *vdev, VirtQueue *vq) /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start * vhost here instead of waiting for .set_status(). */ - ret =3D vhost_user_blk_start(vdev); + ret =3D vhost_user_blk_start(vdev, &local_err); if (ret < 0) { - error_report("vhost-user-blk: vhost start failed: %s", - strerror(-ret)); + error_reportf_err(local_err, "vhost-user-blk: vhost start failed: = "); qemu_chr_fe_disconnect(&s->chardev); return; } @@ -340,9 +340,8 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) =20 /* restore vhost state */ if (virtio_device_started(vdev, vdev->status)) { - ret =3D vhost_user_blk_start(vdev); + ret =3D vhost_user_blk_start(vdev, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost start failed"); return ret; } } --=20 2.30.2 From nobody Thu Mar 28 13:36:13 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623254272; cv=none; d=zohomail.com; s=zohoarc; b=LTsN6hM+815DO4Yeajakm4UfcyZvFDMLyq2lK/58N7I3hxenwXDxUU4qfi9E1dxvrjnrju7OVBufM7XJQ7Ksg7G0JvMKTPAGXeb3YlVBiHFugrYKrZ8inCQMyvqpmR7ysicoRmrsE1/0pEDPfy+ClOt9gUVFgrA376aebzWiqMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623254272; h=Content-Type: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=lafPdDNgOaGiAFN1M8pIDu3WhjvwtEu+uS/zG3ymrgQ=; b=X8e1XsU5ZkxGDsgzpsgMVxUftqHptOOEbMQmb0qpX/7wcsp+zV6ePGApMbZ39SZQb+Uo0ANKE6m1ObCGg4+6Tv6IP7ii/RkWY5XTk4+T1t8fP6hfX6Jx39tJfY4IcBU9q99ZfyYWextaeWTLHl+dps4RODYeUkBNurtnyRV6UpU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623254272056462.3039718502299; Wed, 9 Jun 2021 08:57:52 -0700 (PDT) Received: from localhost ([::1]:46722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lr0aV-0005l4-4J for importer2@patchew.org; Wed, 09 Jun 2021 11:57:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56314) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QR-0007S2-NS for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21793) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QP-0003Zz-0Q for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-191-RcxI_WUwMM-yuDeZ_btCDg-1; Wed, 09 Jun 2021 11:47:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 035A9800D62; Wed, 9 Jun 2021 15:47:22 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-230.ams2.redhat.com [10.36.114.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB24560C04; Wed, 9 Jun 2021 15:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623253644; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lafPdDNgOaGiAFN1M8pIDu3WhjvwtEu+uS/zG3ymrgQ=; b=JrUV8SNEeOCRy6Pf+Aacj6hOvpenoySKng9DPDmB4qQpKijUkTeNaFPNPcwKq3NwhoSsjn kD3fucfcLvT1os00TRaPkgFLt5Qc2Xs8UrH+wBpdCidQAlelw/TR95ASTS+QomaBZPGDeN SamALejLCXYfVSzsr9rL2L1RUrsBiC0= X-MC-Unique: RcxI_WUwMM-yuDeZ_btCDg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 5/7] vhost: Distinguish errors in vhost_dev_get_config() Date: Wed, 9 Jun 2021 17:46:56 +0200 Message-Id: <20210609154658.350308-6-kwolf@redhat.com> In-Reply-To: <20210609154658.350308-1-kwolf@redhat.com> References: <20210609154658.350308-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, raphael.norwitz@nutanix.com, qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of just returning 0/-1 and letting the caller make up a meaningless error message, add an Error parameter to allow reporting the real error and switch to 0/-errno so that different kind of errors can be distinguished in the caller. Signed-off-by: Kevin Wolf Reviewed-by: Raphael Norwitz Reviewed-by: Stefano Garzarella --- include/hw/virtio/vhost-backend.h | 2 +- include/hw/virtio/vhost.h | 4 ++-- hw/block/vhost-user-blk.c | 9 +++++---- hw/display/vhost-user-gpu.c | 6 ++++-- hw/input/vhost-user-input.c | 6 ++++-- hw/net/vhost_net.c | 2 +- hw/virtio/vhost-user-vsock.c | 9 +++++---- hw/virtio/vhost-user.c | 24 ++++++++++++------------ hw/virtio/vhost-vdpa.c | 2 +- hw/virtio/vhost.c | 14 +++++++++++--- 10 files changed, 46 insertions(+), 32 deletions(-) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 728ebb0ed9..8475c5a29d 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -98,7 +98,7 @@ typedef int (*vhost_set_config_op)(struct vhost_dev *dev,= const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags); typedef int (*vhost_get_config_op)(struct vhost_dev *dev, uint8_t *config, - uint32_t config_len); + uint32_t config_len, Error **errp); =20 typedef int (*vhost_crypto_create_session_op)(struct vhost_dev *dev, void *session_info, diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 2d7aaad67b..045d0fd9f2 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -130,8 +130,8 @@ int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file); =20 int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int writ= e); -int vhost_dev_get_config(struct vhost_dev *dev, uint8_t *config, - uint32_t config_len); +int vhost_dev_get_config(struct vhost_dev *hdev, uint8_t *config, + uint32_t config_len, Error **errp); int vhost_dev_set_config(struct vhost_dev *dev, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags); /* notifier callback in case vhost device config space changed diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index e9382e152a..3770f715da 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -91,11 +91,13 @@ static int vhost_user_blk_handle_config_change(struct v= host_dev *dev) int ret; struct virtio_blk_config blkcfg; VHostUserBlk *s =3D VHOST_USER_BLK(dev->vdev); + Error *local_err =3D NULL; =20 ret =3D vhost_dev_get_config(dev, (uint8_t *)&blkcfg, - sizeof(struct virtio_blk_config)); + sizeof(struct virtio_blk_config), + &local_err); if (ret < 0) { - error_report("get config space failed"); + error_report_err(local_err); return -1; } =20 @@ -478,9 +480,8 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) assert(s->connected); =20 ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, - sizeof(struct virtio_blk_config)); + sizeof(struct virtio_blk_config), errp); if (ret < 0) { - error_setg(errp, "vhost-user-blk: get block config failed"); goto vhost_err; } =20 diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 6cdaa1c73b..389199e6ca 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -415,14 +415,16 @@ vhost_user_gpu_get_config(VirtIODevice *vdev, uint8_t= *config_data) VirtIOGPUBase *b =3D VIRTIO_GPU_BASE(vdev); struct virtio_gpu_config *vgconfig =3D (struct virtio_gpu_config *)config_data; + Error *local_err =3D NULL; int ret; =20 memset(config_data, 0, sizeof(struct virtio_gpu_config)); =20 ret =3D vhost_dev_get_config(&g->vhost->dev, - config_data, sizeof(struct virtio_gpu_confi= g)); + config_data, sizeof(struct virtio_gpu_confi= g), + &local_err); if (ret) { - error_report("vhost-user-gpu: get device config space failed"); + error_report_err(local_err); return; } =20 diff --git a/hw/input/vhost-user-input.c b/hw/input/vhost-user-input.c index 63984a8ba7..273e96a7b1 100644 --- a/hw/input/vhost-user-input.c +++ b/hw/input/vhost-user-input.c @@ -49,13 +49,15 @@ static void vhost_input_get_config(VirtIODevice *vdev, = uint8_t *config_data) { VirtIOInput *vinput =3D VIRTIO_INPUT(vdev); VHostUserInput *vhi =3D VHOST_USER_INPUT(vdev); + Error *local_err =3D NULL; int ret; =20 memset(config_data, 0, vinput->cfg_size); =20 - ret =3D vhost_dev_get_config(&vhi->vhost->dev, config_data, vinput->cf= g_size); + ret =3D vhost_dev_get_config(&vhi->vhost->dev, config_data, vinput->cf= g_size, + &local_err); if (ret) { - error_report("vhost-user-input: get device config space failed"); + error_report_err(local_err); return; } } diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 447b119f85..10a7780a13 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -117,7 +117,7 @@ uint64_t vhost_net_get_features(struct vhost_net *net, = uint64_t features) int vhost_net_get_config(struct vhost_net *net, uint8_t *config, uint32_t config_len) { - return vhost_dev_get_config(&net->dev, config, config_len); + return vhost_dev_get_config(&net->dev, config, config_len, NULL); } int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags) diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c index b6a4a25ea1..6095ed7349 100644 --- a/hw/virtio/vhost-user-vsock.c +++ b/hw/virtio/vhost-user-vsock.c @@ -34,10 +34,12 @@ static void vuv_get_config(VirtIODevice *vdev, uint8_t = *config) static int vuv_handle_config_change(struct vhost_dev *dev) { VHostUserVSock *vsock =3D VHOST_USER_VSOCK(dev->vdev); + Error *local_err =3D NULL; int ret =3D vhost_dev_get_config(dev, (uint8_t *)&vsock->vsockcfg, - sizeof(struct virtio_vsock_config)); + sizeof(struct virtio_vsock_config), + &local_err); if (ret < 0) { - error_report("get config space failed"); + error_report_err(local_err); return -1; } =20 @@ -114,9 +116,8 @@ static void vuv_device_realize(DeviceState *dev, Error = **errp) } =20 ret =3D vhost_dev_get_config(&vvc->vhost_dev, (uint8_t *)&vsock->vsock= cfg, - sizeof(struct virtio_vsock_config)); + sizeof(struct virtio_vsock_config), errp); if (ret < 0) { - error_setg_errno(errp, -ret, "get config space failed"); goto err_vhost_dev; } =20 diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 889559d86a..1ac4a2ebec 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -2117,7 +2117,7 @@ static void vhost_user_set_iotlb_callback(struct vhos= t_dev *dev, int enabled) } =20 static int vhost_user_get_config(struct vhost_dev *dev, uint8_t *config, - uint32_t config_len) + uint32_t config_len, Error **errp) { VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_GET_CONFIG, @@ -2127,32 +2127,32 @@ static int vhost_user_get_config(struct vhost_dev *= dev, uint8_t *config, =20 if (!virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_CONFIG)) { - return -1; + error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported"); + return -EINVAL; } =20 - if (config_len > VHOST_USER_MAX_CONFIG_SIZE) { - return -1; - } + assert(config_len <=3D VHOST_USER_MAX_CONFIG_SIZE); =20 msg.payload.config.offset =3D 0; msg.payload.config.size =3D config_len; if (vhost_user_write(dev, &msg, NULL, 0) < 0) { - return -1; + return -EPROTO; } =20 if (vhost_user_read(dev, &msg) < 0) { - return -1; + return -EPROTO; } =20 if (msg.hdr.request !=3D VHOST_USER_GET_CONFIG) { - error_report("Received unexpected msg type. Expected %d received %= d", - VHOST_USER_GET_CONFIG, msg.hdr.request); - return -1; + error_setg(errp, + "Received unexpected msg type. Expected %d received %d", + VHOST_USER_GET_CONFIG, msg.hdr.request); + return -EINVAL; } =20 if (msg.hdr.size !=3D VHOST_USER_CONFIG_HDR_SIZE + config_len) { - error_report("Received bad msg size."); - return -1; + error_setg(errp, "Received bad msg size."); + return -EINVAL; } =20 memcpy(config, msg.payload.config.region, config_len); diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 71897c1a01..6b6f974a83 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -451,7 +451,7 @@ static int vhost_vdpa_set_config(struct vhost_dev *dev,= const uint8_t *data, } =20 static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, - uint32_t config_len) + uint32_t config_len, Error **errp) { struct vhost_vdpa_config *v_config; unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index c7f9d8bb06..1b66f1de70 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1562,15 +1562,23 @@ void vhost_ack_features(struct vhost_dev *hdev, con= st int *feature_bits, } =20 int vhost_dev_get_config(struct vhost_dev *hdev, uint8_t *config, - uint32_t config_len) + uint32_t config_len, Error **errp) { + ERRP_GUARD(); + int ret; + assert(hdev->vhost_ops); =20 if (hdev->vhost_ops->vhost_get_config) { - return hdev->vhost_ops->vhost_get_config(hdev, config, config_len); + ret =3D hdev->vhost_ops->vhost_get_config(hdev, config, config_len= , errp); + if (ret < 0 && !*errp) { + error_setg_errno(errp, -ret, "vhost_get_config failed"); + } + return ret; } =20 - return -1; + error_setg(errp, "vhost_dev_get_config not implemented"); + return -ENOTSUP; } =20 int vhost_dev_set_config(struct vhost_dev *hdev, const uint8_t *data, --=20 2.30.2 From nobody Thu Mar 28 13:36:13 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623254382; cv=none; d=zohomail.com; s=zohoarc; b=nJkBOS7HWOTTDcdBp0uEuBwhw3XHgvkkshou44skiJV0K+KBms9hUHfbKs0f9w+TTiaXgZbUGeEgDFp4Pac0da35IG7j0lmccdeCkVtrozUIpE/3niQS1jRqOzBiSSFhbPvC/Wjcxx8fQm4rG852zPfuITwkRnErWJip60lLeCw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623254382; h=Content-Type: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=ZOo44B98EAyARiLh+Id+3wdcQkLpZKimJCNsNiAmHig=; b=I5KaPw4BgfQKgCtVYAL92KHUNs7heWv4DRK5RBQaV8sHfbipaE2NophWA/UgJHH3Laix3kOM+jm1dORYzTFUJJssY1XlhJaLYP5doSWN9evCjOFldUmEs4QP9Ka1Ue//ML8Vsij1m7P7NBOm6M8q0wO0mR9IOU9sxq8zD1q5M/4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623254382892608.0562464225646; Wed, 9 Jun 2021 08:59:42 -0700 (PDT) Received: from localhost ([::1]:55288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lr0cH-0002zU-T9 for importer2@patchew.org; Wed, 09 Jun 2021 11:59:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QT-0007Y5-2z for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21730) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QQ-0003aI-Da for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-456-7PkDdiuMPQWTVPhHx64wwg-1; Wed, 09 Jun 2021 11:47:24 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63572800C60; Wed, 9 Jun 2021 15:47:23 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-230.ams2.redhat.com [10.36.114.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E07F60C04; Wed, 9 Jun 2021 15:47:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623253645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZOo44B98EAyARiLh+Id+3wdcQkLpZKimJCNsNiAmHig=; b=AEqV9oVwqbGKxEQdoIIqE6z/8MDrNCxbQVcV/3MwdPO6FyrcAXiXS1G05E2Ec4sQXWyPc0 Z3XgJzeMWm2YLUguohybd0tBrAM5DNf4CirKdXh6Luu6gRdYHCOKvU8dQIdXBdDjCkl/gl kxR8w4I/yiDau1FJ9fCzubENmnVZJL8= X-MC-Unique: 7PkDdiuMPQWTVPhHx64wwg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 6/7] vhost-user-blk: Factor out vhost_user_blk_realize_connect() Date: Wed, 9 Jun 2021 17:46:57 +0200 Message-Id: <20210609154658.350308-7-kwolf@redhat.com> In-Reply-To: <20210609154658.350308-1-kwolf@redhat.com> References: <20210609154658.350308-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, raphael.norwitz@nutanix.com, qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This function is the part that we will want to retry if the connection is lost during initialisation, so factor it out to keep the following patch simpler. The error path for vhost_dev_get_config() forgot disconnecting the chardev, add this while touching the code. Signed-off-by: Kevin Wolf Reviewed-by: Raphael Norwitz Reviewed-by: Stefano Garzarella --- hw/block/vhost-user-blk.c | 48 ++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 3770f715da..e49d2e4c83 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -423,6 +423,36 @@ static void vhost_user_blk_event(void *opaque, QEMUChr= Event event) } } =20 +static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp) +{ + DeviceState *dev =3D &s->parent_obj.parent_obj; + int ret; + + s->connected =3D false; + + ret =3D qemu_chr_fe_wait_connected(&s->chardev, errp); + if (ret < 0) { + return ret; + } + + ret =3D vhost_user_blk_connect(dev, errp); + if (ret < 0) { + qemu_chr_fe_disconnect(&s->chardev); + return ret; + } + assert(s->connected); + + ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, + sizeof(struct virtio_blk_config), errp); + if (ret < 0) { + qemu_chr_fe_disconnect(&s->chardev); + vhost_dev_cleanup(&s->dev); + return ret; + } + + return 0; +} + static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -467,22 +497,10 @@ static void vhost_user_blk_device_realize(DeviceState= *dev, Error **errp) =20 s->inflight =3D g_new0(struct vhost_inflight, 1); s->vhost_vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); - s->connected =3D false; - - if (qemu_chr_fe_wait_connected(&s->chardev, errp) < 0) { - goto virtio_err; - } =20 - if (vhost_user_blk_connect(dev, errp) < 0) { - qemu_chr_fe_disconnect(&s->chardev); - goto virtio_err; - } - assert(s->connected); - - ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, - sizeof(struct virtio_blk_config), errp); + ret =3D vhost_user_blk_realize_connect(s, errp); if (ret < 0) { - goto vhost_err; + goto virtio_err; } =20 /* we're fully initialized, now we can operate, so add the handler */ @@ -491,8 +509,6 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) NULL, true); return; =20 -vhost_err: - vhost_dev_cleanup(&s->dev); virtio_err: g_free(s->vhost_vqs); s->vhost_vqs =3D NULL; --=20 2.30.2 From nobody Thu Mar 28 13:36:13 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623254255; cv=none; d=zohomail.com; s=zohoarc; b=mwGjbLwazRm34ttNnDA8ernxaWF5W97QiGb1rra0iwFg7IFWJVd7DZBsTEBZ8vXtVo1wN3ZQaE2BhfCNZeEcf65PQB1XXzLmI+FLlxQaCeBfSNKImhQK/kVfpOEGhlgb9bC2BEePy8et9RcUofsfa6iyMYdKWbgPU7wcji/Dijs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623254255; h=Content-Type: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=sorXIMPWrawIKyHExPP4hkOJoQqX3bYITQsH4ecnDV0=; b=jqrTBoZ0yVNzDozGUJ0fKLD0ulsiNho2eimazM9mOFl/FlzC8+TCk892MLhA/AfRd0p0lEJ1TYOmp9f9nkFirX2IBaD5xWiLPLCZVczNbibJmRqgNFyNZ0rSfJxgvOCidav2vtNvmA67nE1R38B8vE0kP/0lijqLtPAb40wPnTM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623254255003676.2734317694053; Wed, 9 Jun 2021 08:57:35 -0700 (PDT) Received: from localhost ([::1]:46120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lr0aE-0005Mo-8l for importer2@patchew.org; Wed, 09 Jun 2021 11:57:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QW-0007mf-Ex for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20993) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr0QR-0003b7-Jh for qemu-devel@nongnu.org; Wed, 09 Jun 2021 11:47:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-65Us_LKMOSqtqUPFDMy_Uw-1; Wed, 09 Jun 2021 11:47:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C758A100A44B; Wed, 9 Jun 2021 15:47:24 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-230.ams2.redhat.com [10.36.114.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB3F160C04; Wed, 9 Jun 2021 15:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623253647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sorXIMPWrawIKyHExPP4hkOJoQqX3bYITQsH4ecnDV0=; b=N2+LCiYE0f4ulvdQSanm6QrLnDhPy7tGJYr9X9jQz6Kowt6dVQaPpPrENX09pL7dhBDDNI HTJ5KN7f29lNjWZ9CROc1tQf82XwGT+z1rk5RqteDJPV+JpjJ8rrUbSv1Geyistj0XI41+ /iWxTgVdm6V9tJbMuSBZ7GoVXcPUXE8= X-MC-Unique: 65Us_LKMOSqtqUPFDMy_Uw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 7/7] vhost-user-blk: Implement reconnection during realize Date: Wed, 9 Jun 2021 17:46:58 +0200 Message-Id: <20210609154658.350308-8-kwolf@redhat.com> In-Reply-To: <20210609154658.350308-1-kwolf@redhat.com> References: <20210609154658.350308-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, raphael.norwitz@nutanix.com, qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit dabefdd6 removed code that was supposed to try reconnecting during .realize(), but actually just crashed and had several design problems. This adds the feature back without the crash in simple cases while also fixing some design problems: Reconnection is now only tried if there was a problem with the connection and not an error related to the content (which would fail again the same way in the next attempt). Reconnection is limited to three attempts (four with the initial attempt) so that we won't end up in an infinite loop if a problem is permanent. If the backend restarts three times in the very short time window of device initialisation, we have bigger problems and erroring out is the right course of action. In the case that a connection error occurs and we reconnect, the error message is printed using error_report_err(), but otherwise ignored. Signed-off-by: Kevin Wolf Reviewed-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index e49d2e4c83..f75a42bc62 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -455,8 +455,10 @@ static int vhost_user_blk_realize_connect(VHostUserBlk= *s, Error **errp) =20 static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) { + ERRP_GUARD(); VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + int retries; int i, ret; =20 if (!s->chardev.chr) { @@ -498,7 +500,17 @@ 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 - ret =3D vhost_user_blk_realize_connect(s, errp); + retries =3D 3; + assert(!*errp); + do { + if (*errp) { + error_prepend(errp, "Reconnecting after error: "); + error_report_err(*errp); + *errp =3D NULL; + } + ret =3D vhost_user_blk_realize_connect(s, errp); + } while (ret =3D=3D -EPROTO && retries--); + if (ret < 0) { goto virtio_err; } --=20 2.30.2