[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/6] file_ram_alloc(): extract temporary-file creati
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PATCH 5/6] file_ram_alloc(): extract temporary-file creation code to separate function (v2) |
Date: |
Mon, 2 Jul 2012 15:06:37 -0300 |
Changes v1 -> v2:
- Fix trailing space issue
- Rebase against new code using g_strdup_printf()
Signed-off-by: Eduardo Habkost <address@hidden>
---
exec.c | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/exec.c b/exec.c
index 1e98244..456ac73 100644
--- a/exec.c
+++ b/exec.c
@@ -2356,11 +2356,31 @@ static long gethugepagesize(const char *path)
return fs.f_bsize;
}
+/* Return FD to temporary file inside directory at 'path',
+ * truncated to size 'length'
+ */
+static int get_temp_fd(const char *path)
+{
+ int fd;
+ gchar *filename;
+
+ filename = g_strdup_printf("%s/qemu_back_mem.XXXXXX", path);
+ fd = mkstemp(filename);
+ if (fd < 0) {
+ perror("unable to create backing store for hugepages");
+ g_free(filename);
+ return -1;
+ }
+ unlink(filename);
+ g_free(filename);
+
+ return fd;
+}
+
static void *file_ram_alloc(RAMBlock *block,
size_t length,
const char *path)
{
- gchar *filename;
void *area;
int fd;
#ifdef MAP_POPULATE
@@ -2382,15 +2402,10 @@ static void *file_ram_alloc(RAMBlock *block,
return NULL;
}
- filename = g_strdup_printf("%s/qemu_back_mem.XXXXXX", path);
- fd = mkstemp(filename);
+ fd = get_temp_fd(path);
if (fd < 0) {
- perror("unable to create backing store for hugepages");
- g_free(filename);
return NULL;
}
- unlink(filename);
- g_free(filename);
length = (length + hpagesize - 1) & ~(hpagesize - 1);
--
1.7.10.4
- [Qemu-devel] [RFC PATCH 0/6] option to not remove files inside -mem-path dir (v2), Eduardo Habkost, 2012/07/02
- [Qemu-devel] [PATCH 1/6] file_ram_alloc(): coding style fixes, Eduardo Habkost, 2012/07/02
- [Qemu-devel] [PATCH 4/6] file_ram_alloc: change length argument to size_t (v2), Eduardo Habkost, 2012/07/02
- [Qemu-devel] [RFC PATCH 6/6] add -keep-mem-path-files option (v2), Eduardo Habkost, 2012/07/02
- [Qemu-devel] [PATCH 2/6] file_ram_alloc(): use g_strdup_printf() instead of asprintf(), Eduardo Habkost, 2012/07/02
- [Qemu-devel] [PATCH 3/6] vl.c: change mem_prealloc to bool (v2), Eduardo Habkost, 2012/07/02
- [Qemu-devel] [PATCH 5/6] file_ram_alloc(): extract temporary-file creation code to separate function (v2),
Eduardo Habkost <=
- Re: [Qemu-devel] [RFC PATCH 0/6] option to not remove files inside -mem-path dir (v2), Daniel P. Berrange, 2012/07/02