block: Introduce BDRV_O_NO_BACKING
If an image references a backing file that doesn't exist, qemu-img info fails to open this image. Exactly in this case the info would be valuable, though: the user might want to find out which file is missing. This patch introduces a BDRV_O_NO_BACKING flag to ignore the backing file when opening the image. qemu-img info is the first user and provides info now even if the backing file is invalid. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									8f0056b763
								
							
						
					
					
						commit
						b783e409bf
					
				
							
								
								
									
										4
									
								
								block.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								block.c
									
									
									
									
									
								
							@ -477,7 +477,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
 | 
				
			|||||||
        unlink(filename);
 | 
					        unlink(filename);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    if (bs->backing_file[0] != '\0') {
 | 
					    if ((flags & BDRV_O_NO_BACKING) == 0 && bs->backing_file[0] != '\0') {
 | 
				
			||||||
        /* if there is a backing file, use it */
 | 
					        /* if there is a backing file, use it */
 | 
				
			||||||
        BlockDriver *back_drv = NULL;
 | 
					        BlockDriver *back_drv = NULL;
 | 
				
			||||||
        bs->backing_hd = bdrv_new("");
 | 
					        bs->backing_hd = bdrv_new("");
 | 
				
			||||||
@ -1352,7 +1352,7 @@ const char *bdrv_get_encrypted_filename(BlockDriverState *bs)
 | 
				
			|||||||
void bdrv_get_backing_filename(BlockDriverState *bs,
 | 
					void bdrv_get_backing_filename(BlockDriverState *bs,
 | 
				
			||||||
                               char *filename, int filename_size)
 | 
					                               char *filename, int filename_size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (!bs->backing_hd) {
 | 
					    if (!bs->backing_file) {
 | 
				
			||||||
        pstrcpy(filename, filename_size, "");
 | 
					        pstrcpy(filename, filename_size, "");
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        pstrcpy(filename, filename_size, bs->backing_file);
 | 
					        pstrcpy(filename, filename_size, bs->backing_file);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								block.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								block.h
									
									
									
									
									
								
							@ -39,6 +39,7 @@ typedef struct QEMUSnapshotInfo {
 | 
				
			|||||||
#define BDRV_O_NOCACHE     0x0020 /* do not use the host page cache */
 | 
					#define BDRV_O_NOCACHE     0x0020 /* do not use the host page cache */
 | 
				
			||||||
#define BDRV_O_CACHE_WB    0x0040 /* use write-back caching */
 | 
					#define BDRV_O_CACHE_WB    0x0040 /* use write-back caching */
 | 
				
			||||||
#define BDRV_O_NATIVE_AIO  0x0080 /* use native AIO instead of the thread pool */
 | 
					#define BDRV_O_NATIVE_AIO  0x0080 /* use native AIO instead of the thread pool */
 | 
				
			||||||
 | 
					#define BDRV_O_NO_BACKING  0x0100 /* don't open the backing file */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define BDRV_O_CACHE_MASK  (BDRV_O_NOCACHE | BDRV_O_CACHE_WB)
 | 
					#define BDRV_O_CACHE_MASK  (BDRV_O_NOCACHE | BDRV_O_CACHE_WB)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -884,7 +884,7 @@ static int img_info(int argc, char **argv)
 | 
				
			|||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        drv = NULL;
 | 
					        drv = NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) {
 | 
					    if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_NO_BACKING, drv) < 0) {
 | 
				
			||||||
        error("Could not open '%s'", filename);
 | 
					        error("Could not open '%s'", filename);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    bdrv_get_format(bs, fmt_name, sizeof(fmt_name));
 | 
					    bdrv_get_format(bs, fmt_name, sizeof(fmt_name));
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user