Skip to contentSkip to conversation

Block layer patches

GIT PULL Kevin Wolf 2 participants 9 messages Jul 3, 2018 – Jul 5, 2018 Block layer

lore
Share & tools
lore
author
#1 lore raw

[Qemu-devel] [PULL 1/5] qemu-img: allow compressed not-in-order writes

In reply to Kevin Wolf

From: Vladimir Sementsov-Ogievskiy <[email protected]>

No reason to forbid them, and they are needed to improve performance with compress-threads in further patches.

---
 qemu-img.c | 5 -----
 1 file changed, 5 deletions(-)
qemu-img.c +0 -5
index e1a506f7f6..7651d8172c 100644
@@ -2141,11 +2141,6 @@ static int img_convert(int argc, char **argv)
         goto fail_getopt;
     }
 
-    if (!s.wr_in_order && s.compressed) {
-        error_report("Out of order write and compress are mutually exclusive");
-        goto fail_getopt;
-    }
-
     if (tgt_image_opts && !skip_create) {
         error_report("--target-image-opts requires use of -n flag");
         goto fail_getopt;
Signature · 1 line
2.13.6
author
#2 lore raw

[Qemu-devel] [PULL 4/5] block: Move two block permission constants to the relevant enum

In reply to Kevin Wolf

From: Ari Sundholm <[email protected]>

This allows using the two constants outside of block.c, which will happen in a subsequent patch.

---
 include/block/block.h | 7 +++++++
 block.c               | 6 ------
 2 files changed, 7 insertions(+), 6 deletions(-)
include/block/block.h +7 -0
index e5c7759a0c..bc76b1e59f 100644
@@ -225,6 +225,13 @@ enum {
     BLK_PERM_GRAPH_MOD          = 0x10,
 
     BLK_PERM_ALL                = 0x1f,
+
+    DEFAULT_PERM_PASSTHROUGH    = BLK_PERM_CONSISTENT_READ
+                                 | BLK_PERM_WRITE
+                                 | BLK_PERM_WRITE_UNCHANGED
+                                 | BLK_PERM_RESIZE,
+
+    DEFAULT_PERM_UNCHANGED      = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH,
 };
 
 char *bdrv_perm_names(uint64_t perm);
block.c +0 -6
index 70a46fdd84..961ec97d26 100644
@@ -1948,12 +1948,6 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
     return 0;
 }
 
-#define DEFAULT_PERM_PASSTHROUGH (BLK_PERM_CONSISTENT_READ \
-                                 | BLK_PERM_WRITE \
-                                 | BLK_PERM_WRITE_UNCHANGED \
-                                 | BLK_PERM_RESIZE)
-#define DEFAULT_PERM_UNCHANGED (BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH)
-
 void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,
                                const BdrvChildRole *role,
                                BlockReopenQueue *reopen_queue,
Signature · 1 line
2.13.6
author
#3 lore raw

[Qemu-devel] [PULL 3/5] qcow2: add compress threads

In reply to Kevin Wolf

From: Vladimir Sementsov-Ogievskiy <[email protected]>

Do data compression in separate threads. This significantly improve performance for qemu-img convert with -W (allow async writes) and -c (compressed) options.

---
 block/qcow2.h |  3 +++
 block/qcow2.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 64 insertions(+), 1 deletion(-)
block/qcow2.h +3 -0
index 1c9c0d3631..d6aca687d6 100644
@@ -326,6 +326,9 @@ typedef struct BDRVQcow2State {
      * override) */
     char *image_backing_file;
     char *image_backing_format;
+
+    CoQueue compress_wait_queue;
+    int nb_compress_threads;
 } BDRVQcow2State;
 
 typedef struct Qcow2COWRegion {
block/qcow2.c +61 -1

86 lines not on this page · raw message

Signature · 1 line
2.13.6

Kevin Wolf

author
#0 lore raw

The following changes since commit a395717cbd26e7593d3c3fe81faca121ec6d13e8:

Merge remote-tracking branch 'remotes/cody/tags/block-pull-request' into staging (2018-07-03 11:49:51 +0100)

are available in the git repository at:

git://repo.or.cz/qemu/kevin.git tags/for-upstream

for you to fetch changes up to 59738025a1674bb7e07713c3c93ff4fb9c5079f5:

block: Add blklogwrites (2018-07-03 16:09:48 +0200)

----------------------------------------------------------------
Block layer patches:

- qcow2: Use worker threads for compression to improve performance of 'qemu-img convert -W' and compressed backup jobs
- blklogwrites: New filter driver to log write requests to an image in the dm-log-writes format

----------------------------------------------------------------
Aapo Vienamo (1):
block: Add blklogwrites

Ari Sundholm (1):
block: Move two block permission constants to the relevant enum

Vladimir Sementsov-Ogievskiy (3):
qemu-img: allow compressed not-in-order writes
qcow2: refactor data compression
qcow2: add compress threads

 qapi/block-core.json  |  33 ++++-
 block/qcow2.h         |   3 +
 include/block/block.h |   7 +
 block.c               |   6 -
 block/blklogwrites.c  | 392 ++++++++++++++++++++++++++++++++++++++++++++++++++
 block/qcow2.c         | 136 ++++++++++++++----
 qemu-img.c            |   5 -
 MAINTAINERS           |   6 +
 block/Makefile.objs   |   1 +
 9 files changed, 545 insertions(+), 44 deletions(-)
 create mode 100644 block/blklogwrites.c
author
#4 lore raw

[Qemu-devel] [PULL 5/5] block: Add blklogwrites

From: Aapo Vienamo <[email protected]>

Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.

This functionality can be used for crash consistency and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.

The driver accepts an optional parameter to set the sector size used for logging. This makes the driver require all requests to be aligned to this sector size and also makes offsets and sizes of writes in the log metadata to be expressed in terms of this value (the log format has a granularity of one sector for offsets and sizes). This allows accurate logging of writes to guest block devices that have unusual sector sizes.

The implementation is based on the blkverify and blkdebug block drivers.

---
 qapi/block-core.json |  33 ++++-
 block/blklogwrites.c | 392 +++++++++++++++++++++++++++++++++++++++++++++++++++
 MAINTAINERS          |   6 +
 block/Makefile.objs  |   1 +
 4 files changed, 426 insertions(+), 6 deletions(-)
 create mode 100644 block/blklogwrites.c
qapi/block-core.json +27 -6
index 90e554ed0f..a9eab8cab8 100644
@@ -2533,16 +2533,17 @@
 # @throttle: Since 2.11
 # @nvme: Since 2.12
 # @copy-on-read: Since 3.0
+# @blklogwrites: Since 3.0
 #
 # Since: 2.9
 ##
 { 'enum': 'BlockdevDriver',
-  'data': [ 'blkdebug', 'blkverify', 'bochs', 'cloop', 'copy-on-read',
-            'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom',
-            'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs',
-            'null-aio', 'null-co', 'nvme', 'parallels', 'qcow', 'qcow2', 'qed',
-            'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh',
-            'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] }
+  'data': [ 'blkdebug', 'blklogwrites', 'blkverify', 'bochs', 'cloop',
+            'copy-on-read', 'dmg', 'file', 'ftp', 'ftps', 'gluster',
+            'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks',
+            'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'qcow',
+            'qcow2', 'qed', 'quorum', 'raw', 'rbd', 'replication', 'sheepdog',
+            'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] }
 
 ##
 # @BlockdevOptionsFile:
@@ -3045,6 +3046,25 @@
             '*set-state': ['BlkdebugSetStateOptions'] } }
 
 ##
+# @BlockdevOptionsBlklogwrites:
+#
+# Driver specific block device options for blklogwrites.
+#
+# @file:            block device
+#
+# @log:             block device used to log writes to @file
+#
+# @log-sector-size: sector size used in logging writes to @file, determines
+#                   granularity of offsets and sizes of writes (default: 512)
+#
+# Since: 3.0
+##
+{ 'struct': 'BlockdevOptionsBlklogwrites',
+  'data': { 'file': 'BlockdevRef',
+            'log': 'BlockdevRef',
+            '*log-sector-size': 'uint32' } }
+
+##
 # @BlockdevOptionsBlkverify:
 #
 # Driver specific block device options for blkverify.
@@ -3563,6 +3583,7 @@
   'discriminator': 'driver',
   'data': {
       'blkdebug':   'BlockdevOptionsBlkdebug',
+      'blklogwrites':'BlockdevOptionsBlklogwrites',
       'blkverify':  'BlockdevOptionsBlkverify',
       'bochs':      'BlockdevOptionsGenericFormat',
       'cloop':      'BlockdevOptionsGenericFormat',
block/blklogwrites.c new file +392 -0

392 lines not on this page · raw message

MAINTAINERS +6 -0
index 42a1892d6a..5af89e7af3 100644
@@ -2051,6 +2051,12 @@ S: Supported
 F: block/quorum.c
 L: [email protected]
 
+blklogwrites
+M: Ari Sundholm <[email protected]>
+L: [email protected]
+S: Supported
+F: block/blklogwrites.c
+
 blkverify
 M: Stefan Hajnoczi <[email protected]>
 L: [email protected]
block/Makefile.objs +1 -0
index 899bfb5e2c..c8337bf186 100644
@@ -5,6 +5,7 @@ block-obj-y += qed-check.o
 block-obj-y += vhdx.o vhdx-endian.o vhdx-log.o
 block-obj-y += quorum.o
 block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o
+block-obj-y += blklogwrites.o
 block-obj-y += block-backend.o snapshot.o qapi.o
 block-obj-$(CONFIG_WIN32) += file-win32.o win32-aio.o
 block-obj-$(CONFIG_POSIX) += file-posix.o
Signature · 1 line
2.13.6
author
#6 lore raw

[Qemu-devel] [PULL 2/5] qcow2: refactor data compression

In reply to Kevin Wolf

From: Vladimir Sementsov-Ogievskiy <[email protected]>

Make a separate function for compression to be parallelized later.
- use .avail_out field instead of .next_out to calculate size of compressed data. It looks more natural and it allows to keep dest to be void pointer
- set avail_out to be at least one byte less than input, to be sure avoid inefficient compression earlier

---
 block/qcow2.c | 76 ++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 49 insertions(+), 27 deletions(-)
block/qcow2.c +49 -27
index 2f9e58e0c4..67f4fb7c71 100644
@@ -23,11 +23,14 @@
  */
 
 #include "qemu/osdep.h"
+
+#define ZLIB_CONST
+#include <zlib.h>
+
 #include "block/block_int.h"
 #include "block/qdict.h"
 #include "sysemu/block-backend.h"
 #include "qemu/module.h"
-#include <zlib.h>
 #include "qcow2.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
@@ -3650,6 +3653,46 @@ fail:
     return ret;
 }
 
+/*
+ * qcow2_compress()
+ *
+ * @dest - destination buffer, at least of @size-1 bytes
+ * @src - source buffer, @size bytes
+ *
+ * Returns: compressed size on success
+ *          -1 if compression is inefficient
+ *          -2 on any other error
+ */
+static ssize_t qcow2_compress(void *dest, const void *src, size_t size)
+{
+    ssize_t ret;
+    z_stream strm;
+
+    /* best compression, small window, no zlib header */
+    memset(&strm, 0, sizeof(strm));
+    ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
+                       -12, 9, Z_DEFAULT_STRATEGY);
+    if (ret != 0) {
+        return -2;
+    }
+
+    strm.avail_in = size;
+    strm.next_in = src;
+    strm.avail_out = size - 1;
+    strm.next_out = dest;
+
+    ret = deflate(&strm, Z_FINISH);
+    if (ret == Z_STREAM_END) {
+        ret = size - 1 - strm.avail_out;
+    } else {
+        ret = (ret == Z_OK ? -1 : -2);
+    }
+
+    deflateEnd(&strm);
+
+    return ret;
+}
+
 /* XXX: put compressed sectors first, then all the cluster aligned
    tables to avoid losing bytes in alignment */
 static coroutine_fn int
@@ -3659,8 +3702,8 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
     BDRVQcow2State *s = bs->opaque;
     QEMUIOVector hd_qiov;
     struct iovec iov;
-    z_stream strm;
-    int ret, out_len;
+    int ret;
+    size_t out_len;
     uint8_t *buf, *out_buf;
     int64_t cluster_offset;
 
@@ -3694,32 +3737,11 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
 
     out_buf = g_malloc(s->cluster_size);
 
-    /* best compression, small window, no zlib header */
-    memset(&strm, 0, sizeof(strm));
-    ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION,
-                       Z_DEFLATED, -12,
-                       9, Z_DEFAULT_STRATEGY);
-    if (ret != 0) {
+    out_len = qcow2_compress(out_buf, buf, s->cluster_size);
+    if (out_len == -2) {
         ret = -EINVAL;
         goto fail;
-    }
-
-    strm.avail_in = s->cluster_size;
-    strm.next_in = (uint8_t *)buf;
-    strm.avail_out = s->cluster_size;
-    strm.next_out = out_buf;
-
-    ret = deflate(&strm, Z_FINISH);
-    if (ret != Z_STREAM_END && ret != Z_OK) {
-        deflateEnd(&strm);
-        ret = -EINVAL;
-        goto fail;
-    }
-    out_len = strm.next_out - out_buf;
-
-    deflateEnd(&strm);
-
-    if (ret != Z_STREAM_END || out_len >= s->cluster_size) {
+    } else if (out_len == -1) {
         /* could not compress: write normal cluster */
         ret = qcow2_co_pwritev(bs, offset, bytes, qiov, 0);
         if (ret < 0) {
Signature · 1 line
2.13.6
author
#5 lore raw

Re: [Qemu-devel] [PULL 5/5] block: Add blklogwrites

In reply to Kevin Wolf

Am 03.07.2018 um 16:59 hat Kevin Wolf geschrieben:

Quoted 20 lines

From: Aapo Vienamo <[email protected]>

Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.

This functionality can be used for crash consistency and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.

The driver accepts an optional parameter to set the sector size used for logging. This makes the driver require all requests to be aligned to this sector size and also makes offsets and sizes of writes in the log metadata to be expressed in terms of this value (the log format has a granularity of one sector for offsets and sizes). This allows accurate logging of writes to guest block devices that have unusual sector sizes.

Quoted 6 lines

The implementation is based on the blkverify and blkdebug block drivers.

Note that I saw Ari's v7 right after sending the pull request. It contains only a few simple bugfixes compared to the version I had queued, so I quickly squashed the following in and updated the tag.

Kevin

block/blklogwrites.c +28 -6
index 0748b56d72..47093fadd6 100644
@@ -53,6 +53,19 @@ typedef struct {
     uint64_t nr_entries;
 } BDRVBlkLogWritesState;
 
+static QemuOptsList runtime_opts = {
+    .name = "blklogwrites",
+    .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
+    .desc = {
+        {
+            .name = "log-sector-size",
+            .type = QEMU_OPT_SIZE,
+            .help = "Log sector size",
+        },
+        { /* end of list */ }
+    },
+};
+
 static inline uint32_t blk_log_writes_log2(uint32_t value)
 {
     assert(value > 0);
@@ -63,9 +76,18 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags,
                                Error **errp)
 {
     BDRVBlkLogWritesState *s = bs->opaque;
+    QemuOpts *opts;
     Error *local_err = NULL;
     int ret;
-    int64_t log_sector_size = BDRV_SECTOR_SIZE;
+    int64_t log_sector_size;
+
+    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
+    qemu_opts_absorb_qdict(opts, options, &local_err);
+    if (local_err) {
+        ret = -EINVAL;
+        error_propagate(errp, local_err);
+        goto fail;
+    }
 
     /* Open the file */
     bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, false,
@@ -76,12 +98,10 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail;
     }
 
-    if (qdict_haskey(options, "log-sector-size")) {
-        log_sector_size = qdict_get_int(options, "log-sector-size");
-        qdict_del(options, "log-sector-size");
-    }
+    log_sector_size = qemu_opt_get_size(opts, "log-sector-size",
+                                        BDRV_SECTOR_SIZE);
 
-    if (log_sector_size < 0 || log_sector_size >= (1ull << 32) ||
+    if (log_sector_size < 0 || log_sector_size > (1ull << 23) ||
         !is_power_of_2(log_sector_size))
     {
         ret = -EINVAL;
@@ -109,6 +129,7 @@ fail:
         bdrv_unref_child(bs, bs->file);
         bs->file = NULL;
     }
+    qemu_opts_del(opts);
     return ret;
 }
 
@@ -144,6 +165,7 @@ static void blk_log_writes_refresh_filename(BlockDriverState *bs,
         qobject_ref(s->log_file->bs->full_open_options);
         qdict_put_obj(opts, "log",
                       QOBJECT(s->log_file->bs->full_open_options));
+        qdict_put_int(opts, "log-sector-size", s->sectorsize);
 
         bs->full_open_options = opts;
     }
#7 lore raw
In reply to Kevin Wolf
Quoted 15 lines · Kevin Wolf

The following changes since commit a395717cbd26e7593d3c3fe81faca121ec6d13e8:

Merge remote-tracking branch 'remotes/cody/tags/block-pull-request' into staging (2018-07-03 11:49:51 +0100)

are available in the git repository at:

git://repo.or.cz/qemu/kevin.git tags/for-upstream

for you to fetch changes up to 59738025a1674bb7e07713c3c93ff4fb9c5079f5:

block: Add blklogwrites (2018-07-03 16:09:48 +0200)

----------------------------------------------------------------
Block layer patches:

Quoted 6 lines

- qcow2: Use worker threads for compression to improve performance of 'qemu-img convert -W' and compressed backup jobs
- blklogwrites: New filter driver to log write requests to an image in the dm-log-writes format

----------------------------------------------------------------

Hi; this gives some a warning on OpenBSD and NetBSD:

/home/qemu/block/qcow2.c: In function 'qcow2_compress':
/home/qemu/block/qcow2.c:3684:18: warning: assignment discards 'const' qualifier from pointer target type

     strm.next_in = src;
                  ^

thanks
-- PMM

author
#8 lore raw

Am 04.07.2018 um 20:30 hat Peter Maydell geschrieben:

Quoted 21 lines · Kevin Wolf
Quoted 20 lines

The following changes since commit a395717cbd26e7593d3c3fe81faca121ec6d13e8:

Merge remote-tracking branch 'remotes/cody/tags/block-pull-request' into staging (2018-07-03 11:49:51 +0100)

are available in the git repository at:

git://repo.or.cz/qemu/kevin.git tags/for-upstream

for you to fetch changes up to 59738025a1674bb7e07713c3c93ff4fb9c5079f5:

block: Add blklogwrites (2018-07-03 16:09:48 +0200)

----------------------------------------------------------------
Block layer patches:

- qcow2: Use worker threads for compression to improve performance of 'qemu-img convert -W' and compressed backup jobs
- blklogwrites: New filter driver to log write requests to an image in the dm-log-writes format

Quoted 8 lines
Quoted 1 line

----------------------------------------------------------------

Hi; this gives some a warning on OpenBSD and NetBSD:

/home/qemu/block/qcow2.c: In function 'qcow2_compress':
/home/qemu/block/qcow2.c:3684:18: warning: assignment discards 'const' qualifier from pointer target type

     strm.next_in = src;

Hm, looks like they use a really old version of the zlib header, which doesn't care about const correctness. I'll add a cast to work around it.

Kevin