On 27.05.2016 20:45, Stefan Hajnoczi wrote:
On Sat, May 14, 2016 at 03:45:52PM +0300, Denis V. Lunev wrote:+ qemu_co_mutex_lock(&s->lock); + cluster_offset = get_cluster_offset(bs, sector_num << 9, 2, out_len, 0, 0); + qemu_co_mutex_unlock(&s->lock); + if (cluster_offset == 0) { + ret = -EIO; + goto fail; + } + cluster_offset &= s->cluster_offset_mask; + + iov = (struct iovec) { + .iov_base = out_buf, + .iov_len = out_len, + }; + qemu_iovec_init_external(&hd_qiov, &iov, 1); + ret = bdrv_co_pwritev(bs->file->bs, cluster_offset, out_len, &hd_qiov, 0);Not sure if this has the same race condition as the qcow2 patch. It seems that bdrv_getlength() is used to extend the file on a per-sector basis. That would mean compressed data is not packed inside sectors and no read-write-modify race condition exists, but I haven't fully audited get_cluster_offset().
The get_cluster_offset() also doesn't allow to do multiple compressed writes in a single cluster, because this function for all offsets within the cluster returns the same cluster_offset. So here we just can't write at offset in the cluster, only at the beginning of the cluster.
Stefan
