From patchwork Tue Apr 28 16:51:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 47695 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 63C2020553 for ; Tue, 28 Apr 2015 16:51:48 +0000 (UTC) Received: by laat2 with SMTP id t2sf234642laa.2 for ; Tue, 28 Apr 2015 09:51:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=aewfjJkSxyimLBrGY+8ZlDFiGOgV/mO/vBoHFBQirK4=; b=nJG6HUE2EhyGyZcZnkedyYNUjVrjuEs6cYY5y5rnXqyAQZKy545Wgch9oIaEAiGny7 CtMgRMj5QKNsfNLYWJuQhRgWrLu5/kp0ni3MTv5NL2OxBgFQzkrMYFZR9JWmVswclq8z BKZgd92vsVl/1E35zJ8KvbuSNGFAybbNDxxHWZJ3OedNVwdCqIzkjlToIeN/dFrmV1aQ lKxR/l8oip7MYSpBnRLOoCAs9XSxXrs8NSQiQIeqwSlwWUfmEyWNqd0nFDutyudNU1Ua 9CyFOKResffrYKKUxZE1bYEsUuUwLf6DyRpU1TlI4jR/kmvVi11SsvN4xjf+nS/73Csc n39Q== X-Gm-Message-State: ALoCoQmJnn2Ku4/0Ty4tSLPiGBGYsh6FOZCad2JB8GH5iEiXnybDWcUYt7YUtZ4Hnoja8Y1pbjTS X-Received: by 10.112.160.197 with SMTP id xm5mr10796558lbb.15.1430239907023; Tue, 28 Apr 2015 09:51:47 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.227 with SMTP id kt3ls89450lac.18.gmail; Tue, 28 Apr 2015 09:51:46 -0700 (PDT) X-Received: by 10.112.218.67 with SMTP id pe3mr14570642lbc.53.1430239906875; Tue, 28 Apr 2015 09:51:46 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id tq9si17446125lbb.126.2015.04.28.09.51.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 09:51:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by labbd9 with SMTP id bd9so546614lab.2 for ; Tue, 28 Apr 2015 09:51:46 -0700 (PDT) X-Received: by 10.152.27.98 with SMTP id s2mr15411789lag.106.1430239906780; Tue, 28 Apr 2015 09:51:46 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.67.65 with SMTP id l1csp2002334lbt; Tue, 28 Apr 2015 09:51:46 -0700 (PDT) X-Received: by 10.180.9.78 with SMTP id x14mr31679560wia.69.1430239894843; Tue, 28 Apr 2015 09:51:34 -0700 (PDT) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com. [209.85.212.182]) by mx.google.com with ESMTPS id t4si19260758wix.0.2015.04.28.09.51.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 09:51:34 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.182 as permitted sender) client-ip=209.85.212.182; Received: by wizk4 with SMTP id k4so148291033wiz.1 for ; Tue, 28 Apr 2015 09:51:34 -0700 (PDT) X-Received: by 10.194.77.44 with SMTP id p12mr34580347wjw.1.1430239894576; Tue, 28 Apr 2015 09:51:34 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id gs7sm17255958wib.10.2015.04.28.09.51.33 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Apr 2015 09:51:33 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, agraf@suse.de, pbonzini@redhat.com, peter.crosthwaite@xilinx.com Cc: christoffer.dall@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, peter.maydell@linaro.org, alex.bennee@linaro.org, kim.phillips@freescale.com, b.reynal@virtualopensystems.com, Bharat.Bhushan@freescale.com, vikrams@codeaurora.org Subject: [PATCH v13 10/12] qdev: check callback takes the property child as third argument Date: Tue, 28 Apr 2015 17:51:11 +0100 Message-Id: <1430239873-31950-11-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1430239873-31950-1-git-send-email-eric.auger@linaro.org> References: <1430239873-31950-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Check callback now takes as third argument an Object * const*. In object_set_link_property, we pass the property child as argument. We also assign the *child before the check call so that enhanced check can be performed in the callback. In case the check fails, the old value is restored and ref count is left unchanged. This typically makes possible to do checks both on the *child content (for instance a qemu_irq) and also perform some actions/ checks on its container, which was not possible before. This is for example useful for starting irqfd setup in vfio platform use case. Signed-off-by: Eric Auger --- v1 -> v2: - Object ** becomes Object * const* - rename patch title --- hw/core/qdev-properties.c | 3 ++- include/hw/qdev-properties.h | 3 ++- include/qom/object.h | 4 ++-- qom/object.c | 16 +++++++++------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 570d5f0..7e00cd2 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -22,7 +22,8 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name, } void qdev_prop_allow_set_link_before_realize(Object *obj, const char *name, - Object *val, Error **errp) + Object * const *target, + Error **errp) { DeviceState *dev = DEVICE(obj); diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index d67dad5..67ac457 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -213,6 +213,7 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name, * object_property_add_link(). */ void qdev_prop_allow_set_link_before_realize(Object *obj, const char *name, - Object *val, Error **errp); + Object * const *target, + Error **errp); #endif diff --git a/include/qom/object.h b/include/qom/object.h index 95d1a1d..ab60c16 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -34,7 +34,7 @@ typedef struct InterfaceClass InterfaceClass; typedef struct InterfaceInfo InterfaceInfo; typedef void (*LinkPropertySetter)(Object *, const char *, - Object *, Error **); + Object * const *, Error **); #define TYPE_OBJECT "object" @@ -1136,7 +1136,7 @@ typedef enum { * an error. */ void object_property_allow_set_link(Object *, const char *, - Object *, Error **); + Object * const *, Error **); /** * object_property_add_link: diff --git a/qom/object.c b/qom/object.c index b8dff43..ed286e7 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1112,14 +1112,14 @@ out: } void object_property_allow_set_link(Object *obj, const char *name, - Object *val, Error **errp) + Object * const *target, Error **errp) { /* Allow the link to be set, always */ } typedef struct { Object **child; - void (*check)(Object *, const char *, Object *, Error **); + LinkPropertySetter check; ObjectPropertyLinkFlags flags; } LinkProperty; @@ -1201,14 +1201,17 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque, return; } - prop->check(obj, name, new_target, &local_err); + object_ref(new_target); + *child = new_target; + + prop->check(obj, name, child, &local_err); if (local_err) { error_propagate(errp, local_err); + *child = old_target; + object_ref(new_target); return; } - object_ref(new_target); - *child = new_target; object_unref(old_target); } @@ -1232,8 +1235,7 @@ static void object_release_link_property(Object *obj, const char *name, void object_property_add_link(Object *obj, const char *name, const char *type, Object **child, - void (*check)(Object *, const char *, - Object *, Error **), + LinkPropertySetter check, ObjectPropertyLinkFlags flags, Error **errp) {