566
567
/* add virtio block device */
567
568
opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
568
qemu_opt_set(opts, "driver", "virtio-blk");
569
if (arch_type == QEMU_ARCH_S390X) {
570
qemu_opt_set(opts, "driver", "virtio-blk-s390");
572
qemu_opt_set(opts, "driver", "virtio-blk-pci");
569
574
qemu_opt_set(opts, "drive", dinfo->id);
571
576
qemu_opt_set(opts, "addr", devaddr);
718
/* New and old BlockDriverState structs for group snapshots */
719
typedef struct BlkGroupSnapshotStates {
720
BlockDriverState *old_bs;
721
BlockDriverState *new_bs;
722
QSIMPLEQ_ENTRY(BlkGroupSnapshotStates) entry;
723
} BlkGroupSnapshotStates;
726
* 'Atomic' group snapshots. The snapshots are taken as a set, and if any fail
727
* then we do not pivot any of the devices in the group, and abandon the
730
void qmp_blockdev_group_snapshot_sync(SnapshotDevList *dev_list,
734
SnapshotDevList *dev_entry = dev_list;
735
SnapshotDev *dev_info = NULL;
736
BlkGroupSnapshotStates *states;
737
BlockDriver *proto_drv;
741
const char *snapshot_file;
743
QSIMPLEQ_HEAD(snap_bdrv_states, BlkGroupSnapshotStates) snap_bdrv_states;
744
QSIMPLEQ_INIT(&snap_bdrv_states);
746
/* drain all i/o before any snapshots */
749
/* We don't do anything in this loop that commits us to the snapshot */
750
while (NULL != dev_entry) {
751
dev_info = dev_entry->value;
752
dev_entry = dev_entry->next;
754
states = g_malloc0(sizeof(BlkGroupSnapshotStates));
755
QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, states, entry);
757
states->old_bs = bdrv_find(dev_info->device);
759
if (!states->old_bs) {
760
error_set(errp, QERR_DEVICE_NOT_FOUND, dev_info->device);
761
goto delete_and_fail;
764
if (bdrv_in_use(states->old_bs)) {
765
error_set(errp, QERR_DEVICE_IN_USE, dev_info->device);
766
goto delete_and_fail;
769
if (!bdrv_is_read_only(states->old_bs) &&
770
bdrv_is_inserted(states->old_bs)) {
772
if (bdrv_flush(states->old_bs)) {
773
error_set(errp, QERR_IO_ERROR);
774
goto delete_and_fail;
778
snapshot_file = dev_info->snapshot_file;
780
flags = states->old_bs->open_flags;
782
if (!dev_info->has_format) {
785
format = dev_info->format;
788
drv = bdrv_find_format(format);
790
error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
791
goto delete_and_fail;
794
proto_drv = bdrv_find_protocol(snapshot_file);
796
error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
797
goto delete_and_fail;
800
/* create new image w/backing file */
801
ret = bdrv_img_create(snapshot_file, format,
802
states->old_bs->filename,
803
drv->format_name, NULL, -1, flags);
805
error_set(errp, QERR_OPEN_FILE_FAILED, snapshot_file);
806
goto delete_and_fail;
809
/* We will manually add the backing_hd field to the bs later */
810
states->new_bs = bdrv_new("");
811
ret = bdrv_open(states->new_bs, snapshot_file,
812
flags | BDRV_O_NO_BACKING, drv);
814
error_set(errp, QERR_OPEN_FILE_FAILED, snapshot_file);
815
goto delete_and_fail;
820
/* Now we are going to do the actual pivot. Everything up to this point
821
* is reversible, but we are committed at this point */
822
QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
823
/* This removes our old bs from the bdrv_states, and adds the new bs */
824
bdrv_append(states->new_bs, states->old_bs);
832
* failure, and it is all-or-none; abandon each new bs, and keep using
833
* the original bs for all images
835
QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
836
if (states->new_bs) {
837
bdrv_delete(states->new_bs);
841
QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
711
848
static void eject_device(BlockDriverState *bs, int force, Error **errp)
713
850
if (bdrv_in_use(bs)) {