~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to blockdev.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
48
48
extern QemuOptsList qemu_common_drive_opts;
 
49
extern QemuOptsList qemu_old_drive_opts;
49
50
 
50
51
static const char *const if_name[IF_COUNT] = {
51
52
    [IF_NONE] = "none",
312
313
    return true;
313
314
}
314
315
 
315
 
DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 
316
static DriveInfo *blockdev_init(QemuOpts *all_opts,
 
317
                                BlockInterfaceType block_default_type)
316
318
{
317
319
    const char *buf;
318
320
    const char *file = NULL;
322
324
    enum { MEDIA_DISK, MEDIA_CDROM } media;
323
325
    int bus_id, unit_id;
324
326
    int cyls, heads, secs, translation;
325
 
    BlockDriver *drv = NULL;
326
327
    int max_devs;
327
328
    int index;
328
329
    int ro = 0;
338
339
    QemuOpts *opts;
339
340
    QDict *bs_opts;
340
341
    const char *id;
 
342
    bool has_driver_specific_opts;
 
343
    BlockDriver *drv = NULL;
341
344
 
342
345
    translation = BIOS_ATA_TRANSLATION_AUTO;
343
346
    media = MEDIA_DISK;
365
368
        qdict_del(bs_opts, "id");
366
369
    }
367
370
 
 
371
    has_driver_specific_opts = !!qdict_size(bs_opts);
 
372
 
368
373
    /* extract parameters */
369
374
    bus_id  = qemu_opt_get_number(opts, "bus", 0);
370
375
    unit_id = qemu_opt_get_number(opts, "unit", -1);
375
380
    secs  = qemu_opt_get_number(opts, "secs", 0);
376
381
 
377
382
    snapshot = qemu_opt_get_bool(opts, "snapshot", 0);
378
 
    ro = qemu_opt_get_bool(opts, "readonly", 0);
 
383
    ro = qemu_opt_get_bool(opts, "read-only", 0);
379
384
    copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false);
380
385
 
381
386
    file = qemu_opt_get(opts, "file");
449
454
        }
450
455
    }
451
456
 
452
 
    bdrv_flags |= BDRV_O_CACHE_WB;
453
 
    if ((buf = qemu_opt_get(opts, "cache")) != NULL) {
454
 
        if (bdrv_parse_cache_flags(buf, &bdrv_flags) != 0) {
455
 
            error_report("invalid cache option");
456
 
            return NULL;
457
 
        }
 
457
    if (qemu_opt_get_bool(opts, "cache.writeback", true)) {
 
458
        bdrv_flags |= BDRV_O_CACHE_WB;
 
459
    }
 
460
    if (qemu_opt_get_bool(opts, "cache.direct", false)) {
 
461
        bdrv_flags |= BDRV_O_NOCACHE;
 
462
    }
 
463
    if (qemu_opt_get_bool(opts, "cache.no-flush", false)) {
 
464
        bdrv_flags |= BDRV_O_NO_FLUSH;
458
465
    }
459
466
 
460
467
#ifdef CONFIG_LINUX_AIO
477
484
            error_printf("\n");
478
485
            return NULL;
479
486
        }
480
 
        drv = bdrv_find_whitelisted_format(buf);
 
487
 
 
488
        drv = bdrv_find_whitelisted_format(buf, ro);
481
489
        if (!drv) {
482
490
            error_report("'%s' invalid format", buf);
483
491
            return NULL;
486
494
 
487
495
    /* disk I/O throttling */
488
496
    io_limits.bps[BLOCK_IO_LIMIT_TOTAL]  =
489
 
                           qemu_opt_get_number(opts, "bps", 0);
 
497
        qemu_opt_get_number(opts, "throttling.bps-total", 0);
490
498
    io_limits.bps[BLOCK_IO_LIMIT_READ]   =
491
 
                           qemu_opt_get_number(opts, "bps_rd", 0);
 
499
        qemu_opt_get_number(opts, "throttling.bps-read", 0);
492
500
    io_limits.bps[BLOCK_IO_LIMIT_WRITE]  =
493
 
                           qemu_opt_get_number(opts, "bps_wr", 0);
 
501
        qemu_opt_get_number(opts, "throttling.bps-write", 0);
494
502
    io_limits.iops[BLOCK_IO_LIMIT_TOTAL] =
495
 
                           qemu_opt_get_number(opts, "iops", 0);
 
503
        qemu_opt_get_number(opts, "throttling.iops-total", 0);
496
504
    io_limits.iops[BLOCK_IO_LIMIT_READ]  =
497
 
                           qemu_opt_get_number(opts, "iops_rd", 0);
 
505
        qemu_opt_get_number(opts, "throttling.iops-read", 0);
498
506
    io_limits.iops[BLOCK_IO_LIMIT_WRITE] =
499
 
                           qemu_opt_get_number(opts, "iops_wr", 0);
 
507
        qemu_opt_get_number(opts, "throttling.iops-write", 0);
500
508
 
501
509
    if (!do_check_io_limits(&io_limits, &error)) {
502
510
        error_report("%s", error_get_pretty(error));
658
666
        abort();
659
667
    }
660
668
    if (!file || !*file) {
661
 
        if (qdict_size(bs_opts)) {
 
669
        if (has_driver_specific_opts) {
662
670
            file = NULL;
663
671
        } else {
664
672
            return dinfo;
684
692
    } else if (ro == 1) {
685
693
        if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY &&
686
694
            type != IF_NONE && type != IF_PFLASH) {
687
 
            error_report("readonly not supported by this bus type");
 
695
            error_report("read-only not supported by this bus type");
688
696
            goto err;
689
697
        }
690
698
    }
692
700
    bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
693
701
 
694
702
    if (ro && copy_on_read) {
695
 
        error_report("warning: disabling copy_on_read on readonly drive");
 
703
        error_report("warning: disabling copy_on_read on read-only drive");
696
704
    }
697
705
 
 
706
    QINCREF(bs_opts);
698
707
    ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv);
699
 
    bs_opts = NULL;
700
708
 
701
709
    if (ret < 0) {
702
710
        if (ret == -EMEDIUMTYPE) {
703
711
            error_report("could not open disk image %s: not in %s format",
704
 
                         file ?: dinfo->id, drv->format_name);
 
712
                         file ?: dinfo->id, drv ? drv->format_name :
 
713
                         qdict_get_str(bs_opts, "driver"));
705
714
        } else {
706
715
            error_report("could not open disk image %s: %s",
707
716
                         file ?: dinfo->id, strerror(-ret));
712
721
    if (bdrv_key_required(dinfo->bdrv))
713
722
        autostart = 0;
714
723
 
 
724
    QDECREF(bs_opts);
715
725
    qemu_opts_del(opts);
716
726
 
717
727
    return dinfo;
726
736
    return NULL;
727
737
}
728
738
 
 
739
static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)
 
740
{
 
741
    const char *value;
 
742
 
 
743
    value = qemu_opt_get(opts, from);
 
744
    if (value) {
 
745
        qemu_opt_set(opts, to, value);
 
746
        qemu_opt_unset(opts, from);
 
747
    }
 
748
}
 
749
 
 
750
DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 
751
{
 
752
    const char *value;
 
753
 
 
754
    /*
 
755
     * Check that only old options are used by copying into a QemuOpts with
 
756
     * stricter checks. Going through a QDict seems to be the easiest way to
 
757
     * achieve this...
 
758
     */
 
759
    QemuOpts* check_opts;
 
760
    QDict *qdict;
 
761
    Error *local_err = NULL;
 
762
 
 
763
    qdict = qemu_opts_to_qdict(all_opts, NULL);
 
764
    check_opts = qemu_opts_from_qdict(&qemu_old_drive_opts, qdict, &local_err);
 
765
    QDECREF(qdict);
 
766
 
 
767
    if (error_is_set(&local_err)) {
 
768
        qerror_report_err(local_err);
 
769
        error_free(local_err);
 
770
        return NULL;
 
771
    }
 
772
    qemu_opts_del(check_opts);
 
773
 
 
774
    /* Change legacy command line options into QMP ones */
 
775
    qemu_opt_rename(all_opts, "iops", "throttling.iops-total");
 
776
    qemu_opt_rename(all_opts, "iops_rd", "throttling.iops-read");
 
777
    qemu_opt_rename(all_opts, "iops_wr", "throttling.iops-write");
 
778
 
 
779
    qemu_opt_rename(all_opts, "bps", "throttling.bps-total");
 
780
    qemu_opt_rename(all_opts, "bps_rd", "throttling.bps-read");
 
781
    qemu_opt_rename(all_opts, "bps_wr", "throttling.bps-write");
 
782
 
 
783
    qemu_opt_rename(all_opts, "readonly", "read-only");
 
784
 
 
785
    value = qemu_opt_get(all_opts, "cache");
 
786
    if (value) {
 
787
        int flags = 0;
 
788
 
 
789
        if (bdrv_parse_cache_flags(value, &flags) != 0) {
 
790
            error_report("invalid cache option");
 
791
            return NULL;
 
792
        }
 
793
 
 
794
        /* Specific options take precedence */
 
795
        if (!qemu_opt_get(all_opts, "cache.writeback")) {
 
796
            qemu_opt_set_bool(all_opts, "cache.writeback",
 
797
                              !!(flags & BDRV_O_CACHE_WB));
 
798
        }
 
799
        if (!qemu_opt_get(all_opts, "cache.direct")) {
 
800
            qemu_opt_set_bool(all_opts, "cache.direct",
 
801
                              !!(flags & BDRV_O_NOCACHE));
 
802
        }
 
803
        if (!qemu_opt_get(all_opts, "cache.no-flush")) {
 
804
            qemu_opt_set_bool(all_opts, "cache.no-flush",
 
805
                              !!(flags & BDRV_O_NO_FLUSH));
 
806
        }
 
807
        qemu_opt_unset(all_opts, "cache");
 
808
    }
 
809
 
 
810
    return blockdev_init(all_opts, block_default_type);
 
811
}
 
812
 
729
813
void do_commit(Monitor *mon, const QDict *qdict)
730
814
{
731
815
    const char *device = qdict_get_str(qdict, "device");
750
834
 
751
835
static void blockdev_do_action(int kind, void *data, Error **errp)
752
836
{
753
 
    BlockdevAction action;
754
 
    BlockdevActionList list;
 
837
    TransactionAction action;
 
838
    TransactionActionList list;
755
839
 
756
840
    action.kind = kind;
757
841
    action.data = data;
773
857
        .has_mode = has_mode,
774
858
        .mode = mode,
775
859
    };
776
 
    blockdev_do_action(BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC, &snapshot,
777
 
                       errp);
 
860
    blockdev_do_action(TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC,
 
861
                       &snapshot, errp);
778
862
}
779
863
 
780
864
 
781
865
/* New and old BlockDriverState structs for group snapshots */
782
 
typedef struct BlkTransactionStates {
 
866
 
 
867
typedef struct BlkTransactionState BlkTransactionState;
 
868
 
 
869
/* Only prepare() may fail. In a single transaction, only one of commit() or
 
870
   abort() will be called, clean() will always be called if it present. */
 
871
typedef struct BdrvActionOps {
 
872
    /* Size of state struct, in bytes. */
 
873
    size_t instance_size;
 
874
    /* Prepare the work, must NOT be NULL. */
 
875
    void (*prepare)(BlkTransactionState *common, Error **errp);
 
876
    /* Commit the changes, can be NULL. */
 
877
    void (*commit)(BlkTransactionState *common);
 
878
    /* Abort the changes on fail, can be NULL. */
 
879
    void (*abort)(BlkTransactionState *common);
 
880
    /* Clean up resource in the end, can be NULL. */
 
881
    void (*clean)(BlkTransactionState *common);
 
882
} BdrvActionOps;
 
883
 
 
884
/*
 
885
 * This structure must be arranged as first member in child type, assuming
 
886
 * that compiler will also arrange it to the same address with parent instance.
 
887
 * Later it will be used in free().
 
888
 */
 
889
struct BlkTransactionState {
 
890
    TransactionAction *action;
 
891
    const BdrvActionOps *ops;
 
892
    QSIMPLEQ_ENTRY(BlkTransactionState) entry;
 
893
};
 
894
 
 
895
/* external snapshot private data */
 
896
typedef struct ExternalSnapshotState {
 
897
    BlkTransactionState common;
783
898
    BlockDriverState *old_bs;
784
899
    BlockDriverState *new_bs;
785
 
    QSIMPLEQ_ENTRY(BlkTransactionStates) entry;
786
 
} BlkTransactionStates;
 
900
} ExternalSnapshotState;
 
901
 
 
902
static void external_snapshot_prepare(BlkTransactionState *common,
 
903
                                      Error **errp)
 
904
{
 
905
    BlockDriver *drv;
 
906
    int flags, ret;
 
907
    Error *local_err = NULL;
 
908
    const char *device;
 
909
    const char *new_image_file;
 
910
    const char *format = "qcow2";
 
911
    enum NewImageMode mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
 
912
    ExternalSnapshotState *state =
 
913
                             DO_UPCAST(ExternalSnapshotState, common, common);
 
914
    TransactionAction *action = common->action;
 
915
 
 
916
    /* get parameters */
 
917
    g_assert(action->kind == TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC);
 
918
 
 
919
    device = action->blockdev_snapshot_sync->device;
 
920
    new_image_file = action->blockdev_snapshot_sync->snapshot_file;
 
921
    if (action->blockdev_snapshot_sync->has_format) {
 
922
        format = action->blockdev_snapshot_sync->format;
 
923
    }
 
924
    if (action->blockdev_snapshot_sync->has_mode) {
 
925
        mode = action->blockdev_snapshot_sync->mode;
 
926
    }
 
927
 
 
928
    /* start processing */
 
929
    drv = bdrv_find_format(format);
 
930
    if (!drv) {
 
931
        error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
 
932
        return;
 
933
    }
 
934
 
 
935
    state->old_bs = bdrv_find(device);
 
936
    if (!state->old_bs) {
 
937
        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
 
938
        return;
 
939
    }
 
940
 
 
941
    if (!bdrv_is_inserted(state->old_bs)) {
 
942
        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
 
943
        return;
 
944
    }
 
945
 
 
946
    if (bdrv_in_use(state->old_bs)) {
 
947
        error_set(errp, QERR_DEVICE_IN_USE, device);
 
948
        return;
 
949
    }
 
950
 
 
951
    if (!bdrv_is_read_only(state->old_bs)) {
 
952
        if (bdrv_flush(state->old_bs)) {
 
953
            error_set(errp, QERR_IO_ERROR);
 
954
            return;
 
955
        }
 
956
    }
 
957
 
 
958
    flags = state->old_bs->open_flags;
 
959
 
 
960
    /* create new image w/backing file */
 
961
    if (mode != NEW_IMAGE_MODE_EXISTING) {
 
962
        bdrv_img_create(new_image_file, format,
 
963
                        state->old_bs->filename,
 
964
                        state->old_bs->drv->format_name,
 
965
                        NULL, -1, flags, &local_err, false);
 
966
        if (error_is_set(&local_err)) {
 
967
            error_propagate(errp, local_err);
 
968
            return;
 
969
        }
 
970
    }
 
971
 
 
972
    /* We will manually add the backing_hd field to the bs later */
 
973
    state->new_bs = bdrv_new("");
 
974
    /* TODO Inherit bs->options or only take explicit options with an
 
975
     * extended QMP command? */
 
976
    ret = bdrv_open(state->new_bs, new_image_file, NULL,
 
977
                    flags | BDRV_O_NO_BACKING, drv);
 
978
    if (ret != 0) {
 
979
        error_setg_file_open(errp, -ret, new_image_file);
 
980
    }
 
981
}
 
982
 
 
983
static void external_snapshot_commit(BlkTransactionState *common)
 
984
{
 
985
    ExternalSnapshotState *state =
 
986
                             DO_UPCAST(ExternalSnapshotState, common, common);
 
987
 
 
988
    /* This removes our old bs and adds the new bs */
 
989
    bdrv_append(state->new_bs, state->old_bs);
 
990
    /* We don't need (or want) to use the transactional
 
991
     * bdrv_reopen_multiple() across all the entries at once, because we
 
992
     * don't want to abort all of them if one of them fails the reopen */
 
993
    bdrv_reopen(state->new_bs, state->new_bs->open_flags & ~BDRV_O_RDWR,
 
994
                NULL);
 
995
}
 
996
 
 
997
static void external_snapshot_abort(BlkTransactionState *common)
 
998
{
 
999
    ExternalSnapshotState *state =
 
1000
                             DO_UPCAST(ExternalSnapshotState, common, common);
 
1001
    if (state->new_bs) {
 
1002
        bdrv_delete(state->new_bs);
 
1003
    }
 
1004
}
 
1005
 
 
1006
typedef struct DriveBackupState {
 
1007
    BlkTransactionState common;
 
1008
    BlockDriverState *bs;
 
1009
    BlockJob *job;
 
1010
} DriveBackupState;
 
1011
 
 
1012
static void drive_backup_prepare(BlkTransactionState *common, Error **errp)
 
1013
{
 
1014
    DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
 
1015
    DriveBackup *backup;
 
1016
    Error *local_err = NULL;
 
1017
 
 
1018
    assert(common->action->kind == TRANSACTION_ACTION_KIND_DRIVE_BACKUP);
 
1019
    backup = common->action->drive_backup;
 
1020
 
 
1021
    qmp_drive_backup(backup->device, backup->target,
 
1022
                     backup->has_format, backup->format,
 
1023
                     backup->sync,
 
1024
                     backup->has_mode, backup->mode,
 
1025
                     backup->has_speed, backup->speed,
 
1026
                     backup->has_on_source_error, backup->on_source_error,
 
1027
                     backup->has_on_target_error, backup->on_target_error,
 
1028
                     &local_err);
 
1029
    if (error_is_set(&local_err)) {
 
1030
        error_propagate(errp, local_err);
 
1031
        state->bs = NULL;
 
1032
        state->job = NULL;
 
1033
        return;
 
1034
    }
 
1035
 
 
1036
    state->bs = bdrv_find(backup->device);
 
1037
    state->job = state->bs->job;
 
1038
}
 
1039
 
 
1040
static void drive_backup_abort(BlkTransactionState *common)
 
1041
{
 
1042
    DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
 
1043
    BlockDriverState *bs = state->bs;
 
1044
 
 
1045
    /* Only cancel if it's the job we started */
 
1046
    if (bs && bs->job && bs->job == state->job) {
 
1047
        block_job_cancel_sync(bs->job);
 
1048
    }
 
1049
}
 
1050
 
 
1051
static void abort_prepare(BlkTransactionState *common, Error **errp)
 
1052
{
 
1053
    error_setg(errp, "Transaction aborted using Abort action");
 
1054
}
 
1055
 
 
1056
static void abort_commit(BlkTransactionState *common)
 
1057
{
 
1058
    g_assert_not_reached(); /* this action never succeeds */
 
1059
}
 
1060
 
 
1061
static const BdrvActionOps actions[] = {
 
1062
    [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC] = {
 
1063
        .instance_size = sizeof(ExternalSnapshotState),
 
1064
        .prepare  = external_snapshot_prepare,
 
1065
        .commit   = external_snapshot_commit,
 
1066
        .abort = external_snapshot_abort,
 
1067
    },
 
1068
    [TRANSACTION_ACTION_KIND_DRIVE_BACKUP] = {
 
1069
        .instance_size = sizeof(DriveBackupState),
 
1070
        .prepare = drive_backup_prepare,
 
1071
        .abort = drive_backup_abort,
 
1072
    },
 
1073
    [TRANSACTION_ACTION_KIND_ABORT] = {
 
1074
        .instance_size = sizeof(BlkTransactionState),
 
1075
        .prepare = abort_prepare,
 
1076
        .commit = abort_commit,
 
1077
    },
 
1078
};
787
1079
 
788
1080
/*
789
1081
 * 'Atomic' group snapshots.  The snapshots are taken as a set, and if any fail
790
1082
 *  then we do not pivot any of the devices in the group, and abandon the
791
1083
 *  snapshots
792
1084
 */
793
 
void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
 
1085
void qmp_transaction(TransactionActionList *dev_list, Error **errp)
794
1086
{
795
 
    int ret = 0;
796
 
    BlockdevActionList *dev_entry = dev_list;
797
 
    BlkTransactionStates *states, *next;
 
1087
    TransactionActionList *dev_entry = dev_list;
 
1088
    BlkTransactionState *state, *next;
798
1089
    Error *local_err = NULL;
799
1090
 
800
 
    QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionStates) snap_bdrv_states;
 
1091
    QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states;
801
1092
    QSIMPLEQ_INIT(&snap_bdrv_states);
802
1093
 
803
1094
    /* drain all i/o before any snapshots */
805
1096
 
806
1097
    /* We don't do anything in this loop that commits us to the snapshot */
807
1098
    while (NULL != dev_entry) {
808
 
        BlockdevAction *dev_info = NULL;
809
 
        BlockDriver *proto_drv;
810
 
        BlockDriver *drv;
811
 
        int flags;
812
 
        enum NewImageMode mode;
813
 
        const char *new_image_file;
814
 
        const char *device;
815
 
        const char *format = "qcow2";
 
1099
        TransactionAction *dev_info = NULL;
 
1100
        const BdrvActionOps *ops;
816
1101
 
817
1102
        dev_info = dev_entry->value;
818
1103
        dev_entry = dev_entry->next;
819
1104
 
820
 
        states = g_malloc0(sizeof(BlkTransactionStates));
821
 
        QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, states, entry);
822
 
 
823
 
        switch (dev_info->kind) {
824
 
        case BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC:
825
 
            device = dev_info->blockdev_snapshot_sync->device;
826
 
            if (!dev_info->blockdev_snapshot_sync->has_mode) {
827
 
                dev_info->blockdev_snapshot_sync->mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
828
 
            }
829
 
            new_image_file = dev_info->blockdev_snapshot_sync->snapshot_file;
830
 
            if (dev_info->blockdev_snapshot_sync->has_format) {
831
 
                format = dev_info->blockdev_snapshot_sync->format;
832
 
            }
833
 
            mode = dev_info->blockdev_snapshot_sync->mode;
834
 
            break;
835
 
        default:
836
 
            abort();
837
 
        }
838
 
 
839
 
        drv = bdrv_find_format(format);
840
 
        if (!drv) {
841
 
            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
842
 
            goto delete_and_fail;
843
 
        }
844
 
 
845
 
        states->old_bs = bdrv_find(device);
846
 
        if (!states->old_bs) {
847
 
            error_set(errp, QERR_DEVICE_NOT_FOUND, device);
848
 
            goto delete_and_fail;
849
 
        }
850
 
 
851
 
        if (!bdrv_is_inserted(states->old_bs)) {
852
 
            error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
853
 
            goto delete_and_fail;
854
 
        }
855
 
 
856
 
        if (bdrv_in_use(states->old_bs)) {
857
 
            error_set(errp, QERR_DEVICE_IN_USE, device);
858
 
            goto delete_and_fail;
859
 
        }
860
 
 
861
 
        if (!bdrv_is_read_only(states->old_bs)) {
862
 
            if (bdrv_flush(states->old_bs)) {
863
 
                error_set(errp, QERR_IO_ERROR);
864
 
                goto delete_and_fail;
865
 
            }
866
 
        }
867
 
 
868
 
        flags = states->old_bs->open_flags;
869
 
 
870
 
        proto_drv = bdrv_find_protocol(new_image_file);
871
 
        if (!proto_drv) {
872
 
            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
873
 
            goto delete_and_fail;
874
 
        }
875
 
 
876
 
        /* create new image w/backing file */
877
 
        if (mode != NEW_IMAGE_MODE_EXISTING) {
878
 
            bdrv_img_create(new_image_file, format,
879
 
                            states->old_bs->filename,
880
 
                            states->old_bs->drv->format_name,
881
 
                            NULL, -1, flags, &local_err, false);
882
 
            if (error_is_set(&local_err)) {
883
 
                error_propagate(errp, local_err);
884
 
                goto delete_and_fail;
885
 
            }
886
 
        }
887
 
 
888
 
        /* We will manually add the backing_hd field to the bs later */
889
 
        states->new_bs = bdrv_new("");
890
 
        /* TODO Inherit bs->options or only take explicit options with an
891
 
         * extended QMP command? */
892
 
        ret = bdrv_open(states->new_bs, new_image_file, NULL,
893
 
                        flags | BDRV_O_NO_BACKING, drv);
894
 
        if (ret != 0) {
895
 
            error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
 
1105
        assert(dev_info->kind < ARRAY_SIZE(actions));
 
1106
 
 
1107
        ops = &actions[dev_info->kind];
 
1108
        state = g_malloc0(ops->instance_size);
 
1109
        state->ops = ops;
 
1110
        state->action = dev_info;
 
1111
        QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, state, entry);
 
1112
 
 
1113
        state->ops->prepare(state, &local_err);
 
1114
        if (error_is_set(&local_err)) {
 
1115
            error_propagate(errp, local_err);
896
1116
            goto delete_and_fail;
897
1117
        }
898
1118
    }
899
1119
 
900
 
 
901
 
    /* Now we are going to do the actual pivot.  Everything up to this point
902
 
     * is reversible, but we are committed at this point */
903
 
    QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
904
 
        /* This removes our old bs from the bdrv_states, and adds the new bs */
905
 
        bdrv_append(states->new_bs, states->old_bs);
906
 
        /* We don't need (or want) to use the transactional
907
 
         * bdrv_reopen_multiple() across all the entries at once, because we
908
 
         * don't want to abort all of them if one of them fails the reopen */
909
 
        bdrv_reopen(states->new_bs, states->new_bs->open_flags & ~BDRV_O_RDWR,
910
 
                    NULL);
 
1120
    QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) {
 
1121
        if (state->ops->commit) {
 
1122
            state->ops->commit(state);
 
1123
        }
911
1124
    }
912
1125
 
913
1126
    /* success */
918
1131
    * failure, and it is all-or-none; abandon each new bs, and keep using
919
1132
    * the original bs for all images
920
1133
    */
921
 
    QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
922
 
        if (states->new_bs) {
923
 
             bdrv_delete(states->new_bs);
 
1134
    QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) {
 
1135
        if (state->ops->abort) {
 
1136
            state->ops->abort(state);
924
1137
        }
925
1138
    }
926
1139
exit:
927
 
    QSIMPLEQ_FOREACH_SAFE(states, &snap_bdrv_states, entry, next) {
928
 
        g_free(states);
 
1140
    QSIMPLEQ_FOREACH_SAFE(state, &snap_bdrv_states, entry, next) {
 
1141
        if (state->ops->clean) {
 
1142
            state->ops->clean(state);
 
1143
        }
 
1144
        g_free(state);
929
1145
    }
930
1146
}
931
1147
 
990
1206
                                    int bdrv_flags, BlockDriver *drv,
991
1207
                                    const char *password, Error **errp)
992
1208
{
993
 
    if (bdrv_open(bs, filename, NULL, bdrv_flags, drv) < 0) {
994
 
        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
 
1209
    int ret;
 
1210
 
 
1211
    ret = bdrv_open(bs, filename, NULL, bdrv_flags, drv);
 
1212
    if (ret < 0) {
 
1213
        error_setg_file_open(errp, -ret, filename);
995
1214
        return;
996
1215
    }
997
1216
 
1024
1243
    }
1025
1244
 
1026
1245
    if (format) {
1027
 
        drv = bdrv_find_whitelisted_format(format);
 
1246
        drv = bdrv_find_whitelisted_format(format, bs->read_only);
1028
1247
        if (!drv) {
1029
1248
            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
1030
1249
            return;
1108
1327
     */
1109
1328
    if (bdrv_get_attached_dev(bs)) {
1110
1329
        bdrv_make_anon(bs);
 
1330
 
 
1331
        /* Further I/O must not pause the guest */
 
1332
        bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
 
1333
                          BLOCKDEV_ON_ERROR_REPORT);
1111
1334
    } else {
1112
1335
        drive_uninit(drive_get_by_blockdev(bs));
1113
1336
    }
1281
1504
    drive_get_ref(drive_get_by_blockdev(bs));
1282
1505
}
1283
1506
 
 
1507
void qmp_drive_backup(const char *device, const char *target,
 
1508
                      bool has_format, const char *format,
 
1509
                      enum MirrorSyncMode sync,
 
1510
                      bool has_mode, enum NewImageMode mode,
 
1511
                      bool has_speed, int64_t speed,
 
1512
                      bool has_on_source_error, BlockdevOnError on_source_error,
 
1513
                      bool has_on_target_error, BlockdevOnError on_target_error,
 
1514
                      Error **errp)
 
1515
{
 
1516
    BlockDriverState *bs;
 
1517
    BlockDriverState *target_bs;
 
1518
    BlockDriverState *source = NULL;
 
1519
    BlockDriver *drv = NULL;
 
1520
    Error *local_err = NULL;
 
1521
    int flags;
 
1522
    int64_t size;
 
1523
    int ret;
 
1524
 
 
1525
    if (!has_speed) {
 
1526
        speed = 0;
 
1527
    }
 
1528
    if (!has_on_source_error) {
 
1529
        on_source_error = BLOCKDEV_ON_ERROR_REPORT;
 
1530
    }
 
1531
    if (!has_on_target_error) {
 
1532
        on_target_error = BLOCKDEV_ON_ERROR_REPORT;
 
1533
    }
 
1534
    if (!has_mode) {
 
1535
        mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
 
1536
    }
 
1537
 
 
1538
    bs = bdrv_find(device);
 
1539
    if (!bs) {
 
1540
        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
 
1541
        return;
 
1542
    }
 
1543
 
 
1544
    if (!bdrv_is_inserted(bs)) {
 
1545
        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
 
1546
        return;
 
1547
    }
 
1548
 
 
1549
    if (!has_format) {
 
1550
        format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;
 
1551
    }
 
1552
    if (format) {
 
1553
        drv = bdrv_find_format(format);
 
1554
        if (!drv) {
 
1555
            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
 
1556
            return;
 
1557
        }
 
1558
    }
 
1559
 
 
1560
    if (bdrv_in_use(bs)) {
 
1561
        error_set(errp, QERR_DEVICE_IN_USE, device);
 
1562
        return;
 
1563
    }
 
1564
 
 
1565
    flags = bs->open_flags | BDRV_O_RDWR;
 
1566
 
 
1567
    /* See if we have a backing HD we can use to create our new image
 
1568
     * on top of. */
 
1569
    if (sync == MIRROR_SYNC_MODE_TOP) {
 
1570
        source = bs->backing_hd;
 
1571
        if (!source) {
 
1572
            sync = MIRROR_SYNC_MODE_FULL;
 
1573
        }
 
1574
    }
 
1575
    if (sync == MIRROR_SYNC_MODE_NONE) {
 
1576
        source = bs;
 
1577
    }
 
1578
 
 
1579
    size = bdrv_getlength(bs);
 
1580
    if (size < 0) {
 
1581
        error_setg_errno(errp, -size, "bdrv_getlength failed");
 
1582
        return;
 
1583
    }
 
1584
 
 
1585
    if (mode != NEW_IMAGE_MODE_EXISTING) {
 
1586
        assert(format && drv);
 
1587
        if (source) {
 
1588
            bdrv_img_create(target, format, source->filename,
 
1589
                            source->drv->format_name, NULL,
 
1590
                            size, flags, &local_err, false);
 
1591
        } else {
 
1592
            bdrv_img_create(target, format, NULL, NULL, NULL,
 
1593
                            size, flags, &local_err, false);
 
1594
        }
 
1595
    }
 
1596
 
 
1597
    if (error_is_set(&local_err)) {
 
1598
        error_propagate(errp, local_err);
 
1599
        return;
 
1600
    }
 
1601
 
 
1602
    target_bs = bdrv_new("");
 
1603
    ret = bdrv_open(target_bs, target, NULL, flags, drv);
 
1604
    if (ret < 0) {
 
1605
        bdrv_delete(target_bs);
 
1606
        error_setg_file_open(errp, -ret, target);
 
1607
        return;
 
1608
    }
 
1609
 
 
1610
    backup_start(bs, target_bs, speed, sync, on_source_error, on_target_error,
 
1611
                 block_job_cb, bs, &local_err);
 
1612
    if (local_err != NULL) {
 
1613
        bdrv_delete(target_bs);
 
1614
        error_propagate(errp, local_err);
 
1615
        return;
 
1616
    }
 
1617
 
 
1618
    /* Grab a reference so hotplug does not delete the BlockDriverState from
 
1619
     * underneath us.
 
1620
     */
 
1621
    drive_get_ref(drive_get_by_blockdev(bs));
 
1622
}
 
1623
 
1284
1624
#define DEFAULT_MIRROR_BUF_SIZE   (10 << 20)
1285
1625
 
1286
1626
void qmp_drive_mirror(const char *device, const char *target,
1296
1636
{
1297
1637
    BlockDriverState *bs;
1298
1638
    BlockDriverState *source, *target_bs;
1299
 
    BlockDriver *proto_drv;
1300
1639
    BlockDriver *drv = NULL;
1301
1640
    Error *local_err = NULL;
1302
1641
    int flags;
1303
 
    uint64_t size;
 
1642
    int64_t size;
1304
1643
    int ret;
1305
1644
 
1306
1645
    if (!has_speed) {
1364
1703
        sync = MIRROR_SYNC_MODE_FULL;
1365
1704
    }
1366
1705
 
1367
 
    proto_drv = bdrv_find_protocol(target);
1368
 
    if (!proto_drv) {
1369
 
        error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
 
1706
    size = bdrv_getlength(bs);
 
1707
    if (size < 0) {
 
1708
        error_setg_errno(errp, -size, "bdrv_getlength failed");
1370
1709
        return;
1371
1710
    }
1372
1711
 
1373
 
    bdrv_get_geometry(bs, &size);
1374
 
    size *= 512;
1375
1712
    if (sync == MIRROR_SYNC_MODE_FULL && mode != NEW_IMAGE_MODE_EXISTING) {
1376
1713
        /* create new image w/o backing file */
1377
1714
        assert(format && drv);
1404
1741
     */
1405
1742
    target_bs = bdrv_new("");
1406
1743
    ret = bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKING, drv);
1407
 
 
1408
1744
    if (ret < 0) {
1409
1745
        bdrv_delete(target_bs);
1410
 
        error_set(errp, QERR_OPEN_FILE_FAILED, target);
 
1746
        error_setg_file_open(errp, -ret, target);
1411
1747
        return;
1412
1748
    }
1413
1749
 
1585
1921
            .type = QEMU_OPT_STRING,
1586
1922
            .help = "discard operation (ignore/off, unmap/on)",
1587
1923
        },{
 
1924
            .name = "cache.writeback",
 
1925
            .type = QEMU_OPT_BOOL,
 
1926
            .help = "enables writeback mode for any caches",
 
1927
        },{
 
1928
            .name = "cache.direct",
 
1929
            .type = QEMU_OPT_BOOL,
 
1930
            .help = "enables use of O_DIRECT (bypass the host page cache)",
 
1931
        },{
 
1932
            .name = "cache.no-flush",
 
1933
            .type = QEMU_OPT_BOOL,
 
1934
            .help = "ignore any flush requests for the device",
 
1935
        },{
 
1936
            .name = "aio",
 
1937
            .type = QEMU_OPT_STRING,
 
1938
            .help = "host AIO implementation (threads, native)",
 
1939
        },{
 
1940
            .name = "format",
 
1941
            .type = QEMU_OPT_STRING,
 
1942
            .help = "disk format (raw, qcow2, ...)",
 
1943
        },{
 
1944
            .name = "serial",
 
1945
            .type = QEMU_OPT_STRING,
 
1946
            .help = "disk serial number",
 
1947
        },{
 
1948
            .name = "rerror",
 
1949
            .type = QEMU_OPT_STRING,
 
1950
            .help = "read error action",
 
1951
        },{
 
1952
            .name = "werror",
 
1953
            .type = QEMU_OPT_STRING,
 
1954
            .help = "write error action",
 
1955
        },{
 
1956
            .name = "addr",
 
1957
            .type = QEMU_OPT_STRING,
 
1958
            .help = "pci address (virtio only)",
 
1959
        },{
 
1960
            .name = "read-only",
 
1961
            .type = QEMU_OPT_BOOL,
 
1962
            .help = "open drive file as read-only",
 
1963
        },{
 
1964
            .name = "throttling.iops-total",
 
1965
            .type = QEMU_OPT_NUMBER,
 
1966
            .help = "limit total I/O operations per second",
 
1967
        },{
 
1968
            .name = "throttling.iops-read",
 
1969
            .type = QEMU_OPT_NUMBER,
 
1970
            .help = "limit read operations per second",
 
1971
        },{
 
1972
            .name = "throttling.iops-write",
 
1973
            .type = QEMU_OPT_NUMBER,
 
1974
            .help = "limit write operations per second",
 
1975
        },{
 
1976
            .name = "throttling.bps-total",
 
1977
            .type = QEMU_OPT_NUMBER,
 
1978
            .help = "limit total bytes per second",
 
1979
        },{
 
1980
            .name = "throttling.bps-read",
 
1981
            .type = QEMU_OPT_NUMBER,
 
1982
            .help = "limit read bytes per second",
 
1983
        },{
 
1984
            .name = "throttling.bps-write",
 
1985
            .type = QEMU_OPT_NUMBER,
 
1986
            .help = "limit write bytes per second",
 
1987
        },{
 
1988
            .name = "copy-on-read",
 
1989
            .type = QEMU_OPT_BOOL,
 
1990
            .help = "copy read data from backing file into image file",
 
1991
        },{
 
1992
            .name = "boot",
 
1993
            .type = QEMU_OPT_BOOL,
 
1994
            .help = "(deprecated, ignored)",
 
1995
        },
 
1996
        { /* end of list */ }
 
1997
    },
 
1998
};
 
1999
 
 
2000
QemuOptsList qemu_old_drive_opts = {
 
2001
    .name = "drive",
 
2002
    .head = QTAILQ_HEAD_INITIALIZER(qemu_old_drive_opts.head),
 
2003
    .desc = {
 
2004
        {
 
2005
            .name = "bus",
 
2006
            .type = QEMU_OPT_NUMBER,
 
2007
            .help = "bus number",
 
2008
        },{
 
2009
            .name = "unit",
 
2010
            .type = QEMU_OPT_NUMBER,
 
2011
            .help = "unit number (i.e. lun for scsi)",
 
2012
        },{
 
2013
            .name = "if",
 
2014
            .type = QEMU_OPT_STRING,
 
2015
            .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
 
2016
        },{
 
2017
            .name = "index",
 
2018
            .type = QEMU_OPT_NUMBER,
 
2019
            .help = "index number",
 
2020
        },{
 
2021
            .name = "cyls",
 
2022
            .type = QEMU_OPT_NUMBER,
 
2023
            .help = "number of cylinders (ide disk geometry)",
 
2024
        },{
 
2025
            .name = "heads",
 
2026
            .type = QEMU_OPT_NUMBER,
 
2027
            .help = "number of heads (ide disk geometry)",
 
2028
        },{
 
2029
            .name = "secs",
 
2030
            .type = QEMU_OPT_NUMBER,
 
2031
            .help = "number of sectors (ide disk geometry)",
 
2032
        },{
 
2033
            .name = "trans",
 
2034
            .type = QEMU_OPT_STRING,
 
2035
            .help = "chs translation (auto, lba. none)",
 
2036
        },{
 
2037
            .name = "media",
 
2038
            .type = QEMU_OPT_STRING,
 
2039
            .help = "media type (disk, cdrom)",
 
2040
        },{
 
2041
            .name = "snapshot",
 
2042
            .type = QEMU_OPT_BOOL,
 
2043
            .help = "enable/disable snapshot mode",
 
2044
        },{
 
2045
            .name = "file",
 
2046
            .type = QEMU_OPT_STRING,
 
2047
            .help = "disk image",
 
2048
        },{
 
2049
            .name = "discard",
 
2050
            .type = QEMU_OPT_STRING,
 
2051
            .help = "discard operation (ignore/off, unmap/on)",
 
2052
        },{
1588
2053
            .name = "cache",
1589
2054
            .type = QEMU_OPT_STRING,
1590
2055
            .help = "host cache usage (none, writeback, writethrough, "
1658
2123
    .name = "drive",
1659
2124
    .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
1660
2125
    .desc = {
1661
 
        {
1662
 
            .name = "bus",
1663
 
            .type = QEMU_OPT_NUMBER,
1664
 
            .help = "bus number",
1665
 
        },{
1666
 
            .name = "unit",
1667
 
            .type = QEMU_OPT_NUMBER,
1668
 
            .help = "unit number (i.e. lun for scsi)",
1669
 
        },{
1670
 
            .name = "if",
1671
 
            .type = QEMU_OPT_STRING,
1672
 
            .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
1673
 
        },{
1674
 
            .name = "index",
1675
 
            .type = QEMU_OPT_NUMBER,
1676
 
            .help = "index number",
1677
 
        },{
1678
 
            .name = "cyls",
1679
 
            .type = QEMU_OPT_NUMBER,
1680
 
            .help = "number of cylinders (ide disk geometry)",
1681
 
        },{
1682
 
            .name = "heads",
1683
 
            .type = QEMU_OPT_NUMBER,
1684
 
            .help = "number of heads (ide disk geometry)",
1685
 
        },{
1686
 
            .name = "secs",
1687
 
            .type = QEMU_OPT_NUMBER,
1688
 
            .help = "number of sectors (ide disk geometry)",
1689
 
        },{
1690
 
            .name = "trans",
1691
 
            .type = QEMU_OPT_STRING,
1692
 
            .help = "chs translation (auto, lba. none)",
1693
 
        },{
1694
 
            .name = "media",
1695
 
            .type = QEMU_OPT_STRING,
1696
 
            .help = "media type (disk, cdrom)",
1697
 
        },{
1698
 
            .name = "snapshot",
1699
 
            .type = QEMU_OPT_BOOL,
1700
 
            .help = "enable/disable snapshot mode",
1701
 
        },{
1702
 
            .name = "file",
1703
 
            .type = QEMU_OPT_STRING,
1704
 
            .help = "disk image",
1705
 
        },{
1706
 
            .name = "discard",
1707
 
            .type = QEMU_OPT_STRING,
1708
 
            .help = "discard operation (ignore/off, unmap/on)",
1709
 
        },{
1710
 
            .name = "cache",
1711
 
            .type = QEMU_OPT_STRING,
1712
 
            .help = "host cache usage (none, writeback, writethrough, "
1713
 
                    "directsync, unsafe)",
1714
 
        },{
1715
 
            .name = "aio",
1716
 
            .type = QEMU_OPT_STRING,
1717
 
            .help = "host AIO implementation (threads, native)",
1718
 
        },{
1719
 
            .name = "format",
1720
 
            .type = QEMU_OPT_STRING,
1721
 
            .help = "disk format (raw, qcow2, ...)",
1722
 
        },{
1723
 
            .name = "serial",
1724
 
            .type = QEMU_OPT_STRING,
1725
 
            .help = "disk serial number",
1726
 
        },{
1727
 
            .name = "rerror",
1728
 
            .type = QEMU_OPT_STRING,
1729
 
            .help = "read error action",
1730
 
        },{
1731
 
            .name = "werror",
1732
 
            .type = QEMU_OPT_STRING,
1733
 
            .help = "write error action",
1734
 
        },{
1735
 
            .name = "addr",
1736
 
            .type = QEMU_OPT_STRING,
1737
 
            .help = "pci address (virtio only)",
1738
 
        },{
1739
 
            .name = "readonly",
1740
 
            .type = QEMU_OPT_BOOL,
1741
 
            .help = "open drive file as read-only",
1742
 
        },{
1743
 
            .name = "iops",
1744
 
            .type = QEMU_OPT_NUMBER,
1745
 
            .help = "limit total I/O operations per second",
1746
 
        },{
1747
 
            .name = "iops_rd",
1748
 
            .type = QEMU_OPT_NUMBER,
1749
 
            .help = "limit read operations per second",
1750
 
        },{
1751
 
            .name = "iops_wr",
1752
 
            .type = QEMU_OPT_NUMBER,
1753
 
            .help = "limit write operations per second",
1754
 
        },{
1755
 
            .name = "bps",
1756
 
            .type = QEMU_OPT_NUMBER,
1757
 
            .help = "limit total bytes per second",
1758
 
        },{
1759
 
            .name = "bps_rd",
1760
 
            .type = QEMU_OPT_NUMBER,
1761
 
            .help = "limit read bytes per second",
1762
 
        },{
1763
 
            .name = "bps_wr",
1764
 
            .type = QEMU_OPT_NUMBER,
1765
 
            .help = "limit write bytes per second",
1766
 
        },{
1767
 
            .name = "copy-on-read",
1768
 
            .type = QEMU_OPT_BOOL,
1769
 
            .help = "copy read data from backing file into image file",
1770
 
        },{
1771
 
            .name = "boot",
1772
 
            .type = QEMU_OPT_BOOL,
1773
 
            .help = "(deprecated, ignored)",
1774
 
        },
 
2126
        /*
 
2127
         * no elements => accept any params
 
2128
         * validation will happen later
 
2129
         */
1775
2130
        { /* end of list */ }
1776
2131
    },
1777
2132
};