From patchwork Tue Aug 9 07:46:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 109148 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6B34CB6F86 for ; Tue, 9 Aug 2011 17:47:01 +1000 (EST) Received: from localhost ([::1]:36848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqh1d-0003fu-IX for incoming@patchwork.ozlabs.org; Tue, 09 Aug 2011 03:46:57 -0400 Received: from eggs.gnu.org ([140.186.70.92]:40059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqh1U-0003SH-8G for qemu-devel@nongnu.org; Tue, 09 Aug 2011 03:46:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qqh1S-0006na-VZ for qemu-devel@nongnu.org; Tue, 09 Aug 2011 03:46:48 -0400 Received: from mail-ey0-f171.google.com ([209.85.215.171]:43960) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqh1S-0006nW-ME for qemu-devel@nongnu.org; Tue, 09 Aug 2011 03:46:46 -0400 Received: by eyg24 with SMTP id 24so3371321eyg.16 for ; Tue, 09 Aug 2011 00:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=TEDexhv3NOALwSKBhyCdVqi+mw/0gQrCDZp5pt+PzTc=; b=Vljn599cSkY8AiDwvmfUuWQ6xdsVIRBKBL/HbXW0Okg/YpVPX8hWkgrtFuL/CQuH1a 1KUIcnarFuivqWrSd1B8qV/wS2O9yE3PUo4FwKp7gdX1XLZrz9zg33XOMKkzmTvGtG+w iv3UrfVWOuep8Jh0fyNau+V+v8WVnr+QmHqQM= Received: by 10.213.105.74 with SMTP id s10mr14752ebo.77.1312876005819; Tue, 09 Aug 2011 00:46:45 -0700 (PDT) Received: from obol602.omnitel.it ([206.217.137.183]) by mx.google.com with ESMTPS id p49sm2857459eef.58.2011.08.09.00.46.42 (version=SSLv3 cipher=OTHER); Tue, 09 Aug 2011 00:46:44 -0700 (PDT) From: Frediano Ziglio To: kwolf@redhat.com Date: Tue, 9 Aug 2011 09:46:37 +0200 Message-Id: <1312876010-15361-3-git-send-email-freddy77@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1312876010-15361-1-git-send-email-freddy77@gmail.com> References: <1312876010-15361-1-git-send-email-freddy77@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.215.171 Cc: qemu-devel@nongnu.org, Frediano Ziglio Subject: [Qemu-devel] [PATCH v2 02/15] qcow: QCowAIOCB field cleanup 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 remove unused field from this structure and put some of them in qcow_aio_read_cb and qcow_aio_write_cb Signed-off-by: Frediano Ziglio --- block/qcow.c | 137 +++++++++++++++++++++++++++------------------------------ 1 files changed, 65 insertions(+), 72 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index d19ef04..f0b1599 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -487,72 +487,61 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num, #endif typedef struct QCowAIOCB { - BlockDriverAIOCB common; + BlockDriverState *bs; int64_t sector_num; QEMUIOVector *qiov; uint8_t *buf; void *orig_buf; int nb_sectors; - int n; - uint64_t cluster_offset; - uint8_t *cluster_data; - struct iovec hd_iov; - bool is_write; - QEMUBH *bh; - QEMUIOVector hd_qiov; - BlockDriverAIOCB *hd_aiocb; } QCowAIOCB; static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, int is_write, QCowAIOCB *acb) { - memset(acb, 0, sizeof(*acb)); - acb->common.bs = bs; - acb->hd_aiocb = NULL; + acb->bs = bs; acb->sector_num = sector_num; acb->qiov = qiov; - acb->is_write = is_write; if (qiov->niov > 1) { acb->buf = acb->orig_buf = qemu_blockalign(bs, qiov->size); if (is_write) qemu_iovec_to_buffer(qiov, acb->buf); } else { + acb->orig_buf = NULL; acb->buf = (uint8_t *)qiov->iov->iov_base; } acb->nb_sectors = nb_sectors; - acb->n = 0; - acb->cluster_offset = 0; return acb; } static int qcow_aio_read_cb(QCowAIOCB *acb) { - BlockDriverState *bs = acb->common.bs; + BlockDriverState *bs = acb->bs; BDRVQcowState *s = bs->opaque; int index_in_cluster; - int ret; - - acb->hd_aiocb = NULL; + int ret, n = 0; + uint64_t cluster_offset = 0; + struct iovec hd_iov; + QEMUIOVector hd_qiov; redo: /* post process the read buffer */ - if (!acb->cluster_offset) { + if (!cluster_offset) { /* nothing to do */ - } else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) { + } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) { /* nothing to do */ } else { if (s->crypt_method) { encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf, - acb->n, 0, + n, 0, &s->aes_decrypt_key); } } - acb->nb_sectors -= acb->n; - acb->sector_num += acb->n; - acb->buf += acb->n * 512; + acb->nb_sectors -= n; + acb->sector_num += n; + acb->buf += n * 512; if (acb->nb_sectors == 0) { /* request completed */ @@ -560,57 +549,58 @@ static int qcow_aio_read_cb(QCowAIOCB *acb) } /* prepare next AIO request */ - acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, + cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, 0, 0, 0, 0); index_in_cluster = acb->sector_num & (s->cluster_sectors - 1); - acb->n = s->cluster_sectors - index_in_cluster; - if (acb->n > acb->nb_sectors) - acb->n = acb->nb_sectors; + n = s->cluster_sectors - index_in_cluster; + if (n > acb->nb_sectors) { + n = acb->nb_sectors; + } - if (!acb->cluster_offset) { + if (!cluster_offset) { if (bs->backing_hd) { /* read from the base image */ - acb->hd_iov.iov_base = (void *)acb->buf; - acb->hd_iov.iov_len = acb->n * 512; - qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); + hd_iov.iov_base = (void *)acb->buf; + hd_iov.iov_len = n * 512; + qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); ret = bdrv_co_readv(bs->backing_hd, acb->sector_num, - acb->n, &acb->hd_qiov); + n, &hd_qiov); qemu_co_mutex_lock(&s->lock); if (ret < 0) { return -EIO; } } else { /* Note: in this case, no need to wait */ - memset(acb->buf, 0, 512 * acb->n); + memset(acb->buf, 0, 512 * n); goto redo; } - } else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) { + } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) { /* add AIO support for compressed blocks ? */ - if (decompress_cluster(bs, acb->cluster_offset) < 0) { + if (decompress_cluster(bs, cluster_offset) < 0) { return -EIO; } memcpy(acb->buf, - s->cluster_cache + index_in_cluster * 512, 512 * acb->n); + s->cluster_cache + index_in_cluster * 512, 512 * n); goto redo; } else { - if ((acb->cluster_offset & 511) != 0) { + if ((cluster_offset & 511) != 0) { return -EIO; } - acb->hd_iov.iov_base = (void *)acb->buf; - acb->hd_iov.iov_len = acb->n * 512; - qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); + hd_iov.iov_base = (void *)acb->buf; + hd_iov.iov_len = n * 512; + qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); ret = bdrv_co_readv(bs->file, - (acb->cluster_offset >> 9) + index_in_cluster, - acb->n, &acb->hd_qiov); + (cluster_offset >> 9) + index_in_cluster, + n, &hd_qiov); qemu_co_mutex_lock(&s->lock); if (ret < 0) { return ret; } } - return 1; + goto redo; } static int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, @@ -623,9 +613,7 @@ static int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 0, &acb); qemu_co_mutex_lock(&s->lock); - do { - ret = qcow_aio_read_cb(&acb); - } while (ret > 0); + ret = qcow_aio_read_cb(&acb); qemu_co_mutex_unlock(&s->lock); if (acb.qiov->niov > 1) { @@ -638,18 +626,20 @@ static int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, static int qcow_aio_write_cb(QCowAIOCB *acb) { - BlockDriverState *bs = acb->common.bs; + BlockDriverState *bs = acb->bs; BDRVQcowState *s = bs->opaque; int index_in_cluster; uint64_t cluster_offset; const uint8_t *src_buf; - int ret; - - acb->hd_aiocb = NULL; + int ret, n = 0; + uint8_t *cluster_data = NULL; + struct iovec hd_iov; + QEMUIOVector hd_qiov; - acb->nb_sectors -= acb->n; - acb->sector_num += acb->n; - acb->buf += acb->n * 512; +redo: + acb->nb_sectors -= n; + acb->sector_num += n; + acb->buf += n * 512; if (acb->nb_sectors == 0) { /* request completed */ @@ -657,38 +647,43 @@ static int qcow_aio_write_cb(QCowAIOCB *acb) } index_in_cluster = acb->sector_num & (s->cluster_sectors - 1); - acb->n = s->cluster_sectors - index_in_cluster; - if (acb->n > acb->nb_sectors) - acb->n = acb->nb_sectors; + n = s->cluster_sectors - index_in_cluster; + if (n > acb->nb_sectors) { + n = acb->nb_sectors; + } cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, 1, 0, index_in_cluster, - index_in_cluster + acb->n); + index_in_cluster + n); if (!cluster_offset || (cluster_offset & 511) != 0) { return -EIO; } if (s->crypt_method) { - if (!acb->cluster_data) { - acb->cluster_data = qemu_mallocz(s->cluster_size); + if (!cluster_data) { + cluster_data = qemu_mallocz(s->cluster_size); } - encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf, - acb->n, 1, &s->aes_encrypt_key); - src_buf = acb->cluster_data; + encrypt_sectors(s, acb->sector_num, cluster_data, acb->buf, + n, 1, &s->aes_encrypt_key); + src_buf = cluster_data; } else { src_buf = acb->buf; } - acb->hd_iov.iov_base = (void *)src_buf; - acb->hd_iov.iov_len = acb->n * 512; - qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); + hd_iov.iov_base = (void *)src_buf; + hd_iov.iov_len = n * 512; + qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); ret = bdrv_co_writev(bs->file, (cluster_offset >> 9) + index_in_cluster, - acb->n, &acb->hd_qiov); + n, &hd_qiov); + if (cluster_data) { + free(cluster_data); + cluster_data = NULL; + } qemu_co_mutex_lock(&s->lock); if (ret < 0) { return ret; } - return 1; + goto redo; } static int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, @@ -703,9 +698,7 @@ static int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 1, &acb); qemu_co_mutex_lock(&s->lock); - do { - ret = qcow_aio_write_cb(&acb); - } while (ret > 0); + ret = qcow_aio_write_cb(&acb); qemu_co_mutex_unlock(&s->lock); if (acb.qiov->niov > 1) {