From nobody Sat Jul 12 04:48:29 2025 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