All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [PATCH v3 24/33] block: Make format drivers use child_of_bds
Date: Tue, 18 Feb 2020 13:42:33 +0100	[thread overview]
Message-ID: <20200218124242.584644-25-mreitz@redhat.com> (raw)
In-Reply-To: <20200218124242.584644-1-mreitz@redhat.com>

Commonly, they need to pass the BDRV_CHILD_IMAGE set as the
BdrvChildRole; but there are exceptions for drivers with external data
files (qcow2 and vmdk).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block/bochs.c     |  4 ++--
 block/cloop.c     |  4 ++--
 block/crypto.c    |  4 ++--
 block/dmg.c       |  4 ++--
 block/parallels.c |  4 ++--
 block/qcow.c      |  4 ++--
 block/qcow2.c     | 19 +++++++++++++------
 block/qed.c       |  4 ++--
 block/vdi.c       |  4 ++--
 block/vhdx.c      |  4 ++--
 block/vmdk.c      | 20 +++++++++++++++++---
 block/vpc.c       |  4 ++--
 12 files changed, 50 insertions(+), 29 deletions(-)

diff --git a/block/bochs.c b/block/bochs.c
index b013e73063..62c3f42548 100644
--- a/block/bochs.c
+++ b/block/bochs.c
@@ -110,8 +110,8 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
         return ret;
     }
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
diff --git a/block/cloop.c b/block/cloop.c
index 3ed9fa63cc..d374a8427d 100644
--- a/block/cloop.c
+++ b/block/cloop.c
@@ -71,8 +71,8 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
         return ret;
     }
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
diff --git a/block/crypto.c b/block/crypto.c
index 4da74a7737..2d85d9e70a 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -200,8 +200,8 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,
     unsigned int cflags = 0;
     QDict *cryptoopts = NULL;
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
diff --git a/block/dmg.c b/block/dmg.c
index af8188638c..bc64194577 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -439,8 +439,8 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
         return ret;
     }
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
diff --git a/block/parallels.c b/block/parallels.c
index 3d5b3b7c63..7dc9a1fa76 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -728,8 +728,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
     Error *local_err = NULL;
     char *buf;
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
diff --git a/block/qcow.c b/block/qcow.c
index 2bf8e8eb36..bc7f7c1054 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -130,8 +130,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
     qdict_extract_subqdict(options, &encryptopts, "encrypt.");
     encryptfmt = qdict_get_try_str(encryptopts, "format");
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         ret = -EINVAL;
         goto fail;
diff --git a/block/qcow2.c b/block/qcow2.c
index 2ce974df4d..7e1532cc5e 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1537,8 +1537,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
     }
 
     /* Open external data file */
-    s->data_file = bdrv_open_child(NULL, options, "data-file", bs, &child_file,
-                                   0, true, &local_err);
+    s->data_file = bdrv_open_child(NULL, options, "data-file", bs,
+                                   &child_of_bds, BDRV_CHILD_DATA,
+                                   true, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         ret = -EINVAL;
@@ -1548,8 +1549,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
     if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) {
         if (!s->data_file && s->image_data_file) {
             s->data_file = bdrv_open_child(s->image_data_file, options,
-                                           "data-file", bs, &child_file, 0,
-                                           false, errp);
+                                           "data-file", bs, &child_of_bds,
+                                           BDRV_CHILD_DATA, false, errp);
             if (!s->data_file) {
                 ret = -EINVAL;
                 goto fail;
@@ -1560,6 +1561,12 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
             ret = -EINVAL;
             goto fail;
         }
+
+        /* No data here */
+        bs->file->role &= ~BDRV_CHILD_DATA;
+
+        /* Must succeed because we have given up permissions if anything */
+        bdrv_child_refresh_perms(bs, bs->file, &error_abort);
     } else {
         if (s->data_file) {
             error_setg(errp, "'data-file' can only be set for images with an "
@@ -1808,8 +1815,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
         .ret = -EINPROGRESS
     };
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
diff --git a/block/qed.c b/block/qed.c
index d15ba11959..d6222798c2 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -547,8 +547,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
         .ret = -EINPROGRESS
     };
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
diff --git a/block/vdi.c b/block/vdi.c
index 987e2ed592..1736d02eee 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -378,8 +378,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
     Error *local_err = NULL;
     QemuUUID uuid_link, uuid_parent;
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
diff --git a/block/vhdx.c b/block/vhdx.c
index be23290ac8..d8a315015d 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -997,8 +997,8 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
     uint64_t signature;
     Error *local_err = NULL;
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
diff --git a/block/vmdk.c b/block/vmdk.c
index 84f99d881f..497414e5f2 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1089,6 +1089,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
     char *desc_file_dir = NULL;
     char *extent_path;
     BdrvChild *extent_file;
+    BdrvChildRole extent_role;
     BDRVVmdkState *s = bs->opaque;
     VmdkExtent *extent;
     char extent_opt_prefix[32];
@@ -1151,8 +1152,15 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
         ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents);
         assert(ret < 32);
 
+        extent_role = BDRV_CHILD_DATA;
+        if (strcmp(type, "FLAT") != 0 && strcmp(type, "VMFS") != 0) {
+            /* non-flat extents have metadata */
+            extent_role |= BDRV_CHILD_METADATA;
+        }
+
         extent_file = bdrv_open_child(extent_path, options, extent_opt_prefix,
-                                      bs, &child_file, 0, false, &local_err);
+                                      bs, &child_of_bds, extent_role, false,
+                                      &local_err);
         g_free(extent_path);
         if (local_err) {
             error_propagate(errp, local_err);
@@ -1257,8 +1265,8 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
     uint32_t magic;
     Error *local_err = NULL;
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
@@ -1277,6 +1285,12 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
             s->desc_offset = 0x200;
             break;
         default:
+            /* No data in the descriptor file */
+            bs->file->role &= ~BDRV_CHILD_DATA;
+
+            /* Must succeed because we have given up permissions if anything */
+            bdrv_child_refresh_perms(bs, bs->file, &error_abort);
+
             ret = vmdk_open_desc_file(bs, flags, buf, options, errp);
             break;
     }
diff --git a/block/vpc.c b/block/vpc.c
index 5378e32d1d..9acd6edac9 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -228,8 +228,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
     int ret;
     int64_t bs_size;
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               BDRV_CHILD_IMAGE, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
-- 
2.24.1



  parent reply	other threads:[~2020-02-18 13:02 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-18 12:42 [PATCH v3 00/33] block: Introduce real BdrvChildRole Max Reitz
2020-02-18 12:42 ` [PATCH v3 01/33] block: Add BlockDriver.is_format Max Reitz
2020-02-18 12:42 ` [PATCH v3 02/33] block: Rename BdrvChildRole to BdrvChildClass Max Reitz
2020-02-18 12:42 ` [PATCH v3 03/33] block: Add BdrvChildRole and BdrvChildRoleBits Max Reitz
2020-02-18 13:05   ` Eric Blake
2020-05-05 11:19   ` Kevin Wolf
2020-05-05 11:59     ` Max Reitz
2020-05-05 12:54       ` Kevin Wolf
2020-05-05 13:20         ` Max Reitz
2020-05-05 13:38           ` Kevin Wolf
2020-02-18 12:42 ` [PATCH v3 04/33] block: Add BdrvChildRole to BdrvChild Max Reitz
2020-02-18 13:06   ` Eric Blake
2020-02-18 12:42 ` [PATCH v3 05/33] block: Pass BdrvChildRole to bdrv_child_perm() Max Reitz
2020-02-18 12:42 ` [PATCH v3 06/33] block: Pass BdrvChildRole to .inherit_options() Max Reitz
2020-02-18 12:42 ` [PATCH v3 07/33] block: Pass parent_is_format " Max Reitz
2020-02-18 12:42 ` [PATCH v3 08/33] block: Rename bdrv_inherited_options() Max Reitz
2020-02-18 12:42 ` [PATCH v3 09/33] block: Add generic bdrv_inherited_options() Max Reitz
2020-05-06 10:37   ` Kevin Wolf
2020-05-06 13:11     ` Kevin Wolf
2020-05-07  9:18       ` Max Reitz
2020-05-07  8:49     ` Max Reitz
2020-05-07 11:19       ` Kevin Wolf
2020-05-07 11:34         ` Max Reitz
2020-02-18 12:42 ` [PATCH v3 10/33] block: Use bdrv_inherited_options() Max Reitz
2020-02-18 12:42 ` [PATCH v3 11/33] block: Unify bdrv_child_cb_attach() Max Reitz
2020-02-18 12:42 ` [PATCH v3 12/33] block: Unify bdrv_child_cb_detach() Max Reitz
2020-05-06 12:41   ` Kevin Wolf
2020-05-07  9:09     ` Max Reitz
2020-02-18 12:42 ` [PATCH v3 13/33] block: Add child_of_bds Max Reitz
2020-05-06 12:59   ` Kevin Wolf
2020-02-18 12:42 ` [PATCH v3 14/33] block: Distinguish paths in *_format_default_perms Max Reitz
2020-02-18 12:42 ` [PATCH v3 15/33] block: Pull out bdrv_default_perms_for_backing() Max Reitz
2020-05-06 13:21   ` Kevin Wolf
2020-05-07  9:19     ` Max Reitz
2020-02-18 12:42 ` [PATCH v3 16/33] block: Pull out bdrv_default_perms_for_storage() Max Reitz
2020-02-18 12:42 ` [PATCH v3 17/33] block: Split bdrv_default_perms_for_storage() Max Reitz
2020-02-18 12:42 ` [PATCH v3 18/33] block: Add bdrv_default_perms() Max Reitz
2020-05-06 13:47   ` Kevin Wolf
2020-05-07  9:26     ` Max Reitz
2020-02-18 12:42 ` [PATCH v3 19/33] raw-format: Split raw_read_options() Max Reitz
2020-02-18 12:42 ` [PATCH v3 20/33] block: Switch child_format users to child_of_bds Max Reitz
2020-02-18 13:10   ` Eric Blake
2020-02-18 12:42 ` [PATCH v3 21/33] block: Drop child_format Max Reitz
2020-02-18 12:42 ` [PATCH v3 22/33] block: Make backing files child_of_bds children Max Reitz
2020-05-06 16:37   ` Kevin Wolf
2020-05-07  9:28     ` Max Reitz
2020-02-18 12:42 ` [PATCH v3 23/33] block: Drop child_backing Max Reitz
2020-02-18 12:42 ` Max Reitz [this message]
2020-02-18 12:42 ` [PATCH v3 25/33] block: Make filter drivers use child_of_bds Max Reitz
2020-02-18 12:42 ` [PATCH v3 26/33] block: Use child_of_bds in remaining places Max Reitz
2020-05-06 17:04   ` Kevin Wolf
2020-05-07  9:33     ` Max Reitz
2020-05-07 11:32       ` Kevin Wolf
2020-02-18 12:42 ` [PATCH v3 27/33] tests: Use child_of_bds instead of child_file Max Reitz
2020-02-18 12:42 ` [PATCH v3 28/33] block: Use bdrv_default_perms() Max Reitz
2020-02-18 12:42 ` [PATCH v3 29/33] block: Make bdrv_filter_default_perms() static Max Reitz
2020-02-18 12:42 ` [PATCH v3 30/33] block: Drop bdrv_format_default_perms() Max Reitz
2020-02-18 12:42 ` [PATCH v3 31/33] block: Drop child_file Max Reitz
2020-02-18 12:42 ` [PATCH v3 32/33] block: Pass BdrvChildRole in remaining cases Max Reitz
2020-05-06 17:13   ` Kevin Wolf
2020-05-07  9:36     ` Max Reitz
2020-05-07 11:40       ` Kevin Wolf
2020-02-18 12:42 ` [PATCH v3 33/33] block: Drop @child_class from bdrv_child_perm() Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200218124242.584644-25-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.