block.c (9397c14fcb90edf235cee0d11ea12184ea1f601d) | block.c (332b3a175f8cbd730cfe0a53a8e52326f8f98b8b) |
---|---|
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 --- 3191 unchanged lines hidden (view full) --- 3200{ 3201 BlockDriverState *child_bs; 3202 3203 child_bs = child->bs; 3204 bdrv_detach_child(child); 3205 bdrv_unref(child_bs); 3206} 3207 | 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 --- 3191 unchanged lines hidden (view full) --- 3200{ 3201 BlockDriverState *child_bs; 3202 3203 child_bs = child->bs; 3204 bdrv_detach_child(child); 3205 bdrv_unref(child_bs); 3206} 3207 |
3208typedef struct BdrvSetInheritsFrom { 3209 BlockDriverState *bs; 3210 BlockDriverState *old_inherits_from; 3211} BdrvSetInheritsFrom; 3212 3213static void bdrv_set_inherits_from_abort(void *opaque) 3214{ 3215 BdrvSetInheritsFrom *s = opaque; 3216 3217 s->bs->inherits_from = s->old_inherits_from; 3218} 3219 3220static TransactionActionDrv bdrv_set_inherits_from_drv = { 3221 .abort = bdrv_set_inherits_from_abort, 3222 .clean = g_free, 3223}; 3224 3225/* @tran is allowed to be NULL. In this case no rollback is possible */ 3226static void bdrv_set_inherits_from(BlockDriverState *bs, 3227 BlockDriverState *new_inherits_from, 3228 Transaction *tran) 3229{ 3230 if (tran) { 3231 BdrvSetInheritsFrom *s = g_new(BdrvSetInheritsFrom, 1); 3232 3233 *s = (BdrvSetInheritsFrom) { 3234 .bs = bs, 3235 .old_inherits_from = bs->inherits_from, 3236 }; 3237 3238 tran_add(tran, &bdrv_set_inherits_from_drv, s); 3239 } 3240 3241 bs->inherits_from = new_inherits_from; 3242} 3243 |
|
3208/** 3209 * Clear all inherits_from pointers from children and grandchildren of 3210 * @root that point to @root, where necessary. | 3244/** 3245 * Clear all inherits_from pointers from children and grandchildren of 3246 * @root that point to @root, where necessary. |
3247 * @tran is allowed to be NULL. In this case no rollback is possible |
|
3211 */ | 3248 */ |
3212static void bdrv_unset_inherits_from(BlockDriverState *root, BdrvChild *child) | 3249static void bdrv_unset_inherits_from(BlockDriverState *root, BdrvChild *child, 3250 Transaction *tran) |
3213{ 3214 BdrvChild *c; 3215 3216 if (child->bs->inherits_from == root) { 3217 /* 3218 * Remove inherits_from only when the last reference between root and 3219 * child->bs goes away. 3220 */ 3221 QLIST_FOREACH(c, &root->children, next) { 3222 if (c != child && c->bs == child->bs) { 3223 break; 3224 } 3225 } 3226 if (c == NULL) { | 3251{ 3252 BdrvChild *c; 3253 3254 if (child->bs->inherits_from == root) { 3255 /* 3256 * Remove inherits_from only when the last reference between root and 3257 * child->bs goes away. 3258 */ 3259 QLIST_FOREACH(c, &root->children, next) { 3260 if (c != child && c->bs == child->bs) { 3261 break; 3262 } 3263 } 3264 if (c == NULL) { |
3227 child->bs->inherits_from = NULL; | 3265 bdrv_set_inherits_from(child->bs, NULL, tran); |
3228 } 3229 } 3230 3231 QLIST_FOREACH(c, &child->bs->children, next) { | 3266 } 3267 } 3268 3269 QLIST_FOREACH(c, &child->bs->children, next) { |
3232 bdrv_unset_inherits_from(root, c); | 3270 bdrv_unset_inherits_from(root, c, tran); |
3233 } 3234} 3235 3236/* Callers must ensure that child->frozen is false. */ 3237void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child) 3238{ 3239 if (child == NULL) { 3240 return; 3241 } 3242 | 3271 } 3272} 3273 3274/* Callers must ensure that child->frozen is false. */ 3275void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child) 3276{ 3277 if (child == NULL) { 3278 return; 3279 } 3280 |
3243 bdrv_unset_inherits_from(parent, child); | 3281 bdrv_unset_inherits_from(parent, child, NULL); |
3244 bdrv_root_unref_child(child); 3245} 3246 3247 3248static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load) 3249{ 3250 BdrvChild *c; 3251 QLIST_FOREACH(c, &bs->parents, next_parent) { --- 4575 unchanged lines hidden --- | 3282 bdrv_root_unref_child(child); 3283} 3284 3285 3286static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load) 3287{ 3288 BdrvChild *c; 3289 QLIST_FOREACH(c, &bs->parents, next_parent) { --- 4575 unchanged lines hidden --- |