From patchwork Fri Jun 15 11:24:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 929896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 416dff19lxz9s2L for ; Fri, 15 Jun 2018 21:33:46 +1000 (AEST) Received: from localhost ([::1]:45996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTmz9-000669-NM for incoming@patchwork.ozlabs.org; Fri, 15 Jun 2018 07:33:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTmrI-0008Ba-TX for qemu-devel@nongnu.org; Fri, 15 Jun 2018 07:25:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTmrH-0000z2-OX for qemu-devel@nongnu.org; Fri, 15 Jun 2018 07:25:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48848 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fTmrH-0000yT-E2; Fri, 15 Jun 2018 07:25:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07192401CB89; Fri, 15 Jun 2018 11:25:35 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-18.ams2.redhat.com [10.36.117.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2453863AF6; Fri, 15 Jun 2018 11:25:33 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 15 Jun 2018 13:24:58 +0200 Message-Id: <20180615112500.19854-11-david@redhat.com> In-Reply-To: <20180615112500.19854-1-david@redhat.com> References: <20180615112500.19854-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 15 Jun 2018 11:25:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 15 Jun 2018 11:25:35 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 10/12] nvdimm: convert "label-size" into a static property 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: Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We don't allow to modify it after realization. So we can simply turn it into a static property. The value is now validated during realize(). Signed-off-by: David Hildenbrand --- hw/mem/nvdimm.c | 53 ++++++++----------------------------------------- 1 file changed, 8 insertions(+), 45 deletions(-) diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 7260c9c6b1..d3e8a5bcbb 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -27,50 +27,6 @@ #include "qapi/visitor.h" #include "hw/mem/nvdimm.h" -static void nvdimm_get_label_size(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - NVDIMMDevice *nvdimm = NVDIMM(obj); - uint64_t value = nvdimm->label_size; - - visit_type_size(v, name, &value, errp); -} - -static void nvdimm_set_label_size(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - NVDIMMDevice *nvdimm = NVDIMM(obj); - Error *local_err = NULL; - uint64_t value; - - if (memory_region_size(&nvdimm->nvdimm_mr)) { - error_setg(&local_err, "cannot change property value"); - goto out; - } - - visit_type_size(v, name, &value, &local_err); - if (local_err) { - goto out; - } - if (value < MIN_NAMESPACE_LABEL_SIZE) { - error_setg(&local_err, "Property '%s.%s' (0x%" PRIx64 ") is required" - " at least 0x%lx", object_get_typename(obj), - name, value, MIN_NAMESPACE_LABEL_SIZE); - goto out; - } - - nvdimm->label_size = value; -out: - error_propagate(errp, local_err); -} - -static void nvdimm_init(Object *obj) -{ - object_property_add(obj, NVDIMM_LABEL_SIZE_PROP, "int", - nvdimm_get_label_size, nvdimm_set_label_size, NULL, - NULL, NULL); -} - static MemoryRegion *nvdimm_get_memory_region(PCDIMMDevice *dimm, Error **errp) { NVDIMMDevice *nvdimm = NVDIMM(dimm); @@ -86,6 +42,13 @@ static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp) align = memory_region_get_alignment(mr); + if (nvdimm->label_size && nvdimm->label_size < MIN_NAMESPACE_LABEL_SIZE) { + error_setg(errp, "the label-size (0x%" PRIx64 ") has to be " + "either 0 or at least 0x%lx", + nvdimm->label_size, MIN_NAMESPACE_LABEL_SIZE); + return; + } + pmem_size = size - nvdimm->label_size; nvdimm->label_data = memory_region_get_ram_ptr(mr) + pmem_size; pmem_size = QEMU_ALIGN_DOWN(pmem_size, align); @@ -143,6 +106,7 @@ static void nvdimm_write_label_data(NVDIMMDevice *nvdimm, const void *buf, static Property nvdimm_properties[] = { DEFINE_PROP_BOOL(NVDIMM_UNARMED_PROP, NVDIMMDevice, unarmed, false), + DEFINE_PROP_UINT64(NVDIMM_LABEL_SIZE_PROP, NVDIMMDevice, label_size, 0), DEFINE_PROP_END_OF_LIST(), }; @@ -166,7 +130,6 @@ static TypeInfo nvdimm_info = { .class_size = sizeof(NVDIMMClass), .class_init = nvdimm_class_init, .instance_size = sizeof(NVDIMMDevice), - .instance_init = nvdimm_init, }; static void nvdimm_register_types(void)