blockdev.c (5699a02e01a4d046652bc6e77abd67e887ae209c) | blockdev.c (74fe54f2a1b5c4f4498a8fe521e1dfc936656cd4) |
---|---|
1/* 2 * QEMU host block devices 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * 6 * This work is licensed under the terms of the GNU GPL, version 2 or 7 * later. See the COPYING file in the top-level directory. 8 * --- 308 unchanged lines hidden (view full) --- 317 const char *buf; 318 const char *file = NULL; 319 const char *serial; 320 const char *mediastr = ""; 321 BlockInterfaceType type; 322 enum { MEDIA_DISK, MEDIA_CDROM } media; 323 int bus_id, unit_id; 324 int cyls, heads, secs, translation; | 1/* 2 * QEMU host block devices 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * 6 * This work is licensed under the terms of the GNU GPL, version 2 or 7 * later. See the COPYING file in the top-level directory. 8 * --- 308 unchanged lines hidden (view full) --- 317 const char *buf; 318 const char *file = NULL; 319 const char *serial; 320 const char *mediastr = ""; 321 BlockInterfaceType type; 322 enum { MEDIA_DISK, MEDIA_CDROM } media; 323 int bus_id, unit_id; 324 int cyls, heads, secs, translation; |
325 BlockDriver *drv = NULL; | |
326 int max_devs; 327 int index; 328 int ro = 0; 329 int bdrv_flags = 0; 330 int on_read_error, on_write_error; 331 const char *devaddr; 332 DriveInfo *dinfo; 333 BlockIOLimit io_limits; 334 int snapshot = 0; 335 bool copy_on_read; 336 int ret; 337 Error *error = NULL; 338 QemuOpts *opts; 339 QDict *bs_opts; 340 const char *id; | 325 int max_devs; 326 int index; 327 int ro = 0; 328 int bdrv_flags = 0; 329 int on_read_error, on_write_error; 330 const char *devaddr; 331 DriveInfo *dinfo; 332 BlockIOLimit io_limits; 333 int snapshot = 0; 334 bool copy_on_read; 335 int ret; 336 Error *error = NULL; 337 QemuOpts *opts; 338 QDict *bs_opts; 339 const char *id; |
340 bool has_driver_specific_opts; |
|
341 342 translation = BIOS_ATA_TRANSLATION_AUTO; 343 media = MEDIA_DISK; 344 345 /* Check common options by copying from all_opts to opts, all other options 346 * are stored in bs_opts. */ 347 id = qemu_opts_id(all_opts); 348 opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error); --- 11 unchanged lines hidden (view full) --- 360 error_free(error); 361 return NULL; 362 } 363 364 if (id) { 365 qdict_del(bs_opts, "id"); 366 } 367 | 341 342 translation = BIOS_ATA_TRANSLATION_AUTO; 343 media = MEDIA_DISK; 344 345 /* Check common options by copying from all_opts to opts, all other options 346 * are stored in bs_opts. */ 347 id = qemu_opts_id(all_opts); 348 opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error); --- 11 unchanged lines hidden (view full) --- 360 error_free(error); 361 return NULL; 362 } 363 364 if (id) { 365 qdict_del(bs_opts, "id"); 366 } 367 |
368 has_driver_specific_opts = !!qdict_size(bs_opts); 369 |
|
368 /* extract parameters */ 369 bus_id = qemu_opt_get_number(opts, "bus", 0); 370 unit_id = qemu_opt_get_number(opts, "unit", -1); 371 index = qemu_opt_get_number(opts, "index", -1); 372 373 cyls = qemu_opt_get_number(opts, "cyls", 0); 374 heads = qemu_opt_get_number(opts, "heads", 0); 375 secs = qemu_opt_get_number(opts, "secs", 0); --- 96 unchanged lines hidden (view full) --- 472 473 if ((buf = qemu_opt_get(opts, "format")) != NULL) { 474 if (is_help_option(buf)) { 475 error_printf("Supported formats:"); 476 bdrv_iterate_format(bdrv_format_print, NULL); 477 error_printf("\n"); 478 return NULL; 479 } | 370 /* extract parameters */ 371 bus_id = qemu_opt_get_number(opts, "bus", 0); 372 unit_id = qemu_opt_get_number(opts, "unit", -1); 373 index = qemu_opt_get_number(opts, "index", -1); 374 375 cyls = qemu_opt_get_number(opts, "cyls", 0); 376 heads = qemu_opt_get_number(opts, "heads", 0); 377 secs = qemu_opt_get_number(opts, "secs", 0); --- 96 unchanged lines hidden (view full) --- 474 475 if ((buf = qemu_opt_get(opts, "format")) != NULL) { 476 if (is_help_option(buf)) { 477 error_printf("Supported formats:"); 478 bdrv_iterate_format(bdrv_format_print, NULL); 479 error_printf("\n"); 480 return NULL; 481 } |
480 drv = bdrv_find_whitelisted_format(buf, ro); 481 if (!drv) { 482 error_report("'%s' invalid format", buf); 483 return NULL; 484 } | 482 483 qdict_put(bs_opts, "driver", qstring_from_str(buf)); |
485 } 486 487 /* disk I/O throttling */ 488 io_limits.bps[BLOCK_IO_LIMIT_TOTAL] = 489 qemu_opt_get_number(opts, "bps", 0); 490 io_limits.bps[BLOCK_IO_LIMIT_READ] = 491 qemu_opt_get_number(opts, "bps_rd", 0); 492 io_limits.bps[BLOCK_IO_LIMIT_WRITE] = --- 160 unchanged lines hidden (view full) --- 653 if (devaddr) 654 qemu_opt_set(devopts, "addr", devaddr); 655 break; 656 } 657 default: 658 abort(); 659 } 660 if (!file || !*file) { | 484 } 485 486 /* disk I/O throttling */ 487 io_limits.bps[BLOCK_IO_LIMIT_TOTAL] = 488 qemu_opt_get_number(opts, "bps", 0); 489 io_limits.bps[BLOCK_IO_LIMIT_READ] = 490 qemu_opt_get_number(opts, "bps_rd", 0); 491 io_limits.bps[BLOCK_IO_LIMIT_WRITE] = --- 160 unchanged lines hidden (view full) --- 652 if (devaddr) 653 qemu_opt_set(devopts, "addr", devaddr); 654 break; 655 } 656 default: 657 abort(); 658 } 659 if (!file || !*file) { |
661 if (qdict_size(bs_opts)) { | 660 if (has_driver_specific_opts) { |
662 file = NULL; 663 } else { 664 return dinfo; 665 } 666 } 667 if (snapshot) { 668 /* always use cache=unsafe with snapshot */ 669 bdrv_flags &= ~BDRV_O_CACHE_MASK; --- 20 unchanged lines hidden (view full) --- 690 } 691 692 bdrv_flags |= ro ? 0 : BDRV_O_RDWR; 693 694 if (ro && copy_on_read) { 695 error_report("warning: disabling copy_on_read on readonly drive"); 696 } 697 | 661 file = NULL; 662 } else { 663 return dinfo; 664 } 665 } 666 if (snapshot) { 667 /* always use cache=unsafe with snapshot */ 668 bdrv_flags &= ~BDRV_O_CACHE_MASK; --- 20 unchanged lines hidden (view full) --- 689 } 690 691 bdrv_flags |= ro ? 0 : BDRV_O_RDWR; 692 693 if (ro && copy_on_read) { 694 error_report("warning: disabling copy_on_read on readonly drive"); 695 } 696 |
698 ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv); 699 bs_opts = NULL; | 697 QINCREF(bs_opts); 698 ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, NULL); |
700 701 if (ret < 0) { 702 if (ret == -EMEDIUMTYPE) { 703 error_report("could not open disk image %s: not in %s format", | 699 700 if (ret < 0) { 701 if (ret == -EMEDIUMTYPE) { 702 error_report("could not open disk image %s: not in %s format", |
704 file ?: dinfo->id, drv->format_name); | 703 file ?: dinfo->id, qdict_get_str(bs_opts, "driver")); |
705 } else { 706 error_report("could not open disk image %s: %s", 707 file ?: dinfo->id, strerror(-ret)); 708 } 709 goto err; 710 } 711 712 if (bdrv_key_required(dinfo->bdrv)) 713 autostart = 0; 714 | 704 } else { 705 error_report("could not open disk image %s: %s", 706 file ?: dinfo->id, strerror(-ret)); 707 } 708 goto err; 709 } 710 711 if (bdrv_key_required(dinfo->bdrv)) 712 autostart = 0; 713 |
714 QDECREF(bs_opts); |
|
715 qemu_opts_del(opts); 716 717 return dinfo; 718 719err: 720 qemu_opts_del(opts); 721 QDECREF(bs_opts); 722 bdrv_delete(dinfo->bdrv); --- 1182 unchanged lines hidden --- | 715 qemu_opts_del(opts); 716 717 return dinfo; 718 719err: 720 qemu_opts_del(opts); 721 QDECREF(bs_opts); 722 bdrv_delete(dinfo->bdrv); --- 1182 unchanged lines hidden --- |