aboutsummaryrefslogtreecommitdiff
path: root/exec.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-06-02 18:12:23 +0400
committerPaolo Bonzini <pbonzini@redhat.com>2017-06-15 11:04:04 +0200
commit38b3362dd15c2dc4ad0edd105cde914e639d90fa (patch)
tree27b83a948ae958aa6731a99eb6520b15f9e61228 /exec.c
parent8d37b030fe14917a95118db04ed898c1cd2c8f49 (diff)
exec: split qemu_ram_alloc_from_file()
Add qemu_ram_alloc_from_fd(), which can be use to allocate ramblock from fd only. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20170602141229.15326-4-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/exec.c b/exec.c
index 42a5a7c8f0..42ad1eaedd 100644
--- a/exec.c
+++ b/exec.c
@@ -1914,14 +1914,12 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
}
#ifdef __linux__
-RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
- bool share, const char *mem_path,
- Error **errp)
+RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
+ bool share, int fd,
+ Error **errp)
{
RAMBlock *new_block;
Error *local_err = NULL;
- int fd;
- bool created;
int64_t file_size;
if (xen_enabled()) {
@@ -1946,18 +1944,12 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
return NULL;
}
- fd = file_ram_open(mem_path, memory_region_name(mr), &created, errp);
- if (fd < 0) {
- return NULL;
- }
-
size = HOST_PAGE_ALIGN(size);
file_size = get_file_size(fd);
if (file_size > 0 && file_size < size) {
error_setg(errp, "backing store %s size 0x%" PRIx64
" does not match 'size' option 0x" RAM_ADDR_FMT,
mem_path, file_size, size);
- close(fd);
return NULL;
}
@@ -1968,10 +1960,6 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
new_block->flags = share ? RAM_SHARED : 0;
new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
if (!new_block->host) {
- if (created) {
- unlink(mem_path);
- }
- close(fd);
g_free(new_block);
return NULL;
}
@@ -1983,6 +1971,33 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
return NULL;
}
return new_block;
+
+}
+
+
+RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
+ bool share, const char *mem_path,
+ Error **errp)
+{
+ int fd;
+ bool created;
+ RAMBlock *block;
+
+ fd = file_ram_open(mem_path, memory_region_name(mr), &created, errp);
+ if (fd < 0) {
+ return NULL;
+ }
+
+ block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp);
+ if (!block) {
+ if (created) {
+ unlink(mem_path);
+ }
+ close(fd);
+ return NULL;
+ }
+
+ return block;
}
#endif