From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtIbw-0001cF-9w for qemu-devel@nongnu.org; Mon, 02 Nov 2015 12:09:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtIbt-0004bp-I9 for qemu-devel@nongnu.org; Mon, 02 Nov 2015 12:09:36 -0500 Received: from relay.parallels.com ([195.214.232.42]:54522) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtIbt-0004bQ-AY for qemu-devel@nongnu.org; Mon, 02 Nov 2015 12:09:33 -0500 Message-ID: <563798B3.4080204@virtuozzo.com> Date: Mon, 2 Nov 2015 20:09:07 +0300 From: Vladimir Sementsov-Ogievskiy MIME-Version: 1.0 References: <1446455617-129562-1-git-send-email-guangrong.xiao@linux.intel.com> <1446455617-129562-14-git-send-email-guangrong.xiao@linux.intel.com> In-Reply-To: <1446455617-129562-14-git-send-email-guangrong.xiao@linux.intel.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v7 13/35] hostmem-file: use whole file size if possible List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xiao Guangrong , pbonzini@redhat.com, imammedo@redhat.com Cc: ehabkost@redhat.com, kvm@vger.kernel.org, mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, dan.j.williams@intel.com, rth@twiddle.net On 02.11.2015 12:13, Xiao Guangrong wrote: > Use the whole file size if @size is not specified which is useful > if we want to directly pass a file to guest > > Signed-off-by: Xiao Guangrong > --- > backends/hostmem-file.c | 22 ++++++++++++++++++---- > 1 file changed, 18 insertions(+), 4 deletions(-) > > diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c > index 9097a57..ea355c1 100644 > --- a/backends/hostmem-file.c > +++ b/backends/hostmem-file.c > @@ -38,15 +38,29 @@ 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; > } > > + if (!backend->size) { > + Error *local_err = NULL; > + > + /* > + * use the whole file size if @size is not specified. > + */ > + backend->size = qemu_file_getlength(fb->mem_path, &local_err); > + if (local_err) { > + error_propagate(errp, local_err); > + return; > + } > + } > + > + if (!backend->size) { > + error_setg(errp, "can't create backend on the file whose size is 0"); > + return; > + } > + > backend->force_prealloc = mem_prealloc; > memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), > object_get_canonical_path(OBJECT(backend)), why not just + if (!backend->size) { + /* + * use the whole file size if @size is not specified. + */ + backend->size = qemu_file_getlength(fb->mem_path, errp); + if (*errp) { + return; + } + } what the purpose of propagating? -- Best regards, Vladimir * now, @virtuozzo.com instead of @parallels.com. Sorry for this inconvenience.