block.c (ae23f78646e9635ec9cbf15dbf82a717ea1b0e69) | block.c (93393e698c76c9b95b1fcf9649eef41f9cdbbb07) |
---|---|
1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 698 unchanged lines hidden (view full) --- 707 * Try to get @bs's logical and physical block size. 708 * On success, store them in @bsz struct and return 0. 709 * On failure return -errno. 710 * @bs must not be empty. 711 */ 712int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz) 713{ 714 BlockDriver *drv = bs->drv; | 1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 698 unchanged lines hidden (view full) --- 707 * Try to get @bs's logical and physical block size. 708 * On success, store them in @bsz struct and return 0. 709 * On failure return -errno. 710 * @bs must not be empty. 711 */ 712int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz) 713{ 714 BlockDriver *drv = bs->drv; |
715 BlockDriverState *filtered = bdrv_filter_bs(bs); |
|
715 716 if (drv && drv->bdrv_probe_blocksizes) { 717 return drv->bdrv_probe_blocksizes(bs, bsz); | 716 717 if (drv && drv->bdrv_probe_blocksizes) { 718 return drv->bdrv_probe_blocksizes(bs, bsz); |
718 } else if (drv && drv->is_filter && bs->file) { 719 return bdrv_probe_blocksizes(bs->file->bs, bsz); | 719 } else if (filtered) { 720 return bdrv_probe_blocksizes(filtered, bsz); |
720 } 721 722 return -ENOTSUP; 723} 724 725/** 726 * Try to get @bs's geometry (cyls, heads, sectors). 727 * On success, store them in @geo struct and return 0. 728 * On failure return -errno. 729 * @bs must not be empty. 730 */ 731int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo) 732{ 733 BlockDriver *drv = bs->drv; | 721 } 722 723 return -ENOTSUP; 724} 725 726/** 727 * Try to get @bs's geometry (cyls, heads, sectors). 728 * On success, store them in @geo struct and return 0. 729 * On failure return -errno. 730 * @bs must not be empty. 731 */ 732int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo) 733{ 734 BlockDriver *drv = bs->drv; |
735 BlockDriverState *filtered = bdrv_filter_bs(bs); |
|
734 735 if (drv && drv->bdrv_probe_geometry) { 736 return drv->bdrv_probe_geometry(bs, geo); | 736 737 if (drv && drv->bdrv_probe_geometry) { 738 return drv->bdrv_probe_geometry(bs, geo); |
737 } else if (drv && drv->is_filter && bs->file) { 738 return bdrv_probe_geometry(bs->file->bs, geo); | 739 } else if (filtered) { 740 return bdrv_probe_geometry(filtered, geo); |
739 } 740 741 return -ENOTSUP; 742} 743 744/* 745 * Create a uniquely-named empty temporary file. 746 * Return 0 upon success, otherwise a negative errno value. --- 4690 unchanged lines hidden (view full) --- 5437 5438int bdrv_has_zero_init_1(BlockDriverState *bs) 5439{ 5440 return 1; 5441} 5442 5443int bdrv_has_zero_init(BlockDriverState *bs) 5444{ | 741 } 742 743 return -ENOTSUP; 744} 745 746/* 747 * Create a uniquely-named empty temporary file. 748 * Return 0 upon success, otherwise a negative errno value. --- 4690 unchanged lines hidden (view full) --- 5439 5440int bdrv_has_zero_init_1(BlockDriverState *bs) 5441{ 5442 return 1; 5443} 5444 5445int bdrv_has_zero_init(BlockDriverState *bs) 5446{ |
5447 BlockDriverState *filtered; 5448 |
|
5445 if (!bs->drv) { 5446 return 0; 5447 } 5448 5449 /* If BS is a copy on write image, it is initialized to 5450 the contents of the base image, which may not be zeroes. */ 5451 if (bdrv_cow_child(bs)) { 5452 return 0; 5453 } 5454 if (bs->drv->bdrv_has_zero_init) { 5455 return bs->drv->bdrv_has_zero_init(bs); 5456 } | 5449 if (!bs->drv) { 5450 return 0; 5451 } 5452 5453 /* If BS is a copy on write image, it is initialized to 5454 the contents of the base image, which may not be zeroes. */ 5455 if (bdrv_cow_child(bs)) { 5456 return 0; 5457 } 5458 if (bs->drv->bdrv_has_zero_init) { 5459 return bs->drv->bdrv_has_zero_init(bs); 5460 } |
5457 if (bs->file && bs->drv->is_filter) { 5458 return bdrv_has_zero_init(bs->file->bs); | 5461 5462 filtered = bdrv_filter_bs(bs); 5463 if (filtered) { 5464 return bdrv_has_zero_init(filtered); |
5459 } 5460 5461 /* safe default */ 5462 return 0; 5463} 5464 5465bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs) 5466{ --- 13 unchanged lines hidden (view full) --- 5480int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) 5481{ 5482 BlockDriver *drv = bs->drv; 5483 /* if bs->drv == NULL, bs is closed, so there's nothing to do here */ 5484 if (!drv) { 5485 return -ENOMEDIUM; 5486 } 5487 if (!drv->bdrv_get_info) { | 5465 } 5466 5467 /* safe default */ 5468 return 0; 5469} 5470 5471bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs) 5472{ --- 13 unchanged lines hidden (view full) --- 5486int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) 5487{ 5488 BlockDriver *drv = bs->drv; 5489 /* if bs->drv == NULL, bs is closed, so there's nothing to do here */ 5490 if (!drv) { 5491 return -ENOMEDIUM; 5492 } 5493 if (!drv->bdrv_get_info) { |
5488 if (bs->file && drv->is_filter) { 5489 return bdrv_get_info(bs->file->bs, bdi); | 5494 BlockDriverState *filtered = bdrv_filter_bs(bs); 5495 if (filtered) { 5496 return bdrv_get_info(filtered, bdi); |
5490 } 5491 return -ENOTSUP; 5492 } 5493 memset(bdi, 0, sizeof(*bdi)); 5494 return drv->bdrv_get_info(bs, bdi); 5495} 5496 5497ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs, --- 1068 unchanged lines hidden (view full) --- 6566 * filters), or some driver may allow replacing one of its children 6567 * because it can guarantee that this child's data is not visible at 6568 * all (for example, for dissenting quorum children that have no other 6569 * parents). 6570 */ 6571bool bdrv_recurse_can_replace(BlockDriverState *bs, 6572 BlockDriverState *to_replace) 6573{ | 5497 } 5498 return -ENOTSUP; 5499 } 5500 memset(bdi, 0, sizeof(*bdi)); 5501 return drv->bdrv_get_info(bs, bdi); 5502} 5503 5504ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs, --- 1068 unchanged lines hidden (view full) --- 6573 * filters), or some driver may allow replacing one of its children 6574 * because it can guarantee that this child's data is not visible at 6575 * all (for example, for dissenting quorum children that have no other 6576 * parents). 6577 */ 6578bool bdrv_recurse_can_replace(BlockDriverState *bs, 6579 BlockDriverState *to_replace) 6580{ |
6581 BlockDriverState *filtered; 6582 |
|
6574 if (!bs || !bs->drv) { 6575 return false; 6576 } 6577 6578 if (bs == to_replace) { 6579 return true; 6580 } 6581 6582 /* See what the driver can do */ 6583 if (bs->drv->bdrv_recurse_can_replace) { 6584 return bs->drv->bdrv_recurse_can_replace(bs, to_replace); 6585 } 6586 6587 /* For filters without an own implementation, we can recurse on our own */ | 6583 if (!bs || !bs->drv) { 6584 return false; 6585 } 6586 6587 if (bs == to_replace) { 6588 return true; 6589 } 6590 6591 /* See what the driver can do */ 6592 if (bs->drv->bdrv_recurse_can_replace) { 6593 return bs->drv->bdrv_recurse_can_replace(bs, to_replace); 6594 } 6595 6596 /* For filters without an own implementation, we can recurse on our own */ |
6588 if (bs->drv->is_filter) { 6589 BdrvChild *child = bs->file ?: bs->backing; 6590 return bdrv_recurse_can_replace(child->bs, to_replace); | 6597 filtered = bdrv_filter_bs(bs); 6598 if (filtered) { 6599 return bdrv_recurse_can_replace(filtered, to_replace); |
6591 } 6592 6593 /* Safe default */ 6594 return false; 6595} 6596 6597/* 6598 * Check whether the given @node_name can be replaced by a node that --- 533 unchanged lines hidden --- | 6600 } 6601 6602 /* Safe default */ 6603 return false; 6604} 6605 6606/* 6607 * Check whether the given @node_name can be replaced by a node that --- 533 unchanged lines hidden --- |