Skip to contentSkip to conversation

block: Use BDRV_O_NO_BACKING where appropriate

PATCH In review Kevin Wolf 4 participants 4 messages Nov 28, 2013 – Dec 2, 2013 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 block: Use BDRV_O_NO_BACKING where appropriate

If you open an image temporarily just because you want to check its size or get it flushed, there's no real reason to open the whole backing file chain.

---
 block.c       | 3 ++-
 block/qcow2.c | 3 ++-
 block/vmdk.c  | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)
block.c +2 -1
index 03e45fc..e2745a5 100644
@@ -1061,7 +1061,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
         /* Get the required size from the image */
         bs1 = bdrv_new("");
         QINCREF(options);
-        ret = bdrv_open(bs1, filename, options, 0, drv, &local_err);
+        ret = bdrv_open(bs1, filename, options, BDRV_O_NO_BACKING,
+                        drv, &local_err);
         if (ret < 0) {
             bdrv_unref(bs1);
             goto fail;
block/qcow2.c +2 -1
index 2fe37ed..8e2b6c7 100644
@@ -1588,7 +1588,8 @@ static int qcow2_create2(const char *filename, int64_t total_size,
 
     /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
     ret = bdrv_open(bs, filename, NULL,
-                    BDRV_O_RDWR | BDRV_O_CACHE_WB, drv, &local_err);
+                    BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING,
+                    drv, &local_err);
     if (error_is_set(&local_err)) {
         error_propagate(errp, local_err);
         goto out;
block/vmdk.c +1 -1
index 6555663..5fb6c81 100644
@@ -1690,7 +1690,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
     }
     if (backing_file) {
         BlockDriverState *bs = bdrv_new("");
-        ret = bdrv_open(bs, backing_file, NULL, 0, NULL, errp);
+        ret = bdrv_open(bs, backing_file, NULL, BDRV_O_NO_BACKING, NULL, errp);
         if (ret != 0) {
             bdrv_unref(bs);
             return ret;
Signature · 1 line
1.8.1.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 45 lines · Kevin Wolf

If you open an image temporarily just because you want to check its size or get it flushed, there's no real reason to open the whole backing file chain.

---
  block.c       | 3 ++-
  block/qcow2.c | 3 ++-
  block/vmdk.c  | 2 +-
  3 files changed, 5 insertions(+), 3 deletions(-)
block.c +2 -1
index 03e45fc..e2745a5 100644
@@ -1061,7 +1061,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
          /* Get the required size from the image */
          bs1 = bdrv_new("");
          QINCREF(options);
-        ret = bdrv_open(bs1, filename, options, 0, drv, &local_err);
+        ret = bdrv_open(bs1, filename, options, BDRV_O_NO_BACKING,
+                        drv, &local_err);
          if (ret < 0) {
              bdrv_unref(bs1);
              goto fail;
block/qcow2.c +2 -1
index 2fe37ed..8e2b6c7 100644
@@ -1588,7 +1588,8 @@ static int qcow2_create2(const char *filename, int64_t total_size,
 
      /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
      ret = bdrv_open(bs, filename, NULL,
-                    BDRV_O_RDWR | BDRV_O_CACHE_WB, drv, &local_err);
+                    BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING,
+                    drv, &local_err);
      if (error_is_set(&local_err)) {
          error_propagate(errp, local_err);
          goto out;
block/vmdk.c +0 -0
index 6555663..5fb6c81 100644

block/vmdk.c static int vmdk_create(const char *filename, QEMUOptionParameter *options, · line 1696

Quoted 8 lines
block/vmdk.c +1 -1
@@ -1690,7 +1690,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
      }
      if (backing_file) {
          BlockDriverState *bs = bdrv_new("");
-        ret = bdrv_open(bs, backing_file, NULL, 0, NULL, errp);
+        ret = bdrv_open(bs, backing_file, NULL, BDRV_O_NO_BACKING, NULL, errp);
          if (ret != 0) {
              bdrv_unref(bs);
              return ret;
Reviewed-by Benoit Canet on v1 1/1
#2 lore raw
In reply to Kevin Wolf
Quoted 56 lines · Kevin Wolf

If you open an image temporarily just because you want to check its size or get it flushed, there's no real reason to open the whole backing file chain.

---
 block.c       | 3 ++-
 block/qcow2.c | 3 ++-
 block/vmdk.c  | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)
block.c +2 -1
index 03e45fc..e2745a5 100644
@@ -1061,7 +1061,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
         /* Get the required size from the image */
         bs1 = bdrv_new("");
         QINCREF(options);
-        ret = bdrv_open(bs1, filename, options, 0, drv, &local_err);
+        ret = bdrv_open(bs1, filename, options, BDRV_O_NO_BACKING,
+                        drv, &local_err);
         if (ret < 0) {
             bdrv_unref(bs1);
             goto fail;
block/qcow2.c +2 -1
index 2fe37ed..8e2b6c7 100644
@@ -1588,7 +1588,8 @@ static int qcow2_create2(const char *filename, int64_t total_size,
 
     /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
     ret = bdrv_open(bs, filename, NULL,
-                    BDRV_O_RDWR | BDRV_O_CACHE_WB, drv, &local_err);
+                    BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING,
+                    drv, &local_err);
     if (error_is_set(&local_err)) {
         error_propagate(errp, local_err);
         goto out;
block/vmdk.c +1 -1
index 6555663..5fb6c81 100644
@@ -1690,7 +1690,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
     }
     if (backing_file) {
         BlockDriverState *bs = bdrv_new("");
-        ret = bdrv_open(bs, backing_file, NULL, 0, NULL, errp);
+        ret = bdrv_open(bs, backing_file, NULL, BDRV_O_NO_BACKING, NULL, errp);
         if (ret != 0) {
             bdrv_unref(bs);
             return ret;
Signature · 1 line
1.8.1.4

No Tested-By as it doesn't apply to kevin/master yet.