Revisiting an older thread: On 6/9/18 10:17 AM, Vladimir Sementsov-Ogievskiy wrote: > Handle new NBD meta namespace: "qemu", and corresponding queries: > "qemu:dirty-bitmap:". > > With new metadata context negotiated, BLOCK_STATUS query will reply > with dirty-bitmap data, converted to extents. New public function > nbd_export_bitmap selects bitmap to export. For now, only one bitmap > may be exported. > > Signed-off-by: Vladimir Sementsov-Ogievskiy > --- > @@ -2199,3 +2393,44 @@ void nbd_client_new(NBDExport *exp, > co = qemu_coroutine_create(nbd_co_client_start, client); > qemu_coroutine_enter(co); > } > + > +void nbd_export_bitmap(NBDExport *exp, const char *bitmap, > + const char *bitmap_export_name, Error **errp) > +{ > + BdrvDirtyBitmap *bm = NULL; > + BlockDriverState *bs = blk_bs(exp->blk); > + > + if (exp->export_bitmap) { > + error_setg(errp, "Export bitmap is already set"); > + return; > + } > + > + while (true) { > + bm = bdrv_find_dirty_bitmap(bs, bitmap); > + if (bm != NULL || bs->backing == NULL) { > + break; > + } > + > + bs = bs->backing->bs; > + } > + > + if (bm == NULL) { > + error_setg(errp, "Bitmap '%s' is not found", bitmap); > + return; > + } > + > + if (bdrv_dirty_bitmap_enabled(bm)) { > + error_setg(errp, "Bitmap '%s' is enabled", bitmap); > + return; > + } Why are we restricting things to only export disabled bitmaps? I can understand the argument that if the image being exported is read-only, then an enabled bitmap _that can be changed_ is probably a bad idea (it goes against the notion of the export being read only). But if we were to allow a writable access to an image, wouldn't we expect that writes be reflected into the bitmap, which means permitting an enabled bitmap? Furthermore, consider the scenario: backing [with bitmap b0] <- active If I request a bitmap add of b0 for an export of active, then it really shouldn't matter whether b0 is left enabled or disabled - the backing file is read-only, and so no changes will be made to bitmap b0. I stumbled into the latter scenario while testing my new 'qemu-nbd -B bitmap', but the problem appears anywhere that we have read-only access to an image, where we can't change the status of the bitmap from enabled to disabled (because the image is read-only) but where the bitmap shouldn't be changing anyways (because the image is read-only). > + > + if (bdrv_dirty_bitmap_qmp_locked(bm)) { > + error_setg(errp, "Bitmap '%s' is locked", bitmap); > + return; > + } > + > + bdrv_dirty_bitmap_set_qmp_locked(bm, true); Can we have an enabled-but-locked bitmap (one that we can't delete because some operation such as a writable NBD export is still using it, but one that is still being updated by active writes)? If so, then it may make sense to drop the restriction that an exported bitmap must be disabled. And even if it is not possible, I'd still like to loosen the restriction to require a disabled bitmap only if the image owning the bitmap is writable (making it easier to do read-only exports without having to first tweak the bitmap to be disabled). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org