From patchwork Fri Jul 22 08:17:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 9243097 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C3EDB60756 for ; Fri, 22 Jul 2016 08:18:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B398B27FA2 for ; Fri, 22 Jul 2016 08:18:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7D9827FA4; Fri, 22 Jul 2016 08:18:45 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 127D827FA2 for ; Fri, 22 Jul 2016 08:18:44 +0000 (UTC) Received: from localhost ([::1]:45778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQVfP-0005vb-95 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Jul 2016 04:18:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQVep-0005sC-Gj for qemu-devel@nongnu.org; Fri, 22 Jul 2016 04:18:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQVel-0001rP-68 for qemu-devel@nongnu.org; Fri, 22 Jul 2016 04:18:06 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:28142 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQVek-0001qN-Ox for qemu-devel@nongnu.org; Fri, 22 Jul 2016 04:18:03 -0400 Received: from irbis.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u6L0IZxF024246; Thu, 21 Jul 2016 03:18:38 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 22 Jul 2016 11:17:47 +0300 Message-Id: <1469175475-15420-9-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1469175475-15420-1-git-send-email-den@openvz.org> References: <1469175475-15420-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v7 08/16] qcow: cleanup qcow_co_pwritev_compressed to avoid the recursion 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: Kevin Wolf , Pavel Butsykin , Jeff Cody , Markus Armbruster , Stefan Hajnoczi , den@openvz.org, John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Pavel Butsykin Now that the function uses a vector instead of a buffer, there is no need to use recursive code. Signed-off-by: Pavel Butsykin Reviewed-by: Stefan Hajnoczi Signed-off-by: Denis V. Lunev CC: Jeff Cody CC: Markus Armbruster CC: Eric Blake CC: John Snow CC: Stefan Hajnoczi CC: Kevin Wolf --- block/qcow.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index e1d335d..20d2e15 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -927,27 +927,17 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, uint8_t *buf, *out_buf; uint64_t cluster_offset; + buf = qemu_blockalign(bs, s->cluster_size); if (bytes != s->cluster_size) { - ret = -EINVAL; - - /* Zero-pad last write if image size is not cluster aligned */ - if (offset + bytes == bs->total_sectors << BDRV_SECTOR_BITS && - bytes < s->cluster_size) + if (bytes > s->cluster_size || + offset + bytes != bs->total_sectors << BDRV_SECTOR_BITS) { - uint8_t *pad_buf = qemu_blockalign(bs, s->cluster_size); - memset(pad_buf, 0, s->cluster_size); - qemu_iovec_to_buf(qiov, 0, pad_buf, s->cluster_size); - iov = (struct iovec) { - .iov_base = pad_buf, - .iov_len = s->cluster_size, - }; - qemu_iovec_init_external(&hd_qiov, &iov, 1); - ret = qcow_co_pwritev_compressed(bs, offset, bytes, &hd_qiov); - qemu_vfree(pad_buf); + qemu_vfree(buf); + return -EINVAL; } - return ret; + /* Zero-pad last write if image size is not cluster aligned */ + memset(buf + bytes, 0, s->cluster_size - bytes); } - buf = qemu_blockalign(bs, s->cluster_size); qemu_iovec_to_buf(qiov, 0, buf, qiov->size); out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);