2016-03-08 07:44:55 +03:00
|
|
|
/*
|
|
|
|
* Block Dirty Bitmap
|
|
|
|
*
|
2017-09-25 17:55:11 +03:00
|
|
|
* Copyright (c) 2016-2017 Red Hat. Inc
|
2016-03-08 07:44:55 +03:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2016-03-08 07:44:55 +03:00
|
|
|
#include "trace.h"
|
|
|
|
#include "block/block_int.h"
|
|
|
|
#include "block/blockjob.h"
|
2019-09-20 11:25:43 +03:00
|
|
|
#include "qemu/main-loop.h"
|
2016-03-08 07:44:55 +03:00
|
|
|
|
|
|
|
struct BdrvDirtyBitmap {
|
2019-09-16 17:19:09 +03:00
|
|
|
BlockDriverState *bs;
|
2017-09-25 17:55:26 +03:00
|
|
|
HBitmap *bitmap; /* Dirty bitmap implementation */
|
2019-03-12 19:05:48 +03:00
|
|
|
bool busy; /* Bitmap is busy, it can't be used via QMP */
|
2019-03-12 19:05:48 +03:00
|
|
|
BdrvDirtyBitmap *successor; /* Anonymous child, if any. */
|
2016-03-08 07:44:55 +03:00
|
|
|
char *name; /* Optional non-empty unique ID */
|
2017-09-25 17:55:13 +03:00
|
|
|
int64_t size; /* Size of the bitmap, in bytes */
|
2017-06-28 15:05:09 +03:00
|
|
|
bool disabled; /* Bitmap is disabled. It ignores all writes to
|
|
|
|
the device */
|
2016-10-14 00:58:21 +03:00
|
|
|
int active_iterators; /* How many iterators are active */
|
2017-06-28 15:05:10 +03:00
|
|
|
bool readonly; /* Bitmap is read-only. This field also
|
|
|
|
prevents the respective image from being
|
|
|
|
modified (i.e. blocks writes and discards).
|
|
|
|
Such operations must fail and both the image
|
|
|
|
and this bitmap must remain unchanged while
|
|
|
|
this flag is set. */
|
2017-06-28 15:05:17 +03:00
|
|
|
bool persistent; /* bitmap must be saved to owner disk image */
|
2019-03-12 19:05:49 +03:00
|
|
|
bool inconsistent; /* bitmap is persistent, but inconsistent.
|
|
|
|
It cannot be used at all in any way, except
|
|
|
|
a QMP user can remove it. */
|
2019-07-29 23:35:54 +03:00
|
|
|
bool skip_store; /* We are either migrating or deleting this
|
|
|
|
* bitmap; it should not be stored on the next
|
|
|
|
* inactivation. */
|
2016-03-08 07:44:55 +03:00
|
|
|
QLIST_ENTRY(BdrvDirtyBitmap) list;
|
|
|
|
};
|
|
|
|
|
2016-10-14 00:58:21 +03:00
|
|
|
struct BdrvDirtyBitmapIter {
|
|
|
|
HBitmapIter hbi;
|
|
|
|
BdrvDirtyBitmap *bitmap;
|
|
|
|
};
|
|
|
|
|
2017-06-05 15:39:03 +03:00
|
|
|
static inline void bdrv_dirty_bitmaps_lock(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
qemu_mutex_lock(&bs->dirty_bitmap_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bdrv_dirty_bitmaps_unlock(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
qemu_mutex_unlock(&bs->dirty_bitmap_mutex);
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:39:05 +03:00
|
|
|
void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2017-06-05 15:39:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2017-06-05 15:39:05 +03:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:39:03 +03:00
|
|
|
/* Called with BQL or dirty_bitmap lock taken. */
|
2016-03-08 07:44:55 +03:00
|
|
|
BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, const char *name)
|
|
|
|
{
|
|
|
|
BdrvDirtyBitmap *bm;
|
|
|
|
|
|
|
|
assert(name);
|
|
|
|
QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) {
|
|
|
|
if (bm->name && !strcmp(name, bm->name)) {
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:39:03 +03:00
|
|
|
/* Called with BQL taken. */
|
2016-03-08 07:44:55 +03:00
|
|
|
BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
|
|
|
|
uint32_t granularity,
|
|
|
|
const char *name,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
int64_t bitmap_size;
|
|
|
|
BdrvDirtyBitmap *bitmap;
|
|
|
|
|
2017-09-25 17:55:13 +03:00
|
|
|
assert(is_power_of_2(granularity) && granularity >= BDRV_SECTOR_SIZE);
|
2016-03-08 07:44:55 +03:00
|
|
|
|
2019-11-14 05:46:33 +03:00
|
|
|
if (name) {
|
|
|
|
if (bdrv_find_dirty_bitmap(bs, name)) {
|
|
|
|
error_setg(errp, "Bitmap already exists: %s", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (strlen(name) > BDRV_BITMAP_MAX_NAME_SIZE) {
|
|
|
|
error_setg(errp, "Bitmap name too long: %s", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
2017-09-25 17:55:13 +03:00
|
|
|
bitmap_size = bdrv_getlength(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
if (bitmap_size < 0) {
|
|
|
|
error_setg_errno(errp, -bitmap_size, "could not get length of device");
|
|
|
|
errno = -bitmap_size;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bitmap = g_new0(BdrvDirtyBitmap, 1);
|
2019-09-16 17:19:09 +03:00
|
|
|
bitmap->bs = bs;
|
2017-09-25 17:55:26 +03:00
|
|
|
bitmap->bitmap = hbitmap_alloc(bitmap_size, ctz32(granularity));
|
2016-03-08 07:44:55 +03:00
|
|
|
bitmap->size = bitmap_size;
|
|
|
|
bitmap->name = g_strdup(name);
|
|
|
|
bitmap->disabled = false;
|
2017-06-05 15:39:03 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
QLIST_INSERT_HEAD(&bs->dirty_bitmaps, bitmap, list);
|
2017-06-05 15:39:03 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2016-10-14 00:58:25 +03:00
|
|
|
int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2017-09-25 17:55:13 +03:00
|
|
|
return bitmap->size;
|
2016-10-14 00:58:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
|
|
|
return bitmap->name;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:39:03 +03:00
|
|
|
/* Called with BQL taken. */
|
2019-03-12 19:05:48 +03:00
|
|
|
bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
|
|
|
return bitmap->successor;
|
|
|
|
}
|
|
|
|
|
2019-03-12 19:05:49 +03:00
|
|
|
static bool bdrv_dirty_bitmap_busy(const BdrvDirtyBitmap *bitmap)
|
2019-03-12 19:05:48 +03:00
|
|
|
{
|
|
|
|
return bitmap->busy;
|
2018-10-29 23:23:16 +03:00
|
|
|
}
|
|
|
|
|
2019-03-12 19:05:48 +03:00
|
|
|
void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy)
|
2018-03-13 22:34:00 +03:00
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2019-03-12 19:05:48 +03:00
|
|
|
bitmap->busy = busy;
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2018-03-13 22:34:00 +03:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:39:03 +03:00
|
|
|
/* Called with BQL taken. */
|
2016-03-08 07:44:55 +03:00
|
|
|
bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
block/dirty-bitmap: change semantics of enabled predicate
Currently, the enabled predicate means something like:
"the QAPI status of the bitmap is ACTIVE."
After this patch, it should mean exclusively:
"This bitmap is recording guest writes, and is allowed to do so."
In many places, this is how this predicate was already used.
Internal usages of the bitmap QPI can call user_locked to find out if
the bitmap is in use by an operation.
To accommodate this, modify the create_successor routine to now
explicitly disable the parent bitmap at creation time.
Justifications:
1. bdrv_dirty_bitmap_status suffers no change from the lack of
1:1 parity with the new predicates because of the order in which
the predicates are checked. This is now only for compatibility.
2. bdrv_set_dirty() is unchanged: pre-patch, it was skipping bitmaps that were
disabled or had a successor, while post-patch it is only skipping bitmaps
that are disabled. To accommodate this, create_successor now ensures that
any bitmap with a successor is explicitly disabled.
3. qcow2_store_persistent_dirty_bitmaps: No functional change. This function
cares only about the literal enabled bit, and makes no effort to check if
the bitmap is in-use or not. After this patch there are still no ways to
produce an enabled bitmap with a successor.
4. block_dirty_bitmap_enable_prepare
block_dirty_bitmap_disable_prepare
init_dirty_bitmap_migration
nbd_export_new
These functions care about the literal enabled bit,
and already check user_locked separately.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20190223000614.13894-5-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
2019-03-12 19:05:48 +03:00
|
|
|
return !bitmap->disabled;
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
2019-03-12 19:05:48 +03:00
|
|
|
/**
|
|
|
|
* bdrv_dirty_bitmap_status: This API is now deprecated.
|
|
|
|
* Called with BQL taken.
|
|
|
|
*
|
|
|
|
* A BdrvDirtyBitmap can be in four possible user-visible states:
|
|
|
|
* (1) Active: successor is NULL, and disabled is false: full r/w mode
|
|
|
|
* (2) Disabled: successor is NULL, and disabled is true: qualified r/w mode,
|
|
|
|
* guest writes are dropped, but monitor writes are possible,
|
|
|
|
* through commands like merge and clear.
|
|
|
|
* (3) Frozen: successor is not NULL.
|
|
|
|
* A frozen bitmap cannot be renamed, deleted, cleared, set,
|
|
|
|
* enabled, merged to, etc. A frozen bitmap can only abdicate()
|
|
|
|
* or reclaim().
|
|
|
|
* In this state, the anonymous successor bitmap may be either
|
|
|
|
* Active and recording writes from the guest (e.g. backup jobs),
|
|
|
|
* or it can be Disabled and not recording writes.
|
|
|
|
* (4) Locked: Whether Active or Disabled, the user cannot modify this bitmap
|
|
|
|
* in any way from the monitor.
|
2019-03-12 19:05:49 +03:00
|
|
|
* (5) Inconsistent: This is a persistent bitmap whose "in use" bit is set, and
|
|
|
|
* is unusable by QEMU. It can be deleted to remove it from
|
|
|
|
* the qcow2.
|
2019-03-12 19:05:48 +03:00
|
|
|
*/
|
2016-03-08 07:44:55 +03:00
|
|
|
DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2019-03-12 19:05:49 +03:00
|
|
|
if (bdrv_dirty_bitmap_inconsistent(bitmap)) {
|
|
|
|
return DIRTY_BITMAP_STATUS_INCONSISTENT;
|
|
|
|
} else if (bdrv_dirty_bitmap_has_successor(bitmap)) {
|
2016-03-08 07:44:55 +03:00
|
|
|
return DIRTY_BITMAP_STATUS_FROZEN;
|
2019-03-12 19:05:48 +03:00
|
|
|
} else if (bdrv_dirty_bitmap_busy(bitmap)) {
|
2018-03-13 22:34:00 +03:00
|
|
|
return DIRTY_BITMAP_STATUS_LOCKED;
|
2016-03-08 07:44:55 +03:00
|
|
|
} else if (!bdrv_dirty_bitmap_enabled(bitmap)) {
|
|
|
|
return DIRTY_BITMAP_STATUS_DISABLED;
|
|
|
|
} else {
|
|
|
|
return DIRTY_BITMAP_STATUS_ACTIVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-12 19:05:48 +03:00
|
|
|
/* Called with BQL taken. */
|
|
|
|
static bool bdrv_dirty_bitmap_recording(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
|
|
|
return !bitmap->disabled || (bitmap->successor &&
|
|
|
|
!bitmap->successor->disabled);
|
|
|
|
}
|
|
|
|
|
2019-03-12 19:05:49 +03:00
|
|
|
int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
if ((flags & BDRV_BITMAP_BUSY) && bdrv_dirty_bitmap_busy(bitmap)) {
|
|
|
|
error_setg(errp, "Bitmap '%s' is currently in use by another"
|
|
|
|
" operation and cannot be used", bitmap->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & BDRV_BITMAP_RO) && bdrv_dirty_bitmap_readonly(bitmap)) {
|
|
|
|
error_setg(errp, "Bitmap '%s' is readonly and cannot be modified",
|
|
|
|
bitmap->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & BDRV_BITMAP_INCONSISTENT) &&
|
|
|
|
bdrv_dirty_bitmap_inconsistent(bitmap)) {
|
|
|
|
error_setg(errp, "Bitmap '%s' is inconsistent and cannot be used",
|
|
|
|
bitmap->name);
|
|
|
|
error_append_hint(errp, "Try block-dirty-bitmap-remove to delete"
|
|
|
|
" this bitmap from disk");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-08 07:44:55 +03:00
|
|
|
/**
|
|
|
|
* Create a successor bitmap destined to replace this bitmap after an operation.
|
2019-03-12 19:05:48 +03:00
|
|
|
* Requires that the bitmap is not marked busy and has no successor.
|
block/dirty-bitmap: change semantics of enabled predicate
Currently, the enabled predicate means something like:
"the QAPI status of the bitmap is ACTIVE."
After this patch, it should mean exclusively:
"This bitmap is recording guest writes, and is allowed to do so."
In many places, this is how this predicate was already used.
Internal usages of the bitmap QPI can call user_locked to find out if
the bitmap is in use by an operation.
To accommodate this, modify the create_successor routine to now
explicitly disable the parent bitmap at creation time.
Justifications:
1. bdrv_dirty_bitmap_status suffers no change from the lack of
1:1 parity with the new predicates because of the order in which
the predicates are checked. This is now only for compatibility.
2. bdrv_set_dirty() is unchanged: pre-patch, it was skipping bitmaps that were
disabled or had a successor, while post-patch it is only skipping bitmaps
that are disabled. To accommodate this, create_successor now ensures that
any bitmap with a successor is explicitly disabled.
3. qcow2_store_persistent_dirty_bitmaps: No functional change. This function
cares only about the literal enabled bit, and makes no effort to check if
the bitmap is in-use or not. After this patch there are still no ways to
produce an enabled bitmap with a successor.
4. block_dirty_bitmap_enable_prepare
block_dirty_bitmap_disable_prepare
init_dirty_bitmap_migration
nbd_export_new
These functions care about the literal enabled bit,
and already check user_locked separately.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20190223000614.13894-5-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
2019-03-12 19:05:48 +03:00
|
|
|
* The successor will be enabled if the parent bitmap was.
|
2017-06-05 15:39:03 +03:00
|
|
|
* Called with BQL taken.
|
2016-03-08 07:44:55 +03:00
|
|
|
*/
|
2019-09-16 17:19:09 +03:00
|
|
|
int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap, Error **errp)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
|
|
|
uint64_t granularity;
|
|
|
|
BdrvDirtyBitmap *child;
|
|
|
|
|
2019-03-12 19:05:49 +03:00
|
|
|
if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY, errp)) {
|
2019-03-12 19:05:48 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (bdrv_dirty_bitmap_has_successor(bitmap)) {
|
|
|
|
error_setg(errp, "Cannot create a successor for a bitmap that already "
|
|
|
|
"has one");
|
2016-03-08 07:44:55 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create an anonymous successor */
|
|
|
|
granularity = bdrv_dirty_bitmap_granularity(bitmap);
|
2019-09-16 17:19:09 +03:00
|
|
|
child = bdrv_create_dirty_bitmap(bitmap->bs, granularity, NULL, errp);
|
2016-03-08 07:44:55 +03:00
|
|
|
if (!child) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Successor will be on or off based on our current state. */
|
|
|
|
child->disabled = bitmap->disabled;
|
block/dirty-bitmap: change semantics of enabled predicate
Currently, the enabled predicate means something like:
"the QAPI status of the bitmap is ACTIVE."
After this patch, it should mean exclusively:
"This bitmap is recording guest writes, and is allowed to do so."
In many places, this is how this predicate was already used.
Internal usages of the bitmap QPI can call user_locked to find out if
the bitmap is in use by an operation.
To accommodate this, modify the create_successor routine to now
explicitly disable the parent bitmap at creation time.
Justifications:
1. bdrv_dirty_bitmap_status suffers no change from the lack of
1:1 parity with the new predicates because of the order in which
the predicates are checked. This is now only for compatibility.
2. bdrv_set_dirty() is unchanged: pre-patch, it was skipping bitmaps that were
disabled or had a successor, while post-patch it is only skipping bitmaps
that are disabled. To accommodate this, create_successor now ensures that
any bitmap with a successor is explicitly disabled.
3. qcow2_store_persistent_dirty_bitmaps: No functional change. This function
cares only about the literal enabled bit, and makes no effort to check if
the bitmap is in-use or not. After this patch there are still no ways to
produce an enabled bitmap with a successor.
4. block_dirty_bitmap_enable_prepare
block_dirty_bitmap_disable_prepare
init_dirty_bitmap_migration
nbd_export_new
These functions care about the literal enabled bit,
and already check user_locked separately.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20190223000614.13894-5-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
2019-03-12 19:05:48 +03:00
|
|
|
bitmap->disabled = true;
|
2016-03-08 07:44:55 +03:00
|
|
|
|
2019-03-12 19:05:48 +03:00
|
|
|
/* Install the successor and mark the parent as busy */
|
2016-03-08 07:44:55 +03:00
|
|
|
bitmap->successor = child;
|
2019-03-12 19:05:48 +03:00
|
|
|
bitmap->busy = true;
|
2016-03-08 07:44:55 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-04 09:12:49 +03:00
|
|
|
void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
|
|
|
bitmap->disabled = false;
|
|
|
|
}
|
|
|
|
|
2018-03-13 22:33:59 +03:00
|
|
|
/* Called with BQL taken. */
|
|
|
|
void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
assert(bitmap->bs == bitmap->successor->bs);
|
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2018-07-04 09:12:49 +03:00
|
|
|
bdrv_enable_dirty_bitmap_locked(bitmap->successor);
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2018-03-13 22:33:59 +03:00
|
|
|
}
|
|
|
|
|
2018-06-11 21:53:31 +03:00
|
|
|
/* Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken. */
|
|
|
|
static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
|
2018-03-13 22:34:00 +03:00
|
|
|
{
|
2018-06-11 21:53:31 +03:00
|
|
|
assert(!bitmap->active_iterators);
|
2019-03-12 19:05:48 +03:00
|
|
|
assert(!bdrv_dirty_bitmap_busy(bitmap));
|
2019-03-12 19:05:48 +03:00
|
|
|
assert(!bdrv_dirty_bitmap_has_successor(bitmap));
|
2018-06-11 21:53:31 +03:00
|
|
|
QLIST_REMOVE(bitmap, list);
|
|
|
|
hbitmap_free(bitmap->bitmap);
|
|
|
|
g_free(bitmap->name);
|
|
|
|
g_free(bitmap);
|
2018-03-13 22:34:00 +03:00
|
|
|
}
|
|
|
|
|
2016-03-08 07:44:55 +03:00
|
|
|
/**
|
|
|
|
* For a bitmap with a successor, yield our name to the successor,
|
|
|
|
* delete the old bitmap, and return a handle to the new bitmap.
|
2017-06-05 15:39:03 +03:00
|
|
|
* Called with BQL taken.
|
2016-03-08 07:44:55 +03:00
|
|
|
*/
|
2019-09-16 17:19:09 +03:00
|
|
|
BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap,
|
2016-03-08 07:44:55 +03:00
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
BdrvDirtyBitmap *successor = bitmap->successor;
|
|
|
|
|
|
|
|
if (successor == NULL) {
|
|
|
|
error_setg(errp, "Cannot relinquish control if "
|
|
|
|
"there's no successor present");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = bitmap->name;
|
|
|
|
bitmap->name = NULL;
|
|
|
|
successor->name = name;
|
|
|
|
bitmap->successor = NULL;
|
2017-06-28 15:05:17 +03:00
|
|
|
successor->persistent = bitmap->persistent;
|
|
|
|
bitmap->persistent = false;
|
2019-03-12 19:05:48 +03:00
|
|
|
bitmap->busy = false;
|
2019-09-16 17:19:09 +03:00
|
|
|
bdrv_release_dirty_bitmap(bitmap);
|
2016-03-08 07:44:55 +03:00
|
|
|
|
|
|
|
return successor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In cases of failure where we can no longer safely delete the parent,
|
|
|
|
* we may wish to re-join the parent and child/successor.
|
2019-03-12 19:05:48 +03:00
|
|
|
* The merged parent will be marked as not busy.
|
block/dirty-bitmap: change semantics of enabled predicate
Currently, the enabled predicate means something like:
"the QAPI status of the bitmap is ACTIVE."
After this patch, it should mean exclusively:
"This bitmap is recording guest writes, and is allowed to do so."
In many places, this is how this predicate was already used.
Internal usages of the bitmap QPI can call user_locked to find out if
the bitmap is in use by an operation.
To accommodate this, modify the create_successor routine to now
explicitly disable the parent bitmap at creation time.
Justifications:
1. bdrv_dirty_bitmap_status suffers no change from the lack of
1:1 parity with the new predicates because of the order in which
the predicates are checked. This is now only for compatibility.
2. bdrv_set_dirty() is unchanged: pre-patch, it was skipping bitmaps that were
disabled or had a successor, while post-patch it is only skipping bitmaps
that are disabled. To accommodate this, create_successor now ensures that
any bitmap with a successor is explicitly disabled.
3. qcow2_store_persistent_dirty_bitmaps: No functional change. This function
cares only about the literal enabled bit, and makes no effort to check if
the bitmap is in-use or not. After this patch there are still no ways to
produce an enabled bitmap with a successor.
4. block_dirty_bitmap_enable_prepare
block_dirty_bitmap_disable_prepare
init_dirty_bitmap_migration
nbd_export_new
These functions care about the literal enabled bit,
and already check user_locked separately.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20190223000614.13894-5-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
2019-03-12 19:05:48 +03:00
|
|
|
* The marged parent will be enabled if and only if the successor was enabled.
|
2018-03-13 22:34:00 +03:00
|
|
|
* Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken.
|
2016-03-08 07:44:55 +03:00
|
|
|
*/
|
2019-09-16 17:19:09 +03:00
|
|
|
BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *parent,
|
2018-03-13 22:34:00 +03:00
|
|
|
Error **errp)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
2018-03-13 22:34:00 +03:00
|
|
|
BdrvDirtyBitmap *successor = parent->successor;
|
2016-03-08 07:44:55 +03:00
|
|
|
|
|
|
|
if (!successor) {
|
|
|
|
error_setg(errp, "Cannot reclaim a successor when none is present");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-29 23:23:15 +03:00
|
|
|
if (!hbitmap_merge(parent->bitmap, successor->bitmap, parent->bitmap)) {
|
2016-03-08 07:44:55 +03:00
|
|
|
error_setg(errp, "Merging of parent and successor bitmap failed");
|
|
|
|
return NULL;
|
|
|
|
}
|
block/dirty-bitmap: change semantics of enabled predicate
Currently, the enabled predicate means something like:
"the QAPI status of the bitmap is ACTIVE."
After this patch, it should mean exclusively:
"This bitmap is recording guest writes, and is allowed to do so."
In many places, this is how this predicate was already used.
Internal usages of the bitmap QPI can call user_locked to find out if
the bitmap is in use by an operation.
To accommodate this, modify the create_successor routine to now
explicitly disable the parent bitmap at creation time.
Justifications:
1. bdrv_dirty_bitmap_status suffers no change from the lack of
1:1 parity with the new predicates because of the order in which
the predicates are checked. This is now only for compatibility.
2. bdrv_set_dirty() is unchanged: pre-patch, it was skipping bitmaps that were
disabled or had a successor, while post-patch it is only skipping bitmaps
that are disabled. To accommodate this, create_successor now ensures that
any bitmap with a successor is explicitly disabled.
3. qcow2_store_persistent_dirty_bitmaps: No functional change. This function
cares only about the literal enabled bit, and makes no effort to check if
the bitmap is in-use or not. After this patch there are still no ways to
produce an enabled bitmap with a successor.
4. block_dirty_bitmap_enable_prepare
block_dirty_bitmap_disable_prepare
init_dirty_bitmap_migration
nbd_export_new
These functions care about the literal enabled bit,
and already check user_locked separately.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20190223000614.13894-5-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
2019-03-12 19:05:48 +03:00
|
|
|
|
|
|
|
parent->disabled = successor->disabled;
|
2019-03-12 19:05:48 +03:00
|
|
|
parent->busy = false;
|
2018-06-11 21:53:31 +03:00
|
|
|
bdrv_release_dirty_bitmap_locked(successor);
|
2016-03-08 07:44:55 +03:00
|
|
|
parent->successor = NULL;
|
|
|
|
|
2018-03-13 22:34:00 +03:00
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called with BQL taken. */
|
2019-09-16 17:19:09 +03:00
|
|
|
BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *parent,
|
2018-03-13 22:34:00 +03:00
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
BdrvDirtyBitmap *ret;
|
|
|
|
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(parent->bs);
|
2019-09-16 17:19:09 +03:00
|
|
|
ret = bdrv_reclaim_dirty_bitmap_locked(parent, errp);
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(parent->bs);
|
2018-03-13 22:34:00 +03:00
|
|
|
|
2018-03-13 22:34:00 +03:00
|
|
|
return ret;
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Truncates _all_ bitmaps attached to a BDS.
|
2017-06-05 15:39:03 +03:00
|
|
|
* Called with BQL taken.
|
2016-03-08 07:44:55 +03:00
|
|
|
*/
|
2017-09-25 17:55:11 +03:00
|
|
|
void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
|
|
|
BdrvDirtyBitmap *bitmap;
|
|
|
|
|
2017-06-05 15:39:03 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
|
2019-03-12 19:05:48 +03:00
|
|
|
assert(!bdrv_dirty_bitmap_busy(bitmap));
|
2019-03-12 19:05:48 +03:00
|
|
|
assert(!bdrv_dirty_bitmap_has_successor(bitmap));
|
2016-10-14 00:58:21 +03:00
|
|
|
assert(!bitmap->active_iterators);
|
2017-09-25 17:55:26 +03:00
|
|
|
hbitmap_truncate(bitmap->bitmap, bytes);
|
2017-09-25 17:55:13 +03:00
|
|
|
bitmap->size = bytes;
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
2017-06-05 15:39:03 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:39:03 +03:00
|
|
|
/* Called with BQL taken. */
|
2019-09-16 17:19:09 +03:00
|
|
|
void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
2019-09-16 17:19:09 +03:00
|
|
|
BlockDriverState *bs = bitmap->bs;
|
|
|
|
|
2018-06-11 21:53:31 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bs);
|
|
|
|
bdrv_release_dirty_bitmap_locked(bitmap);
|
|
|
|
bdrv_dirty_bitmaps_unlock(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release all named dirty bitmaps attached to a BDS (for use in bdrv_close()).
|
2019-03-12 19:05:48 +03:00
|
|
|
* There must not be any busy bitmaps attached.
|
2017-06-28 15:05:27 +03:00
|
|
|
* This function does not remove persistent bitmaps from the storage.
|
2017-06-05 15:39:03 +03:00
|
|
|
* Called with BQL taken.
|
2016-03-08 07:44:55 +03:00
|
|
|
*/
|
|
|
|
void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs)
|
|
|
|
{
|
2018-06-11 21:53:31 +03:00
|
|
|
BdrvDirtyBitmap *bm, *next;
|
|
|
|
|
|
|
|
bdrv_dirty_bitmaps_lock(bs);
|
|
|
|
QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
|
|
|
|
if (bdrv_dirty_bitmap_name(bm)) {
|
|
|
|
bdrv_release_dirty_bitmap_locked(bm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bdrv_dirty_bitmaps_unlock(bs);
|
2017-06-28 15:05:30 +03:00
|
|
|
}
|
|
|
|
|
2017-06-28 15:05:27 +03:00
|
|
|
/**
|
|
|
|
* Remove persistent dirty bitmap from the storage if it exists.
|
|
|
|
* Absence of bitmap is not an error, because we have the following scenario:
|
|
|
|
* BdrvDirtyBitmap can have .persistent = true but not yet saved and have no
|
|
|
|
* stored version. For such bitmap bdrv_remove_persistent_dirty_bitmap() should
|
|
|
|
* not fail.
|
|
|
|
* This function doesn't release corresponding BdrvDirtyBitmap.
|
|
|
|
*/
|
2019-09-20 11:25:43 +03:00
|
|
|
static int coroutine_fn
|
|
|
|
bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name,
|
|
|
|
Error **errp)
|
2017-06-28 15:05:27 +03:00
|
|
|
{
|
2019-09-20 11:25:43 +03:00
|
|
|
if (bs->drv && bs->drv->bdrv_co_remove_persistent_dirty_bitmap) {
|
|
|
|
return bs->drv->bdrv_co_remove_persistent_dirty_bitmap(bs, name, errp);
|
2017-06-28 15:05:27 +03:00
|
|
|
}
|
2019-09-20 11:25:42 +03:00
|
|
|
|
|
|
|
return 0;
|
2017-06-28 15:05:27 +03:00
|
|
|
}
|
|
|
|
|
2019-09-20 11:25:43 +03:00
|
|
|
typedef struct BdrvRemovePersistentDirtyBitmapCo {
|
|
|
|
BlockDriverState *bs;
|
|
|
|
const char *name;
|
|
|
|
Error **errp;
|
|
|
|
int ret;
|
|
|
|
} BdrvRemovePersistentDirtyBitmapCo;
|
|
|
|
|
|
|
|
static void coroutine_fn
|
|
|
|
bdrv_co_remove_persistent_dirty_bitmap_entry(void *opaque)
|
|
|
|
{
|
|
|
|
BdrvRemovePersistentDirtyBitmapCo *s = opaque;
|
|
|
|
|
|
|
|
s->ret = bdrv_co_remove_persistent_dirty_bitmap(s->bs, s->name, s->errp);
|
|
|
|
aio_wait_kick();
|
|
|
|
}
|
|
|
|
|
|
|
|
int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
if (qemu_in_coroutine()) {
|
|
|
|
return bdrv_co_remove_persistent_dirty_bitmap(bs, name, errp);
|
|
|
|
} else {
|
|
|
|
Coroutine *co;
|
|
|
|
BdrvRemovePersistentDirtyBitmapCo s = {
|
|
|
|
.bs = bs,
|
|
|
|
.name = name,
|
|
|
|
.errp = errp,
|
|
|
|
.ret = -EINPROGRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
co = qemu_coroutine_create(bdrv_co_remove_persistent_dirty_bitmap_entry,
|
|
|
|
&s);
|
|
|
|
bdrv_coroutine_enter(bs, co);
|
|
|
|
BDRV_POLL_WHILE(bs, s.ret == -EINPROGRESS);
|
|
|
|
|
|
|
|
return s.ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool coroutine_fn
|
|
|
|
bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name,
|
|
|
|
uint32_t granularity, Error **errp)
|
2019-09-20 11:25:41 +03:00
|
|
|
{
|
|
|
|
BlockDriver *drv = bs->drv;
|
|
|
|
|
|
|
|
if (!drv) {
|
|
|
|
error_setg_errno(errp, ENOMEDIUM,
|
|
|
|
"Can't store persistent bitmaps to %s",
|
|
|
|
bdrv_get_device_or_node_name(bs));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-20 11:25:43 +03:00
|
|
|
if (!drv->bdrv_co_can_store_new_dirty_bitmap) {
|
2019-09-20 11:25:41 +03:00
|
|
|
error_setg_errno(errp, ENOTSUP,
|
|
|
|
"Can't store persistent bitmaps to %s",
|
|
|
|
bdrv_get_device_or_node_name(bs));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-20 11:25:43 +03:00
|
|
|
return drv->bdrv_co_can_store_new_dirty_bitmap(bs, name, granularity, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct BdrvCanStoreNewDirtyBitmapCo {
|
|
|
|
BlockDriverState *bs;
|
|
|
|
const char *name;
|
|
|
|
uint32_t granularity;
|
|
|
|
Error **errp;
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
bool in_progress;
|
|
|
|
} BdrvCanStoreNewDirtyBitmapCo;
|
|
|
|
|
|
|
|
static void coroutine_fn bdrv_co_can_store_new_dirty_bitmap_entry(void *opaque)
|
|
|
|
{
|
|
|
|
BdrvCanStoreNewDirtyBitmapCo *s = opaque;
|
|
|
|
|
|
|
|
s->ret = bdrv_co_can_store_new_dirty_bitmap(s->bs, s->name, s->granularity,
|
|
|
|
s->errp);
|
|
|
|
s->in_progress = false;
|
|
|
|
aio_wait_kick();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name,
|
|
|
|
uint32_t granularity, Error **errp)
|
|
|
|
{
|
|
|
|
if (qemu_in_coroutine()) {
|
|
|
|
return bdrv_co_can_store_new_dirty_bitmap(bs, name, granularity, errp);
|
|
|
|
} else {
|
|
|
|
Coroutine *co;
|
|
|
|
BdrvCanStoreNewDirtyBitmapCo s = {
|
|
|
|
.bs = bs,
|
|
|
|
.name = name,
|
|
|
|
.granularity = granularity,
|
|
|
|
.errp = errp,
|
|
|
|
.in_progress = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
co = qemu_coroutine_create(bdrv_co_can_store_new_dirty_bitmap_entry,
|
|
|
|
&s);
|
|
|
|
bdrv_coroutine_enter(bs, co);
|
|
|
|
BDRV_POLL_WHILE(bs, s.in_progress);
|
|
|
|
|
|
|
|
return s.ret;
|
|
|
|
}
|
2019-09-20 11:25:41 +03:00
|
|
|
}
|
|
|
|
|
2016-03-08 07:44:55 +03:00
|
|
|
void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
bitmap->disabled = true;
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2018-07-04 09:12:49 +03:00
|
|
|
bdrv_enable_dirty_bitmap_locked(bitmap);
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
BdrvDirtyBitmap *bm;
|
|
|
|
BlockDirtyInfoList *list = NULL;
|
|
|
|
BlockDirtyInfoList **plist = &list;
|
|
|
|
|
2017-06-05 15:39:03 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) {
|
|
|
|
BlockDirtyInfo *info = g_new0(BlockDirtyInfo, 1);
|
|
|
|
BlockDirtyInfoList *entry = g_new0(BlockDirtyInfoList, 1);
|
2017-09-25 17:55:18 +03:00
|
|
|
info->count = bdrv_get_dirty_count(bm);
|
2016-03-08 07:44:55 +03:00
|
|
|
info->granularity = bdrv_dirty_bitmap_granularity(bm);
|
|
|
|
info->has_name = !!bm->name;
|
|
|
|
info->name = g_strdup(bm->name);
|
|
|
|
info->status = bdrv_dirty_bitmap_status(bm);
|
2019-03-12 19:05:48 +03:00
|
|
|
info->recording = bdrv_dirty_bitmap_recording(bm);
|
2019-03-12 19:05:48 +03:00
|
|
|
info->busy = bdrv_dirty_bitmap_busy(bm);
|
2019-02-20 01:49:43 +03:00
|
|
|
info->persistent = bm->persistent;
|
2019-03-12 19:05:49 +03:00
|
|
|
info->has_inconsistent = bm->inconsistent;
|
|
|
|
info->inconsistent = bm->inconsistent;
|
2016-03-08 07:44:55 +03:00
|
|
|
entry->value = info;
|
|
|
|
*plist = entry;
|
|
|
|
plist = &entry->next;
|
|
|
|
}
|
2017-06-05 15:39:03 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:39:05 +03:00
|
|
|
/* Called within bdrv_dirty_bitmap_lock..unlock */
|
2019-07-29 23:35:53 +03:00
|
|
|
bool bdrv_dirty_bitmap_get_locked(BdrvDirtyBitmap *bitmap, int64_t offset)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
2019-07-29 23:35:53 +03:00
|
|
|
return hbitmap_get(bitmap->bitmap, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bdrv_dirty_bitmap_get(BdrvDirtyBitmap *bitmap, int64_t offset)
|
|
|
|
{
|
|
|
|
bool ret;
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2019-07-29 23:35:53 +03:00
|
|
|
ret = bdrv_dirty_bitmap_get_locked(bitmap, offset);
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2019-07-29 23:35:53 +03:00
|
|
|
|
|
|
|
return ret;
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Chooses a default granularity based on the existing cluster size,
|
|
|
|
* but clamped between [4K, 64K]. Defaults to 64K in the case that there
|
|
|
|
* is no cluster size information available.
|
|
|
|
*/
|
|
|
|
uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
BlockDriverInfo bdi;
|
|
|
|
uint32_t granularity;
|
|
|
|
|
|
|
|
if (bdrv_get_info(bs, &bdi) >= 0 && bdi.cluster_size > 0) {
|
|
|
|
granularity = MAX(4096, bdi.cluster_size);
|
|
|
|
granularity = MIN(65536, granularity);
|
|
|
|
} else {
|
|
|
|
granularity = 65536;
|
|
|
|
}
|
|
|
|
|
|
|
|
return granularity;
|
|
|
|
}
|
|
|
|
|
2017-06-28 15:05:05 +03:00
|
|
|
uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
2017-09-25 17:55:26 +03:00
|
|
|
return 1U << hbitmap_granularity(bitmap->bitmap);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
2017-09-25 17:55:16 +03:00
|
|
|
BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap)
|
2016-10-14 00:58:21 +03:00
|
|
|
{
|
|
|
|
BdrvDirtyBitmapIter *iter = g_new(BdrvDirtyBitmapIter, 1);
|
2017-09-25 17:55:16 +03:00
|
|
|
hbitmap_iter_init(&iter->hbi, bitmap->bitmap, 0);
|
2016-10-14 00:58:21 +03:00
|
|
|
iter->bitmap = bitmap;
|
|
|
|
bitmap->active_iterators++;
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter)
|
|
|
|
{
|
|
|
|
if (!iter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(iter->bitmap->active_iterators > 0);
|
|
|
|
iter->bitmap->active_iterators--;
|
|
|
|
g_free(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
2019-01-16 02:26:50 +03:00
|
|
|
return hbitmap_iter_next(&iter->hbi);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:39:05 +03:00
|
|
|
/* Called within bdrv_dirty_bitmap_lock..unlock */
|
|
|
|
void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
|
2017-09-25 17:55:20 +03:00
|
|
|
int64_t offset, int64_t bytes)
|
2017-06-05 15:39:05 +03:00
|
|
|
{
|
2017-06-28 15:05:10 +03:00
|
|
|
assert(!bdrv_dirty_bitmap_readonly(bitmap));
|
2017-09-25 17:55:26 +03:00
|
|
|
hbitmap_set(bitmap->bitmap, offset, bytes);
|
2017-06-05 15:39:05 +03:00
|
|
|
}
|
|
|
|
|
2016-03-08 07:44:55 +03:00
|
|
|
void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap,
|
2017-09-25 17:55:20 +03:00
|
|
|
int64_t offset, int64_t bytes)
|
2017-06-05 15:39:05 +03:00
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2017-09-25 17:55:20 +03:00
|
|
|
bdrv_set_dirty_bitmap_locked(bitmap, offset, bytes);
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2017-06-05 15:39:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Called within bdrv_dirty_bitmap_lock..unlock */
|
|
|
|
void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
|
2017-09-25 17:55:20 +03:00
|
|
|
int64_t offset, int64_t bytes)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
2017-06-28 15:05:10 +03:00
|
|
|
assert(!bdrv_dirty_bitmap_readonly(bitmap));
|
2017-09-25 17:55:26 +03:00
|
|
|
hbitmap_reset(bitmap->bitmap, offset, bytes);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap,
|
2017-09-25 17:55:20 +03:00
|
|
|
int64_t offset, int64_t bytes)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2017-09-25 17:55:20 +03:00
|
|
|
bdrv_reset_dirty_bitmap_locked(bitmap, offset, bytes);
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out)
|
|
|
|
{
|
2017-06-28 15:05:10 +03:00
|
|
|
assert(!bdrv_dirty_bitmap_readonly(bitmap));
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
if (!out) {
|
|
|
|
hbitmap_reset_all(bitmap->bitmap);
|
|
|
|
} else {
|
|
|
|
HBitmap *backup = bitmap->bitmap;
|
2017-09-25 17:55:26 +03:00
|
|
|
bitmap->bitmap = hbitmap_alloc(bitmap->size,
|
2016-03-08 07:44:55 +03:00
|
|
|
hbitmap_granularity(backup));
|
|
|
|
*out = backup;
|
|
|
|
}
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
2018-10-29 23:23:14 +03:00
|
|
|
void bdrv_restore_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *backup)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
|
|
|
HBitmap *tmp = bitmap->bitmap;
|
2017-06-28 15:05:10 +03:00
|
|
|
assert(!bdrv_dirty_bitmap_readonly(bitmap));
|
2018-10-29 23:23:14 +03:00
|
|
|
bitmap->bitmap = backup;
|
2016-03-08 07:44:55 +03:00
|
|
|
hbitmap_free(tmp);
|
|
|
|
}
|
|
|
|
|
2016-10-14 00:58:28 +03:00
|
|
|
uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap,
|
2017-09-25 17:55:14 +03:00
|
|
|
uint64_t offset, uint64_t bytes)
|
2016-10-14 00:58:28 +03:00
|
|
|
{
|
2017-09-25 17:55:26 +03:00
|
|
|
return hbitmap_serialization_size(bitmap->bitmap, offset, bytes);
|
2016-10-14 00:58:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2017-09-25 17:55:26 +03:00
|
|
|
return hbitmap_serialization_align(bitmap->bitmap);
|
2016-10-14 00:58:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
|
2017-09-25 17:55:14 +03:00
|
|
|
uint8_t *buf, uint64_t offset,
|
|
|
|
uint64_t bytes)
|
2016-10-14 00:58:28 +03:00
|
|
|
{
|
2017-09-25 17:55:26 +03:00
|
|
|
hbitmap_serialize_part(bitmap->bitmap, buf, offset, bytes);
|
2016-10-14 00:58:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap,
|
2017-09-25 17:55:14 +03:00
|
|
|
uint8_t *buf, uint64_t offset,
|
|
|
|
uint64_t bytes, bool finish)
|
2016-10-14 00:58:28 +03:00
|
|
|
{
|
2017-09-25 17:55:26 +03:00
|
|
|
hbitmap_deserialize_part(bitmap->bitmap, buf, offset, bytes, finish);
|
2016-10-14 00:58:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap,
|
2017-09-25 17:55:14 +03:00
|
|
|
uint64_t offset, uint64_t bytes,
|
2016-10-14 00:58:28 +03:00
|
|
|
bool finish)
|
|
|
|
{
|
2017-09-25 17:55:26 +03:00
|
|
|
hbitmap_deserialize_zeroes(bitmap->bitmap, offset, bytes, finish);
|
2017-06-28 15:05:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap,
|
2017-09-25 17:55:14 +03:00
|
|
|
uint64_t offset, uint64_t bytes,
|
2017-06-28 15:05:06 +03:00
|
|
|
bool finish)
|
|
|
|
{
|
2017-09-25 17:55:26 +03:00
|
|
|
hbitmap_deserialize_ones(bitmap->bitmap, offset, bytes, finish);
|
2016-10-14 00:58:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
|
|
|
hbitmap_deserialize_finish(bitmap->bitmap);
|
|
|
|
}
|
|
|
|
|
2017-09-25 17:55:25 +03:00
|
|
|
void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
|
|
|
BdrvDirtyBitmap *bitmap;
|
2017-06-05 15:39:03 +03:00
|
|
|
|
|
|
|
if (QLIST_EMPTY(&bs->dirty_bitmaps)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bdrv_dirty_bitmaps_lock(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
|
|
|
|
if (!bdrv_dirty_bitmap_enabled(bitmap)) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-28 15:05:10 +03:00
|
|
|
assert(!bdrv_dirty_bitmap_readonly(bitmap));
|
2017-09-25 17:55:26 +03:00
|
|
|
hbitmap_set(bitmap->bitmap, offset, bytes);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
2017-06-05 15:39:03 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bs);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-14 00:58:21 +03:00
|
|
|
* Advance a BdrvDirtyBitmapIter to an arbitrary offset.
|
2016-03-08 07:44:55 +03:00
|
|
|
*/
|
2017-09-25 17:55:16 +03:00
|
|
|
void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *iter, int64_t offset)
|
2016-03-08 07:44:55 +03:00
|
|
|
{
|
2017-09-25 17:55:26 +03:00
|
|
|
hbitmap_iter_init(&iter->hbi, iter->hbi.hb, offset);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2017-09-25 17:55:26 +03:00
|
|
|
return hbitmap_count(bitmap->bitmap);
|
2016-03-08 07:44:55 +03:00
|
|
|
}
|
2016-10-14 00:58:30 +03:00
|
|
|
|
2017-06-28 15:05:10 +03:00
|
|
|
bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
|
|
|
return bitmap->readonly;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called with BQL taken. */
|
|
|
|
void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value)
|
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2017-06-28 15:05:10 +03:00
|
|
|
bitmap->readonly = value;
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2017-06-28 15:05:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool bdrv_has_readonly_bitmaps(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
BdrvDirtyBitmap *bm;
|
|
|
|
QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) {
|
|
|
|
if (bm->readonly) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-28 15:05:15 +03:00
|
|
|
|
2017-06-28 15:05:17 +03:00
|
|
|
/* Called with BQL taken. */
|
2019-03-12 19:05:49 +03:00
|
|
|
void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap, bool persistent)
|
2017-06-28 15:05:17 +03:00
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2017-06-28 15:05:17 +03:00
|
|
|
bitmap->persistent = persistent;
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2017-06-28 15:05:17 +03:00
|
|
|
}
|
|
|
|
|
2019-03-12 19:05:49 +03:00
|
|
|
/* Called with BQL taken. */
|
|
|
|
void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2019-03-12 19:05:49 +03:00
|
|
|
assert(bitmap->persistent == true);
|
|
|
|
bitmap->inconsistent = true;
|
|
|
|
bitmap->disabled = true;
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
2019-03-12 19:05:49 +03:00
|
|
|
}
|
|
|
|
|
dirty-bitmaps: clean-up bitmaps loading and migration logic
This patch aims to bring the following behavior:
1. We don't load bitmaps, when started in inactive mode. It's the case
of incoming migration. In this case we wait for bitmaps migration
through migration channel (if 'dirty-bitmaps' capability is enabled) or
for invalidation (to load bitmaps from the image).
2. We don't remove persistent bitmaps on inactivation. Instead, we only
remove bitmaps after storing. This is the only way to restore bitmaps,
if we decided to resume source after [failed] migration with
'dirty-bitmaps' capability enabled (which means, that bitmaps were not
stored).
3. We load bitmaps on open and any invalidation, it's ok for all cases:
- normal open
- migration target invalidation with dirty-bitmaps capability
(bitmaps are migrating through migration channel, the are not
stored, so they should have IN_USE flag set and will be skipped
when loading. However, it would fail if bitmaps are read-only[1])
- migration target invalidation without dirty-bitmaps capability
(normal load of the bitmaps, if migrated with shared storage)
- source invalidation with dirty-bitmaps capability
(skip because IN_USE)
- source invalidation without dirty-bitmaps capability
(bitmaps were dropped, reload them)
[1]: to accurately handle this, migration of read-only bitmaps is
explicitly forbidden in this patch.
New mechanism for not storing bitmaps when migrate with dirty-bitmaps
capability is introduced: migration filed in BdrvDirtyBitmap.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: John Snow <jsnow@redhat.com>
2018-10-29 23:23:17 +03:00
|
|
|
/* Called with BQL taken. */
|
2019-07-29 23:35:54 +03:00
|
|
|
void bdrv_dirty_bitmap_skip_store(BdrvDirtyBitmap *bitmap, bool skip)
|
dirty-bitmaps: clean-up bitmaps loading and migration logic
This patch aims to bring the following behavior:
1. We don't load bitmaps, when started in inactive mode. It's the case
of incoming migration. In this case we wait for bitmaps migration
through migration channel (if 'dirty-bitmaps' capability is enabled) or
for invalidation (to load bitmaps from the image).
2. We don't remove persistent bitmaps on inactivation. Instead, we only
remove bitmaps after storing. This is the only way to restore bitmaps,
if we decided to resume source after [failed] migration with
'dirty-bitmaps' capability enabled (which means, that bitmaps were not
stored).
3. We load bitmaps on open and any invalidation, it's ok for all cases:
- normal open
- migration target invalidation with dirty-bitmaps capability
(bitmaps are migrating through migration channel, the are not
stored, so they should have IN_USE flag set and will be skipped
when loading. However, it would fail if bitmaps are read-only[1])
- migration target invalidation without dirty-bitmaps capability
(normal load of the bitmaps, if migrated with shared storage)
- source invalidation with dirty-bitmaps capability
(skip because IN_USE)
- source invalidation without dirty-bitmaps capability
(bitmaps were dropped, reload them)
[1]: to accurately handle this, migration of read-only bitmaps is
explicitly forbidden in this patch.
New mechanism for not storing bitmaps when migrate with dirty-bitmaps
capability is introduced: migration filed in BdrvDirtyBitmap.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: John Snow <jsnow@redhat.com>
2018-10-29 23:23:17 +03:00
|
|
|
{
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(bitmap->bs);
|
2019-07-29 23:35:54 +03:00
|
|
|
bitmap->skip_store = skip;
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(bitmap->bs);
|
dirty-bitmaps: clean-up bitmaps loading and migration logic
This patch aims to bring the following behavior:
1. We don't load bitmaps, when started in inactive mode. It's the case
of incoming migration. In this case we wait for bitmaps migration
through migration channel (if 'dirty-bitmaps' capability is enabled) or
for invalidation (to load bitmaps from the image).
2. We don't remove persistent bitmaps on inactivation. Instead, we only
remove bitmaps after storing. This is the only way to restore bitmaps,
if we decided to resume source after [failed] migration with
'dirty-bitmaps' capability enabled (which means, that bitmaps were not
stored).
3. We load bitmaps on open and any invalidation, it's ok for all cases:
- normal open
- migration target invalidation with dirty-bitmaps capability
(bitmaps are migrating through migration channel, the are not
stored, so they should have IN_USE flag set and will be skipped
when loading. However, it would fail if bitmaps are read-only[1])
- migration target invalidation without dirty-bitmaps capability
(normal load of the bitmaps, if migrated with shared storage)
- source invalidation with dirty-bitmaps capability
(skip because IN_USE)
- source invalidation without dirty-bitmaps capability
(bitmaps were dropped, reload them)
[1]: to accurately handle this, migration of read-only bitmaps is
explicitly forbidden in this patch.
New mechanism for not storing bitmaps when migrate with dirty-bitmaps
capability is introduced: migration filed in BdrvDirtyBitmap.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: John Snow <jsnow@redhat.com>
2018-10-29 23:23:17 +03:00
|
|
|
}
|
|
|
|
|
2019-03-12 19:05:49 +03:00
|
|
|
bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap)
|
2017-06-28 15:05:17 +03:00
|
|
|
{
|
2019-07-29 23:35:54 +03:00
|
|
|
return bitmap->persistent && !bitmap->skip_store;
|
2017-06-28 15:05:17 +03:00
|
|
|
}
|
|
|
|
|
2019-03-12 19:05:49 +03:00
|
|
|
bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
|
|
|
return bitmap->inconsistent;
|
|
|
|
}
|
|
|
|
|
2019-09-16 17:19:11 +03:00
|
|
|
BdrvDirtyBitmap *bdrv_dirty_bitmap_first(BlockDriverState *bs)
|
2017-06-28 15:05:18 +03:00
|
|
|
{
|
2019-09-16 17:19:11 +03:00
|
|
|
return QLIST_FIRST(&bs->dirty_bitmaps);
|
|
|
|
}
|
|
|
|
|
|
|
|
BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BdrvDirtyBitmap *bitmap)
|
|
|
|
{
|
|
|
|
return QLIST_NEXT(bitmap, list);
|
2017-06-28 15:05:18 +03:00
|
|
|
}
|
2017-06-28 15:05:25 +03:00
|
|
|
|
|
|
|
char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp)
|
|
|
|
{
|
|
|
|
return hbitmap_sha256(bitmap->bitmap, errp);
|
|
|
|
}
|
2017-10-12 16:53:09 +03:00
|
|
|
|
2019-01-16 02:26:49 +03:00
|
|
|
int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offset,
|
|
|
|
uint64_t bytes)
|
2017-10-12 16:53:09 +03:00
|
|
|
{
|
2019-01-16 02:26:49 +03:00
|
|
|
return hbitmap_next_zero(bitmap->bitmap, offset, bytes);
|
2017-10-12 16:53:09 +03:00
|
|
|
}
|
2018-06-11 21:53:32 +03:00
|
|
|
|
2019-01-16 02:26:50 +03:00
|
|
|
bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,
|
|
|
|
uint64_t *offset, uint64_t *bytes)
|
|
|
|
{
|
|
|
|
return hbitmap_next_dirty_area(bitmap->bitmap, offset, bytes);
|
|
|
|
}
|
|
|
|
|
2019-07-29 23:35:53 +03:00
|
|
|
/**
|
|
|
|
* bdrv_merge_dirty_bitmap: merge src into dest.
|
|
|
|
* Ensures permissions on bitmaps are reasonable; use for public API.
|
|
|
|
*
|
|
|
|
* @backup: If provided, make a copy of dest here prior to merge.
|
|
|
|
*/
|
2018-06-11 21:53:32 +03:00
|
|
|
void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
|
2018-10-29 23:23:15 +03:00
|
|
|
HBitmap **backup, Error **errp)
|
2018-06-11 21:53:32 +03:00
|
|
|
{
|
2018-10-29 23:23:15 +03:00
|
|
|
bool ret;
|
|
|
|
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(dest->bs);
|
|
|
|
if (src->bs != dest->bs) {
|
|
|
|
bdrv_dirty_bitmaps_lock(src->bs);
|
2019-05-29 02:33:31 +03:00
|
|
|
}
|
2018-06-11 21:53:32 +03:00
|
|
|
|
2019-03-12 19:05:49 +03:00
|
|
|
if (bdrv_dirty_bitmap_check(dest, BDRV_BITMAP_DEFAULT, errp)) {
|
2018-10-29 23:23:14 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-03-12 19:05:49 +03:00
|
|
|
if (bdrv_dirty_bitmap_check(src, BDRV_BITMAP_ALLOW_RO, errp)) {
|
|
|
|
goto out;
|
|
|
|
}
|
2018-06-11 21:53:32 +03:00
|
|
|
|
2018-10-29 23:23:15 +03:00
|
|
|
if (!hbitmap_can_merge(dest->bitmap, src->bitmap)) {
|
2018-06-11 21:53:32 +03:00
|
|
|
error_setg(errp, "Bitmaps are incompatible and can't be merged");
|
2018-10-29 23:23:14 +03:00
|
|
|
goto out;
|
2018-06-11 21:53:32 +03:00
|
|
|
}
|
|
|
|
|
2019-07-29 23:35:53 +03:00
|
|
|
ret = bdrv_dirty_bitmap_merge_internal(dest, src, backup, false);
|
|
|
|
assert(ret);
|
|
|
|
|
|
|
|
out:
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(dest->bs);
|
|
|
|
if (src->bs != dest->bs) {
|
|
|
|
bdrv_dirty_bitmaps_unlock(src->bs);
|
2019-07-29 23:35:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bdrv_dirty_bitmap_merge_internal: merge src into dest.
|
|
|
|
* Does NOT check bitmap permissions; not suitable for use as public API.
|
|
|
|
*
|
|
|
|
* @backup: If provided, make a copy of dest here prior to merge.
|
|
|
|
* @lock: If true, lock and unlock bitmaps on the way in/out.
|
|
|
|
* returns true if the merge succeeded; false if unattempted.
|
|
|
|
*/
|
|
|
|
bool bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *dest,
|
|
|
|
const BdrvDirtyBitmap *src,
|
|
|
|
HBitmap **backup,
|
|
|
|
bool lock)
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
assert(!bdrv_dirty_bitmap_readonly(dest));
|
|
|
|
assert(!bdrv_dirty_bitmap_inconsistent(dest));
|
|
|
|
assert(!bdrv_dirty_bitmap_inconsistent(src));
|
|
|
|
|
|
|
|
if (lock) {
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_lock(dest->bs);
|
|
|
|
if (src->bs != dest->bs) {
|
|
|
|
bdrv_dirty_bitmaps_lock(src->bs);
|
2019-07-29 23:35:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-29 23:23:15 +03:00
|
|
|
if (backup) {
|
|
|
|
*backup = dest->bitmap;
|
|
|
|
dest->bitmap = hbitmap_alloc(dest->size, hbitmap_granularity(*backup));
|
|
|
|
ret = hbitmap_merge(*backup, src->bitmap, dest->bitmap);
|
|
|
|
} else {
|
|
|
|
ret = hbitmap_merge(dest->bitmap, src->bitmap, dest->bitmap);
|
|
|
|
}
|
|
|
|
|
2019-07-29 23:35:53 +03:00
|
|
|
if (lock) {
|
2019-09-16 17:19:10 +03:00
|
|
|
bdrv_dirty_bitmaps_unlock(dest->bs);
|
|
|
|
if (src->bs != dest->bs) {
|
|
|
|
bdrv_dirty_bitmaps_unlock(src->bs);
|
2019-07-29 23:35:53 +03:00
|
|
|
}
|
2019-05-29 02:33:31 +03:00
|
|
|
}
|
2019-07-29 23:35:53 +03:00
|
|
|
|
|
|
|
return ret;
|
2018-06-11 21:53:32 +03:00
|
|
|
}
|