From: Peter Xu <pet...@redhat.com> 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 <peter.mayd...@linaro.org> Signed-off-by: Peter Xu <pet...@redhat.com> Message-Id: <1489151370-15453-2-git-send-email-pet...@redhat.com> Reviewed-by: Eduardo Habkost <ehabk...@redhat.com> Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- include/sysemu/hostmem.h | 1 + backends/hostmem.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index ecae0cff19..ed6a437f4d 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); diff --git a/backends/hostmem.c b/backends/hostmem.c index 89feb9ed75..d8faab4bed 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -237,6 +237,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) { -- 2.11.0.259.g40922b1