[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v9 01/20] Convert -mem-path to QemuOpts and add shar
From: |
Antonios Motakis |
Subject: |
[Qemu-devel] [PATCH v9 01/20] Convert -mem-path to QemuOpts and add share property |
Date: |
Tue, 4 Mar 2014 19:22:44 +0100 |
Extend -mem-path with additional property:
- share=on|off - default off, memory is mmapped with MAP_SHARED flag
Signed-off-by: Antonios Motakis <address@hidden>
Signed-off-by: Nikolay Nikolaev <address@hidden>
---
exec.c | 21 +++++++++++++++++++--
include/exec/cpu-all.h | 1 -
qemu-options.hx | 8 ++++++--
vl.c | 23 +++++++++++++++++++++--
4 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/exec.c b/exec.c
index b69fd29..4fb5cc6 100644
--- a/exec.c
+++ b/exec.c
@@ -1027,7 +1027,10 @@ static void *file_ram_alloc(RAMBlock *block,
char *c;
void *area;
int fd;
+ int flags;
unsigned long hpagesize;
+ QemuOpts *opts;
+ unsigned int mem_share = 0;
hpagesize = gethugepagesize(path);
if (!hpagesize) {
@@ -1043,6 +1046,12 @@ static void *file_ram_alloc(RAMBlock *block,
return NULL;
}
+ /* Fill config options */
+ opts = qemu_opts_find(qemu_find_opts("mem-path"), NULL);
+ if (opts) {
+ mem_share = qemu_opt_get_bool(opts, "share", 0);
+ }
+
/* Make name safe to use with mkstemp by replacing '/' with '_'. */
sanitized_name = g_strdup(block->mr->name);
for (c = sanitized_name; *c != '\0'; c++) {
@@ -1063,7 +1072,7 @@ static void *file_ram_alloc(RAMBlock *block,
unlink(filename);
g_free(filename);
- memory = (memory+hpagesize-1) & ~(hpagesize-1);
+ memory = (memory + hpagesize - 1) & ~(hpagesize - 1);
/*
* ftruncate is not supported by hugetlbfs in older
@@ -1074,7 +1083,8 @@ static void *file_ram_alloc(RAMBlock *block,
if (ftruncate(fd, memory))
perror("ftruncate");
- area = mmap(0, memory, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+ flags = mem_share ? MAP_SHARED : MAP_PRIVATE;
+ area = mmap(0, memory, PROT_READ | PROT_WRITE, flags, fd, 0);
if (area == MAP_FAILED) {
perror("file_ram_alloc: can't mmap RAM pages");
close(fd);
@@ -1244,6 +1254,8 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void
*host,
MemoryRegion *mr)
{
RAMBlock *block, *new_block;
+ QemuOpts *opts;
+ const char *mem_path = 0;
ram_addr_t old_ram_size, new_ram_size;
old_ram_size = last_ram_offset() >> TARGET_PAGE_BITS;
@@ -1252,6 +1264,11 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void
*host,
new_block = g_malloc0(sizeof(*new_block));
new_block->fd = -1;
+ opts = qemu_opts_find(qemu_find_opts("mem-path"), NULL);
+ if (opts) {
+ mem_path = qemu_opt_get(opts, "path");
+ }
+
/* This assumes the iothread lock is taken here too. */
qemu_mutex_lock_ramlist();
new_block->mr = mr;
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 4cb4b4a..afec798 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -468,7 +468,6 @@ typedef struct RAMList {
} RAMList;
extern RAMList ram_list;
-extern const char *mem_path;
extern int mem_prealloc;
/* Flags stored in the low bits of the TLB virtual address. These are
diff --git a/qemu-options.hx b/qemu-options.hx
index 56e5fdf..f9f42a0 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -221,9 +221,13 @@ gigabytes respectively.
ETEXI
DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,
- "-mem-path FILE provide backing storage for guest RAM\n", QEMU_ARCH_ALL)
+ "-mem-path [path=]path[,share=on|off]\n"
+ " provide backing storage for guest RAM\n"
+ " path= a directory path for the backing store\n"
+ " share= enable mmap share flag [default disabled]\n",
+ QEMU_ARCH_ALL)
STEXI
address@hidden -mem-path @var{path}
address@hidden -mem-path address@hidden,share=on|off]
@findex -mem-path
Allocate guest RAM from a temporarily created file in @var{path}.
ETEXI
diff --git a/vl.c b/vl.c
index 1d27b34..6445457 100644
--- a/vl.c
+++ b/vl.c
@@ -135,7 +135,6 @@ DisplayType display_type = DT_DEFAULT;
static int display_remote;
const char* keyboard_layout = NULL;
ram_addr_t ram_size;
-const char *mem_path = NULL;
int mem_prealloc = 0; /* force preallocation of physical target memory */
int nb_nics;
NICInfo nd_table[MAX_NICS];
@@ -479,6 +478,23 @@ static QemuOptsList qemu_msg_opts = {
},
};
+static QemuOptsList qemu_mem_path_opts = {
+ .name = "mem-path",
+ .implied_opt_name = "path",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_path_opts.head),
+ .desc = {
+ {
+ .name = "path",
+ .type = QEMU_OPT_STRING,
+ },
+ {
+ .name = "share",
+ .type = QEMU_OPT_BOOL,
+ },
+ { /* end of list */ }
+ },
+};
+
/**
* Get machine options
*
@@ -2863,6 +2879,7 @@ int main(int argc, char **argv, char **envp)
qemu_add_opts(&qemu_tpmdev_opts);
qemu_add_opts(&qemu_realtime_opts);
qemu_add_opts(&qemu_msg_opts);
+ qemu_add_opts(&qemu_mem_path_opts);
runstate_init();
@@ -3190,7 +3207,9 @@ int main(int argc, char **argv, char **envp)
break;
#endif
case QEMU_OPTION_mempath:
- mem_path = optarg;
+ if (!qemu_opts_parse(qemu_find_opts("mem-path"), optarg, 1)) {
+ exit(1);
+ }
break;
case QEMU_OPTION_mem_prealloc:
mem_prealloc = 1;
--
1.8.3.2
- [Qemu-devel] [PATCH v9 00/20] Vhost and vhost-net support for userspace based backends, Antonios Motakis, 2014/03/04
- [Qemu-devel] [PATCH v9 08/20] Refactor virtio-net to use generic get_vhost_net, Antonios Motakis, 2014/03/04
- [Qemu-devel] [PATCH v9 07/20] vhost_net should call the poll callback only when it is set, Antonios Motakis, 2014/03/04
- [Qemu-devel] [PATCH v9 01/20] Convert -mem-path to QemuOpts and add share property,
Antonios Motakis <=
- [Qemu-devel] [PATCH v9 06/20] Add G_IO_HUP handler for socket chardev, Antonios Motakis, 2014/03/04
- Re: [Qemu-devel] [PATCH v9 00/20] Vhost and vhost-net support for userspace based backends, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH v9 12/20] Add vhost_ops to vhost_dev struct and replace all relevant ioctls, Antonios Motakis, 2014/03/04
- [Qemu-devel] [PATCH v9 10/20] Gracefully handle ioctl failure in vhost_virtqueue_stop, Antonios Motakis, 2014/03/04
- [Qemu-devel] [PATCH v9 05/20] Add chardev API qemu_chr_fe_get_msgfds, Antonios Motakis, 2014/03/04