~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to blockdev.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include "sysemu/sysemu.h"
49
49
#include "block/block_int.h"
50
50
#include "qmp-commands.h"
51
 
#include "trace.h"
 
51
#include "block/trace.h"
52
52
#include "sysemu/arch_init.h"
53
53
#include "qemu/cutils.h"
54
54
#include "qemu/help_option.h"
 
55
#include "qemu/throttle-options.h"
55
56
 
56
57
static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =
57
58
    QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states);
227
228
    return NULL;
228
229
}
229
230
 
230
 
bool drive_check_orphaned(void)
 
231
void drive_check_orphaned(void)
231
232
{
232
233
    BlockBackend *blk;
233
234
    DriveInfo *dinfo;
234
 
    bool rs = false;
 
235
    Location loc;
 
236
    bool orphans = false;
235
237
 
236
238
    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
237
239
        dinfo = blk_legacy_dinfo(blk);
238
 
        /* If dinfo->bdrv->dev is NULL, it has no device attached. */
239
 
        /* Unless this is a default drive, this may be an oversight. */
240
240
        if (!blk_get_attached_dev(blk) && !dinfo->is_default &&
241
241
            dinfo->type != IF_NONE) {
242
 
            fprintf(stderr, "Warning: Orphaned drive without device: "
243
 
                    "id=%s,file=%s,if=%s,bus=%d,unit=%d\n",
244
 
                    blk_name(blk), blk_bs(blk) ? blk_bs(blk)->filename : "",
245
 
                    if_name[dinfo->type], dinfo->bus, dinfo->unit);
246
 
            rs = true;
 
242
            loc_push_none(&loc);
 
243
            qemu_opts_loc_restore(dinfo->opts);
 
244
            error_report("machine type does not support"
 
245
                         " if=%s,bus=%d,unit=%d",
 
246
                         if_name[dinfo->type], dinfo->bus, dinfo->unit);
 
247
            loc_pop(&loc);
 
248
            orphans = true;
247
249
        }
248
250
    }
249
251
 
250
 
    return rs;
 
252
    if (orphans) {
 
253
        exit(1);
 
254
    }
251
255
}
252
256
 
253
257
DriveInfo *drive_get_by_index(BlockInterfaceType type, int index)
554
558
    if ((!file || !*file) && !qdict_size(bs_opts)) {
555
559
        BlockBackendRootState *blk_rs;
556
560
 
557
 
        blk = blk_new();
 
561
        blk = blk_new(0, BLK_PERM_ALL);
558
562
        blk_rs = blk_get_root_state(blk);
559
563
        blk_rs->open_flags    = bdrv_flags;
560
564
        blk_rs->read_only     = read_only;
1610
1614
    BlockDriverState *old_bs;
1611
1615
    BlockDriverState *new_bs;
1612
1616
    AioContext *aio_context;
 
1617
    bool overlay_appended;
1613
1618
} ExternalSnapshotState;
1614
1619
 
1615
1620
static void external_snapshot_prepare(BlkActionState *common,
1764
1769
 
1765
1770
    if (!state->new_bs->drv->supports_backing) {
1766
1771
        error_setg(errp, "The snapshot does not support backing images");
1767
 
    }
 
1772
        return;
 
1773
    }
 
1774
 
 
1775
    bdrv_set_aio_context(state->new_bs, state->aio_context);
 
1776
 
 
1777
    /* This removes our old bs and adds the new bs. This is an operation that
 
1778
     * can fail, so we need to do it in .prepare; undoing it for abort is
 
1779
     * always possible. */
 
1780
    bdrv_ref(state->new_bs);
 
1781
    bdrv_append(state->new_bs, state->old_bs, &local_err);
 
1782
    if (local_err) {
 
1783
        error_propagate(errp, local_err);
 
1784
        return;
 
1785
    }
 
1786
    state->overlay_appended = true;
1768
1787
}
1769
1788
 
1770
1789
static void external_snapshot_commit(BlkActionState *common)
1772
1791
    ExternalSnapshotState *state =
1773
1792
                             DO_UPCAST(ExternalSnapshotState, common, common);
1774
1793
 
1775
 
    bdrv_set_aio_context(state->new_bs, state->aio_context);
1776
 
 
1777
 
    /* This removes our old bs and adds the new bs */
1778
 
    bdrv_append(state->new_bs, state->old_bs);
1779
1794
    /* We don't need (or want) to use the transactional
1780
1795
     * bdrv_reopen_multiple() across all the entries at once, because we
1781
1796
     * don't want to abort all of them if one of them fails the reopen */
1790
1805
    ExternalSnapshotState *state =
1791
1806
                             DO_UPCAST(ExternalSnapshotState, common, common);
1792
1807
    if (state->new_bs) {
1793
 
        bdrv_unref(state->new_bs);
 
1808
        if (state->overlay_appended) {
 
1809
            bdrv_replace_node(state->new_bs, state->old_bs, &error_abort);
 
1810
        }
1794
1811
    }
1795
1812
}
1796
1813
 
1801
1818
    if (state->aio_context) {
1802
1819
        bdrv_drained_end(state->old_bs);
1803
1820
        aio_context_release(state->aio_context);
 
1821
        bdrv_unref(state->new_bs);
1804
1822
    }
1805
1823
}
1806
1824
 
2029
2047
    BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
2030
2048
                                             common, common);
2031
2049
 
2032
 
    bdrv_undo_clear_dirty_bitmap(state->bitmap, state->backup);
 
2050
    if (state->backup) {
 
2051
        bdrv_undo_clear_dirty_bitmap(state->bitmap, state->backup);
 
2052
    }
2033
2053
}
2034
2054
 
2035
2055
static void block_dirty_bitmap_clear_commit(BlkActionState *common)
2307
2327
    }
2308
2328
 
2309
2329
    if (!locked || force) {
2310
 
        blk_dev_change_media_cb(blk, false);
 
2330
        blk_dev_change_media_cb(blk, false, &error_abort);
2311
2331
    }
2312
2332
 
2313
2333
    if (locked && !force) {
2345
2365
                             Error **errp)
2346
2366
{
2347
2367
    BlockBackend *blk;
 
2368
    Error *local_err = NULL;
2348
2369
 
2349
2370
    device = has_device ? device : NULL;
2350
2371
    id = has_id ? id : NULL;
2368
2389
        return;
2369
2390
    }
2370
2391
 
2371
 
    blk_dev_change_media_cb(blk, true);
 
2392
    blk_dev_change_media_cb(blk, true, &local_err);
 
2393
    if (local_err) {
 
2394
        error_propagate(errp, local_err);
 
2395
        return;
 
2396
    }
2372
2397
}
2373
2398
 
2374
2399
void qmp_x_blockdev_remove_medium(bool has_device, const char *device,
2421
2446
         * called at all); therefore, the medium needs to be ejected here.
2422
2447
         * Do it after blk_remove_bs() so blk_is_inserted(blk) returns the @load
2423
2448
         * value passed here (i.e. false). */
2424
 
        blk_dev_change_media_cb(blk, false);
 
2449
        blk_dev_change_media_cb(blk, false, &error_abort);
2425
2450
    }
2426
2451
 
2427
2452
out:
2431
2456
static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
2432
2457
                                            BlockDriverState *bs, Error **errp)
2433
2458
{
 
2459
    Error *local_err = NULL;
2434
2460
    bool has_device;
 
2461
    int ret;
2435
2462
 
2436
2463
    /* For BBs without a device, we can exchange the BDS tree at will */
2437
2464
    has_device = blk_get_attached_dev(blk);
2451
2478
        return;
2452
2479
    }
2453
2480
 
2454
 
    blk_insert_bs(blk, bs);
 
2481
    ret = blk_insert_bs(blk, bs, errp);
 
2482
    if (ret < 0) {
 
2483
        return;
 
2484
    }
2455
2485
 
2456
2486
    if (!blk_dev_has_tray(blk)) {
2457
2487
        /* For tray-less devices, blockdev-close-tray is a no-op (or may not be
2459
2489
         * slot here.
2460
2490
         * Do it after blk_insert_bs() so blk_is_inserted(blk) returns the @load
2461
2491
         * value passed here (i.e. true). */
2462
 
        blk_dev_change_media_cb(blk, true);
 
2492
        blk_dev_change_media_cb(blk, true, &local_err);
 
2493
        if (local_err) {
 
2494
            error_propagate(errp, local_err);
 
2495
            blk_remove_bs(blk);
 
2496
            return;
 
2497
        }
2463
2498
    }
2464
2499
}
2465
2500
 
2800
2835
 
2801
2836
    bs = bdrv_find_node(id);
2802
2837
    if (bs) {
2803
 
        qmp_x_blockdev_del(id, &local_err);
 
2838
        qmp_blockdev_del(id, &local_err);
2804
2839
        if (local_err) {
2805
2840
            error_report_err(local_err);
2806
2841
        }
2855
2890
                      int64_t size, Error **errp)
2856
2891
{
2857
2892
    Error *local_err = NULL;
 
2893
    BlockBackend *blk = NULL;
2858
2894
    BlockDriverState *bs;
2859
2895
    AioContext *aio_context;
2860
2896
    int ret;
2885
2921
        goto out;
2886
2922
    }
2887
2923
 
 
2924
    blk = blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL);
 
2925
    ret = blk_insert_bs(blk, bs, errp);
 
2926
    if (ret < 0) {
 
2927
        goto out;
 
2928
    }
 
2929
 
2888
2930
    /* complete all in-flight operations before resizing the device */
2889
2931
    bdrv_drain_all();
2890
2932
 
2891
 
    ret = bdrv_truncate(bs, size);
 
2933
    ret = blk_truncate(blk, size);
2892
2934
    switch (ret) {
2893
2935
    case 0:
2894
2936
        break;
2910
2952
    }
2911
2953
 
2912
2954
out:
 
2955
    blk_unref(blk);
2913
2956
    aio_context_release(aio_context);
2914
2957
}
2915
2958
 
3005
3048
                      bool has_top, const char *top,
3006
3049
                      bool has_backing_file, const char *backing_file,
3007
3050
                      bool has_speed, int64_t speed,
 
3051
                      bool has_filter_node_name, const char *filter_node_name,
3008
3052
                      Error **errp)
3009
3053
{
3010
3054
    BlockDriverState *bs;
3020
3064
    if (!has_speed) {
3021
3065
        speed = 0;
3022
3066
    }
 
3067
    if (!has_filter_node_name) {
 
3068
        filter_node_name = NULL;
 
3069
    }
3023
3070
 
3024
3071
    /* Important Note:
3025
3072
     *  libvirt relies on the DeviceNotFound error class in order to probe for
3094
3141
            goto out;
3095
3142
        }
3096
3143
        commit_active_start(has_job_id ? job_id : NULL, bs, base_bs,
3097
 
                            BLOCK_JOB_DEFAULT, speed, on_error, NULL, NULL,
3098
 
                            &local_err, false);
 
3144
                            BLOCK_JOB_DEFAULT, speed, on_error,
 
3145
                            filter_node_name, NULL, NULL, &local_err, false);
3099
3146
    } else {
3100
3147
        BlockDriverState *overlay_bs = bdrv_find_overlay(bs, top_bs);
3101
3148
        if (bdrv_op_is_blocked(overlay_bs, BLOCK_OP_TYPE_COMMIT_TARGET, errp)) {
3103
3150
        }
3104
3151
        commit_start(has_job_id ? job_id : NULL, bs, base_bs, top_bs, speed,
3105
3152
                     on_error, has_backing_file ? backing_file : NULL,
3106
 
                     &local_err);
 
3153
                     filter_node_name, &local_err);
3107
3154
    }
3108
3155
    if (local_err != NULL) {
3109
3156
        error_propagate(errp, local_err);
3339
3386
                                   bool has_on_target_error,
3340
3387
                                   BlockdevOnError on_target_error,
3341
3388
                                   bool has_unmap, bool unmap,
 
3389
                                   bool has_filter_node_name,
 
3390
                                   const char *filter_node_name,
3342
3391
                                   Error **errp)
3343
3392
{
3344
3393
 
3360
3409
    if (!has_unmap) {
3361
3410
        unmap = true;
3362
3411
    }
 
3412
    if (!has_filter_node_name) {
 
3413
        filter_node_name = NULL;
 
3414
    }
3363
3415
 
3364
3416
    if (granularity != 0 && (granularity < 512 || granularity > 1048576 * 64)) {
3365
3417
        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "granularity",
3389
3441
    mirror_start(job_id, bs, target,
3390
3442
                 has_replaces ? replaces : NULL,
3391
3443
                 speed, granularity, buf_size, sync, backing_mode,
3392
 
                 on_source_error, on_target_error, unmap, errp);
 
3444
                 on_source_error, on_target_error, unmap, filter_node_name,
 
3445
                 errp);
3393
3446
}
3394
3447
 
3395
3448
void qmp_drive_mirror(DriveMirror *arg, Error **errp)
3527
3580
                           arg->has_on_source_error, arg->on_source_error,
3528
3581
                           arg->has_on_target_error, arg->on_target_error,
3529
3582
                           arg->has_unmap, arg->unmap,
 
3583
                           false, NULL,
3530
3584
                           &local_err);
3531
3585
    bdrv_unref(target_bs);
3532
3586
    error_propagate(errp, local_err);
3545
3599
                         BlockdevOnError on_source_error,
3546
3600
                         bool has_on_target_error,
3547
3601
                         BlockdevOnError on_target_error,
 
3602
                         bool has_filter_node_name,
 
3603
                         const char *filter_node_name,
3548
3604
                         Error **errp)
3549
3605
{
3550
3606
    BlockDriverState *bs;
3576
3632
                           has_on_source_error, on_source_error,
3577
3633
                           has_on_target_error, on_target_error,
3578
3634
                           true, true,
 
3635
                           has_filter_node_name, filter_node_name,
3579
3636
                           &local_err);
3580
3637
    error_propagate(errp, local_err);
3581
3638
 
3843
3900
    visit_free(v);
3844
3901
}
3845
3902
 
3846
 
void qmp_x_blockdev_del(const char *node_name, Error **errp)
 
3903
void qmp_blockdev_del(const char *node_name, Error **errp)
3847
3904
{
3848
3905
    AioContext *aio_context;
3849
3906
    BlockDriverState *bs;
3999
4056
            .name = BDRV_OPT_READ_ONLY,
4000
4057
            .type = QEMU_OPT_BOOL,
4001
4058
            .help = "open drive file as read-only",
4002
 
        },{
4003
 
            .name = "throttling.iops-total",
4004
 
            .type = QEMU_OPT_NUMBER,
4005
 
            .help = "limit total I/O operations per second",
4006
 
        },{
4007
 
            .name = "throttling.iops-read",
4008
 
            .type = QEMU_OPT_NUMBER,
4009
 
            .help = "limit read operations per second",
4010
 
        },{
4011
 
            .name = "throttling.iops-write",
4012
 
            .type = QEMU_OPT_NUMBER,
4013
 
            .help = "limit write operations per second",
4014
 
        },{
4015
 
            .name = "throttling.bps-total",
4016
 
            .type = QEMU_OPT_NUMBER,
4017
 
            .help = "limit total bytes per second",
4018
 
        },{
4019
 
            .name = "throttling.bps-read",
4020
 
            .type = QEMU_OPT_NUMBER,
4021
 
            .help = "limit read bytes per second",
4022
 
        },{
4023
 
            .name = "throttling.bps-write",
4024
 
            .type = QEMU_OPT_NUMBER,
4025
 
            .help = "limit write bytes per second",
4026
 
        },{
4027
 
            .name = "throttling.iops-total-max",
4028
 
            .type = QEMU_OPT_NUMBER,
4029
 
            .help = "I/O operations burst",
4030
 
        },{
4031
 
            .name = "throttling.iops-read-max",
4032
 
            .type = QEMU_OPT_NUMBER,
4033
 
            .help = "I/O operations read burst",
4034
 
        },{
4035
 
            .name = "throttling.iops-write-max",
4036
 
            .type = QEMU_OPT_NUMBER,
4037
 
            .help = "I/O operations write burst",
4038
 
        },{
4039
 
            .name = "throttling.bps-total-max",
4040
 
            .type = QEMU_OPT_NUMBER,
4041
 
            .help = "total bytes burst",
4042
 
        },{
4043
 
            .name = "throttling.bps-read-max",
4044
 
            .type = QEMU_OPT_NUMBER,
4045
 
            .help = "total bytes read burst",
4046
 
        },{
4047
 
            .name = "throttling.bps-write-max",
4048
 
            .type = QEMU_OPT_NUMBER,
4049
 
            .help = "total bytes write burst",
4050
 
        },{
4051
 
            .name = "throttling.iops-total-max-length",
4052
 
            .type = QEMU_OPT_NUMBER,
4053
 
            .help = "length of the iops-total-max burst period, in seconds",
4054
 
        },{
4055
 
            .name = "throttling.iops-read-max-length",
4056
 
            .type = QEMU_OPT_NUMBER,
4057
 
            .help = "length of the iops-read-max burst period, in seconds",
4058
 
        },{
4059
 
            .name = "throttling.iops-write-max-length",
4060
 
            .type = QEMU_OPT_NUMBER,
4061
 
            .help = "length of the iops-write-max burst period, in seconds",
4062
 
        },{
4063
 
            .name = "throttling.bps-total-max-length",
4064
 
            .type = QEMU_OPT_NUMBER,
4065
 
            .help = "length of the bps-total-max burst period, in seconds",
4066
 
        },{
4067
 
            .name = "throttling.bps-read-max-length",
4068
 
            .type = QEMU_OPT_NUMBER,
4069
 
            .help = "length of the bps-read-max burst period, in seconds",
4070
 
        },{
4071
 
            .name = "throttling.bps-write-max-length",
4072
 
            .type = QEMU_OPT_NUMBER,
4073
 
            .help = "length of the bps-write-max burst period, in seconds",
4074
 
        },{
4075
 
            .name = "throttling.iops-size",
4076
 
            .type = QEMU_OPT_NUMBER,
4077
 
            .help = "when limiting by iops max size of an I/O in bytes",
4078
 
        },{
 
4059
        },
 
4060
 
 
4061
        THROTTLE_OPTS,
 
4062
 
 
4063
        {
4079
4064
            .name = "throttling.group",
4080
4065
            .type = QEMU_OPT_STRING,
4081
4066
            .help = "name of the block throttling group",