From patchwork Thu Jul 21 19:40:11 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: 9242413 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 11242602F0 for ; Thu, 21 Jul 2016 19:45:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC7E927BF7 for ; Thu, 21 Jul 2016 19:45:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF32F27DE0; Thu, 21 Jul 2016 19:45:24 +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 5CD6D27BF7 for ; Thu, 21 Jul 2016 19:45:24 +0000 (UTC) Received: from localhost ([::1]:43307 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQJuN-0006Wh-EV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jul 2016 15:45:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQJpf-0002La-N8 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 15:40:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQJpa-00011l-0i for qemu-devel@nongnu.org; Thu, 21 Jul 2016 15:40:30 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:4063 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQJpZ-0000zn-Jx for qemu-devel@nongnu.org; Thu, 21 Jul 2016 15:40:25 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u6KBAfvc027557; Wed, 20 Jul 2016 14:10:43 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 21 Jul 2016 22:40:11 +0300 Message-Id: <1469130019-18497-9-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1469130019-18497-1-git-send-email-den@openvz.org> References: <1469130019-18497-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 v6 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);