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

« back to all changes in this revision

Viewing changes to block/qed.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:
273
273
    return l2_table;
274
274
}
275
275
 
276
 
static void qed_aio_next_io(void *opaque, int ret);
 
276
static void qed_aio_next_io(QEDAIOCB *acb, int ret);
 
277
 
 
278
static void qed_aio_start_io(QEDAIOCB *acb)
 
279
{
 
280
    qed_aio_next_io(acb, 0);
 
281
}
 
282
 
 
283
static void qed_aio_next_io_cb(void *opaque, int ret)
 
284
{
 
285
    QEDAIOCB *acb = opaque;
 
286
 
 
287
    qed_aio_next_io(acb, ret);
 
288
}
277
289
 
278
290
static void qed_plug_allocating_write_reqs(BDRVQEDState *s)
279
291
{
292
304
 
293
305
    acb = QSIMPLEQ_FIRST(&s->allocating_write_reqs);
294
306
    if (acb) {
295
 
        qed_aio_next_io(acb, 0);
 
307
        qed_aio_start_io(acb);
296
308
    }
297
309
}
298
310
 
333
345
 
334
346
    trace_qed_need_check_timer_cb(s);
335
347
 
 
348
    qed_acquire(s);
336
349
    qed_plug_allocating_write_reqs(s);
337
350
 
338
351
    /* Ensure writes are on disk before clearing flag */
339
352
    bdrv_aio_flush(s->bs->file->bs, qed_clear_need_check, s);
 
353
    qed_release(s);
 
354
}
 
355
 
 
356
void qed_acquire(BDRVQEDState *s)
 
357
{
 
358
    aio_context_acquire(bdrv_get_aio_context(s->bs));
 
359
}
 
360
 
 
361
void qed_release(BDRVQEDState *s)
 
362
{
 
363
    aio_context_release(bdrv_get_aio_context(s->bs));
340
364
}
341
365
 
342
366
static void qed_start_need_check_timer(BDRVQEDState *s)
391
415
    }
392
416
}
393
417
 
394
 
static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
395
 
                         Error **errp)
 
418
static int bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flags,
 
419
                            Error **errp)
396
420
{
397
421
    BDRVQEDState *s = bs->opaque;
398
422
    QEDHeader le_header;
526
550
    return ret;
527
551
}
528
552
 
 
553
static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
 
554
                         Error **errp)
 
555
{
 
556
    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
 
557
                               false, errp);
 
558
    if (!bs->file) {
 
559
        return -EINVAL;
 
560
    }
 
561
 
 
562
    return bdrv_qed_do_open(bs, options, flags, errp);
 
563
}
 
564
 
529
565
static void bdrv_qed_refresh_limits(BlockDriverState *bs, Error **errp)
530
566
{
531
567
    BDRVQEDState *s = bs->opaque;
589
625
    }
590
626
 
591
627
    blk = blk_new_open(filename, NULL, NULL,
592
 
                       BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
 
628
                       BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
 
629
                       &local_err);
593
630
    if (blk == NULL) {
594
631
        error_propagate(errp, local_err);
595
632
        return -EIO;
721
758
    }
722
759
 
723
760
    if (cb->co) {
724
 
        qemu_coroutine_enter(cb->co);
 
761
        aio_co_wake(cb->co);
725
762
    }
726
763
}
727
764
 
918
955
static void qed_aio_complete_bh(void *opaque)
919
956
{
920
957
    QEDAIOCB *acb = opaque;
 
958
    BDRVQEDState *s = acb_to_s(acb);
921
959
    BlockCompletionFunc *cb = acb->common.cb;
922
960
    void *user_opaque = acb->common.opaque;
923
961
    int ret = acb->bh_ret;
925
963
    qemu_aio_unref(acb);
926
964
 
927
965
    /* Invoke callback */
 
966
    qed_acquire(s);
928
967
    cb(user_opaque, ret);
 
968
    qed_release(s);
929
969
}
930
970
 
931
971
static void qed_aio_complete(QEDAIOCB *acb, int ret)
959
999
        QSIMPLEQ_REMOVE_HEAD(&s->allocating_write_reqs, next);
960
1000
        acb = QSIMPLEQ_FIRST(&s->allocating_write_reqs);
961
1001
        if (acb) {
962
 
            qed_aio_next_io(acb, 0);
 
1002
            qed_aio_start_io(acb);
963
1003
        } else if (s->header.features & QED_F_NEED_CHECK) {
964
1004
            qed_start_need_check_timer(s);
965
1005
        }
984
1024
    acb->request.l2_table = qed_find_l2_cache_entry(&s->l2_cache, l2_offset);
985
1025
    assert(acb->request.l2_table != NULL);
986
1026
 
987
 
    qed_aio_next_io(opaque, ret);
 
1027
    qed_aio_next_io(acb, ret);
988
1028
}
989
1029
 
990
1030
/**
1032
1072
    if (need_alloc) {
1033
1073
        /* Write out the whole new L2 table */
1034
1074
        qed_write_l2_table(s, &acb->request, 0, s->table_nelems, true,
1035
 
                            qed_aio_write_l1_update, acb);
 
1075
                           qed_aio_write_l1_update, acb);
1036
1076
    } else {
1037
1077
        /* Write out only the updated part of the L2 table */
1038
1078
        qed_write_l2_table(s, &acb->request, index, acb->cur_nclusters, false,
1039
 
                            qed_aio_next_io, acb);
 
1079
                           qed_aio_next_io_cb, acb);
1040
1080
    }
1041
1081
    return;
1042
1082
 
1088
1128
    }
1089
1129
 
1090
1130
    if (acb->find_cluster_ret == QED_CLUSTER_FOUND) {
1091
 
        next_fn = qed_aio_next_io;
 
1131
        next_fn = qed_aio_next_io_cb;
1092
1132
    } else {
1093
1133
        if (s->bs->backing) {
1094
1134
            next_fn = qed_aio_write_flush_before_l2_update;
1201
1241
    if (acb->flags & QED_AIOCB_ZERO) {
1202
1242
        /* Skip ahead if the clusters are already zero */
1203
1243
        if (acb->find_cluster_ret == QED_CLUSTER_ZERO) {
1204
 
            qed_aio_next_io(acb, 0);
 
1244
            qed_aio_start_io(acb);
1205
1245
            return;
1206
1246
        }
1207
1247
 
1321
1361
    /* Handle zero cluster and backing file reads */
1322
1362
    if (ret == QED_CLUSTER_ZERO) {
1323
1363
        qemu_iovec_memset(&acb->cur_qiov, 0, 0, acb->cur_qiov.size);
1324
 
        qed_aio_next_io(acb, 0);
 
1364
        qed_aio_start_io(acb);
1325
1365
        return;
1326
1366
    } else if (ret != QED_CLUSTER_FOUND) {
1327
1367
        qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov,
1328
 
                              &acb->backing_qiov, qed_aio_next_io, acb);
 
1368
                              &acb->backing_qiov, qed_aio_next_io_cb, acb);
1329
1369
        return;
1330
1370
    }
1331
1371
 
1332
1372
    BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
1333
1373
    bdrv_aio_readv(bs->file, offset / BDRV_SECTOR_SIZE,
1334
1374
                   &acb->cur_qiov, acb->cur_qiov.size / BDRV_SECTOR_SIZE,
1335
 
                   qed_aio_next_io, acb);
 
1375
                   qed_aio_next_io_cb, acb);
1336
1376
    return;
1337
1377
 
1338
1378
err:
1342
1382
/**
1343
1383
 * Begin next I/O or complete the request
1344
1384
 */
1345
 
static void qed_aio_next_io(void *opaque, int ret)
 
1385
static void qed_aio_next_io(QEDAIOCB *acb, int ret)
1346
1386
{
1347
 
    QEDAIOCB *acb = opaque;
1348
1387
    BDRVQEDState *s = acb_to_s(acb);
1349
1388
    QEDFindClusterFunc *io_fn = (acb->flags & QED_AIOCB_WRITE) ?
1350
1389
                                qed_aio_write_data : qed_aio_read_data;
1400
1439
    qemu_iovec_init(&acb->cur_qiov, qiov->niov);
1401
1440
 
1402
1441
    /* Start request */
1403
 
    qed_aio_next_io(acb, 0);
 
1442
    qed_aio_start_io(acb);
1404
1443
    return &acb->common;
1405
1444
}
1406
1445
 
1436
1475
    cb->done = true;
1437
1476
    cb->ret = ret;
1438
1477
    if (cb->co) {
1439
 
        qemu_coroutine_enter(cb->co);
 
1478
        aio_co_wake(cb->co);
1440
1479
    }
1441
1480
}
1442
1481
 
1603
1642
    bdrv_qed_close(bs);
1604
1643
 
1605
1644
    memset(s, 0, sizeof(BDRVQEDState));
1606
 
    ret = bdrv_qed_open(bs, NULL, bs->open_flags, &local_err);
 
1645
    ret = bdrv_qed_do_open(bs, NULL, bs->open_flags, &local_err);
1607
1646
    if (local_err) {
1608
1647
        error_propagate(errp, local_err);
1609
1648
        error_prepend(errp, "Could not reopen qed layer: ");
1666
1705
    .bdrv_open                = bdrv_qed_open,
1667
1706
    .bdrv_close               = bdrv_qed_close,
1668
1707
    .bdrv_reopen_prepare      = bdrv_qed_reopen_prepare,
 
1708
    .bdrv_child_perm          = bdrv_format_default_perms,
1669
1709
    .bdrv_create              = bdrv_qed_create,
1670
1710
    .bdrv_has_zero_init       = bdrv_has_zero_init_1,
1671
1711
    .bdrv_co_get_block_status = bdrv_qed_co_get_block_status,