From patchwork Fri Mar 10 13:09:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 737407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vfngP0XYDz9s7p for ; Sat, 11 Mar 2017 00:10:25 +1100 (AEDT) Received: from localhost ([::1]:39065 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmKJK-0002CZ-GD for incoming@patchwork.ozlabs.org; Fri, 10 Mar 2017 08:10:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmKIn-0002BF-MF for qemu-devel@nongnu.org; Fri, 10 Mar 2017 08:09:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmKIm-00020e-FE for qemu-devel@nongnu.org; Fri, 10 Mar 2017 08:09:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35178) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmKIm-00020N-9h for qemu-devel@nongnu.org; Fri, 10 Mar 2017 08:09:48 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85D837F342; Fri, 10 Mar 2017 13:09:48 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-8-39.pek2.redhat.com [10.72.8.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0096A2D653; Fri, 10 Mar 2017 13:09:44 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Fri, 10 Mar 2017 21:09:29 +0800 Message-Id: <1489151370-15453-2-git-send-email-peterx@redhat.com> In-Reply-To: <1489151370-15453-1-git-send-email-peterx@redhat.com> References: <1489151370-15453-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 10 Mar 2017 13:09:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] hostmem: introduce host_memory_backend_mr_inited() 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: Peter Maydell , Paolo Bonzini , Eduardo Habkost , peterx@redhat.com, Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We were checking this against memory region size of host memory backend's mr field to see whether the mr has been inited. This is efficient but less elegant. Let's make a helper for it to avoid confusions, along with some notes. Suggested-by: Peter Maydell Signed-off-by: Peter Xu --- backends/hostmem.c | 9 +++++++++ include/sysemu/hostmem.h | 1 + 2 files changed, 10 insertions(+) diff --git a/backends/hostmem.c b/backends/hostmem.c index 7f5de70..4e9ef62 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -243,6 +243,15 @@ static void host_memory_backend_init(Object *obj) backend->prealloc = mem_prealloc; } +bool host_memory_backend_mr_inited(HostMemoryBackend *backend) +{ + /* + * NOTE: We forbid zero-length memory backend, so here zero means + * "we haven't inited the backend memory region yet". + */ + return memory_region_size(&backend->mr) != 0; +} + MemoryRegion * host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp) { diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index ecae0cf..ed6a437 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -62,6 +62,7 @@ struct HostMemoryBackend { MemoryRegion mr; }; +bool host_memory_backend_mr_inited(HostMemoryBackend *backend); MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp);