block: Factor out should_update_child()
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
This commit is contained in:
		
							parent
							
								
									067acf28d1
								
							
						
					
					
						commit
						d0ac038025
					
				
							
								
								
									
										24
									
								
								block.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								block.c
									
									
									
									
									
								
							@ -2886,15 +2886,14 @@ void bdrv_close_all(void)
 | 
				
			|||||||
    assert(QTAILQ_EMPTY(&all_bdrv_states));
 | 
					    assert(QTAILQ_EMPTY(&all_bdrv_states));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void change_parent_backing_link(BlockDriverState *from,
 | 
					static bool should_update_child(BdrvChild *c, BlockDriverState *to)
 | 
				
			||||||
                                       BlockDriverState *to)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    BdrvChild *c, *next, *to_c;
 | 
					    BdrvChild *to_c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) {
 | 
					 | 
				
			||||||
    if (c->role->stay_at_node) {
 | 
					    if (c->role->stay_at_node) {
 | 
				
			||||||
            continue;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (c->role == &child_backing) {
 | 
					    if (c->role == &child_backing) {
 | 
				
			||||||
        /* If @from is a backing file of @to, ignore the child to avoid
 | 
					        /* If @from is a backing file of @to, ignore the child to avoid
 | 
				
			||||||
         * creating a loop. We only want to change the pointer of other
 | 
					         * creating a loop. We only want to change the pointer of other
 | 
				
			||||||
@ -2905,10 +2904,23 @@ static void change_parent_backing_link(BlockDriverState *from,
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (to_c) {
 | 
					        if (to_c) {
 | 
				
			||||||
                continue;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void change_parent_backing_link(BlockDriverState *from,
 | 
				
			||||||
 | 
					                                       BlockDriverState *to)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    BdrvChild *c, *next;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) {
 | 
				
			||||||
 | 
					        if (!should_update_child(c, to)) {
 | 
				
			||||||
 | 
					            continue;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        bdrv_ref(to);
 | 
					        bdrv_ref(to);
 | 
				
			||||||
        /* FIXME Are we sure that bdrv_replace_child() can't run into
 | 
					        /* FIXME Are we sure that bdrv_replace_child() can't run into
 | 
				
			||||||
         * &error_abort because of permissions? */
 | 
					         * &error_abort because of permissions? */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user