Revision d6e9098e

b/block.c
338 338
    int ret;
339 339

  
340 340
    bs = bdrv_new("");
341
    ret = bdrv_open2(bs, filename, flags | BDRV_O_FILE, NULL);
341
    ret = bdrv_open(bs, filename, flags | BDRV_O_FILE, NULL);
342 342
    if (ret < 0) {
343 343
        bdrv_delete(bs);
344 344
        return ret;
......
348 348
    return 0;
349 349
}
350 350

  
351
int bdrv_open(BlockDriverState *bs, const char *filename, int flags)
352
{
353
    return bdrv_open2(bs, filename, flags, NULL);
354
}
355

  
356
int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
357
               BlockDriver *drv)
351
int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
352
              BlockDriver *drv)
358 353
{
359 354
    int ret, open_flags;
360 355
    char tmp_filename[PATH_MAX];
......
379 374

  
380 375
        /* if there is a backing file, use it */
381 376
        bs1 = bdrv_new("");
382
        ret = bdrv_open2(bs1, filename, 0, drv);
377
        ret = bdrv_open(bs1, filename, 0, drv);
383 378
        if (ret < 0) {
384 379
            bdrv_delete(bs1);
385 380
            return ret;
......
491 486

  
492 487
        /* backing files always opened read-only */
493 488
        open_flags &= ~BDRV_O_RDWR;
494
        
495
        ret = bdrv_open2(bs->backing_hd, backing_filename, open_flags,
496
                         back_drv);
489

  
490
        ret = bdrv_open(bs->backing_hd, backing_filename, open_flags, back_drv);
497 491
        if (ret < 0) {
498 492
            bdrv_close(bs);
499 493
            return ret;
......
605 599
        bdrv_delete(bs->backing_hd);
606 600
        bs->backing_hd = NULL;
607 601
        bs_rw = bdrv_new("");
608
        rw_ret = bdrv_open2(bs_rw, filename, open_flags | BDRV_O_RDWR, NULL);
602
        rw_ret = bdrv_open(bs_rw, filename, open_flags | BDRV_O_RDWR, NULL);
609 603
        if (rw_ret < 0) {
610 604
            bdrv_delete(bs_rw);
611 605
            /* try to re-open read-only */
612 606
            bs_ro = bdrv_new("");
613
            ret = bdrv_open2(bs_ro, filename, open_flags & ~BDRV_O_RDWR, NULL);
607
            ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR, NULL);
614 608
            if (ret < 0) {
615 609
                bdrv_delete(bs_ro);
616 610
                /* drive not functional anymore */
......
662 656
        bdrv_delete(bs->backing_hd);
663 657
        bs->backing_hd = NULL;
664 658
        bs_ro = bdrv_new("");
665
        ret = bdrv_open2(bs_ro, filename, open_flags & ~BDRV_O_RDWR, NULL);
659
        ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR, NULL);
666 660
        if (ret < 0) {
667 661
            bdrv_delete(bs_ro);
668 662
            /* drive not functional anymore */
b/block.h
68 68
BlockDriverState *bdrv_new(const char *device_name);
69 69
void bdrv_delete(BlockDriverState *bs);
70 70
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
71
int bdrv_open(BlockDriverState *bs, const char *filename, int flags);
72
int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
73
               BlockDriver *drv);
71
int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
72
              BlockDriver *drv);
74 73
void bdrv_close(BlockDriverState *bs);
75 74
int bdrv_check(BlockDriverState *bs);
76 75
int bdrv_read(BlockDriverState *bs, int64_t sector_num,
b/block/qcow2.c
52 52
#define  QCOW_EXT_MAGIC_END 0
53 53
#define  QCOW_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA
54 54

  
55

  
55
static BlockDriver bdrv_qcow2;
56 56

  
57 57
static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
58 58
{
......
1033 1033
    if (ret == 0 && prealloc) {
1034 1034
        BlockDriverState *bs;
1035 1035
        bs = bdrv_new("");
1036
        bdrv_open(bs, filename, BDRV_O_CACHE_WB | BDRV_O_RDWR);
1036
        bdrv_open(bs, filename, BDRV_O_CACHE_WB | BDRV_O_RDWR, &bdrv_qcow2);
1037 1037
        preallocate(bs);
1038 1038
        bdrv_close(bs);
1039 1039
    }
b/block/vmdk.c
390 390
            return -1;
391 391
        }
392 392
        parent_open = 1;
393
        if (bdrv_open(bs->backing_hd, parent_img_name, 0) < 0)
393
        if (bdrv_open(bs->backing_hd, parent_img_name, 0, NULL) < 0)
394 394
            goto failure;
395 395
        parent_open = 0;
396 396
    }
b/block/vvfat.c
2795 2795
    if (bdrv_create(bdrv_qcow, s->qcow_filename, options) < 0)
2796 2796
	return -1;
2797 2797
    s->qcow = bdrv_new("");
2798
    if (s->qcow == NULL || bdrv_open(s->qcow, s->qcow_filename, BDRV_O_RDWR) < 0)
2798
    if (s->qcow == NULL ||
2799
        bdrv_open(s->qcow, s->qcow_filename, BDRV_O_RDWR, bdrv_qcow) < 0)
2800
    {
2799 2801
	return -1;
2802
    }
2800 2803

  
2801 2804
#ifndef _WIN32
2802 2805
    unlink(s->qcow_filename);
b/hw/xen_disk.c
629 629
        xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
630 630
	blkdev->bs = bdrv_new(blkdev->dev);
631 631
	if (blkdev->bs) {
632
	    if (bdrv_open2(blkdev->bs, blkdev->filename, qflags,
632
	    if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
633 633
                           bdrv_find_whitelisted_format(blkdev->fileproto))
634 634
                != 0) {
635 635
		bdrv_delete(blkdev->bs);
b/monitor.c
1099 1099
    if (eject_device(mon, bs, 0) < 0) {
1100 1100
        return -1;
1101 1101
    }
1102
    if (bdrv_open2(bs, filename, BDRV_O_RDWR, drv) < 0) {
1102
    if (bdrv_open(bs, filename, BDRV_O_RDWR, drv) < 0) {
1103 1103
        qerror_report(QERR_OPEN_FILE_FAILED, filename);
1104 1104
        return -1;
1105 1105
    }
b/qemu-img.c
210 210
    if (!readonly) {
211 211
        flags |= BDRV_O_RDWR;
212 212
    }
213
    if (bdrv_open2(bs, filename, flags, drv) < 0) {
213
    if (bdrv_open(bs, filename, flags, drv) < 0) {
214 214
        error("Could not open '%s'", filename);
215 215
    }
216 216
    if (bdrv_is_encrypted(bs)) {
......
415 415
    } else {
416 416
        drv = NULL;
417 417
    }
418
    if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) {
418
    if (bdrv_open(bs, filename, BRDV_O_FLAGS, drv) < 0) {
419 419
        error("Could not open '%s'", filename);
420 420
    }
421 421
    ret = bdrv_check(bs);
......
474 474
    } else {
475 475
        drv = NULL;
476 476
    }
477
    if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_RDWR, drv) < 0) {
477
    if (bdrv_open(bs, filename, BRDV_O_FLAGS | BDRV_O_RDWR, drv) < 0) {
478 478
        error("Could not open '%s'", filename);
479 479
    }
480 480
    ret = bdrv_commit(bs);
......
926 926
    } else {
927 927
        drv = NULL;
928 928
    }
929
    if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_NO_BACKING, drv) < 0) {
929
    if (bdrv_open(bs, filename, BRDV_O_FLAGS | BDRV_O_NO_BACKING, drv) < 0) {
930 930
        error("Could not open '%s'", filename);
931 931
    }
932 932
    bdrv_get_format(bs, fmt_name, sizeof(fmt_name));
......
1032 1032
    if (!bs)
1033 1033
        error("Not enough memory");
1034 1034

  
1035
    if (bdrv_open2(bs, filename, bdrv_oflags, NULL) < 0) {
1035
    if (bdrv_open(bs, filename, bdrv_oflags, NULL) < 0) {
1036 1036
        error("Could not open '%s'", filename);
1037 1037
    }
1038 1038

  
......
1137 1137
    }
1138 1138

  
1139 1139
    flags = BRDV_O_FLAGS | BDRV_O_RDWR | (unsafe ? BDRV_O_NO_BACKING : 0);
1140
    if (bdrv_open2(bs, filename, flags, drv) < 0) {
1140
    if (bdrv_open(bs, filename, flags, drv) < 0) {
1141 1141
        error("Could not open '%s'", filename);
1142 1142
    }
1143 1143

  
......
1169 1169

  
1170 1170
        bs_old_backing = bdrv_new("old_backing");
1171 1171
        bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
1172
        if (bdrv_open2(bs_old_backing, backing_name, BRDV_O_FLAGS,
1172
        if (bdrv_open(bs_old_backing, backing_name, BRDV_O_FLAGS,
1173 1173
            old_backing_drv))
1174 1174
        {
1175 1175
            error("Could not open old backing file '%s'", backing_name);
......
1177 1177
        }
1178 1178

  
1179 1179
        bs_new_backing = bdrv_new("new_backing");
1180
        if (bdrv_open2(bs_new_backing, out_baseimg, BRDV_O_FLAGS | BDRV_O_RDWR,
1180
        if (bdrv_open(bs_new_backing, out_baseimg, BRDV_O_FLAGS | BDRV_O_RDWR,
1181 1181
            new_backing_drv))
1182 1182
        {
1183 1183
            error("Could not open new backing file '%s'", out_baseimg);
b/qemu-io.c
1284 1284
		flags |= BDRV_O_FILE;
1285 1285
	}
1286 1286

  
1287
	if (bdrv_open(bs, name, flags) < 0) {
1287
	if (bdrv_open(bs, name, flags, NULL) < 0) {
1288 1288
		fprintf(stderr, "%s: can't open device %s\n", progname, name);
1289 1289
		bs = NULL;
1290 1290
		return 1;
b/qemu-nbd.c
333 333
    if (bs == NULL)
334 334
        return 1;
335 335

  
336
    if (bdrv_open(bs, argv[optind], flags) < 0)
336
    if (bdrv_open(bs, argv[optind], flags, NULL) < 0)
337 337
        return 1;
338 338

  
339 339
    fd_size = bs->total_sectors * 512;
b/vl.c
1129 1129

  
1130 1130
    bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
1131 1131

  
1132
    if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
1132
    if (bdrv_open(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
1133 1133
        fprintf(stderr, "qemu: could not open disk image %s: %s\n",
1134 1134
                        file, strerror(errno));
1135 1135
        return NULL;

Also available in: Unified diff