~dannf/qemu-linaro/qemu-highbank-ppa

« back to all changes in this revision

Viewing changes to blockdev.c

  • Committer: Steve Langasek
  • Date: 2012-03-15 21:13:19 UTC
  • mfrom: (0.1.15)
  • Revision ID: steve.langasek@canonical.com-20120315211319-f1j3ot1ihx30b2s9
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "block_int.h"
19
19
#include "qmp-commands.h"
20
20
#include "trace.h"
 
21
#include "arch_init.h"
21
22
 
22
23
static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
23
24
 
565
566
    case IF_VIRTIO:
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");
 
571
        } else {
 
572
            qemu_opt_set(opts, "driver", "virtio-blk-pci");
 
573
        }
569
574
        qemu_opt_set(opts, "drive", dinfo->id);
570
575
        if (devaddr)
571
576
            qemu_opt_set(opts, "addr", devaddr);
590
595
        /* CDROM is fine for any interface, don't check.  */
591
596
        ro = 1;
592
597
    } else if (ro == 1) {
593
 
        if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY && type != IF_NONE) {
 
598
        if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY &&
 
599
            type != IF_NONE && type != IF_PFLASH) {
594
600
            error_report("readonly not supported by this bus type");
595
601
            goto err;
596
602
        }
708
714
    }
709
715
}
710
716
 
 
717
 
 
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;
 
724
 
 
725
/*
 
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
 
728
 *  snapshots
 
729
 */
 
730
void qmp_blockdev_group_snapshot_sync(SnapshotDevList *dev_list,
 
731
                                      Error **errp)
 
732
{
 
733
    int ret = 0;
 
734
    SnapshotDevList *dev_entry = dev_list;
 
735
    SnapshotDev *dev_info = NULL;
 
736
    BlkGroupSnapshotStates *states;
 
737
    BlockDriver *proto_drv;
 
738
    BlockDriver *drv;
 
739
    int flags;
 
740
    const char *format;
 
741
    const char *snapshot_file;
 
742
 
 
743
    QSIMPLEQ_HEAD(snap_bdrv_states, BlkGroupSnapshotStates) snap_bdrv_states;
 
744
    QSIMPLEQ_INIT(&snap_bdrv_states);
 
745
 
 
746
    /* drain all i/o before any snapshots */
 
747
    bdrv_drain_all();
 
748
 
 
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;
 
753
 
 
754
        states = g_malloc0(sizeof(BlkGroupSnapshotStates));
 
755
        QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, states, entry);
 
756
 
 
757
        states->old_bs = bdrv_find(dev_info->device);
 
758
 
 
759
        if (!states->old_bs) {
 
760
            error_set(errp, QERR_DEVICE_NOT_FOUND, dev_info->device);
 
761
            goto delete_and_fail;
 
762
        }
 
763
 
 
764
        if (bdrv_in_use(states->old_bs)) {
 
765
            error_set(errp, QERR_DEVICE_IN_USE, dev_info->device);
 
766
            goto delete_and_fail;
 
767
        }
 
768
 
 
769
        if (!bdrv_is_read_only(states->old_bs) &&
 
770
             bdrv_is_inserted(states->old_bs)) {
 
771
 
 
772
            if (bdrv_flush(states->old_bs)) {
 
773
                error_set(errp, QERR_IO_ERROR);
 
774
                goto delete_and_fail;
 
775
            }
 
776
        }
 
777
 
 
778
        snapshot_file = dev_info->snapshot_file;
 
779
 
 
780
        flags = states->old_bs->open_flags;
 
781
 
 
782
        if (!dev_info->has_format) {
 
783
            format = "qcow2";
 
784
        } else {
 
785
            format = dev_info->format;
 
786
        }
 
787
 
 
788
        drv = bdrv_find_format(format);
 
789
        if (!drv) {
 
790
            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
 
791
            goto delete_and_fail;
 
792
        }
 
793
 
 
794
        proto_drv = bdrv_find_protocol(snapshot_file);
 
795
        if (!proto_drv) {
 
796
            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
 
797
            goto delete_and_fail;
 
798
        }
 
799
 
 
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);
 
804
        if (ret) {
 
805
            error_set(errp, QERR_OPEN_FILE_FAILED, snapshot_file);
 
806
            goto delete_and_fail;
 
807
        }
 
808
 
 
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);
 
813
        if (ret != 0) {
 
814
            error_set(errp, QERR_OPEN_FILE_FAILED, snapshot_file);
 
815
            goto delete_and_fail;
 
816
        }
 
817
    }
 
818
 
 
819
 
 
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);
 
825
    }
 
826
 
 
827
    /* success */
 
828
    goto exit;
 
829
 
 
830
delete_and_fail:
 
831
    /*
 
832
    * failure, and it is all-or-none; abandon each new bs, and keep using
 
833
    * the original bs for all images
 
834
    */
 
835
    QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
 
836
        if (states->new_bs) {
 
837
             bdrv_delete(states->new_bs);
 
838
        }
 
839
    }
 
840
exit:
 
841
    QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
 
842
        g_free(states);
 
843
    }
 
844
    return;
 
845
}
 
846
 
 
847
 
711
848
static void eject_device(BlockDriverState *bs, int force, Error **errp)
712
849
{
713
850
    if (bdrv_in_use(bs)) {