All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 04/11] qcow: Use BB functions in .bdrv_create()
Date: Tue,  8 Mar 2016 17:34:25 +0100	[thread overview]
Message-ID: <1457454872-12183-5-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1457454872-12183-1-git-send-email-kwolf@redhat.com>

All users of the block layers are supposed to go through a BlockBackend.
The .bdrv_create() implementation is one such user, so this patch
converts it.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qcow.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index c46810c..2fd5ee6 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -24,6 +24,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "block/block_int.h"
+#include "sysemu/block-backend.h"
 #include "qemu/module.h"
 #include <zlib.h>
 #include "qapi/qmp/qerror.h"
@@ -780,7 +781,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
     int flags = 0;
     Error *local_err = NULL;
     int ret;
-    BlockDriverState *qcow_bs;
+    BlockBackend *qcow_blk;
 
     /* Read out options */
     total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
@@ -796,16 +797,18 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
         goto cleanup;
     }
 
-    qcow_bs = NULL;
-    ret = bdrv_open(&qcow_bs, filename, NULL, NULL,
-                    BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
-                    &local_err);
-    if (ret < 0) {
+    qcow_blk = blk_new_open("image", filename, NULL, NULL,
+                            BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
+                            &local_err);
+    if (qcow_blk == NULL) {
         error_propagate(errp, local_err);
+        ret = -EIO;
         goto cleanup;
     }
 
-    ret = bdrv_truncate(qcow_bs, 0);
+    blk_set_allow_write_beyond_eof(qcow_blk, true);
+
+    ret = blk_truncate(qcow_blk, 0);
     if (ret < 0) {
         goto exit;
     }
@@ -845,13 +848,13 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
     }
 
     /* write all the data */
-    ret = bdrv_pwrite(qcow_bs, 0, &header, sizeof(header));
+    ret = blk_pwrite(qcow_blk, 0, &header, sizeof(header));
     if (ret != sizeof(header)) {
         goto exit;
     }
 
     if (backing_file) {
-        ret = bdrv_pwrite(qcow_bs, sizeof(header),
+        ret = blk_pwrite(qcow_blk, sizeof(header),
             backing_file, backing_filename_len);
         if (ret != backing_filename_len) {
             goto exit;
@@ -861,7 +864,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
     tmp = g_malloc0(BDRV_SECTOR_SIZE);
     for (i = 0; i < ((sizeof(uint64_t)*l1_size + BDRV_SECTOR_SIZE - 1)/
         BDRV_SECTOR_SIZE); i++) {
-        ret = bdrv_pwrite(qcow_bs, header_size +
+        ret = blk_pwrite(qcow_blk, header_size +
             BDRV_SECTOR_SIZE*i, tmp, BDRV_SECTOR_SIZE);
         if (ret != BDRV_SECTOR_SIZE) {
             g_free(tmp);
@@ -872,7 +875,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
     g_free(tmp);
     ret = 0;
 exit:
-    bdrv_unref(qcow_bs);
+    blk_unref(qcow_blk);
 cleanup:
     g_free(backing_file);
     return ret;
-- 
1.8.3.1

  parent reply	other threads:[~2016-03-08 16:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-08 16:34 [Qemu-devel] [PATCH 00/11] block: Use BB function in .bdrv_create() implementations Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 01/11] block: Use writeback " Kevin Wolf
2016-03-09 12:14   ` Paolo Bonzini
2016-03-09 12:27     ` Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 02/11] block: Introduce blk_set_allow_write_beyond_eof() Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 03/11] parallels: Use BB functions in .bdrv_create() Kevin Wolf
2016-03-08 16:34 ` Kevin Wolf [this message]
2016-03-08 16:34 ` [Qemu-devel] [PATCH 05/11] qcow2: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 06/11] qed: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 07/11] sheepdog: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 08/11] vdi: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 09/11] vhdx: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 10/11] vmdk: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 11/11] vpc: " Kevin Wolf
2016-03-14 11:31 ` [Qemu-devel] [PATCH 00/11] block: Use BB function in .bdrv_create() implementations Kevin Wolf
2016-03-14 16:55   ` Max Reitz
2016-03-14 17:34     ` Kevin Wolf

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=1457454872-12183-5-git-send-email-kwolf@redhat.com \
    --to=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.