aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorJunyan He <junyan.he@intel.com>2018-07-18 15:48:00 +0800
committerMichael S. Tsirkin <mst@redhat.com>2018-08-10 13:29:39 +0300
commita4de8552b2580adf6fa4874439217b65d3bdd88b (patch)
tree0cfd280873e9c1a616d17d88a06bc9f32863e2d4 /backends
parent17824406fa55b303379f2e4af715c1e876c3535f (diff)
downloadqemu-a4de8552b2580adf6fa4874439217b65d3bdd88b.zip
qemu-a4de8552b2580adf6fa4874439217b65d3bdd88b.tar.gz
qemu-a4de8552b2580adf6fa4874439217b65d3bdd88b.tar.bz2
hostmem-file: add the 'pmem' option
When QEMU emulates vNVDIMM labels and migrates vNVDIMM devices, it needs to know whether the backend storage is a real persistent memory, in order to decide whether special operations should be performed to ensure the data persistence. This boolean option 'pmem' allows users to specify whether the backend storage of memory-backend-file is a real persistent memory. If 'pmem=on', QEMU will set the flag RAM_PMEM in the RAM block of the corresponding memory region. If 'pmem' is set while lack of libpmem support, a error is generated. Signed-off-by: Junyan He <junyan.he@intel.com> Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'backends')
-rw-r--r--backends/hostmem-file.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 34c68bb..2476dcb 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -12,6 +12,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu-common.h"
+#include "qemu/error-report.h"
#include "sysemu/hostmem.h"
#include "sysemu/sysemu.h"
#include "qom/object_interfaces.h"
@@ -31,9 +32,10 @@ typedef struct HostMemoryBackendFile HostMemoryBackendFile;
struct HostMemoryBackendFile {
HostMemoryBackend parent_obj;
- bool discard_data;
char *mem_path;
uint64_t align;
+ bool discard_data;
+ bool is_pmem;
};
static void
@@ -59,7 +61,8 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
path,
backend->size, fb->align,
- backend->share ? RAM_SHARED : 0,
+ (backend->share ? RAM_SHARED : 0) |
+ (fb->is_pmem ? RAM_PMEM : 0),
fb->mem_path, errp);
g_free(path);
}
@@ -131,6 +134,39 @@ static void file_memory_backend_set_align(Object *o, Visitor *v,
error_propagate(errp, local_err);
}
+static bool file_memory_backend_get_pmem(Object *o, Error **errp)
+{
+ return MEMORY_BACKEND_FILE(o)->is_pmem;
+}
+
+static void file_memory_backend_set_pmem(Object *o, bool value, Error **errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(o);
+ HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
+
+ if (host_memory_backend_mr_inited(backend)) {
+ error_setg(errp, "cannot change property 'pmem' of %s '%s'",
+ object_get_typename(o),
+ object_get_canonical_path_component(o));
+ return;
+ }
+
+#ifndef CONFIG_LIBPMEM
+ if (value) {
+ Error *local_err = NULL;
+ error_setg(&local_err,
+ "Lack of libpmem support while setting the 'pmem=on'"
+ " of %s '%s'. We can't ensure data persistence.",
+ object_get_typename(o),
+ object_get_canonical_path_component(o));
+ error_propagate(errp, local_err);
+ return;
+ }
+#endif
+
+ fb->is_pmem = value;
+}
+
static void file_backend_unparent(Object *obj)
{
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
@@ -162,6 +198,9 @@ file_backend_class_init(ObjectClass *oc, void *data)
file_memory_backend_get_align,
file_memory_backend_set_align,
NULL, NULL, &error_abort);
+ object_class_property_add_bool(oc, "pmem",
+ file_memory_backend_get_pmem, file_memory_backend_set_pmem,
+ &error_abort);
}
static void file_backend_instance_finalize(Object *o)