From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:45326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCaoV-0004TZ-4U for qemu-devel@nongnu.org; Mon, 04 Mar 2013 14:12:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCaoQ-0007Qs-Dl for qemu-devel@nongnu.org; Mon, 04 Mar 2013 14:12:43 -0500 Received: from mail-ie0-x234.google.com ([2607:f8b0:4001:c03::234]:55916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCaWl-0001Gj-N8 for qemu-devel@nongnu.org; Mon, 04 Mar 2013 13:54:23 -0500 Received: by mail-ie0-f180.google.com with SMTP id bn7so6684783ieb.11 for ; Mon, 04 Mar 2013 10:54:22 -0800 (PST) From: peter@gridcentric.ca Date: Mon, 4 Mar 2013 13:54:25 -0500 Message-Id: <1362423265-15855-1-git-send-email-peter@gridcentric.ca> Subject: [Qemu-devel] [PATCH v3] exec: make -mem-path filenames deterministic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, aliguori@us.ibm.com, afaerber@suse.de Cc: andreslc@gridcentric.ca, peter@gridcentric.ca From: Peter Feiner Adds ramblocks' names to their backing files when using -mem-path. Eases introspection and debugging. Signed-off-by: Peter Feiner --- The commit should probably be called "exec: add ramblocks' names to -mem-path files" since the paths aren't deterministic. v1 -> v2: Just add ramblock name to mkstemp template. v2 -> v3: Safely handle ramblocks with "/" in their names exec.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 46a2830..f84e095 100644 --- a/exec.c +++ b/exec.c @@ -844,6 +844,8 @@ static void *file_ram_alloc(RAMBlock *block, const char *path) { char *filename; + char *sanitized_name; + char *c; void *area; int fd; #ifdef MAP_POPULATE @@ -865,7 +867,16 @@ static void *file_ram_alloc(RAMBlock *block, return NULL; } - filename = g_strdup_printf("%s/qemu_back_mem.XXXXXX", path); + /* Make name safe to use with mkstemp by replacing '/' with '_'. */ + sanitized_name = g_strdup(block->mr->name); + for (c = sanitized_name; *c != '\0'; c++) { + if (*c == '/') + *c = '_'; + } + + filename = g_strdup_printf("%s/qemu_back_mem.%s.XXXXXX", path, + sanitized_name); + g_free(sanitized_name); fd = mkstemp(filename); if (fd < 0) { -- 1.7.10.4