From patchwork Tue Apr 28 09:18:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 47656 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D23AB20553 for ; Tue, 28 Apr 2015 09:18:14 +0000 (UTC) Received: by wiun10 with SMTP id n10sf4212224wiu.1 for ; Tue, 28 Apr 2015 02:18:14 -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=NKCkWhrVpgMuinrGlL98d33sv4M5E2v2PNGVA/SPJ+c=; b=FKXkP9q/t8AT/ufo3RXglyDj3Vv+3e7wfqndtuoaRc2KKmDs1SBuNNOjrs6yreLrHw jvs1t170YeE6atFZv4+8rt9gfvibEWNDicClVogW9pgfe/oNK+aOzsoLQNhoWzeBPutI nBoMrgsHwgD/CTNyMW3Q1yQE/BOkZw7XLooKW5ISBPEdafNcsfbjBntppiQWOFwPC/nK UExa1Nbl8mCYddTZasWYd8emYm3LIccPrbhFPb1Yn+d9R8MkD7E0UebK6cwhm4PY1xv3 aMry36CO2/ReDot4VT6A+tgs9jxESzYcDeZlBbDvY00JG4ECwNBi/uDQd9or+urpRcE6 C9Lw== X-Gm-Message-State: ALoCoQl9QjRVlaENgL0vHudsMVqgR4OsZWe0PZUh3CvsRjRA4sbtWLka1C3mRXPf1N6Z0+gAu2Z6 X-Received: by 10.194.241.200 with SMTP id wk8mr9750740wjc.7.1430212694047; Tue, 28 Apr 2015 02:18:14 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.30.74 with SMTP id q10ls47687lah.35.gmail; Tue, 28 Apr 2015 02:18:13 -0700 (PDT) X-Received: by 10.112.211.167 with SMTP id nd7mr13826708lbc.62.1430212693795; Tue, 28 Apr 2015 02:18:13 -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 lb7si16629910lac.89.2015.04.28.02.18.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 02:18:13 -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 bd9so99484537lab.2 for ; Tue, 28 Apr 2015 02:18:13 -0700 (PDT) X-Received: by 10.152.27.98 with SMTP id s2mr13789596lag.106.1430212693695; Tue, 28 Apr 2015 02:18:13 -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 l1csp1764910lbt; Tue, 28 Apr 2015 02:18:13 -0700 (PDT) X-Received: by 10.194.86.135 with SMTP id p7mr30937722wjz.89.1430212691501; Tue, 28 Apr 2015 02:18:11 -0700 (PDT) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com. [209.85.212.177]) by mx.google.com with ESMTPS id q20si17014053wiv.60.2015.04.28.02.18.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 02:18:11 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.177 as permitted sender) client-ip=209.85.212.177; Received: by wief7 with SMTP id f7so12186156wie.0 for ; Tue, 28 Apr 2015 02:18:11 -0700 (PDT) X-Received: by 10.180.77.83 with SMTP id q19mr27529107wiw.89.1430212691197; Tue, 28 Apr 2015 02:18:11 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id em18sm9518708wjd.19.2015.04.28.02.18.10 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Apr 2015 02:18:10 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, pbonzini@redhat.com, peter.crosthwaite@xilinx.com Cc: christoffer.dall@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, alex.williamson@redhat.com Subject: [PATCH 2/3] qdev: check callback takes Object **target as third argument Date: Tue, 28 Apr 2015 10:18:02 +0100 Message-Id: <1430212683-10984-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1430212683-10984-1-git-send-email-eric.auger@linaro.org> References: <1430212683-10984-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 **. 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 typically useful for starting irqfd setup in vfio platform use case. Signed-off-by: Eric Auger --- hw/core/qdev-properties.c | 2 +- include/hw/qdev-properties.h | 2 +- include/qom/object.h | 7 +++---- qom/object.c | 15 +++++++++------ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 570d5f0..a42f9d4 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -22,7 +22,7 @@ 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 **target, Error **errp) { DeviceState *dev = DEVICE(obj); diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index d67dad5..b2868be 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -213,6 +213,6 @@ 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 **target, Error **errp); #endif diff --git a/include/qom/object.h b/include/qom/object.h index 4687fa1..0a7daff 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 (*object_property_set_link_t)(Object *, const char *, - Object *, Error **); + Object **, 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 **, Error **); /** * object_property_add_link: @@ -1168,8 +1168,7 @@ void object_property_allow_set_link(Object *, const char *, */ void object_property_add_link(Object *obj, const char *name, const char *type, Object **child, - void (*check)(Object *obj, const char *name, - Object *val, Error **errp), + object_property_set_link_t check, ObjectPropertyLinkFlags flags, Error **errp); diff --git a/qom/object.c b/qom/object.c index b8dff43..cc9ed87 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 **target, Error **errp) { /* Allow the link to be set, always */ } typedef struct { Object **child; - void (*check)(Object *, const char *, Object *, Error **); + void (*check)(Object *, const char *, Object **, Error **); 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); } @@ -1233,7 +1236,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 **), + Object **, Error **), ObjectPropertyLinkFlags flags, Error **errp) {