From patchwork Mon Jul 2 18:06:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 168630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 08AF92C00A4 for ; Tue, 3 Jul 2012 04:52:41 +1000 (EST) Received: from localhost ([::1]:47548 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sll1e-00034k-Jv for incoming@patchwork.ozlabs.org; Mon, 02 Jul 2012 14:07:06 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sll0u-0001Ln-KA for qemu-devel@nongnu.org; Mon, 02 Jul 2012 14:06:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sll0p-0001uo-IJ for qemu-devel@nongnu.org; Mon, 02 Jul 2012 14:06:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sll0p-0001tJ-AW for qemu-devel@nongnu.org; Mon, 02 Jul 2012 14:06:15 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q62I5nQD004061 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 2 Jul 2012 14:05:49 -0400 Received: from blackpad.lan.raisama.net (vpn1-4-141.gru2.redhat.com [10.97.4.141]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q62I5nwI025996; Mon, 2 Jul 2012 14:05:49 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id C2D72203EE2; Mon, 2 Jul 2012 15:06:40 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2012 15:06:37 -0300 Message-Id: <1341252398-12268-6-git-send-email-ehabkost@redhat.com> In-Reply-To: <1341252398-12268-1-git-send-email-ehabkost@redhat.com> References: <1341252398-12268-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Bill Gray , Andrea Arcangeli , Andre Przywara , kvm@vger.kernel.org, Bharata B Rao Subject: [Qemu-devel] [PATCH 5/6] file_ram_alloc(): extract temporary-file creation code to separate function (v2) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Changes v1 -> v2: - Fix trailing space issue - Rebase against new code using g_strdup_printf() Signed-off-by: Eduardo Habkost --- 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);