From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600793195; cv=none; d=zohomail.com; s=zohoarc; b=jz7pXgja7HmISQayBLyZTrItuFOBwvhZLAkDaehneUYN5QDmDgE1E5+xn0FBdYFDkl6Qty8tISxL8yyIQIBd4xAwAGQLWlrfZS2gsxjGxxYGdBNZ67uHNOpwHEKTBmn8dAoiPkZH3cqH+JINnvsrM36cKON8v590r7sWKF3ttso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600793195; 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=AueNZhdLhYocaLCRBb3j6nP0goFi/pKPAVv9RYVyxmg=; b=OQU1zyMDClJLxagxcRIKdXH4Z8HyMq3mJxwnXTfJ9JjDwf0+zdn47N+HTFIoL3eIVKWuyTYSKZquNKJGPWm6MbGS1IHIMUy/ntJnbe2Ubx1sWTrkPeqzs4ORbYAIY68/bD2lysrlLKgfcySipiTuLOBORniVqcD2cVspVyFxW0M= 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+importer=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 1600793195141127.84407151975677; Tue, 22 Sep 2020 09:46:35 -0700 (PDT) Received: from localhost ([::1]:57210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKlR3-00035E-Cn for importer@patchew.org; Tue, 22 Sep 2020 12:46:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKkmN-0002wO-4H for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60406) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKkm8-0005NB-4N for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:26 -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-379-5ocR_u6eMKaA1JSTSzY_ew-1; Tue, 22 Sep 2020 12:04:11 -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 1FE1B1007466; Tue, 22 Sep 2020 16:04:10 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 009F960C04; Tue, 22 Sep 2020 16:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600790655; 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=AueNZhdLhYocaLCRBb3j6nP0goFi/pKPAVv9RYVyxmg=; b=cOLmjqA5l88RIcr0KxIJj6ktgEXfuhlt+PLw6a+nBfQWXtsjdSUCsAgrcvHoLrY/UmU0kE 0cdNXPcyO3co/RbMPzzE30A1VV5pzO1mRxfaIA7s2l1wxyQ8PAorqAXFjgASuP9iRLx6zb glY5wfcqYTSQJ9Ivo4R5MsUGzfNBatI= X-MC-Unique: 5ocR_u6eMKaA1JSTSzY_ew-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 01/11] block/export: shorten serial string to fit Date: Tue, 22 Sep 2020 17:03:51 +0100 Message-Id: <20200922160401.294055-2-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@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=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 00:31:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The serial field is only 20 bytes long. Shorten the string so it fits. This fixes the following compiler warning: ../block/export/vhost-user-blk-server.c:178:50: error: =E2=80=98%s=E2=80= =99 directive output truncated writing 21 bytes into a region of size 20 [-= Werror=3Dformat-truncation=3D] 178 | snprintf(elem->in_sg[0].iov_base, size, "%s", "vhost_user_b= lk_server"); | ^~ ~~~~~~~~~~~~~= ~~~~~~~~~~ Signed-off-by: Stefan Hajnoczi --- block/export/vhost-user-blk-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index ec78130f09..fb7764a730 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -175,7 +175,7 @@ static void coroutine_fn vu_block_virtio_process_req(vo= id *opaque) case VIRTIO_BLK_T_GET_ID: { size_t size =3D MIN(iov_size(&elem->in_sg[0], in_num), VIRTIO_BLK_ID_BYTES); - snprintf(elem->in_sg[0].iov_base, size, "%s", "vhost_user_blk_serv= er"); + snprintf(elem->in_sg[0].iov_base, size, "%s", "vhost_user_blk"); req->in->status =3D VIRTIO_BLK_S_OK; req->size =3D elem->in_sg[0].iov_len; break; --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600793342; cv=none; d=zohomail.com; s=zohoarc; b=TWqxnVuNmXIhkCYA6GpXVe6PqznPshZb/KsJsvqTKeBv4qaFGV0ArFSTC1PS6bjNHOKIIdc5w6weXZn8QzR59S0a1JAHKHa4gj/PZvp+ZVb+FbwvZNMoqLxL2Vy/hVWIRAqn5sVZgBycnCnfkLpGlLfR5xgJrEmZ7lanDGf0y2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600793342; 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=cySJN7dpuz/Va7hJwVhgUr/eA+8gkNc8rx9Q59fpqDE=; b=PPPhc+d9LPpdYUAa6xkfXQ+O552pJIDwMjFVkqxhhF1O8iJdckOnxYnrw0Fi8JbijJt6S6ONT/gRpxXgJ1bLZ/FrRRL5AtDjP8p8XsoLfX+eEgDkACm2lWivqzcnQ443cnmLQFC4LYLSNBaBBmDZ/i/YrZgXQLhyPZwtkvYRCVQ= 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+importer=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 1600793342385425.284391382452; Tue, 22 Sep 2020 09:49:02 -0700 (PDT) Received: from localhost ([::1]:60250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKlTQ-0004Zx-QY for importer@patchew.org; Tue, 22 Sep 2020 12:49:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKkmN-0002wR-8L for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKkmB-0005NU-31 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04: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-103-BUbP_qbwMAanNGDrCT1mAg-1; Tue, 22 Sep 2020 12:04:13 -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 D360A1868429; Tue, 22 Sep 2020 16:04:11 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A6B060CCC; Tue, 22 Sep 2020 16:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600790656; 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=cySJN7dpuz/Va7hJwVhgUr/eA+8gkNc8rx9Q59fpqDE=; b=amCMGiqcgKVksfZIZdt6o1cj42UtJjvNFY88WOxwgJk3PZN/qhwAKJrTiu/aqPvxEjO7g7 tnwwUWR+TN09mj2Ciu7Nd769PVpKl0T4SUybOCcJEG7bQCZr4Na4OiPVJ0Lk9Z+yJ0/hMn WG4nas4c29lTMxwNKpDrWYJXGEjYzzU= X-MC-Unique: BUbP_qbwMAanNGDrCT1mAg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 02/11] util/vhost-user-server: s/fileds/fields/ typo fix Date: Tue, 22 Sep 2020 17:03:52 +0100 Message-Id: <20200922160401.294055-3-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@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=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 00:31:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 7b50a2b1fd..2cd0cf8277 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -407,7 +407,7 @@ bool vhost_user_server_start(VuServer *server, return false; } =20 - /* zero out unspecified fileds */ + /* zero out unspecified fields */ *server =3D (VuServer) { .listener =3D listener, .vu_iface =3D vu_iface, --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600792308; cv=none; d=zohomail.com; s=zohoarc; b=gtXHOL3+qvTfMdQuIlUcabeTkQAnNYHn54nN0r9+SwN+GNIqppmvAOYNNHIsfw3rIKbL86eVNY4JhUkKUviA97ZDVWSVwvu+LFtCN1TNNOEiNNpJkcGcPJRhEDOfj95ssOvuZO2rUQTeQoTDzkIB2PDZWWj/k3lxbIzQFhfuFjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600792308; 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=/LX/tRWhvQdbHE+td9jJrkcTKAjU6Xk+V7/V7qmQ1XQ=; b=As9S1Qx43wJAmHxbfNPkhP4o//EqBVktKitwNONTMRSvF1OqrH1IOO6PTJTBk6ec9TUyZq65+OnBtPgJnz/fXVPhaWfIlf68mphhAzpBhet8h8Kr0aG9YgIymCW2Wcw1raRHYVHEL0phV5aC6k6dRjhKkWjR2w8dUo9s7z791JU= 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+importer=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 160079230842254.44538624816926; Tue, 22 Sep 2020 09:31:48 -0700 (PDT) Received: from localhost ([::1]:57108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKlCl-0006k2-4x for importer@patchew.org; Tue, 22 Sep 2020 12:31:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKkxC-0007gF-8A for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:15:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46625) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKkx8-0007qq-SQ for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:15:41 -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-44-1BfTWMYWO1mSvl_7zg4Unw-1; Tue, 22 Sep 2020 12:04:17 -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 4F382186841A; Tue, 22 Sep 2020 16:04:16 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1817478825; Tue, 22 Sep 2020 16:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600791337; 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=/LX/tRWhvQdbHE+td9jJrkcTKAjU6Xk+V7/V7qmQ1XQ=; b=IWiQpG9+Sf9ZqS6VpSrNvfkarONCrh9HcrPzVU9D9XQX9hT6Q9O3xqw79vasDWm//IgAZI YWZa5okNUT0wZ31Zhsq60UByxvu1vjHHN2AFyodjUqZljwaR/1JvI6DOjZAHHeF7A2PTcn S0rQGnj2FxkvEnvoP6/YmkCFhiDYsRw= X-MC-Unique: 1BfTWMYWO1mSvl_7zg4Unw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 03/11] util/vhost-user-server: drop unnecessary QOM cast Date: Tue, 22 Sep 2020 17:03:53 +0100 Message-Id: <20200922160401.294055-4-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We already have access to the value with the correct type (ioc and sioc are the same QIOChannel). Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 2cd0cf8277..ebe47885f5 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -337,7 +337,7 @@ static void vu_accept(QIONetListener *listener, QIOChan= nelSocket *sioc, server->ioc =3D QIO_CHANNEL(sioc); object_ref(OBJECT(server->ioc)); qio_channel_attach_aio_context(server->ioc, server->ctx); - qio_channel_set_blocking(QIO_CHANNEL(server->sioc), false, NULL); + qio_channel_set_blocking(server->ioc, false, NULL); vu_client_start(server); } =20 --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600791158; cv=none; d=zohomail.com; s=zohoarc; b=bA+W0ZOivpJbm8I1n6eug+Bdq2decCkZXox1ryQub4MWJmunl8H7vXHRb/7l8YTRJH95jkYfZ3kgQWeMBumOV4yLjVttWdpRMx4vsFuYTYvqGmIG8XUW/3DLpn1WAmwNxG4x/J8SsBARNXwbDPcEqxyHJEP9bsNHf1JT3CquZ0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600791158; 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=BmBrjvKqCUANWBkNsuYymq/QQChNylLEcnQneRjNiPg=; b=MKaCzFhfOLX9L2WwvjS0RA4RW9g50bWfUcQoF8eCB8wH4YS0kqyXpa6E3sAM73TpvAq73GGoZiyVT4soyfThRvlc19cf5X49FlBUucXzbozZTxZ+LKC4NiAuWoRTM1kNSMNBg+Zn0yIoiFh3dcO4zytGguWX81k304KEVNibZn0= 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+importer=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 160079115881492.37926175928123; Tue, 22 Sep 2020 09:12:38 -0700 (PDT) Received: from localhost ([::1]:37794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKkuD-000371-0L for importer@patchew.org; Tue, 22 Sep 2020 12:12:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKknb-000451-AS for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:05:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46117) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKknT-00063q-Dm for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:05:43 -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-346-IUF7ztqnNR6BGqgKZJ4Qeg-1; Tue, 22 Sep 2020 12:04:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E61EE8027E1; Tue, 22 Sep 2020 16:04:20 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F9F91A913; Tue, 22 Sep 2020 16:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600790738; 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=BmBrjvKqCUANWBkNsuYymq/QQChNylLEcnQneRjNiPg=; b=DFCfaOu0sxG7OM8aVIkCVj8QDRl0jJWoEmstsqGMfZ1z551fL6Nt8GLthPtnhN19EOmd+M TZHNYrKPgLlmlZDwHCl9t/Vr3YeVCVIzLl9K2dtHudE0zdr133jUbgNoE0Vgs3OiXNk6dS UgT4j8RlYZfv5EEJJGdqE3AwTtJG3Yo= X-MC-Unique: IUF7ztqnNR6BGqgKZJ4Qeg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 04/11] util/vhost-user-server: drop unnecessary watch deletion Date: Tue, 22 Sep 2020 17:03:54 +0100 Message-Id: <20200922160401.294055-5-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Explicitly deleting watches is not necessary since libvhost-user calls remove_watch() during vu_deinit(). Add an assertion to check this though. Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index ebe47885f5..ebb850731b 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -48,21 +48,6 @@ static void close_client(VuServer *server) /* When this is set vu_client_trip will stop new processing vhost-user= message */ server->sioc =3D NULL; =20 - VuFdWatch *vu_fd_watch, *next; - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { - aio_set_fd_handler(server->ioc->ctx, vu_fd_watch->fd, true, NULL, - NULL, NULL, NULL); - } - - while (!QTAILQ_EMPTY(&server->vu_fd_watches)) { - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, nex= t) { - if (!vu_fd_watch->processing) { - QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); - g_free(vu_fd_watch); - } - } - } - while (server->processing_msg) { if (server->ioc->read_coroutine) { server->ioc->read_coroutine =3D NULL; @@ -73,6 +58,10 @@ static void close_client(VuServer *server) } =20 vu_deinit(&server->vu_dev); + + /* vu_deinit() should have called remove_watch() */ + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); + object_unref(OBJECT(sioc)); object_unref(OBJECT(server->ioc)); } --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600791663; cv=none; d=zohomail.com; s=zohoarc; b=FWBaZIV1oLVAnOHPXM3g0UALCbqg+67VoQfKwdfPYzAV366MQzMdV/kPGEbFFemC4WT20Lkt9QO7R1TPjtp9pYpErUlg2i7LPbNQicG8TD7UJS5vaeIitvo7JWrN5g2EANLmfr5ki7EKhCtBs75mraMhRxBg4Zma4A1ZC4Emd+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600791663; 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=o/i7M8x0JtS+aV98vuz04DrGNw45KYP2zPxbS/98mBc=; b=B0a/mygZRE6GiqIRaZCipgN56iEDPmZBiyX3xB8mQw0TNHo0tu7+D7jI5/1sjvb4G2GzdBLPSBLwLDdBPhDvz/+8OdHy7nbZB0bRHdONOhOKWR/MgxjjBc+5yXN0enlzxf5oGrVf07DWdddoLq13OXx4k872M6/nQfn62EKjs60= 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+importer=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 1600791663531844.1381145883588; Tue, 22 Sep 2020 09:21:03 -0700 (PDT) Received: from localhost ([::1]:58754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKl2M-0003nR-R2 for importer@patchew.org; Tue, 22 Sep 2020 12:21:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKknd-00045t-Ds for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:05:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20743) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKknV-000648-B1 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:05:49 -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-524-aC55cG3XPj65VVCRZfL4LA-1; Tue, 22 Sep 2020 12:04:23 -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 73ECD57088; Tue, 22 Sep 2020 16:04:22 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A3BE78825; Tue, 22 Sep 2020 16:04:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600790740; 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=o/i7M8x0JtS+aV98vuz04DrGNw45KYP2zPxbS/98mBc=; b=S4uCrQgquvrOQty4kuYKZ5M+er7HIdB1lrgQE3jZewvFj2+MG+3HZrnd/SjYYpViGZvWPP mFyYAiaVstlo7FXEfovdal0UJSW6AZ6oHoJpiTkjJFJ6zneIEGGORLJm0KYuHIIS+cgmLG +aw52oliplJDIiG7RdvvJbqxXIkOWds= X-MC-Unique: aC55cG3XPj65VVCRZfL4LA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 05/11] block/export: consolidate request structs into VuBlockReq Date: Tue, 22 Sep 2020 17:03:55 +0100 Message-Id: <20200922160401.294055-6-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 00:31:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Only one struct is needed per request. Drop req_data and the separate VuBlockReq instance. Instead let vu_queue_pop() allocate everything at once. This fixes the req_data memory leak in vu_block_virtio_process_req(). Signed-off-by: Stefan Hajnoczi --- block/export/vhost-user-blk-server.c | 68 +++++++++------------------- 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index fb7764a730..ef07a87eb1 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -25,7 +25,7 @@ struct virtio_blk_inhdr { }; =20 typedef struct VuBlockReq { - VuVirtqElement *elem; + VuVirtqElement elem; int64_t sector_num; size_t size; struct virtio_blk_inhdr *in; @@ -39,14 +39,10 @@ static void vu_block_req_complete(VuBlockReq *req) VuDev *vu_dev =3D &req->server->vu_dev; =20 /* IO size with 1 extra status byte */ - vu_queue_push(vu_dev, req->vq, req->elem, req->size + 1); + vu_queue_push(vu_dev, req->vq, &req->elem, req->size + 1); vu_queue_notify(vu_dev, req->vq); =20 - if (req->elem) { - free(req->elem); - } - - g_free(req); + free(req); } =20 static VuBlockDev *get_vu_block_device_by_server(VuServer *server) @@ -89,20 +85,12 @@ static void coroutine_fn vu_block_flush(VuBlockReq *req) blk_co_flush(backend); } =20 -struct req_data { - VuServer *server; - VuVirtq *vq; - VuVirtqElement *elem; -}; - static void coroutine_fn vu_block_virtio_process_req(void *opaque) { - struct req_data *data =3D opaque; - VuServer *server =3D data->server; - VuVirtq *vq =3D data->vq; - VuVirtqElement *elem =3D data->elem; + VuBlockReq *req =3D opaque; + VuServer *server =3D req->server; + VuVirtqElement *elem =3D &req->elem; uint32_t type; - VuBlockReq *req; =20 VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); BlockBackend *backend =3D vdev_blk->backend; @@ -111,18 +99,13 @@ static void coroutine_fn vu_block_virtio_process_req(v= oid *opaque) struct iovec *out_iov =3D elem->out_sg; unsigned in_num =3D elem->in_num; unsigned out_num =3D elem->out_num; + /* refer to hw/block/virtio_blk.c */ if (elem->out_num < 1 || elem->in_num < 1) { error_report("virtio-blk request missing headers"); - free(elem); - return; + goto err; } =20 - req =3D g_new0(VuBlockReq, 1); - req->server =3D server; - req->vq =3D vq; - req->elem =3D elem; - if (unlikely(iov_to_buf(out_iov, out_num, 0, &req->out, sizeof(req->out)) !=3D sizeof(req->out))) { error_report("virtio-blk request outhdr too short"); @@ -202,36 +185,27 @@ static void coroutine_fn vu_block_virtio_process_req(= void *opaque) =20 err: free(elem); - g_free(req); - return; } =20 static void vu_block_process_vq(VuDev *vu_dev, int idx) { - VuServer *server; - VuVirtq *vq; - struct req_data *req_data; + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + VuVirtq *vq =3D vu_get_queue(vu_dev, idx); =20 - server =3D container_of(vu_dev, VuServer, vu_dev); - assert(server); - - vq =3D vu_get_queue(vu_dev, idx); - assert(vq); - VuVirtqElement *elem; while (1) { - elem =3D vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + - sizeof(VuBlockReq)); - if (elem) { - req_data =3D g_new0(struct req_data, 1); - req_data->server =3D server; - req_data->vq =3D vq; - req_data->elem =3D elem; - Coroutine *co =3D qemu_coroutine_create(vu_block_virtio_proces= s_req, - req_data); - aio_co_enter(server->ioc->ctx, co); - } else { + VuBlockReq *req; + + req =3D vu_queue_pop(vu_dev, vq, sizeof(VuBlockReq)); + if (!req) { break; } + + req->server =3D server; + req->vq =3D vq; + + Coroutine *co =3D + qemu_coroutine_create(vu_block_virtio_process_req, req); + qemu_coroutine_enter(co); } } =20 --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600791835; cv=none; d=zohomail.com; s=zohoarc; b=UeGJJCevGXCDBRMOwejUb7UFTZXFCC4tZbYxE6D5gPgKYj5GX+GjzaPuCuAFP4tPinRWsifuQLz/uu3atyudOJIeb/DOIkv/1BMI6IuLZP3VT/RrE5v5MiEdQLxWAwBDkbGGFckeL4kzkmK5v61Tt7HDUa8vfNF/ZCTjU243RBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600791835; 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=X6PHIjyFCnSD5O0lRubUaswcGxHfrErHXK9pUYe9z2k=; b=AlUI4BPSpDO6MKrS3iq3TcoF26BRFq3qYTfSry1DSDoKGRaTlKJFHuaNoPkukcceXoyPJYlsVwFdSrOr2164r+94tSlw3RCLy3Qm6I0SvqnBwgksKykOIIPCk5Wv9oTd+YnXNS7vzJdV30tc5Ondb2F3XSL3hUnsBHQh8yedbNI= 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+importer=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 1600791835213970.3859458729058; Tue, 22 Sep 2020 09:23:55 -0700 (PDT) Received: from localhost ([::1]:37844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKl58-00070J-AN for importer@patchew.org; Tue, 22 Sep 2020 12:23:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKknt-0004X2-Tb for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:06:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51530) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKknq-0006CK-UH for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:06:05 -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-569-h3P6-6OiPiCRX5oQMfNn9g-1; Tue, 22 Sep 2020 12:04:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9D54186841A; Tue, 22 Sep 2020 16:04:26 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA1D3614F5; Tue, 22 Sep 2020 16:04:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600790762; 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=X6PHIjyFCnSD5O0lRubUaswcGxHfrErHXK9pUYe9z2k=; b=Cn+tOHIr2o0L+bBHDFuJz/ond5+7AGRnDYlrnR23FUFj1zuRey5Cz6dUF/8qJMuU2G7Nzs kTPRjzRPLKVacoAJ9IihrYMdwhht83nrndq9iBQX5GNeZlkvOLTx7UsHGcqPlUzXMYGpXa Ju6cAzq48fHS1Yfhot92/GVdyJRr6hk= X-MC-Unique: h3P6-6OiPiCRX5oQMfNn9g-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 06/11] util/vhost-user-server: drop unused DevicePanicNotifier Date: Tue, 22 Sep 2020 17:03:56 +0100 Message-Id: <20200922160401.294055-7-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The device panic notifier callback is not used. Drop it. Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.h | 3 --- block/export/vhost-user-blk-server.c | 3 +-- util/vhost-user-server.c | 6 ------ 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h index 5232f96718..92177fc911 100644 --- a/util/vhost-user-server.h +++ b/util/vhost-user-server.h @@ -29,12 +29,10 @@ typedef struct VuFdWatch { } VuFdWatch; =20 typedef struct VuServer VuServer; -typedef void DevicePanicNotifierFn(VuServer *server); =20 struct VuServer { QIONetListener *listener; AioContext *ctx; - DevicePanicNotifierFn *device_panic_notifier; int max_queues; const VuDevIface *vu_iface; VuDev vu_dev; @@ -54,7 +52,6 @@ bool vhost_user_server_start(VuServer *server, SocketAddress *unix_socket, AioContext *ctx, uint16_t max_queues, - DevicePanicNotifierFn *device_panic_notifier, const VuDevIface *vu_iface, Error **errp); =20 diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index ef07a87eb1..f2bfddbf26 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -439,8 +439,7 @@ static void vhost_user_blk_server_start(VuBlockDev *vu_= block_device, ctx =3D bdrv_get_aio_context(blk_bs(vu_block_device->backend)); =20 if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, - VHOST_USER_BLK_MAX_QUEUES, - NULL, &vu_block_iface, + VHOST_USER_BLK_MAX_QUEUES, &vu_block_ifac= e, errp)) { goto error; } diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index ebb850731b..892815827d 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -81,10 +81,6 @@ static void panic_cb(VuDev *vu_dev, const char *buf) close_client(server); } =20 - if (server->device_panic_notifier) { - server->device_panic_notifier(server); - } - /* * Set the callback function for network listener so another * vhost-user client can connect to this server @@ -385,7 +381,6 @@ bool vhost_user_server_start(VuServer *server, SocketAddress *socket_addr, AioContext *ctx, uint16_t max_queues, - DevicePanicNotifierFn *device_panic_notifier, const VuDevIface *vu_iface, Error **errp) { @@ -402,7 +397,6 @@ bool vhost_user_server_start(VuServer *server, .vu_iface =3D vu_iface, .max_queues =3D max_queues, .ctx =3D ctx, - .device_panic_notifier =3D device_panic_notifier, }; =20 qio_net_listener_set_name(server->listener, "vhost-user-backend-listen= er"); --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600791835; cv=none; d=zohomail.com; s=zohoarc; b=jdjzvPdP6dAqobYd+7SG+IrjVferhBYV0eZnBwtJHMGEJABHyKvA0zPLkdAyhzz8ps/Y/V+Z1HWR91B8/IKe9vQxpthht5dQ6ZqD+ktwPmM2ByPZyyHNY+x1bIVup0O0qyXtHOyLsIwrpEOzGSC1DLv3/4ktygv7OTsU6/5ujUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600791835; 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=s7V1hlg580q8ybpxd/zxqIbK2WCB7lCN7vK6A1tffNk=; b=MLsTCOIzxumMRfaG1BhYxiNygHx7ldhUUMy2hO0mHSqQTiwkg5n8zAGtzShGe4czVAeHL7LpnPmKK125bvd1nkiHy/P9JrNPXWE8y3l3/lnHkTfjO4c0OUCIyMKC6h1ouNUT5b6v/itxofSEBb66NyUiFp3OY8McAcahfN/00BI= 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+importer=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 1600791835232254.49197488997982; Tue, 22 Sep 2020 09:23:55 -0700 (PDT) Received: from localhost ([::1]:37842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKl58-00070G-8t for importer@patchew.org; Tue, 22 Sep 2020 12:23:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKkxb-0008BC-OL for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:16:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKkxa-0007ul-6P for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:16:07 -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-340-Nv3MYijXO3CBzOgzsBvFIA-1; Tue, 22 Sep 2020 12:04:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A4DF57086; Tue, 22 Sep 2020 16:04:28 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CE9F73689; Tue, 22 Sep 2020 16:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600791362; 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=s7V1hlg580q8ybpxd/zxqIbK2WCB7lCN7vK6A1tffNk=; b=h/gfX5mB8qkVtAMXuEFXnUnpX21zOnD4b64RHWLqmThoEPfV3cbklYrwz1Ot3K2csQniUT Qhznlubm7QkUMC1/K1fQY05leVQLdP26tmUNvYds74kSaDVea/rRDQbORuFgCxFuksLwwp o3Qts9MwH5WUR+e9YY0Xao6yIh/Gq00= X-MC-Unique: Nv3MYijXO3CBzOgzsBvFIA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 07/11] util/vhost-user-server: fix memory leak in vu_message_read() Date: Tue, 22 Sep 2020 17:03:57 +0100 Message-Id: <20200922160401.294055-8-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 00:31:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" fds[] is leaked when qio_channel_readv_full() fails. Use vmsg->fds[] instead of keeping a local fds[] array. Then we can reuse goto fail to clean up fds. vmsg->fd_num must be zeroed before the loop to make this safe. Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 50 ++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 892815827d..5a60e2ca2a 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -100,21 +100,11 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUser= Msg *vmsg) }; int rc, read_bytes =3D 0; Error *local_err =3D NULL; - /* - * Store fds/nfds returned from qio_channel_readv_full into - * temporary variables. - * - * VhostUserMsg is a packed structure, gcc will complain about passing - * pointer to a packed structure member if we pass &VhostUserMsg.fd_num - * and &VhostUserMsg.fds directly when calling qio_channel_readv_full, - * thus two temporary variables nfds and fds are used here. - */ - size_t nfds =3D 0, nfds_t =3D 0; const size_t max_fds =3D G_N_ELEMENTS(vmsg->fds); - int *fds_t =3D NULL; VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); QIOChannel *ioc =3D server->ioc; =20 + vmsg->fd_num =3D 0; if (!ioc) { error_report_err(local_err); goto fail; @@ -122,41 +112,47 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUser= Msg *vmsg) =20 assert(qemu_in_coroutine()); do { + size_t nfds =3D 0; + int *fds =3D NULL; + /* * qio_channel_readv_full may have short reads, keeping calling it * until getting VHOST_USER_HDR_SIZE or 0 bytes in total */ - rc =3D qio_channel_readv_full(ioc, &iov, 1, &fds_t, &nfds_t, &loca= l_err); + rc =3D qio_channel_readv_full(ioc, &iov, 1, &fds, &nfds, &local_er= r); if (rc < 0) { if (rc =3D=3D QIO_CHANNEL_ERR_BLOCK) { + assert(local_err =3D=3D NULL); qio_channel_yield(ioc, G_IO_IN); continue; } else { error_report_err(local_err); - return false; + goto fail; } } - read_bytes +=3D rc; - if (nfds_t > 0) { - if (nfds + nfds_t > max_fds) { + + if (nfds > 0) { + if (vmsg->fd_num + nfds > max_fds) { error_report("A maximum of %zu fds are allowed, " "however got %lu fds now", - max_fds, nfds + nfds_t); + max_fds, vmsg->fd_num + nfds); + g_free(fds); goto fail; } - memcpy(vmsg->fds + nfds, fds_t, - nfds_t *sizeof(vmsg->fds[0])); - nfds +=3D nfds_t; - g_free(fds_t); + memcpy(vmsg->fds + vmsg->fd_num, fds, nfds * sizeof(vmsg->fds[= 0])); + vmsg->fd_num +=3D nfds; + g_free(fds); } - if (read_bytes =3D=3D VHOST_USER_HDR_SIZE || rc =3D=3D 0) { - break; + + if (rc =3D=3D 0) { /* socket closed */ + goto fail; } - iov.iov_base =3D (char *)vmsg + read_bytes; - iov.iov_len =3D VHOST_USER_HDR_SIZE - read_bytes; - } while (true); =20 - vmsg->fd_num =3D nfds; + iov.iov_base +=3D rc; + iov.iov_len -=3D rc; + read_bytes +=3D rc; + } while (read_bytes !=3D VHOST_USER_HDR_SIZE); + /* qio_channel_readv_full will make socket fds blocking, unblock them = */ vmsg_unblock_fds(vmsg); if (vmsg->size > sizeof(vmsg->payload)) { --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600793489; cv=none; d=zohomail.com; s=zohoarc; b=d9DD9mWVso1By9bBtrUnOQBEmFoFXyNDbnqcvAjuFRWc/aC0bolMMjbxyTWgLhLTKfFOEO33Eoi+iIazdM1i7n9IlzaHQLTLXzVEvayM5wHF45hterCOllSYEhtvD3TrhYYu5cXtJSO3wrCzkOzBDWqfIDiMsaPkSC/VGZKSHW4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600793489; 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=fppLXmQv9qPvl0QxtXe3MG+Wd3tEhVkjsRPWoeaRRSE=; b=ceh3RzW9PdrTgpphtB25QjKYm7qdnyUqkieIAG3B4OCGCQN1DKdrdWfFW5ApKiPJ3GVnTDej+8WXxzqbywUjI6ZfOrwiPHXq0/U49aHM3bUR57+n3pDHrSsfDkvoou6Zevhm+HfPDf6scM0IHz3rmxEUpNKRU6XMWC0VdbbQ0uo= 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+importer=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 1600793489889773.1405466215837; Tue, 22 Sep 2020 09:51:29 -0700 (PDT) Received: from localhost ([::1]:36144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKlVo-0006QN-Bi for importer@patchew.org; Tue, 22 Sep 2020 12:51:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKkmW-00038h-T0 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26332) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKkmS-0005a6-SG for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:40 -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-150-RgFkAa1VNXOMTJcqTkDgFQ-1; Tue, 22 Sep 2020 12:04:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09E191007464; Tue, 22 Sep 2020 16:04:33 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id B02D25C1A3; Tue, 22 Sep 2020 16:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600790676; 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=fppLXmQv9qPvl0QxtXe3MG+Wd3tEhVkjsRPWoeaRRSE=; b=BqtxCO9uD8O14kbmfycsjm+/hEFgnjyuBWGU7ODxPsbjo+EAG+FEn/SEjC9LuZasAmQG5F he6yc7hjZg0OtdM49Z+v5pvMTts0COR4tzi0izAIlsbuWtenJlrg1tsLJa1VfLq2kSwFpb hDKM/HZDslF0G/Za8GedWZcfZ2PoTIE= X-MC-Unique: RgFkAa1VNXOMTJcqTkDgFQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 08/11] util/vhost-user-server: check EOF when reading payload Date: Tue, 22 Sep 2020 17:03:58 +0100 Message-Id: <20200922160401.294055-9-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Unexpected EOF is an error that must be reported. Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 5a60e2ca2a..ec555abcb2 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -169,8 +169,10 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserM= sg *vmsg) }; if (vmsg->size) { rc =3D qio_channel_readv_all_eof(ioc, &iov_payload, 1, &local_err); - if (rc =3D=3D -1) { - error_report_err(local_err); + if (rc !=3D 1) { + if (local_err) { + error_report_err(local_err); + } goto fail; } } --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600790971; cv=none; d=zohomail.com; s=zohoarc; b=GXh4YTMTRyaSPgDIegMyJpQL6Pahh+f2psaqXtvTqDovCG6K9ZpyHiOVv5fKy0rn1rY79mRaQMFJlb1kpaPf7KZ4C6Hr/sHj2WYOLkUniBaJhTaNY0U9M2lQMeUWUv3eMp6TsMh21Bm6yHiAD5rDB0Y6H8dvQ/r/yKFo+B+GepY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600790971; 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=A4Pdyu/nzfDZOJq6MEf/FsawlBQezQlxsaBdgCLFLV0=; b=CREa4GME2HGJ1Nv0JGgHaebcdTE0wjHXCYyqczhkRdyQ7eOu52yKatDbqwEvz+FS20g8iopmfQsKGX0+qle/RZfErWiZu7o8f2bPRuzgc4f0eqw2PiSkp2x5N1TOv/0+LzZ7rAag7HHxQ7x14/GxAB9w88HmtA09Qp6RxUHwQjg= 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+importer=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 1600790971627957.8614806263313; Tue, 22 Sep 2020 09:09:31 -0700 (PDT) Received: from localhost ([::1]:58706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKkrB-0008EG-DS for importer@patchew.org; Tue, 22 Sep 2020 12:09:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKkmZ-0003Fs-Qr for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37438) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKkmW-0005ef-Cp for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:43 -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-320-A4qGfIS5OQyxepfL130WGg-1; Tue, 22 Sep 2020 12:04:35 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D883380046A; Tue, 22 Sep 2020 16:04:34 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 522E95C1A3; Tue, 22 Sep 2020 16:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600790678; 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=A4Pdyu/nzfDZOJq6MEf/FsawlBQezQlxsaBdgCLFLV0=; b=SYfUkXh5MOl+KWtjY3ha/gKhnAlV0AFGU+/BPYpZfsH9GlS/TihCT7BBby3jRLo2ncF/Xp BfhLyFPn3WdjfOnVxp2uBJQnq9nSXfagQ9+ZXkCj1RjQSx5Vvbp0OlhmQkt0mUo1aVNcen 5Gbe7OB+NUGs/LTWrwaROeRO2NPQrzw= X-MC-Unique: A4qGfIS5OQyxepfL130WGg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 09/11] util/vhost-user-server: rework vu_client_trip() coroutine lifecycle Date: Tue, 22 Sep 2020 17:03:59 +0100 Message-Id: <20200922160401.294055-10-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The vu_client_trip() coroutine is leaked during AioContext switching. It is also unsafe to destroy the vu_dev in panic_cb() since its callers still access it in some cases. Rework the lifecycle to solve these safety issues. Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.h | 29 ++-- block/export/vhost-user-blk-server.c | 9 +- util/vhost-user-server.c | 245 +++++++++++++++------------ 3 files changed, 155 insertions(+), 128 deletions(-) diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h index 92177fc911..0da4c2cc4c 100644 --- a/util/vhost-user-server.h +++ b/util/vhost-user-server.h @@ -19,34 +19,36 @@ #include "qapi/error.h" #include "standard-headers/linux/virtio_blk.h" =20 +/* A kick fd that we monitor on behalf of libvhost-user */ typedef struct VuFdWatch { VuDev *vu_dev; int fd; /*kick fd*/ void *pvt; vu_watch_cb cb; - bool processing; QTAILQ_ENTRY(VuFdWatch) next; } VuFdWatch; =20 -typedef struct VuServer VuServer; - -struct VuServer { +/** + * VuServer: + * A vhost-user server instance with user-defined VuDevIface callbacks. + * Vhost-user device backends can be implemented using VuServer. VuDevIface + * callbacks and virtqueue kicks run in the given AioContext. + */ +typedef struct { QIONetListener *listener; + QEMUBH *restart_listener_bh; AioContext *ctx; int max_queues; const VuDevIface *vu_iface; + + /* Protected by ctx lock */ VuDev vu_dev; QIOChannel *ioc; /* The I/O channel with the client */ QIOChannelSocket *sioc; /* The underlying data channel with the client= */ - /* IOChannel for fd provided via VHOST_USER_SET_SLAVE_REQ_FD */ - QIOChannel *ioc_slave; - QIOChannelSocket *sioc_slave; - Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ QTAILQ_HEAD(, VuFdWatch) vu_fd_watches; - /* restart coroutine co_trip if AIOContext is changed */ - bool aio_context_changed; - bool processing_msg; -}; + + Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ +} VuServer; =20 bool vhost_user_server_start(VuServer *server, SocketAddress *unix_socket, @@ -57,6 +59,7 @@ bool vhost_user_server_start(VuServer *server, =20 void vhost_user_server_stop(VuServer *server); =20 -void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx); +void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ct= x); +void vhost_user_server_detach_aio_context(VuServer *server); =20 #endif /* VHOST_USER_SERVER_H */ diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index f2bfddbf26..b609a3e4d6 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -313,18 +313,13 @@ static const VuDevIface vu_block_iface =3D { static void blk_aio_attached(AioContext *ctx, void *opaque) { VuBlockDev *vub_dev =3D opaque; - aio_context_acquire(ctx); - vhost_user_server_set_aio_context(&vub_dev->vu_server, ctx); - aio_context_release(ctx); + vhost_user_server_attach_aio_context(&vub_dev->vu_server, ctx); } =20 static void blk_aio_detach(void *opaque) { VuBlockDev *vub_dev =3D opaque; - AioContext *ctx =3D vub_dev->vu_server.ctx; - aio_context_acquire(ctx); - vhost_user_server_set_aio_context(&vub_dev->vu_server, NULL); - aio_context_release(ctx); + vhost_user_server_detach_aio_context(&vub_dev->vu_server); } =20 static void diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index ec555abcb2..d8b8c08b5f 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -9,8 +9,50 @@ */ #include "qemu/osdep.h" #include "qemu/main-loop.h" +#include "block/aio-wait.h" #include "vhost-user-server.h" =20 +/* + * Theory of operation: + * + * VuServer is started and stopped by vhost_user_server_start() and + * vhost_user_server_stop() from the main loop thread. Starting the server + * opens a vhost-user UNIX domain socket and listens for incoming connecti= ons. + * Only one connection is allowed at a time. + * + * The connection is handled by the vu_client_trip() coroutine in the + * VuServer->ctx AioContext. The coroutine consists of a vu_dispatch() loop + * where libvhost-user calls vu_message_read() to receive the next vhost-u= ser + * protocol messages over the UNIX domain socket. + * + * When virtqueues are set up libvhost-user calls set_watch() to monitor k= ick + * fds. These fds are also handled in the VuServer->ctx AioContext. + * + * Both vu_client_trip() and kick fd monitoring can be stopped by shutting= down + * the socket connection. Shutting down the socket connection causes + * vu_message_read() to fail since no more data can be received from the s= ocket. + * After vu_dispatch() fails, vu_client_trip() calls vu_deinit() to stop + * libvhost-user before terminating the coroutine. vu_deinit() calls + * remove_watch() to stop monitoring kick fds and this stops virtqueue + * processing. + * + * When vu_client_trip() has finished cleaning up it schedules a BH in the= main + * loop thread to accept the next client connection. + * + * When libvhost-user detects an error it calls panic_cb() and sets the + * dev->broken flag. Both vu_client_trip() and kick fd processing stop when + * the dev->broken flag is set. + * + * It is possible to switch AioContexts using + * vhost_user_server_detach_aio_context() and + * vhost_user_server_attach_aio_context(). They stop monitoring fds in the= old + * AioContext and resume monitoring in the new AioContext. The vu_client_t= rip() + * coroutine remains in a yielded state during the switch. This is made + * possible by QIOChannel's support for spurious coroutine re-entry in + * qio_channel_yield(). The coroutine will restart I/O when re-entered fro= m the + * new AioContext. + */ + static void vmsg_close_fds(VhostUserMsg *vmsg) { int i; @@ -27,68 +69,9 @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) } } =20 -static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, - gpointer opaque); - -static void close_client(VuServer *server) -{ - /* - * Before closing the client - * - * 1. Let vu_client_trip stop processing new vhost-user msg - * - * 2. remove kick_handler - * - * 3. wait for the kick handler to be finished - * - * 4. wait for the current vhost-user msg to be finished processing - */ - - QIOChannelSocket *sioc =3D server->sioc; - /* When this is set vu_client_trip will stop new processing vhost-user= message */ - server->sioc =3D NULL; - - while (server->processing_msg) { - if (server->ioc->read_coroutine) { - server->ioc->read_coroutine =3D NULL; - qio_channel_set_aio_fd_handler(server->ioc, server->ioc->ctx, = NULL, - NULL, server->ioc); - server->processing_msg =3D false; - } - } - - vu_deinit(&server->vu_dev); - - /* vu_deinit() should have called remove_watch() */ - assert(QTAILQ_EMPTY(&server->vu_fd_watches)); - - object_unref(OBJECT(sioc)); - object_unref(OBJECT(server->ioc)); -} - static void panic_cb(VuDev *vu_dev, const char *buf) { - VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); - - /* avoid while loop in close_client */ - server->processing_msg =3D false; - - if (buf) { - error_report("vu_panic: %s", buf); - } - - if (server->sioc) { - close_client(server); - } - - /* - * Set the callback function for network listener so another - * vhost-user client can connect to this server - */ - qio_net_listener_set_client_func(server->listener, - vu_accept, - server, - NULL); + error_report("vu_panic: %s", buf); } =20 static bool coroutine_fn @@ -185,28 +168,31 @@ fail: return false; } =20 - -static void vu_client_start(VuServer *server); static coroutine_fn void vu_client_trip(void *opaque) { VuServer *server =3D opaque; + VuDev *vu_dev =3D &server->vu_dev; =20 - while (!server->aio_context_changed && server->sioc) { - server->processing_msg =3D true; - vu_dispatch(&server->vu_dev); - server->processing_msg =3D false; + while (!vu_dev->broken && vu_dispatch(vu_dev)) { + /* Keep running */ } =20 - if (server->aio_context_changed && server->sioc) { - server->aio_context_changed =3D false; - vu_client_start(server); - } -} + vu_deinit(vu_dev); + + /* vu_deinit() should have called remove_watch() */ + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); + + object_unref(OBJECT(server->sioc)); + server->sioc =3D NULL; =20 -static void vu_client_start(VuServer *server) -{ - server->co_trip =3D qemu_coroutine_create(vu_client_trip, server); - aio_co_enter(server->ctx, server->co_trip); + object_unref(OBJECT(server->ioc)); + server->ioc =3D NULL; + + server->co_trip =3D NULL; + if (server->restart_listener_bh) { + qemu_bh_schedule(server->restart_listener_bh); + } + aio_wait_kick(); } =20 /* @@ -219,12 +205,18 @@ static void vu_client_start(VuServer *server) static void kick_handler(void *opaque) { VuFdWatch *vu_fd_watch =3D opaque; - vu_fd_watch->processing =3D true; - vu_fd_watch->cb(vu_fd_watch->vu_dev, 0, vu_fd_watch->pvt); - vu_fd_watch->processing =3D false; + VuDev *vu_dev =3D vu_fd_watch->vu_dev; + + vu_fd_watch->cb(vu_dev, 0, vu_fd_watch->pvt); + + /* Stop vu_client_trip() if an error occurred in vu_fd_watch->cb() */ + if (vu_dev->broken) { + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + } } =20 - static VuFdWatch *find_vu_fd_watch(VuServer *server, int fd) { =20 @@ -319,62 +311,95 @@ static void vu_accept(QIONetListener *listener, QIOCh= annelSocket *sioc, qio_channel_set_name(QIO_CHANNEL(sioc), "vhost-user client"); server->ioc =3D QIO_CHANNEL(sioc); object_ref(OBJECT(server->ioc)); - qio_channel_attach_aio_context(server->ioc, server->ctx); + + /* TODO vu_message_write() spins if non-blocking! */ qio_channel_set_blocking(server->ioc, false, NULL); - vu_client_start(server); + + server->co_trip =3D qemu_coroutine_create(vu_client_trip, server); + + aio_context_acquire(server->ctx); + vhost_user_server_attach_aio_context(server, server->ctx); + aio_context_release(server->ctx); } =20 - void vhost_user_server_stop(VuServer *server) { + aio_context_acquire(server->ctx); + + qemu_bh_delete(server->restart_listener_bh); + server->restart_listener_bh =3D NULL; + if (server->sioc) { - close_client(server); + VuFdWatch *vu_fd_watch; + + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, + NULL, NULL, NULL, vu_fd_watch); + } + + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + + AIO_WAIT_WHILE(server->ctx, server->co_trip); } =20 + aio_context_release(server->ctx); + if (server->listener) { qio_net_listener_disconnect(server->listener); object_unref(OBJECT(server->listener)); } +} + +/* + * Allow the next client to connect to the server. Called from a BH in the= main + * loop. + */ +static void restart_listener_bh(void *opaque) +{ + VuServer *server =3D opaque; =20 + qio_net_listener_set_client_func(server->listener, vu_accept, server, + NULL); } =20 -void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx) +/* Called with ctx acquired */ +void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ct= x) { - VuFdWatch *vu_fd_watch, *next; - void *opaque =3D NULL; - IOHandler *io_read =3D NULL; - bool attach; + VuFdWatch *vu_fd_watch; =20 - server->ctx =3D ctx ? ctx : qemu_get_aio_context(); + server->ctx =3D ctx; =20 if (!server->sioc) { - /* not yet serving any client*/ return; } =20 - if (ctx) { - qio_channel_attach_aio_context(server->ioc, ctx); - server->aio_context_changed =3D true; - io_read =3D kick_handler; - attach =3D true; - } else { + qio_channel_attach_aio_context(server->ioc, ctx); + + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { + aio_set_fd_handler(ctx, vu_fd_watch->fd, true, kick_handler, NULL, + NULL, vu_fd_watch); + } + + aio_co_schedule(ctx, server->co_trip); +} + +/* Called with server->ctx acquired */ +void vhost_user_server_detach_aio_context(VuServer *server) +{ + if (server->sioc) { + VuFdWatch *vu_fd_watch; + + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, + NULL, NULL, NULL, vu_fd_watch); + } + qio_channel_detach_aio_context(server->ioc); - /* server->ioc->ctx keeps the old AioConext */ - ctx =3D server->ioc->ctx; - attach =3D false; } =20 - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { - if (vu_fd_watch->cb) { - opaque =3D attach ? vu_fd_watch : NULL; - aio_set_fd_handler(ctx, vu_fd_watch->fd, true, - io_read, NULL, NULL, - opaque); - } - } + server->ctx =3D NULL; } =20 - bool vhost_user_server_start(VuServer *server, SocketAddress *socket_addr, AioContext *ctx, @@ -382,6 +407,7 @@ bool vhost_user_server_start(VuServer *server, const VuDevIface *vu_iface, Error **errp) { + QEMUBH *bh; QIONetListener *listener =3D qio_net_listener_new(); if (qio_net_listener_open_sync(listener, socket_addr, 1, errp) < 0) { @@ -389,9 +415,12 @@ bool vhost_user_server_start(VuServer *server, return false; } =20 + bh =3D qemu_bh_new(restart_listener_bh, server); + /* zero out unspecified fields */ *server =3D (VuServer) { .listener =3D listener, + .restart_listener_bh =3D bh, .vu_iface =3D vu_iface, .max_queues =3D max_queues, .ctx =3D ctx, --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600791424; cv=none; d=zohomail.com; s=zohoarc; b=bjFmi/JIfDXNvj17g8LQnd7IHVAyPYT19D4aHLth9JwDL5eyv1ISjXpagBCllavH1JW4pF4sK+hBJLkRDZvdhoZugraKh2pTDAIG4/sY2F32YILAs+Oe1NS6ZYxIwPDRYonwArc3ysgHe26mBOgI/3ang7KJYs8hKEliYwApZic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600791424; 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=2Zau7i4WwA2sOzgmtuSsO1DFTPk1a1haFmHDmb8VWHk=; b=ikhp8JK2pHJ4rY9kECJ/rFRGZ3eTEN2vcLFhG2oDpCuGlWUp3B0O4PpmuiNSFAqO6sJuRuu7ilCTL1JcQPbiNIX1KmyMQBIj96r6nNaK6MB63Vn3e8nZ0zyOCTewMrwaRdurF1EW86Qzk0KasE09CjXstj6AnhgnOPAe6CnZII0= 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+importer=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 1600791424615652.3543096289555; Tue, 22 Sep 2020 09:17:04 -0700 (PDT) Received: from localhost ([::1]:49680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKkyV-0008MF-GI for importer@patchew.org; Tue, 22 Sep 2020 12:17:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKkmc-0003LG-9o for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30158) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKkmZ-0005fT-IA for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:45 -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-87-OFDwj5wNMqCvdcy7zrDZ9w-1; Tue, 22 Sep 2020 12:04:40 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 410708015FA; Tue, 22 Sep 2020 16:04:39 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2C671B42F; Tue, 22 Sep 2020 16:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600790682; 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=2Zau7i4WwA2sOzgmtuSsO1DFTPk1a1haFmHDmb8VWHk=; b=cMyBmBE88L3yXshtSXhfbuYDxtBQ2MBoqhR2opuuJ3Y2yRuZPosNyhWlRcBqpNQQuI6/wf rBdSGu0M45aYHrmSduhWfCtxBtyrF/z3slYUzJcOJOw/zlTLveliMObE3Ic/JfCpoGgwe+ qXsc+/S8yHMSqgusMO1zXukSH7vLIZU= X-MC-Unique: OFDwj5wNMqCvdcy7zrDZ9w-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 10/11] block/export: report flush errors Date: Tue, 22 Sep 2020 17:04:00 +0100 Message-Id: <20200922160401.294055-11-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 00:31:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Propagate the flush return value since errors are possible. Signed-off-by: Stefan Hajnoczi --- block/export/vhost-user-blk-server.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index b609a3e4d6..44d3c45fa2 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -78,11 +78,11 @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct i= ovec *iov, return -EINVAL; } =20 -static void coroutine_fn vu_block_flush(VuBlockReq *req) +static int coroutine_fn vu_block_flush(VuBlockReq *req) { VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(req->server); BlockBackend *backend =3D vdev_blk->backend; - blk_co_flush(backend); + return blk_co_flush(backend); } =20 static void coroutine_fn vu_block_virtio_process_req(void *opaque) @@ -152,8 +152,11 @@ static void coroutine_fn vu_block_virtio_process_req(v= oid *opaque) break; } case VIRTIO_BLK_T_FLUSH: - vu_block_flush(req); - req->in->status =3D VIRTIO_BLK_S_OK; + if (vu_block_flush(req) =3D=3D 0) { + req->in->status =3D VIRTIO_BLK_S_OK; + } else { + req->in->status =3D VIRTIO_BLK_S_IOERR; + } break; case VIRTIO_BLK_T_GET_ID: { size_t size =3D MIN(iov_size(&elem->in_sg[0], in_num), --=20 2.26.2 From nobody Tue Apr 30 05:33:15 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600791213; cv=none; d=zohomail.com; s=zohoarc; b=PqAiroJ9WnE8bXt3Co1FKNN+HfrS33Rsf6Dwb5sEbxVDFn5avca/aVTO4E85ommEaHEqs7ty2PX8KMvD4kmjteIDr8QwNMZrFg7+HUwg7JYN2uvkoN6r3jl8nWmaoqS0YBs0reBgqO6ST1cNnat8sc8teNnBwmfpBTagEFrYay4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600791213; 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=BN0mDWS0Jks4TTWCUyAWyxyS9BNNtn+o/qsNSIbuj10=; b=Bh5KwGuWSa6badgrq+bTtuPG/js5vg5a7iJvSJS3tyA9/GFjsg7WFDKgfkJuScRBVq4rjemLzWRh1N4rNJA37pk9awYx5KlmkmHFfxXgvwiMdLpKhvIqdy0QY4Q6B95P2pl8hB6oGCFEmPU6cxzJjg6kFrx4avF6lk+bG84I5Bg= 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+importer=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 1600791212930530.712810224752; Tue, 22 Sep 2020 09:13:32 -0700 (PDT) Received: from localhost ([::1]:40010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKkv5-00049B-Su for importer@patchew.org; Tue, 22 Sep 2020 12:13:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKkmg-0003Qs-AF for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47901) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKkmb-0005g3-FQ for qemu-devel@nongnu.org; Tue, 22 Sep 2020 12:04:49 -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-488-1AACv8jUOZq1g5PwrpJ_uw-1; Tue, 22 Sep 2020 12:04:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4CC75802EA5; Tue, 22 Sep 2020 16:04:41 +0000 (UTC) Received: from localhost (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 943765C1A3; Tue, 22 Sep 2020 16:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600790684; 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=BN0mDWS0Jks4TTWCUyAWyxyS9BNNtn+o/qsNSIbuj10=; b=LOJBk6JVxzepnirfZ2G2EgkUeRIS+iAdF72+3SR+nVe2+tbxz320cJp4qNE9wkCq0kdIt7 haELs0itz9YbCcacb5aAk3C4Xb+sLdFte+aDDqVFsPoQXzVjr9o8QnhSHfBb7leG+zGdhC s5JXRvJgK6vcKuRI39mU815UcP6Uicw= X-MC-Unique: 1AACv8jUOZq1g5PwrpJ_uw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 11/11] block/export: convert vhost-user-blk server to block export API Date: Tue, 22 Sep 2020 17:04:01 +0100 Message-Id: <20200922160401.294055-12-stefanha@redhat.com> In-Reply-To: <20200922160401.294055-1-stefanha@redhat.com> References: <20200922160401.294055-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Coiby Xu , mreitz@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use the new QAPI block exports API instead of defining our own QOM objects. This is a large change because the lifecycle of VuBlockDev needs to follow BlockExportDriver. QOM properties are replaced by QAPI options objects. VuBlockDev is renamed VuBlkExport and contains a BlockExport field. Several fields can be dropped since BlockExport already has equivalents. The file names and meson build integration will be adjusted in a future patch. libvhost-user should probably be built as a static library that is linked into QEMU instead of as a .c file that results in duplicate compilation. The new command-line syntax is: $ qemu-storage-daemon \ --blockdev file,node-name=3Ddrive0,filename=3Dtest.img \ --export vhost-user-blk,node-name=3Ddrive0,id=3Dexport0,unix-socket= =3D/tmp/vhost-user-blk.sock Note that unix-socket is optional because we may wish to accept chardevs too in the future. Signed-off-by: Stefan Hajnoczi --- qapi/block-export.json | 19 +- block/export/vhost-user-blk-server.h | 23 +- block/export/export.c | 8 +- block/export/vhost-user-blk-server.c | 461 ++++++++------------------- block/export/meson.build | 1 + block/meson.build | 1 - 6 files changed, 156 insertions(+), 357 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index ace0d66e17..840dcbe833 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -84,6 +84,19 @@ 'data': { '*name': 'str', '*description': 'str', '*bitmap': 'str' } } =20 +## +# @BlockExportOptionsVhostUserBlk: +# +# A vhost-user-blk block export. +# +# @unix-socket: Path where the vhost-user UNIX domain socket will be creat= ed. +# @logical-block-size: Logical block size in bytes. +# +# Since: 5.2 +## +{ 'struct': 'BlockExportOptionsVhostUserBlk', + 'data': { '*unix-socket': 'str', '*logical-block-size': 'size' } } + ## # @NbdServerAddOptions: # @@ -180,11 +193,12 @@ # An enumeration of block export types # # @nbd: NBD export +# @vhost-user-blk: vhost-user-blk export (since 5.2) # # Since: 4.2 ## { 'enum': 'BlockExportType', - 'data': [ 'nbd' ] } + 'data': [ 'nbd', 'vhost-user-blk' ] } =20 ## # @BlockExportOptions: @@ -213,7 +227,8 @@ '*writethrough': 'bool' }, 'discriminator': 'type', 'data': { - 'nbd': 'BlockExportOptionsNbd' + 'nbd': 'BlockExportOptionsNbd', + 'vhost-user-blk': 'BlockExportOptionsVhostUserBlk' } } =20 ## diff --git a/block/export/vhost-user-blk-server.h b/block/export/vhost-user= -blk-server.h index f06f37c4c8..fcf46fc8a5 100644 --- a/block/export/vhost-user-blk-server.h +++ b/block/export/vhost-user-blk-server.h @@ -10,27 +10,10 @@ =20 #ifndef VHOST_USER_BLK_SERVER_H #define VHOST_USER_BLK_SERVER_H -#include "util/vhost-user-server.h" =20 -typedef struct VuBlockDev VuBlockDev; -#define TYPE_VHOST_USER_BLK_SERVER "vhost-user-blk-server" -#define VHOST_USER_BLK_SERVER(obj) \ - OBJECT_CHECK(VuBlockDev, obj, TYPE_VHOST_USER_BLK_SERVER) +#include "block/export.h" =20 -/* vhost user block device */ -struct VuBlockDev { - Object parent_obj; - char *node_name; - SocketAddress *addr; - AioContext *ctx; - VuServer vu_server; - bool running; - uint32_t blk_size; - BlockBackend *backend; - QIOChannelSocket *sioc; - QTAILQ_ENTRY(VuBlockDev) next; - struct virtio_blk_config blkcfg; - bool writable; -}; +/* For block/export/export.c */ +extern const BlockExportDriver blk_exp_vhost_user_blk; =20 #endif /* VHOST_USER_BLK_SERVER_H */ diff --git a/block/export/export.c b/block/export/export.c index 87516d1e05..d0c7590911 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -17,6 +17,9 @@ #include "sysemu/block-backend.h" #include "block/export.h" #include "block/nbd.h" +#if CONFIG_LINUX +#include "block/export/vhost-user-blk-server.h" +#endif #include "qapi/error.h" #include "qapi/qapi-commands-block-export.h" #include "qapi/qapi-events-block-export.h" @@ -24,6 +27,9 @@ =20 static const BlockExportDriver *blk_exp_drivers[] =3D { &blk_exp_nbd, +#if CONFIG_LINUX + &blk_exp_vhost_user_blk, +#endif }; =20 /* Only accessed from the main thread */ @@ -123,7 +129,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) assert(drv->instance_size >=3D sizeof(BlockExport)); exp =3D g_malloc0(drv->instance_size); *exp =3D (BlockExport) { - .drv =3D &blk_exp_nbd, + .drv =3D drv, .refcount =3D 1, .user_owned =3D true, .id =3D g_strdup(export->id), diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index 44d3c45fa2..9908b3287e 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -11,6 +11,9 @@ */ #include "qemu/osdep.h" #include "block/block.h" +#include "contrib/libvhost-user/libvhost-user.h" +#include "standard-headers/linux/virtio_blk.h" +#include "util/vhost-user-server.h" #include "vhost-user-blk-server.h" #include "qapi/error.h" #include "qom/object_interfaces.h" @@ -24,7 +27,7 @@ struct virtio_blk_inhdr { unsigned char status; }; =20 -typedef struct VuBlockReq { +typedef struct VuBlkReq { VuVirtqElement elem; int64_t sector_num; size_t size; @@ -32,9 +35,19 @@ typedef struct VuBlockReq { struct virtio_blk_outhdr out; VuServer *server; struct VuVirtq *vq; -} VuBlockReq; +} VuBlkReq; =20 -static void vu_block_req_complete(VuBlockReq *req) +/* vhost user block device */ +typedef struct { + BlockExport export; + VuServer vu_server; + uint32_t blk_size; + QIOChannelSocket *sioc; + struct virtio_blk_config blkcfg; + bool writable; +} VuBlkExport; + +static void vu_blk_req_complete(VuBlkReq *req) { VuDev *vu_dev =3D &req->server->vu_dev; =20 @@ -45,14 +58,9 @@ static void vu_block_req_complete(VuBlockReq *req) free(req); } =20 -static VuBlockDev *get_vu_block_device_by_server(VuServer *server) -{ - return container_of(server, VuBlockDev, vu_server); -} - static int coroutine_fn -vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov, - uint32_t iovcnt, uint32_t type) +vu_blk_discard_write_zeroes(BlockBackend *blk, struct iovec *iov, + uint32_t iovcnt, uint32_t type) { struct virtio_blk_discard_write_zeroes desc; ssize_t size =3D iov_to_buf(iov, iovcnt, 0, &desc, sizeof(desc)); @@ -61,16 +69,14 @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct i= ovec *iov, return -EINVAL; } =20 - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(req->server); uint64_t range[2] =3D { le64_to_cpu(desc.sector) << 9, le32_to_cpu(desc.num_sectors) << 9 }; if (type =3D=3D VIRTIO_BLK_T_DISCARD) { - if (blk_co_pdiscard(vdev_blk->backend, range[0], range[1]) =3D=3D = 0) { + if (blk_co_pdiscard(blk, range[0], range[1]) =3D=3D 0) { return 0; } } else if (type =3D=3D VIRTIO_BLK_T_WRITE_ZEROES) { - if (blk_co_pwrite_zeroes(vdev_blk->backend, - range[0], range[1], 0) =3D=3D 0) { + if (blk_co_pwrite_zeroes(blk, range[0], range[1], 0) =3D=3D 0) { return 0; } } @@ -78,22 +84,15 @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct i= ovec *iov, return -EINVAL; } =20 -static int coroutine_fn vu_block_flush(VuBlockReq *req) +static void coroutine_fn vu_blk_virtio_process_req(void *opaque) { - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(req->server); - BlockBackend *backend =3D vdev_blk->backend; - return blk_co_flush(backend); -} - -static void coroutine_fn vu_block_virtio_process_req(void *opaque) -{ - VuBlockReq *req =3D opaque; + VuBlkReq *req =3D opaque; VuServer *server =3D req->server; VuVirtqElement *elem =3D &req->elem; uint32_t type; =20 - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); - BlockBackend *backend =3D vdev_blk->backend; + VuBlkExport *vexp =3D container_of(server, VuBlkExport, vu_server); + BlockBackend *blk =3D vexp->export.blk; =20 struct iovec *in_iov =3D elem->in_sg; struct iovec *out_iov =3D elem->out_sg; @@ -133,16 +132,19 @@ static void coroutine_fn vu_block_virtio_process_req(= void *opaque) bool is_write =3D type & VIRTIO_BLK_T_OUT; req->sector_num =3D le64_to_cpu(req->out.sector); =20 - int64_t offset =3D req->sector_num * vdev_blk->blk_size; + if (is_write && !vexp->writable) { + req->in->status =3D VIRTIO_BLK_S_IOERR; + break; + } + + int64_t offset =3D req->sector_num * vexp->blk_size; QEMUIOVector qiov; if (is_write) { qemu_iovec_init_external(&qiov, out_iov, out_num); - ret =3D blk_co_pwritev(backend, offset, qiov.size, - &qiov, 0); + ret =3D blk_co_pwritev(blk, offset, qiov.size, &qiov, 0); } else { qemu_iovec_init_external(&qiov, in_iov, in_num); - ret =3D blk_co_preadv(backend, offset, qiov.size, - &qiov, 0); + ret =3D blk_co_preadv(blk, offset, qiov.size, &qiov, 0); } if (ret >=3D 0) { req->in->status =3D VIRTIO_BLK_S_OK; @@ -152,7 +154,7 @@ static void coroutine_fn vu_block_virtio_process_req(vo= id *opaque) break; } case VIRTIO_BLK_T_FLUSH: - if (vu_block_flush(req) =3D=3D 0) { + if (blk_co_flush(blk) =3D=3D 0) { req->in->status =3D VIRTIO_BLK_S_OK; } else { req->in->status =3D VIRTIO_BLK_S_IOERR; @@ -169,8 +171,13 @@ static void coroutine_fn vu_block_virtio_process_req(v= oid *opaque) case VIRTIO_BLK_T_DISCARD: case VIRTIO_BLK_T_WRITE_ZEROES: { int rc; - rc =3D vu_block_discard_write_zeroes(req, &elem->out_sg[1], - out_num, type); + + if (!vexp->writable) { + req->in->status =3D VIRTIO_BLK_S_IOERR; + break; + } + + rc =3D vu_blk_discard_write_zeroes(blk, &elem->out_sg[1], out_num,= type); if (rc =3D=3D 0) { req->in->status =3D VIRTIO_BLK_S_OK; } else { @@ -183,22 +190,22 @@ static void coroutine_fn vu_block_virtio_process_req(= void *opaque) break; } =20 - vu_block_req_complete(req); + vu_blk_req_complete(req); return; =20 err: - free(elem); + free(req); } =20 -static void vu_block_process_vq(VuDev *vu_dev, int idx) +static void vu_blk_process_vq(VuDev *vu_dev, int idx) { VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); VuVirtq *vq =3D vu_get_queue(vu_dev, idx); =20 while (1) { - VuBlockReq *req; + VuBlkReq *req; =20 - req =3D vu_queue_pop(vu_dev, vq, sizeof(VuBlockReq)); + req =3D vu_queue_pop(vu_dev, vq, sizeof(VuBlkReq)); if (!req) { break; } @@ -207,26 +214,26 @@ static void vu_block_process_vq(VuDev *vu_dev, int id= x) req->vq =3D vq; =20 Coroutine *co =3D - qemu_coroutine_create(vu_block_virtio_process_req, req); + qemu_coroutine_create(vu_blk_virtio_process_req, req); qemu_coroutine_enter(co); } } =20 -static void vu_block_queue_set_started(VuDev *vu_dev, int idx, bool starte= d) +static void vu_blk_queue_set_started(VuDev *vu_dev, int idx, bool started) { VuVirtq *vq; =20 assert(vu_dev); =20 vq =3D vu_get_queue(vu_dev, idx); - vu_set_queue_handler(vu_dev, vq, started ? vu_block_process_vq : NULL); + vu_set_queue_handler(vu_dev, vq, started ? vu_blk_process_vq : NULL); } =20 -static uint64_t vu_block_get_features(VuDev *dev) +static uint64_t vu_blk_get_features(VuDev *dev) { uint64_t features; VuServer *server =3D container_of(dev, VuServer, vu_dev); - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); + VuBlkExport *vexp =3D container_of(server, VuBlkExport, vu_server); features =3D 1ull << VIRTIO_BLK_F_SIZE_MAX | 1ull << VIRTIO_BLK_F_SEG_MAX | 1ull << VIRTIO_BLK_F_TOPOLOGY | @@ -240,35 +247,35 @@ static uint64_t vu_block_get_features(VuDev *dev) 1ull << VIRTIO_RING_F_EVENT_IDX | 1ull << VHOST_USER_F_PROTOCOL_FEATURES; =20 - if (!vdev_blk->writable) { + if (!vexp->writable) { features |=3D 1ull << VIRTIO_BLK_F_RO; } =20 return features; } =20 -static uint64_t vu_block_get_protocol_features(VuDev *dev) +static uint64_t vu_blk_get_protocol_features(VuDev *dev) { return 1ull << VHOST_USER_PROTOCOL_F_CONFIG | 1ull << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD; } =20 static int -vu_block_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) +vu_blk_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) { + /* TODO blkcfg must be little-endian for VIRTIO 1.0 */ VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); - memcpy(config, &vdev_blk->blkcfg, len); - + VuBlkExport *vexp =3D container_of(server, VuBlkExport, vu_server); + memcpy(config, &vexp->blkcfg, len); return 0; } =20 static int -vu_block_set_config(VuDev *vu_dev, const uint8_t *data, +vu_blk_set_config(VuDev *vu_dev, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags) { VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); + VuBlkExport *vexp =3D container_of(server, VuBlkExport, vu_server); uint8_t wce; =20 /* don't support live migration */ @@ -282,8 +289,8 @@ vu_block_set_config(VuDev *vu_dev, const uint8_t *data, } =20 wce =3D *data; - vdev_blk->blkcfg.wce =3D wce; - blk_set_enable_write_cache(vdev_blk->backend, wce); + vexp->blkcfg.wce =3D wce; + blk_set_enable_write_cache(vexp->export.blk, wce); return 0; } =20 @@ -295,7 +302,7 @@ vu_block_set_config(VuDev *vu_dev, const uint8_t *data, * of vu_process_message. * */ -static int vu_block_process_msg(VuDev *dev, VhostUserMsg *vmsg, int *do_re= ply) +static int vu_blk_process_msg(VuDev *dev, VhostUserMsg *vmsg, int *do_repl= y) { if (vmsg->request =3D=3D VHOST_USER_NONE) { dev->panic(dev, "disconnect"); @@ -304,29 +311,29 @@ static int vu_block_process_msg(VuDev *dev, VhostUser= Msg *vmsg, int *do_reply) return false; } =20 -static const VuDevIface vu_block_iface =3D { - .get_features =3D vu_block_get_features, - .queue_set_started =3D vu_block_queue_set_started, - .get_protocol_features =3D vu_block_get_protocol_features, - .get_config =3D vu_block_get_config, - .set_config =3D vu_block_set_config, - .process_msg =3D vu_block_process_msg, +static const VuDevIface vu_blk_iface =3D { + .get_features =3D vu_blk_get_features, + .queue_set_started =3D vu_blk_queue_set_started, + .get_protocol_features =3D vu_blk_get_protocol_features, + .get_config =3D vu_blk_get_config, + .set_config =3D vu_blk_set_config, + .process_msg =3D vu_blk_process_msg, }; =20 static void blk_aio_attached(AioContext *ctx, void *opaque) { - VuBlockDev *vub_dev =3D opaque; - vhost_user_server_attach_aio_context(&vub_dev->vu_server, ctx); + VuBlkExport *vexp =3D opaque; + vhost_user_server_attach_aio_context(&vexp->vu_server, ctx); } =20 static void blk_aio_detach(void *opaque) { - VuBlockDev *vub_dev =3D opaque; - vhost_user_server_detach_aio_context(&vub_dev->vu_server); + VuBlkExport *vexp =3D opaque; + vhost_user_server_detach_aio_context(&vexp->vu_server); } =20 static void -vu_block_initialize_config(BlockDriverState *bs, +vu_blk_initialize_config(BlockDriverState *bs, struct virtio_blk_config *config, uint32_t blk_= size) { config->capacity =3D bdrv_getlength(bs) >> BDRV_SECTOR_BITS; @@ -343,290 +350,78 @@ vu_block_initialize_config(BlockDriverState *bs, config->max_write_zeroes_seg =3D 1; } =20 -static VuBlockDev *vu_block_init(VuBlockDev *vu_block_device, Error **errp) +static void vu_blk_exp_request_shutdown(BlockExport *exp) { + VuBlkExport *vexp =3D container_of(exp, VuBlkExport, export); =20 - BlockBackend *blk; - Error *local_error =3D NULL; - const char *node_name =3D vu_block_device->node_name; - bool writable =3D vu_block_device->writable; - uint64_t perm =3D BLK_PERM_CONSISTENT_READ; - int ret; - - AioContext *ctx; - - BlockDriverState *bs =3D bdrv_lookup_bs(node_name, node_name, &local_e= rror); - - if (!bs) { - error_propagate(errp, local_error); - return NULL; - } - - if (bdrv_is_read_only(bs)) { - writable =3D false; - } - - if (writable) { - perm |=3D BLK_PERM_WRITE; - } - - ctx =3D bdrv_get_aio_context(bs); - aio_context_acquire(ctx); - bdrv_invalidate_cache(bs, NULL); - aio_context_release(ctx); - - /* - * Don't allow resize while the vhost user server is running, - * otherwise we don't care what happens with the node. - */ - blk =3D blk_new(bdrv_get_aio_context(bs), perm, - BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | - BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD); - ret =3D blk_insert_bs(blk, bs, errp); - - if (ret < 0) { - goto fail; - } - - blk_set_enable_write_cache(blk, false); - - blk_set_allow_aio_context_change(blk, true); - - vu_block_device->blkcfg.wce =3D 0; - vu_block_device->backend =3D blk; - if (!vu_block_device->blk_size) { - vu_block_device->blk_size =3D BDRV_SECTOR_SIZE; - } - vu_block_device->blkcfg.blk_size =3D vu_block_device->blk_size; - blk_set_guest_block_size(blk, vu_block_device->blk_size); - vu_block_initialize_config(bs, &vu_block_device->blkcfg, - vu_block_device->blk_size); - return vu_block_device; - -fail: - blk_unref(blk); - return NULL; -} - -static void vu_block_deinit(VuBlockDev *vu_block_device) -{ - if (vu_block_device->backend) { - blk_remove_aio_context_notifier(vu_block_device->backend, blk_aio_= attached, - blk_aio_detach, vu_block_device); - } - - blk_unref(vu_block_device->backend); -} - -static void vhost_user_blk_server_stop(VuBlockDev *vu_block_device) -{ - vhost_user_server_stop(&vu_block_device->vu_server); - vu_block_deinit(vu_block_device); -} - -static void vhost_user_blk_server_start(VuBlockDev *vu_block_device, - Error **errp) -{ - AioContext *ctx; - SocketAddress *addr =3D vu_block_device->addr; - - if (!vu_block_init(vu_block_device, errp)) { - return; - } - - ctx =3D bdrv_get_aio_context(blk_bs(vu_block_device->backend)); - - if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, - VHOST_USER_BLK_MAX_QUEUES, &vu_block_ifac= e, - errp)) { - goto error; - } - - blk_add_aio_context_notifier(vu_block_device->backend, blk_aio_attache= d, - blk_aio_detach, vu_block_device); - vu_block_device->running =3D true; - return; - - error: - vu_block_deinit(vu_block_device); -} - -static bool vu_prop_modifiable(VuBlockDev *vus, Error **errp) -{ - if (vus->running) { - error_setg(errp, "The property can't be modified " - "while the server is running"); - return false; - } - return true; -} - -static void vu_set_node_name(Object *obj, const char *value, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - - if (!vu_prop_modifiable(vus, errp)) { - return; - } - - if (vus->node_name) { - g_free(vus->node_name); - } - - vus->node_name =3D g_strdup(value); -} - -static char *vu_get_node_name(Object *obj, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - return g_strdup(vus->node_name); -} - -static void free_socket_addr(SocketAddress *addr) -{ - g_free(addr->u.q_unix.path); - g_free(addr); -} - -static void vu_set_unix_socket(Object *obj, const char *value, - Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - - if (!vu_prop_modifiable(vus, errp)) { - return; - } - - if (vus->addr) { - free_socket_addr(vus->addr); - } - - SocketAddress *addr =3D g_new0(SocketAddress, 1); - addr->type =3D SOCKET_ADDRESS_TYPE_UNIX; - addr->u.q_unix.path =3D g_strdup(value); - vus->addr =3D addr; + vhost_user_server_stop(&vexp->vu_server); } =20 -static char *vu_get_unix_socket(Object *obj, Error **errp) +static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, + Error **errp) { - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - return g_strdup(vus->addr->u.q_unix.path); -} - -static bool vu_get_block_writable(Object *obj, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - return vus->writable; -} - -static void vu_set_block_writable(Object *obj, bool value, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - - if (!vu_prop_modifiable(vus, errp)) { - return; - } - - vus->writable =3D value; -} - -static void vu_get_blk_size(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - uint32_t value =3D vus->blk_size; - - visit_type_uint32(v, name, &value, errp); -} - -static void vu_set_blk_size(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - + VuBlkExport *vexp =3D container_of(exp, VuBlkExport, export); + BlockExportOptionsVhostUserBlk *vu_opts =3D &opts->u.vhost_user_blk; + SocketAddress addr =3D { + .type =3D SOCKET_ADDRESS_TYPE_UNIX, + .u.q_unix.path =3D vu_opts->has_unix_socket ? + vu_opts->unix_socket : + NULL, + }; Error *local_err =3D NULL; - uint32_t value; + uint64_t logical_block_size; =20 - if (!vu_prop_modifiable(vus, errp)) { - return; + if (!vu_opts->has_unix_socket) { + error_setg(errp, "Missing unix-socket path to listen on"); + return -EINVAL; } =20 - visit_type_uint32(v, name, &value, &local_err); - if (local_err) { - goto out; - } + vexp->writable =3D opts->writable; + vexp->blkcfg.wce =3D 0; =20 - check_block_size(object_get_typename(obj), name, value, &local_err); + if (vu_opts->has_logical_block_size) { + logical_block_size =3D vu_opts->logical_block_size; + } else { + logical_block_size =3D BDRV_SECTOR_SIZE; + } + check_block_size(exp->id, "logical-block-size", logical_block_size, + &local_err); if (local_err) { - goto out; + error_propagate(errp, local_err); + return -EINVAL; + } + vexp->blk_size =3D logical_block_size; + blk_set_guest_block_size(exp->blk, logical_block_size); + vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, + logical_block_size); + + blk_set_allow_aio_context_change(exp->blk, true); + blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detac= h, + vexp); + + if (!vhost_user_server_start(&vexp->vu_server, &addr, exp->ctx, + VHOST_USER_BLK_MAX_QUEUES, &vu_blk_iface, + errp)) { + blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, + blk_aio_detach, vexp); + return -EADDRNOTAVAIL; } =20 - vus->blk_size =3D value; - -out: - error_propagate(errp, local_err); -} - -static void vhost_user_blk_server_instance_finalize(Object *obj) -{ - VuBlockDev *vub =3D VHOST_USER_BLK_SERVER(obj); - - vhost_user_blk_server_stop(vub); - - /* - * Unlike object_property_add_str, object_class_property_add_str - * doesn't have a release method. Thus manual memory freeing is - * needed. - */ - free_socket_addr(vub->addr); - g_free(vub->node_name); -} - -static void vhost_user_blk_server_complete(UserCreatable *obj, Error **err= p) -{ - VuBlockDev *vub =3D VHOST_USER_BLK_SERVER(obj); - - vhost_user_blk_server_start(vub, errp); + return 0; } =20 -static void vhost_user_blk_server_class_init(ObjectClass *klass, - void *class_data) +static void vu_blk_exp_delete(BlockExport *exp) { - UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(klass); - ucc->complete =3D vhost_user_blk_server_complete; - - object_class_property_add_bool(klass, "writable", - vu_get_block_writable, - vu_set_block_writable); - - object_class_property_add_str(klass, "node-name", - vu_get_node_name, - vu_set_node_name); - - object_class_property_add_str(klass, "unix-socket", - vu_get_unix_socket, - vu_set_unix_socket); + VuBlkExport *vexp =3D container_of(exp, VuBlkExport, export); =20 - object_class_property_add(klass, "logical-block-size", "uint32", - vu_get_blk_size, vu_set_blk_size, - NULL, NULL); + blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_de= tach, + vexp); } =20 -static const TypeInfo vhost_user_blk_server_info =3D { - .name =3D TYPE_VHOST_USER_BLK_SERVER, - .parent =3D TYPE_OBJECT, - .instance_size =3D sizeof(VuBlockDev), - .instance_finalize =3D vhost_user_blk_server_instance_finalize, - .class_init =3D vhost_user_blk_server_class_init, - .interfaces =3D (InterfaceInfo[]) { - {TYPE_USER_CREATABLE}, - {} - }, +const BlockExportDriver blk_exp_vhost_user_blk =3D { + .type =3D BLOCK_EXPORT_TYPE_VHOST_USER_BLK, + .instance_size =3D sizeof(VuBlkExport), + .create =3D vu_blk_exp_create, + .delete =3D vu_blk_exp_delete, + .request_shutdown =3D vu_blk_exp_request_shutdown, }; - -static void vhost_user_blk_server_register_types(void) -{ - type_register_static(&vhost_user_blk_server_info); -} - -type_init(vhost_user_blk_server_register_types) diff --git a/block/export/meson.build b/block/export/meson.build index 558ef35d38..ef3a9576f7 100644 --- a/block/export/meson.build +++ b/block/export/meson.build @@ -1 +1,2 @@ block_ss.add(files('export.c')) +block_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-server.c= ', '../../contrib/libvhost-user/libvhost-user.c')) diff --git a/block/meson.build b/block/meson.build index cd52104c84..0b38dc36f7 100644 --- a/block/meson.build +++ b/block/meson.build @@ -60,7 +60,6 @@ block_ss.add(when: 'CONFIG_WIN32', if_true: files('file-w= in32.c', 'win32-aio.c') block_ss.add(when: 'CONFIG_POSIX', if_true: [files('file-posix.c'), coref,= iokit]) block_ss.add(when: 'CONFIG_LIBISCSI', if_true: files('iscsi-opts.c')) block_ss.add(when: 'CONFIG_LINUX', if_true: files('nvme.c')) -block_ss.add(when: 'CONFIG_LINUX', if_true: files('export/vhost-user-blk-s= erver.c', '../contrib/libvhost-user/libvhost-user.c')) block_ss.add(when: 'CONFIG_REPLICATION', if_true: files('replication.c')) block_ss.add(when: 'CONFIG_SHEEPDOG', if_true: files('sheepdog.c')) block_ss.add(when: ['CONFIG_LINUX_AIO', libaio], if_true: files('linux-aio= .c')) --=20 2.26.2