diff options
-rw-r--r-- | block/qcow2-cache.c | 6 | ||||
-rw-r--r-- | block/qcow2.c | 8 | ||||
-rw-r--r-- | docs/qcow2-cache.txt | 5 |
3 files changed, 14 insertions, 5 deletions
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c index 6eaefeddc4..1d25147392 100644 --- a/block/qcow2-cache.c +++ b/block/qcow2-cache.c @@ -22,7 +22,6 @@ * THE SOFTWARE. */ -/* Needed for CONFIG_MADVISE */ #include "qemu/osdep.h" #include "block/block_int.h" #include "qemu-common.h" @@ -66,7 +65,8 @@ static inline int qcow2_cache_get_table_idx(BlockDriverState *bs, static void qcow2_cache_table_release(BlockDriverState *bs, Qcow2Cache *c, int i, int num_tables) { -#if QEMU_MADV_DONTNEED != QEMU_MADV_INVALID +/* Using MADV_DONTNEED to discard memory is a Linux-specific feature */ +#ifdef CONFIG_LINUX BDRVQcow2State *s = bs->opaque; void *t = qcow2_cache_get_table_addr(bs, c, i); int align = getpagesize(); @@ -74,7 +74,7 @@ static void qcow2_cache_table_release(BlockDriverState *bs, Qcow2Cache *c, size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t; size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align); if (length > 0) { - qemu_madvise((uint8_t *) t + offset, length, QEMU_MADV_DONTNEED); + madvise((uint8_t *) t + offset, length, MADV_DONTNEED); } #endif } diff --git a/block/qcow2.c b/block/qcow2.c index 7cfcd8412c..ed9e0f31d6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -668,6 +668,14 @@ static int qcow2_update_options_prepare(BlockDriverState *bs, r->cache_clean_interval = qemu_opt_get_number(opts, QCOW2_OPT_CACHE_CLEAN_INTERVAL, s->cache_clean_interval); +#ifndef CONFIG_LINUX + if (r->cache_clean_interval != 0) { + error_setg(errp, QCOW2_OPT_CACHE_CLEAN_INTERVAL + " not supported on this host"); + ret = -EINVAL; + goto fail; + } +#endif if (r->cache_clean_interval > UINT_MAX) { error_setg(errp, "Cache clean interval too big"); ret = -EINVAL; diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt index 5bb06072d3..1fdd6f9ce7 100644 --- a/docs/qcow2-cache.txt +++ b/docs/qcow2-cache.txt @@ -160,5 +160,6 @@ If unset, the default value for this parameter is 0 and it disables this feature. Note that this functionality currently relies on the MADV_DONTNEED -argument for madvise() to actually free the memory, so it is not -useful in systems that don't follow that behavior. +argument for madvise() to actually free the memory. This is a +Linux-specific feature, so cache-clean-interval is not supported in +other systems. |