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;
void bdrv_close(BlockDriverState *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_delete(bs->file);
}
+ assert(bs != bs_snapshots);
qemu_free(bs);
}
return 1;
}
+BlockDriverState *bdrv_snapshots(void)
+{
+ BlockDriverState *bs;
+
+ if (bs_snapshots)
+ return bs_snapshots;
+
+ bs = NULL;
+ while ((bs = bdrv_next(bs))) {
+ if (bdrv_can_snapshot(bs)) {
+ goto ok;
+ }
+ }
+ return NULL;
+ ok:
+ bs_snapshots = bs;
+ return bs;
+}
+
int bdrv_snapshot_create(BlockDriverState *bs,
QEMUSnapshotInfo *sn_info)
{
void bdrv_get_backing_filename(BlockDriverState *bs,
char *filename, int filename_size);
int bdrv_can_snapshot(BlockDriverState *bs);
+BlockDriverState *bdrv_snapshots(void);
int bdrv_snapshot_create(BlockDriverState *bs,
QEMUSnapshotInfo *sn_info);
int bdrv_snapshot_goto(BlockDriverState *bs,
#include "qemu_socket.h"
#include "qemu-queue.h"
-/* point to the block driver where the snapshots are managed */
-static BlockDriverState *bs_snapshots;
-
#define SELF_ANNOUNCE_ROUNDS 5
#ifndef ETH_P_RARP
return ret;
}
-static BlockDriverState *get_bs_snapshots(void)
-{
- BlockDriverState *bs;
-
- if (bs_snapshots)
- return bs_snapshots;
- /* FIXME what if bs_snapshots gets hot-unplugged? */
-
- bs = NULL;
- while ((bs = bdrv_next(bs))) {
- if (bdrv_can_snapshot(bs)) {
- goto ok;
- }
- }
- return NULL;
- ok:
- bs_snapshots = bs;
- return bs;
-}
-
static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
const char *name)
{
}
}
- bs = get_bs_snapshots();
+ bs = bdrv_snapshots();
if (!bs) {
monitor_printf(mon, "No block device can accept snapshots\n");
return;
}
}
- bs = get_bs_snapshots();
+ bs = bdrv_snapshots();
if (!bs) {
error_report("No block device supports snapshots");
return -EINVAL;
int ret;
const char *name = qdict_get_str(qdict, "name");
- bs = get_bs_snapshots();
+ bs = bdrv_snapshots();
if (!bs) {
monitor_printf(mon, "No block device supports snapshots\n");
return;
int nb_sns, i;
char buf[256];
- bs = get_bs_snapshots();
+ bs = bdrv_snapshots();
if (!bs) {
monitor_printf(mon, "No available block device supports snapshots\n");
return;