From nobody Tue Dec 16 13:04:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633700223; cv=none; d=zohomail.com; s=zohoarc; b=VJFp2Z2WshaQzE1aLPb3YHiy2WMpnLhRkAOhN0tn3XYm6M6Z08HLZZdGnb/2NE/zPO4RoBiaQGQGLBtrNDFUJTzSW+pFMdI79c/urE0ZE/c0iE4bYc6eSnvglt8DPNhONm/iYrLHn0wFPIO1T8Y0YYulFWTjs3ZbEDdC5FTy7Jo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633700223; 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=An3rlqqtX/BUcmE8YQxipfru8u0V/Sx9fhWF0Iscit4=; b=HC8J11ZzpQgccBX31p4n9EdpYhvdcsKSVHfNxuWrK4lvc43rYGpqnJrTvU0Ms9jftNJyoye+KqTwuB4xFR5mfaZwr4FcBW5CzVNqqJCtWJJCt50Bs6aw6OMTpKISjTJT2Po7rhsYeOt6txkuY31FX9GRCKNhloaUh9DW3/c6zrQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 163370022339970.43143339219944; Fri, 8 Oct 2021 06:37:03 -0700 (PDT) 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-556-vAb0gDofMoWTnu6OjziU8g-1; Fri, 08 Oct 2021 09:36:59 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A654D10939E6; Fri, 8 Oct 2021 13:35:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E70657CA1; Fri, 8 Oct 2021 13:35:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3DE5C4E590; Fri, 8 Oct 2021 13:35:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 198DZ88e026044 for ; Fri, 8 Oct 2021 09:35:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 89970196E5; Fri, 8 Oct 2021 13:35:08 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D9BA196E2; Fri, 8 Oct 2021 13:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633700222; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=An3rlqqtX/BUcmE8YQxipfru8u0V/Sx9fhWF0Iscit4=; b=M55Ip6nSw90LCCgPcuHX7ReM7TXV0YEb8Sy/HNeBR/0KzIhMRM6BN7ZqFn65uTHvyrG442 xMrbvzD+gCVhndnzqxLlJ+HUbyVcfx5lPLKcx3xfbKFx+HafRA//DstWgRhU2WrV679COL +NUMWWRuxht03Rsws7D0HH6fQXNJ0gk= X-MC-Unique: vAb0gDofMoWTnu6OjziU8g-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v2 02/15] net/vhost-user: Fix device compatibility check Date: Fri, 8 Oct 2021 15:34:29 +0200 Message-Id: <20211008133442.141332-3-kwolf@redhat.com> In-Reply-To: <20211008133442.141332-1-kwolf@redhat.com> References: <20211008133442.141332-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, damien.hedde@greensocs.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, mst@redhat.com, libvir-list@redhat.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, vsementsov@virtuozzo.com, lvivier@redhat.com, its@irrelevant.dk, pbonzini@redhat.com, eblake@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633700224198100001 Content-Type: text/plain; charset="utf-8" vhost-user works only with specific devices. At startup, it second guesses what the command line option handling will do and error out if it thinks a non-virtio device will attach to them. This second guessing is not only ugly, it can lead to wrong error messages ('-device floppy,netdev=3Dfoo' should complain about an unknown property, not about the wrong kind of network device being attached) and completely ignores hotplugging. Drop the old checks and implement .check_peer_type() instead to fix this. As a nice side effect, it also removes one more dependency on the legacy QemuOpts infrastructure and even reduces the code size. Signed-off-by: Kevin Wolf Acked-by: Jason Wang Reviewed-by: Damien Hedde --- net/vhost-user.c | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/net/vhost-user.c b/net/vhost-user.c index 4a939124d2..b1a0247b59 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -198,6 +198,19 @@ static bool vhost_user_has_ufo(NetClientState *nc) return true; } =20 +static bool vhost_user_check_peer_type(NetClientState *nc, ObjectClass *oc, + Error **errp) +{ + const char *driver =3D object_class_get_name(oc); + + if (!g_str_has_prefix(driver, "virtio-net-")) { + error_setg(errp, "vhost-user requires frontend driver virtio-net-*= "); + return false; + } + + return true; +} + static NetClientInfo net_vhost_user_info =3D { .type =3D NET_CLIENT_DRIVER_VHOST_USER, .size =3D sizeof(NetVhostUserState), @@ -207,6 +220,7 @@ static NetClientInfo net_vhost_user_info =3D { .has_ufo =3D vhost_user_has_ufo, .set_vnet_be =3D vhost_user_set_vnet_endianness, .set_vnet_le =3D vhost_user_set_vnet_endianness, + .check_peer_type =3D vhost_user_check_peer_type, }; =20 static gboolean net_vhost_user_watch(void *do_not_use, GIOCondition cond, @@ -397,27 +411,6 @@ static Chardev *net_vhost_claim_chardev( return chr; } =20 -static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp) -{ - const char *name =3D opaque; - const char *driver, *netdev; - - driver =3D qemu_opt_get(opts, "driver"); - netdev =3D qemu_opt_get(opts, "netdev"); - - if (!driver || !netdev) { - return 0; - } - - if (strcmp(netdev, name) =3D=3D 0 && - !g_str_has_prefix(driver, "virtio-net-")) { - error_setg(errp, "vhost-user requires frontend driver virtio-net-*= "); - return -1; - } - - return 0; -} - int net_init_vhost_user(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -433,12 +426,6 @@ int net_init_vhost_user(const Netdev *netdev, const ch= ar *name, return -1; } =20 - /* verify net frontend */ - if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net, - (char *)name, errp)) { - return -1; - } - queues =3D vhost_user_opts->has_queues ? vhost_user_opts->queues : 1; if (queues < 1 || queues > MAX_QUEUE_NUM) { error_setg(errp, --=20 2.31.1