block.c (b26ded9a7d9709aacdff36e39630acbb87201057) | block.c (5c8cab48087d3544cb788309ac729bca08244020) |
---|---|
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 --- 1200 unchanged lines hidden (view full) --- 1209 1210 if (child->bs->inherits_from == parent) { 1211 child->bs->inherits_from = NULL; 1212 } 1213 1214 bdrv_root_unref_child(child); 1215} 1216 | 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 --- 1200 unchanged lines hidden (view full) --- 1209 1210 if (child->bs->inherits_from == parent) { 1211 child->bs->inherits_from = NULL; 1212 } 1213 1214 bdrv_root_unref_child(child); 1215} 1216 |
1217 1218static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load) 1219{ 1220 BdrvChild *c; 1221 QLIST_FOREACH(c, &bs->parents, next_parent) { 1222 if (c->role->change_media) { 1223 c->role->change_media(c, load); 1224 } 1225 } 1226} 1227 1228static void bdrv_parent_cb_resize(BlockDriverState *bs) 1229{ 1230 BdrvChild *c; 1231 QLIST_FOREACH(c, &bs->parents, next_parent) { 1232 if (c->role->resize) { 1233 c->role->resize(c); 1234 } 1235 } 1236} 1237 |
|
1217/* 1218 * Sets the backing file link of a BDS. A new reference is created; callers 1219 * which don't need their own reference any more must call bdrv_unref(). 1220 */ 1221void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd) 1222{ 1223 if (backing_hd) { 1224 bdrv_ref(backing_hd); --- 443 unchanged lines hidden (view full) --- 1668 drv->format_name, entry->key); 1669 } 1670 1671 ret = -EINVAL; 1672 goto close_and_fail; 1673 } 1674 1675 if (!bdrv_key_required(bs)) { | 1238/* 1239 * Sets the backing file link of a BDS. A new reference is created; callers 1240 * which don't need their own reference any more must call bdrv_unref(). 1241 */ 1242void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd) 1243{ 1244 if (backing_hd) { 1245 bdrv_ref(backing_hd); --- 443 unchanged lines hidden (view full) --- 1689 drv->format_name, entry->key); 1690 } 1691 1692 ret = -EINVAL; 1693 goto close_and_fail; 1694 } 1695 1696 if (!bdrv_key_required(bs)) { |
1676 if (bs->blk) { 1677 blk_dev_change_media_cb(bs->blk, true); 1678 } | 1697 bdrv_parent_cb_change_media(bs, true); |
1679 } else if (!runstate_check(RUN_STATE_PRELAUNCH) 1680 && !runstate_check(RUN_STATE_INMIGRATE) 1681 && !runstate_check(RUN_STATE_PAUSED)) { /* HACK */ 1682 error_setg(errp, 1683 "Guest must be stopped for opening of encrypted image"); 1684 ret = -EBUSY; 1685 goto close_and_fail; 1686 } --- 429 unchanged lines hidden (view full) --- 2116 2117 bdrv_drained_begin(bs); /* complete I/O */ 2118 bdrv_flush(bs); 2119 bdrv_drain(bs); /* in case flush left pending I/O */ 2120 2121 bdrv_release_named_dirty_bitmaps(bs); 2122 assert(QLIST_EMPTY(&bs->dirty_bitmaps)); 2123 | 1698 } else if (!runstate_check(RUN_STATE_PRELAUNCH) 1699 && !runstate_check(RUN_STATE_INMIGRATE) 1700 && !runstate_check(RUN_STATE_PAUSED)) { /* HACK */ 1701 error_setg(errp, 1702 "Guest must be stopped for opening of encrypted image"); 1703 ret = -EBUSY; 1704 goto close_and_fail; 1705 } --- 429 unchanged lines hidden (view full) --- 2135 2136 bdrv_drained_begin(bs); /* complete I/O */ 2137 bdrv_flush(bs); 2138 bdrv_drain(bs); /* in case flush left pending I/O */ 2139 2140 bdrv_release_named_dirty_bitmaps(bs); 2141 assert(QLIST_EMPTY(&bs->dirty_bitmaps)); 2142 |
2124 if (bs->blk) { 2125 blk_dev_change_media_cb(bs->blk, false); 2126 } | 2143 bdrv_parent_cb_change_media(bs, false); |
2127 2128 if (bs->drv) { 2129 BdrvChild *child, *next; 2130 2131 bs->drv->bdrv_close(bs); 2132 bs->drv = NULL; 2133 2134 bdrv_set_backing_hd(bs, NULL); --- 434 unchanged lines hidden (view full) --- 2569 return -ENOTSUP; 2570 if (bs->read_only) 2571 return -EACCES; 2572 2573 ret = drv->bdrv_truncate(bs, offset); 2574 if (ret == 0) { 2575 ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); 2576 bdrv_dirty_bitmap_truncate(bs); | 2144 2145 if (bs->drv) { 2146 BdrvChild *child, *next; 2147 2148 bs->drv->bdrv_close(bs); 2149 bs->drv = NULL; 2150 2151 bdrv_set_backing_hd(bs, NULL); --- 434 unchanged lines hidden (view full) --- 2586 return -ENOTSUP; 2587 if (bs->read_only) 2588 return -EACCES; 2589 2590 ret = drv->bdrv_truncate(bs, offset); 2591 if (ret == 0) { 2592 ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); 2593 bdrv_dirty_bitmap_truncate(bs); |
2577 if (bs->blk) { 2578 blk_dev_resize_cb(bs->blk); 2579 } | 2594 bdrv_parent_cb_resize(bs); |
2580 } 2581 return ret; 2582} 2583 2584/** 2585 * Length of a allocated file in bytes. Sparse files are counted by actual 2586 * allocated space. Return < 0 if error or unknown. 2587 */ --- 93 unchanged lines hidden (view full) --- 2681 return -EINVAL; 2682 } else if (!bs->drv || !bs->drv->bdrv_set_key) { 2683 return -ENOMEDIUM; 2684 } 2685 ret = bs->drv->bdrv_set_key(bs, key); 2686 if (ret < 0) { 2687 bs->valid_key = 0; 2688 } else if (!bs->valid_key) { | 2595 } 2596 return ret; 2597} 2598 2599/** 2600 * Length of a allocated file in bytes. Sparse files are counted by actual 2601 * allocated space. Return < 0 if error or unknown. 2602 */ --- 93 unchanged lines hidden (view full) --- 2696 return -EINVAL; 2697 } else if (!bs->drv || !bs->drv->bdrv_set_key) { 2698 return -ENOMEDIUM; 2699 } 2700 ret = bs->drv->bdrv_set_key(bs, key); 2701 if (ret < 0) { 2702 bs->valid_key = 0; 2703 } else if (!bs->valid_key) { |
2704 /* call the change callback now, we skipped it on open */ |
|
2689 bs->valid_key = 1; | 2705 bs->valid_key = 1; |
2690 if (bs->blk) { 2691 /* call the change callback now, we skipped it on open */ 2692 blk_dev_change_media_cb(bs->blk, true); 2693 } | 2706 bdrv_parent_cb_change_media(bs, true); |
2694 } 2695 return ret; 2696} 2697 2698/* 2699 * Provide an encryption key for @bs. 2700 * If @key is non-null: 2701 * If @bs is not encrypted, fail. --- 1305 unchanged lines hidden --- | 2707 } 2708 return ret; 2709} 2710 2711/* 2712 * Provide an encryption key for @bs. 2713 * If @key is non-null: 2714 * If @bs is not encrypted, fail. --- 1305 unchanged lines hidden --- |