From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZIqm-0005q7-S6 for qemu-devel@nongnu.org; Mon, 15 Aug 2016 10:26:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bZIqi-0000kV-Ke for qemu-devel@nongnu.org; Mon, 15 Aug 2016 10:26:47 -0400 References: <1469175475-15420-1-git-send-email-den@openvz.org> <1469175475-15420-5-git-send-email-den@openvz.org> <20160808134400.GC25992@noname.str.redhat.com> From: Pavel Butsykin Message-ID: <57B182F1.8080001@virtuozzo.com> Date: Mon, 15 Aug 2016 11:53:05 +0300 MIME-Version: 1.0 In-Reply-To: <20160808134400.GC25992@noname.str.redhat.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v7 04/16] qcow2: add qcow2_co_pwritev_compressed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , "Denis V. Lunev" Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Jeff Cody , Markus Armbruster , Eric Blake , John Snow , Stefan Hajnoczi On 08.08.2016 16:44, Kevin Wolf wrote: > Am 22.07.2016 um 10:17 hat Denis V. Lunev geschrieben: >> From: Pavel Butsykin >> >> Added implementation of the qcow2_co_pwritev_compressed function that >> will allow us to safely use compressed writes for the qcow2 from running >> VMs. >> >> 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 > >> /* XXX: put compressed sectors first, then all the cluster aligned >> tables to avoid losing bytes in alignment */ >> -static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, >> - const uint8_t *buf, int nb_sectors) >> +static coroutine_fn int >> +qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, >> + uint64_t bytes, QEMUIOVector *qiov) >> { >> BDRVQcow2State *s = bs->opaque; >> + QEMUIOVector hd_qiov; >> + struct iovec iov; >> z_stream strm; >> int ret, out_len; >> - uint8_t *out_buf; >> + uint8_t *buf, *out_buf; >> uint64_t cluster_offset; >> >> - if (nb_sectors == 0) { >> + if (bytes == 0) { >> /* align end of file to a sector boundary to ease reading with >> sector based I/Os */ >> cluster_offset = bdrv_getlength(bs->file->bs); >> return bdrv_truncate(bs->file->bs, cluster_offset); >> } >> >> - if (nb_sectors != s->cluster_sectors) { >> + if (bytes != s->cluster_size) { >> ret = -EINVAL; >> >> /* Zero-pad last write if image size is not cluster aligned */ >> - if (sector_num + nb_sectors == bs->total_sectors && >> - nb_sectors < s->cluster_sectors) { >> + if (offset + bytes == bs->total_sectors << BDRV_SECTOR_BITS && >> + bytes < s->cluster_size) >> + { >> uint8_t *pad_buf = qemu_blockalign(bs, s->cluster_size); >> memset(pad_buf, 0, s->cluster_size); >> - memcpy(pad_buf, buf, nb_sectors * BDRV_SECTOR_SIZE); >> - ret = qcow2_write_compressed(bs, sector_num, >> - pad_buf, s->cluster_sectors); >> + qemu_iovec_to_buf(qiov, 0, pad_buf, s->cluster_size); > > I think, bytes would be more exact than s->cluster_size here. Anyway, > shouldn't hurt because we stop at the end of the qiov anyway and its > size should match bytes. Yes, I can send follow-up patches. > >> + iov = (struct iovec) { >> + .iov_base = pad_buf, >> + .iov_len = s->cluster_size, >> + }; >> + qemu_iovec_init_external(&hd_qiov, &iov, 1); >> + ret = qcow2_co_pwritev_compressed(bs, offset, bytes, &hd_qiov); >> qemu_vfree(pad_buf); >> } >> return ret; >> } > > Kevin >