On 09/02/2017 17:00, Eric Blake wrote: >> + if (!client->block_status_ok) { >> + *pnum = nb_sectors; >> + ret = BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED; >> + if (bs->drv->protocol_name) { This condition is always true, I think? >> + ret |= BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_SIZE); >> + } >> + return ret; >> + } > Looks like a sane fallback when we don't have anything more accurate. >> + >> + ret = nbd_client_co_cmd_block_status(bs, sector_num << BDRV_SECTOR_BITS, >> + nb_sectors << BDRV_SECTOR_BITS, >> + &extents, &nb_extents); >> + if (ret < 0) { >> + return ret; >> + } >> + >> + *pnum = extents[0].length >> BDRV_SECTOR_BITS; >> + ret = (extents[0].flags & NBD_STATE_HOLE ? 0 : BDRV_BLOCK_ALLOCATED) | >> + (extents[0].flags & NBD_STATE_ZERO ? BDRV_BLOCK_ZERO : 0); >> + >> + if ((ret & BDRV_BLOCK_ALLOCATED) && !(ret & BDRV_BLOCK_ZERO)) { >> + ret |= BDRV_BLOCK_DATA; >> + } You can always return BDRV_BLOCK_OFFSET_VALID here, too. Paolo