Skip to contentSkip to conversation

block_int: add basic conversion api

PATCH Superseded Devin Nakamura 3 participants 12 messages Jul 5, 2011 – Jul 13, 2011

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 block_int: add basic conversion api

add functions to block driver interface to support inplace image conversion

---
 block_int.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
block_int.h +10 -0
index 1e265d2..ef311c7 100644
@@ -136,6 +136,16 @@ struct BlockDriver {
      * zeros, 0 otherwise.
      */
     int (*bdrv_has_zero_init)(BlockDriverState *bs);
+    
+    /*  Image conversion stuff */
+    int (*bdrv_open_conversion_target)(BlockDriverState *bs, char *filename,
+        QEMUOptionParameter *options);
+    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);
+    
 
     QLIST_ENTRY(BlockDriver) list;
 };
Signature · 1 line
1.7.6.rc1
#1 lore raw

PATCH 2/5 block: add bdrv_open_conversion_target

---
 block.c |   19 +++++++++++++++++++
 block.h |    2 ++
 2 files changed, 21 insertions(+), 0 deletions(-)
block.c +19 -0
index 24a25d5..e7699a6 100644
@@ -3018,3 +3018,22 @@ out:
 
     return ret;
 }
+
+
+int bdrv_open_conversion_target(BlockDriverState **bs,
+        char *filename, char *target_fmt, QEMUOptionParameter *options)
+{
+    BlockDriver *drv;
+
+    drv = bdrv_find_format(target_fmt);
+    if(!drv){
+        return -ENOENT;
+    }
+
+    if(!drv->bdrv_open_conversion_target){
+        return -ENOTSUP;
+    }
+    *bs = bdrv_new("");
+    (*bs)->opaque = qemu_malloc(drv->instance_size);
+    return drv->bdrv_open_conversion_target(*bs, filename, options);
+}
block.h +2 -0
index 859d1d9..da87afb 100644
@@ -250,6 +250,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);
 
+int bdrv_open_conversion_target(BlockDriverState **bs, char *filename,
+                                char *target_fmt, QEMUOptionParameter *options);
 typedef enum {
     BLKDBG_L1_UPDATE,
 
Signature · 1 line
1.7.6.rc1
#2 lore raw

Re: [Qemu-devel] [PATCH 2/5] block: add bdrv_open_conversion_target

Am 05.07.2011 06:41, schrieb Devin Nakamura:

Quoted 13 lines
---
 block.c |   19 +++++++++++++++++++
 block.h |    2 ++
 2 files changed, 21 insertions(+), 0 deletions(-)
block.c +0 -0
index 24a25d5..e7699a6 100644
@@ -3018,3 +3018,22 @@ out:
 
     return ret;

block.c out: · line 3029

Quoted 10 lines
block.c +9 -0
 }
+
+
+int bdrv_open_conversion_target(BlockDriverState **bs,
+        char *filename, char *target_fmt, QEMUOptionParameter *options)
+{
+    BlockDriver *drv;
+
+    drv = bdrv_find_format(target_fmt);
+    if(!drv){

I'll comment on it here, but you need to fix the coding style in the whole series. You may want to try scripts/checkpatch.pl.

block.c out: · line 3038

Quoted 9 lines
block.c +9 -0
+        return -ENOENT;
+    }
+
+    if(!drv->bdrv_open_conversion_target){
+        return -ENOTSUP;
+    }
+    *bs = bdrv_new("");
+    (*bs)->opaque = qemu_malloc(drv->instance_size);
+    return drv->bdrv_open_conversion_target(*bs, filename, options);

Is this actually enough? The normal bdrv_open() sets much more fields of the BlockDriverState, and I would expect that the block drivers rely on at least some of them.

Kevin

#3 lore raw

Re: [Qemu-devel] [PATCH 2/5] block: add bdrv_open_conversion_target

In reply to Devin Nakamura

block.c out: · line 3029

Quoted 7 lines · Devin Nakamura
block.c +7 -0
+int bdrv_open_conversion_target(BlockDriverState **bs,
+        char *filename, char *target_fmt, QEMUOptionParameter *options)
+{
+    BlockDriver *drv;
+
+    drv = bdrv_find_format(target_fmt);
+    if(!drv){

Please run scripts/checkpatch.pl before submitting patches. It will report coding style issues.

block.c out: · line 3037

Quoted 8 lines
block.c +8 -0
+        return -ENOENT;
+    }
+
+    if(!drv->bdrv_open_conversion_target){
+        return -ENOTSUP;
+    }
+    *bs = bdrv_new("");
+    (*bs)->opaque = qemu_malloc(drv->instance_size);

Please use qemu_mallocz() like bdrv_open_common() does. This is safer in case a block driver relies on the memory being zeroed (which is a useful property).

Quoted 1 line

+ return drv->bdrv_open_conversion_target(*bs, filename, options);

Have you considered using bdrv_open_common() with a flag to avoid duplicating bs initialization code? You have not dealt with several fields that bdrv_open_common() initializes.

Stefan

#4 lore raw

PATCH 3/5 block: add bdrv_get_mapping()

In reply to Devin Nakamura
---
 block.c |   12 ++++++++++++
 block.h |    2 ++
 2 files changed, 14 insertions(+), 0 deletions(-)
block.c +12 -0
index e7699a6..302b0d5 100644
@@ -3037,3 +3037,15 @@ int bdrv_open_conversion_target(BlockDriverState **bs,
     (*bs)->opaque = qemu_malloc(drv->instance_size);
     return drv->bdrv_open_conversion_target(*bs, filename, 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
index da87afb..8207389 100644
@@ -252,6 +252,8 @@ int bdrv_in_use(BlockDriverState *bs);
 
 int bdrv_open_conversion_target(BlockDriverState **bs, char *filename,
                                 char *target_fmt, QEMUOptionParameter *options);
+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
#5 lore raw

PATCH v2 3/5 block: add bdrv_get_mapping()

---
 block.c |   14 ++++++++++++++
 block.h |    2 ++
 2 files changed, 16 insertions(+), 0 deletions(-)
block.c +14 -0
index 97d5a6b..3874ed5 100644
@@ -3037,3 +3037,17 @@ int bdrv_open_conversion_target(BlockDriverState **bs,
     (*bs)->opaque = qemu_malloc(drv->instance_size);
     return drv->bdrv_open_conversion_target(*bs, filename, 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
index da87afb..8207389 100644
@@ -252,6 +252,8 @@ int bdrv_in_use(BlockDriverState *bs);
 
 int bdrv_open_conversion_target(BlockDriverState **bs, char *filename,
                                 char *target_fmt, QEMUOptionParameter *options);
+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
#6 lore raw

Re: [Qemu-devel] [PATCH v2 3/5] block: add bdrv_get_mapping()

Am 11.07.2011 21:55, schrieb Devin Nakamura:

Quoted 5 lines
---
 block.c |   14 ++++++++++++++
 block.h |    2 ++
 2 files changed, 16 insertions(+), 0 deletions(-)

I only received patches 3-5 for v2, the first two seem to be missing.

Kevin

#7 lore raw

PATCH 4/5 block: add bdrv_map()

In reply to Devin Nakamura
---
 block.c |   12 ++++++++++++
 block.h |    2 ++
 2 files changed, 14 insertions(+), 0 deletions(-)
block.c +12 -0
index 302b0d5..c9ea201 100644
@@ -3049,3 +3049,15 @@ 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
index 8207389..ed21ead 100644
@@ -254,6 +254,8 @@ int bdrv_open_conversion_target(BlockDriverState **bs, char *filename,
                                 char *target_fmt, QEMUOptionParameter *options);
 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
#8 lore raw

PATCH v2 4/5 block: add bdrv_map()

---
 block.c |   14 ++++++++++++++
 block.h |    2 ++
 2 files changed, 16 insertions(+), 0 deletions(-)
block.c +14 -0
index 3874ed5..39510cb 100644
@@ -3051,3 +3051,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
index 8207389..ed21ead 100644
@@ -254,6 +254,8 @@ int bdrv_open_conversion_target(BlockDriverState **bs, char *filename,
                                 char *target_fmt, QEMUOptionParameter *options);
 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
#9 lore raw

PATCH 5/5 block: add bdrv_copy_header()

In reply to Devin Nakamura
---
 block.c |   10 ++++++++++
 block.h |    2 ++
 2 files changed, 12 insertions(+), 0 deletions(-)
block.c +10 -0
index c9ea201..c6c36e7 100644
@@ -3061,3 +3061,13 @@ int bdrv_map(BlockDriverState *bs, uint64_t *guest_offset,
     return drv->bdrv_map(bs, guest_offset, host_offset,
         contiguous_bytes);
 }
+
+int bdrv_copy_header(BlockDriverState *bs)
+{
+    BlockDriver *drv = bs->drv;
+    if (!drv)
+        return -ENOMEDIUM;
+    if (!drv->bdrv_copy_header)
+        return -ENOTSUP;
+    return drv->bdrv_copy_header(bs);
+}
block.h +2 -0
index ed21ead..0583875 100644
@@ -256,6 +256,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);
+
 typedef enum {
     BLKDBG_L1_UPDATE,
 
Signature · 1 line
1.7.6.rc1
#10 lore raw

PATCH v2 5/5 block: add bdrv_copy_header()

---
 block.c |   12 ++++++++++++
 block.h |    2 ++
 2 files changed, 14 insertions(+), 0 deletions(-)
block.c +12 -0
index 39510cb..69a3e13 100644
@@ -3065,3 +3065,15 @@ int bdrv_map(BlockDriverState *bs, uint64_t *guest_offset,
     return drv->bdrv_map(bs, guest_offset, host_offset,
         contiguous_bytes);
 }
+
+int bdrv_copy_header(BlockDriverState *bs)
+{
+    BlockDriver *drv = bs->drv;
+    if (!drv) {
+        return -ENOMEDIUM;
+    }
+    if (!drv->bdrv_copy_header) {
+        return -ENOTSUP;
+    }
+    return drv->bdrv_copy_header(bs);
+}
block.h +2 -0
index ed21ead..0583875 100644
@@ -256,6 +256,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);
+
 typedef enum {
     BLKDBG_L1_UPDATE,
 
Signature · 1 line
1.7.6.rc1
#11 lore raw
In reply to Devin Nakamura

On Tue, Jul 05, 2011 at 12:41:20AM -0400, Devin Nakamura wrote:

Please use 'block' instead of 'block_int' as the tag for this patch. I usually do git log <filename> to find out which tag is used for a particular file. 'block_int' has never been used in qemu.git but 'block' is used on block layer changes.

Quoted 12 lines

add functions to block driver interface to support inplace image conversion

---
 block_int.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
block_int.h +0 -0
index 1e265d2..ef311c7 100644

block_int.h struct BlockDriver { · line 140

Quoted 5 lines
block_int.h +2 -0
@@ -136,6 +136,16 @@ struct BlockDriver {
      * zeros, 0 otherwise.
      */
     int (*bdrv_has_zero_init)(BlockDriverState *bs);
+    
+    /*  Image conversion stuff */

How about:

/* In-place image conversion */

block_int.h struct BlockDriver { · line 147

Quoted 7 lines
block_int.h +7 -0
+    int (*bdrv_open_conversion_target)(BlockDriverState *bs, char *filename,
+        QEMUOptionParameter *options);
+    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);

Please document these functions so people working on block drivers know what semantics they must implement. Unfortunately other interfaces are not documented but I don't see a reason to avoid documentation in the future.

Important bits would be:
* How is .bdrv_open_conversion_target() different from a regular .bdrv_open()?
* Which BlockDriver functions are fair game to be called while opened as a conversion target?
* Any constraints or assumptions when a block device is in conversion target mode?
* How do the pointer arguments of .bdrv_get_mapping() behave? Which arguments are inputs, outputs, input/output?
* Does .bdrv_copy_header() actually copy any header or does it "install" or "write out" a new header?
* After .bdrv_copy_header() is the block device upgraded to first-class operation or do you need to close and then reopen the image file?

Stefan