The bs_snapshots global variable points to the BlockDriverState which
will be used to save vmstate. This is really a savevm.c concept but was
moved into block.c:bdrv_snapshots() when it became clear that hotplug
could result in a dangling pointer.
While auditing the block layer's global state I came upon bs_snapshots
and realized that a variable is not necessary here. Simply find the
first BlockDriverState capable of internal snapshots each time this is
needed.
The behavior of bdrv_snapshots() is preserved across hotplug because new
drives are always appended to the bdrv_states list. This means that
calling the new find_vmstate_bs() function is idempotent - it returns
the same BlockDriverState unless it was hot-unplugged.
Signed-off-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Wenchao Xia <[email protected]>
Signed-off-by: Wenchao Xia <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
static QLIST_HEAD(, BlockDriver) bdrv_drivers =
QLIST_HEAD_INITIALIZER(bdrv_drivers);
-/* The device to use for VM snapshots */
-static BlockDriverState *bs_snapshots;
-
/* If non-zero, use only whitelisted block drivers */
static int use_bdrv_whitelist;
notifier_list_notify(&bs->close_notifiers, bs);
if (bs->drv) {
- if (bs == bs_snapshots) {
- bs_snapshots = NULL;
- }
if (bs->backing_hd) {
bdrv_delete(bs->backing_hd);
bs->backing_hd = NULL;
bdrv_close(bs);
- assert(bs != bs_snapshots);
g_free(bs);
}
{
bs->dev_ops = ops;
bs->dev_opaque = opaque;
- if (bdrv_dev_has_removable_media(bs) && bs == bs_snapshots) {
- bs_snapshots = NULL;
- }
}
void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
return !!(bs->open_flags & BDRV_O_SNAPSHOT);
}
-BlockDriverState *bdrv_snapshots(void)
-{
- BlockDriverState *bs;
-
- if (bs_snapshots) {
- return bs_snapshots;
- }
-
- bs = NULL;
- while ((bs = bdrv_next(bs))) {
- if (bdrv_can_snapshot(bs)) {
- bs_snapshots = bs;
- return bs;
- }
- }
- return NULL;
-}
-
int bdrv_snapshot_create(BlockDriverState *bs,
QEMUSnapshotInfo *sn_info)
{
BlockStats *bdrv_query_stats(const BlockDriverState *bs);
int bdrv_can_snapshot(BlockDriverState *bs);
int bdrv_is_snapshot(BlockDriverState *bs);
-BlockDriverState *bdrv_snapshots(void);
int bdrv_snapshot_create(BlockDriverState *bs,
QEMUSnapshotInfo *sn_info);
int bdrv_snapshot_goto(BlockDriverState *bs,
return ret;
}
+static BlockDriverState *find_vmstate_bs(void)
+{
+ BlockDriverState *bs = NULL;
+ while ((bs = bdrv_next(bs))) {
+ if (bdrv_can_snapshot(bs)) {
+ return bs;
+ }
+ }
+ return NULL;
+}
+
static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
const char *name)
{
}
}
- bs = bdrv_snapshots();
+ bs = find_vmstate_bs();
if (!bs) {
monitor_printf(mon, "No block device can accept snapshots\n");
return;
QEMUFile *f;
int ret;
- bs_vm_state = bdrv_snapshots();
+ bs_vm_state = find_vmstate_bs();
if (!bs_vm_state) {
error_report("No block device supports snapshots");
return -ENOTSUP;
int ret;
const char *name = qdict_get_str(qdict, "name");
- bs = bdrv_snapshots();
+ bs = find_vmstate_bs();
if (!bs) {
monitor_printf(mon, "No block device supports snapshots\n");
return;
int *available_snapshots;
char buf[256];
- bs = bdrv_snapshots();
+ bs = find_vmstate_bs();
if (!bs) {
monitor_printf(mon, "No available block device supports snapshots\n");
return;