From patchwork Tue Apr 12 11:55:24 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: 8809781 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 CF6C79F39A for ; Tue, 12 Apr 2016 11:58:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 33E7D2035B for ; Tue, 12 Apr 2016 11:58:29 +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 8A075200C1 for ; Tue, 12 Apr 2016 11:58:28 +0000 (UTC) Received: from localhost ([::1]:47902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwxf-0001QU-VS for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Apr 2016 07:58:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv4-0004Yp-So 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 1apwv3-0008NW-Nu for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:46 -0400 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]:34151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv3-0008NS-Hn for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:45 -0400 Received: by mail-qg0-x236.google.com with SMTP id c6so13191479qga.1 for ; Tue, 12 Apr 2016 04:55:45 -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=0/+1DcYnojagOnHi+LWdlFeKiOJf4lz2/OiOMZjJCxg=; b=Jv7xCs9Cuu2fqcRS6VlNU+OFLLB02jnZl9Dzs+Zszcy0GQ4ntfye1JAmEKY8neWgk6 8lew1TYOnemFvl+A7WHDgLTTuJzdXX+7zjEBCXco61DurSM/XBix2mXpZE62rk9cm81J jwOp1JkkkqQO+H/W+YPfhfGNg7DzwOEyx+HatHb7F6akvTnlLqglcZvrvulWbU0qRf0S K7E+PtMdwKO3SRmdUuLMjIrXKzppKrMal/MLbv+rLnZmxxz3jCz8MXV7Mo/qKfAZpmGH 2GmB5E+bmec/3fnYGkjwRqC0V/WrugbTAYbXuqSmIXDFHbzoXU4WZqhGMu8W2KAO7uni 2kYA== 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=0/+1DcYnojagOnHi+LWdlFeKiOJf4lz2/OiOMZjJCxg=; b=f+ocea6BtvTVwFkGKgIkV5rGOTRrXuJ9FKoOygwY/QaQ4s1MDetKFt3+5VLj4dwLdk LVDpbXQVg+tATJKr2mU2idTr9LsPEXcUYnzorMQtsjF/bJD+g7JB7WQ5rx+r4CCORUVB 3tNhEBsBBDteRwgpkfjiZw7a0PhP5q8P5XaEj8g9DAGh06IElFo3LyrQPWK23+KX5SuU N8eKAzTr9sFqV/meZ5+XwlqzvmXRjinjrlv4e4FuLdhtPw/8z1Yy2NQBsa8LdRVuyRCR M/6ueqO/I0yoUhFe+WQRJrL9E8+jR2B1D7RrFo8A9gLpr9L5jf6JOdYxDhPxDaSGBxoB IpSg== X-Gm-Message-State: AOPr4FVdORG1K9ZmwAV5qo9PxIOD1UNP37yDxDhgHLCuSZI//vkbJttzvt5xIkoGVtswiA== X-Received: by 10.140.23.139 with SMTP id 11mr3211117qgp.62.1460462144978; Tue, 12 Apr 2016 04:55:44 -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 o77sm13390072qgd.37.2016.04.12.04.55.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Apr 2016 04:55:44 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Tue, 12 Apr 2016 13:55:24 +0200 Message-Id: <1460462129-17363-5-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::236 Subject: [Qemu-devel] [PATCH 4/9] Add memory_region_init_ram_from_fd() 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 a new function to Initialize a RAM memory region with a mmap-ed file descriptor. Signed-off-by: Marc-André Lureau --- include/exec/memory.h | 20 ++++++++++++++++++++ memory.c | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index e2a3e99..017bfdd 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -399,6 +399,26 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, bool share, const char *path, Error **errp); + +/** + * memory_region_init_ram_from_fd: Initialize RAM memory region with a + * mmap-ed backend. + * + * @mr: the #MemoryRegion to be initialized. + * @owner: the object that tracks the region's reference count + * @name: the name of the region. + * @size: size of the region. + * @share: %true if memory must be mmaped with the MAP_SHARED flag + * @fd: the fd to mmap. + * @errp: pointer to Error*, to store an error if it happens. + */ +void memory_region_init_ram_from_fd(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + bool share, + int fd, + Error **errp); #endif /** diff --git a/memory.c b/memory.c index f76f85d..dad99a9 100644 --- a/memory.c +++ b/memory.c @@ -1351,6 +1351,22 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, mr->ram_block = qemu_ram_alloc_from_file(size, mr, share, path, errp); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } + +void memory_region_init_ram_from_fd(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + bool share, + int fd, + Error **errp) +{ + memory_region_init(mr, owner, name, size); + mr->ram = true; + mr->terminates = true; + mr->destructor = memory_region_destructor_ram; + mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp); + mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; +} #endif void memory_region_init_ram_ptr(MemoryRegion *mr,