On Thu, 05/10 10:25, Stefan Hajnoczi wrote:
> On Wed, May 09, 2018 at 10:58:09PM +0800, Fam Zheng wrote:
> > +static int qcow2_co_copy_range_from(BlockDriverState *bs,
> > + BdrvChild *src, uint64_t src_offset,
> > + BdrvChild *dst, uint64_t dst_offset,
> > + uint64_t bytes, BdrvRequestFlags flags)
> > +{
> > + BDRVQcow2State *s = bs->opaque;
> > + int offset_in_cluster;
> > + int ret;
> > + unsigned int cur_bytes; /* number of bytes in current iteration */
> > + uint64_t cluster_offset = 0;
> > + BdrvChild *child = NULL;
> > +
> > + assert(!bs->encrypted);
> > + qemu_co_mutex_lock(&s->lock);
> > +
> > + while (bytes != 0) {
> > +
> > + /* prepare next request */
> > + cur_bytes = MIN(bytes, INT_MAX);
> > +
> > + ret = qcow2_get_cluster_offset(bs, src_offset, &cur_bytes,
> > &cluster_offset);
> > + if (ret < 0) {
> > + goto out;
> > + }
> > +
> > + offset_in_cluster = offset_into_cluster(s, src_offset);
> > +
> > + switch (ret) {
> > + case QCOW2_CLUSTER_UNALLOCATED:
> > + if (bs->backing) {
> > + child = bs->backing;
> > + } else {
> > + flags |= BDRV_REQ_ZERO_WRITE;
> > + }
> > + break;
>
> Do we need a special case if the backing file is shorter than this
> image?
Yes, we should take the BDRV_REQ_ZERO_WRITE path if the range is fully beyond
EOF, otherwise clip cur_bytes at the backing image offset.
Fam