aboutsummaryrefslogtreecommitdiff
path: root/backends/hostmem-file.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2014-06-10 19:15:24 +0800
committerMichael S. Tsirkin <mst@redhat.com>2014-06-19 18:44:20 +0300
commitdbcb8981183592be129b2e624b7bcd4245e75fbc (patch)
tree639391848fc2cb66c281fb7e8a9fae377bee87f1 /backends/hostmem-file.c
parenta35ba7be4b696d4c7b47318fd2022e6c3eca0a63 (diff)
hostmem: add property to map memory with MAP_SHARED
A new "share" property can be used with the "memory-file" backend to map memory with MAP_SHARED instead of MAP_PRIVATE. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'backends/hostmem-file.c')
-rw-r--r--backends/hostmem-file.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 92659c119d..51799943f1 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -28,6 +28,8 @@ typedef struct HostMemoryBackendFile HostMemoryBackendFile;
struct HostMemoryBackendFile {
HostMemoryBackend parent_obj;
+
+ bool share;
char *mem_path;
};
@@ -51,7 +53,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
backend->force_prealloc = mem_prealloc;
memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
object_get_canonical_path(OBJECT(backend)),
- backend->size,
+ backend->size, fb->share,
fb->mem_path, errp);
}
#endif
@@ -87,9 +89,31 @@ static void set_mem_path(Object *o, const char *str, Error **errp)
fb->mem_path = g_strdup(str);
}
+static bool file_memory_backend_get_share(Object *o, Error **errp)
+{
+ HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
+
+ return fb->share;
+}
+
+static void file_memory_backend_set_share(Object *o, bool value, Error **errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(o);
+ HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
+
+ if (memory_region_size(&backend->mr)) {
+ error_setg(errp, "cannot change property value");
+ return;
+ }
+ fb->share = value;
+}
+
static void
file_backend_instance_init(Object *o)
{
+ object_property_add_bool(o, "share",
+ file_memory_backend_get_share,
+ file_memory_backend_set_share, NULL);
object_property_add_str(o, "mem-path", get_mem_path,
set_mem_path, NULL);
}