Revision 34b5d2c6

b/block.c
552 552
}
553 553

  
554 554
static int find_image_format(BlockDriverState *bs, const char *filename,
555
                             BlockDriver **pdrv)
555
                             BlockDriver **pdrv, Error **errp)
556 556
{
557 557
    int score, score_max;
558 558
    BlockDriver *drv1, *drv;
......
563 563
    if (bs->sg || !bdrv_is_inserted(bs) || bdrv_getlength(bs) == 0) {
564 564
        drv = bdrv_find_format("raw");
565 565
        if (!drv) {
566
            error_setg(errp, "Could not find raw image format");
566 567
            ret = -ENOENT;
567 568
        }
568 569
        *pdrv = drv;
......
571 572

  
572 573
    ret = bdrv_pread(bs, 0, buf, sizeof(buf));
573 574
    if (ret < 0) {
575
        error_setg_errno(errp, -ret, "Could not read image for determining its "
576
                         "format");
574 577
        *pdrv = NULL;
575 578
        return ret;
576 579
    }
......
587 590
        }
588 591
    }
589 592
    if (!drv) {
593
        error_setg(errp, "Could not determine image format: No compatible "
594
                   "driver found");
590 595
        ret = -ENOENT;
591 596
    }
592 597
    *pdrv = drv;
......
706 711
 * Removes all processed options from *options.
707 712
 */
708 713
static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
709
    QDict *options, int flags, BlockDriver *drv)
714
    QDict *options, int flags, BlockDriver *drv, Error **errp)
710 715
{
711 716
    int ret, open_flags;
712 717
    const char *filename;
718
    Error *local_err = NULL;
713 719

  
714 720
    assert(drv != NULL);
715 721
    assert(bs->file == NULL);
......
738 744
    bs->read_only = !(open_flags & BDRV_O_RDWR);
739 745

  
740 746
    if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
747
        error_setg(errp, "Driver '%s' is not whitelisted", drv->format_name);
741 748
        return -ENOTSUP;
742 749
    }
743 750

  
......
761 768
    if (drv->bdrv_file_open) {
762 769
        assert(file == NULL);
763 770
        assert(drv->bdrv_parse_filename || filename != NULL);
764
        ret = drv->bdrv_file_open(bs, options, open_flags, NULL);
771
        ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);
765 772
    } else {
766 773
        if (file == NULL) {
767
            qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't use '%s' as a "
768
                          "block driver for the protocol level",
769
                          drv->format_name);
774
            error_setg(errp, "Can't use '%s' as a block driver for the "
775
                       "protocol level", drv->format_name);
770 776
            ret = -EINVAL;
771 777
            goto free_and_fail;
772 778
        }
773 779
        bs->file = file;
774
        ret = drv->bdrv_open(bs, options, open_flags, NULL);
780
        ret = drv->bdrv_open(bs, options, open_flags, &local_err);
775 781
    }
776 782

  
777 783
    if (ret < 0) {
784
        if (error_is_set(&local_err)) {
785
            error_propagate(errp, local_err);
786
        } else if (filename) {
787
            error_setg_errno(errp, -ret, "Could not open '%s'", filename);
788
        } else {
789
            error_setg_errno(errp, -ret, "Could not open image");
790
        }
778 791
        goto free_and_fail;
779 792
    }
780 793

  
781 794
    ret = refresh_total_sectors(bs, bs->total_sectors);
782 795
    if (ret < 0) {
796
        error_setg_errno(errp, -ret, "Could not refresh total sector count");
783 797
        goto free_and_fail;
784 798
    }
785 799

  
......
808 822
 * dictionary, it needs to use QINCREF() before calling bdrv_file_open.
809 823
 */
810 824
int bdrv_file_open(BlockDriverState **pbs, const char *filename,
811
                   QDict *options, int flags)
825
                   QDict *options, int flags, Error **errp)
812 826
{
813 827
    BlockDriverState *bs;
814 828
    BlockDriver *drv;
815 829
    const char *drvname;
816 830
    bool allow_protocol_prefix = false;
831
    Error *local_err = NULL;
817 832
    int ret;
818 833

  
819 834
    /* NULL means an empty set of options */
......
832 847
        qdict_put(options, "filename", qstring_from_str(filename));
833 848
        allow_protocol_prefix = true;
834 849
    } else {
835
        qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't specify 'file' and "
836
                      "'filename' options at the same time");
850
        error_setg(errp, "Can't specify 'file' and 'filename' options at the "
851
                   "same time");
837 852
        ret = -EINVAL;
838 853
        goto fail;
839 854
    }
......
842 857
    drvname = qdict_get_try_str(options, "driver");
843 858
    if (drvname) {
844 859
        drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR));
860
        if (!drv) {
861
            error_setg(errp, "Unknown driver '%s'", drvname);
862
        }
845 863
        qdict_del(options, "driver");
846 864
    } else if (filename) {
847 865
        drv = bdrv_find_protocol(filename, allow_protocol_prefix);
848 866
        if (!drv) {
849
            qerror_report(ERROR_CLASS_GENERIC_ERROR, "Unknown protocol");
867
            error_setg(errp, "Unknown protocol");
850 868
        }
851 869
    } else {
852
        qerror_report(ERROR_CLASS_GENERIC_ERROR,
853
                      "Must specify either driver or file");
870
        error_setg(errp, "Must specify either driver or file");
854 871
        drv = NULL;
855 872
    }
856 873

  
857 874
    if (!drv) {
875
        /* errp has been set already */
858 876
        ret = -ENOENT;
859 877
        goto fail;
860 878
    }
861 879

  
862 880
    /* Parse the filename and open it */
863 881
    if (drv->bdrv_parse_filename && filename) {
864
        Error *local_err = NULL;
865 882
        drv->bdrv_parse_filename(filename, options, &local_err);
866 883
        if (error_is_set(&local_err)) {
867
            qerror_report_err(local_err);
868
            error_free(local_err);
884
            error_propagate(errp, local_err);
869 885
            ret = -EINVAL;
870 886
            goto fail;
871 887
        }
872 888
        qdict_del(options, "filename");
873 889
    } else if (!drv->bdrv_parse_filename && !filename) {
874
        qerror_report(ERROR_CLASS_GENERIC_ERROR,
875
                      "The '%s' block driver requires a file name",
876
                      drv->format_name);
890
        error_setg(errp, "The '%s' block driver requires a file name",
891
                   drv->format_name);
877 892
        ret = -EINVAL;
878 893
        goto fail;
879 894
    }
880 895

  
881
    ret = bdrv_open_common(bs, NULL, options, flags, drv);
896
    ret = bdrv_open_common(bs, NULL, options, flags, drv, &local_err);
882 897
    if (ret < 0) {
898
        error_propagate(errp, local_err);
883 899
        goto fail;
884 900
    }
885 901

  
886 902
    /* Check if any unknown options were used */
887 903
    if (qdict_size(options) != 0) {
888 904
        const QDictEntry *entry = qdict_first(options);
889
        qerror_report(ERROR_CLASS_GENERIC_ERROR, "Block protocol '%s' doesn't "
890
                      "support the option '%s'",
891
                      drv->format_name, entry->key);
905
        error_setg(errp, "Block protocol '%s' doesn't support the option '%s'",
906
                   drv->format_name, entry->key);
892 907
        ret = -EINVAL;
893 908
        goto fail;
894 909
    }
......
915 930
 * function (even on failure), so if the caller intends to reuse the dictionary,
916 931
 * it needs to use QINCREF() before calling bdrv_file_open.
917 932
 */
918
int bdrv_open_backing_file(BlockDriverState *bs, QDict *options)
933
int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
919 934
{
920 935
    char backing_filename[PATH_MAX];
921 936
    int back_flags, ret;
922 937
    BlockDriver *back_drv = NULL;
938
    Error *local_err = NULL;
923 939

  
924 940
    if (bs->backing_hd != NULL) {
925 941
        QDECREF(options);
......
952 968

  
953 969
    ret = bdrv_open(bs->backing_hd,
954 970
                    *backing_filename ? backing_filename : NULL, options,
955
                    back_flags, back_drv);
971
                    back_flags, back_drv, &local_err);
956 972
    if (ret < 0) {
957 973
        bdrv_unref(bs->backing_hd);
958 974
        bs->backing_hd = NULL;
959 975
        bs->open_flags |= BDRV_O_NO_BACKING;
976
        error_propagate(errp, local_err);
960 977
        return ret;
961 978
    }
962 979
    return 0;
......
990 1007
 * dictionary, it needs to use QINCREF() before calling bdrv_open.
991 1008
 */
992 1009
int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
993
              int flags, BlockDriver *drv)
1010
              int flags, BlockDriver *drv, Error **errp)
994 1011
{
995 1012
    int ret;
996 1013
    /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
......
998 1015
    BlockDriverState *file = NULL;
999 1016
    QDict *file_options = NULL;
1000 1017
    const char *drvname;
1018
    Error *local_err = NULL;
1001 1019

  
1002 1020
    /* NULL means an empty set of options */
1003 1021
    if (options == NULL) {
......
1016 1034
        char backing_filename[PATH_MAX];
1017 1035

  
1018 1036
        if (qdict_size(options) != 0) {
1019
            error_report("Can't use snapshot=on with driver-specific options");
1037
            error_setg(errp, "Can't use snapshot=on with driver-specific options");
1020 1038
            ret = -EINVAL;
1021 1039
            goto fail;
1022 1040
        }
......
1027 1045

  
1028 1046
        /* if there is a backing file, use it */
1029 1047
        bs1 = bdrv_new("");
1030
        ret = bdrv_open(bs1, filename, NULL, 0, drv);
1048
        ret = bdrv_open(bs1, filename, NULL, 0, drv, &local_err);
1031 1049
        if (ret < 0) {
1032 1050
            bdrv_unref(bs1);
1033 1051
            goto fail;
......
1038 1056

  
1039 1057
        ret = get_tmp_filename(tmp_filename, sizeof(tmp_filename));
1040 1058
        if (ret < 0) {
1059
            error_setg_errno(errp, -ret, "Could not get temporary filename");
1041 1060
            goto fail;
1042 1061
        }
1043 1062

  
......
1046 1065
            snprintf(backing_filename, sizeof(backing_filename),
1047 1066
                     "%s", filename);
1048 1067
        } else if (!realpath(filename, backing_filename)) {
1068
            error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
1049 1069
            ret = -errno;
1050 1070
            goto fail;
1051 1071
        }
......
1065 1085
        ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options);
1066 1086
        free_option_parameters(create_options);
1067 1087
        if (ret < 0) {
1088
            error_setg_errno(errp, -ret, "Could not create temporary overlay "
1089
                             "'%s'", tmp_filename);
1068 1090
            goto fail;
1069 1091
        }
1070 1092

  
......
1081 1103
    extract_subqdict(options, &file_options, "file.");
1082 1104

  
1083 1105
    ret = bdrv_file_open(&file, filename, file_options,
1084
                         bdrv_open_flags(bs, flags | BDRV_O_UNMAP));
1106
                         bdrv_open_flags(bs, flags | BDRV_O_UNMAP), &local_err);
1085 1107
    if (ret < 0) {
1086 1108
        goto fail;
1087 1109
    }
......
1094 1116
    }
1095 1117

  
1096 1118
    if (!drv) {
1097
        ret = find_image_format(file, filename, &drv);
1119
        ret = find_image_format(file, filename, &drv, &local_err);
1098 1120
    }
1099 1121

  
1100 1122
    if (!drv) {
......
1102 1124
    }
1103 1125

  
1104 1126
    /* Open the image */
1105
    ret = bdrv_open_common(bs, file, options, flags, drv);
1127
    ret = bdrv_open_common(bs, file, options, flags, drv, &local_err);
1106 1128
    if (ret < 0) {
1107 1129
        goto unlink_and_fail;
1108 1130
    }
......
1117 1139
        QDict *backing_options;
1118 1140

  
1119 1141
        extract_subqdict(options, &backing_options, "backing.");
1120
        ret = bdrv_open_backing_file(bs, backing_options);
1142
        ret = bdrv_open_backing_file(bs, backing_options, &local_err);
1121 1143
        if (ret < 0) {
1122 1144
            goto close_and_fail;
1123 1145
        }
......
1126 1148
    /* Check if any unknown options were used */
1127 1149
    if (qdict_size(options) != 0) {
1128 1150
        const QDictEntry *entry = qdict_first(options);
1129
        qerror_report(ERROR_CLASS_GENERIC_ERROR, "Block format '%s' used by "
1130
            "device '%s' doesn't support the option '%s'",
1131
            drv->format_name, bs->device_name, entry->key);
1151
        error_setg(errp, "Block format '%s' used by device '%s' doesn't "
1152
                   "support the option '%s'", drv->format_name, bs->device_name,
1153
                   entry->key);
1132 1154

  
1133 1155
        ret = -EINVAL;
1134 1156
        goto close_and_fail;
......
1152 1174
    QDECREF(bs->options);
1153 1175
    QDECREF(options);
1154 1176
    bs->options = NULL;
1177
    if (error_is_set(&local_err)) {
1178
        error_propagate(errp, local_err);
1179
    }
1155 1180
    return ret;
1156 1181

  
1157 1182
close_and_fail:
1158 1183
    bdrv_close(bs);
1159 1184
    QDECREF(options);
1185
    if (error_is_set(&local_err)) {
1186
        error_propagate(errp, local_err);
1187
    }
1160 1188
    return ret;
1161 1189
}
1162 1190

  
......
4519 4547
            bs = bdrv_new("");
4520 4548

  
4521 4549
            ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags,
4522
                            backing_drv);
4550
                            backing_drv, NULL);
4523 4551
            if (ret < 0) {
4524 4552
                error_setg_errno(errp, -ret, "Could not open '%s'",
4525 4553
                                 backing_file->value.s);
b/block/blkdebug.c
387 387
        goto fail;
388 388
    }
389 389

  
390
    ret = bdrv_file_open(&bs->file, filename, NULL, flags);
390
    ret = bdrv_file_open(&bs->file, filename, NULL, flags, &local_err);
391 391
    if (ret < 0) {
392
        qerror_report_err(local_err);
393
        error_free(local_err);
392 394
        goto fail;
393 395
    }
394 396

  
b/block/blkverify.c
141 141
        goto fail;
142 142
    }
143 143

  
144
    ret = bdrv_file_open(&bs->file, raw, NULL, flags);
144
    ret = bdrv_file_open(&bs->file, raw, NULL, flags, &local_err);
145 145
    if (ret < 0) {
146
        qerror_report_err(local_err);
147
        error_free(local_err);
146 148
        goto fail;
147 149
    }
148 150

  
......
154 156
    }
155 157

  
156 158
    s->test_file = bdrv_new("");
157
    ret = bdrv_open(s->test_file, filename, NULL, flags, NULL);
159
    ret = bdrv_open(s->test_file, filename, NULL, flags, NULL, &local_err);
158 160
    if (ret < 0) {
161
        qerror_report_err(local_err);
162
        error_free(local_err);
159 163
        bdrv_unref(s->test_file);
160 164
        s->test_file = NULL;
161 165
        goto fail;
b/block/cow.c
302 302
    struct stat st;
303 303
    int64_t image_sectors = 0;
304 304
    const char *image_filename = NULL;
305
    Error *local_err = NULL;
305 306
    int ret;
306 307
    BlockDriverState *cow_bs;
307 308

  
......
320 321
        return ret;
321 322
    }
322 323

  
323
    ret = bdrv_file_open(&cow_bs, filename, NULL, BDRV_O_RDWR);
324
    ret = bdrv_file_open(&cow_bs, filename, NULL, BDRV_O_RDWR, &local_err);
324 325
    if (ret < 0) {
326
        qerror_report_err(local_err);
327
        error_free(local_err);
325 328
        return ret;
326 329
    }
327 330

  
b/block/mirror.c
505 505
static void mirror_complete(BlockJob *job, Error **errp)
506 506
{
507 507
    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
508
    Error *local_err = NULL;
508 509
    int ret;
509 510

  
510
    ret = bdrv_open_backing_file(s->target, NULL);
511
    ret = bdrv_open_backing_file(s->target, NULL, &local_err);
511 512
    if (ret < 0) {
512 513
        char backing_filename[PATH_MAX];
513 514
        bdrv_get_full_backing_filename(s->target, backing_filename,
514 515
                                       sizeof(backing_filename));
515
        error_setg_file_open(errp, -ret, backing_filename);
516
        error_propagate(errp, local_err);
516 517
        return;
517 518
    }
518 519
    if (!s->synced) {
b/block/qcow.c
668 668
    int64_t total_size = 0;
669 669
    const char *backing_file = NULL;
670 670
    int flags = 0;
671
    Error *local_err = NULL;
671 672
    int ret;
672 673
    BlockDriverState *qcow_bs;
673 674

  
......
688 689
        return ret;
689 690
    }
690 691

  
691
    ret = bdrv_file_open(&qcow_bs, filename, NULL, BDRV_O_RDWR);
692
    ret = bdrv_file_open(&qcow_bs, filename, NULL, BDRV_O_RDWR, &local_err);
692 693
    if (ret < 0) {
694
        qerror_report_err(local_err);
695
        error_free(local_err);
693 696
        return ret;
694 697
    }
695 698

  
b/block/qcow2.c
1370 1370
        return ret;
1371 1371
    }
1372 1372

  
1373
    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR);
1373
    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR, NULL);
1374 1374
    if (ret < 0) {
1375 1375
        return ret;
1376 1376
    }
......
1423 1423
    BlockDriver* drv = bdrv_find_format("qcow2");
1424 1424
    assert(drv != NULL);
1425 1425
    ret = bdrv_open(bs, filename, NULL,
1426
        BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv);
1426
        BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv, NULL);
1427 1427
    if (ret < 0) {
1428 1428
        goto out;
1429 1429
    }
b/block/qed.c
551 551
    QEDHeader le_header;
552 552
    uint8_t *l1_table = NULL;
553 553
    size_t l1_size = header.cluster_size * header.table_size;
554
    Error *local_err = NULL;
554 555
    int ret = 0;
555 556
    BlockDriverState *bs = NULL;
556 557

  
......
559 560
        return ret;
560 561
    }
561 562

  
562
    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB);
563
    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB,
564
                         &local_err);
563 565
    if (ret < 0) {
566
        qerror_report_err(local_err);
567
        error_free(local_err);
564 568
        return ret;
565 569
    }
566 570

  
b/block/sheepdog.c
1401 1401
    uint32_t idx, max_idx;
1402 1402
    int64_t vdi_size;
1403 1403
    void *buf = g_malloc0(SD_DATA_OBJ_SIZE);
1404
    Error *local_err = NULL;
1404 1405
    int ret;
1405 1406

  
1406
    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR);
1407
    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR, &local_err);
1407 1408
    if (ret < 0) {
1409
        qerror_report_err(local_err);
1410
        error_free(local_err);
1408 1411
        goto out;
1409 1412
    }
1410 1413

  
......
1449 1452
    char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];
1450 1453
    uint32_t snapid;
1451 1454
    bool prealloc = false;
1455
    Error *local_err = NULL;
1452 1456

  
1453 1457
    s = g_malloc0(sizeof(BDRVSheepdogState));
1454 1458

  
......
1502 1506
            goto out;
1503 1507
        }
1504 1508

  
1505
        ret = bdrv_file_open(&bs, backing_file, NULL, 0);
1509
        ret = bdrv_file_open(&bs, backing_file, NULL, 0, &local_err);
1506 1510
        if (ret < 0) {
1511
            qerror_report_err(local_err);
1512
            error_free(local_err);
1507 1513
            goto out;
1508 1514
        }
1509 1515

  
b/block/vmdk.c
697 697
    int64_t flat_offset;
698 698
    char extent_path[PATH_MAX];
699 699
    BlockDriverState *extent_file;
700
    Error *local_err = NULL;
700 701

  
701 702
    while (*p) {
702 703
        /* parse extent line:
......
726 727

  
727 728
        path_combine(extent_path, sizeof(extent_path),
728 729
                desc_file_path, fname);
729
        ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags);
730
        ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags,
731
                             &local_err);
730 732
        if (ret) {
733
            qerror_report_err(local_err);
734
            error_free(local_err);
731 735
            return ret;
732 736
        }
733 737

  
......
1591 1595
        "ddb.geometry.heads = \"%d\"\n"
1592 1596
        "ddb.geometry.sectors = \"63\"\n"
1593 1597
        "ddb.adapterType = \"%s\"\n";
1598
    Error *local_err = NULL;
1594 1599

  
1595 1600
    if (filename_decompose(filename, path, prefix, postfix, PATH_MAX)) {
1596 1601
        return -EINVAL;
......
1653 1658
    }
1654 1659
    if (backing_file) {
1655 1660
        BlockDriverState *bs = bdrv_new("");
1656
        ret = bdrv_open(bs, backing_file, NULL, 0, NULL);
1661
        ret = bdrv_open(bs, backing_file, NULL, 0, NULL, &local_err);
1657 1662
        if (ret != 0) {
1663
            qerror_report_err(local_err);
1664
            error_free(local_err);
1658 1665
            bdrv_unref(bs);
1659 1666
            return ret;
1660 1667
        }
b/block/vvfat.c
2910 2910
{
2911 2911
    BlockDriver *bdrv_qcow;
2912 2912
    QEMUOptionParameter *options;
2913
    Error *local_err = NULL;
2913 2914
    int ret;
2914 2915
    int size = sector2cluster(s, s->sector_count);
2915 2916
    s->used_clusters = calloc(size, 1);
......
2935 2936
    s->qcow = bdrv_new("");
2936 2937

  
2937 2938
    ret = bdrv_open(s->qcow, s->qcow_filename, NULL,
2938
            BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow);
2939
            BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow,
2940
            &local_err);
2939 2941
    if (ret < 0) {
2942
        qerror_report_err(local_err);
2943
        error_free(local_err);
2940 2944
        bdrv_unref(s->qcow);
2941 2945
        goto err;
2942 2946
    }
b/blockdev.c
710 710
    }
711 711

  
712 712
    QINCREF(bs_opts);
713
    ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv);
713
    ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv, &error);
714 714

  
715 715
    if (ret < 0) {
716
        if (ret == -EMEDIUMTYPE) {
717
            error_report("could not open disk image %s: not in %s format",
718
                         file ?: dinfo->id, drv ? drv->format_name :
719
                         qdict_get_str(bs_opts, "driver"));
720
        } else {
721
            error_report("could not open disk image %s: %s",
722
                         file ?: dinfo->id, strerror(-ret));
723
        }
716
        error_report("could not open disk image %s: %s",
717
                     file ?: dinfo->id, error_get_pretty(error));
724 718
        goto err;
725 719
    }
726 720

  
......
1156 1150
    /* TODO Inherit bs->options or only take explicit options with an
1157 1151
     * extended QMP command? */
1158 1152
    ret = bdrv_open(state->new_bs, new_image_file, NULL,
1159
                    flags | BDRV_O_NO_BACKING, drv);
1153
                    flags | BDRV_O_NO_BACKING, drv, &local_err);
1160 1154
    if (ret != 0) {
1161
        error_setg_file_open(errp, -ret, new_image_file);
1155
        error_propagate(errp, local_err);
1162 1156
    }
1163 1157
}
1164 1158

  
......
1393 1387
                                    int bdrv_flags, BlockDriver *drv,
1394 1388
                                    const char *password, Error **errp)
1395 1389
{
1390
    Error *local_err = NULL;
1396 1391
    int ret;
1397 1392

  
1398
    ret = bdrv_open(bs, filename, NULL, bdrv_flags, drv);
1393
    ret = bdrv_open(bs, filename, NULL, bdrv_flags, drv, &local_err);
1399 1394
    if (ret < 0) {
1400
        error_setg_file_open(errp, -ret, filename);
1395
        error_propagate(errp, local_err);
1401 1396
        return;
1402 1397
    }
1403 1398

  
......
1817 1812
    }
1818 1813

  
1819 1814
    target_bs = bdrv_new("");
1820
    ret = bdrv_open(target_bs, target, NULL, flags, drv);
1815
    ret = bdrv_open(target_bs, target, NULL, flags, drv, &local_err);
1821 1816
    if (ret < 0) {
1822 1817
        bdrv_unref(target_bs);
1823
        error_setg_file_open(errp, -ret, target);
1818
        error_propagate(errp, local_err);
1824 1819
        return;
1825 1820
    }
1826 1821

  
......
1952 1947
     * file.
1953 1948
     */
1954 1949
    target_bs = bdrv_new("");
1955
    ret = bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKING, drv);
1950
    ret = bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKING, drv,
1951
                    &local_err);
1956 1952
    if (ret < 0) {
1957 1953
        bdrv_unref(target_bs);
1958
        error_setg_file_open(errp, -ret, target);
1954
        error_propagate(errp, local_err);
1959 1955
        return;
1960 1956
    }
1961 1957

  
b/hw/block/xen_disk.c
809 809
        xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
810 810
        blkdev->bs = bdrv_new(blkdev->dev);
811 811
        if (blkdev->bs) {
812
            Error *local_err = NULL;
812 813
            BlockDriver *drv = bdrv_find_whitelisted_format(blkdev->fileproto,
813 814
                                                           readonly);
814 815
            if (bdrv_open(blkdev->bs,
815
                          blkdev->filename, NULL, qflags, drv) != 0) {
816
                          blkdev->filename, NULL, qflags, drv, &local_err) != 0)
817
            {
818
                xen_be_printf(&blkdev->xendev, 0, "error: %s\n",
819
                              error_get_pretty(local_err));
820
                error_free(local_err);
816 821
                bdrv_unref(blkdev->bs);
817 822
                blkdev->bs = NULL;
818 823
            }
b/include/block/block.h
151 151
int bdrv_parse_cache_flags(const char *mode, int *flags);
152 152
int bdrv_parse_discard_flags(const char *mode, int *flags);
153 153
int bdrv_file_open(BlockDriverState **pbs, const char *filename,
154
                   QDict *options, int flags);
155
int bdrv_open_backing_file(BlockDriverState *bs, QDict *options);
154
                   QDict *options, int flags, Error **errp);
155
int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
156 156
int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
157
              int flags, BlockDriver *drv);
157
              int flags, BlockDriver *drv, Error **errp);
158 158
BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
159 159
                                    BlockDriverState *bs, int flags);
160 160
int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp);
b/qemu-img.c
266 266
    BlockDriverState *bs;
267 267
    BlockDriver *drv;
268 268
    char password[256];
269
    Error *local_err = NULL;
269 270
    int ret;
270 271

  
271 272
    bs = bdrv_new("image");
......
280 281
        drv = NULL;
281 282
    }
282 283

  
283
    ret = bdrv_open(bs, filename, NULL, flags, drv);
284
    ret = bdrv_open(bs, filename, NULL, flags, drv, &local_err);
284 285
    if (ret < 0) {
285
        error_report("Could not open '%s': %s", filename, strerror(-ret));
286
        error_report("Could not open '%s': %s", filename,
287
                     error_get_pretty(local_err));
288
        error_free(local_err);
286 289
        goto fail;
287 290
    }
288 291

  
......
2127 2130
    int unsafe = 0;
2128 2131
    int progress = 0;
2129 2132
    bool quiet = false;
2133
    Error *local_err = NULL;
2130 2134

  
2131 2135
    /* Parse commandline parameters */
2132 2136
    fmt = NULL;
......
2230 2234
        bs_old_backing = bdrv_new("old_backing");
2231 2235
        bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
2232 2236
        ret = bdrv_open(bs_old_backing, backing_name, NULL, BDRV_O_FLAGS,
2233
                        old_backing_drv);
2237
                        old_backing_drv, &local_err);
2234 2238
        if (ret) {
2235
            error_report("Could not open old backing file '%s'", backing_name);
2239
            error_report("Could not open old backing file '%s': %s",
2240
                         backing_name, error_get_pretty(local_err));
2241
            error_free(local_err);
2236 2242
            goto out;
2237 2243
        }
2238 2244
        if (out_baseimg[0]) {
2239 2245
            bs_new_backing = bdrv_new("new_backing");
2240 2246
            ret = bdrv_open(bs_new_backing, out_baseimg, NULL, BDRV_O_FLAGS,
2241
                        new_backing_drv);
2247
                        new_backing_drv, &local_err);
2242 2248
            if (ret) {
2243
                error_report("Could not open new backing file '%s'",
2244
                             out_baseimg);
2249
                error_report("Could not open new backing file '%s': %s",
2250
                             out_baseimg, error_get_pretty(local_err));
2251
                error_free(local_err);
2245 2252
                goto out;
2246 2253
            }
2247 2254
        }
b/qemu-io.c
46 46

  
47 47
static int openfile(char *name, int flags, int growable)
48 48
{
49
    Error *local_err = NULL;
50

  
49 51
    if (qemuio_bs) {
50 52
        fprintf(stderr, "file open already, try 'help close'\n");
51 53
        return 1;
52 54
    }
53 55

  
54 56
    if (growable) {
55
        if (bdrv_file_open(&qemuio_bs, name, NULL, flags)) {
56
            fprintf(stderr, "%s: can't open device %s\n", progname, name);
57
        if (bdrv_file_open(&qemuio_bs, name, NULL, flags, &local_err)) {
58
            fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
59
                    error_get_pretty(local_err));
60
            error_free(local_err);
57 61
            return 1;
58 62
        }
59 63
    } else {
60 64
        qemuio_bs = bdrv_new("hda");
61 65

  
62
        if (bdrv_open(qemuio_bs, name, NULL, flags, NULL) < 0) {
63
            fprintf(stderr, "%s: can't open device %s\n", progname, name);
66
        if (bdrv_open(qemuio_bs, name, NULL, flags, NULL, &local_err) < 0) {
67
            fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
68
                    error_get_pretty(local_err));
69
            error_free(local_err);
64 70
            bdrv_unref(qemuio_bs);
65 71
            qemuio_bs = NULL;
66 72
            return 1;
b/qemu-nbd.c
355 355
#endif
356 356
    pthread_t client_thread;
357 357
    const char *fmt = NULL;
358
    Error *local_err = NULL;
358 359

  
359 360
    /* The client thread uses SIGTERM to interrupt the server.  A signal
360 361
     * handler ensures that "qemu-nbd -v -c" exits with a nice status code.
......
573 574

  
574 575
    bs = bdrv_new("hda");
575 576
    srcpath = argv[optind];
576
    ret = bdrv_open(bs, srcpath, NULL, flags, drv);
577
    ret = bdrv_open(bs, srcpath, NULL, flags, drv, &local_err);
577 578
    if (ret < 0) {
578 579
        errno = -ret;
579
        err(EXIT_FAILURE, "Failed to bdrv_open '%s'", argv[optind]);
580
        err(EXIT_FAILURE, "Failed to bdrv_open '%s': %s", argv[optind],
581
            error_get_pretty(local_err));
580 582
    }
581 583

  
582 584
    fd_size = bdrv_getlength(bs);

Also available in: Unified diff