vhdx: Use BB functions in .bdrv_create()
All users of the block layers are supposed to go through a BlockBackend. The .bdrv_create() implementation is one such user, so this patch converts it. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
		
							parent
							
								
									a08f0c3b5f
								
							
						
					
					
						commit
						10bf03af12
					
				
							
								
								
									
										23
									
								
								block/vhdx.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								block/vhdx.c
									
									
									
									
									
								
							@ -18,6 +18,7 @@
 | 
				
			|||||||
#include "qemu/osdep.h"
 | 
					#include "qemu/osdep.h"
 | 
				
			||||||
#include "qemu-common.h"
 | 
					#include "qemu-common.h"
 | 
				
			||||||
#include "block/block_int.h"
 | 
					#include "block/block_int.h"
 | 
				
			||||||
 | 
					#include "sysemu/block-backend.h"
 | 
				
			||||||
#include "qemu/module.h"
 | 
					#include "qemu/module.h"
 | 
				
			||||||
#include "qemu/crc32c.h"
 | 
					#include "qemu/crc32c.h"
 | 
				
			||||||
#include "block/vhdx.h"
 | 
					#include "block/vhdx.h"
 | 
				
			||||||
@ -1772,7 +1773,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    gunichar2 *creator = NULL;
 | 
					    gunichar2 *creator = NULL;
 | 
				
			||||||
    glong creator_items;
 | 
					    glong creator_items;
 | 
				
			||||||
    BlockDriverState *bs;
 | 
					    BlockBackend *blk;
 | 
				
			||||||
    char *type = NULL;
 | 
					    char *type = NULL;
 | 
				
			||||||
    VHDXImageType image_type;
 | 
					    VHDXImageType image_type;
 | 
				
			||||||
    Error *local_err = NULL;
 | 
					    Error *local_err = NULL;
 | 
				
			||||||
@ -1837,15 +1838,17 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
 | 
				
			|||||||
        goto exit;
 | 
					        goto exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bs = NULL;
 | 
					    blk = blk_new_open("image", filename, NULL, NULL,
 | 
				
			||||||
    ret = bdrv_open(&bs, filename, NULL, NULL,
 | 
					 | 
				
			||||||
                       BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
 | 
					                       BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
 | 
				
			||||||
                       &local_err);
 | 
					                       &local_err);
 | 
				
			||||||
    if (ret < 0) {
 | 
					    if (blk == NULL) {
 | 
				
			||||||
        error_propagate(errp, local_err);
 | 
					        error_propagate(errp, local_err);
 | 
				
			||||||
 | 
					        ret = -EIO;
 | 
				
			||||||
        goto exit;
 | 
					        goto exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    blk_set_allow_write_beyond_eof(blk, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Create (A) */
 | 
					    /* Create (A) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* The creator field is optional, but may be useful for
 | 
					    /* The creator field is optional, but may be useful for
 | 
				
			||||||
@ -1853,12 +1856,12 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
 | 
				
			|||||||
    creator = g_utf8_to_utf16("QEMU v" QEMU_VERSION, -1, NULL,
 | 
					    creator = g_utf8_to_utf16("QEMU v" QEMU_VERSION, -1, NULL,
 | 
				
			||||||
                              &creator_items, NULL);
 | 
					                              &creator_items, NULL);
 | 
				
			||||||
    signature = cpu_to_le64(VHDX_FILE_SIGNATURE);
 | 
					    signature = cpu_to_le64(VHDX_FILE_SIGNATURE);
 | 
				
			||||||
    ret = bdrv_pwrite(bs, VHDX_FILE_ID_OFFSET, &signature, sizeof(signature));
 | 
					    ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, &signature, sizeof(signature));
 | 
				
			||||||
    if (ret < 0) {
 | 
					    if (ret < 0) {
 | 
				
			||||||
        goto delete_and_exit;
 | 
					        goto delete_and_exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (creator) {
 | 
					    if (creator) {
 | 
				
			||||||
        ret = bdrv_pwrite(bs, VHDX_FILE_ID_OFFSET + sizeof(signature),
 | 
					        ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature),
 | 
				
			||||||
                         creator, creator_items * sizeof(gunichar2));
 | 
					                         creator, creator_items * sizeof(gunichar2));
 | 
				
			||||||
        if (ret < 0) {
 | 
					        if (ret < 0) {
 | 
				
			||||||
            goto delete_and_exit;
 | 
					            goto delete_and_exit;
 | 
				
			||||||
@ -1867,13 +1870,13 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Creates (B),(C) */
 | 
					    /* Creates (B),(C) */
 | 
				
			||||||
    ret = vhdx_create_new_headers(bs, image_size, log_size);
 | 
					    ret = vhdx_create_new_headers(blk_bs(blk), image_size, log_size);
 | 
				
			||||||
    if (ret < 0) {
 | 
					    if (ret < 0) {
 | 
				
			||||||
        goto delete_and_exit;
 | 
					        goto delete_and_exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Creates (D),(E),(G) explicitly. (F) created as by-product */
 | 
					    /* Creates (D),(E),(G) explicitly. (F) created as by-product */
 | 
				
			||||||
    ret = vhdx_create_new_region_table(bs, image_size, block_size, 512,
 | 
					    ret = vhdx_create_new_region_table(blk_bs(blk), image_size, block_size, 512,
 | 
				
			||||||
                                       log_size, use_zero_blocks, image_type,
 | 
					                                       log_size, use_zero_blocks, image_type,
 | 
				
			||||||
                                       &metadata_offset);
 | 
					                                       &metadata_offset);
 | 
				
			||||||
    if (ret < 0) {
 | 
					    if (ret < 0) {
 | 
				
			||||||
@ -1881,7 +1884,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Creates (H) */
 | 
					    /* Creates (H) */
 | 
				
			||||||
    ret = vhdx_create_new_metadata(bs, image_size, block_size, 512,
 | 
					    ret = vhdx_create_new_metadata(blk_bs(blk), image_size, block_size, 512,
 | 
				
			||||||
                                   metadata_offset, image_type);
 | 
					                                   metadata_offset, image_type);
 | 
				
			||||||
    if (ret < 0) {
 | 
					    if (ret < 0) {
 | 
				
			||||||
        goto delete_and_exit;
 | 
					        goto delete_and_exit;
 | 
				
			||||||
@ -1889,7 +1892,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
delete_and_exit:
 | 
					delete_and_exit:
 | 
				
			||||||
    bdrv_unref(bs);
 | 
					    blk_unref(blk);
 | 
				
			||||||
exit:
 | 
					exit:
 | 
				
			||||||
    g_free(type);
 | 
					    g_free(type);
 | 
				
			||||||
    g_free(creator);
 | 
					    g_free(creator);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user