From patchwork Mon Feb 18 10:27:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10817739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 689EF14E1 for ; Mon, 18 Feb 2019 10:32:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54F772A002 for ; Mon, 18 Feb 2019 10:32:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 489612A007; Mon, 18 Feb 2019 10:32:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D73652A002 for ; Mon, 18 Feb 2019 10:32:47 +0000 (UTC) Received: from localhost ([127.0.0.1]:56045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvgEB-0003BM-4U for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Feb 2019 05:32:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvgAM-0000AQ-5g for qemu-devel@nongnu.org; Mon, 18 Feb 2019 05:28:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvgAI-0006K4-MT for qemu-devel@nongnu.org; Mon, 18 Feb 2019 05:28:48 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:33410) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gvgAH-000697-G5 for qemu-devel@nongnu.org; Mon, 18 Feb 2019 05:28:46 -0500 Received: by mail-pf1-x442.google.com with SMTP id c123so8357271pfb.0 for ; Mon, 18 Feb 2019 02:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=slWfpnGw8tZys3H9fBrwFQqWU/09SRe8VQgxBOnTr1M=; b=Dg9Y3tJMmp7Oq8P2bRKv2h+b/qZRcYof9N5KoC/IEQohuu9zejEdlftjme4SgJ1iHk p0ikNCI57tySttkV3B44wAEHCUkQlpZT592zOKnq4MsRiw10LyTmQPCSZktUTiU+0ZHh Wqc0uXgPhkk7u9XeZNSfc+SoeWrFgz5NUm2Z1WIxv/wFvKXgvy69+a5IssulgdfrW66U ncnr9aC4Ob2ienZNu2GM9kVrm42yvV2+Re9vCao5SZoZQfCKdW/f4cFTm6Wsq6t0GB5a ElDYeayLk04suZUiqcXYuTATNhk4Dp5ow8pIgo3SBQbbja6hS+SgEoY1PL1cTNG0hUmW 7BIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=slWfpnGw8tZys3H9fBrwFQqWU/09SRe8VQgxBOnTr1M=; b=b5iJwyp7SwMBtkzaBczEwzYllhuMkinjS6/y/G+GUxHHHsaGsDG/nfIyU+ZoBMlfZR NxZkXRmbcYdmzBz15zBMJ2BEagtyb7WTfiM9td4hh55LcVEtsNhRp2GLiGtDiZ214IqH IjbwFZ5uG7ktRFkpAww/gwyONLwcckw1WoRVi5/UQToFHpaGSHPsT7G5eTXTIWGvcSR5 rkNStPkrZ1Uoh5HOX4SwI2QO/7FFvCY8tnk1sjMEgSK4fKjkftkAlywSi3A2S9ySEbd6 KcDjJvaV4AawLxZCJP7lZeRECYE7UsvR8gGfH5ebhLCUryonxB9mvPfGk/IX/u1tVyFu JYBg== X-Gm-Message-State: AHQUAubcI4v58+JC9Hz5fbp41yN+PKXX1RD+m/uxr8wkYz6JpI0CS3Uh EfNMg24sWFWv+P0G6crUhVc= X-Google-Smtp-Source: AHgI3Ibyn55RQAMeu4JnFJLDfThrh+yWJ+Mdp8Wh3rUeuQ4ic/NdYxQhzTY6iSORKtQLWCwrsFQUJA== X-Received: by 2002:a63:4658:: with SMTP id v24mr21900915pgk.114.1550485708553; Mon, 18 Feb 2019 02:28:28 -0800 (PST) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id a187sm18820989pfb.61.2019.02.18.02.28.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 02:28:28 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, stefanha@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, jasowang@redhat.com, maxime.coquelin@redhat.com, yury-kotov@yandex-team.ru, wrfsh@yandex-team.ru Date: Mon, 18 Feb 2019 18:27:46 +0800 Message-Id: <20190218102748.2242-6-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190218102748.2242-1-xieyongji@baidu.com> References: <20190218102748.2242-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v6 5/7] vhost-user-blk: Add support to get/set inflight buffer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nixun@baidu.com, qemu-devel@nongnu.org, lilin24@baidu.com, zhangyu31@baidu.com, chaiwen@baidu.com, Xie Yongji Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji This patch adds support for vhost-user-blk device to get/set inflight buffer from/to backend. Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu --- hw/block/vhost-user-blk.c | 28 ++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-blk.h | 1 + 2 files changed, 29 insertions(+) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 44ac814016..9682df1a7b 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -128,6 +128,21 @@ static void vhost_user_blk_start(VirtIODevice *vdev) } s->dev.acked_features = vdev->guest_features; + + if (!s->inflight->addr) { + ret = vhost_dev_get_inflight(&s->dev, s->queue_size, s->inflight); + if (ret < 0) { + error_report("Error get inflight: %d", -ret); + goto err_guest_notifiers; + } + } + + ret = vhost_dev_set_inflight(&s->dev, s->inflight); + if (ret < 0) { + error_report("Error set inflight: %d", -ret); + goto err_guest_notifiers; + } + ret = vhost_dev_start(&s->dev, vdev); if (ret < 0) { error_report("Error starting vhost: %d", -ret); @@ -249,6 +264,13 @@ static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) } } +static void vhost_user_blk_reset(VirtIODevice *vdev) +{ + VHostUserBlk *s = VHOST_USER_BLK(vdev); + + vhost_dev_free_inflight(s->inflight); +} + static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -289,6 +311,8 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) vhost_user_blk_handle_output); } + s->inflight = g_new0(struct vhost_inflight, 1); + s->dev.nvqs = s->num_queues; s->dev.vqs = g_new(struct vhost_virtqueue, s->dev.nvqs); s->dev.vq_index = 0; @@ -321,6 +345,7 @@ vhost_err: vhost_dev_cleanup(&s->dev); virtio_err: g_free(vqs); + g_free(s->inflight); virtio_cleanup(vdev); vhost_user_cleanup(user); @@ -336,7 +361,9 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp) vhost_user_blk_set_status(vdev, 0); vhost_dev_cleanup(&s->dev); + vhost_dev_free_inflight(s->inflight); g_free(vqs); + g_free(s->inflight); virtio_cleanup(vdev); if (s->vhost_user) { @@ -386,6 +413,7 @@ static void vhost_user_blk_class_init(ObjectClass *klass, void *data) vdc->set_config = vhost_user_blk_set_config; vdc->get_features = vhost_user_blk_get_features; vdc->set_status = vhost_user_blk_set_status; + vdc->reset = vhost_user_blk_reset; } static const TypeInfo vhost_user_blk_info = { diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h index d52944aeeb..445516604a 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -36,6 +36,7 @@ typedef struct VHostUserBlk { uint32_t queue_size; uint32_t config_wce; struct vhost_dev dev; + struct vhost_inflight *inflight; VhostUserState *vhost_user; } VHostUserBlk;