From patchwork Mon Oct 24 09:21:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9391781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A024E60231 for ; Mon, 24 Oct 2016 09:25:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90ABE28E45 for ; Mon, 24 Oct 2016 09:25:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8581C28E48; Mon, 24 Oct 2016 09:25:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 1359B28E45 for ; Mon, 24 Oct 2016 09:25:21 +0000 (UTC) Received: from localhost ([::1]:45441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bybVQ-00033n-SC for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Oct 2016 05:25:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bybSV-0000ws-Kv for qemu-devel@nongnu.org; Mon, 24 Oct 2016 05:22:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bybSU-0004ql-Rq for qemu-devel@nongnu.org; Mon, 24 Oct 2016 05:22:19 -0400 Received: from mga03.intel.com ([134.134.136.65]:49655) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bybSU-0004qB-Hd for qemu-devel@nongnu.org; Mon, 24 Oct 2016 05:22:18 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 24 Oct 2016 02:22:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,541,1473145200"; d="scan'208"; a="1049138401" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.148]) by orsmga001.jf.intel.com with ESMTP; 24 Oct 2016 02:22:16 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org, Eduardo Habkost , Igor Mammedov Date: Mon, 24 Oct 2016 17:21:51 +0800 Message-Id: <20161024092151.32386-3-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161024092151.32386-1-haozhong.zhang@intel.com> References: <20161024092151.32386-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH 2/2] hostmem-file: allow option 'size' optional 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: Paolo Bonzini , Richard Henderson , Xiao Guangrong , Haozhong Zhang , Peter Crosthwaite Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If 'size' option of hostmem-file is not given, QEMU will use the file size of 'mem-path' instead. For an empty file, a non-zero size must be specified by the option 'size'. Signed-off-by: Haozhong Zhang --- backends/hostmem-file.c | 10 ++++++---- exec.c | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 42efb2f..f94d2f7 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -40,10 +40,6 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend); - if (!backend->size) { - error_setg(errp, "can't create backend with size 0"); - return; - } if (!fb->mem_path) { error_setg(errp, "mem-path property not set"); return; @@ -62,6 +58,12 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) g_free(path); } #endif + if (!errp && !backend->size) { + backend->size = memory_region_size(&backend->mr); + if (!backend->size) { + error_setg(errp, "can't create backend with size 0"); + } + } } static char *get_mem_path(Object *o, Error **errp) diff --git a/exec.c b/exec.c index 95983c9..91adc62 100644 --- a/exec.c +++ b/exec.c @@ -1274,6 +1274,14 @@ static void *file_ram_alloc(RAMBlock *block, goto error; } + if (memory) { + memory = memory ?: file_size; + memory_region_set_size(block->mr, memory); + memory = HOST_PAGE_ALIGN(memory); + block->used_length = memory; + block->max_length = memory; + } + if (memory < block->page_size) { error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to " "or larger than page size 0x%zx",