From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzcEN-0007ei-53 for qemu-devel@nongnu.org; Thu, 27 Oct 2016 00:23:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzcEK-0006Pj-S5 for qemu-devel@nongnu.org; Thu, 27 Oct 2016 00:23:55 -0400 Received: from mga09.intel.com ([134.134.136.24]:33340) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bzcEK-0006Ld-Ix for qemu-devel@nongnu.org; Thu, 27 Oct 2016 00:23:52 -0400 From: Haozhong Zhang Date: Thu, 27 Oct 2016 12:22:59 +0800 Message-Id: <20161027042300.5929-3-haozhong.zhang@intel.com> In-Reply-To: <20161027042300.5929-1-haozhong.zhang@intel.com> References: <20161027042300.5929-1-haozhong.zhang@intel.com> Subject: [Qemu-devel] [PATCH v2 2/3] exec.c: check memory backend file size with 'size' option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Eduardo Habkost , Igor Mammedov Cc: Paolo Bonzini , Peter Crosthwaite , Richard Henderson , Haozhong Zhang If the memory backend file is not large enough to hold the required 'size', Qemu will report error and exit. Signed-off-by: Haozhong Zhang --- exec.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/exec.c b/exec.c index a2b371a..264a25f 100644 --- a/exec.c +++ b/exec.c @@ -1316,6 +1316,13 @@ static void *file_ram_alloc(RAMBlock *block, goto error; } + if (file_size > 0 && file_size < memory) { + error_setg(errp, "backing store %s size %"PRId64 + " does not match 'size' option %"PRIu64, + path, file_size, memory); + goto error; + } + memory = ROUND_UP(memory, block->page_size); /* -- 2.10.1