[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 3/4] file_ram_alloc(): extract temporary-file cr
From: |
Blue Swirl |
Subject: |
Re: [Qemu-devel] [PATCH 3/4] file_ram_alloc(): extract temporary-file creation code to separate function |
Date: |
Wed, 27 Jun 2012 17:27:37 +0000 |
On Tue, Jun 26, 2012 at 8:51 PM, Eduardo Habkost <address@hidden> wrote:
> Signed-off-by: Eduardo Habkost <address@hidden>
> ---
> exec.c | 35 +++++++++++++++++++++++++----------
> 1 file changed, 25 insertions(+), 10 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index 5f3b265..dcbe4e1 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2353,11 +2353,34 @@ 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;
> + char *filename;
> +
> + if (asprintf(&filename, "%s/qemu_back_mem.XXXXXX", path) == -1) {
> + return -1;
> + }
> +
> + fd = mkstemp(filename);
> + if (fd < 0) {
> + perror("unable to create backing store for hugepages");
> + free(filename);
> + return -1;
> + }
> + unlink(filename);
> + free(filename);
> +
> + return fd;
See my comments against 4/4.
> +}
> +
> static void *file_ram_alloc(RAMBlock *block,
> size_t length,
> const char *path)
> {
> - char *filename;
> void *area;
> int fd;
> #ifdef MAP_POPULATE
> @@ -2379,18 +2402,10 @@ static void *file_ram_alloc(RAMBlock *block,
> return NULL;
> }
>
> - if (asprintf(&filename, "%s/qemu_back_mem.XXXXXX", path) == -1) {
> - return NULL;
> - }
> -
> - fd = mkstemp(filename);
> + fd = get_temp_fd(path);
> if (fd < 0) {
> - perror("unable to create backing store for hugepages");
> - free(filename);
> return NULL;
> }
> - unlink(filename);
> - free(filename);
>
> length = (length+hpagesize-1) & ~(hpagesize-1);
>
> --
> 1.7.10.4
>
>