blockdev: Fix drive_del not to crash when drive is not in use
Watch this:
    (qemu) drive_add 0 if=none,file=tmp.img
    OK
    (qemu) info block
    none0: type=hd removable=0 file=tmp.img ro=0 drv=raw encrypted=0
    (qemu) drive_del none0
    Segmentation fault (core dumped)
do_drive_del()'s code to clean up the pointer from a qdev using the
drive back to the drive needs to check whether such a device exists.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
			
			
This commit is contained in:
		
							parent
							
								
									807105a775
								
							
						
					
					
						commit
						850ec1133b
					
				@ -687,16 +687,18 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
 | 
			
		||||
 | 
			
		||||
    /* clean up guest state from pointing to host resource by
 | 
			
		||||
     * finding and removing DeviceState "drive" property */
 | 
			
		||||
    if (bs->peer) {
 | 
			
		||||
        for (prop = bs->peer->info->props; prop && prop->name; prop++) {
 | 
			
		||||
            if (prop->info->type == PROP_TYPE_DRIVE) {
 | 
			
		||||
                ptr = qdev_get_prop_ptr(bs->peer, prop);
 | 
			
		||||
            if ((*ptr) == bs) {
 | 
			
		||||
                if (*ptr == bs) {
 | 
			
		||||
                    bdrv_detach(bs, bs->peer);
 | 
			
		||||
                    *ptr = NULL;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* clean up host side */
 | 
			
		||||
    drive_uninit(drive_get_by_blockdev(bs));
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user