From patchwork Fri Jun 6 16:13:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 356923 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6480D1400E9 for ; Sat, 7 Jun 2014 02:19:26 +1000 (EST) Received: from localhost ([::1]:48154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WswrU-0000uB-9Z for incoming@patchwork.ozlabs.org; Fri, 06 Jun 2014 12:19:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WswnS-0005KI-NM for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WswnM-0004kh-JH for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7186) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WswnM-0004kM-Ar for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:08 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s56GF6IA018685 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Jun 2014 12:15:06 -0400 Received: from localhost (ovpn-112-25.ams2.redhat.com [10.36.112.25]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s56GF5Tx006467; Fri, 6 Jun 2014 12:15:05 -0400 From: Stefan Hajnoczi To: Date: Fri, 6 Jun 2014 18:13:46 +0200 Message-Id: <1402071243-16702-26-git-send-email-stefanha@redhat.com> In-Reply-To: <1402071243-16702-1-git-send-email-stefanha@redhat.com> References: <1402071243-16702-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Stefan Hajnoczi Subject: [Qemu-devel] [PULL 25/42] dataplane: implement async flush 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 Stop using the raw-posix file descriptor for synchronous qemu_fdatasync(). Use bdrv_aio_flush() instead and drop the VirtIOBlockDataPlane->fd field. Signed-off-by: Stefan Hajnoczi --- hw/block/dataplane/virtio-blk.c | 43 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 75616da..c058c73 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -40,7 +40,6 @@ struct VirtIOBlockDataPlane { bool stopping; VirtIOBlkConf *blk; - int fd; /* image file descriptor */ VirtIODevice *vdev; Vring vring; /* virtqueue vring */ @@ -179,6 +178,32 @@ static void do_rdwr_cmd(VirtIOBlockDataPlane *s, bool read, } } +static void complete_flush(void *opaque, int ret) +{ + VirtIOBlockRequest *req = opaque; + unsigned char status; + + if (ret == 0) { + status = VIRTIO_BLK_S_OK; + } else { + status = VIRTIO_BLK_S_IOERR; + } + + complete_request_early(req->s, req->elem, req->inhdr, status); + g_slice_free(VirtIOBlockRequest, req); +} + +static void do_flush_cmd(VirtIOBlockDataPlane *s, VirtQueueElement *elem, + QEMUIOVector *inhdr) +{ + VirtIOBlockRequest *req = g_slice_new(VirtIOBlockRequest); + req->s = s; + req->elem = elem; + req->inhdr = inhdr; + + bdrv_aio_flush(s->blk->conf.bs, complete_flush, req); +} + static int process_request(VirtIOBlockDataPlane *s, VirtQueueElement *elem) { struct iovec *iov = elem->out_sg; @@ -232,12 +257,7 @@ static int process_request(VirtIOBlockDataPlane *s, VirtQueueElement *elem) return 0; case VIRTIO_BLK_T_FLUSH: - /* TODO fdsync not supported by Linux AIO, do it synchronously here! */ - if (qemu_fdatasync(s->fd) < 0) { - complete_request_early(s, elem, inhdr, VIRTIO_BLK_S_IOERR); - } else { - complete_request_early(s, elem, inhdr, VIRTIO_BLK_S_OK); - } + do_flush_cmd(s, elem, inhdr); return 0; case VIRTIO_BLK_T_GET_ID: @@ -302,7 +322,6 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk, Error **errp) { VirtIOBlockDataPlane *s; - int fd; Error *local_err = NULL; *dataplane = NULL; @@ -333,16 +352,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk, return; } - fd = raw_get_aio_fd(blk->conf.bs); - if (fd < 0) { - error_setg(errp, "drive is incompatible with x-data-plane, " - "use format=raw,cache=none,aio=native"); - return; - } - s = g_new0(VirtIOBlockDataPlane, 1); s->vdev = vdev; - s->fd = fd; s->blk = blk; if (blk->iothread) {