All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v5 09/22] block: Allow reference for bdrv_file_open()
Date: Fri, 13 Dec 2013 18:10:20 +0100	[thread overview]
Message-ID: <1386954633-28905-10-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1386954633-28905-1-git-send-email-mreitz@redhat.com>

Allow specifying a reference to an existing block device (by name) for
bdrv_file_open() instead of a filename and/or options.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c               | 25 ++++++++++++++++++++++---
 block/blkdebug.c      |  2 +-
 block/blkverify.c     |  2 +-
 block/cow.c           |  3 ++-
 block/qcow.c          |  3 ++-
 block/qcow2.c         |  2 +-
 block/qed.c           |  4 ++--
 block/sheepdog.c      |  4 ++--
 block/vhdx.c          |  2 +-
 block/vmdk.c          |  4 ++--
 include/block/block.h |  3 ++-
 qemu-io.c             |  2 +-
 12 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/block.c b/block.c
index 64e7d22..1e53b3d 100644
--- a/block.c
+++ b/block.c
@@ -858,9 +858,10 @@ free_and_fail:
  * dictionary, it needs to use QINCREF() before calling bdrv_file_open.
  */
 int bdrv_file_open(BlockDriverState **pbs, const char *filename,
-                   QDict *options, int flags, Error **errp)
+                   const char *reference, QDict *options, int flags,
+                   Error **errp)
 {
-    BlockDriverState *bs;
+    BlockDriverState *bs = NULL;
     BlockDriver *drv;
     const char *drvname;
     bool allow_protocol_prefix = false;
@@ -872,6 +873,24 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
         options = qdict_new();
     }
 
+    if (reference) {
+        if (filename || qdict_size(options)) {
+            error_setg(errp, "Cannot reference an existing block device with "
+                       "additional options or a new filename");
+            return -EINVAL;
+        }
+        QDECREF(options);
+
+        bs = bdrv_find(reference);
+        if (!bs) {
+            error_setg(errp, "Cannot find block device '%s'", reference);
+            return -ENODEV;
+        }
+        bdrv_ref(bs);
+        *pbs = bs;
+        return 0;
+    }
+
     bs = bdrv_new("");
     bs->options = options;
     options = qdict_clone_shallow(options);
@@ -1124,7 +1143,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
 
     qdict_extract_subqdict(options, &file_options, "file.");
 
-    ret = bdrv_file_open(&file, filename, file_options,
+    ret = bdrv_file_open(&file, filename, NULL, file_options,
                          bdrv_open_flags(bs, flags | BDRV_O_UNMAP), &local_err);
     if (ret < 0) {
         goto fail;
diff --git a/block/blkdebug.c b/block/blkdebug.c
index 08ea88c..c73a6cf 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -403,7 +403,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail;
     }
 
-    ret = bdrv_file_open(&bs->file, filename, NULL, flags, &local_err);
+    ret = bdrv_file_open(&bs->file, filename, NULL, NULL, flags, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto fail;
diff --git a/block/blkverify.c b/block/blkverify.c
index 3c63528..c6eb287 100644
--- a/block/blkverify.c
+++ b/block/blkverify.c
@@ -141,7 +141,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail;
     }
 
-    ret = bdrv_file_open(&bs->file, raw, NULL, flags, &local_err);
+    ret = bdrv_file_open(&bs->file, raw, NULL, NULL, flags, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto fail;
diff --git a/block/cow.c b/block/cow.c
index dc15e46..7fc0b12 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -351,7 +351,8 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
         return ret;
     }
 
-    ret = bdrv_file_open(&cow_bs, filename, NULL, BDRV_O_RDWR, &local_err);
+    ret = bdrv_file_open(&cow_bs, filename, NULL, NULL, BDRV_O_RDWR,
+                         &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
diff --git a/block/qcow.c b/block/qcow.c
index c470e05..948b0c5 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -691,7 +691,8 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
         return ret;
     }
 
-    ret = bdrv_file_open(&qcow_bs, filename, NULL, BDRV_O_RDWR, &local_err);
+    ret = bdrv_file_open(&qcow_bs, filename, NULL, NULL, BDRV_O_RDWR,
+                         &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
diff --git a/block/qcow2.c b/block/qcow2.c
index f29aa88..62e3f6a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1483,7 +1483,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
         return ret;
     }
 
-    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR, &local_err);
+    ret = bdrv_file_open(&bs, filename, NULL, NULL, BDRV_O_RDWR, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
diff --git a/block/qed.c b/block/qed.c
index 450a1fa..0dd5c58 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -563,8 +563,8 @@ static int qed_create(const char *filename, uint32_t cluster_size,
         return ret;
     }
 
-    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB,
-                         &local_err);
+    ret = bdrv_file_open(&bs, filename, NULL, NULL,
+                         BDRV_O_RDWR | BDRV_O_CACHE_WB, &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
diff --git a/block/sheepdog.c b/block/sheepdog.c
index d1c812d..8d6e940 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1534,7 +1534,7 @@ static int sd_prealloc(const char *filename)
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR, &local_err);
+    ret = bdrv_file_open(&bs, filename, NULL, NULL, BDRV_O_RDWR, &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
@@ -1695,7 +1695,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
             goto out;
         }
 
-        ret = bdrv_file_open(&bs, backing_file, NULL, 0, &local_err);
+        ret = bdrv_file_open(&bs, backing_file, NULL, NULL, 0, &local_err);
         if (ret < 0) {
             qerror_report_err(local_err);
             error_free(local_err);
diff --git a/block/vhdx.c b/block/vhdx.c
index 67bbe10..4809056 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1798,7 +1798,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
         goto exit;
     }
 
-    ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR, &local_err);
+    ret = bdrv_file_open(&bs, filename, NULL, NULL, BDRV_O_RDWR, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto exit;
diff --git a/block/vmdk.c b/block/vmdk.c
index 0734bc2..a095f1e 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -764,8 +764,8 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
 
         path_combine(extent_path, sizeof(extent_path),
                 desc_file_path, fname);
-        ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags,
-                             errp);
+        ret = bdrv_file_open(&extent_file, extent_path, NULL, NULL,
+                             bs->open_flags, errp);
         if (ret) {
             return ret;
         }
diff --git a/include/block/block.h b/include/block/block.h
index 36efaea..e2b2a15 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -184,7 +184,8 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
 int bdrv_parse_cache_flags(const char *mode, int *flags);
 int bdrv_parse_discard_flags(const char *mode, int *flags);
 int bdrv_file_open(BlockDriverState **pbs, const char *filename,
-                   QDict *options, int flags, Error **errp);
+                   const char *reference, QDict *options, int flags,
+                   Error **errp);
 int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
 int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
               int flags, BlockDriver *drv, Error **errp);
diff --git a/qemu-io.c b/qemu-io.c
index 3b3340a..f180813 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -56,7 +56,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
     }
 
     if (growable) {
-        if (bdrv_file_open(&qemuio_bs, name, opts, flags, &local_err)) {
+        if (bdrv_file_open(&qemuio_bs, name, NULL, opts, flags, &local_err)) {
             fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
                     error_get_pretty(local_err));
             error_free(local_err);
-- 
1.8.5.1

  parent reply	other threads:[~2013-12-13 17:10 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-13 17:10 [Qemu-devel] [PATCH v3 00/21] blkdebug/blkverify: Allow QMP configuration Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 01/22] blkdebug: Use errp for read_config() Max Reitz
2013-12-13 18:59   ` Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 02/22] blkdebug: Don't require sophisticated filename Max Reitz
2013-12-13 19:00   ` Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 03/22] qdict: Add qdict_array_split() Max Reitz
2013-12-13 19:00   ` Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 04/22] qapi: extend qdict_flatten() for QLists Max Reitz
2013-12-13 19:01   ` Kevin Wolf
2013-12-13 20:04   ` Eric Blake
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 05/22] qdict: Remove delete from qdict_flatten_qdict() Max Reitz
2013-12-13 18:58   ` Kevin Wolf
2013-12-14  0:05     ` Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 06/22] qemu-option: Add qemu_config_parse_qdict() Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 07/22] blkdebug: Always call read_config() Max Reitz
2013-12-13 19:04   ` Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 08/22] blkdebug: Use command-line in read_config() Max Reitz
2013-12-13 19:48   ` Kevin Wolf
2013-12-13 17:10 ` Max Reitz [this message]
2013-12-13 19:54   ` [Qemu-devel] [PATCH v5 09/22] block: Allow reference for bdrv_file_open() Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 10/22] block: Pass reference to bdrv_file_open() Max Reitz
2013-12-13 19:56   ` Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 11/22] block: Allow block devices without files Max Reitz
2013-12-13 20:06   ` Kevin Wolf
2013-12-14  0:10     ` Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 12/22] block: Allow recursive "file"s Max Reitz
2013-12-13 20:19   ` Kevin Wolf
2013-12-13 20:36     ` Eric Blake
2013-12-13 21:21       ` Kevin Wolf
2013-12-14  0:16     ` Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 13/22] qemu-iotests: Fix output of test 051 Max Reitz
2013-12-13 20:21   ` Eric Blake
2013-12-13 20:21   ` Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 14/22] blockdev: Move "file" to legacy_opts Max Reitz
2013-12-13 20:27   ` Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 15/22] blkdebug: Allow command-line file configuration Max Reitz
2013-12-13 20:36   ` Kevin Wolf
2013-12-13 23:57     ` Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 16/22] blkdebug: Make filename optional Max Reitz
2013-12-13 20:43   ` Kevin Wolf
2013-12-14  0:27     ` Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 17/22] blkverify: Allow command-line configuration Max Reitz
2013-12-13 20:46   ` Kevin Wolf
2013-12-14  0:22     ` Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 18/22] blkverify: Don't require protocol filename Max Reitz
2013-12-13 20:47   ` Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 19/22] blkdebug: Alias "errno" as "error" Max Reitz
2013-12-13 20:49   ` Kevin Wolf
2013-12-13 21:00     ` Eric Blake
2013-12-13 21:23       ` Kevin Wolf
2013-12-13 23:59       ` Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 20/22] qapi: QMP interface for blkdebug and blkverify Max Reitz
2013-12-13 20:54   ` Kevin Wolf
2013-12-13 21:03     ` Eric Blake
2013-12-14  0:20     ` Max Reitz
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 21/22] qemu-io: Make filename optional Max Reitz
2013-12-13 20:57   ` Kevin Wolf
2013-12-13 17:10 ` [Qemu-devel] [PATCH v5 22/22] iotests: Test new blkdebug/blkverify interface Max Reitz
2013-12-13 21:08   ` Kevin Wolf
2013-12-14  0:01     ` Max Reitz
2013-12-13 17:15 ` [Qemu-devel] [PATCH v3 00/21] blkdebug/blkverify: Allow QMP configuration 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=1386954633-28905-10-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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.