From patchwork Mon Jul 15 14:42:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 259060 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A63372C00EE for ; Tue, 16 Jul 2013 00:44:20 +1000 (EST) Received: from localhost ([::1]:60155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uyk0g-00007K-KD for incoming@patchwork.ozlabs.org; Mon, 15 Jul 2013 10:44:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uyk04-0008Ri-R6 for qemu-devel@nongnu.org; Mon, 15 Jul 2013 10:43:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uyjzz-0001pp-17 for qemu-devel@nongnu.org; Mon, 15 Jul 2013 10:43:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22918) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uyjzy-0001pY-QP for qemu-devel@nongnu.org; Mon, 15 Jul 2013 10:43:34 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6FEhYsK032404 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 15 Jul 2013 10:43:34 -0400 Received: from localhost (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6FEhU70010787; Mon, 15 Jul 2013 10:43:33 -0400 From: Stefan Hajnoczi To: Date: Mon, 15 Jul 2013 22:42:52 +0800 Message-Id: <1373899382-13514-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1373899382-13514-1-git-send-email-stefanha@redhat.com> References: <1373899382-13514-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 03/13] virtio-blk: implement BlockDevOps->drain_threads_cb() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Drain and stop the dataplane thread when bdrv_drain_all() is called. Note that the thread will be restarted in virtio_blk_handle_output() the next time the guest kicks the virtqueue. Signed-off-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index cf12469..f4ad528 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -618,8 +618,24 @@ static void virtio_blk_resize(void *opaque) virtio_notify_config(vdev); } +static void virtio_blk_drain_threads(void *opaque) +{ +#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE + VirtIOBlock *s = VIRTIO_BLK(opaque); + + if (s->dataplane) { + /* Drain I/O and stop thread. Next time the guest kicks the virtqueue + * we restart the thread. In the meantime the main loop may access the + * block device. + */ + virtio_blk_data_plane_stop(s->dataplane); + } +#endif +} + static const BlockDevOps virtio_block_ops = { .resize_cb = virtio_blk_resize, + .drain_threads_cb = virtio_blk_drain_threads, }; void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)