From patchwork Tue Mar 16 18:51:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 47899 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 565F0B7D71 for ; Wed, 17 Mar 2010 06:11:55 +1100 (EST) Received: from localhost ([127.0.0.1]:42824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrcBD-0007wK-Tx for incoming@patchwork.ozlabs.org; Tue, 16 Mar 2010 15:11:51 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nrbro-0002TK-Bt for qemu-devel@nongnu.org; Tue, 16 Mar 2010 14:51:48 -0400 Received: from [199.232.76.173] (port=42507 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nrbrm-0002QB-9M for qemu-devel@nongnu.org; Tue, 16 Mar 2010 14:51:46 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nrbri-0000C6-Ji for qemu-devel@nongnu.org; Tue, 16 Mar 2010 14:51:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8724) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nrbrh-0000Bb-QR for qemu-devel@nongnu.org; Tue, 16 Mar 2010 14:51:42 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2GIpcF7007787 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 16 Mar 2010 14:51:38 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2GIpPvG023231; Tue, 16 Mar 2010 14:51:37 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 16 Mar 2010 19:51:25 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 9/9] virtio-blk: use QLIST for the list of requests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org viltio_blak_dma_restart_bh() was unsafe, it used req->next after having (possible) put req in another list Signed-off-by: Juan Quintela --- hw/virtio-blk.c | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index c2ee27d..e22a911 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -20,13 +20,14 @@ #endif typedef struct VirtIOBlockReq VirtIOBlockReq; +typedef QLIST_HEAD (,VirtIOBlockReq) VirtIOBlockReqHead; typedef struct VirtIOBlock { VirtIODevice vdev; BlockDriverState *bs; VirtQueue *vq; - VirtIOBlockReq *rq; + VirtIOBlockReqHead rq; QEMUBH *bh; BlockConf *conf; } VirtIOBlock; @@ -39,7 +40,7 @@ struct VirtIOBlockReq struct virtio_blk_outhdr *out; struct virtio_scsi_inhdr *scsi; QEMUIOVector qiov; - struct VirtIOBlockReq *next; + QLIST_ENTRY(VirtIOBlockReq) next; }; static void virtio_blk_req_complete(VirtIOBlockReq *req, int status) @@ -67,8 +68,7 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC) || action == BLOCK_ERR_STOP_ANY) { - req->next = s->rq; - s->rq = req; + QLIST_INSERT_HEAD(&s->rq, req, next); bdrv_mon_event(req->dev->bs, BDRV_ACTION_STOP, is_read); vm_stop(0); } else { @@ -342,7 +342,8 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) static void virtio_blk_dma_restart_bh(void *opaque) { VirtIOBlock *s = opaque; - VirtIOBlockReq *req = s->rq; + VirtIOBlockReqHead rq_copy; + VirtIOBlockReq *req, *next_req; MultiReqBuffer mrb = { .num_writes = 0, .old_bs = NULL, @@ -351,11 +352,12 @@ static void virtio_blk_dma_restart_bh(void *opaque) qemu_bh_delete(s->bh); s->bh = NULL; - s->rq = NULL; + QLIST_COPY_HEAD(&rq_copy, &s->rq); + QLIST_INIT(&s->rq); - while (req) { + QLIST_FOREACH_SAFE(req, &rq_copy, next, next_req) { + QLIST_REMOVE(req, next); virtio_blk_handle_request(req, &mrb); - req = req->next; } if (mrb.num_writes > 0) { @@ -430,14 +432,13 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features) static void virtio_blk_save(QEMUFile *f, void *opaque) { VirtIOBlock *s = opaque; - VirtIOBlockReq *req = s->rq; + VirtIOBlockReq *req;; virtio_save(&s->vdev, f); - - while (req) { + + QLIST_FOREACH(req, &s->rq, next) { qemu_put_sbyte(f, 1); qemu_put_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem)); - req = req->next; } qemu_put_sbyte(f, 0); } @@ -453,8 +454,7 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id) while (qemu_get_sbyte(f)) { VirtIOBlockReq *req = virtio_blk_alloc_request(s); qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem)); - req->next = s->rq; - s->rq = req->next; + QLIST_INSERT_HEAD(&s->rq, req, next); } return 0; @@ -476,7 +476,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf) s->vdev.reset = virtio_blk_reset; s->bs = conf->dinfo->bdrv; s->conf = conf; - s->rq = NULL; + QLIST_INIT(&s->rq); bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); bdrv_set_geometry_hint(s->bs, cylinders, heads, secs);