diff options
author | Alexander Graf <agraf@suse.de> | 2015-01-22 15:01:38 +0100 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2015-02-05 17:16:14 +0100 |
commit | 972214001120e4cf2f4ac35b6ccbd1777b11e060 (patch) | |
tree | a9b707976274a579422b776f7d68918e57863173 /migration | |
parent | 190c882ce219ed89ac7d0633cfd11ad75fb0b46e (diff) |
qemu-file: Add fast ftell code path
For ftell we flush the output buffer to ensure that we don't have anything
lingering in our internal buffers. This is a very safe thing to do.
However, with the dynamic size measurement that the dynamic vmstate
description will bring this would turn out quite slow.
Instead, we can fast path this specific measurement and just take the
internal buffers into account when telling the kernel our position.
I'm sure I overlooked some corner cases where this doesn't work, so
instead of tuning the safe, existing version, this patch adds a fast
variant of ftell that gets used by the dynamic vmstate description code
which isn't critical when it fails.
Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'migration')
-rw-r--r-- | migration/qemu-file.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/migration/qemu-file.c b/migration/qemu-file.c index edc283073a..e66e55712f 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -452,6 +452,22 @@ int qemu_get_byte(QEMUFile *f) return result; } +int64_t qemu_ftell_fast(QEMUFile *f) +{ + int64_t ret = f->pos; + int i; + + if (f->ops->writev_buffer) { + for (i = 0; i < f->iovcnt; i++) { + ret += f->iov[i].iov_len; + } + } else { + ret += f->buf_index; + } + + return ret; +} + int64_t qemu_ftell(QEMUFile *f) { qemu_fflush(f); |