On Mon, Dec 01, 2014 at 03:30:12PM -0500, John Snow wrote: > +/** > + * Return a dirty bitmap (if present), after validating > + * the device and bitmap names. Returns NULL on error, > + * including when the device and/or bitmap is not found. > + */ > +static BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *device, > + const char *name, > + Error **errp) > +{ > + BlockDriverState *bs; > + BdrvDirtyBitmap *bitmap; > + > + if (!device) { > + error_setg(errp, "Device cannot be NULL"); > + return NULL; > + } > + if (!name) { > + error_setg(errp, "Bitmap name cannot be NULL"); > + return NULL; > + } > + > + bs = bdrv_lookup_bs(device, NULL, errp); > + if (!bs) { > + return NULL; > + } > + > + bitmap = bdrv_find_dirty_bitmap(bs, name); > + if (!bitmap) { > + error_setg(errp, "Dirty bitmap not found: %s", name); > + return NULL; > + } > + > + return bitmap; > +}
qmp_block_dirty_bitmap_remove() in an earlier patch should use this instead of duplicating code. > + > /* New and old BlockDriverState structs for atomic group operations */ > > typedef struct BlkTransactionState BlkTransactionState; > @@ -1948,6 +1983,32 @@ void qmp_block_dirty_bitmap_remove(const char *device, > const char *name, > bdrv_release_dirty_bitmap(bs, bitmap); > } > > +void qmp_block_dirty_bitmap_enable(const char *device, const char *name, > + Error **errp) > +{ > + BdrvDirtyBitmap *bitmap; > + > + bitmap = block_dirty_bitmap_lookup(device, name, errp); > + if (!bitmap) { > + return; > + } > + > + bdrv_enable_dirty_bitmap(bitmap); > +} > + > +void qmp_block_dirty_bitmap_disable(const char *device, const char *name, > + Error **errp) > +{ > + BdrvDirtyBitmap *bitmap; > + > + bitmap = block_dirty_bitmap_lookup(device, name, errp); > + if (!bitmap) { > + return; > + } > + > + bdrv_disable_dirty_bitmap(bitmap); > +} The dirty bitmap is accessed during the BDS request processing code path and is owned by the BDS, so it should be protected by AioContext too.
pgp97fS9apUjs.pgp
Description: PGP signature