aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAri Sundholm <ari@tuxera.com>2018-07-04 17:59:36 +0300
committerKevin Wolf <kwolf@redhat.com>2018-07-05 10:50:21 +0200
commit1dce698ea85bb18f62e4c540d4db628bacfba6ba (patch)
tree1806b6bba47728cc6ef53b87acd3b410cd1b7fb7
parent0878b3c113145d4e01d65aadd4efaf097a3fda4b (diff)
block/blklogwrites: Add an option for the update interval of the log superblock
This is a way to ensure that the log superblock is periodically updated. Before, this was only done on flush requests, which may not be enough if the VM exits abnormally, omitting the final flush. The default interval is 4096 write requests. Signed-off-by: Ari Sundholm <ari@tuxera.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r--block/blklogwrites.c20
-rw-r--r--qapi/block-core.json6
2 files changed, 23 insertions, 3 deletions
diff --git a/block/blklogwrites.c b/block/blklogwrites.c
index 56154e7325..63bf6b34a9 100644
--- a/block/blklogwrites.c
+++ b/block/blklogwrites.c
@@ -55,6 +55,7 @@ typedef struct {
uint32_t sectorbits;
uint64_t cur_log_sector;
uint64_t nr_entries;
+ uint64_t update_interval;
} BDRVBlkLogWritesState;
static QemuOptsList runtime_opts = {
@@ -71,6 +72,11 @@ static QemuOptsList runtime_opts = {
.type = QEMU_OPT_SIZE,
.help = "Log sector size",
},
+ {
+ .name = "log-super-update-interval",
+ .type = QEMU_OPT_NUMBER,
+ .help = "Log superblock update interval (# of write requests)",
+ },
{ /* end of list */ }
},
};
@@ -234,6 +240,14 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags,
s->sectorsize = log_sector_size;
s->sectorbits = blk_log_writes_log2(log_sector_size);
+ s->update_interval = qemu_opt_get_number(opts, "log-super-update-interval",
+ 4096);
+ if (!s->update_interval) {
+ ret = -EINVAL;
+ error_setg(errp, "Invalid log superblock update interval %"PRIu64,
+ s->update_interval);
+ goto fail_log;
+ }
ret = 0;
fail_log:
@@ -360,8 +374,10 @@ static void coroutine_fn blk_log_writes_co_do_log(BlkLogWritesLogReq *lr)
lr->zero_size, 0);
}
- /* Update super block on flush */
- if (lr->log_ret == 0 && lr->entry.flags & LOG_FLUSH_FLAG) {
+ /* Update super block on flush or every update interval */
+ if (lr->log_ret == 0 && ((lr->entry.flags & LOG_FLUSH_FLAG)
+ || (s->nr_entries % s->update_interval == 0)))
+ {
struct log_write_super super = {
.magic = cpu_to_le64(WRITE_LOG_MAGIC),
.version = cpu_to_le64(WRITE_LOG_VERSION),
diff --git a/qapi/block-core.json b/qapi/block-core.json
index d1753a2ae7..38b31250f9 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3057,13 +3057,17 @@
# @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-append': 'bool',
+ '*log-super-update-interval': 'uint64' } }
##
# @BlockdevOptionsBlkverify: