Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging

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
- file-posix: Fix image locking during image creation
- crypto: Fix memory leak in error path
- Error out instead of silently truncating node names

# gpg: Signature made Thu 05 Jul 2018 11:24:33 BST
# gpg:                using RSA key 7F09B272C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"
# Primary key fingerprint: DC3D EB15 9A9A F95D 3D74  56FE 7F09 B272 C88F 2FD6

* remotes/kevin/tags/for-upstream:
  file-posix: Unlock FD after creation
  file-posix: Fix creation locking
  block/blklogwrites: Add an option for the update interval of the log superblock
  block/blklogwrites: Add an option for appending to an old log
  block/blklogwrites: Change log_sector_size from int64_t to uint64_t
  block/crypto: Fix memory leak in create error path
  block: Don't silently truncate node names
  block: Add blklogwrites
  block: Move two block permission constants to the relevant enum
  qcow2: add compress threads
  qcow2: refactor data compression
  qemu-img: allow compressed not-in-order writes

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell
2018-07-05 15:53:04 +01:00
14 changed files with 791 additions and 50 deletions
+6
View File
@@ -2052,6 +2052,12 @@ S: Supported
F: block/quorum.c
L: qemu-block@nongnu.org
blklogwrites
M: Ari Sundholm <ari@tuxera.com>
L: qemu-block@nongnu.org
S: Supported
F: block/blklogwrites.c
blkverify
M: Stefan Hajnoczi <stefanha@redhat.com>
L: qemu-block@nongnu.org
+6 -6
View File
@@ -1156,6 +1156,12 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
goto out;
}
/* Make sure that the node name isn't truncated */
if (strlen(node_name) >= sizeof(bs->node_name)) {
error_setg(errp, "Node name too long");
goto out;
}
/* copy node name into the bs and insert it into the graph list */
pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
@@ -1948,12 +1954,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,
+1
View File
@@ -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
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -551,7 +551,7 @@ static int coroutine_fn block_crypto_co_create_opts_luks(const char *filename,
/* Create protocol layer */
ret = bdrv_create_file(filename, opts, errp);
if (ret < 0) {
return ret;
goto fail;
}
bs = bdrv_open(filename, NULL, NULL,
+16 -5
View File
@@ -2111,8 +2111,9 @@ static int coroutine_fn
raw_co_create(BlockdevCreateOptions *options, Error **errp)
{
BlockdevCreateOptionsFile *file_opts;
Error *local_err = NULL;
int fd;
int perm, shared;
uint64_t perm, shared;
int result = 0;
/* Validate options and set default values */
@@ -2148,7 +2149,7 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
shared = BLK_PERM_ALL & ~BLK_PERM_RESIZE;
/* Step one: Take locks */
result = raw_apply_lock_bytes(fd, perm, shared, false, errp);
result = raw_apply_lock_bytes(fd, perm, ~shared, false, errp);
if (result < 0) {
goto out_close;
}
@@ -2156,13 +2157,13 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
/* Step two: Check that nobody else has taken conflicting locks */
result = raw_check_lock_bytes(fd, perm, shared, errp);
if (result < 0) {
goto out_close;
goto out_unlock;
}
/* Clear the file by truncating it to 0 */
result = raw_regular_truncate(NULL, fd, 0, PREALLOC_MODE_OFF, errp);
if (result < 0) {
goto out_close;
goto out_unlock;
}
if (file_opts->nocow) {
@@ -2185,7 +2186,17 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
result = raw_regular_truncate(NULL, fd, file_opts->size,
file_opts->preallocation, errp);
if (result < 0) {
goto out_close;
goto out_unlock;
}
out_unlock:
raw_apply_lock_bytes(fd, 0, 0, true, &local_err);
if (local_err) {
/* The above call should not fail, and if it does, that does
* not mean the whole creation operation has failed. So
* report it the user for their convenience, but do not report
* it to the caller. */
error_report_err(local_err);
}
out_close:
+111 -27
View File
@@ -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"
@@ -41,6 +44,7 @@
#include "qapi/qobject-input-visitor.h"
#include "qapi/qapi-visit-block-core.h"
#include "crypto.h"
#include "block/thread-pool.h"
/*
Differences with QCOW:
@@ -1541,6 +1545,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
qcow2_check_refcounts(bs, &result, 0);
}
#endif
qemu_co_queue_init(&s->compress_wait_queue);
return ret;
fail:
@@ -3650,6 +3657,104 @@ 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.next_in is not const in old zlib versions, such as those used on
* OpenBSD/NetBSD, so cast the const away */
strm.avail_in = size;
strm.next_in = (void *) 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;
}
#define MAX_COMPRESS_THREADS 4
typedef struct Qcow2CompressData {
void *dest;
const void *src;
size_t size;
ssize_t ret;
} Qcow2CompressData;
static int qcow2_compress_pool_func(void *opaque)
{
Qcow2CompressData *data = opaque;
data->ret = qcow2_compress(data->dest, data->src, data->size);
return 0;
}
static void qcow2_compress_complete(void *opaque, int ret)
{
qemu_coroutine_enter(opaque);
}
/* See qcow2_compress definition for parameters description */
static ssize_t qcow2_co_compress(BlockDriverState *bs,
void *dest, const void *src, size_t size)
{
BDRVQcow2State *s = bs->opaque;
BlockAIOCB *acb;
ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
Qcow2CompressData arg = {
.dest = dest,
.src = src,
.size = size,
};
while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
qemu_co_queue_wait(&s->compress_wait_queue, NULL);
}
s->nb_compress_threads++;
acb = thread_pool_submit_aio(pool, qcow2_compress_pool_func, &arg,
qcow2_compress_complete,
qemu_coroutine_self());
if (!acb) {
s->nb_compress_threads--;
return -EINVAL;
}
qemu_coroutine_yield();
s->nb_compress_threads--;
qemu_co_queue_next(&s->compress_wait_queue);
return arg.ret;
}
/* XXX: put compressed sectors first, then all the cluster aligned
tables to avoid losing bytes in alignment */
static coroutine_fn int
@@ -3659,8 +3764,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 +3799,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_co_compress(bs, 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) {
+3
View File
@@ -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 {
+7
View File
@@ -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);
+32 -6
View File
@@ -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:
@@ -3044,6 +3045,30 @@
'*inject-error': ['BlkdebugInjectErrorOptions'],
'*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)
#
# @log-super-update-interval: interval of write requests after which the log
# super block is updated to disk (default: 4096)
#
# Since: 3.0
##
{ 'struct': 'BlockdevOptionsBlklogwrites',
'data': { 'file': 'BlockdevRef',
'log': 'BlockdevRef',
'*log-sector-size': 'uint32',
'*log-append': 'bool',
'*log-super-update-interval': 'uint64' } }
##
# @BlockdevOptionsBlkverify:
#
@@ -3563,6 +3588,7 @@
'discriminator': 'driver',
'data': {
'blkdebug': 'BlockdevOptionsBlkdebug',
'blklogwrites':'BlockdevOptionsBlklogwrites',
'blkverify': 'BlockdevOptionsBlkverify',
'bochs': 'BlockdevOptionsGenericFormat',
'cloop': 'BlockdevOptionsGenericFormat',
-5
View File
@@ -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;
+15
View File
@@ -99,6 +99,21 @@ run_qemu -drive file="$TEST_IMG",driver=foo
run_qemu -drive file="$TEST_IMG",driver=raw,format=qcow2
run_qemu -drive file="$TEST_IMG",driver=qcow2,format=qcow2
echo
echo === Node names ===
echo
# Maximum length: 31 characters
run_qemu -drive file="$TEST_IMG",node-name=x123456789012345678901234567890
run_qemu -drive file="$TEST_IMG",node-name=x1234567890123456789012345678901
# First character must be alphabetic
# Following characters alphanumeric or -._
run_qemu -drive file="$TEST_IMG",node-name=All-Types.of_all0wed_chars
run_qemu -drive file="$TEST_IMG",node-name=123foo
run_qemu -drive file="$TEST_IMG",node-name=_foo
run_qemu -drive file="$TEST_IMG",node-name=foo#12
echo
echo === Device without drive ===
echo
+23
View File
@@ -47,6 +47,29 @@ Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specify both 'driver' and 'format'
=== Node names ===
Testing: -drive file=TEST_DIR/t.qcow2,node-name=x123456789012345678901234567890
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) quit
Testing: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901: Node name too long
Testing: -drive file=TEST_DIR/t.qcow2,node-name=All-Types.of_all0wed_chars
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) quit
Testing: -drive file=TEST_DIR/t.qcow2,node-name=123foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=123foo: Invalid node name
Testing: -drive file=TEST_DIR/t.qcow2,node-name=_foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=_foo: Invalid node name
Testing: -drive file=TEST_DIR/t.qcow2,node-name=foo#12
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=foo#12: Invalid node name
=== Device without drive ===
Testing: -device VIRTIO_SCSI -device scsi-hd
+23
View File
@@ -47,6 +47,29 @@ Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specify both 'driver' and 'format'
=== Node names ===
Testing: -drive file=TEST_DIR/t.qcow2,node-name=x123456789012345678901234567890
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) quit
Testing: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901: Node name too long
Testing: -drive file=TEST_DIR/t.qcow2,node-name=All-Types.of_all0wed_chars
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) quit
Testing: -drive file=TEST_DIR/t.qcow2,node-name=123foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=123foo: Invalid node name
Testing: -drive file=TEST_DIR/t.qcow2,node-name=_foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=_foo: Invalid node name
Testing: -drive file=TEST_DIR/t.qcow2,node-name=foo#12
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=foo#12: Invalid node name
=== Device without drive ===
Testing: -device VIRTIO_SCSI -device scsi-hd