Block Conversion
v4 cover Block Conversion
This patch series introduces the api to support block conversion.
Devin Nakamura (7):
block: add block conversion api
block: make bdrv_open_common more ready to be called by
bdrv_open_conversion_target
block: add bdrv_get_conversion_options()
block: add bdrv_open_conversion_target()
block: add bdrv_get_mapping()
block: add bdrv_map()
block: add bdrv_copy_header()
block.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- block.h | 16 +++++++ block_int.h | 82 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.6.rc1
PATCH v4 1/7 block: add block conversion api
add functions to block driver interface to support inplace image conversion
--- block.h | 3 ++ block_int.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 0 deletions(-)
block.h +3 -0
@@ -35,6 +35,7 @@ typedef struct QEMUSnapshotInfo {#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_NO_FLUSH 0x0200/* disable flushing on this disk */ +#define BDRV_O_CONVERSION 0x0400/* open as conversion target */ #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH)
@@ -254,6 +255,8 @@ int64_t bdrv_get_dirty_count(BlockDriverState *bs);void bdrv_set_in_use (BlockDriverState *bs,int in_use);int bdrv_in_use (BlockDriverState *bs); +typedef struct BlockConversionOptions BlockConversionOptions ; + typedef enum { BLKDBG_L1_UPDATE,
block_int.h +82 -0
98 lines not on this page · raw message
Signature · 1 line
1.7.6.rc1
Re: [Qemu-devel] [PATCH V4 1/7] block: add block conversion api
Am 23.08.2011 06:27, schrieb Devin Nakamura:
Quoted 45 lines
add functions to block driver interface to support inplace image conversion
Signed-off-by Devin Nakamura <[email protected]>--- block.h | 3 ++ block_int.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 0 deletions(-)block.h +3
-0@@ -35,6 +35,7 @@ typedef struct QEMUSnapshotInfo {#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_NO_FLUSH 0x0200/* disable flushing on this disk */ +#define BDRV_O_CONVERSION 0x0400/* open as conversion target */ #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH)@@ -254,6 +255,8 @@ int64_t bdrv_get_dirty_count(BlockDriverState *bs);void bdrv_set_in_use (BlockDriverState *bs,int in_use);int bdrv_in_use (BlockDriverState *bs); +typedef struct BlockConversionOptions BlockConversionOptions ; + typedef enum { BLKDBG_L1_UPDATE,block_int.h +3
-0@@ -42,6 +42,9 @@#define BLOCK_OPT_PREALLOC "preallocation"#define BLOCK_OPT_SUBFMT "subformat" +#define BLOCK_CRYPT_NONE 0 +#define BLOCK_CRYPT_AES 1 + typedef struct AIOPool { void (*cancel)(BlockDriverAIOCB *acb); int aiocb_size;@@ -145,6 +148,79 @@ struct BlockDriver {*/
block_int.h struct BlockDriver { · line 158
Quoted 10 lines
block_int.h +8
-0int (*bdrv_has_zero_init)(BlockDriverState *bs); +/* In-place image conversion */ + +/** +* Opens an image conversion target. +* +* @param bs Basic Initialization done by +* bdrv_open_conversion_target() Still need to set format +* specific data.
I find this hard to understand. Can we rephrase it? Maybe something like "Image to be opened. Basic initialization that doesn't depend on format specific data must be completed."
(An interface like this shouldn't refer to bdrv_open_conversion_target, which is an implementation detail of the user of the interface)
block_int.h struct BlockDriver { · line 160
Quoted 2 lines
block_int.h +2
-0+* @param usr_options Creation options. +* @param drv_options Conversion Options
Lower case "options"
Quoted 9 lines
block_int.h +9
-0+* @return Returns non-zero on failure. +*/ +int (*bdrv_open_conversion_target)(BlockDriverState *bs, +BlockConversionOptions *drv_options,QEMUOptionParameter *usr_options, +bool force); + +/** +* Gets a mapping from an offset in the image to an offset within a file +*
block_int.h struct BlockDriver { · line 179
Quoted 10 lines
block_int.h +10
-0+* All offsets are in bytes. +* +* @param guest_offset The starting offset of the mapping +* @param host_offset[out] The starting file offset of the mapping. +* A value of -1 is invalid and means the +* cluster is unallocated (contiguous_bytes is +* still valid) +* @param contiguous_bytes[out] The number of bytes for which this mapping +* is contiguous. If 0, there are no more +* mapppings in the image
Typo in "mappings"
Quoted 19 lines
block_int.h +19
-0+* @return Returns 0 on error; +*/ + +int (*bdrv_get_mapping)(BlockDriverState *bs,uint64_t guest_offset, +uint64_t *host_offset,uint64_t *contiguous_bytes); + +/** +* Sets a mapping in the image file. +* +* @param bs Usually opened with bdrv_open_conversion_target +* @param guest_offset The starting guest offset of the mapping +* (in bytes). +* @param host_offset The starting image offset of the mapping +* (in bytes). +* @param contiguous_bytes The number of bytes for which this mapping exists +* @return Returns non-zero on error. Will return -EINVAL if +* guest_offset, host_offset, or contiguous_bytes +* not cluster aligned +*/
block_int.h struct BlockDriver { · line 208
Quoted 10 lines
block_int.h +10
-0+int (*bdrv_map)(BlockDriverState *bs,uint64_t guest_offset, +uint64_t host_offset,uint64_t contiguous_bytes); + +/** +* Copies out the header of a conversion target +* +* Saves the current header for the image in a temporary file and overwrites +* it with the header for the new format (at the moment the header is +* assumed to be 1 sector) +* @param bs Usualy opened with bdrv_open_conversion_target()
"Must be opened..."? I don't think it makes sense with any other image.
block_int.h struct BlockDriver { · line 212
Quoted 4 lines
block_int.h +4
-0+* @param filename The name of the file to copy the header into +* @return Returns non-zero on failure +*/ +int (*bdrv_copy_header) (BlockDriverState *bs,char * filename);
const char*?
Quoted 15 lines
block_int.h +11
-0+ +/** +* Asks the block driver what options should be used to create a conversion +* target. +* +* @param options[out] Block conversion options +*/ +int (*bdrv_get_conversion_options)(BlockDriverState *bs, +BlockConversionOptions *options); + +QLIST_ENTRY (BlockDriver) list; };
block_int.h static inline unsigned int get_physical_block_exp(BlockConf *conf) · line 353
Quoted 9 lines
block_int.h +6
-0@@ -269,4 +345,10 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)DEFINE_PROP_UINT32 ("discard_granularity" , _state, \ _conf.discard_granularity, 0) +struct BlockConversionOptions { +int encryption_type; +uint64_t image_size; +uint64_t cluster_size; +int nb_snapshots; +};
If you put the two ints together, I think you would avoid some padding. Not that it really matters here...
Kevin
PATCH v4 2/7 block: make bdrv_open_common more ready to be called by bdrv_open_conversion_target
In reply to Devin Nakamura--- block.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-)
block.c +12 -6
@@ -441,14 +441,17 @@ static int refresh_total_sectors(BlockDriverState *bs, int64_t hint)* Common part for opening disk images and files */ static int bdrv_open_common (BlockDriverState *bs,const char *filename, -int flags,BlockDriver *drv) +int flags,BlockDriver *drv,BlockConversionOptions *drv_options, +QEMUOptionParameter *usr_options,bool force) {int ret, open_flags;assert (drv !=NULL ); - bs->file =NULL ; - bs->total_sectors =0 ; +if (~flags &BDRV_O_CONVERSION ) { + bs->file =NULL ; + bs->total_sectors =0 ; + } bs->encrypted =0 ; bs->valid_key =0 ; bs->open_flags = flags;
@@ -481,7 +484,10 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, }/* Open the image, either directly or using a protocol */ -if (drv->bdrv_file_open) { +if (flags &BDRV_O_CONVERSION ) { + ret = drv->bdrv_open_conversion_target (bs, drv_options, usr_options, + force); + }else if (drv->bdrv_file_open) { ret = drv->bdrv_file_open (bs, filename, open_flags); }else { ret =bdrv_file_open (&bs->file, filename, open_flags);
@@ -534,7 +540,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags) } bs =bdrv_new ("" ); - ret =bdrv_open_common (bs, filename, flags, drv); + ret =bdrv_open_common (bs, filename, flags, drv,NULL ,NULL , false);if (ret <0 ) {bdrv_delete (bs);return ret;
@@ -618,7 +624,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, }/* Open the image */ - ret =bdrv_open_common (bs, filename, flags, drv); + ret =bdrv_open_common (bs, filename, flags, drv,NULL ,NULL , false);if (ret <0 ) { goto unlink_and_fail; }
Signature · 1 line
1.7.6.rc1
Re: [Qemu-devel] [PATCH V4 2/7] block: make bdrv_open_common more ready to be called by bdrv_open_conversion_target
Am 23.08.2011 06:27, schrieb Devin Nakamura:
Quoted 14 lines
Signed-off-by Devin Nakamura <[email protected]>--- block.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-)block.c +0
-1@@ -441,14 +441,17 @@ static int refresh_total_sectors(BlockDriverState *bs, int64_t hint)* Common part for opening disk images and files */ static int bdrv_open_common(BlockDriverState *bs, const char *filename, -int flags,BlockDriver *drv)
block.c static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) · line 451
Quoted 10 lines
block.c +3
-2+ int flags, BlockDriver *drv, BlockConversionOptions *drv_options, + QEMUOptionParameter *usr_options, bool force) { int ret, open_flags;assert (drv !=NULL ); - bs->file =NULL ; - bs->total_sectors =0 ; +if (~flags &BDRV_O_CONVERSION ) {
I prefer if ((flags & BDRV_O_CONVERSION) == 0), but that's a matter of taste I guess.
block.c static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) · line 454
Quoted 3 lines
block.c +3
-0+ bs->file =NULL ; + bs->total_sectors =0 ; + }
Why are these a problem from BDRV_O_CONVERSION? (Reading the rest of the patch, I understand bs->file, but still not bs->total_sectors) Maybe add a comment.
Kevin
PATCH v4 3/7 block: add bdrv_get_conversion_options()
In reply to Devin Nakamura--- block.c | 13 +++++++++++++ block.h | 2 ++ 2 files changed, 15 insertions(+), 0 deletions(-)
block.c +13 -0
@@ -3281,3 +3281,16 @@ out:return ret; } + +int bdrv_get_conversion_options (BlockDriverState *bs, +BlockConversionOptions *options) +{ +if (!bs->drv) { +return -ENOENT ; + } + +if (!bs->drv->bdrv_get_conversion_options) { +return -ENOTSUP ; + } +return bs->drv->bdrv_get_conversion_options (bs, options); +}
block.h +2 -0
@@ -257,6 +257,8 @@ int bdrv_in_use(BlockDriverState *bs);typedef struct BlockConversionOptions BlockConversionOptions ; +int bdrv_get_conversion_options (BlockDriverState *bs, +BlockConversionOptions *options); typedef enum { BLKDBG_L1_UPDATE,
Signature · 1 line
1.7.6.rc1
PATCH v4 4/7 block: add bdrv_open_conversion_target()
In reply to Devin Nakamura--- block.c | 26 ++++++++++++++++++++++++++ block.h | 5 +++++ 2 files changed, 31 insertions(+), 0 deletions(-)
block.c +26 -0
@@ -3282,6 +3282,32 @@ out:return ret; } +int bdrv_open_conversion_target (BlockDriverState **bs,BlockDriverState *file, +BlockConversionOptions *drv_options, +QEMUOptionParameter *usr_options, +const char *target_fmt, +bool force) +{ +BlockDriver *drv; +BlockDriverState *bss; + *bs =NULL ; + + drv =bdrv_find_format (target_fmt); +if (!drv) { +return -ENOENT ; + } + +if (!drv->bdrv_open_conversion_target) { +return -ENOTSUP ; + } + + *bs =bdrv_new ("" ); + bss = *bs; + bss->file = file; +return bdrv_open_common (bss, file->filename,BDRV_O_CONVERSION , drv, + drv_options, usr_options, force); +} +int bdrv_get_conversion_options (BlockDriverState *bs,BlockConversionOptions *options) {
block.h +5 -0
@@ -259,6 +259,11 @@ typedef struct BlockConversionOptions BlockConversionOptions;int bdrv_get_conversion_options (BlockDriverState *bs,BlockConversionOptions *options); +int bdrv_open_conversion_target (BlockDriverState **bs,BlockDriverState *file, +BlockConversionOptions *drv_options, +QEMUOptionParameter *usr_options, +const char *target_fmt, +bool force); typedef enum { BLKDBG_L1_UPDATE,
Signature · 1 line
1.7.6.rc1
PATCH v4 5/7 block: add bdrv_get_mapping()
In reply to Devin Nakamura--- block.c | 15 +++++++++++++++ block.h | 2 ++ 2 files changed, 17 insertions(+), 0 deletions(-)
block.c +15 -0
@@ -3320,3 +3320,18 @@ int bdrv_get_conversion_options(BlockDriverState *bs, }return bs->drv->bdrv_get_conversion_options (bs, options); } + + +int bdrv_get_mapping (BlockDriverState *bs,uint64_t guest_offset, +uint64_t *host_offset,uint64_t *contiguous_bytes) +{ +BlockDriver *drv = bs->drv; +if (!drv) { +return -ENOMEDIUM ; + } +if (!drv->bdrv_get_mapping) { +return -ENOTSUP ; + } +return drv->bdrv_get_mapping (bs, guest_offset, host_offset, + contiguous_bytes); +}
block.h +2 -0
@@ -264,6 +264,8 @@ int bdrv_open_conversion_target(BlockDriverState **bs, BlockDriverState *file,QEMUOptionParameter *usr_options, const char *target_fmt, bool force); +int bdrv_get_mapping (BlockDriverState *bs,uint64_t guest_offset, +uint64_t *host_offset,uint64_t *contiguous_bytes); typedef enum { BLKDBG_L1_UPDATE,
Signature · 1 line
1.7.6.rc1
PATCH v4 6/7 block: add bdrv_map()
In reply to Devin Nakamura--- block.c | 14 ++++++++++++++ block.h | 2 ++ 2 files changed, 16 insertions(+), 0 deletions(-)
block.c +14 -0
@@ -3335,3 +3335,17 @@ int bdrv_get_mapping(BlockDriverState *bs, uint64_t guest_offset,return drv->bdrv_get_mapping (bs, guest_offset, host_offset, contiguous_bytes); } + +int bdrv_map (BlockDriverState *bs,uint64_t guest_offset, +uint64_t host_offset,uint64_t contiguous_bytes) +{ +BlockDriver *drv = bs->drv; +if (!drv) { +return -ENOMEDIUM ; + } +if (!drv->bdrv_map) { +return -ENOTSUP ; + } +return drv->bdrv_map (bs, guest_offset, host_offset, + contiguous_bytes); +}
block.h +2 -0
@@ -266,6 +266,8 @@ int bdrv_open_conversion_target(BlockDriverState **bs, BlockDriverState *file, bool force);int bdrv_get_mapping (BlockDriverState *bs,uint64_t guest_offset,uint64_t *host_offset,uint64_t *contiguous_bytes); +int bdrv_map (BlockDriverState *bs,uint64_t guest_offset, +uint64_t host_offset,uint64_t contiguous_bytes); typedef enum { BLKDBG_L1_UPDATE,
Signature · 1 line
1.7.6.rc1
PATCH v4 7/7 block: add bdrv_copy_header()
In reply to Devin Nakamura--- block.c | 41 +++++++++++++++++++++++++++++++++++++++++ block.h | 2 ++ 2 files changed, 43 insertions(+), 0 deletions(-)
block.c +41 -0
@@ -3349,3 +3349,44 @@ int bdrv_map(BlockDriverState *bs, uint64_t guest_offset,return drv->bdrv_map (bs, guest_offset, host_offset, contiguous_bytes); } + +/** +* Copies out the header of a conversion target +* +* Saves the current header for the image in a temporary file and overwrites +* it with the header for the new format (at the moment the header is +* assumed to be 1 sector) +* +* A filename can be specified by using filename. On entry if +* filename = NULL , or filename points to an empty string, a random file +* name will be generated. +* +* If a random filename was generated it will be returned to the user by +* copying it to the location pointed at by filename. Filename must already +* be allocated to a size of at least PATH_MAX +* +* @param bs Usualy opened with bdrv_open_conversion_target() +* @param filename[in,out] On entry is the optional filename to be used. On +* exit it will be the filename used (assuming +* filename != NULL at entry) +* @return Returns non-zero on failure +*/ +int bdrv_copy_header (BlockDriverState *bs,char *filename) +{ +BlockDriver *drv = bs->drv; +char tmp_filename[PATH_MAX ] ="" ; + +if (!drv) { +return -ENOMEDIUM ; + } +if (!drv->bdrv_copy_header) { +return -ENOTSUP ; + } +if (!filename) { + filename = tmp_filename; + } +if (!filename[0 ]) { +get_tmp_filename (filename,PATH_MAX ); + } +return drv->bdrv_copy_header (bs, filename); +}
block.h +2 -0
@@ -268,6 +268,8 @@ int bdrv_get_mapping(BlockDriverState *bs, uint64_t guest_offset, uint64_t *host_offset, uint64_t *contiguous_bytes);int bdrv_map (BlockDriverState *bs,uint64_t guest_offset,uint64_t host_offset,uint64_t contiguous_bytes); +int bdrv_copy_header (BlockDriverState *bs,char *filename); + typedef enum { BLKDBG_L1_UPDATE,
Signature · 1 line
1.7.6.rc1
Quoted 12 lines · Devin Nakamura
This patch series introduces the api to support block conversion.
Devin Nakamura (7):
block: add block conversion api
block: makebdrv_open_commonmore ready to be called bybdrv_open_conversion_target
block: addbdrv_get_conversion_options()
block: addbdrv_open_conversion_target()
block: addbdrv_get_mapping()
block: addbdrv_map()
block: addbdrv_copy_header()
Quoted 9 lines
block.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
block.h| 16 +++++++
block_int.h | 82 ++++++++++++++++++++++++++++++++++++++3 files changed, 219 insertions(+), 6 deletions(-)--
1.7.6.rc1
ping?
Am 23.08.2011 06:27, schrieb Devin Nakamura:
Quoted 12 lines
This patch series introduces the api to support block conversion.
Devin Nakamura (7):
block: add block conversion api
block: makebdrv_open_commonmore ready to be called by
bdrv_open_conversion_target
block: addbdrv_get_conversion_options()
block: addbdrv_open_conversion_target()
block: addbdrv_get_mapping()
block: addbdrv_map()
block: addbdrv_copy_header()
Quoted 4 lines
block.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- block.h | 16 +++++++ block_int.h | 82 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 6 deletions(-)
Looks good to me apart from the minor comments on patches 1 and 2.
We can't merge interfaces into master without having users, though. So as the interface itself seems to be final now, please continue with posting the patches implementing this interface. (You can just include more patches in a v5, or send a second patch series and add a note in PATCH 0/n that it depends on this one)
Kevin