block.c (5d69b5ab85d30201c1f5ef34651ba910977fc583) block.c (810803a87ce88abd695f07f434d00e7cd1e122e2)
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

--- 6258 unchanged lines hidden (view full) ---

6267 BdrvChild *child = bs->file ?: bs->backing;
6268 return bdrv_recurse_can_replace(child->bs, to_replace);
6269 }
6270
6271 /* Safe default */
6272 return false;
6273}
6274
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

--- 6258 unchanged lines hidden (view full) ---

6267 BdrvChild *child = bs->file ?: bs->backing;
6268 return bdrv_recurse_can_replace(child->bs, to_replace);
6269 }
6270
6271 /* Safe default */
6272 return false;
6273}
6274
6275/*
6276 * Check whether the given @node_name can be replaced by a node that
6277 * has the same data as @parent_bs. If so, return @node_name's BDS;
6278 * NULL otherwise.
6279 *
6280 * @node_name must be a (recursive) *child of @parent_bs (or this
6281 * function will return NULL).
6282 *
6283 * The result (whether the node can be replaced or not) is only valid
6284 * for as long as no graph or permission changes occur.
6285 */
6275BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs,
6276 const char *node_name, Error **errp)
6277{
6278 BlockDriverState *to_replace_bs = bdrv_find_node(node_name);
6279 AioContext *aio_context;
6280
6281 if (!to_replace_bs) {
6282 error_setg(errp, "Node name '%s' not found", node_name);

--- 8 unchanged lines hidden (view full) ---

6291 goto out;
6292 }
6293
6294 /* We don't want arbitrary node of the BDS chain to be replaced only the top
6295 * most non filter in order to prevent data corruption.
6296 * Another benefit is that this tests exclude backing files which are
6297 * blocked by the backing blockers.
6298 */
6286BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs,
6287 const char *node_name, Error **errp)
6288{
6289 BlockDriverState *to_replace_bs = bdrv_find_node(node_name);
6290 AioContext *aio_context;
6291
6292 if (!to_replace_bs) {
6293 error_setg(errp, "Node name '%s' not found", node_name);

--- 8 unchanged lines hidden (view full) ---

6302 goto out;
6303 }
6304
6305 /* We don't want arbitrary node of the BDS chain to be replaced only the top
6306 * most non filter in order to prevent data corruption.
6307 * Another benefit is that this tests exclude backing files which are
6308 * blocked by the backing blockers.
6309 */
6299 if (!bdrv_recurse_is_first_non_filter(parent_bs, to_replace_bs)) {
6300 error_setg(errp, "Only top most non filter can be replaced");
6310 if (!bdrv_recurse_can_replace(parent_bs, to_replace_bs)) {
6311 error_setg(errp, "Cannot replace '%s' by a node mirrored from '%s', "
6312 "because it cannot be guaranteed that doing so would not "
6313 "lead to an abrupt change of visible data",
6314 node_name, parent_bs->node_name);
6301 to_replace_bs = NULL;
6302 goto out;
6303 }
6304
6305out:
6306 aio_context_release(aio_context);
6307 return to_replace_bs;
6308}

--- 308 unchanged lines hidden ---
6315 to_replace_bs = NULL;
6316 goto out;
6317 }
6318
6319out:
6320 aio_context_release(aio_context);
6321 return to_replace_bs;
6322}

--- 308 unchanged lines hidden ---