From patchwork Tue Apr 12 11:55:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 8809771 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EB4AF9F39A for ; Tue, 12 Apr 2016 11:58:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E2E02035D for ; Tue, 12 Apr 2016 11:58:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 868F520148 for ; Tue, 12 Apr 2016 11:58:24 +0000 (UTC) Received: from localhost ([::1]:47901 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwxb-0001DK-UI for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Apr 2016 07:58:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv4-0004X0-88 for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1apwv1-0008N9-Cu for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:46 -0400 Received: from mail-qg0-x229.google.com ([2607:f8b0:400d:c04::229]:34142) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv1-0008Mf-40 for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:43 -0400 Received: by mail-qg0-x229.google.com with SMTP id c6so13190700qga.1 for ; Tue, 12 Apr 2016 04:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ptWslqRPkGVC3LS80SjOmzHnaHAJl0kVQ/Z9CF9MTvs=; b=uRWrg0vvpUnLOqHL/6qi/zM2TZXVcyxl1zTtSQ3yQO4azYC1k1bQXdoGZHpQe5JOFk NJ9DNWQTmsoJ2GmIep6/3mb3nzew+sRY9gZ3AGDmH8bDMX9WDNH34qr0qeIfxtI/ZfU+ 0KvcLAeB9dVwLSmEH7GlViychs8PB+6+4PoYzfeMI9GAhWQ8Kd8LCxiEQmjl0/XnC6tJ 9cnLEGnZXb5K6lzeWqpkXSLecn+I7qnb7bZa7mUEPR8v3V4j5Py/9V/ONmjPDOhidfdP Zys+Y0ctNf4waDo7tUpyqmxo5pJKmYJhX1NjtjomMM1u6nRJBDosI6ZlKZ5qs44OpFbi HbXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ptWslqRPkGVC3LS80SjOmzHnaHAJl0kVQ/Z9CF9MTvs=; b=d61nxqqMeHIyQ9glKQKR4P0oj9//fMREEFKQNy898smTqKnw1FGCestuoH0nN5R102 6psMpGQrYh9Ip4oE/FX9nOqilONk0L9Y/7ETaVbOsD0rxIyMyIWe2XSmTTxlVI9VLUg1 QN4eX7L7Ke4NYwUrvtuxkDYDLRLda/SxCzUAmigFH0uL5gOehoCGqMHeyRYNjoHbKE6T EruQWPr09CsS6zRGVQLD7tkIgCSKAyZYEn3cMfiEXCCW5Nsu98bII96eeRWbiw4WRhLD tubHAU6PIlZqzHFooipP8M9f+pSmdO7kCfEJiUfvoYxOfR5G6gkCX7ZSI4LeFiuf+0lr VIpA== X-Gm-Message-State: AOPr4FXKUmkmujLb9tSrDs4QDDFPTm6CrfLJB+62VnFyX3BkBJv3GQzKU6rveurZMZUlIA== X-Received: by 10.140.82.69 with SMTP id g63mr3173303qgd.106.1460462142503; Tue, 12 Apr 2016 04:55:42 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id z141sm13356638qhd.1.2016.04.12.04.55.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Apr 2016 04:55:41 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Tue, 12 Apr 2016 13:55:23 +0200 Message-Id: <1460462129-17363-4-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460462129-17363-1-git-send-email-marcandre.lureau@redhat.com> References: <1460462129-17363-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::229 Subject: [Qemu-devel] [PATCH 3/9] exec: split qemu_ram_alloc_from_file() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Add qemu_ram_alloc_from_fd(), which can be use to allocate ramblock from fd only. Signed-off-by: Marc-André Lureau --- exec.c | 45 ++++++++++++++++++++++++++++++--------------- include/exec/ram_addr.h | 3 +++ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/exec.c b/exec.c index 422ea3e..8675b5e 100644 --- a/exec.c +++ b/exec.c @@ -1646,14 +1646,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; if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); @@ -1677,11 +1675,6 @@ 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); new_block = g_malloc0(sizeof(*new_block)); new_block->mr = mr; @@ -1690,11 +1683,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, errp); if (!new_block->host) { - if (created) { - unlink(mem_path); - } - close(fd); - g_free(new_block); return NULL; } @@ -1705,6 +1693,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 diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 5adf7a4..153f1b2 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -97,6 +97,9 @@ void qemu_mutex_unlock_ramlist(void); 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 *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr, Error **errp);